Perhaps someone with a bit more familiarity with the Parrot IO subsystem
could give me some guidance here.  I'm currently trying to get a new
'peek' opcode working, and I'm having difficulties getting the io_unix
layer implemented correctly.

As far as I know, I'd get a call down into the io_unix layer when the
ParrotIO object isn't buffered.  What I want to be able to do is to
read()/fread() a character off of the io->fd filedescriptor, copy it into
the buffer, then ungetc() it back onto the stream.  Unfortunately,
however, ungetc requires a (FILE *), while the ParrotIO object carries
around only a raw file descriptor (I think).

I've seen some instances where people will cast the raw descriptor to a
(FILE *), however the man page for ungetc warns ominously in its BUGS
section that:

       It  is  not advisable to mix calls to input functions from
       the stdio library with low - level calls to read() for the
       file  descriptor  associated  with  the  input stream; the
       results will be undefined and very probably not  what  you
       want.

Numerous segfaults would seem to confirm that this is indeed very probably
not what I want.

That being said, what is the best course for buffering such characters at
the io_unix layer?  I apparently am not able to use the standard library
functions to do so (additionally, they only guarantee that you can peek
and replace a single character).

-c

Reply via email to