# OPs that store things other than flags in their op_private,
# like OP_AELEMFAST, won't be immediate children of a list.
#
- # OP_ENTERSUB can break this logic, so check for it.
+ # OP_ENTERSUB and OP_SPLIT can break this logic, so check for them.
# I suspect that open and exit can too.
+ # XXX This really needs to be rewritten to accept only those ops
+ # known to take the OPpLVAL_INTRO flag.
if (!($lop->private & (OPpLVAL_INTRO|OPpOUR_INTRO)
or $lop->name eq "undef")
- or $lop->name eq "entersub"
- or $lop->name eq "exit"
- or $lop->name eq "open")
+ or $lop->name =~ /^(?:entersub|exit|open|split)\z/)
{
$local = ""; # or not
last;
OP_PRIVATE_ONCE(op_delete, OPpSLICE, ",SLICE");
OP_PRIVATE_ONCE(op_exists, OPpEXISTS_SUB, ",EXISTS_SUB");
OP_PRIVATE_ONCE(op_die, OPpHUSH_VMSISH, ",HUSH_VMSISH");
+OP_PRIVATE_ONCE(op_split, OPpSPLIT_IMPLIM, ",IMPLIM");
struct op_private_by_op {
U16 op_type;
{OP_CONST, C_ARRAY_LENGTH(op_const_names), op_const_names },
{OP_SORT, C_ARRAY_LENGTH(op_sort_names), op_sort_names },
{OP_OPEN, C_ARRAY_LENGTH(op_open_names), op_open_names },
+ {OP_SPLIT, C_ARRAY_LENGTH(op_split_names), op_split_names },
{OP_BACKTICK, C_ARRAY_LENGTH(op_open_names), op_open_names }
};
$priv{$_}{128} = '+1' for qw "caller wantarray runcv";
@{$priv{coreargs}}{1,2,64,128} = ('DREF1','DREF2','$MOD','MARK');
$priv{$_}{128} = 'UTF' for qw "last redo next goto dump";
+$priv{split}{128} = 'IMPLIM';
our %hints; # used to display each COP's op_hints values
if (PL_modcount < RETURN_UNLIMITED_NUMBER &&
((LISTOP*)right)->op_last->op_type == OP_CONST)
{
- SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
+ SV ** const svp =
+ &((SVOP*)((LISTOP*)right)->op_last)->op_sv;
+ SV * const sv = *svp;
if (SvIOK(sv) && SvIVX(sv) == 0)
+ {
+ if (right->op_private & OPpSPLIT_IMPLIM) {
+ /* our own SV, created in ck_split */
+ SvREADONLY_off(sv);
sv_setiv(sv, PL_modcount+1);
+ }
+ else {
+ /* SV may belong to someone else */
+ SvREFCNT_dec(sv);
+ *svp = newSViv(PL_modcount+1);
+ }
+ }
}
}
}
scalar(kid);
if (!kid->op_sibling)
+ {
op_append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
+ o->op_private |= OPpSPLIT_IMPLIM;
+ }
assert(kid->op_sibling);
kid = kid->op_sibling;
/* Private for OP_(LAST|REDO|NEXT|GOTO|DUMP) */
#define OPpPV_IS_UTF8 128 /* label is in UTF8 */
+/* Private for OP_SPLIT */
+#define OPpSPLIT_IMPLIM 128 /* implicit limit */
+
struct op {
BASEOP
};
require './test.pl';
}
-plan tests => 118;
+plan tests => 119;
$FS = ':';
"RT #116086: split on string of single hex-20: first element is non-empty; multiple contiguous space characters";
}
+# Nasty interaction between split and use constant
+use constant nought => 0;
+($a,$b,$c) = split //, $foo, nought;
+is nought, 0, 'split does not mangle 0 constants';