in reply to Re: XS replacing my c library, not compatible with OS threads
in thread XS replacing my c library, not compatible with OS threads

Whilst mismatched C runtime libraries is certainly an issue with building XS extensions for use with binary distributions, it is far from being the predominant problem.

The single biggest problem is trying to work out what actually gets called when you use an *alloc call. There are so many #defines, #undefs, wrapper-functions and dispatch tables that conditionally define and redefine each of these calls, that you need to be a compiler to work out what actually gets called. And with so many levels of indirection and macro redefinition, setting breakpoints within a debugger is almost impossible.

And as the OP indicated, even if you use the compiler /E switch (or equivalent) to view the post preprocessor output, what you get is so complicated--a simple char *p = malloc( 10 ); decoding to several hundred bytes of tortuously nested, and often duplicated) function calls, casts and parens--that it is still essentially unintelligible.


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.

Replies are listed 'Best First'.
Re^3: XS replacing my c library, not compatible with OS threads
by Corion (Patriarch) on Dec 01, 2010 at 10:28 UTC

    There is at least a small utility distributed with Perl to help expanding the macros without having to talk to gcc /E yourself: expand-macro.pl. Of course that only shows you what the macros expand to, eventually, and not what the C code means.

      Shame it doesn't work with my compiler :(

      Actually doing the expansion isn't hard:

      C:\test>type expand_malloc.c #include "EXTERN.h" #include "perl.h" char *p = malloc( 10 ); C:\test> cl -E -nologo -GF -W3 -MD -Zi -DNDEBUG -Ox -GL -Wp64 -fp:prec +ise -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DWIN64 -DCONSER +VATIVE -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IMPLICIT_CONT +EXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX -MD -Zi -D +NDEBUG -Ox -GL -Wp64 -fp:precise -DVERSION=\"1.76\" -DXS_VERSION= +\"1.76\" "-IC:\Perl64\lib\CORE" -DHAS_PPPORT_H expand_malloc.c >jun +k.txt

      And if you load up the output file junk.txt, and wade you way down to line: 203,525 (Yes! That really is line: two hundred and three thousand five hundred and twenty five!), you get:

      [203524 lines omitted :)] #line 3 "expand_malloc.c" char *p = malloc( 10 );

      which probably means I've got the wrong set of defines on the command line :(

      Update: Of course. I forgot to include XSUB.h:

      ... #line 4 "expand_malloc.c" char *p = (*(*Perl_IMem_ptr(((PerlInterpreter *)Perl_get_context())))- +>pMalloc)((*Perl_IMem_ptr(((PerlInterpreter *)Perl_get_context()))), +(10));

      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.