summaryrefslogtreecommitdiff
path: root/regnodes.h
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2013-03-25 23:23:40 +0100
committerYves Orton <demerphq@gmail.com>2013-03-27 08:38:00 +0100
commitdbc200c5a1d3ae1d9360435a384c19883bf5f4f6 (patch)
tree2312197f897140b952835ad4d7864c03d9fcd791 /regnodes.h
parentc9d98c4e542a0779fb34f107a15def6ed7ff3f98 (diff)
downloadperl-dbc200c5a1d3ae1d9360435a384c19883bf5f4f6.tar.gz
rework split() special case interaction with regex engine
This patch resolves several issues at once. The parts are sufficiently interconnected that it is hard to break it down into smaller commits. The tickets open for these issues are: RT #94490 - split and constant folding RT #116086 - split "\x20" doesn't work as documented It additionally corrects some issues with cached regexes that were exposed by the split changes (and applied to them). It effectively reverts 5255171e6cd0accee6f76ea2980e32b3b5b8e171 and cccd1425414e6518c1fc8b7bcaccfb119320c513. Prior to this patch the special RXf_SKIPWHITE behavior of split(" ", $thing) was only available if Perl could resolve the first argument to split at compile time, meaning under various arcane situations. This manifested as oddities like my $delim = $cond ? " " : qr/\s+/; split $delim, $string; and split $cond ? " ", qr/\s+/, $string not behaving the same as: ($cond ? split(" ", $string) : split(/\s+/, $string)) which isn't very convenient. This patch changes this by adding a new flag to the op_pmflags, PMf_SPLIT which enables pp_regcomp() to know whether it was called as part of split, which allows the RXf_SPLIT to be passed into run time regex compilation. We also preserve the original flags so pattern caching works properly, by adding a new property to the regexp structure, "compflags", and related macros for accessing it. We preserve the original flags passed into the compilation process, so we can compare when we are trying to decide if we need to recompile. Note that this essentially the opposite fix from the one applied originally to fix #94490 in 5255171e6cd0accee6f76ea2980e32b3b5b8e171. The reverted patch was meant to make: split( 0 || " ", $thing ) #1 consistent with my $x=0; split( $x || " ", $thing ) #2 and not with split( " ", $thing ) #3 This was reverted because it broke C<split("\x{20}", $thing)>, and because one might argue that is not that #1 does the wrong thing, but rather that the behavior of #2 that is wrong. In other words we might expect that all three should behave the same as #3, and that instead of "fixing" the behavior of #1 to be like #2, we should really fix the behavior of #2 to behave like #3. (Which is what we did.) Also, it doesn't make sense to move the special case detection logic further from the regex engine. We really want the regex engine to decide this stuff itself, otherwise split " ", ... wouldn't work properly with an alternate engine. (Imagine we add a special regexp meta pattern that behaves the same as " " does in a split /.../. For instance we might make split /(*SPLITWHITE)/ trigger the same behavior as split " ". The other major change as result of this patch is it effectively reverts commit cccd1425414e6518c1fc8b7bcaccfb119320c513, which was intended to get rid of RXf_SPLIT and RXf_SKIPWHITE, which and free up bits in the regex flags structure. But we dont want to get rid of these vars, and it turns out that RXf_SEEN_LOOKBEHIND is used only in the same situation as the new RXf_MODIFIES_VARS. So I have renamed RXf_SEEN_LOOKBEHIND to RXf_NO_INPLACE_SUBST, and then instead of using two vars we use only the one. Which in turn allows RXf_SPLIT and RXf_SKIPWHITE to have their bits back.
Diffstat (limited to 'regnodes.h')
-rw-r--r--regnodes.h10
1 files changed, 5 insertions, 5 deletions
diff --git a/regnodes.h b/regnodes.h
index fd2102e9ec..0caf86dd55 100644
--- a/regnodes.h
+++ b/regnodes.h
@@ -650,7 +650,7 @@ EXTCONST char * const PL_reg_name[] = {
EXTCONST char * PL_reg_extflags_name[];
#else
EXTCONST char * const PL_reg_extflags_name[] = {
- /* Bits in extflags defined: 11011111111111111111111011111111 */
+ /* Bits in extflags defined: 11111110111111111111111111111111 */
"MULTILINE", /* 0x00000001 */
"SINGLELINE", /* 0x00000002 */
"FOLD", /* 0x00000004 */
@@ -659,14 +659,14 @@ EXTCONST char * const PL_reg_extflags_name[] = {
"CHARSET0", /* 0x00000020 : "CHARSET" - 0x000000e0 */
"CHARSET1", /* 0x00000040 : "CHARSET" - 0x000000e0 */
"CHARSET2", /* 0x00000080 : "CHARSET" - 0x000000e0 */
- "UNUSED_BIT_8", /* 0x00000100 */
+ "SPLIT", /* 0x00000100 */
"ANCH_BOL", /* 0x00000200 */
"ANCH_MBOL", /* 0x00000400 */
"ANCH_SBOL", /* 0x00000800 */
"ANCH_GPOS", /* 0x00001000 */
"GPOS_SEEN", /* 0x00002000 */
"GPOS_FLOAT", /* 0x00004000 */
- "LOOKBEHIND_SEEN", /* 0x00008000 */
+ "NO_INPLACE_SUBST", /* 0x00008000 */
"EVAL_SEEN", /* 0x00010000 */
"CANY_SEEN", /* 0x00020000 */
"NOSCAN", /* 0x00040000 */
@@ -675,12 +675,12 @@ EXTCONST char * const PL_reg_extflags_name[] = {
"USE_INTUIT_NOML", /* 0x00200000 */
"USE_INTUIT_ML", /* 0x00400000 */
"INTUIT_TAIL", /* 0x00800000 */
- "MODIFIES_VARS", /* 0x01000000 */
+ "UNUSED_BIT_24", /* 0x01000000 */
"COPY_DONE", /* 0x02000000 */
"TAINTED_SEEN", /* 0x04000000 */
"TAINTED", /* 0x08000000 */
"START_ONLY", /* 0x10000000 */
- "UNUSED_BIT_29", /* 0x20000000 */
+ "SKIPWHITE", /* 0x20000000 */
"WHITE", /* 0x40000000 */
"NULL", /* 0x80000000 */
};