bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bison-20001221


From: Akim Demaille
Subject: Re: bison-20001221
Date: 22 Jan 2001 11:40:01 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.1 (Crater Lake)

>>>>> "Hans" == Hans Aberg <address@hidden> writes:

Hans> At 12:24 +0100 1-01-18, Akim Demaille wrote: Another idea I had
Hans> is to make obstack into a FILE
>> May I recall that we moved to obstack to avoid temp files?

Hans> May I recall that FILE is a C data struct and not a file? :-)

Err, right, sorry.  But then, I don't understand what you mean.

Hans> -- The idea is of course to make something like obstack working
Hans> on memory, but wrapped up to look like a FILE struct. It would
Hans> have been easy in C++, in C I do not know.

Aah, that.  Well, again, this is out of the scope of this list.  And
indeed the Glibc has that feature:


 - Function: int obstack_printf (struct obstack *OBSTACK, const char
          *TEMPLATE, ...)
     This function is similar to `asprintf', except that it uses the
     obstack OBSTACK to allocate the space.  *Note Obstacks::.

     The characters are written onto the end of the current object.  To
     get at them, you must finish the object with `obstack_finish'
     (*note Growing Objects::).

and

Obstack Streams
---------------

   You can open an output stream that puts it data in an obstack.
*Note Obstacks::.

 - Function: FILE * open_obstack_stream (struct obstack *OBSTACK)
     This function opens a stream for writing data into the obstack
     OBSTACK.  This starts an object in the obstack and makes it grow
     as data is written (*note Growing Objects::).

     Calling `fflush' on this stream updates the current size of the
     object to match the amount of data that has been written.  After a
     call to `fflush', you can examine the object temporarily.

     You can move the file position of an obstack stream with `fseek' or
     `fseeko' (*note File Positioning::).  Moving the file position past
     the end of the data written fills the intervening space with zeros.

     To make the object permanent, update the obstack with `fflush', and
     then use `obstack_finish' to finalize the object and get its
     address.  The following write to the stream starts a new object in
     the obstack, and later writes add to that object until you do
     another `fflush' and `obstack_finish'.

     But how do you find out how long the object is?  You can get the
     length in bytes by calling `obstack_object_size' (*note Status of
     an Obstack::), or you can null-terminate the object like this:

          obstack_1grow (OBSTACK, 0);

     Whichever one you do, you must do it _before_ calling
     `obstack_finish'.  (You can do both if you wish.)

   Here is a sample function that uses `open_obstack_stream':

     char *
     make_message_string (const char *a, int b)
     {
       FILE *stream = open_obstack_stream (&message_obstack);
       output_task (stream);
       fprintf (stream, ": ");
       fprintf (stream, a, b);
       fprintf (stream, "\n");
       fclose (stream);
       obstack_1grow (&message_obstack, 0);
       return obstack_finish (&message_obstack);
     }


but it's not portable.


Hans> The header <size_t.h> is included from <stddef.h> on my
Hans> computer, and the latter is ISO/ANSI C. 

GNU is about POSIX.  And why did this size_t.h stuff show up actually?
OK with stddefs.h etc, but this is definitely the first time I hear
about size_t.h.  But really, *end of this story*, I am *not*
interested in porting Bison to MacOS.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]