Hi BrowserUK,
I had missed that final post of yours to the thread Inline C: using stderr segfaults?. I think you've got down to a level that I'd like to stay well clear of :-)
Incidentally, as regards *your* thread, did it make any difference if you rewrote test2() to use the perl abstraction layer ?
void test2 ( char* text ) {
PerlIO_printf( PerlIO_stderr(), "Got:'%s'\n", text );
}
As you say, the problems that you faced there may well be related to the problems I've been looking at - though I still have this notion that (at least part of) your problem might arise from the involvement of *2* C runtime libraries.
As for my particular issue, the following (somewhat kludgy) workaround seems to work reliably without any need to turn on $| ... though I haven't yet tried it on anything other than Win32:
use warnings;
use strict;
use Inline C => Config =>
INC => '-IC:/_32/C',
LIBS => '-LC:/_32/C -lmylib',
BUILD_NOISY => 1;
use Inline C => <<'EOC';
#include <mylib.h>
void _foo(PerlIO * stream) {
FILE * stdio_stream = PerlIO_exportFILE(stream, NULL);
my_puts(stdio_stream);
fflush(stdio_stream);
PerlIO_releaseFILE(stream, stdio_stream);
}
void _foo2(PerlIO * stream, SV * suffix) {
FILE * stdio_stream = PerlIO_exportFILE(stream, NULL);
my_puts(stdio_stream);
fflush(stdio_stream);
PerlIO_releaseFILE(stream, stdio_stream);
PerlIO_printf(stream, "%s", SvPV_nolen(suffix));
PerlIO_flush(stream);
}
EOC
for(1 .. 2) {
foo(*stdout, "\nhello from perl\n");
}
for(1 .. 2) {
foo(*stderr);
print "\nhello from perl\n";
}
sub foo {
if(@_ == 1) { _foo($_[0]) }
elsif(@_ == 2) { _foo2($_[0], $_[1]) }
else {die "Wrong no. of args to foo" }
}
Cheers, Rob
|