From 07e0e3d17b524760dfc48c29ff5b7b71a2bdd1b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branislav=20Zahradn=C3=ADk?= Date: Sat, 31 May 2025 11:26:14 +0200 Subject: [PATCH 1/3] [op.c] Break fragile long-distance dependency on keyword list order Perl_coresub_op generating OPs for __FILE__, __LINE__, and __PACKAGE__ keywords relied on the exact order of their codes, introducing a dependency between parser and runtime by using magic transformation of keyword code to index into the return list of `OP_CALLER`. --- op.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/op.c b/op.c index f616532c491c..c2a9514425fb 100644 --- a/op.c +++ b/op.c @@ -6081,7 +6081,7 @@ Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last) ? 2 /* Otherwise, minimum of 2 hex digits */\ : NUM_HEX_CHARS(num))))))) -/* To make evident, Configure with `-DDEBUGGING`, build, run +/* To make evident, Configure with `-DDEBUGGING`, build, run * `./perl -Ilib -Dy t/op/tr.t` */ void @@ -16048,14 +16048,22 @@ Perl_coresub_op(pTHX_ SV * const coreargssv, const int code, PERL_ARGS_ASSERT_CORESUB_OP; switch(opnum) { - case 0: + case 0: { + int caller_index = -1; + switch (-code) { + case (KEY___PACKAGE__): { caller_index = 0; break; } /* (caller)[0] */ + case (KEY___FILE__): { caller_index = 1; break; } /* (caller)[1] */ + case (KEY___LINE__): { caller_index = 2; break; } /* (caller)[2] */ + } + return op_append_elem(OP_LINESEQ, argop, newSLICEOP(0, - newSVOP(OP_CONST, 0, newSViv(-code % 3)), + newSVOP(OP_CONST, 0, newSViv(caller_index)), newOP(OP_CALLER,0) ) ); + } case OP_EACH: case OP_KEYS: case OP_VALUES: From 1e55bcb72c1b4cc57827cd9ef96836200843da16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branislav=20Zahradn=C3=ADk?= Date: Sat, 31 May 2025 11:43:52 +0200 Subject: [PATCH 2/3] [regen/keywords] Remove obsoleted comment --- regen/keywords.pl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/regen/keywords.pl b/regen/keywords.pl index 26ccf515ef2e..4bcd1a0f0994 100755 --- a/regen/keywords.pl +++ b/regen/keywords.pl @@ -114,10 +114,6 @@ END read_only_bottom_close_and_rename($_, [$0]) foreach $c, $h; - -# coresub_op in op.c expects __FILE__, __LINE__ and __PACKAGE__ to be the -# first three. - __END__ NULL From 02a751611139991fe8e6e5d7937af6428ad4804e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branislav=20Zahradn=C3=ADk?= Date: Sat, 31 May 2025 11:47:46 +0200 Subject: [PATCH 3/3] [regen/keywords] Order keywords alphabetically --- keywords.c | 2 +- keywords.h | 22 +++++++++++----------- regen/keywords.pl | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/keywords.c b/keywords.c index 1b1fcc24943e..52e0030697b3 100644 --- a/keywords.c +++ b/keywords.c @@ -3590,5 +3590,5 @@ Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords) } /* Generated from: - * cc0991530edda2eb87e845d9347acc0f8d2debabab27608ef65ebd2b8d221c08 regen/keywords.pl + * b80b258f40fffe7f5874ff4ba9d6a8747490098e37de73bc4c0e681789f273a6 ./regen/keywords.pl * ex: set ro ft=c: */ diff --git a/keywords.h b/keywords.h index b3f5ec4244ce..a262b5a2a11d 100644 --- a/keywords.h +++ b/keywords.h @@ -14,21 +14,21 @@ */ #define KEY_NULL 0 -#define KEY___FILE__ 1 -#define KEY___LINE__ 2 -#define KEY___PACKAGE__ 3 -#define KEY___CLASS__ 4 -#define KEY___DATA__ 5 -#define KEY___END__ 6 +#define KEY___CLASS__ 1 +#define KEY___DATA__ 2 +#define KEY___END__ 3 +#define KEY___FILE__ 4 +#define KEY___LINE__ 5 +#define KEY___PACKAGE__ 6 #define KEY___SUB__ 7 #define KEY_ADJUST 8 #define KEY_AUTOLOAD 9 #define KEY_BEGIN 10 -#define KEY_UNITCHECK 11 +#define KEY_CHECK 11 #define KEY_DESTROY 12 #define KEY_END 13 #define KEY_INIT 14 -#define KEY_CHECK 15 +#define KEY_UNITCHECK 15 #define KEY_abs 16 #define KEY_accept 17 #define KEY_alarm 18 @@ -254,8 +254,8 @@ #define KEY_time 238 #define KEY_times 239 #define KEY_tr 240 -#define KEY_try 241 -#define KEY_truncate 242 +#define KEY_truncate 241 +#define KEY_try 242 #define KEY_uc 243 #define KEY_ucfirst 244 #define KEY_umask 245 @@ -282,5 +282,5 @@ #define KEY_y 266 /* Generated from: - * cc0991530edda2eb87e845d9347acc0f8d2debabab27608ef65ebd2b8d221c08 regen/keywords.pl + * b80b258f40fffe7f5874ff4ba9d6a8747490098e37de73bc4c0e681789f273a6 ./regen/keywords.pl * ex: set ro ft=c: */ diff --git a/regen/keywords.pl b/regen/keywords.pl index 4bcd1a0f0994..45917561ff26 100755 --- a/regen/keywords.pl +++ b/regen/keywords.pl @@ -117,21 +117,21 @@ END __END__ NULL --__FILE__ --__LINE__ --__PACKAGE__ -__CLASS__ +__DATA__ +__END__ +-__FILE__ +-__LINE__ +-__PACKAGE__ -__SUB__ +ADJUST +AUTOLOAD +BEGIN -+UNITCHECK ++CHECK +DESTROY +END +INIT -+CHECK ++UNITCHECK -abs -accept -alarm @@ -357,8 +357,8 @@ END -time -times +tr -+try -truncate ++try -uc -ucfirst -umask