From 830748013f81bcc28d145baf4024efd1b6537704 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Mon, 25 Oct 2010 12:28:33 -0700 Subject: Make untie check the FAKE flag on globs This allows untie($scalar) to untie the scalar if the last assigned or returned happened to be a typeglob. --- pp_sys.c | 2 +- t/op/tie.t | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pp_sys.c b/pp_sys.c index 7fa9f02e31..2497ec2ce1 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -903,7 +903,7 @@ PP(pp_untie) const char how = (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV) ? PERL_MAGIC_tied : PERL_MAGIC_tiedscalar; - if (isGV_with_GP(sv) && !(sv = MUTABLE_SV(GvIOp(sv)))) + if (isGV_with_GP(sv) && !SvFAKE(sv) && !(sv = MUTABLE_SV(GvIOp(sv)))) RETPUSHYES; if ((mg = SvTIED_mg(sv, how))) { diff --git a/t/op/tie.t b/t/op/tie.t index 5acd9a9db0..6bad251d14 100644 --- a/t/op/tie.t +++ b/t/op/tie.t @@ -955,12 +955,20 @@ main f ######## -# tie $glob_copy vs tie *$glob_copy -sub TIESCALAR { print "TIESCALAR\n" } -sub TIEHANDLE{ print "TIEHANDLE\n" } +# (un)tie $glob_copy vs (un)tie *$glob_copy +sub TIESCALAR { print "TIESCALAR\n"; bless [] } +sub TIEHANDLE{ print "TIEHANDLE\n"; bless [] } +sub FETCH { print "never called\n" } $f = *foo; tie *$f, ""; tie $f, ""; +untie $f; +print "ok 1\n" if !tied $f; +() = $f; # should not call FETCH +untie *$f; +print "ok 2\n" if !tied *foo; EXPECT TIEHANDLE TIESCALAR +ok 1 +ok 2 -- cgit v1.2.1