Skip to content

Commit 851c968

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 dddbfc6 commit 851c968

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
@@ -11717,11 +11717,17 @@ S_process_special_blocks(pTHX_ I32 floor, const char *const fullname,
1171711717

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

0 commit comments

Comments
 (0)