There does appear to be a bug in the impementation of fprintf(). Note how in the output of the following code, test() prints the value of stderr when fetched via the Perl macros, and directly from the OS and gets the same value. But then in test2(), when it tries to pass & use the directly accessed value with fprintf() it does in exactly the same way and at exactly the same point as when using it via the Perl macro.

However, when I pass the Perl macro derived value to vfprintf() in eprintf() it works fine. Indicative of something, though I'm not sure exactly what :)

#! perl -slw use strict; #use Inline 'FORCE'; use Inline C => 'DATA', NAME => 'IC_junk1', CLEAN_AFTER_BUILD => 0; test( 'fred' ); test2( 'fred' ); __DATA__ __C__ #include <stdio.h> #include <stdarg.h> void eprintf (const char *template, ...) { va_list ap; va_start( ap, template ); vfprintf( stderr, template, ap ); va_end( ap ); } void test ( char* text ) { printf( "Got:'%s'\n", text ); printf( "stderr via PerlIO macro: %x\n", stderr ); printf( "stderr via Win32_stderr: %x\n", win32_stderr() ); } void test2 ( char* text ) { // eprintf( "Get:'%s'\n", text ); fprintf( win32_stderr(), "Get:'%s'\n", text ); } /* Outputs: C:\test>IC-junk1.pl Got:'fred' stderr via PerlIO macro: 77c5acc0 stderr via Win32_stderr: 77c5acc0 then segfaults when fprintf( stderr, .... ) is called. */

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^4: Inline C: using stderr segfaults? by BrowserUk
in thread Inline C: using stderr segfaults? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.