Tassilo Parseval <[EMAIL PROTECTED]> writes:
>
>My concern was with PerIO_fdopen(). I didn't know whether perl would
>reuse the fd (and simply sort of wrap it in a PerlIO) or duplicate it.

There is a pod which tells you.

>In case of duping, ignoring O_NONBLOCK would be bad.

AFAIK a dup()ed fd inherits the non-blocking-ness along with 
all the other kernel level attributes like file position.

>
>The problem with fd-versus-FILE IO is eventually what bothers me. 

For Perl5.8+ you can avoid the buffering issues of that problem
by just using :unix layer.


>> >Going the other way (XSUB gets a glob-ref and needs FILE*/fd) isn't
>> >always smooth either. 
>> 
>> 
>> First step is to get the IO *  Perl_sv2io() does that.
>> Next you get your PerlIO * - you have a choice of two the one for output
>> and the one for input (often same but not for sockets or (some) ttys).
>> 
>> Getting a FILE * isn't smooth, but we have an API for that.
>> Getting a fd is just PerlIO_fileno(PerlIO *f)
>
>That reads amazingly simple as you describe it. Good that I can from now
>on look it up for future reference.
>
>> >For that purpose, I made two macros:
>> >
>> >    #ifdef _WIN32
>> >    # define PerlIO_exportFILE(f,fl) ((FILE*)(f))
>> >    #endif
>> 
>> >Especially the _WIN32 branch is fishy. But it was on this list that
>> >someone said that on windows a PerlIO* would just be an alias for FILE*.
>> 
>> It was on perl5.6 - not on perl5.8.
>
>Bah! That means I have to change one of my modules. Quite
>unsurprisingly, the branch of the code that converted a glob-ref to a
>FILE* was not covered by the tests. :-(
>
>> >    #define sv_to_file(sv) (PerlIO_exportFILE(IoIFP(sv_2io(sv)), NULL))
>> >
>> That is "okay" anywhere with perl5.8+ - but please read the PODs.
>> In perl5.8+ there isn't necessarily a FILE * in normal perl IO.
>> So the above may have to 
>> 
>>     FILE *stdio = fdopen(PerlIO_fileno(pio),mode))
>
>Sigh, so not even my non-Win32 path is necessarily right.

Why do you need a FILE *?
Won't a PerlIO * do? - you always have one of those.

IMHO you only need a FILE * for passing external C libraries
that expect such a thing.

>
>Anyway, Nick, thanks for your patient attempts to explain this book
>with 7^7 seals to me. I think I'm now able to find a way through this
>muddle somehow.

I will try and remember to add the essence of these discussions 
to the PODs.


Reply via email to