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