On Wed, Oct 16, 2002 at 10:19:55PM +0100, Unknown Sender wrote:
> The other thing I'd like (more often than this, actually) is a way to say
> char *, but if the scalar is undef, give me NULL rather than "" and a perl
> warning about an uninitialized value.

It's on the tip of your tounge - it's as simple as supplying a typemap
for char* that tests for PL_sv_undef.  Attached is a demonstration of this.

-- 
Richard Clamp <[EMAIL PROTECTED]>
#!perl -w
use strict;
use Data::Dumper;
use Inline C => Config =>
  NAME => 'charp',
  TYPEMAPS => 'my_typemap';
use Inline C => <<END;
char *foo (char *bar) {
    printf("%x\n", bar);
    return NULL;
}
END


foo(undef);
my $u = foo("hello");
print Dumper \$u;
char *          T_CHARPTR

INPUT
T_CHARPTR
        $var = $arg == &PL_sv_undef ? NULL : (char *)SvPV_nolen($arg)

OUTPUT
T_CHARPTR
        sv_setpv((SV*)$arg, $var);

Reply via email to