In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/691f175822a5edda9dc7ba243d6c774254b9e225?hp=aeba7c97cf81cc1734fe47cebfeef2fa5e3d696f>
- Log ----------------------------------------------------------------- commit 691f175822a5edda9dc7ba243d6c774254b9e225 Author: Tony Cook <t...@develop-help.com> Date: Mon Nov 14 19:48:54 2011 +1100 Internals::SvREFCNT() now treats reference counts as unsigned Previously setting a large (negative in 32-bit signed) reference count would be returned as a positive number on 64-bit builds and negative on 32-bit builds. M lib/Internals.t M universal.c commit 28884311ae0933070ec776bd972da9d711a5184b Author: Tony Cook <t...@develop-help.com> Date: Mon Nov 14 19:30:17 2011 +1100 [rt #103222] make Internals::SvREFCNT set/get consistent M lib/Internals.t M universal.c ----------------------------------------------------------------------- Summary of changes: lib/Internals.t | 13 ++++++++++++- universal.c | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/Internals.t b/lib/Internals.t index b0d5bda..d3fce9c 100644 --- a/lib/Internals.t +++ b/lib/Internals.t @@ -7,7 +7,7 @@ BEGIN { } } -use Test::More tests => 74; +use Test::More tests => 78; my $ro_err = qr/^Modification of a read-only value attempted/; @@ -163,3 +163,14 @@ is( Internals::SvREFCNT($foo[2]), 1 ); is( Internals::SvREFCNT(%foo), 1 ); is( Internals::SvREFCNT($foo{foo}), 1 ); +is( Internals::SvREFCNT($foo, 2), 2, "update ref count"); +is( Internals::SvREFCNT($foo), 2, "check we got the stored value"); + +# the reference count is a U16, but was returned as an IV resulting in +# different values between 32 and 64-bit builds +my $big_count = 0xFFFFFFF0; # -16 32-bit signed +is( Internals::SvREFCNT($foo, $big_count), $big_count, + "set reference count unsigned"); +is( Internals::SvREFCNT($foo), $big_count, "reference count unsigned"); + +Internals::SvREFCNT($foo, 1 ); diff --git a/universal.c b/universal.c index d623a67..6ea0e29 100644 --- a/universal.c +++ b/universal.c @@ -924,11 +924,11 @@ XS(XS_Internals_SvREFCNT) /* This is dangerous stuff. */ sv = SvRV(svz); if (items == 1) - XSRETURN_IV(SvREFCNT(sv) - 1); /* Minus the ref created for us. */ + XSRETURN_UV(SvREFCNT(sv) - 1); /* Minus the ref created for us. */ else if (items == 2) { /* I hope you really know what you are doing. */ - SvREFCNT(sv) = SvIV(ST(1)); - XSRETURN_IV(SvREFCNT(sv)); + SvREFCNT(sv) = SvUV(ST(1)) + 1; /* we free one ref on exit */ + XSRETURN_UV(SvREFCNT(sv) - 1); } XSRETURN_UNDEF; /* Can't happen. */ } -- Perl5 Master Repository