[perl #36297] builtin attrs on subrutine declarations
authorSalvador FandiXXo <unknown>
Wed, 15 Jun 2005 13:54:53 +0000 (13:54 +0000)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Wed, 15 Jun 2005 14:40:40 +0000 (14:40 +0000)
From: Salvador "FandiXXo" (via RT) <perlbug-followup@perl.org>
Message-ID: <rt-3.0.11-36297-115797.8.75971493113916@perl.org>

p4raw-id: //depot/perl@24851

op.c
t/op/attrs.t

diff --git a/op.c b/op.c
index bfdd1aa..7b4f477 100644 (file)
--- a/op.c
+++ b/op.c
@@ -4232,6 +4232,7 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
     STRLEN ps_len;
     register CV *cv=0;
     SV *const_sv;
+    I32 gv_fetch_flags;
 
     const char * const name = o ? SvPVx_nolen_const(cSVOPo->op_sv) : Nullch;
 
@@ -4251,13 +4252,13 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
     }
     else
        aname = Nullch;
-    gv = name ? gv_fetchsv(cSVOPo->op_sv,
-                          GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
-                          SVt_PVCV)
+
+    gv_fetch_flags = (block || attrs || (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS))
+       ? GV_ADDMULTI : GV_ADDMULTI | GV_NOINIT;
+    gv = name ? gv_fetchsv(cSVOPo->op_sv, gv_fetch_flags, SVt_PVCV)
        : gv_fetchpv(aname ? aname
                     : (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"),
-                    GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
-                    SVt_PVCV);
+                    gv_fetch_flags, SVt_PVCV);
 
     if (o)
        SAVEFREEOP(o);
index 2169e3c..10e2c24 100644 (file)
@@ -106,6 +106,11 @@ is ref($thunk), "Z";
 @attrs = eval 'attributes::get $thunk';
 is "@attrs", "locked method Z";
 
+# Test attributes on predeclared subroutines:
+eval 'package A; sub PS : lvalue';
+@attrs = eval 'attributes::get \&A::PS';
+is "@attrs", "lvalue";
+
 # Test ability to modify existing sub's (or XSUB's) attributes.
 eval 'package A; sub X { $_[0] } sub X : lvalue';
 @attrs = eval 'attributes::get \&A::X';