Tassilo Parseval <[EMAIL PROTECTED]> writes:
>On Tue, Jul 13, 2004 at 03:06:11PM +1000 Sisyphus wrote:
>
>> Consider the following Inline C script:
>> 
>> use warnings;
>> use Inline C => <<'EOC';
>> 
>> void func_1() {
>>      printf("SOMETHING");

Depending on a whole mess of #define options printf is either 
the <stdio.h> one that does 
        fprintf(stdout,...) 

This is now the default.

or, possibly a #define to 

        PerlIO_stdoutf(...)
which does :
        PerlIO_printf(PerlIO_stdout(),...)  

If you use the PerlIO_stdoutf() explicitly then the PerlIO_flush() will work.

Which is right for you depends on whether you want XS output and perl 
output to interleave nicely. Using printf/fflush(stdout) in XS 
means both stdio and PerlIO have buffers to fd == 1.

>
>I'd say that you can't simply because PerlIOs are not (necessarily) the
>same as C's FILE*. Perl does its own flushing when appropriate.

It also depends if PerlIO is using stdio as an implemementation layer.
This is default on most UNIXes (when perl's Configure can decide 
how stdio works), but not on Win32 (because Win32's CRLF handling 
varies wildly between version of C runtime).

So a 

   binmode(STDOUT,":raw:stdio") 

in your perl part might help.

>
>> The actual XS file that Inline generates is included below (if that helps).
>> 
>
>After a call to this function, you could do a 
>
>    fflush(stdin);

fflush(stdin) is almost certainly wrong.
I think you mean fflush(stdout).

Many stdio-s do very strange things if you fflush() an input stream.


Reply via email to