Hello!

I have to investigate the functionality of a C library and while in the past I always used SWIG to interface with C/C++ code, I am now trying to use Inline::C instead to save time on the "interface compilation" phase, seen that I'm only interested in experimenting with the C functions and copy/paste is not a problem.

All is good except I don't see how to "pass a NULL pointer from Perl". SWIG resolves by passing undef but Inline::C explodes on that, e.g.:

use v5.10; use Inline 'C'; say "At least we have compiled a bit of C code!"; my $ret= "HD3"; my $output = enctypex_msname("HD2", undef); say "Output from enctypex_msname() call: '$output', \$ret is '$ret'"; __END__ __C__ unsigned char *enctypex_msname(unsigned char *name, unsigned char *ret +name) { static unsigned char msname[256]; unsigned i, c, server_num; if(!name) return(NULL); server_num = 0; for(i = 0; name[i]; i++) { c = tolower(name[i]); server_num = c - (server_num * 0x63306ce7); } server_num %= 20; if(retname) { snprintf(retname, 256, "%s.ms%d.host.com", name, server_num); return(retname); } snprintf(msname, sizeof(msname), "%s.ms%d.host.com", name, server_ +num); return(msname); }

This results in:

At least we have compiled a bit of C code!
Use of uninitialized value in subroutine entry at script/decode_test.pl line 12.
Segmentation fault (core dumped)
I see that SWIG provides some custom type mappings for all the bindings, so unless I re-use those I am probably out of luck and have to write one for my use case? I wonder how it comes that nobody has ever had to pass a NULL pointer or have I overlooked something in Inline::* docs ?
Any hints?


In reply to Inline::C and NULL pointers by markong

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.