This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
11 years agohandle /$not_utf8(?{...})$utf8/
David Mitchell [Fri, 18 Nov 2011 16:54:10 +0000 (16:54 +0000)]
handle /$not_utf8(?{...})$utf8/

the bit of code that concats the args into a pattern and at the same time
notes the start and end indices of the text of the code blocks, got it
wrong if the pattern got upgraded half way through concatting. So work out
in advance whether the string is likely to be utf8.

11 years agoinline S_get_pat_and_code_indices()
David Mitchell [Fri, 18 Nov 2011 16:30:17 +0000 (16:30 +0000)]
inline S_get_pat_and_code_indices()

Now that that static function is only used in one place, get rid of it.

11 years agofix dumping of PMf_CODELIST_PRIVATE flag
David Mitchell [Fri, 18 Nov 2011 15:21:27 +0000 (15:21 +0000)]
fix dumping of PMf_CODELIST_PRIVATE flag

11 years ago"don't recompile pattern" check: account for UTF8
David Mitchell [Fri, 18 Nov 2011 14:48:49 +0000 (14:48 +0000)]
"don't recompile pattern" check: account for UTF8

When recompiling a pattern (e.g. for $x (x,y) { /$x/ }),
it tests whether the new pattern string matches the old one, and if so
skips recompiling it. However, it doesn't take account of the UTF8ness of
the old and new patterns, so can falsely skip recompiling. Now fixed.

Also, there is a feature in re_op_compile() that may abort a pattern
compilation, upgrade the pattern to UTF8, then begin the compile again.
I've added a second check for whether the pattern matches the old pattern,
against the upgraded string. I can't see a way to test this, since its
just an optimisation.  Arguably I could add a BEGIN in an embedded code
block to see if it gets compiled twice, but soon I'm going to make it so
that embedded code blocks always get recompiled anyway.

11 years agore_op_compile: recalc code indexes on utf8 upgrade
David Mitchell [Fri, 18 Nov 2011 12:37:59 +0000 (12:37 +0000)]
re_op_compile: recalc code indexes on utf8 upgrade

As part of the compilation, we calculate the start and end positions
of the text of each literal code block within the pattern string.

The 'if pattern gets unexpected upgraded to UTF8, longjmp and restart
the compilation' mechanism, means that these indices can become invalid,
so if this happens, recalculate them. We do this by unrolling a call
to Perl_bytes_to_utf8(), which updates the indices at the same time that
it uopdtes the string.

Note that some of the new TODO test are actually passing, but this is for
the wrong reason. They're supposed to test for forced recompilation of
non-literal code blocks, even if the pattern string hasn't changed (which I
haven't implemented yet), but instead they're passing because the "don't
recomile if strings match" check isn't UTF8-aware. I'll fix this
(pre-existing) bug in the next commit.

11 years agoin re_op_compile, change code_blocks[].end offset
David Mitchell [Wed, 16 Nov 2011 10:42:36 +0000 (10:42 +0000)]
in re_op_compile, change code_blocks[].end  offset

previously, code_blocks[].end pointed to the char *after* the
end of (?{...}); make it instead the last char, i.e. ')'.

This will make the code for the next commit slightly easier.

11 years agopp_regcomp(): fix casting issue from prev commit
David Mitchell [Mon, 14 Nov 2011 16:21:42 +0000 (16:21 +0000)]
pp_regcomp(): fix casting issue from prev commit

11 years agoHandle literal code blocks in runtime regexes
David Mitchell [Sat, 12 Nov 2011 20:51:27 +0000 (20:51 +0000)]
Handle literal code blocks in runtime regexes

In the following types of regex:

      /$runtime(?{...})/
    qr/$runtime(?{...})/

make it so that the code block is compiled at the same time that the
surrounding code is compiled, then is incorporated, rather than
re-compiled, when the regex source is assembled and compiled at runtime.

This fixes a bunch of closure-related TODO tests.

Note that this still doesn't yet handle the cases where $runtime contains:
    $runtime = qr/...(?{...})/; # block will be stringified and recompiled
    $runtime = '(?{...})';      # block compiled the old way, with
                                  matching nesting of {} required

It also doesn't yet handle the case where the pattern getting compiled is
upgraded to utf8 and so is restarted.

Note that this is rather complex, because in something like

    $str =~ qr/$a(?{...})$b[1]/

there are four separate phases

* perl compile time; we also compile the code block at the same time,
  but within a separate anon CV (with a separate pad)

* at run time, we execute the code that generates the list of SVs
  (i.e. $a, $b[1] etc), but have to execute them within the context of the
  anon sub, since that's what they were compiled in; we then have to
  concat the arguments, while remembering which were literal code blocks;

* then qr// clones the compiled regex, and clones the anon CV at the same
  time;

* finally, the pattern is executed.

Through all this we have to ensure that the code blocks and associated
anon CV and pad get preserved and incorporated into the right places
for eventual use.

The changes in this commit build upon the work in the previous few
commits, and work by:

* at (perl) compile time, in pmruntime(), the anon CV (if any) associated
  with a qr//, as well as being referred to by the op_targ of the
  anoncode op, is also made the targ of the regcomp op;

* at pattern assembly and compile time,
    * Perl_re_op_compile() takes the list of SVs gathered by pp_regcomp(),
      along with the op tree (from op_code_list) that was used to generate
      those SVs (as well as containing the individual DO blocks), and
      concatenates them to get a final pattern source string, while
      noting the start and end positions of any literal (?{..})'s,
      and which block they must correspond to.

    * after compilation, pp_regcomp() then uses op_targ to locate
      the anon CV and store a pointer to it in the regex.

qr// instantiation and execution work unchanged.

11 years agore_op_compile(): rejig code-block handling code
David Mitchell [Fri, 11 Nov 2011 14:14:39 +0000 (14:14 +0000)]
re_op_compile(): rejig code-block handling code

In the code that keeps track of the start and end positions of each
code block, i.e. (?{....}), refactor it:

Rather than an array of STRLENs, with two slots to mark start and
positions, turn it into an array of structs; each holding the start and end
position, plus a pointer to the code block op. This will make it easier
when we shortly allow literal code from run-time patterns too.

Also rename some of the variables accordingly.

11 years agore_op_compile(): refactor some code
David Mitchell [Fri, 11 Nov 2011 11:31:37 +0000 (11:31 +0000)]
re_op_compile(): refactor some code

