From: Stas Bekman <stas@stason.org>
Date: Thu, 27 May 2004 11:25:08 +0000 (-0700)
Subject: Re: undef loses it magicness when assigned to a variable?
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9adebda4fef8cbc5965f9327c10fca15b814f305;p=p5sagit%2Fp5-mst-13.2.git

Re: undef loses it magicness when assigned to a variable?
Message-ID: <40B63284.5040203@stason.org>

p4raw-id: //depot/perl@22853
---

diff --git a/pod/perlapi.pod b/pod/perlapi.pod
index 27daa64..d1ae530 100644
--- a/pod/perlapi.pod
+++ b/pod/perlapi.pod
@@ -3196,7 +3196,8 @@ Found in file sv.h
 
 =item SvOK
 
-Returns a boolean indicating whether the value is an SV.
+Returns a boolean indicating whether the value is an SV. It also tells
+whether the value is defined or not.
 
 	bool	SvOK(SV* sv)
 
diff --git a/pod/perlguts.pod b/pod/perlguts.pod
index 9932b37..99c79d0 100644
--- a/pod/perlguts.pod
+++ b/pod/perlguts.pod
@@ -201,9 +201,22 @@ you can call:
     SvOK(SV*)
 
 The scalar C<undef> value is stored in an SV instance called C<PL_sv_undef>.
-Its address can be used whenever an C<SV*> is needed.
-However, you have to be careful when using C<&PL_sv_undef> as a value in AVs
-or HVs (see L<AVs, HVs and undefined values>).
+
+Its address can be used whenever an C<SV*> is needed. Make sure that
+you don't try to compare a random sv with C<&PL_sv_undef>. For example
+when interfacing Perl code, it'll work correctly for:
+
+  foo(undef);
+
+But won't work when called as:
+
+  $x = undef;
+  foo($x);
+
+So to repeat always use SvOK() to check whether an sv is defined.
+
+Also you have to be careful when using C<&PL_sv_undef> as a value in
+AVs or HVs (see L<AVs, HVs and undefined values>).
 
 There are also the two values C<PL_sv_yes> and C<PL_sv_no>, which contain
 boolean TRUE and FALSE values, respectively.  Like C<PL_sv_undef>, their
diff --git a/sv.h b/sv.h
index fab44eb..4edd87f 100644
--- a/sv.h
+++ b/sv.h
@@ -410,7 +410,8 @@ double.  Checks the B<private> setting.  Use C<SvNIOK>.
 Unsets the NV/IV status of an SV.
 
 =for apidoc Am|bool|SvOK|SV* sv
-Returns a boolean indicating whether the value is an SV.
+Returns a boolean indicating whether the value is an SV. It also tells
+whether the value is defined or not.
 
 =for apidoc Am|bool|SvIOKp|SV* sv
 Returns a boolean indicating whether the SV contains an integer.  Checks