are you SvOK?

geoff on 2004-03-10T07:59:59

it turns out a bug (that I introduced) in mod_perl 1.0 core could be boiled down to this simple XS:

RETVAL = Nullsv;
                                                                                                                             
if (! SvOK(RETVAL)) {
  ...
}


as it turns out, Nullsv really expands to

#define Nullsv Null(SV*)


then to

#define Null(type) ((type)NULL)


now, maybe it's obvious to the perl core gurus, but I never would have expected SvOK not to protect against situations like these, especially while SvTRUE is DWIMmy. but that's just me.


Didn't know it either

ethan on 2004-03-10T09:04:18

As a matter of fact, I always used SvOK to check that an SV is non-NULL, oups. Whereas I only used SvTRUE after I tested for nun-NULLness (with the help of SvOK of course:-).

A patch to SvOK adding a NULL-check would probably be in order.

Re:Didn't know it either

rafael on 2004-03-10T09:09:51

I'd rather have a doc patch. Lots of macros don't check the nullness of their argument. As a matter of fact null SVs are quite rare compared to &PL_sv_undef or &PL_sv_no.

Re:Didn't know it either

geoff on 2004-03-10T18:05:22

--- sv.h        2004-03-07 09:06:01.000000000 -0800
+++ sv.h~       2004-03-10 10:03:23.000000000 -0800
@@ -428,7 +428,8 @@
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.  Does not protect
+against NULL SVs, such as those created by C<Nullsv>.

=for apidoc Am|bool|SvIOKp|SV* sv
Returns a boolean indicating whether the SV contains an integer.  Checks

SvOOK

sky on 2004-03-10T09:10:20

I prefer to be a SvOOK