This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
9 years agoconst + static vtables in threads::shared
Daniel Dragan [Mon, 5 Jan 2015 06:44:59 +0000 (01:44 -0500)]
const + static vtables in threads::shared

This makes threads::shared have no non-NULL initialized RW static data.
Uninitialized and NULL filled RW data like PL_sharedsv_space and
prev_signal_hook remain, but on some OSes/CCs (Win32 with special tweaks),
this means that now the RW data section in threads::shared shared library
has no disk representation. Static the remaining RW vars to trim the
symbol table on non-Win32.

9 years agoconst a PERLIO vtable in PerlIO::encoding
Daniel Dragan [Mon, 5 Jan 2015 06:27:11 +0000 (01:27 -0500)]
const a PERLIO vtable in PerlIO::encoding

This makes PerlIO::encoding's shared library free of any perl caused RW
static data.

9 years agomake minitest (mostly) work on Win32
Tony Cook [Tue, 6 Jan 2015 00:24:53 +0000 (11:24 +1100)]
make minitest (mostly) work on Win32

The only test left failing is op/glob.t, since I couldn't find the
cause of the failure

9 years agominitest: run the sames tests on win32 as on POSIXish systems
Tony Cook [Tue, 9 Dec 2014 04:13:04 +0000 (15:13 +1100)]
minitest: run the sames tests on win32 as on POSIXish systems

9 years agominitest: miniperl on win32 always displays the x86 arch, so skip testing it
Tony Cook [Tue, 9 Dec 2014 04:06:05 +0000 (15:06 +1100)]
minitest: miniperl on win32 always displays the x86 arch, so skip testing it

9 years agominitest op/magic.t: skip the env_is() tests on Win32 miniperl
Tony Cook [Tue, 9 Dec 2014 03:38:38 +0000 (14:38 +1100)]
minitest op/magic.t: skip the env_is() tests on Win32 miniperl

Since 1070c8d6 env_is() requires the Win32 module on Win32, which
miniperl can't load

9 years agoWin32 minitest: -k is never available on Win32
Tony Cook [Mon, 8 Dec 2014 04:11:29 +0000 (15:11 +1100)]
Win32 minitest: -k is never available on Win32

Given the structure of the tests and the code, I can only assume
S_ISVTX is only unavailable on Win32 out of the systems we run
minitest on.

9 years agominiperl on Win32 doesn't have fork()
Tony Cook [Mon, 8 Dec 2014 02:27:35 +0000 (13:27 +1100)]
miniperl on Win32 doesn't have fork()

9 years agosome socket functions aren't available under Win32 miniperl
Tony Cook [Mon, 8 Dec 2014 01:56:07 +0000 (12:56 +1100)]
some socket functions aren't available under Win32 miniperl

This only skips for bind, connect, accept() and select().

Other functions are tested in coreamp.t, but either aren't called with
valid handles, so don't reach the "unimplemented" errors, or don't
trigger the errors for other reasons.

fixes: op/coreamp.t, op/sselect.t, op/tie_fetch_count.t

9 years agodisable Win32 sloppy stat in io/fs.t, io/stat.t
Tony Cook [Mon, 8 Dec 2014 00:44:52 +0000 (11:44 +1100)]
disable Win32 sloppy stat in io/fs.t, io/stat.t

8ce7a7e8b08f added a line to write_buildcustomize.pl to enable
${^WIN32_SLOPPY_STAT} in lib/buildcustomize.pl on Win32.

This meant the nlink value from stat wasn't being populated correctly
causing the link count tests to fail

9 years agouse textmode when opening scripts in miniperl to match perl
Tony Cook [Tue, 16 Dec 2014 06:05:18 +0000 (17:05 +1100)]
use textmode when opening scripts in miniperl to match perl

fixes io/data.t

This could be considered a bug in io/data.t, since it writes the scripts
in text mode, but making miniperl behave closer to perl may fix
other issues too.

9 years agobuild miniperl with PerlIO
Tony Cook [Tue, 16 Dec 2014 06:04:09 +0000 (17:04 +1100)]
build miniperl with PerlIO

Several tests use PerlIO layers (:utf8, :pop) without testing for it.

non-PerlIO builds were vaguely deprecated in 5.18.0 and can no longer be
enabled on POSIX systems through Configure, so making miniperl PerlIO
on Win32 is no big stretch

minitests failing now:

io/data.t
io/fs.t
op/coreamp.t
op/filetest.t
op/fork.t
op/glob.t
op/heredoc.t
op/magic.t
op/sselect.t
op/stat.t
op/tie_fetch_count.t

9 years agot/TEST: glob the supplied filenames on Win32
Tony Cook [Mon, 8 Dec 2014 00:01:34 +0000 (11:01 +1100)]
t/TEST: glob the supplied filenames on Win32

since Win32 perl doesn't glob by default

at this point the following tests fail:

io/dup.t
io/fs.t
io/open.t
io/perlio_leaks.t
op/coreamp.t
op/filetest.t
op/fork.t
op/fresh_perl_utf8.t
op/glob.t
op/heredoc.t
op/magic.t
op/read.t
op/readline.t
op/sselect.t
op/stat.t
op/substr.t
op/tie_fetch_count.t
op/write.t

9 years agouse TEST for minitest, same as POSIX systems
Tony Cook [Sun, 7 Dec 2014 23:48:32 +0000 (10:48 +1100)]
use TEST for minitest, same as POSIX systems

Test::Harness now requires IO at all times, which means it can't
be used with miniperl

many tests fail with minitest at this point

9 years agob.t: Fix test sequence numbers
Father Chrysostomos [Mon, 5 Jan 2015 22:13:05 +0000 (14:13 -0800)]
b.t: Fix test sequence numbers

I should have tested more thoroughly before pushing a462fa007.

9 years agofix test fail on unthreaded perl
Daniel Dragan [Mon, 5 Jan 2015 20:01:04 +0000 (15:01 -0500)]
fix test fail on unthreaded perl

