develooper Front page | perl.perl5.changes | Postings from November 2010

[perl.git] branch blead, updated. v5.13.7-115-g75bd28c

From:
Father Chrysostomos
Date:
November 26, 2010 09:40
Subject:
[perl.git] branch blead, updated. v5.13.7-115-g75bd28c
Message ID:
E1PM2H8-0001Km-00@camel.ams6.corp.booking.com
In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/75bd28cfd597653e1169cbeb4920b7ba42eb8503?hp=abf9167d3fff002ddaed53abb44d638387bca978>

- Log -----------------------------------------------------------------
commit 75bd28cfd597653e1169cbeb4920b7ba42eb8503
Author: Father Chrysostomos <sprout@cpan.org>
Date:   Fri Nov 26 07:22:47 2010 -0800

    [perl #78634] Conflict in defining constant INIT
    
    When gv_init tries to turn a constant named INIT into a CV, the auto-
    matic special processing of the INIT ‘block’ kicks in, which removes
    the CV from the GV.
    
    This should not happen with gv_init, as $::{INIT} = \5 is supposed
    to be equivalent to *INIT = sub(){5}, which does not do that.
    
    This commit makes gv_init check for that, increase the reference
    count, and reassign the CV. It does not stop the CV from being called
    as a special block, but it is harmless to call a constant CV.
-----------------------------------------------------------------------

Summary of changes:
 gv.c          |    3 +++
 t/op/blocks.t |    6 +++++-
 2 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/gv.c b/gv.c
index b2cb5a4..f51839e 100644
--- a/gv.c
+++ b/gv.c
@@ -317,6 +317,9 @@ Perl_gv_init(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, int multi)
 
 	    /* newCONSTSUB takes ownership of the reference from us.  */
 	    cv = newCONSTSUB(stash, (name0 ? name0 : name), has_constant);
+	    /* In case op.c:S_process_special_blocks stole it: */
+	    if (!GvCV(gv))
+		GvCV(gv) = SvREFCNT_inc_simple_NN(cv);
 	    assert(GvCV(gv) == cv); /* newCONSTSUB should have set this */
 	    if (name0)
 		Safefree(name0);
diff --git a/t/op/blocks.t b/t/op/blocks.t
index 717be4c..8460371 100644
--- a/t/op/blocks.t
+++ b/t/op/blocks.t
@@ -6,7 +6,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan tests => 4;
+plan tests => 5;
 
 my @expect = qw(
 b1
@@ -109,3 +109,7 @@ SCRIPT3
 fresh_perl_is(<<'SCRIPT70614', "still here",{switches => [''], stdin => '', stderr => 1 },'eval-UNITCHECK-eval (bug 70614)');
 eval "UNITCHECK { eval 0 }"; print "still here";
 SCRIPT70614
+
+# [perl #78634] Make sure block names can be used as constants.
+use constant INIT => 5;
+::is INIT, 5, 'constant named after a special block';

--
Perl5 Master Repository



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About