diff options
-rw-r--r-- | op.c | 5 | ||||
-rw-r--r-- | t/op/attrs.t | 21 |
2 files changed, 26 insertions, 0 deletions
@@ -8662,6 +8662,11 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, PL_compcv = NULL; goto done; } + + /* don't copy new BEGIN CV to old BEGIN CV - RT #129099 */ + if (name && *name == 'B' && strEQ(name, "BEGIN")) + cv = NULL; + if (cv) { /* must reuse cv if autoloaded */ /* transfer PL_compcv to cv */ if (block diff --git a/t/op/attrs.t b/t/op/attrs.t index 23b00cadd5..318a9d6f4a 100644 --- a/t/op/attrs.t +++ b/t/op/attrs.t @@ -447,4 +447,25 @@ package P126257 { ::is $@, "", "RT 126257 sub"; } +# RT #129099 +# Setting an attribute on a BEGIN prototype causes +# BEGIN { require "attributes"; ... } +# to be compiled, which caused problems with ops being prematurely +# freed when CvSTART was transferred from the old BEGIN to the new BEGIN + +is runperl( + prog => 'package Foo; sub MODIFY_CODE_ATTRIBUTES {()} ' + . 'sub BEGIN :Foo; print q{OK}', + stderr => 1, + ), + "OK", + 'RT #129099 BEGIN'; +is runperl( + prog => 'package Foo; sub MODIFY_CODE_ATTRIBUTES {()} ' + . 'no warnings q{prototype}; sub BEGIN() :Foo; print q{OK}', + stderr => 1, + ), + "OK", + 'RT #129099 BEGIN()'; + done_testing(); |