../ext/B/t/b.t                          (Wstat: 65280 Tests: 0 Failed: 0)
  Non-zero exit status: 255
  Parse errors: No plan found in TAP output

part of [perl #123544]

9 years agoconst the custom op struct in Devel::Peek
Daniel Dragan [Mon, 5 Jan 2015 04:37:58 +0000 (23:37 -0500)]
const the custom op struct in Devel::Peek

This makes the Devel::Peek shared library free of perl caused RW static
data vars, and if CC/OS platform allows, removes RW data section from the
shared library.

9 years agopp.c pp_split GvAVn can't return NULL
Daniel Dragan [Mon, 5 Jan 2015 03:42:49 +0000 (22:42 -0500)]
pp.c pp_split GvAVn can't return NULL

clang optimized the function call free branch of GvAVn to skip the
"if (ary)" test, but the function call creation branch also will never
return NULL (but no CC knows that) so use goto to skip the test on both
halfs of GvAVn.

9 years agomake B psuedofork safe
Daniel Dragan [Mon, 5 Jan 2015 03:27:04 +0000 (22:27 -0500)]
make B psuedofork safe

Previously B incorrectly used MY_CXT since commit 89ca4ac7af (5.7.2),
there was a MY_CXT declared, but it was never cloned after a win32
psuedofork, negating the whole point of using MY_CXT. This was probably
an oversight since the old code didn't use CLONE method, and would have
been threadsafe only if the module was loaded after a psuedofork/ithread
creation. Rearrange my_cxt_t so there isn't an alignment gap between the 32
bit and 32/64 bit ptrs.

This patch does not address the current lack of CLONE method in
Opcode:: and in File::DosGlob . File::Glob was fixed in commit facf34ef48
DynaLoader in commit 8c472fc1d4 and re:: doesn't use MY_CXT anymore at all.

Failure message of the test before the fix was

not ok 88 - special SV table works after psuedofork
#   Failed test 'special SV table works after psuedofork'
#   at b.t line 229.
#          got: 'B::PVNV'
#     expected: 'B::SPECIAL'

9 years agoperldiag: Document ‘Bad symbol for scalar’
Father Chrysostomos [Mon, 5 Jan 2015 07:18:02 +0000 (23:18 -0800)]
perldiag: Document ‘Bad symbol for scalar’

Originally this was a separate message in gv.c, with an exception
listed in diag.t

d5713896ec merged several functions together, changing the exception
to ‘Bad symbol for %s’.

bb85b28a added diag_listed_as in the wrong place.

de6f7947 moved it to the right place, removing the diag.t entry.

But all this time ‘Bad symbol for scalar’ remained undocumented.

9 years agot/base/lex.t: Remove commented-out test
Father Chrysostomos [Mon, 5 Jan 2015 07:16:58 +0000 (23:16 -0800)]
t/base/lex.t: Remove commented-out test

It has been commented out since it was added in 2b92dfceaa9d.

9 years agocomplement can have OPpTARGET_MY
Father Chrysostomos [Mon, 5 Jan 2015 07:16:21 +0000 (23:16 -0800)]
complement can have OPpTARGET_MY

It always reads its argument out the outset and always returns its
target, so there is no reason its target cannot be a lexical.  (The
OPpTARGET_MY optimisation makes $lexical = <some op> have the op
write directly to the lexical; the assignment gets optimised away.)

9 years agoPut pthread in front of libswanted and add cl
H.Merijn Brand [Mon, 5 Jan 2015 11:33:49 +0000 (12:33 +0100)]
Put pthread in front of libswanted and add cl

If pthread is found on HP-UX, it is required to be in front and
libcl is required too

9 years agoUpdate Module-Metadata to CPAN version 1.000025
Chris 'BinGOs' Williams [Sun, 4 Jan 2015 19:09:11 +0000 (19:09 +0000)]
Update Module-Metadata to CPAN version 1.000025

  [DELTA]

1.000025  2015-01-04 18:56:00Z
  - evaluate version assignment in a clean environment, to fix assignment in a
    block (RT#101095)

9 years agoreg_nocapture.t: Skip %+ tests under miniperl
Father Chrysostomos [Sun, 4 Jan 2015 02:55:49 +0000 (18:55 -0800)]
reg_nocapture.t: Skip %+ tests under miniperl

9 years agoperl.h:MY_CXT_CLONE: void *, not void **
Father Chrysostomos [Sun, 4 Jan 2015 02:53:29 +0000 (18:53 -0800)]
perl.h:MY_CXT_CLONE: void *, not void **

C++ fails otherwise, and PL_my_cxt_list is void ** so individual
elephants (aka elements) should be void *.

9 years agoconst a table in B
Daniel Dragan [Sat, 3 Jan 2015 05:15:55 +0000 (00:15 -0500)]
const a table in B

B is now free of all RW static data except for my_cxt_index

9 years agoreorder MY_CXT_CLONE for less memory reads
Daniel Dragan [Fri, 2 Jan 2015 23:59:06 +0000 (18:59 -0500)]
reorder MY_CXT_CLONE for less memory reads

Nn VC 2003 32, taking a very simple CLONE XSUB, specifically
Time::HiRes::CLONE, shows a reduction from 0x53 to 0x47 bytes of machine
code. This is because my_cxt_index has to be reread after the memcpy
function call incase my_cxt_index was changed by memcpy (GCC usually
inlines short fixed length memcpys, on VC P5P perl, the option to inline
memcpy is off), also the new my_cxtp does not need to be saved in a non-vol
anymore, previously my_cxtp had to be copied to a non-vol for it be
available after the memcpy function call. In a simple XSUB like the one
mentioned here, saving and restoring the non-vol register is also
removed.

See details in perl #123534.

9 years agopad.c: Obsolete comment
Father Chrysostomos [Sat, 3 Jan 2015 04:20:17 +0000 (20:20 -0800)]
pad.c: Obsolete comment

This comment, added by 3291825f, was made obsolete by 0f94cb1f.

9 years agoFix CvOUTSIDE for state subs in predeclared subs
Father Chrysostomos [Sat, 3 Jan 2015 04:15:10 +0000 (20:15 -0800)]
Fix CvOUTSIDE for state subs in predeclared subs

use 5.018;
use experimental 'lexical_subs';
$::x = "global";
sub x;
sub x {
    state $x = 42;
    state sub x { print eval '$x', "\n" }
    \&x;
}
x()->();
__END__

Output:

Segmentation fault: 11

Because this line in pad.c:S_findpadlex:

1141     const PADLIST * const padlist = CvPADLIST(cv);

is trying to read this SV:

SV = UNKNOWN(0x76) (0xaa170e4fd) at 0x10060c928
  REFCNT = 1697135711
  FLAGS = (PADSTALE,TEMP,GMG,SMG,IOK,pNOK,pPOK,UTF8)

(i.e., gibberish).

During compilation, ‘sub x{’ creates a new CV.  When the sub is about
to be installed (when the final ‘}’ is reached), the existing stub
must be reused.  So everything is copied from the new CV (PL_compcv)
to the stub.  Also, any CvOUTSIDE pointers of nested subs get updated
to point to the erstwhile stub.

State subs were not getting their CvOUTSIDE pointers updated.  This
patch implements that.

9 years agoTest-Simple Version Bump, 1.301001_096 (RC16)
Chad Granum [Sat, 3 Jan 2015 21:04:16 +0000 (13:04 -0800)]
Test-Simple Version Bump, 1.301001_096 (RC16)

Mainly fixes for older perls. Still important to bring this in line with
what is on cpan.

9 years agocheck more carefully for empty negative lookahead
Hugo van der Sanden [Tue, 16 Dec 2014 14:50:09 +0000 (14:50 +0000)]
check more carefully for empty negative lookahead

We replace with OPFAIL, but if we wait till study_chunk() to do that it
gets rather more complicated.

9 years agoUpdate IO-Socket-IP to CPAN version 0.35
Chris 'BinGOs' Williams [Sat, 3 Jan 2015 15:56:34 +0000 (15:56 +0000)]
Update IO-Socket-IP to CPAN version 0.35

  [DELTA]

0.35    2015/01/02 19:45:20
        [BUGFIXES]
         * Restore blocking mode after timeout connect immediate success
           (RT100947)
         * Avoid CORE:: prefixing so global override modules work (RT101174)
         * Ensure that ->peer{host,port,hostname,service} never die even when
           unconnected (RT98759)

9 years agoRevert "Fix PerlIO vtables on VMS."
Craig A. Berry [Sat, 3 Jan 2015 03:27:21 +0000 (21:27 -0600)]
Revert "Fix PerlIO vtables on VMS."

This reverts commit 0c2c3d000e799a35bdc2bdd24feaf77cf854a2dd.

It's not needed after 400638aa931c47.

9 years agoDitch the custom extern/const model on VMS.
Craig A. Berry [Sat, 3 Jan 2015 00:42:31 +0000 (18:42 -0600)]
Ditch the custom extern/const model on VMS.

We've been using globaldef/globalref for global data since eons
ago.  It was a requirement for the ancient and long-defunct VAXC
compiler (not to be confused with DEC C for OpenVMS VAX), but
DEC/Compaq/HP C supports extern and const pretty much the way
everybody else does, and has for many years. HP C also supports
globaldef/globalref for backward compatibility, but the C++ compiler
does not, so continuing to use it means two different models for
C and C++.

While there is a slight theoretical benefit to using the old model
and its fine-grained control of program section attributes and
having all the read-write variables in one program section and all
the read-only variables in another, there is no measureable
performance or code size benefit, and being different just isn't
worth the aggravation.

So let's resign ourselves to having a separate program section in
the shareable image for each global item and make a couple of places
in the code easier on everyone's eyeballs and less likely to collide
with other work.

9 years agoSimplify PIC specification in perlshr.exe.
Craig A. Berry [Fri, 2 Jan 2015 15:25:05 +0000 (09:25 -0600)]
Simplify PIC specification in perlshr.exe.

PIC has no meaning on Alpha as all code generated by the compiler
is position independent.  So only specify it for VAX.  This allows
us to get rid of the test for whether we are on Itanium.

9 years agoExplicitly name linker map on VMS.
Craig A. Berry [Fri, 2 Jan 2015 15:21:00 +0000 (09:21 -0600)]
Explicitly name linker map on VMS.

By default the linker takes the base name of the first object file
and uses that when creating the name of the linker map file, which
means we've been getting a file named dynaloader.map for the main
shareable image map.  Name it after the target instead.

9 years agoRemove dead line of code from vms/test.com.
Craig A. Berry [Fri, 2 Jan 2015 15:17:57 +0000 (09:17 -0600)]
Remove dead line of code from vms/test.com.

Hasn't been needed since 34b5aed4c569.

9 years agoFix PerlIO vtables on VMS.
Craig A. Berry [Thu, 1 Jan 2015 15:02:37 +0000 (09:02 -0600)]
Fix PerlIO vtables on VMS.

f0e5c859d36afe5 broke the build because it caused the PerlIO_funcs
declarations to be const in perlio.h and EXTPERLIO in perliol.h
and on VMS, EXTPERLIO was EXTCONST which is globalref.  The compiler
considers globalref and const to be incompatible.

As a workaround, make EXTPERLIO "extern const" on VMS only.  The
whole custom global data model on VMS probably needs a rethink,
but this gets the build working again.

9 years agoUpdate ExtUtils-Manifest to CPAN version 1.70
Chris 'BinGOs' Williams [Wed, 31 Dec 2014 21:54:07 +0000 (21:54 +0000)]
Update ExtUtils-Manifest to CPAN version 1.70

  [DELTA]

1.70  2014-12-31
  - also skip _eumm, an artifact of ExtUtils::MakeMaker 7.05*
  - avoid unreliable permissions tests on cygwin

9 years agoPerldelta for /n regexp flag. Also ?: to C<?:> in perlre.pod.
Matthew Horsfall [Wed, 31 Dec 2014 16:05:57 +0000 (11:05 -0500)]
Perldelta for /n regexp flag. Also ?: to C<?:> in perlre.pod.

9 years agoRemove sources of "unreferenced label" warning on Win32
Steve Hay [Tue, 30 Dec 2014 12:00:54 +0000 (12:00 +0000)]
Remove sources of "unreferenced label" warning on Win32

and then remove the disabling of that warning.

9 years agoRemove redundant -I..\lib arguments from some Win32 makefile command-lines
Steve Hay [Wed, 31 Dec 2014 13:43:52 +0000 (13:43 +0000)]
Remove redundant -I..\lib arguments from some Win32 makefile command-lines

Invocations of $(PERLEXE) from win32\ do not need -I..\lib since $(PERLEXE)
is ..\perl.exe, which will pick up the lib\ folder in ..\ anyway.

Invocations of perl.exe from t\ (which may be a copy of either perl.exe or
miniperl.exe from the top-level folder) also do not need -I..\lib since
they all run the harness program, which fixes up @INC with exactly that
..\lib folder in a BEGIN block anyway.

9 years agomake win32 harness process use tested perl binary
Daniel Dragan [Tue, 23 Dec 2014 09:02:33 +0000 (04:02 -0500)]
make win32 harness process use tested perl binary

On Unix /t/perl is a symlink to /perl and the OS knows they are the same
file. On Win32 perl.exe and perl5**.dll are copied from / to /t, and the OS
thinks they are 2 separate files (and they are on disk). Both Win32 and
Unix use MMIO and COW/inter-process sharing for their running binaries. On
Unix the symlink means the 2 perl binaries will be memory mapped to the
same physical memory when running. On Win32 they won't be since they are 2
separate files. It is a waste of CPU cache/physical memory for the Win32
harness process and the child .t processes to not share the same disk
file/phy mem/same binary. Previously only the XS DLLs in /lib/auto were
shared between harness process and child .t processes, now perl.exe and
perl5**.dll will be shared between the 2 processes. Copying /perl.exe to
/t/perl.exe is from 1st commit of current Makefile in commit 68dc074516
and predates Win32 perl running harness which is from commit 137443ea0a
Also fix the broken "-I.\lib" in test-notty in  makefile.mk . This problem
was discovered with VMMap. This patch is slightly related to
[perl #114704] .

9 years agoConfigure: silence ASan warnings
David Mitchell [Mon, 22 Dec 2014 21:36:14 +0000 (21:36 +0000)]
Configure: silence ASan warnings

When run under -fsanitize=undefined, some of the try.c's that are compiled
and executed give runtime warnings. Since the intent of these particular
executables is to probe beyond certain limits in order to determine those
limits, these warnings can be safely ignored.  So file them in /dev/null.

9 years agoFile::Glob: avoid qsort() on no entries
David Mitchell [Wed, 31 Dec 2014 11:16:06 +0000 (11:16 +0000)]
File::Glob: avoid qsort() on no entries

If a glob doesn't match anything, it will try to call qsort()
with a null pointer, and on my OS, qsort() marked as needing a non-null
arg, which clang 3.6 is now detecting.

9 years agoclone PL_cv_has_eval and PL_savebegin
David Mitchell [Tue, 23 Dec 2014 19:32:43 +0000 (19:32 +0000)]
clone PL_cv_has_eval and PL_savebegin

These two boolean vars weren't being cloned in new threads, and in
debugging builds were getting set to 0xab, which -fsanitize=undefined
regarded as no suitable value for a boolean.

9 years agosv_vcatpvfn_flags() avoid array bounds err
David Mitchell [Tue, 23 Dec 2014 10:38:01 +0000 (10:38 +0000)]
sv_vcatpvfn_flags() avoid array bounds err

clang -fsanitize=undefined is being a bit too clever for its own good
here.

The code looks something like

    U8 vhex[VHEX_SIZE];
    ...
    v = vhex + ...;
    if (v < vend) ...

The code itself is safe, but ASan detects if you've added a value
greater than the buffer size to vhex and whines.

I've changed it so that the conditional comes first and is done in such
a way that arbitrary values can't be added to vhex.

To reproduce:

    printf "%.1000a\n", 1;

gives

    sv.c:12327:34: runtime error: index 1000 out of bounds for type 'U8 [17]'

9 years agoasan_ignore: exclude S_expect_number()
David Mitchell [Mon, 22 Dec 2014 20:57:52 +0000 (20:57 +0000)]
asan_ignore: exclude S_expect_number()

This function numifies the field width string in something like
printf "%10f". It handles integer overflow itself, so suppress
ASan warnings, e.g.

sv.c:10716:26: runtime error: signed integer overflow: 922337203 * 10 cannot be represented in type 'int'

9 years agofix integer overflow in S_study_chunk().
David Mitchell [Mon, 22 Dec 2014 20:23:28 +0000 (20:23 +0000)]
fix integer overflow in S_study_chunk().

Don't increment delta if it's "infinity" (SSize_t_MAX)
Found by -fsanitize=undefined:

regcomp.c:4999:11: runtime error: signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'ssize_t' (aka 'long')

9 years agopack(): avoid << of negative values
David Mitchell [Mon, 22 Dec 2014 20:12:22 +0000 (20:12 +0000)]
pack(): avoid << of negative values

Treat the string as U8* rather than char* when doing all the
bit shifts for uuencode. That stops these warnings under ASan:

    pp_pack.c:1890:34: runtime error: left shift of negative value -127
    pp_pack.c:1891:34: runtime error: left shift of negative value -126
    pp_pack.c:1899:34: runtime error: left shift of negative value -1
    pp_pack.c:1900:30: runtime error: left shift of negative value -31

9 years agoavoid integer overflow in pp_flop()
David Mitchell [Mon, 22 Dec 2014 20:04:59 +0000 (20:04 +0000)]
avoid integer overflow in pp_flop()

This;
    @a=(0x7ffffffffffffffe..0x7fffffffffffffff);

could produce under ASan:

    pp_ctl.c:1212:19: runtime error: signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'IV' (aka 'long')

so avoid post-incrementing the loop var on the last iteration.

This fix is more to shut ASan up than an actual bug, since the
bad value on the last iteration wouldn't actually be used.

9 years agofix more -IV_MIN negations
David Mitchell [Mon, 22 Dec 2014 16:25:59 +0000 (16:25 +0000)]
fix more -IV_MIN negations

Doing uv = -iv is undefined behaviour if iv happens to be IV_MIN.
This occurs in several places in the perl sources.

These ones were found by visual code inspection rather than
using -fsanitize=undefined, but I've added extra tests so that
-fsanitize could find them now.

9 years agofix undefined float behaviour in pack('f')
David Mitchell [Mon, 22 Dec 2014 09:34:40 +0000 (09:34 +0000)]
fix undefined float behaviour in pack('f')

The C standard says that the value of the expression (float)double_var is
undefined if 'the value being converted is outside the range of values
that can be represented'.

So to shut up -fsanitize=undefined:

    my $p = pack 'f', 1.36514538e67;

giving

    runtime error: value 1.36515e+67 is outside the range of representable values of type 'float'

explicitly handle the out of range values.
Something similar is already done under defined(VMS) && !defined(_IEEE_FP),
except that there it floors to +/- FLT_MAX rather than +/- (float)NV_INF.
I don't know which branch is best, and whether they should be merged.

This fix was suggested by Aaron Crane.

9 years agoavoid integer overflow in Perl_av_extend_guts()
David Mitchell [Sun, 21 Dec 2014 00:40:13 +0000 (00:40 +0000)]
avoid integer overflow in Perl_av_extend_guts()

There were two issues; first the 'overextend' algorithm (add a fifth of
the current size to the requested size) could overflow,
and secondly MEM_WRAP_CHECK_1() was being called with newmax+1,
which could overflow if newmax happened to equal SSize_t_MAX.

e.g.

    $a[0x7fffffffffffffff] = 1
    $a[5] = 1; $a[0x7fffffffffffffff] = 1

could produce under ASan:

    av.c:133:16: runtime error: signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long'
    av.c:170:7: runtime error: signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long'

9 years agoasan_ignore: exclude Perl_pp_left_shift()
David Mitchell [Sun, 21 Dec 2014 00:00:10 +0000 (00:00 +0000)]
asan_ignore: exclude Perl_pp_left_shift()

<< in perl maps directly to << in C, so don't warn about it when the RHS
is too big.

Fixes e.g.:

    print 1 << 64
    use integer; print 1 << 63

Typical ASan warning:

pp.c:1893:2: runtime error: left shift of 1 by 63 places cannot be represented in type 'IV' (aka 'long')

9 years agofix -IV_MIN negations
David Mitchell [Sat, 20 Dec 2014 16:40:52 +0000 (16:40 +0000)]
fix -IV_MIN negations

Doing uv = -iv is undefined behaviour if iv happens to be IV_MIN.
This occurs in several places in the perl sources.

Found by -fsanitize=undefined.

Here's a typical message:

sv.c:2864:7: runtime error: negation of -9223372036854775808 cannot be represented in type 'IV' (aka 'long'); cast to an unsigned type to negate this value to itself

9 years agofix integer overflow in S_study_chunk().
David Mitchell [Sat, 20 Dec 2014 15:30:01 +0000 (15:30 +0000)]
fix integer overflow in S_study_chunk().

It was calculating final_minlen + delta even when delta was already
SSize_t_MAX and final_minlen > 0.

This triggered it: /a(??{}){2}/.

Found by -fsanitize=undefined:

regcomp.c:5623:89: runtime error: signed integer overflow: 1 + 9223372036854775807 cannot be represented in type 'long'

9 years agohandy.h Cast to unsigned before doing xor
Karl Williamson [Sun, 14 Dec 2014 17:39:14 +0000 (10:39 -0700)]
handy.h Cast to unsigned before doing xor

It occurred to me that these macros could have an xor applied to a
signed value if the argument is signed, whereas the xor is expecting
unsigned.

9 years agoEmpty \N{} in regex pattern should force /d to /u
Karl Williamson [Mon, 22 Dec 2014 05:02:30 +0000 (22:02 -0700)]
Empty \N{} in regex pattern should force /d to /u

\N{} is for Unicode names, even if the name is actually omitted.
(Accepting an empty name is, I believe, an accident, and now is
supported only for backwards compatibility.)

9 years agoregcomp.c: comment and white-space changes only
Karl Williamson [Mon, 22 Dec 2014 04:47:04 +0000 (21:47 -0700)]
regcomp.c: comment and white-space changes only

9 years agowarnings.pm: Fix too long verbatim lines
Karl Williamson [Wed, 31 Dec 2014 03:49:25 +0000 (20:49 -0700)]
warnings.pm: Fix too long verbatim lines

By not indentins verbatim text so much, we don't run over 79 columns.

9 years agoperlre: Fix too long verbatim line
Karl Williamson [Wed, 31 Dec 2014 03:48:26 +0000 (20:48 -0700)]
perlre: Fix too long verbatim line

9 years agolib/B/Deparse.pm: refactor a hash slightly
Karl Williamson [Wed, 31 Dec 2014 03:50:39 +0000 (20:50 -0700)]
lib/B/Deparse.pm: refactor a hash slightly

Two of the three uses of this hash want the result to be of the form
"\cX".  The other wants "^X".  This changes the hash to be the common
substring to all three, and then the proper prefix is added to each.

9 years agolib/B/Deparse.pm: Add comment
Karl Williamson [Tue, 30 Dec 2014 21:13:34 +0000 (14:13 -0700)]
lib/B/Deparse.pm: Add comment

9 years agolib/B/Deparse.pm: Generalize for non-ASCII platforms
Karl Williamson [Tue, 30 Dec 2014 21:04:10 +0000 (14:04 -0700)]
lib/B/Deparse.pm: Generalize for non-ASCII platforms

This makes ASCII platform-specific code generalized to non-ASCII.

9 years agolib/B/Deparse.pm: Output WARNING_BITS in binary
Karl Williamson [Tue, 30 Dec 2014 21:09:40 +0000 (14:09 -0700)]
lib/B/Deparse.pm: Output WARNING_BITS in binary

This binary value was being output as just another string, which would
cause the bit patterns that coincidentally coincided with letters to be
output as those.  This is not portable to EBCDIC, but outputting it as
\xXX is, which this commit does.  I chose to output in hex instead of
octal, as I think that is the more modern thing to do, and it's easier
for me to grok the larger values when they are in hex.

9 years agolib/B/Deparse.pm: Move hash to earlier in file
Karl Williamson [Tue, 30 Dec 2014 20:55:42 +0000 (13:55 -0700)]
lib/B/Deparse.pm: Move hash to earlier in file

No other change besides the move is done.  This is so the hash can be
used from another place than currently.

9 years agoperlpod: Latin1 pods need an =encoding
Karl Williamson [Mon, 29 Dec 2014 20:57:10 +0000 (13:57 -0700)]
perlpod: Latin1 pods need an =encoding

9 years agoregcomp.c: Fix [_A-Z] for EBCDIC
Karl Williamson [Thu, 25 Dec 2014 20:16:19 +0000 (13:16 -0700)]
regcomp.c: Fix [_A-Z] for EBCDIC

Special handling is required on EBCDIC for ranges that are subsets of
either a-z or A-Z.  This is triggered when both ends are literals.  It
is implemented by keeping a count of the literal endpoints, and when
that is two do the handling.  But the count was not getting reset, so
it could go to 3, 4, ... so the special handling would only get
triggered if the range was the first thing in the brackets,
like [A-Z], but not if there was something before it, like [_A-Z].  The
solution is to reset the counter appropriately each time through the
loop.  For the A-Z range, the ASCII-equivalent characters wrongly
matched were backslash and '}'.  For a-z, it was '~'

9 years agoregcomp.c: Replace dead code with NOT_REACHED
Karl Williamson [Thu, 25 Dec 2014 20:15:58 +0000 (13:15 -0700)]
regcomp.c: Replace dead code with NOT_REACHED

9 years agofix a broken optimization in win32/config_h.PL to stop excessive rebuilding
Daniel Dragan [Sun, 28 Dec 2014 20:59:38 +0000 (15:59 -0500)]
fix a broken optimization in win32/config_h.PL to stop excessive rebuilding

In commit 137443ea0a config_h.PL was introduced. There is no ML archive
from that time of the actual patches or their rational. From day 1 of
config_h.PL for the root config.h, it didn't copy the new one config.h to
the normal location of config.h if the files matched. This prevents
redundant dirtying of all core moudules with the
"Makefile out-of-date with respect to "/make clean/rerunning of makefile.pl
/new make all cycle. But the optimization didn't work in practice since
the modules declare a dependency on /lib/CORE/config.h not /config.h.
Previously "touch"ing /win32/Makefile would trigger a mass rebuild,
even if config.h's contents are the same. Now only if the new after
"touch"ing /win32/makefile config.h is different from the old config.h
, will a mass rebuild of module be triggered. This makes reduced the
amount of time core devs have to spend to work on Win32 perl.

9 years agoAdd documentation for /n (non-capture) regexp flag.
Matthew Horsfall [Tue, 30 Dec 2014 00:21:39 +0000 (19:21 -0500)]
Add documentation for /n (non-capture) regexp flag.

9 years agolex_assign.t: Actually test chomp
Father Chrysostomos [Mon, 29 Dec 2014 14:24:12 +0000 (06:24 -0800)]
lex_assign.t: Actually test chomp

9 years agolex_assign.t: Correct (s)cho(m)p comments
Father Chrysostomos [Mon, 29 Dec 2014 14:22:07 +0000 (06:22 -0800)]
lex_assign.t: Correct (s)cho(m)p comments

The were backwards.  ‘s’ means a single item.

9 years agoop_private: Update note about targlex and trans
Father Chrysostomos [Mon, 29 Dec 2014 14:16:33 +0000 (06:16 -0800)]
op_private: Update note about targlex and trans

9 years agoEnable OPpTARGET_MY optimisation for cmp/<=>
Father Chrysostomos [Mon, 29 Dec 2014 14:13:48 +0000 (06:13 -0800)]
Enable OPpTARGET_MY optimisation for cmp/<=>

We can only do it for <=> under ‘use integer’.

The non-integer <=> will push undef on to the stack.  Enabling
the optimisation for it would cause \($lexical = $x <=> "nan") to
leave $lexical with its previous value and return a reference to
&PL_sv_undef.

9 years agoFix breakage of 780fcc9
Karl Williamson [Tue, 30 Dec 2014 01:27:42 +0000 (02:27 +0100)]
Fix breakage of 780fcc9

I got confused in writing this: the global needs to be cleared always,
and set to NULL.

9 years agoregexec.c: Suppress warning messages
Karl Williamson [Tue, 30 Dec 2014 01:39:40 +0000 (18:39 -0700)]
regexec.c: Suppress warning messages

A message on some compilers is geing generated that two variables may be
unininitialized.  In fact there is no path through that uses them
thusly, but initialize them anyway where the compiler is wrong.

9 years agoRaise warning on multi-byte char in single-byte locale
Karl Williamson [Mon, 29 Dec 2014 20:15:57 +0000 (13:15 -0700)]
Raise warning on multi-byte char in single-byte locale

See http://nntp.perl.org/group/perl.perl5.porters/211909

Something is quite likely wrong with the logic if say in a Greek locale,
Unicode characters (especially Greek ones) are encountered.  The same
character will be represented by two different code points.  This
warning alerts the user to this undesirable state of affairs.

9 years agoperllocale: Nits
Karl Williamson [Mon, 29 Dec 2014 19:57:02 +0000 (12:57 -0700)]
perllocale: Nits

9 years agofoldEQ_utf8(): Add some internal flags
Karl Williamson [Mon, 29 Dec 2014 18:01:59 +0000 (11:01 -0700)]
foldEQ_utf8(): Add some internal flags

The comments explain their purpose

9 years agolib/warnings/utf8: Add missing tests
Karl Williamson [Sat, 27 Dec 2014 02:37:50 +0000 (19:37 -0700)]
lib/warnings/utf8: Add missing tests

lcfirst had been overlooked, and we had failed to test that turning off
warnings actually suppresses them.

9 years agoSimplify foldEQ_utf8
Karl Williamson [Sat, 27 Dec 2014 01:31:04 +0000 (18:31 -0700)]
Simplify foldEQ_utf8

This moves the uncommon case of handling inputs under non-UTF-8 locales
out of this function to the functions it calls, which already have the
logic to handle it.  This simplifies this function, cutting a couple
branches each time through the loop from the common usage.

The locale handling is slowed down somewhat, but even if that were a
concern, another simpler function is normally used for locale handling.
This gets called only when one or both of the comparison strings is
UTF-8, which should be comparatively rare for non-UTF8 locales.

9 years agoutf8.c: Use OP_DESC instead of passing string.
Karl Williamson [Sat, 27 Dec 2014 01:20:14 +0000 (18:20 -0700)]
utf8.c: Use OP_DESC instead of passing string.

OP_DESC is simpler and more general.

9 years agoutf8.c: Fix potential fold bug
Karl Williamson [Sat, 27 Dec 2014 00:47:37 +0000 (17:47 -0700)]
utf8.c: Fix potential fold bug

The function _to_uni_fold_flags() supposedly had the ability to do
folding based on the current locale, if the correct flag is passed.
However, it didn't actually do that, returning a non-locale fold
instead.  Fortunately, this is an undocumented capability (actually, the
whole function is undocumented), and no current calls to it used the
flag.  This commit causes it to work.

9 years agoutf8.c: Add some function parameter assertions
Karl Williamson [Fri, 26 Dec 2014 22:41:33 +0000 (15:41 -0700)]
utf8.c: Add some function parameter assertions

Currently these are not violated, but this guards against future
mistakes.

9 years agoregexec.c: Move goto label to avoid redundant work
Karl Williamson [Fri, 19 Dec 2014 05:21:21 +0000 (22:21 -0700)]
regexec.c: Move goto label to avoid redundant work

This causes a goto to skip work that has already been done.

9 years agoregexec.c: White-space only
Karl Williamson [Fri, 26 Dec 2014 23:08:28 +0000 (16:08 -0700)]
regexec.c: White-space only

9 years agoDon't raise 'poorly supported' locale warning unnecessarily
Karl Williamson [Thu, 18 Dec 2014 20:29:51 +0000 (13:29 -0700)]
Don't raise 'poorly supported' locale warning unnecessarily

Commit 8c6180a91de91a1194f427fc639694f43a903a78 added a warning message
for when Perl determines that the program's underlying locale just
switched into is poorly supported.  At the time it was thought that this
would be an extremely rare occurrence.  However, a bug in HP-UX -
B.11.00/64 causes this message to be raised for the "C" locale.  A
workaround was done that silenced those.  However, before it got fixed,
this message would occur gobs of times executing the test suite.  It was
raised even if the script is not locale-aware, so that the underlying
locale was completely irrelevant.  There is a good prospect that someone
using an older Asian locale as their default would get this message
inappropriately, even if they don't use locales, or switch to a
supported one before using them.

This commit causes the message to be raised only if it actually is
relevant.  When not in the scope of 'use locale', the message is stored,
not raised.  Upon the first locale-dependent operation within a bad
locale, the saved message is raised, and the storage cleared.  I was
able to do this without adding extra branching to the main-line
non-locale execution code.  This was done by adding regnodes which get
jumped to by switch statements, and refactoring some existing C tests so
they exclude non-locale right off the bat.

These changes would have been necessary for another locale warning that
I previously agreed to implement, and which is coming a few commits from
now.

I do not know of any way to add tests in the test suite for this.  It is
in fact rare for modern locales to have these issues.  The way I tested
this was to temporarily change the C code so that all locales are viewed
as defective, and manually note that the warnings came out where
expected, and only where expected.

I chose not to try to output this warning on any POSIX functions called.
I believe that all that are affected are deprecated or scheduled to be
deprecated anyway.  And POSIX is closer to the hardware of the machine.

For convenience, I also don't output the message for some zero-length
pattern matches.  If something is going to be matched, the message will
likely very soon be raised anyway.

9 years agoAdd regex nodes for locale
Karl Williamson [Thu, 18 Dec 2014 17:42:30 +0000 (10:42 -0700)]
Add regex nodes for locale

These will be used in a future commit to distinguish between /l patterns
vs non-/l.

9 years agoregcomp.c, regexec.c: Vertically align ternary operators
Karl Williamson [Thu, 18 Dec 2014 21:03:09 +0000 (14:03 -0700)]
regcomp.c, regexec.c: Vertically align ternary operators

For clarity

9 years agoNits in comments
Karl Williamson [Thu, 18 Dec 2014 20:32:21 +0000 (13:32 -0700)]
Nits in comments

9 years agoAdd support for new warning categories outside of "all"
Ævar Arnfjörð Bjarmason [Mon, 29 Dec 2014 20:04:01 +0000 (21:04 +0100)]
Add support for new warning categories outside of "all"

When someone suggests a new warning on p5p it always often up being
argued about on the basis that it'll break existing code, and that we
shouldn't add warnings for possibly legitimate code just because it's
unusual or odd.

As I pointed out in a discussion about RT #121025 (see [1]) we only keep
having this discussion because until now we've had no facility to add
new warnings outside of the default set that'll be retroactively enabled
for everything that does 'use warnings'. This patch introduces such a
facility.

As a proof of concept I'm adding a warning for something that was added
as a warning in the past, but pulled out because it was deemed too
controversial at the time: warning about the use of grep in void
context.

That warning was added back in v5.10.0-218-g74295f0 but quickly pulled
out in v5.10.0-230-gf5df478. See [2] for the discussion about it at the
time.

Now if you do:

    use warnings;
    grep /42/, (1,2);

You'll get no warnings as before, but if you do:

    use warnings qw(extra); # Or its sole subcategory: void_unusual
    grep /42/, (1,2);

You'll get a warning about "Unusual use of grep in void context". To
turn off this warning once you've turned it on it's *not* sufficient to
do:

    no warnings;

You need to do:

    no warnings qw(pedantic);

Or:

    no warnings qw(everything);

I'm willing to change that, but first we should ask ourselves whether
this should continue to remain a symmetric operation:

    {use,no} warnings ['all'];

There's more elaboration on how this works in the changes I'm making to
the perldelta and the warnings documentation. But briefly this should be
100% backwards compatible, but allow us to have our cake and eat it too
in the future by adding new warnings without imposing them on existing
code written against older perl versions (unless that code explicitly
requested to get new warnings as they upgrade perl).

The patch to the warnings.pm documentation lays out a backwards
compatibility policy for warnings, we promise that we'll continue the
status quo with the "all" category, but for other categories (including
future additions) we'll make such promises on a per-category basis.

TODO: I wanted to come up with some more general facility for being able
to add these new warnings without altering the behavior of the -w and -W
switches. I.e. now we'll emit this, as intended:

    $ ./perl -Ilib -w -e 'grep /42/, (1,2)'
    $ ./perl -Ilib -W -e 'grep /42/, (1,2)'
    $ ./perl -Ilib -e 'use warnings; grep /42/, (1,2)'
    $ ./perl -Ilib -e 'use warnings "extra"; grep /42/, (1,2)'
    Unusual use of grep in void context at -e line 1.

I.e. we don't want -w and -W to mean "use warnings 'everything'", it
should continue to mean "use warnings 'all'". But due to how they're
implemented I couldn't find an easy way to generalize this. Right now
I'm just hardcoding an exception to the new warning category I've added
outside "all" for these warnings.

That should be followed-up with a more general solution, but for now if
we only have a few of these catogeries we should be fine.

This patch incorporates work from Andreas Guðmundsson
<andreasg@nasarde.org> who picked up an earlier version of mine and
figured out the change being made to mg.c here. That change removes an
optimization in the ${^WARNING_BITS} magic which might make things a tad
slower.

1. https://rt.perl.org/Ticket/Display.html?id=121025#txn-1276663
2. http://www.nntp.perl.org/group/perl.perl5.porters/2007/12/msg131922.html

9 years agoMore CUSTOMIZED updates:
Steve Hay [Mon, 29 Dec 2014 15:22:43 +0000 (15:22 +0000)]
More CUSTOMIZED updates:

- The Encode change already has a CPAN RT ticket, so note it here.
- The Socket changes were assimilated by v2.016
- The autodie changes were assimilated by v2.26

9 years agoCall FETCH once for values in {...}
Father Chrysostomos [Mon, 29 Dec 2014 07:13:26 +0000 (23:13 -0800)]
Call FETCH once for values in {...}

I broke this inadvertently in v5.17.5-55-g3ed356d while fixing a
memory leak.

9 years agot/op/caller.t: Remove hardcoded $warnings::BYTES in favor of using $warnings::BYTES
Ævar Arnfjörð Bjarmason [Mon, 29 Dec 2014 12:44:52 +0000 (13:44 +0100)]
t/op/caller.t: Remove hardcoded $warnings::BYTES in favor of using $warnings::BYTES

This was originally hardcoded here in perl-5.8.0-909-g75b6c4c but since
then in numerous subsequent commits starting with v5.13.9-546-g3a32947
we've been bumping this number as we increase the number of warning
bits.

Just use the variable from warnings.pm instead, we're already using
other variables from there.

9 years agopp.c:pp_quotemeta: No need for PUTBACK
Father Chrysostomos [Mon, 29 Dec 2014 06:39:45 +0000 (22:39 -0800)]
pp.c:pp_quotemeta: No need for PUTBACK

We don’t manipulate the stack pointer at all here.

9 years agoRemove PUTBACK/SPAGAIN from hash iter ops
Father Chrysostomos [Mon, 29 Dec 2014 06:38:00 +0000 (22:38 -0800)]
Remove PUTBACK/SPAGAIN from hash iter ops

These were added by perl-5a2-2-g463ee0b and perl-5.003-2-gc750a3e.  At
the time, hv_iternext and hv_iterval could reallocate the stack, but
hv_iterkey was safe.  perl-5.6.0-8537-g574c802 divorced the comments
about hv_iterkey from the lines containing hv_iterkey, making things a
bit confusing.  Somewhere along the road, all tied hash functionality
started being guarded with PUSHSTACK, so these hash functions won’t
reallocate the stack any more.

9 years agopp.c:pp_[ul]c(first): No need for PUTBACK
Father Chrysostomos [Mon, 29 Dec 2014 03:11:34 +0000 (19:11 -0800)]
pp.c:pp_[ul]c(first): No need for PUTBACK

We don’t manipulate the stack pointer at all here.