This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
8 years agoassert(key) before it is derefed.
Jarkko Hietaniemi [Wed, 24 Jun 2015 23:52:27 +0000 (19:52 -0400)]
assert(key) before it is derefed.

Coverity CID 104855.

8 years agoassert(perinterp_sv) before sv_setiv() derefs NULL.
Jarkko Hietaniemi [Thu, 25 Jun 2015 00:14:39 +0000 (20:14 -0400)]
assert(perinterp_sv) before sv_setiv() derefs NULL.

Coverity CID 104842.

8 years agoCheck success of store().
Jarkko Hietaniemi [Thu, 25 Jun 2015 00:00:55 +0000 (20:00 -0400)]
Check success of store().

Coverity CID 118699.

8 years agoThere is no SSize_t_size.
Jarkko Hietaniemi [Thu, 25 Jun 2015 01:58:51 +0000 (21:58 -0400)]
There is no SSize_t_size.

Coverity CID 104775.

Seemed to be the only one.

8 years agoIf IVSIZE == LONGSIZE, long cannot be beyond IV_MIN/IV_MAX.
Jarkko Hietaniemi [Wed, 24 Jun 2015 02:28:57 +0000 (22:28 -0400)]
If IVSIZE == LONGSIZE, long cannot be beyond IV_MIN/IV_MAX.

It can be if LONGSIZE > IVSIZE, which should be rather rare
(since Perl aims for at least long, someone would have to
force IV to be 32 bits?)

Coverity CID 104770.

8 years agolseek() SEEK_SET pos may not be negative
Jarkko Hietaniemi [Fri, 26 Jun 2015 12:03:14 +0000 (08:03 -0400)]
lseek() SEEK_SET pos may not be negative

Coverity CID 104832

8 years agonl_langinfo code can be negative.
Jarkko Hietaniemi [Thu, 25 Jun 2015 12:41:13 +0000 (08:41 -0400)]
nl_langinfo code can be negative.

Coverity CID 104814.

8 years agostrtol and strtoul base should be [2, 36] or zero.
Jarkko Hietaniemi [Tue, 23 Jun 2015 11:21:03 +0000 (07:21 -0400)]
strtol and strtoul base should be [2, 36] or zero.

Coverity CID 104817 and CID 104836.

8 years agoshmat id can be invalid.
Jarkko Hietaniemi [Tue, 23 Jun 2015 11:30:58 +0000 (07:30 -0400)]
shmat id can be invalid.

Coverity CID 104852.

8 years agomsgrcv id can be invalid.
Jarkko Hietaniemi [Tue, 23 Jun 2015 11:32:43 +0000 (07:32 -0400)]
msgrcv id can be invalid.

Coverity CID 104825.

8 years agomsgsnd id can be invalid.
Jarkko Hietaniemi [Tue, 23 Jun 2015 11:26:46 +0000 (07:26 -0400)]
msgsnd id can be invalid.

Coverity CID 104833.

8 years agotcsetattr optional_actions can be invalid.
Jarkko Hietaniemi [Thu, 25 Jun 2015 12:56:59 +0000 (08:56 -0400)]
tcsetattr optional_actions can be invalid.

Coverity CID 104815.

8 years agotcsetattr fd can be bad.
Jarkko Hietaniemi [Tue, 23 Jun 2015 11:12:08 +0000 (07:12 -0400)]
tcsetattr fd can be bad.

Coverity CID 104815

8 years agodup2 fds can be bad.
Jarkko Hietaniemi [Tue, 23 Jun 2015 10:58:35 +0000 (06:58 -0400)]
dup2 fds can be bad.

Coverity CID 104812.

8 years agotcdrain fd can be bad.
Jarkko Hietaniemi [Tue, 23 Jun 2015 11:28:57 +0000 (07:28 -0400)]
tcdrain fd can be bad.

Coverity CID 104838.

8 years agotcflush/tcflow/tcsendbreak fd/action can be bad.
Jarkko Hietaniemi [Tue, 23 Jun 2015 10:55:45 +0000 (06:55 -0400)]
tcflush/tcflow/tcsendbreak fd/action can be bad.

Coverity CID 104807.

8 years agolseek fd can be bad.
Jarkko Hietaniemi [Tue, 23 Jun 2015 10:51:37 +0000 (06:51 -0400)]
lseek fd can be bad.

Coverity CID 104788

8 years agoImpossible for entry to be NULL at this point.
Jarkko Hietaniemi [Tue, 23 Jun 2015 02:47:50 +0000 (22:47 -0400)]
Impossible for entry to be NULL at this point.

