Sisyphus <[EMAIL PROTECTED]> writes: >Hi, > >Consider the following Inline C script: > >use warnings; >use Inline C => <<'EOC'; > >void func_1() { > printf("SOMETHING"); > } > >void func_2() { > printf("something\n"); > } > >EOC > >#$| = 1; #makes no difference
All $| = 1 does is cause the print "ops" in perl to do a PerlIO_flush() when they reach the end of their argument list. > >print "1\n"; >func_1(); >print "\n2\n"; >func_2; >print "3\n"; > >__END__ > >With perl 5.8.4 I would expect that to produce the following output: >1 >SOMETHING >2 >something >3 > >And that's exactly what is produced for me on Win32. Once more demonstrating that Win32 IO is still weird. >But on my MDK-9.1 >Linux I'm getting: >1 > >2 >SOMETHINGsomething >3 > >So the question is: How do I get the expected result without altering >the C code ? You can't. You have to add PerlIO_flush() call as suggested elsewhere. Or you could make stdout line buffered (which is probably what happens on Win32), or even unbuffered (like stderr). > >The actual XS file that Inline generates is included below (if that helps). > >Note that the problem is _not_ specific to Inline C. I've simply written >it that way for simplicity, hoping that someone else can readily >replicate the unusual result and maybe point to a solution. In "real >life" I'm dealing with a third party library in a normal XS-build >environment - and getting that odd behaviour with a function (within >that library) that prints to stdout but doesn't print a newline. > >Cheers, >Rob > >#include "EXTERN.h" >#include "perl.h" >#include "XSUB.h" >#include "INLINE.h" > >void func_1() { > printf("SOMETHING"); > } > > >void func_2() { > printf("something\n"); > } > > >MODULE = try_pl_903a PACKAGE = main > >PROTOTYPES: DISABLE > > >void >func_1 () > PREINIT: > I32* temp; > PPCODE: > temp = PL_markstack_ptr++; > func_1(); > if (PL_markstack_ptr != temp) { > /* truly void, because dXSARGS not invoked */ > PL_markstack_ptr = temp; > XSRETURN_EMPTY; /* return empty stack */ > } > /* must have used dXSARGS; list context implied */ > return; /* assume stack size is correct */ > >void >func_2 () > PREINIT: > I32* temp; > PPCODE: > temp = PL_markstack_ptr++; > func_2(); > if (PL_markstack_ptr != temp) { > /* truly void, because dXSARGS not invoked */ > PL_markstack_ptr = temp; > XSRETURN_EMPTY; /* return empty stack */ > } > /* must have used dXSARGS; list context implied */ > return; /* assume stack size is correct */