develooper Front page | perl.perl5.porters | Postings from May 2004

undef loses it magicness when assigned to a variable?

Thread Next
Stas Bekman
May 27, 2004 00:45
undef loses it magicness when assigned to a variable?
Message ID:
Part of one of XS API (let's say foo()) goes:

  if (items == 1 && ST(0) == &PL_sv_undef)) { ... }

if that API is called as:


then the if condition is true. However if I do:

   $x = undef;

it's false, i.e. ST(0) is no longer == &PL_sv_undef. I did a quick check with

% perl -le 'use Devel::Peek; Dump undef; $x = undef; Dump $x'
SV = NULL(0x0) at 0x804c6e4
   REFCNT = 2147483624
SV = NULL(0x0) at 0x8065690
   REFCNT = 1
   FLAGS = ()

which are different. And I've checked the C addresses, passing undef, gives 
the same address as &PL_sv_undef, passing $x = undef, gives a different 
address. It makes sense to me since in the latter case we have a real sv with 
its own address, in the previous case we have a shared sv which always has the 
same address.

So how do I check in C whether the passed variable (or a random sv) is undef 
or not if comparing to &PL_sv_undef doesn't work? am I missing some obvious 
RTFM section? I've read: 'perlguts:=head2 AVs, HVs and undefined values'
but it doesn't seem to be related. There were many other references to undef 
in the perl manpages, but I didn't find anything useful.


Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About