740        if (return_svp) {
           notnull: At condition entry, the value of entry cannot be NULL.
           dead_error_condition: The condition entry must be true.

CID 104777: Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach the expression NULL inside this statement: return entry ? (void *)&ent....
741            return entry ? (void *) &HeVAL(entry) : NULL;

8 years agoHaving both assert() and if () for maxlen is redundant.
Jarkko Hietaniemi [Tue, 23 Jun 2015 02:25:52 +0000 (22:25 -0400)]
Having both assert() and if () for maxlen is redundant.

Coverity CID 104784

8 years agoCannot do much if putc fails in debug output.
Jarkko Hietaniemi [Tue, 23 Jun 2015 01:57:36 +0000 (21:57 -0400)]
Cannot do much if putc fails in debug output.

Coverity CID 104782 (only flagged the deb.c spot)

8 years agomg_find can return NULL.
Jarkko Hietaniemi [Tue, 23 Jun 2015 01:46:09 +0000 (21:46 -0400)]
mg_find can return NULL.

CID 104831: Dereference null return value (NULL_RETURNS)
43. dereference: Dereferencing a pointer that might be null Perl_mg_find(sv, 112) when calling Perl_magic_existspack. (The dereference is assumed on the basis of the 'nonnull' parameter attribute.)
499                magic_existspack(svret, mg_find(sv, PERL_MAGIC_tiedelem));

8 years agoPossible NULL cxt derefs.
Jarkko Hietaniemi [Tue, 23 Jun 2015 01:31:36 +0000 (21:31 -0400)]
Possible NULL cxt derefs.

Coverity CIDs 104819, 104820, 104821, 104827, 104859, 104860

Using assert() instead of Storable ASSERT() because Coverity
understands the first one.

8 years agosizeof * and sizeof ** not necessarily the same.
Jarkko Hietaniemi [Mon, 22 Jun 2015 23:05:51 +0000 (19:05 -0400)]
sizeof * and sizeof ** not necessarily the same.

Coverity CID 104792.

8 years agofileno might return negative.
Jarkko Hietaniemi [Mon, 22 Jun 2015 11:25:27 +0000 (07:25 -0400)]
fileno might return negative.

(Coverity CID 104853)

Also rewrite the fstat call to test for zero (success) explicitly,
instead of the sneaky bang-negation.

8 years agosleep() with negative argument makes no sense.
Jarkko Hietaniemi [Mon, 22 Jun 2015 10:50:34 +0000 (06:50 -0400)]
sleep() with negative argument makes no sense.

Give by default a warning, do not sleep, and return zero.

(the signedness problem detected by Coverity, CID 104844)

Other options would include not giving a warning at all,
giving a warning only if asked, and finally croaking.
(Python had this problem earlier, and chose croaking.)

Earlier discussion in
http://www.nntp.perl.org/group/perl.perl5.porters/2015/03/msg226304.html

See also:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html
http://linux.die.net/man/3/sleep
https://www.freebsd.org/cgi/man.cgi?query=sleep&sektion=3

8 years agoalarm() with negative argument makes no sense.
Jarkko Hietaniemi [Thu, 5 Mar 2015 12:57:14 +0000 (07:57 -0500)]
alarm() with negative argument makes no sense.

Give by default a warning, do not set the alarm, and return undef.

(the signedness problem detected by Coverity, CID 104837)

alarm() takes and returns unsigned int, not signed.

In other words, the C library function alarm() cannot fail, ever.
See for example:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/alarm.html
http://linux.die.net/man/3/alarm
https://www.freebsd.org/cgi/man.cgi?query=alarm&sektion=3

8 years agoUpdate File::Spec advice in perlport.
Craig A. Berry [Fri, 26 Jun 2015 21:50:27 +0000 (16:50 -0500)]
Update File::Spec advice in perlport.

Eighteen years ago, with Mac OS Classic in full swing and Unix
emulation on VMS spotty or non-existent, it made some sense to
reach for File::Spec sooner rather than later.  This is no longer
sound advice, so attempt to describe succinctly how things
actually work now, fix the broken examples, and drop the ancient
history of the File::Spec module.

8 years agoFix Pod::Simple tests that use catdir on non-directories.
Craig A. Berry [Fri, 26 Jun 2015 20:10:18 +0000 (15:10 -0500)]
Fix Pod::Simple tests that use catdir on non-directories.

Also sent upstream as:

https://rt.cpan.org/Public/Bug/Display.html?id=105511

8 years agoCorrect t/op/chdir.t test count following b4929cb48878.
Craig A. Berry [Fri, 26 Jun 2015 12:24:30 +0000 (07:24 -0500)]
Correct t/op/chdir.t test count following b4929cb48878.

8 years agoCorrect errno value in vms/vms.c's home-grown chdir.
Craig A. Berry [Fri, 26 Jun 2015 10:41:48 +0000 (05:41 -0500)]
Correct errno value in vms/vms.c's home-grown chdir.

It appears that in 09f253ec43d3a97e7 I made a guess without
consulting the standard, which in fact specifies that ENOENT
should be set when the input path is an empty string.  We now
test for the standard behavior as of b4929cb48878718c, and this
change gets that passing again.

8 years agoRemove unused variables from t/op/chdir.t.
Craig A. Berry [Fri, 26 Jun 2015 10:39:48 +0000 (05:39 -0500)]
Remove unused variables from t/op/chdir.t.

8 years agoAdd a direct link to perldelta in the release announcement
Max Maischein [Sun, 7 Jun 2015 15:13:25 +0000 (17:13 +0200)]
Add a direct link to perldelta in the release announcement

As the release announcement itself only contains the SHA1 digests and
not much information on the changes with this release, providing
a direct link to where the information is available seems to be wanted.

8 years agomake Encode compile under -pedantic
David Mitchell [Tue, 23 Jun 2015 10:12:40 +0000 (11:12 +0100)]
make Encode compile under -pedantic

enc2xs generates some C code which contains tables. These tables contain
recursive and mutually recursive pointers to other tables. Normally they
are declared as 'static const', except under C++ which can't handle this,
so there they are declared 'extern' and defined ''.

-Wc++-compat and -pedantic put a bit of a spanner in the works.
There is an existing hack to shut up a warning with -Wc++-compat by not
including the table's size in the forward declaration, but this breaks
-pedantic.

This commit does two things to enc2xs. First it moves all the logic that
examines the build options and decides whether to use 'const' etc, into
a separate function, compiler_info().  Second, it fixes the -pedantic
compilation failure by, in the presence of both -Wc++-compat and
-pedantic, falling back to a C++-style compile without the 'static const'.

This is monkey-patching an unstream-CPAN module in core due to it failing
one of the smoke configurations.

8 years agoMake the LoTR quote of reentr.c formatted more like the others.
Jarkko Hietaniemi [Wed, 24 Jun 2015 03:33:23 +0000 (23:33 -0400)]
Make the LoTR quote of reentr.c formatted more like the others.

(Note: the p.260 is my best estimate since I don't have
 the same edition as tchrist)

8 years agofix si_names context debugging names
David Mitchell [Wed, 24 Jun 2015 07:57:41 +0000 (08:57 +0100)]
fix si_names context debugging names

I recently added a new context stack type, MULTICALL. The table
si_names[], which contains the stack type names to display with
-Dsv a new label added, "MULTICALL", but the previous label didn't
have a comma after it, so the two labels were actually being concatenated.

Spotted by Coverity

8 years agofix harmless(ish) thinko in pp_return
David Mitchell [Wed, 24 Jun 2015 07:52:14 +0000 (08:52 +0100)]
fix harmless(ish) thinko in pp_return

My recently added Move() is moving an array of SV*'s, not SV**'s.
Spotted by Coverity.

8 years agofix punctuation in Tolkien quote in regexec.c
Chas. Owens [Tue, 23 Jun 2015 12:52:45 +0000 (13:52 +0100)]
fix punctuation in Tolkien quote in regexec.c

Message-ID:
<CAH2YjjEcaHknBtb1g0jxPZAXXtkQ-7ODjWbSyioKUjxr0_NN4A@mail.gmail.com>

8 years agodo not try printing undef
Ricardo Signes [Mon, 22 Jun 2015 14:57:04 +0000 (10:57 -0400)]
do not try printing undef

8 years agoUpdate autodie to CPAN version 2.28
Chris 'BinGOs' Williams [Mon, 22 Jun 2015 12:28:06 +0000 (13:28 +0100)]
Update autodie to CPAN version 2.28

  [DELTA]

2.28      2015-06-22 16:20:35+10:00 Australia/Melbourne

        * TEST BUG: Properly skip the Import::Into test if the
          version of Import::Into is insufficent.  Thanks to
          Olivier Mengué.  (GH#67)

        * DOC: Document change in 2.27 that was omitted from the
          Changes-file by mistake.

8 years agoUpdate Getopt-Long to CPAN version 2.47
Chris 'BinGOs' Williams [Mon, 22 Jun 2015 12:06:17 +0000 (13:06 +0100)]
Update Getopt-Long to CPAN version 2.47

  [DELTA]

Changes in version 2.47
-----------------------

* Fix bug https://rt.cpan.org/Ticket/Display.html?id=89513.

  Should have done that earlier :)

  This changes the format for accepted float numbers:

  <optional sign>
  <optional mantissa>
  <optional dec.point and fraction>
  <optional "e" and exponent>

  Mantissa and decimal fraction may not both be omitted.

  Underscores are permissible virtually anywhere in numbers for clarity.

8 years agoRespect hashbangs containing perl6
Leon Timmermans [Sun, 19 Apr 2015 11:03:28 +0000 (13:03 +0200)]
Respect hashbangs containing perl6

8 years agoIncrease the maximal size of the string displayed in non-numeric warnings
Rafael Garcia-Suarez [Mon, 22 Jun 2015 07:46:18 +0000 (09:46 +0200)]
Increase the maximal size of the string displayed in non-numeric warnings

This has the interesting side-effect of "fixing" some of the UTF-8
glob warnings, which indicates that sv_uni_display is probably not
dealing with stringified globs correctly.

Also add a test for the truncation of strings in the non-numeric
warnings.

8 years agoThese be the versions on CPAN now, ye scurvy dogs.
Chris 'BinGOs' Williams [Mon, 22 Jun 2015 07:25:07 +0000 (08:25 +0100)]
These be the versions on CPAN now, ye scurvy dogs.

8 years agoperlvar: fix list of defaulted array operators
Aristotle Pagaltzis [Sun, 21 Jun 2015 19:25:55 +0000 (21:25 +0200)]
perlvar: fix list of defaulted array operators

8 years agowelcome to v5.23.1, please make regen
Ricardo Signes [Sat, 20 Jun 2015 20:35:57 +0000 (16:35 -0400)]
welcome to v5.23.1, please make regen

8 years agocorelist: update for v5.23.1
Ricardo Signes [Sat, 20 Jun 2015 20:34:32 +0000 (16:34 -0400)]
corelist: update for v5.23.1

8 years agopatchlevel: we are now perl v5.23.1
Ricardo Signes [Sat, 20 Jun 2015 20:24:47 +0000 (16:24 -0400)]
patchlevel: we are now perl v5.23.1

8 years agoperldelta: correct target version v5.23.0
Ricardo Signes [Sat, 20 Jun 2015 20:13:57 +0000 (16:13 -0400)]
perldelta: correct target version

8 years agoperldelta: remove some unneeded bits
Ricardo Signes [Sat, 20 Jun 2015 19:02:46 +0000 (15:02 -0400)]
perldelta: remove some unneeded bits

8 years agoperlhist: v5.23.0 will be today
Ricardo Signes [Sat, 20 Jun 2015 18:51:41 +0000 (14:51 -0400)]
perlhist: v5.23.0 will be today

8 years agoperldelta: update for v5.23.0
Ricardo Signes [Sat, 20 Jun 2015 18:31:04 +0000 (14:31 -0400)]
perldelta: update for v5.23.0

8 years agoCoreList: update corelist for release of v5.23.0
Ricardo Signes [Sat, 20 Jun 2015 17:45:56 +0000 (13:45 -0400)]
CoreList: update corelist for release of v5.23.0

8 years agopartially revert 'silence gcc -pendantic warnings'
David Mitchell [Sat, 20 Jun 2015 01:56:03 +0000 (02:56 +0100)]
partially revert 'silence gcc -pendantic warnings'

The GCC_DIAG_IGNORE(-Wpedantic) stuff added by me to
STATIC_ASSERT_GLOBAL() by ac892e4a230de5b was causing some smoke failures.

I don't yet understand why.

8 years agoperlebcdic: Fix typo
Karl Williamson [Fri, 19 Jun 2015 19:40:33 +0000 (13:40 -0600)]
perlebcdic: Fix typo

8 years agosilence some gcc -pendantic warnings
David Mitchell [Fri, 19 Jun 2015 13:52:17 +0000 (14:52 +0100)]
silence some gcc -pendantic warnings

8 years agosilence some -Wc++-compat warnings
David Mitchell [Fri, 19 Jun 2015 12:41:42 +0000 (13:41 +0100)]
silence some -Wc++-compat warnings

The initialisers for PL_inf and PL_nan disabled -Wc++-compat warnings for
some ifdef branches but not others. Expand the scope of the
GCC_DIAG_IGNORE() to all cases.

8 years agoremove deprecated /\C/ RE character class
David Mitchell [Fri, 19 Jun 2015 11:47:05 +0000 (12:47 +0100)]
remove deprecated /\C/ RE character class

This horrible thing broke encapsulation and was as buggy as a very buggy
thing. It's been officially deprecated since 5.20.0 and now it can finally
die die die!!!!

8 years ago[MERGE] refactor sub returns (pp_return etc)
David Mitchell [Fri, 19 Jun 2015 08:51:10 +0000 (09:51 +0100)]
[MERGE] refactor sub returns (pp_return etc)

This series of commits attempts to reduce duplication and partially unify
the code that handles subroutine exit, in places like pp_leavesub,
pp_return etc.  In particular, pp_return has been heavily modified so that
it is now only responsible for doing any extra work required above and
beyond that done by pp_leavesub et al (popping contexts and removing junk
left on the stack). It now tail calls pp_leavesub / pp_leaveeval/ etc to
do the remaining heavy lifting. This reduces the code size of pp_return to
about a quarter of what it was previously, and ensures that exactly the
same processes happen regardless of whether an explicit return is is done
or not.

It also fixes using return in list context in a MULTICALL, e.g.

    use List::Util qw(pairmap);
    @a = pairmap { for (1,2) { return (3,4)} } qw(a b);

formerly returned (1,2,3,4) and now returns (3,4).

It also simplifies S_sortcv() et al which are responsible for calling
a sort sub.

8 years agosinplify Perl_block_gimme()
David Mitchell [Fri, 19 Jun 2015 08:45:54 +0000 (09:45 +0100)]
sinplify Perl_block_gimme()

The switch statement was fairly pointless, as it was just a bunch of

    case G_VOID:
       return G_VOID;

so replace the switch with a simple "croak if 0, otherwise return the
value".

8 years agopp_return: optimise a couple of conditions
David Mitchell [Thu, 11 Jun 2015 10:11:19 +0000 (11:11 +0100)]
pp_return: optimise a couple of conditions

Change:

    if (cxix < 0) {
        A; return;
    }
    if (cxix < cxstack_ix)
        B;

to

    if (cxix < cxstack_ix) {
        if (cxix < 0) {
            A; return;
        }
        B;
    }

This is functionally the same, since cxstack_ix is always positive at
this point, and makes for a quicker code path (one less test and branch)
in the reasonably common case of a return from a sub which doesn't
have any extra nested contexts to pop.

8 years agopp_return: reindent
David Mitchell [Thu, 11 Jun 2015 10:05:50 +0000 (11:05 +0100)]
pp_return: reindent

Re-indent a code block that got stranded after the previous commit.
Whitespace-only change.

8 years agopp_return(): tail call pp_leavewrite()
David Mitchell [Thu, 11 Jun 2015 09:54:12 +0000 (10:54 +0100)]
pp_return(): tail call pp_leavewrite()

When 'return'ing from a format, rather than handling it ourselves, fall
through to pp_leavewrite(). pp_return() is now only responsible for
popping any extra contexts and junk from the stack.

With this commit, *all* types of return are now handled by tail-calling
the appropriate pp_leaveFOO() function, so this commit also cuts out big
chunks of dead code.

Note that the behaviour on using 'return' in a format is completely
undocumented, and almost completely untested. In fact there is only a
single format in the test suite that does a return, and the tests which
use that are mainly there to ensure that extra stuff on the stack doesn't
leak into the value(s) returned by write().

In particular, its not clear whether a return half-way through a format
should cause the lines processed so far to be output, or to be discarded;
currently it discards. Also, its not clear what (if anything) should be
done with any args to the 'return' call. Currently they're just discarded.
Also, the format in the test suite which does a return only does a
'return;', not a 'return x,y,z'. So that's still untested.

So I decided to keep the current behaviour of return in format as close
as possible rather than trying to change of fix anything.

8 years agopp_return(): tail call pp_leaveeval()
David Mitchell [Thu, 11 Jun 2015 09:30:48 +0000 (10:30 +0100)]
pp_return(): tail call pp_leaveeval()

When 'return'ing from an eval STRING, rather than handling it
ourselves, fall through to pp_leaveeval(). pp_return() is now only
responsible for popping any extra contexts and junk from the stack.

This helps avoid two different blocks of code doing roughly the same
thing.

The functional changes caused by this commit signify the divergence over
time between pp_leaveeval and the try-ish parts of pp_return. After this
commit, a return will:

    * now do an PERL_ASYNC_CHECK();
    * be smarter about not unnecessarily creating mortal copies
      of returned args;
    * restore PL_curpm *before* the LEAVE() rather than after.

The first two are probably good things; I'm not sure about the latter; it
may well be a regression, but nothing tests for it. At least it's
consistent now.

8 years agopp_return: set eval CV depth to 0
David Mitchell [Thu, 11 Jun 2015 09:06:02 +0000 (10:06 +0100)]
pp_return: set eval CV depth to 0

In pp_leaveval, the CvDEPTH of the eval is set to 0. This doesn't
seem to be actually necessary (no tests fail if its removed),
but for consistency, add the same step to pp_return, which currently
doesn't do this. This is so that shortly we can make pp_return tail call
pp_leaveval.

8 years agopp_return: move 'die on require fail' later
David Mitchell [Thu, 11 Jun 2015 08:57:43 +0000 (09:57 +0100)]
pp_return: move 'die on require fail' later

In pp_leaveeval the test to die on require not returning a true value
is done late, after the return args have been processed, while in
pp_return it is checked *before* the args are processed. Move the test in
pp_return to after the args to make it more like pp_leaveeval. This is a
preparatory step in making pp_return eventually tail call pp_leaveeval.

It probably doesn't make any difference whether it's done early or late
(although arguably dying early is infinitesimally more efficient); but
since pp_leaveeval is going to be overwhelmingly a more common way of
returning from a require than pp_return, its seems prudent to to not mess
with the most widely used code path.

8 years agopp_leaveeval: use EVAL_KEEPERR
David Mitchell [Tue, 9 Jun 2015 16:11:06 +0000 (17:11 +0100)]
pp_leaveeval: use EVAL_KEEPERR

In order shortly to allow pp_return to tail call pp_leaveval,
make pp_leaveval use the EVAL_KEEPERR flag bit of PL_in_eval
to decide whether to call CLEAR_ERRSV() rather than testing the
OPf_SPECIAL flag bit on the OP_LEAVEEVAL op (since we may no longer be
that op).

The two are equivalent (I checked this by running test test suite with
an assert that they were the same).

Note that pp_return already uses the EVAL_KEEPERR flag test, so this
commit makes the pp_return and pp_leavesub code blocks more similar.

I've also added some more tests, as I initially got the logic of this
wrong, and no core tests failed - only cpan/ ones.  In particular, no core
tests checked whether eval-string actually cleared $@ on success!

8 years agoXS-APItest/t/call.t: make loops more flexible
David Mitchell [Wed, 10 Jun 2015 15:20:00 +0000 (16:20 +0100)]
XS-APItest/t/call.t: make loops more flexible

There's a loop which tests eval_pv, eval_sv, call_sv with various
types of argument. Currently the argument is determined by an integer
in a loop (0..3) with various values derived on an ad-hoc basis
from that index. Instead put all the data into an array of arrays
and iterate over that instead.

Similarly for the function names (eval_pv et al), loop over the names
rather than over 0..2.

This should make no functional change to what is tested, but makes the
test code clearer and more expandable.

8 years agopp_return(): tail call pp_leavetry()
David Mitchell [Tue, 9 Jun 2015 14:48:15 +0000 (15:48 +0100)]
pp_return(): tail call pp_leavetry()

When 'return'ing from an eval { BLOCK }, rather than handling it
ourselves, fall through to pp_leavetry(). pp_return() is now only
responsible for popping any extra contexts and junk from the stack.

This helps avoid two different blocks of code doing roughly the same
thing.

The functional changes caused by this commit signify the divergence over
time between pp_leavetry and the try-ish parts of pp_return. After this
commit, a return will:

    * now do an PERL_ASYNC_CHECK();
    * be smarter about not unnecessarily creating mortal copies
      of returned args;
    * restore PL_curpm *before* the LEAVE() rather than after.

The first two are probably good things; I'm not sure about the latter; it
may well be a regression, but nothing tests for it. At least it's
consistent now.

8 years agomake MULTICALL handle list context
David Mitchell [Tue, 9 Jun 2015 10:17:44 +0000 (11:17 +0100)]
make MULTICALL handle list context

Currently in something like

    for (1,2) { return 3,4 }

the user of MULTICALL will see 1,2,3,4 returned, because in pp_return,
MULTICALL is handled as a special case, and that special-case code doesn't
handle list context.

A simple fix is just to remove the special handling in pp_return.
Allow a MULTICALL return to pass through the normal pp_return stack
manging code, then tail call pp_leavesub or pp_leavesublv as approriate.
Both those subs do an immeidate 'return 0' if CxMULTICALL().

As well as fixing list context MULTICALL, it removes one extra condition
in the path of a normal return.

8 years agoeliminate S_return_lvalues()
David Mitchell [Tue, 9 Jun 2015 09:59:52 +0000 (10:59 +0100)]
eliminate S_return_lvalues()

After the previous commit, pp_leavesublv was just an empty wrapper
around S_return_lvalues() (which is also called from pp_return).

So just rename S_return_lvalues to pp_leavesublv, and make pp_return
call pp_leavesublv directly.

8 years agomove multicall check to S_return_lvalues
David Mitchell [Tue, 9 Jun 2015 09:51:15 +0000 (10:51 +0100)]
move multicall check to S_return_lvalues

Currently pp_leavesublv has a check at the top:

    if (CxMULTICALL(&cxstack[cxstack_ix]))
       return 0;

Move this instead into S_return_lvalues(), which pp_leavesublv immediately
calls. This has no effect on the pp_leavesublv code path, and also
has no effect on the pp_return code path, because although pp_return
calls S_return_lvalues, it doesn't in the case of MULTICALL, which it has
already checked for earlier.

So it shouldn't change anything functionally.

This will allow us to eliminate S_return_lvalues in the next commit.

8 years agoreindent code block in pp_return
David Mitchell [Tue, 9 Jun 2015 09:46:17 +0000 (10:46 +0100)]
reindent code block in pp_return

Just a whitespace change.

8 years agoSimplify S_return_lvalues()
David Mitchell [Tue, 9 Jun 2015 09:31:10 +0000 (10:31 +0100)]
Simplify S_return_lvalues()

S_return_lvalues() was written to handle both pp_leavesublv and pp_return;
in the latter case there could be junk on the stack that needs skipping;
e.g.

    for (1,2) { return 3,4 }

leaves 1,2,3,4 on the stack, and in list context the 3,4 needs shifting
down two places. After the previous commit, any return-specific processing
is now handled by pp_return itself, so S_return_lvalues only has to
worry about mortalising its args and grabbing the last arg in scalar
context.

Formerly there were two vars: newsp, which pointed to the slot before the
'1', and MARK, which pointed to the slot before the '3'. They now both
point to just before the '1'. So we only need to use one of them. Here
I've standardised on MARK, to make the code as similar as possible to that
in pp_leavesub, from which this code was forked back in 1999. For the same
reason I've set MARK to point to the '1' slot rather than the slot before
it, since that's what pp_leavesub does.

8 years agolval subs: do arg shifting in pp_return
David Mitchell [Tue, 9 Jun 2015 07:23:18 +0000 (08:23 +0100)]
lval subs: do arg shifting in pp_return

When an lvalue sub does an explicit return, currently pp_return
doesn't touch the args stack and instead tail calls S_return_lvalues()
which does both the leavesuby stuff (e.g. mortalise args) and the returny
stuff (e.g. shift the args down in list context).

Move the call to S_return_lvalues() further down in pp_return so that
the arg shifty stuff is done in pp_return now (like it is for non-lvalue
returns). This will allow us shortly to simply S_return_lvalues.

8 years agopp_return: simplify arg handling code
David Mitchell [Mon, 8 Jun 2015 17:46:50 +0000 (18:46 +0100)]
pp_return: simplify arg handling code

pp_return() only needs to do the extra arg handling associated
with the args not being at the base of the stack frame. For example

    for (1,2) { return 3,4 }

has to cope with 1,2,3,4 being on the stack.
Apart from handling junk, everything else  - in particular pushing
&PL_sv_undef in scalar context if there are no return args - is already
done by Perl_pp_leavesub, which pp_return tail calls.

So reduce what pp_return does to the bare minimum. This makes one less
conditional branch in a few cases.

8 years agosimplify sort sub return arg processing
David Mitchell [Mon, 8 Jun 2015 10:53:38 +0000 (11:53 +0100)]
simplify sort sub return arg processing

This commit:

1) makes the  gimme of sort blocks, as specified by the pushed cx_gimme,
be G_SCALAR. Formerly it was likely to be G_ARRAY, as it inherited
whatever sort() was called as, and sort doesn't bother calling a sort
block unless sort was called in list context.

