Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found