summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Internals.t6
-rw-r--r--universal.c4
2 files changed, 7 insertions, 3 deletions
diff --git a/lib/Internals.t b/lib/Internals.t
index b0d5bda352..d6c2367436 100644
--- a/lib/Internals.t
+++ b/lib/Internals.t
@@ -7,7 +7,7 @@ BEGIN {
}
}
-use Test::More tests => 74;
+use Test::More tests => 76;
my $ro_err = qr/^Modification of a read-only value attempted/;
@@ -163,3 +163,7 @@ 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");
+
+Internals::SvREFCNT($foo, 1 );
diff --git a/universal.c b/universal.c
index d623a67ed3..0599e6795d 100644
--- a/universal.c
+++ b/universal.c
@@ -927,8 +927,8 @@ XS(XS_Internals_SvREFCNT) /* This is dangerous stuff. */
XSRETURN_IV(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) = SvIV(ST(1)) + 1; /* we free one ref on exit */
+ XSRETURN_IV(SvREFCNT(sv) - 1);
}
XSRETURN_UNDEF; /* Can't happen. */
}