This change is largely cosmetic, as
    a) the sort block is already compiled in scalar context; and
    b) the code in S_sortcv() etc does its own return arg context
       processing anyway, and assumes scalar context.
But it makes it consistent with sort SUB, which *does* set gimme to
G_SCALAR.

2) Makes use of the fact that a sort sub or block will always be
called as the first context in a new stackinfo, and such stackinfos always
have PL_stack_base[0] set to &PL_sv_undef as a guard.
So handling scalar context return (where zero args returned needs to be
converted into 1 PL_sv_undef arg) can be simplified by just always
accessing the last arg, *PL_stack_sp, regardless of whether 0,1,2+ args
were returned.
Note that some code making use of MULTICALL (e.g. List::Util) has already
been (possibly inadvertently) relying on this fact.

3) Remove the "Sort subroutine didn't return single value" fatal error.
This croak was removed from the sort BLOCK and sort NON-XS-SUB variants
in v5.15.5-82-g1715fa6, but the croak was left for XS sort subs.
That commit incorrectly asserted that for "sort BLOCK" and "sort
NON-XS-SUB", more than 1 arg could never be returned, but:

    $ perl -e'sub f { return (1,2) } @a = sort f 1,2,3'
    perl: pp_sort.c:1789: S_sortcv: Assertion `PL_stack_sp ==
        PL_stack_base' failed.

That has been fixed by (2) above. By removing the croak from the XS branch
too, we make things consistent. This means that an XS sub which returns
more than 1 arg will just gets its return args be evaluated in scalar
context (so @return_args[-1] will be used), rather than being handled
specially.

8 years agosort fns: simplify handing uninit warnings
David Mitchell [Tue, 2 Jun 2015 13:59:46 +0000 (14:59 +0100)]
sort fns: simplify handing uninit warnings

When a sort function or code block returns an undef value (rather than the
typical -1,0,-1), you get the usual "Use of uninitialized value" warning.

Originally the message didn't say " ... in sort" because at the end of
running a sort sub, PL_op is NULL rather rather than pointing at the sort
op.

v5.15.3-364-gd4c6760 changed the sort sub return code in S_sortcv() et al
to temporarily set PL_op to point to the sort OP, which made
Perl_report_uninit() emit the desired " in sort" suffix.

However, this meant that PL_op and PL_curpad briefly referenced two
different CVs; since Perl_report_uninit() rummages around in pads looking
for lexicals, consts etc, this could lead to SEGVs.

v5.15.3-372-g1aa032b fixed that by temporarily setting PL_curpad to NULL
at the same time. However that then caused problems if the code dies
(e.g. if warnings are upgraded to errors) since the old PL_curpad value
wasn't being restored.

v5.17.6-7-g2f43ddf fixed that by wrapping the PL_curpad=NULL with
appropriate ENTER/SAVEVPTR(PL_curpad)/..../LEAVE where necessary.

However, this is starting to get quite complex, and in a hot piece of
code, and the 3 sort functions S_sortcv/S_sortcv_stacked/S_sortcv_xsub
are all diverging from each other in subtle and confusing ways.

This commit takes a different approach. It effectively reverts those three
commits (apart from the tests) and instead updates Perl_report_uninit()
to say "if PL_op is NULL, but the context stack indicates that we're
currently in a sort, then append " in sort" to the warning.

This is a lot less messy, and moves all the clutter from the two hot
functions S_sortcv/S_sortcv_stacked into a function that is only called
when we're emitting warnings.

8 years agoPerl_report_uninit(): simplify code
David Mitchell [Tue, 2 Jun 2015 12:50:06 +0000 (13:50 +0100)]
Perl_report_uninit(): simplify code

Simplify the code in this function a bit.
It should have no functional effect, but will make the next commit
easier.

8 years agoadd PERLSI_MULTICALL
David Mitchell [Tue, 2 Jun 2015 10:51:44 +0000 (11:51 +0100)]
add PERLSI_MULTICALL

Currently when MULTICALL pushes a new stackinfo, it uses the si_type
PERLSI_SORT. This is probably just a hangover from when the MULTICALL code
was created from similar code used to implement sort.

Change it to use the new PERLSI_MULTICALL si_type.

The si_type value is mainly used for debugging/dumping purposes,
apart from a few places where we check for whether this is
the top stack (PERLSI_MAIN); or check for a sort BLOCK (cxix = 0,
CXt_NULL, PERLSI_SORT).

So this commit should have no immediate effect. It will in future
however allow us to detect whether we have a sort or a true MULTICALL.

8 years agoS_return_lvalues(): merge two similar blocks
David Mitchell [Sun, 24 May 2015 15:53:05 +0000 (16:53 +0100)]
S_return_lvalues(): merge two similar blocks

Two blocks of error-reporting code both clean up the context state and
then croak with a similar message. Make the second block just goto the
first block instead.

8 years agoS_return_lvalues(): consistent cxstack_ix--
David Mitchell [Sun, 24 May 2015 15:42:29 +0000 (16:42 +0100)]
S_return_lvalues(): consistent cxstack_ix--

After merging in the functionality from pp_leavesublv and pp_return
into S_return_lvalues(), there were two context stack pointer decrement
conventions: before or after the POPSUB(). Both are wrong in different
ways, and will be more generally fixed up in later commits. For now,
standardise on a single form: that used by pp_leavesub and pp_leavesublv.

8 years agopp_return: re-indent after last commit
David Mitchell [Sun, 24 May 2015 08:53:37 +0000 (09:53 +0100)]
pp_return: re-indent after last commit

whitespace-only change.

8 years agohandle most of lvalue return in single place
David Mitchell [Sun, 24 May 2015 08:48:53 +0000 (09:48 +0100)]
handle most of lvalue return in single place

Currently about half the work involved in returning from an lvalue sub
call is done by the shared sub S_return_lvalues() function, while the
other half is duplicated in pp_leavesublv() and pp_return(). Move most of
that duplicated code into S_return_lvalues().

8 years agopp_return: tail call pp_leavesub
David Mitchell [Sat, 23 May 2015 10:12:18 +0000 (11:12 +0100)]
pp_return: tail call pp_leavesub

For returns within normal (rvalue) subs, handle the bulk of of the work by
falling through into pp_leavesub, rather than repeating most of the code.
So pp_return is now just responsible for popping any extra contexts and
shifting any return args back down to the base of the stack.

Return in lvalue subs, evals etc is unaffected.

8 years agopp_last: only handle loop context types
David Mitchell [Sat, 23 May 2015 19:25:45 +0000 (20:25 +0100)]
pp_last: only handle loop context types

pp_last pops to the next relevant loop context type, or croaks.
Yet once it does this, it attempts to handle *all* context types
(subs, evals etc), even those which can never be the current
context.

Rip all this dead code out, and replace with an assertion that the
context is one of the loop types.

This dead code has been there since 5.000.

8 years agomktables: Fix logic error
Karl Williamson [Fri, 19 Jun 2015 00:45:05 +0000 (18:45 -0600)]
mktables: Fix logic error

When I wrote this some years ago, I committed a logic error, so that a
constraint I thought applied was in fact somewhat different than what I
thought.  The new comments give the proper constraint.

The code is taking the data furnished by unicode.org and massaging it
into tables usable by the perl interpreter.  This bug can cause wrong
tables to be generated.  Fortunately, this bug does not arise with
typical unicode.org data sets, so it hasn't shown up as a problem.
Fixing it makes no difference in the current Unicode version.  I
discovered it only in compiling Unicode 1.1.5, somewhat tweaked by me,
so not the official data there either.

8 years agoautodie/t/mkdir.t: escape build dir path
David Mitchell [Thu, 18 Jun 2015 16:51:40 +0000 (17:51 +0100)]
autodie/t/mkdir.t: escape build dir path

This test file creates a regex which includes the path of the build
directory. If that path includes regex metachars (e.g. blead_g++_quick)
then the test fails. Easily fixed with \Q...\E.

Monkey-patching here rather than waiting for upstream, since this is
currently breaking blead g++ smokes.

8 years agoPorting/release_schedule.pod: add july 2015 volunteer
Ricardo Signes [Thu, 18 Jun 2015 13:16:07 +0000 (09:16 -0400)]
Porting/release_schedule.pod: add july 2015 volunteer

8 years agoensure chdir('') sets $! to ENOENT on non-IMP_SYS Win32 builds
Tony Cook [Thu, 18 Jun 2015 04:08:48 +0000 (14:08 +1000)]
ensure chdir('') sets $! to ENOENT on non-IMP_SYS Win32 builds

8 years agostart fleshing out the 5.23 release schedule
Ricardo Signes [Thu, 18 Jun 2015 01:39:07 +0000 (21:39 -0400)]
start fleshing out the 5.23 release schedule

8 years agoSwitch to Unicode Version 8
The Unicode Consortium [Wed, 1 Apr 2015 16:35:39 +0000 (10:35 -0600)]
Switch to Unicode Version 8

8 years agoAdd unicode.org to the AUTHOR file
Karl Williamson [Wed, 17 Jun 2015 22:27:08 +0000 (16:27 -0600)]
Add unicode.org to the AUTHOR file

8 years agoregexec.c: Change \b{sb} rule in prep for Unicode 8.0
Karl Williamson [Wed, 17 Jun 2015 22:25:48 +0000 (16:25 -0600)]
regexec.c: Change \b{sb} rule in prep for Unicode 8.0

Unicode 8 version modifies this rule.

8 years agoPorting/release_schedule.pod: Fix wrong year in dates
Karl Williamson [Wed, 17 Jun 2015 21:46:02 +0000 (15:46 -0600)]
Porting/release_schedule.pod: Fix wrong year in dates

8 years agoMicrooptimize some matches in utf8_heavy.pl
Rafael Garcia-Suarez [Wed, 17 Jun 2015 11:18:59 +0000 (13:18 +0200)]
Microoptimize some matches in utf8_heavy.pl

8 years ago[perl #125305] chdir("") no longer behaves like chdir()
Tony Cook [Wed, 17 Jun 2015 01:10:18 +0000 (11:10 +1000)]
[perl #125305] chdir("") no longer behaves like chdir()

8 years ago[perl #123264] explicitly document the return value of sysopen
Tony Cook [Wed, 17 Jun 2015 00:55:19 +0000 (10:55 +1000)]
[perl #123264] explicitly document the return value of sysopen

8 years agoPerl example style nit in docs for sort()
Rafael Garcia-Suarez [Tue, 16 Jun 2015 10:21:04 +0000 (12:21 +0200)]
Perl example style nit in docs for sort()

Declare both arrays, no need to clear them.

8 years agoadd Martijn Lievaart as a perl author
Tony Cook [Tue, 16 Jun 2015 00:17:47 +0000 (10:17 +1000)]
add Martijn Lievaart as a perl author

8 years agoAvoid gcc warning "‘start’ may be used uninitialized in this function"
Martijn Lievaart [Mon, 15 Jun 2015 07:04:56 +0000 (17:04 +1000)]
Avoid gcc warning "‘start’ may be used uninitialized in this function"