The 'scan the op tree looking for DO blocks' code will need to
be used in both the 'list of SV' and 'OP tree' cases, so hoist the code
up a level

11 years agoremove target from REGCOMP op
David Mitchell [Wed, 9 Nov 2011 14:38:26 +0000 (14:38 +0000)]
remove target from REGCOMP op

after the previous commit, the target is no longer needed;
so don't allocate it.

11 years agoMove bulk of pp_regcomp() into re_op_compile()
David Mitchell [Fri, 4 Nov 2011 10:12:20 +0000 (10:12 +0000)]
Move bulk of pp_regcomp() into re_op_compile()

When called, pp_regcomp() is presented with a list of SVs on the stack.
Previously, it would perform (amongst other things):
  * overloading those SVs;
  * concatenating them;
  * detection of bare /$qr/;
  * detection of unchanged pattern;
optionally followed by a call to the built-in or an external regexp
compiler.

Since we want to avoid premature concatenation (so that we can handle
/$runtime(?{...})/), move all these activities from pp_regcomp() into
re_op_compile().

This makes re_op_compile() a bit cumbersome, with a large arg list,
but I haven't found any way of only moving only a subset of the above.

Note that a side-effect of this is that qr-overloading now works for all
regex compilations, not just those reached via pp_regcomp(); in particular
this now invokes the qr method rather than the "" method if available:
/(??{ $overloaded_object })/

11 years agoadd PMf_CODELIST_PRIVATE flag
David Mitchell [Tue, 1 Nov 2011 16:50:16 +0000 (16:50 +0000)]
add PMf_CODELIST_PRIVATE flag

This indicates that the op_code_list field in a PMOP is "private";
that is, it points to a list of DO blocks that we don't own, and
shouldn't free, and whose pad may not match ours.

This will allow us to use the op_code_list field in the runtime case of
literal code, e.g. /$runtime(?{...})/ and qr/$runtime(?{...})/. Here, at
compile-time, we need to make the pre-compiled (?{..}) blocks available to
pp_regcomp, but the list containing those blocks is also the list that is
executed in the lead-up to executing pp_regcomp (while skipping the DO
blocks), so the code is already embedded, and doesn't need freeing.
Furthermore, in the qr// case, the code blocks are actually within a
different sub (an anon one) than the PMOP, so the pads won't match.

11 years agoremove private flag 1 from OP_REGCOMP
David Mitchell [Tue, 1 Nov 2011 13:57:50 +0000 (13:57 +0000)]
remove private flag 1 from OP_REGCOMP

When an OP_REGCOMP is hand-rolled, the op_private flags field is
set to 1. This has been so since 1993, but it is undocumented and appears
completely unused. So remove it.

11 years agoFix =~ $str_overloaded (5.10 regression)
Father Chrysostomos [Sat, 29 Oct 2011 20:40:06 +0000 (13:40 -0700)]
Fix =~ $str_overloaded (5.10 regression)

[ DAPM: I just cherry-picked the tests from this commit, since my own
  changes have already fixed this bug. FC's two commits:
      15d9c083b08647e489d279a1059b4f14a3df187b
      3e1022372a8200bc4c7354e0f588c7f71584a888
  were unrolled at the start of this branch since they clashed with my own
  stuff; this commit is re-adding the bits of those commits that are
  still needed: i.e. just the tests.
]

In 5.8.x, this code:

  use overload '""'=>sub { warn "stringify"; --$| ? "gonzo" : chr 256 };
  my $obj = bless\do{my $x};
  warn "$obj";
  print "match\n" if chr(256) =~ $obj;

prints

  stringify at - line 1.
  gonzo at - line 3.
  stringify at - line 1.
  match

which is to be expected.

In 5.10+, the stringification happens one extra time, causing a failed match:

  stringify at - line 1.
  gonzo at - line 3.
  stringify at - line 1.
  stringify at - line 1.

This logic in pp_regcomp is faulty:

    if (DO_UTF8(tmpstr)) {
assert (SvUTF8(tmpstr));
    } else if (SvUTF8(tmpstr)) {
... copy under ‘use bytes’...
    }
    else if (SvAMAGIC(tmpstr)) {
/* make a copy to avoid extra stringifies */
tmpstr = newSVpvn_flags(t, len, SVs_TEMP | SvUTF8(tmpstr));
    }

The SvAMAGIC check never happens when the UTF8 flag is on.

11 years agoadd volatile decl to fix previous commit
David Mitchell [Mon, 31 Oct 2011 12:10:26 +0000 (12:10 +0000)]
add volatile decl to fix previous commit

The previous commit changed the nature of the exp variable in
Perl_re_op_compile(), so it needs to be marked with VOL to work around
setjmp.

