Skip to content

Commit b6dcc2d

Browse files
committed
Issue #19350: Revert op.c change from 2a98b8c
This reverts the op.c change from "newSVpvn_flags().. is more efficient than sv_2mortal(newSVpvn(..))" full commit id 2a98b8c For some reason the op.c change tickles a compiler bug. Various minor changes to the text result in this working as expected, and then other changes make it fail, etc. I was not able to work out why, the code as presented is not wrong, although it hides some stuff underneath. The expression is: newSVpvn_flags( PadnamePV(name)+1,PadnameLEN(name)-1, (PadnameUTF8(name)) ? SVf_UTF8|SVs_TEMP : SVs_TEMP ); Which should be the same as: sv_2mortal(newSVpvn_utf8( PadnamePV(name)+1,PadnameLEN(name)-1, PadnameUTF8(name) )); However for some reason the compiler does something different. An interesting subtlety is that PadnameUTF8() always returns 1. So you would think that it could be replaced by newSVpvn_flags( PadnamePV(name)+1,PadnameLEN(name)-1, SVf_UTF8|SVs_TEMP); but when I compile that it seems to randomly produce the right result or not. I tried various formulations of parenthesizing the arguments, reducing the ternary to its natural result (above) etc, and the compiler seemed to produce random results. The only formulation that reliably produced the correct results is the original one.
1 parent 8030c9e commit b6dcc2d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

op.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10962,9 +10962,12 @@ S_already_defined(pTHX_ CV *const cv, OP * const block, OP * const o,
1096210962
const line_t oldline = CopLINE(PL_curcop);
1096310963
SV *namesv = o
1096410964
? cSVOPo->op_sv
10965-
: newSVpvn_flags( PadnamePV(name)+1,PadnameLEN(name)-1,
10966-
(PadnameUTF8(name)) ? SVf_UTF8|SVs_TEMP : SVs_TEMP
10967-
);
10965+
/* warning, DO NOT change this to use newSVpvn_flags()
10966+
as it will tickle a compiler bug - see patch that
10967+
introduced this comment */
10968+
: sv_2mortal(newSVpvn_utf8(
10969+
PadnamePV(name)+1,PadnameLEN(name)-1, PadnameUTF8(name)
10970+
));
1096810971
if (PL_parser && PL_parser->copline != NOLINE)
1096910972
/* This ensures that warnings are reported at the first
1097010973
line of a redefinition, not the last. */

0 commit comments

Comments
 (0)