platform/upstream/perl.git
12 years ago[perl #113940] Make make_ext delete Makefiles when version changes
Father Chrysostomos [Sun, 29 Jul 2012 05:48:27 +0000 (22:48 -0700)]
[perl #113940] Make make_ext delete Makefiles when version changes

This eliminates this annoyance:

$ ./perl -Ilib -MStorable -e0
Storable object version 2.37 does not match bootstrap parameter 2.38 at lib/XSLoader.pm line 95.
Compilation failed in require.
BEGIN failed--compilation aborted.

12 years agoRemove some redundant magical flag checks
Father Chrysostomos [Sun, 29 Jul 2012 07:26:55 +0000 (00:26 -0700)]
Remove some redundant magical flag checks

Now that gmagical svs use the OK flags the same way as muggles,
things like SvPOK || (SvGMAGICAL && SvPOKp) are no longer necessary.

12 years agoUse $^S instead of caller in splain
Father Chrysostomos [Sun, 29 Jul 2012 07:03:45 +0000 (00:03 -0700)]
Use $^S instead of caller in splain

12 years agoIncrease $diagnostics::VERSION to 1.31
Father Chrysostomos [Sun, 29 Jul 2012 06:58:44 +0000 (23:58 -0700)]
Increase $diagnostics::VERSION to 1.31

12 years agoperldelta: proto mismatch warnings
Father Chrysostomos [Sun, 29 Jul 2012 06:54:16 +0000 (23:54 -0700)]
perldelta: proto mismatch warnings

12 years agoFix scrambled and incorrect proto mismatch error
Father Chrysostomos [Sun, 29 Jul 2012 06:41:00 +0000 (23:41 -0700)]
Fix scrambled and incorrect proto mismatch error

$ ./perl -Ilib -e 'use constant foo=>bar; sub foo(@);'
Prototype mismatch:: none vs (@) at -e line 1.
$ ./perl -Ilib -e 'sub foo(); sub foo(@);'
Prototype mismatch: () vs (@) at -e line 1.

Notice the double colon and the ‘none’ in the first example?

We also have this bug, where the prototype is the same, but we get the
warning anyway:

$ ./perl -Ilib -e 'use constant foo=>bar; sub foo();'
Prototype mismatch:: none vs () at -e line 1.

When the $::{foo} = \1 constant optimisation was added in 5.10.0, pro-
totype warnings were not taken into account.  A forward declaration
like sub foo() puts a string in the stash element.  newATTRSUB was
passing a non-SVt_NULL non-gv stash element to cv_ckproto_len_flags,
which assumed that !SvPOK meant no prototype.  That’s not the case
with a reference.

The double colon, which goes back to 5.8.4 (ebe643b99/59e7bac08e),
occurs when the sub name is not available:

$ perl5.8.4 -e 'sub foo; sub foo();'
Prototype mismatch:: none vs () at -e line 1.

(Before that the message was worse:
$ perl5.8.3 -e 'sub foo; sub foo();'
Prototype mismatch: vs () at -e line 1.)

In 5.10.0, it started applying to constants as well, which used to
show the sub name:

$ perl5.8.9 -e 'use constant foo=>bar; sub foo(@);'
Prototype mismatch: sub main::foo () vs (@) at -e line 1.
$ perl5.10.0 -e 'use constant foo=>bar; sub foo(@);'
Runaway prototype at -e line 1.
Prototype mismatch:: none vs (@) at -e line 1.

(‘Runaway prototype’ is already gone in blead [acfcf464b177, in which
I stated wrongly that the warning could only come about with stash
manipulation].)

This commit changes cv_ckproto_len_flags to assume that a reference
is a constant with an empty string for a prototype.  It also makes
newATTRSUB pass the sub name sv instead of a gv in those cases where
the stash element isn’t a gv.  This doesn’t restore things to exactly
the way they were before (foo instead of main::foo), but I’m not sure
it’s worth the added complexity of constructing the fully-qualified
name, just for a warning.

12 years agoperldelta for 4499db7385 (vstr =~ s/a/a/)
Father Chrysostomos [Sun, 29 Jul 2012 05:52:57 +0000 (22:52 -0700)]
perldelta for 4499db7385 (vstr =~ s/a/a/)

12 years agosv.h: Document SvTHINKFIRST
Father Chrysostomos [Sun, 29 Jul 2012 01:32:02 +0000 (18:32 -0700)]
sv.h: Document SvTHINKFIRST

12 years agoDumper.xs: Avoid scan_vstring on 5.17.3
Father Chrysostomos [Sat, 28 Jul 2012 07:39:41 +0000 (00:39 -0700)]
Dumper.xs: Avoid scan_vstring on 5.17.3

Now that vstring set-magic is gone (4499db7385), there is no
PL_vtbl_vstring, so we cannot use it for detecting vstring
bugginess.

12 years agoIncrease $Data::Dumper::VERSION to 2.135_07
Father Chrysostomos [Sat, 28 Jul 2012 07:35:18 +0000 (00:35 -0700)]
Increase $Data::Dumper::VERSION to 2.135_07

12 years agoOust sv_gmagical_2iv_please
Father Chrysostomos [Sat, 28 Jul 2012 07:33:33 +0000 (00:33 -0700)]
Oust sv_gmagical_2iv_please

The magic flags patch prevents this from ever being called, since the
OK flags work the same way for magic variables now as they have for
muggle vars, avoid these fiddly games.  (It was when writing it that I
realised the value of the magic flags proposal.)

12 years agoRemove code for supporting 80286 based systems.
Nicholas Clark [Fri, 27 Jul 2012 17:17:54 +0000 (19:17 +0200)]
Remove code for supporting 80286 based systems.

The 80286 was released two years before Perl 1, but the support code was
added with Perl 3. The chip hasn't been produced for more than 15 years -
even the 80386 hasn't been manufactured since 2007. Most of the other
memory model code was removed by commit 5869b1f143426909 in Sep 2000, so
support for 16 bit systems is long dead.

12 years agoRemove dead code related to the Atari ST port of perl 4.0 patchlevel 19
Nicholas Clark [Fri, 27 Jul 2012 15:53:22 +0000 (17:53 +0200)]
Remove dead code related to the Atari ST port of perl 4.0 patchlevel 19

The subdirectory containing the port specific files was purged when 5.000
was released, but changes made to other files were not removed.

12 years agoMerge the refactoring of the filetest OPs' return code.
Nicholas Clark [Sat, 28 Jul 2012 08:11:08 +0000 (10:11 +0200)]
Merge the refactoring of the filetest OPs' return code.

12 years agoComment the code with how filetest operators interact with the Perl stack.
Nicholas Clark [Fri, 27 Jul 2012 14:38:01 +0000 (16:38 +0200)]
Comment the code with how filetest operators interact with the Perl stack.

12 years agoEliminate the macros FT_RETURN_FALSE() and FT_RETURN_TRUE().
Nicholas Clark [Fri, 27 Jul 2012 13:05:00 +0000 (15:05 +0200)]
Eliminate the macros FT_RETURN_FALSE() and FT_RETURN_TRUE().

As they now simply return the results of S_ft_return_false() and
S_ft_return_true() respectively, use this explicitly in the 7 places where
the macros had been used.

12 years agoRefactor the macro FT_RETURN_TRUE() into the function S_ft_return_true()
Nicholas Clark [Fri, 27 Jul 2012 12:47:56 +0000 (14:47 +0200)]
Refactor the macro FT_RETURN_TRUE() into the function S_ft_return_true()

This makes the true and false code paths as similar as possible. It also
eliminates a macro that the HP compiler was choking on.

12 years agoConsolidate the code for returning false values from filetest operators.
Nicholas Clark [Fri, 27 Jul 2012 12:19:27 +0000 (14:19 +0200)]
Consolidate the code for returning false values from filetest operators.

Move the code that implements the non-stacking return processing from the
macro FT_RETURN_FALSE() into the static function S_ft_stacking_return_false().
Rename the function to S_ft_return_false() as it now handles all false cases.

12 years agoReorder S_ft_stacking_return_false().
Nicholas Clark [Fri, 27 Jul 2012 11:32:33 +0000 (13:32 +0200)]
Reorder S_ft_stacking_return_false().

Move the code which deals with setting the return value on perl's stack
ahead of the code which calculates which op to run next (the return value of
the C function).

12 years agoRemove dSP from all filetest ops.
Nicholas Clark [Fri, 27 Jul 2012 11:16:29 +0000 (13:16 +0200)]
Remove dSP from all filetest ops.

Following commit d2c4d2d1e22d3125, all filetest ops avoid manipulating the
stack pointer until the point of pushing a return value. As all the filetest
returns now go through either FT_RETURN_FALSE() or FT_RETURN_TRUE(), it's
viable to put the dSP inside those two macros and use *PL_stack_sp in place
of TOPs. This eliminates all uses of sp in the bodies of the functions
(explicit, or implicit via macros), and that makes it clear that the main
bodies of the functions are not manipulating the stack.

12 years agoReplace the macro RETURNX() with its expansion in FT_RETURN_{FALSE,TRUE}
Nicholas Clark [Fri, 27 Jul 2012 10:54:49 +0000 (12:54 +0200)]
Replace the macro RETURNX() with its expansion in FT_RETURN_{FALSE,TRUE}

The macros FT_RETURN_FALSE and FT_RETURN_TRUE in pp_ctl.c are already very
complex, sufficient to trigger an internal failure in HP's compiler [and
possibly also some humans :-)]. Replacing RETURNX() with the 3 statements it
expands to makes the intent of macros clearer, and exposes more refactoring
possibilities.

