Skip to content

Commit 1b218d2

Browse files
committed
we aren't going to run late INIT blocks, so don't save them
I was looking over #1674, where it was suggested that late INIT blocks behave like BEGIN, and Larry approved of that (25 years ago). But history has moved on, we have 25 years of code developed under the current behaviour of INIT and I suspect such a change is more likely to break existing code than fix anything. But looking at the code in S_process_special_blocks() we do still push the CV onto PL_initav, even though that CV will never be called. So don't push the CV if it's too late to call it.
1 parent 5b9aabc commit 1b218d2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

op.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11716,11 +11716,17 @@ S_process_special_blocks(pTHX_ I32 floor, const char *const fullname,
1171611716

1171711717
}
1171811718
#endif
11719-
if (PL_main_start)
11719+
if (PL_main_start) {
1172011720
/* diag_listed_as: Too late to run %s block */
1172111721
ck_warner(packWARN(WARN_VOID),
1172211722
"Too late to run INIT block");
11723-
Perl_av_create_and_push(aTHX_ &PL_initav, MUTABLE_SV(cv));
11723+
/* callers may touch cv after we return so don't
11724+
just release it.
11725+
*/
11726+
SAVEFREESV(cv);
11727+
}
11728+
else
11729+
Perl_av_create_and_push(aTHX_ &PL_initav, MUTABLE_SV(cv));
1172411730
}
1172511731
else
1172611732
return FALSE;

0 commit comments

Comments
 (0)