[perl #97980] Stop tied() from returning a copy
authorFather Chrysostomos <sprout@cpan.org>
Sun, 27 Nov 2011 02:17:45 +0000 (18:17 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 27 Nov 2011 03:43:32 +0000 (19:43 -0800)
Now tied() returns the actual scalar used to hold the tie object,
so one can write weaken(tied $foo).

pp_sys.c
t/op/tie.t

index cc8b099..78a51ae 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -973,10 +973,7 @@ PP(pp_tied)
        RETPUSHUNDEF;
 
     if ((mg = SvTIED_mg(sv, how))) {
-       SV *osv = SvTIED_obj(sv, mg);
-       if (osv == mg->mg_obj)
-           osv = sv_mortalcopy(osv);
-       PUSHs(osv);
+       PUSHs(SvTIED_obj(sv, mg));
        RETURN;
     }
     RETPUSHUNDEF;
index b6567fc..887fa96 100644 (file)
@@ -1180,3 +1180,11 @@ fetching
 before at - line 8.
 fetching
 after at - line 10.
+########
+
+# tied returns same value as tie
+sub TIESCALAR{bless[]}
+$tyre = \tie $tied, "";
+print "ok\n" if \tied $tied == $tyre;
+EXPECT
+ok