Coding Guidelines/SWIG Gotchas

From wiki.zmanda.com
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

'undef' in hashes

http://perldoc.perl.org/perlguts.html#AVs%2c-HVs-and-undefined-values

If you're building a hash for return to Perl, and you need to add an undef, do not use &PL_sv_undef. Instead, use newSV(0):

 hv_store(hv, "template", 8, &newSV(0), 0);

Boolean Values

If you're using boolean values, use &PL_sv_yes or &PL_sv_no, instead of making new IV's.

SWIG doesn't like SWIG's strings

When you access a member of a SWIGged struct directly via hashref syntax:

my $foo = $hdr->{'name'};

you get back a "magic" scalar. This is used to support setting those values:

 $hdr->{'name'} = "jimmy";

but unfortunately, SWIG doesn't like its magic strings. This won't work:

 print Amanda::Util::quote_string($hdr->{'name'});

to work around this, re-stringifiy it with

 print Amanda::Util::quote_string("".$hdr->{'name'}); # SWIG sucks