12 years agoperldelta for 1eb0b7be2ff1 (B::Deparse and loopex prec)
Father Chrysostomos [Sat, 28 Jul 2012 07:17:04 +0000 (00:17 -0700)]
perldelta for 1eb0b7be2ff1 (B::Deparse and loopex prec)

12 years agoperldelta for 1f039d60d3 (last $foo)
Father Chrysostomos [Sat, 28 Jul 2012 07:15:58 +0000 (00:15 -0700)]
perldelta for 1f039d60d3 (last $foo)

12 years agoperldelta for 2ba1f20ac3a (loopex prec docs)
Father Chrysostomos [Sat, 28 Jul 2012 07:12:59 +0000 (00:12 -0700)]
perldelta for 2ba1f20ac3a (loopex prec docs)

12 years agoperldelta for f6894bc8d44 and e52de15a29
Father Chrysostomos [Sat, 28 Jul 2012 07:10:53 +0000 (00:10 -0700)]
perldelta for f6894bc8d44 and e52de15a29

12 years agoperldelta for 42409c4069 (truncate FILENAME)
Father Chrysostomos [Sat, 28 Jul 2012 07:09:11 +0000 (00:09 -0700)]
perldelta for 42409c4069 (truncate FILENAME)

12 years agoperldelta for 9a0c99494c and 06b58b76f31
Father Chrysostomos [Sat, 28 Jul 2012 07:07:17 +0000 (00:07 -0700)]
perldelta for 9a0c99494c and 06b58b76f31

12 years agoperldelta for c9df4fdaad9 (dump LABEL leak)
Father Chrysostomos [Sat, 28 Jul 2012 07:04:25 +0000 (00:04 -0700)]
perldelta for c9df4fdaad9 (dump LABEL leak)

12 years agodoop.c: Simplify do_trans’ un-cow logic
Father Chrysostomos [Sat, 28 Jul 2012 06:59:19 +0000 (23:59 -0700)]
doop.c: Simplify do_trans’ un-cow logic

Since it calls SvPV_force_nomg a little further on, there is no need
for a separate sv_force_normal call to handle COWs.

12 years agoFix C++ build broken by 1f039d60d3
Father Chrysostomos [Sat, 28 Jul 2012 06:51:59 +0000 (23:51 -0700)]
Fix C++ build broken by 1f039d60d3

The goto was bypassing initialisation.  Avoiding goto altogether actu-
ally simplifies things.

