Package: perl
Version: 5.8.8-6.1

        I recently discovered that Devel::Peek's SvREFCNT, SvREFCNT_inc
and SvREFCNT_dec functions are not as flexible as the XS functions that
they wrap.  In XS where you wish to get the reference count of an hash
your HV * pointer will cast to an SV * when passed as an argument to
SvREFCNT().  In Perl using Devel::Peek:SvREFCNT(%m) does not return the
reference count of %m, but rather treats %m as a list of arguments to
the function causing a runtime error.  I believe the intent of the code was
to return the reference count of the parameter passed and the difference
between Perl Prototypes and C casting was overlooked.
        A small patch (attached) will extend these three functions to
work on any perl variable type.  This could break code in cases where
users expect an array of one member passed to these functions to operate
on that only member of the array, but for all other data types (and
arrays of any other length) these functions currently croak.  Possibly a
new family of functions is warranted to maintain reverse compatibility
in the single element array case in the existing functions, but it is
not my place to make that judgement.
                                                Thanks,
                                                Robert Stone
diff -Naur perl-5.8.8.deborig/ext/Devel/Peek/Peek.xs 
perl-5.8.8/ext/Devel/Peek/Peek.xs
--- perl-5.8.8.deborig/ext/Devel/Peek/Peek.xs   2005-06-07 09:27:36.000000000 
-0700
+++ perl-5.8.8/ext/Devel/Peek/Peek.xs   2006-11-30 15:49:39.837153699 -0800
@@ -383,15 +383,22 @@
 I32
 SvREFCNT(sv)
 SV *   sv
+PROTOTYPE: [EMAIL PROTECTED]&*]
+PPCODE:
+{
+    RETVAL = SvREFCNT(SvRV(sv)) - 1; // -1 because our ref doesn't count
+    PUSHi(RETVAL);
+}
 
 # PPCODE needed since otherwise sv_2mortal is inserted that will kill the 
value.
 
 SV *
 SvREFCNT_inc(sv)
 SV *   sv
+PROTOTYPE: [EMAIL PROTECTED]&*]
 PPCODE:
 {
-    RETVAL = SvREFCNT_inc(sv);
+    RETVAL = SvREFCNT_inc(SvRV(sv));
     PUSHs(RETVAL);
 }
 
@@ -400,9 +407,10 @@
 void
 SvREFCNT_dec(sv)
 SV *   sv
+PROTOTYPE: [EMAIL PROTECTED]&*]
 PPCODE:
 {
-    SvREFCNT_dec(sv);
+    SvREFCNT_dec(SvRV(sv));
     PUSHs(sv);
 }
 

Reply via email to