11 years agoPATCH: [perl #101940]: BBC Tk
Karl Williamson [Sat, 29 Oct 2011 17:20:40 +0000 (11:20 -0600)]
PATCH: [perl #101940]: BBC Tk

This commit that turned up this bug turns out merely exposes an
underlying problem that could be generated via other means.

regcomp.c was looking at the SvUTF8 flag on the input pattern before
doing an SvPV on it.  Generally the flag is considered not reliable
unless checked immediately after a SvPV.

I haven't been able to come up with a simple test case that reproduces
the bug.  I suspect that XS code is required to trigger it.

[ this is a re-application by davem of commit
  11951bcbfcaf4c260b0da0421e72fc80b4654f17 ]

11 years agoregcomp.c: Use no_mg for 2nd fetch of pattern
Karl Williamson [Sun, 30 Oct 2011 16:47:21 +0000 (16:47 +0000)]
regcomp.c: Use no_mg for 2nd fetch of pattern

The pattern could be tied, for example, and so only want to access it
once.  I couldn't come up with a test case that actually exercised this,
but I can think of future changes to regcomp that would.

[ this is a re-application by davem of commit
3e0b93e82af0f1a033bcdb918b413113f1d61cf0 ]

11 years agopp_regcomp: dopn't special-case n->1 arg folding
David Mitchell [Sun, 30 Oct 2011 12:35:13 +0000 (12:35 +0000)]
pp_regcomp: dopn't special-case n->1 arg folding

Currently, pp_regcomp() specially handles the case where the result of
concating all its args is a regexp. Change this so that this only occurs
if there is a single arg.

This means that if $a is an overloaded object whose concat op returns
a regexp, then /$a+/ no longer special-cases, and thus the returned regex
is now stringified and recompiled. This slight loss of efficiency in a
rare case is necessary to allow us to delay concating for as long as possible,

11 years agopp_regcomp: split overloading and concat tasks
David Mitchell [Wed, 26 Oct 2011 12:21:10 +0000 (13:21 +0100)]
pp_regcomp: split overloading and concat tasks

Make two passes through the list of args: first to apply
magic/overloading, and secondly to concatenate them. This will
shortly allow us to pass a processed, but unconcatenated list to
re_op_compile().

Also, simplify the code by treating the 1-arg case as an arg list
of length 1.  This also allows us to use the tryAMAGICregexp macro
in only one place, and thus to unroll and eliminate it.

11 years agochange re_op_compile() to take a list of SVs
David Mitchell [Wed, 26 Oct 2011 11:23:52 +0000 (12:23 +0100)]
change re_op_compile() to take a list of SVs

rather than passing a single SV string containing the pattern,
allow a list of SVs (plus count) to be passed. For the moment, only allow
that list to be one element long, but this will allow us to directly
pass in the list of SVs normally pre-processed into a single SV by
pp_regcomp.

11 years agofix for overload/stringfy and pp_regcomp
David Mitchell [Tue, 25 Oct 2011 14:42:44 +0000 (15:42 +0100)]
fix for overload/stringfy and pp_regcomp

(bug found by code inspection)

The code in pp_regcomp to make a mortal copy of the pattern string
in the case of overload or utf8+'use bytes', missed the case of overload
with utf8. Fix this and at the same time simplify the code.

11 years agounlink re_eval code blocks from op list
David Mitchell [Fri, 21 Oct 2011 14:00:47 +0000 (15:00 +0100)]
unlink re_eval code blocks from op list

In the list of ops generated by something like /abc(?{...})def/,

const(abc)
null/special
    ...
const(...)
const(def)

link the list, but skip the DO blocks. This means that for the runtime
case, we no longer need the temporary measure of deleting the DO blocks,
and it will facilitate the next step of handling literal code at runtime,
i.e. /$runtime(?{...})/.

11 years agoIn Perl_re_op_compile, make a var volatile
David Mitchell [Wed, 19 Oct 2011 10:49:40 +0000 (11:49 +0100)]
In Perl_re_op_compile, make a var volatile

This function includes a setjmp to allow for abort and retry if the
pattern getting compiled suddenly becomes UTF8. My recent changes to
it left one var generating the dreaded "warning: variable ‘pat’ might be
clobbered" warning. So declare it VOL to fix this.

11 years agomake qr/(?{})/ behave with closures
David Mitchell [Wed, 12 Oct 2011 13:01:50 +0000 (14:01 +0100)]
make qr/(?{})/ behave with closures

With this commit, qr// with a literal (compile-time) code block
will Do the Right Thing as regards closures and the scope of lexical vars;
in particular, the following now creates three regexes that match 1, 2
and 3:

    for my $i (0..2) {
        push @r, qr/^(??{$i})$/;
    }
    "1" =~ $r[1]; # matches

Previously, $i would be evaluated as undef in all 3 patterns.

This is achieved by wrapping the compilation of the pattern within a
new anonymous CV, which is then attached to the pattern. At run-time
pp_qr() clones the CV as well as copying the REGEXP; and when the code
block is executed, it does so using the pad of the cloned CV.
Which makes everything come out all right in the wash.

The CV is stored in a new field of the REGEXP, called qr_anoncv.

Note that run-time qr//s are still not fixed, e.g. qr/$foo(?{...})/;
nor is it yet fixed where the qr// is embedded within another pattern:
continuing with the code example from above,

    my $i = 99;
    "1"   =~ $r[1];    # bare qr:     matches: correct!
    "X99" =~ /X$r[1]/; # embedded qr: matches: whoops, it's still
       seeing the wrong $i

11 years agoIgnore code blocks within /[...]/
David Mitchell [Sat, 17 Sep 2011 11:55:29 +0000 (12:55 +0100)]
Ignore code blocks within /[...]/

Now that RE code blocks are being handled by the lexer rather than the RE
compiler, make sure that stuff like

    /[(?{]/

isn't mis-interpreted as the start of a code block.

11 years agomake recent re_eval changes compile under -Dmad
David Mitchell [Mon, 12 Sep 2011 13:32:11 +0000 (14:32 +0100)]
make recent re_eval changes compile under -Dmad

Note that this doesn't mean that MAD output is correct; I haven't tested
that. In particular, I have no idea when and how CURMAD() is supposed to
be used.

11 years agoMostly complete fix for literal /(?{..})/ blocks
David Mitchell [Thu, 25 Aug 2011 10:41:49 +0000 (11:41 +0100)]
Mostly complete fix for literal /(?{..})/ blocks

Change the way that code blocks in patterns are parsed and executed,
especially as regards lexical and scoping behaviour.

(Note that this fix only applies to literal code blocks appearing within
patterns: run-time patterns, and literals within qr//, are still done the
old broken way for now).

This change means that for literal /(?{..})/ and /(??{..})/:

* the code block is now fully parsed in the same pass as the surrounding
  code, which means that the compiler no longer just does a simplistic
  count of balancing {} to find the limits of the code block;
  i.e. stuff like /(?{  $x = "{" })/ now works (in the same way
  that subscripts in double quoted strings always have: "$a{'{'}" )

* Error and warning messages will now appear to emanate from the main body
  rather than an re_eval; e.g. the output from

    #!/usr/bin/perl
    /(?{ warn "boo" })/

has changed from

    boo at (re_eval 1) line 1.

to

    boo at /tmp/p line 2.

* scope and closures now behave as you might expect; for example

        for my $x (qw(a b c)) { "" =~ /(?{ print $x })/ }

  now prints "abc" rather than ""

* with recursion, it now finds the lexical within the appropriate depth
  of pad: this code now prints "012" rather than "000":

    sub recurse {
        my ($n) = @_;
        return if $n > 2;
        "" =~ /^(?{print $n})/;
        recurse($n+1);
    }
    recurse(0);

* an earlier fix that stopped 'my' declarations within code blocks causing
  crashes, required the accumulating of two SAVECOMPPADs on the stack for
  each iteration of the code block; this is no longer needed;

* UNITCHECK blocks within literal code blocks are now run as part of the
  main body of code (run-time code blocks still trigger an immediate
  call to the UNITCHECK block though)

This is all achieved by building upon the efforts of the commits which led
up to this; those altered the parser to parse literal code blocks
directly, but up until now those code blocks were discarded by
Perl_pmruntime and the block re-compiled using the original re_eval
mechanism. As of this commit, for the non-qr and non-runtime variants,
those code blocks are no longer thrown away. Instead:

* the LISTOP generated by the parser, which contains all the code
  blocks plus OP_CONSTs that collectively make up the literal pattern,
  is now stored in a new field in PMOPs, called op_code_list. For example
  in /A(?{BLOCK})C/, the listop stored in op_code_list looks like

    LIST
        PUSHMARK
        CONST['A']
        NULL/special (aka a DO block)
            BLOCK
        CONST['(?{BLOCK})']
        CONST['B']

* each of the code blocks has its last op set to null and is individually
  run through the peephole optimiser, so each one becomes a little
  self-contained block of code, rather than a list of blocks that run into
  each other;

* then in re_op_compile(), we concatenate the list of CONSTs to produce a
  string to be compiled, but at the same time we note any DO blocks and
  note the start and end positions of the corresponding CONST['(?{BLOCK})'];

* (if the current regex engine isn't the built-in perl one, then we just
  throw away the code blocks and pass the concatenated string to the engine)

* then during regex compilation, whenever we encounter a '(?{', we see if
  it matches the index of one of the pre-compiled blocks, and if so, we
  store a pointer to that block in an 'l' data slot, and use the end index
  to skip over the text of the code body. Conversely, if the index doesn't
  match, then we know that it's a run-time pattern and (for now), compile
  it in the old way.

* During execution, when an EVAL op is encountered, if data->what is 'l',
  then we just use the pad that was in effect when the pattern was called;
  i.e. we use the current pad slot of the currently executing CV that the
  pattern is embedded within.

11 years agoadd Perl_re_op_compile function
David Mitchell [Fri, 19 Aug 2011 11:10:01 +0000 (12:10 +0100)]
add Perl_re_op_compile function

Make Perl_re_compile() a thin wrapper around a new function,
Perl_re_op_compile(). This function can take either a string pattern or a
list of ops. Then make pmruntime() pass a list of ops directly to it, rather
concatenating all the consts into a single string and passing the const to
Perl_re_compile(). For now, Perl_re_op_compile just does the same: if its
passed an op tree rather than an SV, then it just concats the consts.

So this is is just the next step towards eventually allowing the regex
engine to use the ops directly.

11 years agoadd Perl_current_re_engine() function
David Mitchell [Wed, 17 Aug 2011 15:41:04 +0000 (16:41 +0100)]
add Perl_current_re_engine() function

Abstract out into a separate function the task of finding the current
in-scope regex engine ($^H{regex}). Currently this task is only done in
one place each for compile- and run-time, but shortly we'll need it in
other places too.

11 years agore_eval and closures: add lots of TODO tests
David Mitchell [Mon, 8 Aug 2011 16:56:10 +0000 (17:56 +0100)]
re_eval and closures: add lots of TODO tests

re_evals currently almost always do the wrong thing as regards what
lexical variable they refer to. This commit adds lots of TODO tests that
show what behaviour I think there should be. Note that because hardly any
of these tests pass yet, I haven't been able to verify whether they have
any subtle typos etc.

The basic philosophy behind these tests is:

* literal code is compiled once at compile-time and shares the same
  lexical environment as its surroundings; i.e.

    /A(?{..$x..})B/

  is like

    /A/ && do {..$x..} && /B/

* qr is treated as a closure: compiling once, but capturing its
  environment anew each time it is instantiated; i.e.

    for my $x (...) { push @r, qr/A(?{..$x..}B)/ }

  is like

    for my $x (...) { push @r, sub { /A/ && do {..$x..} && /B/ } }

* run-time code is recompiled each time the regex is compiled; literal
  code in the same expression isn't recompiled; i.e.

    $code = '(?{ BEGIN{$y++} })';
    for (1..3) { /(?{ BEGIN{$x++}})$code/ }
    # x==1, y==3

* an embedded qr is not stringified, so the qr retains its original
  lexical environment; i.e.

  $x = 1;
  { my $x = 2: $r = qr/(??{$x})/ }
  /A$r/; # matches A2, not A1

11 years agofix the descriptions for pregcomp/re_compile
David Mitchell [Mon, 1 Aug 2011 15:53:00 +0000 (16:53 +0100)]
fix the descriptions for pregcomp/re_compile

Some while ago most of the body of Perl_pregcomp was extracted out into
a new sub, Perl_re_compile, but the comments describing the function stayed
with pregcomp. Move them down to re_compile, since they mostly apply to
that sub now.

11 years agodisable lexing of (?{}) within \Q, \U etc
David Mitchell [Mon, 1 Aug 2011 11:40:32 +0000 (12:40 +0100)]
disable lexing of (?{}) within \Q, \U etc

when (?{..}) or (??{..}) is enclosed in one of the modifiers like \Q,
don't parse it; treat it as plain characters that are modified by \Q etc.
This means that any code blocks will be interpreted by the regexp compiler
rather than the lexer. This restores behaviour similar to 5.14 and
earlier, except that the (?{}) is *completely* uninterpreted by the lexer,
whereas 5.14 would skip  till matching {}.

11 years agoupdate diagnostics message
David Mitchell [Mon, 1 Aug 2011 11:06:00 +0000 (12:06 +0100)]
update diagnostics message

The description of the "Sequence (?{...}) not terminated with ')'" error
was cut and paste from another error without the text being updated!

11 years agomake re_evals be seen by the toker/parser
David Mitchell [Sat, 23 Jul 2011 20:29:02 +0000 (21:29 +0100)]
make re_evals be seen by the toker/parser

This commit is a first step to making the handling of (/(?{...})/ more sane.
But see the big proviso at the end.

Currently a patten like /a(?{...})b/ is uninterpreted by the lexer and
parser, and is instead passed as-is to the regex compiler, which is
responsible for ensuring that the embedded perl code is extracted and
compiled. The only thing the quoted string code in the lexer currently
does is to skip nested matched {}'s, in order to get to end of the code
block and restart looking for interpolated variables, \Q etc.

This commit makes the lexer smarter.

Consider the following pattern:

    /FOO(?{BLOCK})BAR$var/

This is currently tokenised as

    op_match
    (
    op_const["FOO(?{BLOCK})BAR"]
    ,
    $
    "var"
    )

Instead, tokenise it as:

    op_match
    (
    op_const["FOO"]
    ,
    DO
    {
    BLOCK
    ;
    }
    ,
    op_const["(?{BLOCK})"]
    ,
    op_const["BAR"]
    ,
    $
    "var"
    )

This means that BLOCK is itself tokenised and parsed. We also insert
a const into the stream to include the original source text of BLOCK so
that it's available for stringifying qr's etc.

Note that by allowing the lexer/parser direct access to BLOCK, we can now
handle things like
    /(?{"{"})/

This mechanism is similar to the way something like

    "abc $a[foo(q(]))] def"

is currently parsed: the double-quoted string handler in the lexer stops
at $a[, the 'foo(q(]))' is treated as perl code, then at the end control is
passed back to the string handler to handle the ' def'.

This commit includes a new error message:

    Sequence (?{...}) not terminated with ')'

since when control is passed back to the quoted-string handler, it expects
to find the ')' as the next char. This new error mostly replaces the old

    Sequence (?{...}) not terminated or not {}-balanced in regex

Big proviso:

This commit updates toke.c to recognise the embedded code, but doesn't
then do anything with it. The parser will pass both a compiled do block
and a const for each embedded (?{..}), and Perl_pmruntime just throws
away the do block and keeps the constant text instead which is passed to
the regex compiler. So currently each code block gets compiled twice (!)
with two sets of warnings etc. The next stage will be to pass these do
blocks to the regex compiler.

This commit is based on a patch I had originally worked up about 6 years
ago and has been sitting bit-rotting ever since.

11 years agocorrect comment about how strings are tokenised
David Mitchell [Fri, 22 Jul 2011 13:56:17 +0000 (14:56 +0100)]
correct comment about how strings are tokenised

The stuff about "foo\lbar" being tokenised as a list which you need to
apply join() to, was wrong; the tokeniser outputs the necessary concats
rather than commas.

11 years agoRevert 4 regex commits to ease rebasing
David Mitchell [Sun, 30 Oct 2011 16:12:02 +0000 (16:12 +0000)]
Revert 4 regex commits to ease rebasing

Revert "Remove some repeated code in pp_regcomp"
This reverts commit 3e1022372a8200bc4c7354e0f588c7f71584a888.

Revert "regcomp.c: Use no_mg for 2nd fetch of pattern"
This reverts commit 3e0b93e82af0f1a033bcdb918b413113f1d61cf0.
`
Revert "PATCH: [perl #101940]: BBC Tk"
This reverts commit 11951bcbfcaf4c260b0da0421e72fc80b4654f17.

Revert "Fix =~ $str_overloaded (5.10 regression)"
This reverts commit 15d9c083b08647e489d279a1059b4f14a3df187b.

These four recent commits on the blead branch overlap with work on the
re_eval branch. To make rebasing re_eval easier, revert them at the
beginning of the re_eval branch. Any remaining value will be re-added
later in the re_eval branch.

11 years agoRevert two commits that fix a VOL declaration.
David Mitchell [Sat, 12 Nov 2011 22:11:28 +0000 (22:11 +0000)]
Revert two commits that fix a VOL declaration.
This has also been done on my davem/re_eval branch,
and its easiest to revert these at the start of my branch

Revert "regcomp.c: Silence compiler warning about longjump"

This reverts commit 24efd69ba77ba76cd714519dccee88f45820d8b4.

Revert "Fix volatile declaration"

This reverts commit 4d6b28934825c9c735195140271a6f93f9c07348.

11 years agorevert a trailing whitespace removal
David Mitchell [Tue, 14 Feb 2012 17:25:32 +0000 (17:25 +0000)]
revert a trailing whitespace removal

this is to make rebasing easier. On one of the rebased commits
also removes this whitespace

11 years agoTemporarily revert some lib/overload.t tests
David Mitchell [Tue, 14 Feb 2012 16:20:14 +0000 (16:20 +0000)]
Temporarily revert some lib/overload.t tests

these accumulated from a few recent commits. Removing will make rebasing
easier.

11 years agoRevert two commits to make rebasing easier
David Mitchell [Tue, 14 Feb 2012 11:55:46 +0000 (11:55 +0000)]
Revert two commits to make rebasing easier

These two commits will be added back later after rebasing

    "[perl #108780] Make /foo$qr/ work under ‘no overloading’"

        37c07a4b201c9f799808d346817c4685e3e9002a.

    "regcomp.c: Silence valgrind warning"

        44bed85634c450533d59ae9e371037dde0101d51.

11 years agoTemporarily remove overload.t changes
David Mitchell [Mon, 4 Jun 2012 14:25:23 +0000 (15:25 +0100)]
Temporarily remove overload.t changes

undo commits done to lib/overload.t on the blead branch
between 2012/03/31 and 2012/06/04 to make rebasing the re_eval
branch easier. These changes will be re-applied at the end of the rebase

11 years agoUpdate List-Util to CPAN version 1.25
Chris 'BinGOs' Williams [Sun, 27 May 2012 21:19:38 +0000 (22:19 +0100)]
Update List-Util to CPAN version 1.25

  [DELTA]

1.25 -- Sat Mar 24 13:10:13 UTC 2012

  * Restore back-compat. to perl 5.6 (thanks to Zefram)

1.24 -- Thu Mar 22 18:10:10 UTC 2012

  * Update to 1.24 release version (no other changes since 1.23_04).

1.23_04 -- Sat Mar 10 00:16:16 UTC 2012

  * RT#72700 Fix off-by-two on string literal length

1.23_03 -- Tue Sep 14 10:09:59 CDT 2010

  * Min perl version supported for build is not 5.008
  * Dropped the pure-Perl implementation of both Scalar::- and List::Util.
  * RT#61118 Fix assumption in sum() that once magic, always magic

1.23_02 -- Tue Mar 30 11:09:15 CDT 2010

  * Fix first() and reduce() to check the callback first; &first(1) is now illigal. [gfx]
  * Fix reduce() to allow XSUB callbacks [gfx]
  * Fix first() to allow XSUB callbacks [gfx]
  * Resolve RT #55763: tainted() doesn't do SvGETMAGIC(sv) [gfx]
  * define CvISXSUB so older perl versions will still compile

1.23_01 -- Mon Mar 22 08:24:11 CDT 2010

  * Add failing tests; SVt_RV is not directly SvROK [gfx]
  * Implement openhandle() in XS (with extra tests) [gfx]
  * Modernize *.pm [gfx]
  * Modernize ListUtil.xs [gfx]
  * Add ppport.h [gfx]
  * Fix an overloading issue on sum(), and add tests for overloading [gfx]
  * Small tweaks for minstr()/maxstr() [gfx]
  * Optimize dualvar() [gfx]
  * Use sv_copypv() instead of SvPV() and sv_setpv() [gfx]
  * avoid non-portable warnings

11 years agoUse standard gcc names in config_H.gc64's CPPSTDIN/CPPRUN
Steve Hay [Tue, 12 Jun 2012 07:44:31 +0000 (08:44 +0100)]
Use standard gcc names in config_H.gc64's CPPSTDIN/CPPRUN

These canned defaults are not used in making miniperl.exe, after which the
real config.h will be generated with the correct values depending on the
compiler toolchain. This is just for sanity's sake to make the diff
between the .gc and .gc64 files clearer.

11 years agodon't override a user supplied prefix on Haiku-OS
Tony Cook [Tue, 12 Jun 2012 11:05:37 +0000 (11:05 +0000)]
don't override a user supplied prefix on Haiku-OS

11 years agoRequire space between regex and following alnum operator
Karl Williamson [Mon, 11 Jun 2012 17:48:04 +0000 (11:48 -0600)]
Require space between regex and following alnum operator

Not having such space has been deprecated since v5.14.0.

11 years agoop/eval.t: Change test
Karl Williamson [Mon, 11 Jun 2012 17:45:02 +0000 (11:45 -0600)]
op/eval.t: Change test

A future commit will change the output for this test, so use another one
that generates a straight syntax error.

11 years agoperldelta for RT #113584
Karl Williamson [Mon, 11 Jun 2012 16:35:49 +0000 (10:35 -0600)]
perldelta for RT #113584

11 years agoPATCH: [perl #113584] tr/// multiple transliterations
Karl Williamson [Mon, 11 Jun 2012 15:56:56 +0000 (09:56 -0600)]
PATCH: [perl #113584] tr/// multiple transliterations

Commit 4de6d205aeab9ec737ca35ba4eb61f37cebefc55 failed to take into
consideration tr///.

11 years agoreorganize perlcheat
H.Merijn Brand [Mon, 11 Jun 2012 10:57:36 +0000 (12:57 +0200)]
reorganize perlcheat

add FALSE/TRUE, \K, better named capture, remove links section,
unindent DEBUG

11 years agoFix typo in comment
Steve Hay [Mon, 11 Jun 2012 07:53:08 +0000 (08:53 +0100)]
Fix typo in comment

11 years agoCorrect the comment style of a couple of not #defined symbols
Steve Hay [Mon, 11 Jun 2012 07:52:20 +0000 (08:52 +0100)]
Correct the comment style of a couple of not #defined symbols

11 years agoTrailing whitespace removal
Steve Hay [Mon, 11 Jun 2012 07:50:54 +0000 (08:50 +0100)]
Trailing whitespace removal

11 years agoMinGW/gcc does have long long, even for 32-bit builds
Steve Hay [Mon, 11 Jun 2012 07:49:46 +0000 (08:49 +0100)]
MinGW/gcc does have long long, even for 32-bit builds

(It's already used for [iu]64type and [u]quadtype, just like __int64 is
used on 32-bit VC++ builds.)

Thanks to Sisyphus & kmx for the spot.

11 years agoInstall all include files on VMS.
Craig A. Berry [Sun, 10 Jun 2012 19:04:36 +0000 (14:04 -0500)]
Install all include files on VMS.

On most platforms, installperl copies *.h from the top-level source
directory to an appropriate installed location.  On VMS, we stage
everything to an archcore directory first and installperl copies
them from there.  Whether this is a good way to be doing things in
this day and age is questionable, but the more immediate problem is
that we have been (badly) maintaining our own list of what should
get staged in the archcore directory.  By my count, 5.16.0 shipped
with 18 of 69 include files missing.[1]  Ouch.

So this commit abolishes the separately-maintained, explicitly-named
list of include files and just copies all of them to the staging
directory, where installperl will pick them up.

[1] For folks counting at home, we have vmsish.h, which no one else
has, so that's why there are 69, not 68.

11 years agoOnly export Perl_alloccopstash under threads.
Craig A. Berry [Sun, 10 Jun 2012 02:48:22 +0000 (21:48 -0500)]
Only export Perl_alloccopstash under threads.

It might make more sense for makedef.pl to more carefully examine
embed.fnc for what's a symbol to be exported only under threads and
what's not, but for now, we appear to be maintaining a hard-coded
list of symbols not to export when not under threads, so let's add
Perl_alloccopstash to the list.  Failing to do so breaks the
build on platforms where the linker is literal-minded about what
symbols it's been told to find in the export list.

11 years agoUnicode::UCD: typo and incorrect recipe in pod
Karl Williamson [Sat, 9 Jun 2012 23:43:15 +0000 (17:43 -0600)]
Unicode::UCD: typo and incorrect recipe in pod

An extra word is removed, and the recipe should not eval lines with NaN
in them and expect the answer to be NaN

11 years agoRemove win32/config*.gc64nox
Steve Hay [Sat, 9 Jun 2012 16:56:40 +0000 (17:56 +0100)]
Remove win32/config*.gc64nox

The ARCHPREFIX setting from makefile.mk is now passed into config_sh.PL
and config_h.PL and used to apply the changes necessary to the
config*.gc64 files to support both the usual gcc suite and the
x86_64-w64-mingw32-gcc suite (used when GCCCROSS=define).

Also remove the redundant INST_VER argument in the config_h.PL calls.

11 years agoRemove __GNUC__ / _MSC_VER games from win32/config_H.*
Steve Hay [Sat, 9 Jun 2012 10:57:58 +0000 (11:57 +0100)]
Remove __GNUC__ / _MSC_VER games from win32/config_H.*

The code was added by 465b7da985, based on changes in ActivePerl 816, but
it's not working correctly because the current build process winds up with
a config.h in lib/CORE which doesn't contain that code anyway.

(The appropriate canned config_H.* file is copied to config.h in order to
build miniperl.exe, but then miniperl.exe is used to run config_h.PL to
generate the real config.h from config_h.SH and config.sh. The real
config.h is then used to build perl.exe and is what gets copied into
lib/CORE for later use when building extensions, but it doesn't contain
the support for other compilers because that isn't in config_h.SH...)

Removing the code won't affect ActivePerl since it has not been getting
installed anyway, and Jan Dubois has confirmed that it is possible to
build a Perl extension using e.g. Off_t with MinGW even with the VC
config.h header file. Furthermore, anyone building perl from source
themselves will presumably be able to use the same compiler to build
extensions as they used to build perl itself anyway, so there is no
obvious need for this in the core perl distro.

Therefore, removing it rather than fixing it is better for simplicity.

11 years agoUpdated perlfaq to CPAN version 5.0150040
Chris 'BinGOs' Williams [Sat, 9 Jun 2012 11:27:09 +0000 (12:27 +0100)]
Updated perlfaq to CPAN version 5.0150040

  [DELTA]

  5.0150040 Sat  9 Jun 2012 12:02:27 +0100
    * perlglossary provided by Tom C. from Camel 4
    * remove prototypes and & for subroutine (mauke)
    * Grammar from patch [RT #113492]
    * utf8 in Email::MIME (wchristian)

11 years agoQuieten B::Deparse warnings (fixes #113464).
Paul Johnson [Sat, 2 Jun 2012 12:44:47 +0000 (14:44 +0200)]
Quieten B::Deparse warnings (fixes #113464).

11 years ago[perl #111610] Trouble with XS-APItest/t/clone-with-stack.t
Michael Schroeder [Sat, 9 Jun 2012 03:29:54 +0000 (20:29 -0700)]
[perl #111610] Trouble with XS-APItest/t/clone-with-stack.t

I ran into a bit of a problem when building perl-5.16.0.
'make test' showed a segfault in ext/XS-APItest/t/clone-with-stack.t.
It seems to be caused by accessing already freed memory, it
segfaults because I have MALLOC_PERTUBE_ set, thus glibc fills
freed memory with some value.

Digging deeper, it seems like perl_clone() does not fix
the cx's blk_oldcop element when doing context cloning, thus
blk_oldcop still points to PL_compiling in the old interp--the
calling scope for the BEGIN block being the compilation of the
code surrounding it--and the POPBLOCK done in leavesub will copy
the data from the old interp to PL_curcop.

After fixing this, it still crashed because interp_dup->Iop was
zero after the runops_standard() call (which is probably
correct as the end of the BEGIN block was reached). So I
also added an if statement that checks the pointer.

11 years agocflags: clang complains a lot about -Wunused-value which are not fixable
Reini Urban [Thu, 31 May 2012 19:58:35 +0000 (14:58 -0500)]
cflags: clang complains a lot about -Wunused-value which are not fixable

11 years agoAdd alloccopstash provisionally to the API
Father Chrysostomos [Sat, 9 Jun 2012 00:58:39 +0000 (17:58 -0700)]
Add alloccopstash provisionally to the API

11 years agoUpgrade initialization code in vms/vms.c.
Craig A. Berry [Fri, 8 Jun 2012 23:33:33 +0000 (18:33 -0500)]
Upgrade initialization code in vms/vms.c.

The LIB$INITIALIZE program section is examined by the image
activator for an array of 32-bit pointers to functions that will
get called early in start-up, before main() is called.  We use
this mechanism to get and set various run-time features.

The implementation we had was a bit cluttered with undocumented
features that weren't being used, and it didn't work under C++.
This new implementation is simpler and follows the documented
usage in the C++ release notes much more closely, and it works
under both C and C++.

We also now explicitly export the LIB$INITIALIZE psect in the
linker options file used to create the PERLSHR shareable image.

11 years agoRemove pragma about pragma messages.
Craig A. Berry [Fri, 8 Jun 2012 23:17:54 +0000 (18:17 -0500)]
Remove pragma about pragma messages.

We currently aren't getting any warnings about pragmas that need
to be suppressed and the C++ compiler doesn't know about the
"pragma" class of warnings, so stop disabling them.

11 years agoConsistent indentation in perlbook
Father Chrysostomos [Fri, 8 Jun 2012 23:19:40 +0000 (16:19 -0700)]
Consistent indentation in perlbook

11 years agoIncrease $B::Deparse::VERSION to 1.15
Father Chrysostomos [Fri, 8 Jun 2012 21:50:35 +0000 (14:50 -0700)]
Increase $B::Deparse::VERSION to 1.15

11 years agoB::Deparse: loopexes have list prec
Father Chrysostomos [Fri, 8 Jun 2012 21:49:57 +0000 (14:49 -0700)]
B::Deparse: loopexes have list prec

11 years agoConstant folding for x
Father Chrysostomos [Fri, 8 Jun 2012 19:58:42 +0000 (12:58 -0700)]
Constant folding for x

11 years agocv.h: Add comments
Father Chrysostomos [Fri, 8 Jun 2012 19:27:16 +0000 (12:27 -0700)]
cv.h: Add comments

11 years agoMake __SUB__ work in special blocks
Father Chrysostomos [Fri, 8 Jun 2012 17:00:38 +0000 (10:00 -0700)]
Make __SUB__ work in special blocks

11 years agosv.h: Comment typo
Father Chrysostomos [Fri, 8 Jun 2012 15:45:11 +0000 (08:45 -0700)]
sv.h: Comment typo

11 years agocop_stashoff is an integer, not a pointer.
Craig A. Berry [Fri, 8 Jun 2012 22:28:00 +0000 (17:28 -0500)]
cop_stashoff is an integer, not a pointer.

Fix for compiler warning introduced by d4d03940c58.

11 years agoUpdate perlbook.pod with recent releases
Herbert Breunung [Fri, 8 Jun 2012 22:16:12 +0000 (23:16 +0100)]
Update perlbook.pod with recent releases

Signed-off-by: Chris 'BinGOs' Williams <chris@bingosnet.co.uk>
11 years agoExperimentally Use Unicode 6.2 beta
Karl Williamson [Fri, 8 Jun 2012 16:10:28 +0000 (10:10 -0600)]
Experimentally Use Unicode 6.2 beta

Unicode 6.2 is proposing some changes that may very well break some
CPAN modules.  The timing of this nicely coincides with Perl's being
early in the release cycle.  This commit takes the current beta 6.2,
adds the proposed changes that aren't yet in it, and subtracts the
changes that would affect \X processing, as those turn out to have
errors, and may have to be rethought.  Unicode has been notified of
these problems.

This commit is to gather data as to whether or not the proposed changes
cause us problems.  These will be presented to Unicode to aid in their
final decision as to whether or not to go forward with the changes.

This commit should be reverted at some point, and the final 6.2 used
instead.

11 years agomktables: Remove unused $scalar
Karl Williamson [Fri, 8 Jun 2012 15:53:57 +0000 (09:53 -0600)]
mktables: Remove unused $scalar

This variable is no longer used, but the expression needs to be
evaluated anyway.  The code is outdented.

11 years agounicore/README.perl: Make text comments
Karl Williamson [Thu, 7 Jun 2012 04:32:53 +0000 (22:32 -0600)]
unicore/README.perl: Make text comments

This is so that it can be run by a Unix shell command to rename the
files that Unicode furnishes to the ones that Perl expects (because of
DOS 8.3 filesystems).

11 years agomktables: Add error check for overloaded &=
Karl Williamson [Fri, 8 Jun 2012 03:38:01 +0000 (21:38 -0600)]
mktables: Add error check for overloaded &=

This operation is not commutative, so should fail if the operands are
swapped.

11 years agomktables: Add &= overload for Range_Lists
Karl Williamson [Fri, 8 Jun 2012 03:35:17 +0000 (21:35 -0600)]
mktables: Add &= overload for Range_Lists

This is useful under the -annotate option

11 years agomktables: Use control names under -annotate
Karl Williamson [Fri, 8 Jun 2012 03:33:10 +0000 (21:33 -0600)]
mktables: Use control names under -annotate

Now that all the control characters have names, use them instead of the
generic, "Control", but retain that as a fall back just in case.

11 years agoSync base in Maintainers.pl with CPAN version
Chris 'BinGOs' Williams [Fri, 8 Jun 2012 12:26:48 +0000 (13:26 +0100)]
Sync base in Maintainers.pl with CPAN version

11 years agoperldelta for $@=3; warn
Father Chrysostomos [Fri, 8 Jun 2012 06:48:14 +0000 (23:48 -0700)]
perldelta for $@=3; warn

11 years agoperldelta for -$utf8
Father Chrysostomos [Fri, 8 Jun 2012 06:46:18 +0000 (23:46 -0700)]
perldelta for -$utf8

11 years agoperldelta for -"-10" with gmagic
Father Chrysostomos [Fri, 8 Jun 2012 06:45:16 +0000 (23:45 -0700)]
perldelta for -"-10" with gmagic

11 years agoperldelta for -$str_with_cached_num
Father Chrysostomos [Fri, 8 Jun 2012 06:44:10 +0000 (23:44 -0700)]
perldelta for -$str_with_cached_num

11 years agoperldelta for numeric opts, gmg, and 64-bit ints
Father Chrysostomos [Fri, 8 Jun 2012 06:40:55 +0000 (23:40 -0700)]
perldelta for numeric opts, gmg, and 64-bit ints

11 years agoperldelta for warn gmagic fixes
Father Chrysostomos [Fri, 8 Jun 2012 06:38:40 +0000 (23:38 -0700)]
perldelta for warn gmagic fixes

11 years agoperldelta for prototype($1)
Father Chrysostomos [Fri, 8 Jun 2012 06:35:16 +0000 (23:35 -0700)]
perldelta for prototype($1)

11 years agoperldelta for open, <&, and $1
Father Chrysostomos [Fri, 8 Jun 2012 06:31:39 +0000 (23:31 -0700)]
perldelta for open, <&, and $1

11 years agoperldelta for UNIVERSAL::can($num,...)
Father Chrysostomos [Fri, 8 Jun 2012 06:28:42 +0000 (23:28 -0700)]
perldelta for UNIVERSAL::can($num,...)

11 years agoperldelta for ‘Not a format ref’
Father Chrysostomos [Fri, 8 Jun 2012 06:25:39 +0000 (23:25 -0700)]
perldelta for ‘Not a format ref’

11 years agoperldelta for B::COP::stashpv and utf8/nulls
Father Chrysostomos [Fri, 8 Jun 2012 06:23:19 +0000 (23:23 -0700)]
perldelta for B::COP::stashpv and utf8/nulls

11 years agoperldelta for B::COP::stashoff
Father Chrysostomos [Fri, 8 Jun 2012 06:22:41 +0000 (23:22 -0700)]
perldelta for B::COP::stashoff

11 years agoperldelta for caller crashing on SvOOK str
Father Chrysostomos [Fri, 8 Jun 2012 06:20:52 +0000 (23:20 -0700)]
perldelta for caller crashing on SvOOK str

11 years agoperldelta for cop_stashoff
Father Chrysostomos [Fri, 8 Jun 2012 06:17:22 +0000 (23:17 -0700)]
perldelta for cop_stashoff

11 years agoperldelta for #78742 — eval "__PACKAGE__"
Father Chrysostomos [Fri, 8 Jun 2012 03:02:19 +0000 (20:02 -0700)]
perldelta for #78742 — eval "__PACKAGE__"

11 years agoperldelta: fix pod syntax
Father Chrysostomos [Fri, 8 Jun 2012 02:54:36 +0000 (19:54 -0700)]
perldelta: fix pod syntax

11 years agoperldelta for rv2cv not cloning closures
Father Chrysostomos [Fri, 8 Jun 2012 01:01:07 +0000 (18:01 -0700)]
perldelta for rv2cv not cloning closures

11 years agoperldelta for ‘Runaway prototype’ removal
Father Chrysostomos [Thu, 7 Jun 2012 23:14:18 +0000 (16:14 -0700)]
perldelta for ‘Runaway prototype’ removal