12 years agoFlatten vstrings modified in place
Father Chrysostomos [Sat, 28 Jul 2012 06:46:07 +0000 (23:46 -0700)]
Flatten vstrings modified in place

A substitution forces its target to a string upon successful substitu-
tion, even if the substitution did nothing:

$ ./perl -Ilib -le '$a = *f; $a =~ s/f/f/; print ref \$a'
SCALAR

Notice that $a is no longer a glob after s///.

But vstrings are different:

$ ./perl -Ilib -le '$a = v102; $a =~ s/f/f/; print ref \$a'
VSTRING

I fixed this in 5.16 (1e6bda93) for those cases where the vstring ends
up with a value that doesn’t correspond to the actual string:

$ ./perl -Ilib -le '$a = v102; $a =~ s/f/o/; print ref \$a'
SCALAR

It works through vstring set-magic, that does the check and removes
the magic if it doesn’t match.

I did it that way because I couldn’t think of any other way to fix
bug #29070, and I didn’t realise at the time that I hadn’t fixed
all the bugs.

By making SvTHINKFIRST true on a vstring, we force it through
sv_force_normal before any in-place string operations.  We can also
make sv_force_normal handle vstrings as well.  This fixes all the lin-
gering-vstring-magic bugs in just two lines, making the vstring set-
magic (which is also slow) redundant.  It also allows the special case
in sv_setsv_flags to be removed.

Or at least that was what I had hoped.

It turns out that pp_subst, twists and turns in tortuous ways, and
needs special treatment for things like this.

And do_trans functions wasn’t checking SvTHINKFIRST when arguably it
should have.

I tweaked sv_2pv{utf8,byte} to avoid copying magic variables that do
not need copying.

12 years agopp.c:pp_trans: avoid redundant sv in transr
Father Chrysostomos [Sat, 28 Jul 2012 01:05:02 +0000 (18:05 -0700)]
pp.c:pp_trans: avoid redundant sv in transr

I think I added the if (OP_TRANSR) block to the wrong spot, because the
mortal scalar created just before it is only used for y/// without /r.

12 years agoDocument return to be exempt from the looks-like-a-function rule, like dump, goto...
Eric Brine [Fri, 27 Jul 2012 22:54:24 +0000 (18:54 -0400)]
Document return to be exempt from the looks-like-a-function rule, like dump, goto and next.

12 years agoperlfunc: document last/next EXPR
Father Chrysostomos [Fri, 27 Jul 2012 21:52:21 +0000 (14:52 -0700)]
perlfunc: document last/next EXPR

Also remove some repetitive text from goto, added in 2ba1f20ac3.

12 years agoB::Deparse: loopexes have assignment prec
Father Chrysostomos [Fri, 27 Jul 2012 21:41:05 +0000 (14:41 -0700)]
B::Deparse: loopexes have assignment prec

See ticket #113684 for detail.

12 years agoIncrease $B::Deparse::VERSION to 1.16
Father Chrysostomos [Fri, 27 Jul 2012 21:37:22 +0000 (14:37 -0700)]
Increase $B::Deparse::VERSION to 1.16

