From 61dbb99a522b2949bb5b65d33183104796a3c272 Mon Sep 17 00:00:00 2001 From: Salvador FandiXXo Date: Wed, 15 Jun 2005 13:54:53 +0000 Subject: [PATCH] [perl #36297] builtin attrs on subrutine declarations From: Salvador "FandiXXo" (via RT) Message-ID: p4raw-id: //depot/perl@24851 --- op.c | 11 ++++++----- t/op/attrs.t | 5 +++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/op.c b/op.c index bfdd1aa..7b4f477 100644 --- 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); diff --git a/t/op/attrs.t b/t/op/attrs.t index 2169e3c..10e2c24 100644 --- a/t/op/attrs.t +++ b/t/op/attrs.t @@ -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'; -- 2.7.4