Perhaps pass "\0' rather than undef:
my $foo = undef;
my $bar = wrap_create_bar(\$foo);
sub wrap_create_bar {
if(defined(${$_[0]}) {create_bar($_[0]}
else {create_bar(\"\0")}
}
Update: I've had a couple of goes at correcting the above code (which is, of course, untested). I hope I've got it right ... or at least made my intention clear.
I'm basing that on the following Inline::C script, for which the foo1() sub produces the warning, but the foo2() sub does not. (Plus the fact that C seems to regard "\0" as equivalent to NULL.)
use warnings;
use Inline C => Config => BUILD_NOISY => 1;
use Inline C => <<'EOC';
void foo1(SV *x) {
printf("%s\n", SvPV_nolen(x));
}
EOC
$x = undef;
foo1($x);
foo2($x);
sub foo2 {
if(defined($x)) {foo1($x)}
else {foo1("\0")}
}
The problem is that as soon as a perl API function detects that it has been passed an undef, you'll get that warning (iff warnings are enabled). Simplest solution is to therefore pass a value that is not regarded as undef, but still has the desired effect - which means modifying the undef argument appropriately before it gets passed to the XSub. At least that's the only approach I could get to work for me ... though there may be others.
Cheers,
Rob
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.