12 years ago[perl #113684] Make redo/last/next/dump accept expr
Father Chrysostomos [Fri, 27 Jul 2012 21:26:39 +0000 (14:26 -0700)]
[perl #113684] Make redo/last/next/dump accept expr

These functions have been allowing arbitrary expressions, but would
treat anything that did not resolve to a const op as the empty string.
Not only were arguments swallowed up without warning, but constant
folding could change the behaviour.  Computed labels are allowed for
goto, and there is no reason to disallow them for these other ops.
This can also come in handy for certain types of code generators.

In the process of modifying pp functions to accept arbitrary labels,
I noticed that the label and loop-popping code was identical in three
functions, so I moved it out into a separate static function, to make
the changes easier.

I also had to reorder newLOOPEX significantly, because code under the
goto branch needed to a apply to last, and vice versa.  Using multiple
gotos to switch between the branches created too much of a mess.

I also eliminated the use of SP from pp_last, to avoid copying the
value back and forth between SP and PL_stack_sp.

12 years agopp.h: Make [TP]OPp and [TP]OPpx identical
Father Chrysostomos [Fri, 27 Jul 2012 20:36:35 +0000 (13:36 -0700)]
pp.h: Make [TP]OPp and [TP]OPpx identical

In the absence of n_a (see 8c074e2a and 95fad918), there is no differ-
ence between [TP]OPp and [TP]OPpx except speed, so there is no reason
for the x-less variant to be deprecated.

12 years agoop.c: apidoc typo
Father Chrysostomos [Fri, 27 Jul 2012 20:02:13 +0000 (13:02 -0700)]
op.c: apidoc typo

12 years ago[perl #113684] Document actual prec of loop exits
Father Chrysostomos [Fri, 27 Jul 2012 17:46:26 +0000 (10:46 -0700)]
[perl #113684] Document actual prec of loop exits

These have always* had assignment precedence, such that

$a = goto $b = $c

is equivalent to

$a = (goto ($b = $c))

* I haven’t checked before perl 5.

12 years agoFix CvOUTSIDE assert/refcnt bugs with sub redefinition
Father Chrysostomos [Fri, 27 Jul 2012 17:30:58 +0000 (10:30 -0700)]
Fix CvOUTSIDE assert/refcnt bugs with sub redefinition

my $sub = sub { 4 };
*foo = $sub;
*bar = *foo;
undef &$sub;
eval "sub bar { 3 }";
undef *foo;
undef *bar;

As of 5.8.4, this script produces:

Attempt to free unreferenced scalar: SV 0x8002c4.

As of 5.14.0:

panic: del_backref.

Or, undef debugging builds:

Assertion failed: (!CvWEAKOUTSIDE(cv)), function Perl_newATTRSUB_flags, file op.c, line 7045.

Commit 5c41a5fa918 (backported to 5.8.4 in commit 7a565e5d) caused the
first bug:

commit 5c41a5fa918d32924e1ac2f02418d5d7f465ef26
Author: Dave Mitchell <davem@fdisolutions.com>
Date:   Sun Jan 25 02:04:23 2004 +0000

    Remove small memory leak in newATTRSUB that manifested as a
    leaking scalar after the interpeter was cloned

    p4raw-id: //depot/perl@22209

diff --git a/op.c b/op.c
index b902fed..5fd21bf 100644
--- a/op.c
+++ b/op.c
@@ -4165,6 +4165,8 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
  /* transfer PL_compcv to cv */
  cv_undef(cv);
  CvFLAGS(cv) = CvFLAGS(PL_compcv);
+ if (!CvWEAKOUTSIDE(cv))
+     SvREFCNT_dec(CvOUTSIDE(cv));
  CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
  CvOUTSIDE_SEQ(cv) = CvOUTSIDE_SEQ(PL_compcv);
  CvOUTSIDE(PL_compcv) = 0;

Checking the flags right after clobbering them can’t be a good idea.

Commit 437388a93 caused the panics and assertion failures.  See com-
mit f6894bc for detail.

Commit f6894bc fixed the panics and assertion failures involving CvGV.

One remaining assertion (!CvWEAKOUTSIDE) added by 437388a93 is still
incorrect.  It’s not true that CvWEAKOUTSIDE is never set on a re-
used stub.

In both cases (5c41a5fa’s code and 437388a93’s code), the weakness
of CvOUTSIDE is ignored and the outside sub (the eval) is freed
prematurely.

It could be that this type of redefinition should be disallowed (des-
pite its usefulness), but that is a separate issue.  This used to
work.  And pure-Perl code should not be triggering assertion failures
or freeing scalars twice.

12 years agoFix CvGV assertion bug with sub redefinition
Father Chrysostomos [Fri, 27 Jul 2012 17:11:25 +0000 (10:11 -0700)]
Fix CvGV assertion bug with sub redefinition

*foo = \&baz;
*bar = *foo;
eval 'sub bar { print +(caller 0)[3], "\n" }';
bar();

Before 5.14, that produces:

main::foo

As of 5.14, it produces:

main::baz

Or, under debugging builds:

Assertion failed: (CvGV(cv) == gv), function Perl_newATTRSUB_flags, file op.c, line 7139.

commit 437388a93114b1acbfb3a173dfa7aa2138fd8283
Author: Nicholas Clark <nick@ccl4.org>
Date:   Thu Nov 18 14:54:44 2010 +0000

    Refactor newATTRSUB()'s logic for grafting a sub definition to an existing stub

    Previously it was using cv_undef() to (partially) free the target CV (the
    pre-existing stub), before donating it the padlist and outside pointers from
    the source CV (the definition, just compiled), and then freeing up the remains
    of the source CV.

    Instead, explicitly exchange padlist and outside pointers, explicitly assign
    other fields that need changing (file and stash), and assert that various
    CvFLAGS are as we expect them.

That commit adds some assertions, including:

+     assert(!CvCVGV_RC(cv));
+     assert(CvGV(cv) == gv);

Those assertions are not always true.  CvGV might be refcounted, and
it might not point to the same gv.

437388a93 also changed things such that the CVf_CVGV_RC flag is clob-
bered, so refcounting and backrefs get out of synch (tests for that
specific bug will be in a subsequent commit).  It also stopped sub
redefinition from setting CvGV.

12 years agoRestore microperl, which has been unable to build since January.
Nicholas Clark [Fri, 27 Jul 2012 15:36:40 +0000 (17:36 +0200)]
Restore microperl, which has been unable to build since January.

microperl was broken by commit 82ad65bb0613be64 on 2012-01-16, which used
IN_LOCALE_COMPILETIME for the first time in the C code. Unlike
IN_LOCALE_RUNTIME, it had no fallback definition for microperl.

Commit f90a9a0230170cc0 on 2012-01-28 added the first use of Strtol(),
which means that microperl now needs to assume that the system has strtol().
(Which is not unreasonable, as it's part of C89).

12 years agoWhen setting environment variables via %ENV, force values to be strings only
Chip Salzenberg [Thu, 26 Jul 2012 03:27:30 +0000 (20:27 -0700)]
When setting environment variables via %ENV, force values to be strings only
(turning off other OK flags), make them byte strings; if wide characters can't
be downgraded to bytes, leave the string utf8 and issue a warning.

12 years agoMake all the SvPV*force* macros always return sv with SvPOK_only, as API
Chip Salzenberg [Thu, 26 Jul 2012 01:41:50 +0000 (18:41 -0700)]
Make all the SvPV*force* macros always return sv with SvPOK_only, as API
docs always claimed they did.  Also update those docs to be clearer.

12 years agomktables: Change \w definition to match new Unicode's
Karl Williamson [Thu, 26 Jul 2012 15:56:27 +0000 (09:56 -0600)]
mktables: Change \w definition to match new Unicode's

Unicode has changed their definition of what should match \w.
http://www.unicode.org/reports/tr18/.  This follows that change.

12 years agoMake Module::CoreList install into 'site' >= 5.012
Chris 'BinGOs' Williams [Thu, 26 Jul 2012 14:58:02 +0000 (15:58 +0100)]
Make Module::CoreList install into 'site' >= 5.012

Also if versiononly is set make sure that corelist is installed
with the appropriate versioned suffix.

12 years ago[perl #113872] Fix leavewrite’s stack handling
Father Chrysostomos [Thu, 26 Jul 2012 07:16:00 +0000 (00:16 -0700)]
[perl #113872] Fix leavewrite’s stack handling

This commit fixes Scope::Escape compatibility by restoring the old
stack pointer stored on the context stack when exiting a write.

I don’t really understand why this fixes Scope::Escape, or rather, how
Scope::Escape ends up leaving some number of items on the stack other
than 1.  But I *do* know this is the correct approach, as it mirrors
what pp_leavesub does in scalar context, but pops the stack back
to the old value (SP = newsp), rather than the old value+1 (see
pp_hot.c:pp_leavesub: MARK = newsp + 1; and later SP = MARK;).  Then
the code that follows takes care of pushing write’s own return value.

12 years agoop.c: op_clear is tempting fate
Father Chrysostomos [Thu, 26 Jul 2012 05:19:56 +0000 (22:19 -0700)]
op.c: op_clear is tempting fate

This if() statement can be reached by op types to which the OpTRANS*
flags to not apply.  They happen at present not to use any flags that
conflict with these (except when OPf_KIDS is set, in which case this
code is not reached).   But we should make sure, via an assertion,
that new flags added to goto or last do not conflict with trans utf8
flags, and that trans utf8 flags (1 and 2), if renumbered, do not con-
flict with goto/last utf8 flags (128).

12 years agoDon’t let ?: folding affect truncate
Father Chrysostomos [Thu, 26 Jul 2012 05:07:12 +0000 (22:07 -0700)]
Don’t let ?: folding affect truncate

truncate(${\1} ? foo : bar, 0) and truncate(1 ? foo : bar, 0) should
behave the same way, but were treated differently, due to the way ?:
is folded in the latter case.  Now that foldedness is recorded in the
op tree (cc2ebcd7902), we can use the OPpCONST_FOLDED flag to distin-
guish truncate(1 ? foo : bar, 0) from truncate(foo, 0).

12 years agoStop truncate(word) from falling back to file name
Father Chrysostomos [Thu, 26 Jul 2012 05:04:02 +0000 (22:04 -0700)]
Stop truncate(word) from falling back to file name

In commit 5e0adc2d66, which was a bug fix, I made the mistake of
checking the truth of the return value of gv_fetchsv, which is called
when truncate’s argument is a bareword.

This meant that truncate FOO, 0; would truncate the file named FOO if
the glob happened to have been deleted.

12 years agoDon’t let ?: folding affect stat
Father Chrysostomos [Thu, 26 Jul 2012 03:15:36 +0000 (20:15 -0700)]
Don’t let ?: folding affect stat

stat(${\1} ? foo : bar) and stat(1 ? foo : bar) should behave the same
way, but were treated differently, due to the way ?: is folded in
the latter case.  Now that foldedness is recorded in the op tree
(cc2ebcd7902), we can use the OPpCONST_FOLDED flag to distinguish
stat(1 ? foo : bar) from stat(foo).

12 years agoMerge ck_trunc and ck_chdir
Father Chrysostomos [Thu, 26 Jul 2012 01:00:34 +0000 (18:00 -0700)]
Merge ck_trunc and ck_chdir

ck_chdir, added in 2006 (d4ac975e) duplicates ck_trunc, added in
1993 (79072805), except for a null op check which is harmless when
applied to chdir.

12 years agoop.c: dump LABEL leaks its label
Father Chrysostomos [Wed, 25 Jul 2012 23:40:37 +0000 (16:40 -0700)]
op.c: dump LABEL leaks its label

./perl -Ilib -e 'warn $$; eval "sub { dump a }" while 1'

Watch the memory usage go up.

It didn’t have its own case in op_clear.

12 years agoop.c:op_free: Rmv dead code; simplify cop_free logic
Father Chrysostomos [Wed, 25 Jul 2012 23:31:07 +0000 (16:31 -0700)]
op.c:op_free: Rmv dead code; simplify cop_free logic

This reverts c53f1caa and cc93af5f.

See the thread starting at
http://www.nntp.perl.org/group/perl.perl5.porters/2008/04/msg135885.html

Basically, change c53f1caa made a change, but then cc93af5f undid it,
but differently.  This resulted in dead code left by c53f1caa (type is
unused after the assignment).  And in the end the code behaved exactly
the same way, so the original problem was not fixed.  I suspect this
was a B::C bug.

12 years agoMerge branch 'blead' of ssh://perl5.git.perl.org/perl into blead
Karl Williamson [Wed, 25 Jul 2012 03:39:32 +0000 (21:39 -0600)]
Merge branch 'blead' of ssh://perl5.git.perl.org/perl into blead

12 years agoMerge branch 'khw/invlist' into blead
Karl Williamson [Wed, 25 Jul 2012 03:14:46 +0000 (21:14 -0600)]
Merge branch 'khw/invlist' into blead

This topic branch deals mostly with bracketed character classes in
regular expressions.  It has several main thrusts:

1) The character class macros in handy.h are tied to the class numbers
   in regcomp.h, and a new set of regnode types, POSIX, are introduced.
   This will allow more table driven code in regular expression
   compilation and matching, so that the same regnode type can be used
   for any of the Posix-like character classes, such as \w as well as
   [:upper:].  This will allow removal of nearly-duplicate (and
   triplicate, etc) code.

2) The optimizations for bracketed character classes are extended to
   work off not just the first 256 characters, but all code points.
   This extends some char class optimizations to Unicode, and will
   allow future work to change the regular expression optimizer to work
   off all Unicode characters, instead of its current behavior of mostly
   giving up on these.

3) Several new character class optimizations are introduced, with the
   groundwork laid for more.  A character class containing a single
   character is the same as the single character without the class,
   except that most metacharacters are treated as literals.  Thus,
   /a[.]b/ produces identical results to /a\.b/.  Prior to this merge,
   the first form's compiled version would require quite a bit more
   space than the second.  Now they are identical.

Inversion lists of the whole class are used for optimization
   calculations.

12 years agoregcomp.c: Revise bracketed char class optimizations
Karl Williamson [Mon, 23 Jul 2012 04:37:21 +0000 (22:37 -0600)]
regcomp.c: Revise bracketed char class optimizations

This commit uses the inversion list instead of the bit map constructed
during compilation of [bracketed classes] for determining the
optimizations that are done at the very end of processing the class.
This provides optimizations for things that can't be seen by just
looking at the bitmap.

There are optimizations done earlier in the code for things
that can be easily caught in Pass 1, but now we have complete
information.  At this time, I'm not repeating checking for most
optimizations that are checked for earlier, though this could be added.
The earlier optimizations could overlook cases where someone specified a
class in a suboptimal way.  For example the earlier code looks for a
class with a single range [0-9], but those 10 code points could instead
have been specified via [0123456789], and the code doesn't catch that
currently; here we could, but I'm not doing so at this time.

The code does do some duplicate checking.  For example, some Unicode
properties match only a single code point, such as lb=cr, and these
aren't known at the earlier point where single code point classes are
checked for.

12 years agoregcomp.c: Fix <if> condition
Karl Williamson [Mon, 23 Jul 2012 04:09:21 +0000 (22:09 -0600)]
regcomp.c: Fix <if> condition

The else clause is expecting that the regex is compiled under /d, when
in fact, until this commit, it could also be under /l.  I could not come
up with a case currently where this distinction matters, but it's best
to not tempt fate.

12 years agoregcomp.c: Add _invlist_contains_cp
Karl Williamson [Mon, 23 Jul 2012 04:00:46 +0000 (22:00 -0600)]
regcomp.c: Add _invlist_contains_cp

This simply searches an inversion list without going through a swash.
It will be used in a future commit.

12 years agoutf8.c: Add a get_() method to hide internal details
Karl Williamson [Wed, 25 Jul 2012 02:53:41 +0000 (20:53 -0600)]
utf8.c: Add a get_() method to hide internal details

This should have been written this way to begin with (I'm the culprit).
But we should have a method so another routine doesn't have to know the
internal details.

12 years agoregcomp.c: Optimize /[[:blank:]]/u into \h
Karl Williamson [Fri, 20 Jul 2012 17:39:09 +0000 (11:39 -0600)]
regcomp.c: Optimize /[[:blank:]]/u into \h

These two are equivalent.

12 years agoregcomp.c: Properly count elements in [] for false ranges
Karl Williamson [Fri, 20 Jul 2012 17:35:07 +0000 (11:35 -0600)]
regcomp.c: Properly count elements in [] for false ranges

When something that looks like a range turns out not to be, the hyphen
is matched literally, and so is a separate element in the character
class.  It needs to be accounted as such.

12 years agoregcomp.c: Use POSIXA, NPOSIXA
Karl Williamson [Fri, 20 Jul 2012 16:23:14 +0000 (10:23 -0600)]
regcomp.c: Use POSIXA, NPOSIXA

This commit optimizes character classes which are matched under /a or
/aa and consist of a single Posix class, into POSIXA or NPOSIXA regop
types.  For example /[[:word:]]/a.  Since [:ascii:] is always
ascii-restricted no matter what the charset modifier is, it is always
optimized.

These nodes should execute somewhat faster than a generic ANYOF node,
and are significantly smaller, taking 2 bytes instead of 12.

The flags field of the node structure is used to hold an enum indicating
which of the 15 Posix classes is being matched.

12 years agoregcomp.sym: Add new node types POSIXA and NPOSIXA
Karl Williamson [Fri, 20 Jul 2012 16:02:23 +0000 (10:02 -0600)]
regcomp.sym: Add new node types POSIXA and NPOSIXA

These will be used to handle things like /[[:word:]]/a.  This patch
doesn't add the code to actually use these.  That will be done in a
future patch.

Also, placeholders POSIXD, POSIXL, and POSIXU are also added for future
use.

12 years agoregcomp.h: Use handy.h constants
Karl Williamson [Mon, 9 Jul 2012 21:17:28 +0000 (15:17 -0600)]
regcomp.h: Use handy.h constants

This synchronizes the ANYOF_FOO usages to the isFOO() usages.  Future
commits will take advantage of this relationship.

12 years agohandy.h: Free up bits in PL_charclass[]
Karl Williamson [Fri, 20 Jul 2012 03:53:06 +0000 (21:53 -0600)]
handy.h: Free up bits in PL_charclass[]

This array is a bit map containing the Posix and similar character
classes for the first 256 code points.  Prior to this commit many
character classes were represented by two bits, one for characters that
are in it over the full Latin-1 range, and one for just the ASCII
characters that are in it.  The number of bits in use was approaching
the 32-bit limit available without playing games.

This commit takes advantage of a recent commit that adds a bit to the
table for all the ASCII characters, and the fact that the ASCII
characters in a character class are a subset of the full Latin1
range.  So, iff both the full-range character class bit and the ASCII
bit is set is that character an ASCII-range character with the given
character class.

A new internal macro is created to generate code to determine if a
character is an ASCII range character with the given class.  It's not
clear if the generated code is faster or slower than the full range
version.

The result is that nearly half the bits are freed up, as the ones for
the ASCII-range are now redundant.

12 years agohandy.h: Add intermediate internal macro
Karl Williamson [Fri, 20 Jul 2012 03:47:48 +0000 (21:47 -0600)]
handy.h: Add intermediate internal macro

This macro abstracts an operation, and will make future commits cleaner.

12 years agoregcomp.c: Relax some restrictions on optimizations for locale
Karl Williamson [Tue, 10 Jul 2012 04:00:16 +0000 (22:00 -0600)]
regcomp.c: Relax some restrictions on optimizations for locale

Prior to this commit, we didn't do any inversions for bracketed
character classes running under locale.  However, this is more strict
than necessary.  If there is no folding, and everything else is known at
compile time, then what is matched when the result is complemented is
well-defined, and can be done now.  (Also clarifies one of the affected
comments)

12 years agoregcomp.c: Add func to test 2 inversion lists for equality
Karl Williamson [Tue, 10 Jul 2012 00:44:46 +0000 (18:44 -0600)]
regcomp.c: Add func to test 2 inversion lists for equality

This adds _invlistEQ which for now is commented out

12 years agoutf8.c: Add info to commented-out -DU lines
Karl Williamson [Mon, 9 Jul 2012 22:35:11 +0000 (16:35 -0600)]
utf8.c: Add info to commented-out -DU lines

This proved useful when I recently needed to use these for debugging

12 years agoregcomp.c: Reverse order of setting, for speed
Karl Williamson [Mon, 9 Jul 2012 22:17:40 +0000 (16:17 -0600)]
regcomp.c: Reverse order of setting, for speed

It's faster to append to an inversion list than to insert into the
middle.  The previous order of doing things guaranteed that the 2nd
thing done would be an insertion, hence slower than an append.  Now we
add the lowest ordinal character first, so there is a chance that both
will be appends

12 years agoperllocale: Mention that \n doesn't change for locales
Karl Williamson [Mon, 9 Jul 2012 21:12:36 +0000 (15:12 -0600)]
perllocale: Mention that \n doesn't change for locales

12 years agohandy.h: Remove duplicated test
Karl Williamson [Mon, 9 Jul 2012 20:30:29 +0000 (14:30 -0600)]
handy.h: Remove duplicated test

This test is duplicated in the called macro

12 years agohandy.h: White space only
Karl Williamson [Mon, 9 Jul 2012 20:28:11 +0000 (14:28 -0600)]
handy.h: White space only

This moves a #define next to similar ones, and removes some white space

12 years agoregcomp.c: Move table to wider scope
Karl Williamson [Mon, 9 Jul 2012 20:25:03 +0000 (14:25 -0600)]
regcomp.c: Move table to wider scope

This table will be used in future commits outside this block's scope

12 years agoregcomp.c: Silence compiler warning
Karl Williamson [Mon, 9 Jul 2012 19:59:09 +0000 (13:59 -0600)]
regcomp.c: Silence compiler warning

I suspect this being an IV stemmed from an earlier version.  It always
contains unsigneds

12 years agoregcomp.c: Change macro name to better indicate its purpose
Karl Williamson [Mon, 9 Jul 2012 19:54:13 +0000 (13:54 -0600)]
regcomp.c: Change macro name to better indicate its purpose

12 years agoOptimize a single character [class] into EXACTish
Karl Williamson [Sat, 7 Jul 2012 16:10:30 +0000 (10:10 -0600)]
Optimize a single character [class] into EXACTish

Things like /[s]/ or /[s]/i can be optimized as if they did not have the
brackets, /s/ or /s/i.

12 years agoregcomp.c: Extract some code into an inline function
Karl Williamson [Mon, 9 Jul 2012 19:10:00 +0000 (13:10 -0600)]
regcomp.c: Extract some code into an inline function

This code will be used in future commits in multiple places

12 years agoregcomp.c: shrink some optimized [class] nodes
Karl Williamson [Sat, 7 Jul 2012 17:46:40 +0000 (11:46 -0600)]
regcomp.c: shrink some optimized [class] nodes

Various bracketed character class specifications don't need the full
generality, and can be optimized into smaller, faster nodes.  Recent
commits, such as 3a64b5154fffec75126d34d25954f0aef30d9f8a have
introduced some such optimizations.  However, their commit messages are
wrong, in that they don't end taking up any less space than the original
ANYOF node, as there is no provision for giving it back, once reserved.

This commit corrects that for non-locale nodes.  Restructuring of the
code, more than I care to do now, would be required to extend this to
locale nodes.

Only optimizations that are determined in pass1 of the regex compilation
are eligible for this, as once the space is calculated, it is reserved
before pass2 begins.  There are now two sections where optimization is
done in this routine.  The final section is after all the data is
examined and processed, and we know exactly what is to be in the ANYOF
node.  Currently, most of this calculation processing is skipped in pass
1.  We could do everything in both passes, greatly slowing down the
first, in order to figure out the exact space requirements.

But instead, I've chosen to add a separate optimization section that
looks at only the optimizations that are easily computable in the
current first pass, and to apply those early, in time for the shrinking
to occur.  This commit adds that shrinking.

Locale nodes can't be shrunk because the code currently writes into
their larger buffer before this decision to optimize is made.  To
illustrate, say that the node is at the end of the regex, and the data
is written at x+20, within a generic locale ANYOF node's space.  Pass 1
doesn't write anything, but calculates the space needed.  At the point
that this commit addresses, we would shrink the amount of space to be
allocated to be allocated.  Then we carve out space for the regex from
the heap.  That x+20 could be pointing to something entirely different,
which Pass 2 would destroy.  This can be avoided by storing the stuff
that would be written into a temporary until the optimization decision
has been made.  But there is extra work involved in doing this, that I
don't think is worth it at this time.

The same problem doesn't occur in non-locale situations, even though the
flags field of the node is written before the optimization decision.
This is because every node has the space for a flags field, so it just
gets overwritten as necessary when the optimization is done.

12 years agoregcomp.c: Delay some initialization until needed
Karl Williamson [Sat, 7 Jul 2012 17:42:30 +0000 (11:42 -0600)]
regcomp.c: Delay some initialization until needed

This delays the initialization of the bitmap in ANYOF nodes until just
before it is needed, and to after where we make a decision to optimize
that node to a node which takes less space.  Currently, the space is
not given up, once reserved in pass 1, so the write is harmless.  This
will allow a future commit to shrink the space.

12 years agoregcomp.c: Remove duplicate assignments
Karl Williamson [Sat, 7 Jul 2012 14:15:56 +0000 (08:15 -0600)]
regcomp.c: Remove duplicate assignments

These variables are already set to the same values a few lines up.

12 years agohandy.h: Move bit shifting into base macro
Karl Williamson [Tue, 3 Jul 2012 04:18:47 +0000 (22:18 -0600)]
handy.h: Move bit shifting into base macro

This changes the #defines to be just the shift number, while doing
the shifting in the macro that the number is passed to.  This will prove
useful in future commits

12 years agohandy.h: Renumber character class bits
Karl Williamson [Tue, 3 Jul 2012 03:39:56 +0000 (21:39 -0600)]
handy.h: Renumber character class bits

These are renumbered so that the ones that correspond to character
classes in regcomp.h are related numerically as well.  This will prove
useful in future commits.

12 years agohandy.h: Reorder some #defines
Karl Williamson [Tue, 3 Jul 2012 03:31:31 +0000 (21:31 -0600)]
handy.h: Reorder some #defines

They are now ordered in the same order as the similar #defines in
regcomp.h.  This will be useful in later commits

12 years agohandy.h: l1_charclass.h: Add bit for matching ASCII
Karl Williamson [Tue, 3 Jul 2012 03:09:18 +0000 (21:09 -0600)]
handy.h: l1_charclass.h: Add bit for matching ASCII

This does not replace the isASCII macro definition, as I think the
current one is more efficient than this one provides.  But future
commits will rely on all the named character classes (e.g.,
/[[:ascii:]]/) having a bit, and this is the only one missing.

12 years agohandy.h: refactor some macros to use a new one in common.
Karl Williamson [Tue, 3 Jul 2012 03:04:16 +0000 (21:04 -0600)]
handy.h: refactor some macros to use a new one in common.

This creates a new, unpublished, macro to implement most of the other
macros.  This macro will be useful in future commits.

12 years agoregcomp.c: Extract code to inline function
Karl Williamson [Sat, 7 Jul 2012 03:41:07 +0000 (21:41 -0600)]
regcomp.c: Extract code to inline function

Future commits will use this paradigm in additional places, so extract
it to a function, so they all do things right.  This isn't a great API,
but it works for the few places this will be called.

12 years agoregcomp.sym: Correct and add comments
Karl Williamson [Fri, 6 Jul 2012 21:14:19 +0000 (15:14 -0600)]
regcomp.sym: Correct and add comments

12 years agoregen/regcomp.pl: Allow ';' in comments
Karl Williamson [Fri, 6 Jul 2012 17:31:11 +0000 (11:31 -0600)]
regen/regcomp.pl: Allow ';' in comments

If a comment contained a semi-colon, the regular expression's greedy
quantifier would think the portion of the comment before it was part of
the data to be processed

12 years agoregcomp.c: Optimize [^\n] into \N
Karl Williamson [Wed, 4 Jul 2012 21:22:59 +0000 (15:22 -0600)]
regcomp.c: Optimize [^\n] into \N

This optimization is a big win, as it takes less space, and completely
avoids any swash hash creation, and use.

12 years agoregcomp.c: White-space, comments only
Karl Williamson [Wed, 4 Jul 2012 20:49:22 +0000 (14:49 -0600)]
regcomp.c: White-space, comments only

This fixes some nits in a some comments, adds some comments, but mostly
just indents and outdents to reflect a new outer block, and to fit
within 80 columns

12 years agoregcomp.c: Refactor new charclass optimizations
Karl Williamson [Wed, 4 Jul 2012 20:16:29 +0000 (14:16 -0600)]
regcomp.c: Refactor new charclass optimizations

Commits 3a64b5154fffec75126d34d25954f0aef30d9f8a and
3172e3fd885a9c54105d3b6156f18dc761fe29e5 introduced some optimizations
into the handling of bracketed character classes with just a single
element.

In working on other optimizations, I realized that it would be better to
put these all in one spot, instead of doing things partially and setting
flags to pass to other areas of the routine.

This commit moves all the processing to a single spot, which gets called
only after we know that there will be just one element in the character
class.

I also realized that the [0-9] optimization should strictly not be done
under locale.  There is no test for this, as actually this would only be
a problem if a locale was in violation of the C standard.  But (most) of
the rest of Perl doesn't assume that locales are well-behaved in this
regard, so now this code doesn't either.

12 years agoregcomp.c: Use data structure properties to remove tests
Karl Williamson [Tue, 3 Jul 2012 02:50:33 +0000 (20:50 -0600)]
regcomp.c: Use data structure properties to remove tests

The ANYOF_foo character class #defines really form an enum, with the
property that the regular one is n, and its complement is n+1.  So
we can replace the tests in each case: of the switch, with a single test
afterwards.

12 years agoregcomp.c: Use macro for clarity
Karl Williamson [Sun, 1 Jul 2012 18:37:04 +0000 (12:37 -0600)]
regcomp.c: Use macro for clarity

It's kind of obscure what this test is doing, so change it into a macro
to clarify things

12 years agoregcomp.c: Only try to fold foldable chars
Karl Williamson [Thu, 28 Jun 2012 23:13:18 +0000 (17:13 -0600)]
regcomp.c: Only try to fold foldable chars

This uses the new table that a previous commit caused mktables to
generate which more precisely determines which Unicode characters
participate in folds.  This avoids trying to calculate a fold that we
can know beforehand doesn't have a fold.

12 years agomktables: Generate new table for foldable chars
Karl Williamson [Thu, 28 Jun 2012 19:32:17 +0000 (13:32 -0600)]
mktables: Generate new table for foldable chars

This table consists of all characters that participate in any way in a
fold in the current Unicode version.  regcomp.c currently uses the Cased
property as a proxy for these.  This information is used to limit the
number of characters whose folds have to be dealt with in compiling
bracketed regex character classess.   It turns out that Cased contains
more than 1300 more code points than actually do appear in folds, which
means potential extra work for compiling.  Hence this patch allows that
work to be avoided.

There are a few characters in this new table that aren't in Cased, which
are potential bugs in the old way of doing things.  In Unicode 6.1,
these are:  U+02BC MODIFIER LETTER APOSTROPHE, U+0308 COMBINING
DIAERESIS, U+0313 COMBINING COMMA ABOVE, and U+0342 COMBINING GREEK
PERISPOMENI.  I can't figure out how these might be currently causing a
bug, but this patch fixes any such.

12 years agoregcomp.c: Correct outdated comment
Karl Williamson [Wed, 27 Jun 2012 23:18:20 +0000 (17:18 -0600)]
regcomp.c: Correct outdated comment

12 years agoregcomp.c: Change and comment a problematic #define
Karl Williamson [Wed, 27 Jun 2012 22:57:25 +0000 (16:57 -0600)]
regcomp.c: Change and comment a problematic #define

As noted in the new comments, there is no out-of-bounds code point, so
this should not be used as such; and it turns out, it really isn't.
But this is a fall-back in case code is changed to not set the variable
that this initializes, and the comment will prevent someone else from
wasting their time trying to figure out why this is like this.