http://qs1969.pair.com?node_id=11139712

markong has asked for the wisdom of the Perl Monks concerning the following question:

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?