This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
6 years agoStorable 3.01 security: detect CVE-2015-1592
Reini Urban [Thu, 15 Sep 2016 23:20:42 +0000 (01:20 +0200)]
Storable 3.01 security: detect CVE-2015-1592

warn and test against this published metasploit attack vector.
See GH #199

Conflicts:
dist/Storable/Storable.pm

TonyC:
 - backported parts of 17a1797 to make it compatible with blead
 - updated MANIFEST

6 years agoStorable: silence cast warnings
Reini Urban [Fri, 16 Sep 2016 10:01:48 +0000 (12:01 +0200)]
Storable: silence cast warnings

6 years agoStorable: comments
Reini Urban [Mon, 20 Jun 2016 06:29:27 +0000 (08:29 +0200)]
Storable: comments

6 years agoStorable: throw exception on huge values
Reini Urban [Wed, 4 Oct 2017 04:26:37 +0000 (15:26 +1100)]
Storable: throw exception on huge values

The Storable data format is incapable of representing lengths of 2**31 or
greater; and if you try, you can get segfaults or corrupt data or other fun
and games.

Though it would be undeniably good to fix this properly, this is just a
simple starting point: the limitation is documented, and an exception is
thrown when such data is encountered.

Signed-off-by: Reini Urban <rurban@cpanel.net>
Conflicts:
dist/Storable/Storable.pm
dist/Storable/Storable.xs

6 years agoRelease cperl-5.22.2
Reini Urban [Sun, 8 May 2016 18:28:51 +0000 (20:28 +0200)]
Release cperl-5.22.2

Conflicts:
INSTALL
META.json
dist/Module-CoreList/lib/Module/CoreList.pm
dist/Module-CoreList/lib/Module/CoreList/Utils.pm
pod/perlhist.pod
t/porting/customized.dat

TonyC:
 - this was largely a core commit, with a minor change to Storable.
   Only the change to Storable has been included.

Cherry-picked from 5d23481d9dc73edc8b59e3ad1ea9f7da164fcfd3

6 years agoStorable: fix win32, missing INT32_MAX
Reini Urban [Fri, 29 Apr 2016 10:26:47 +0000 (12:26 +0200)]
Storable: fix win32, missing INT32_MAX

6 years agoparser: expand tokenbuf from 256 to 1024
Reini Urban [Fri, 1 Apr 2016 07:42:41 +0000 (09:42 +0200)]
parser: expand tokenbuf from 256 to 1024

This should speed up parsing,
and changes the "Identifier too long" limitation from max 256 to 1024.
See [cperl #124]

TonyC:
 - this was largely a core change, with an incidental change to Storable,
   only the Storable change has been included for compatibility with cperl

6 years agoStorable 3.00: u64 strings, arrays and hashes >2G
Reini Urban [Tue, 29 Mar 2016 15:50:09 +0000 (17:50 +0200)]
Storable 3.00: u64 strings, arrays and hashes >2G

via a new LOBJECT tag. This is for 32bit systems and lengths
between 2GB and 4GB (I32-U32), and 64bit (>I32).
Use SSize_t array and hash lengths, see [cperl #123].

Even for hashes, which we cannot iterate over.
This is a upstream limitation in the HvAUX struct and API.
We can store >2G keys though, which is fully supported
in subsequent cperl commits for #123, but not perl5 upstream.

Add several helper functions for strings and hash entries,
removed a lot of duplicate code.

Reformat consistently (tabs: 8)

Modernize:
* get rid of main'dump
* get rid of *FILE typeglob, replace with lexical filehandle
* fix parallel tests, use unique filenames.
* fixed many instances of 2arg open,
* keep backcompat default handling for XS functions, handle the flag
  default there.
* remove default $Storable::flags settings in the tests
* fix some too short I32 len types in the XS

Conflicts:
dist/Storable/Storable.pm
dist/Storable/Storable.xs
dist/Storable/t/attach_errors.t
dist/Storable/t/blessed.t
dist/Storable/t/destroy.t
dist/Storable/t/testlib.pl

6 years agoStorable: throw exception on huge values
Aaron Crane [Fri, 18 Mar 2016 15:22:12 +0000 (15:22 +0000)]
Storable: throw exception on huge values

The Storable data format is incapable of representing lengths of 2**31 or
greater; and if you try, you can get segfaults or corrupt data or other fun
and games.

Though it would be undeniably good to fix this properly, this is just a
simple starting point: the limitation is documented, and an exception is
thrown when such data is encountered.

Signed-off-by: Reini Urban <rurban@cpanel.net>
Conflicts:
dist/Storable/Storable.pm
dist/Storable/Storable.xs

6 years agoStorable: document, reformat and fix for DEBUGGING
Reini Urban [Tue, 29 Mar 2016 12:59:02 +0000 (14:59 +0200)]
Storable: document, reformat and fix for DEBUGGING

fix t/blessed.t: we do try to auto-load modules
for bless, and avoid regressions. One security flag
BLESS_OK is enough to disable this.

fix all DEBUGGING 64bit warnings, with TRACEME.

add asserts from blead perl 5.24.

update hints/linux.pl for the known gcc -O3 bug.
Not repro with gcc 4 nor clang.

fix documentation: SECURITY WARNING, Large data
on 64-bit platforms

Conflicts:
dist/Storable/Storable.xs
dist/Storable/t/blessed.t

Cherry-picked from fe00be04fba2ec29f6d0c897a21d0c2771954def

6 years agocPanel Storable 2.53_03: don't bless [security]
Todd Rinaldo [Tue, 3 Oct 2017 01:49:07 +0000 (12:49 +1100)]
cPanel Storable 2.53_03: don't bless [security]

Optional flags arg to disable bless|tie on retrieve/thaw

Signed-off-by: Reini Urban <rurban@cpanel.net>
and added documentation, reformat, compute CAN_FLOCK at compile-time.
See [cperl #120]

TonyC:

 - removed pod/perlcdelta.pod changes
 - this commit removed auto-loading modules for overloading, which
   was reinstated in a later commit.

cherry-picked from 04b58ce1b1c391d04efb2c0a3da108603b8cafc6

6 years agoStorable: bump to 2.53_02
Reini Urban [Thu, 24 Mar 2016 16:49:07 +0000 (17:49 +0100)]
Storable: bump to 2.53_02

enable STORABLE_DEBUGME with -DEBUGGING.
add split debugging trace messages.
improve canonical store_hash pre-allocation.

Conflicts:
dist/Storable/Storable.pm
dist/Storable/Storable.xs
dist/Storable/t/restrict.t

6 years agofix perl #132630, dont try to fbm match past end of string
Yves Orton [Wed, 7 Feb 2018 22:00:18 +0000 (23:00 +0100)]
fix perl #132630, dont try to fbm match past end of string

6 years agoperlapi: Rmv nonapplicable text
Karl Williamson [Sun, 4 Feb 2018 05:16:39 +0000 (22:16 -0700)]
perlapi: Rmv nonapplicable text

6 years agoregcomp.c: Fix comment
Karl Williamson [Sun, 4 Feb 2018 05:15:51 +0000 (22:15 -0700)]
regcomp.c: Fix comment

6 years agoAdd uvchr_to_utf8_flags_msgs()
Karl Williamson [Sun, 4 Feb 2018 05:14:22 +0000 (22:14 -0700)]
Add uvchr_to_utf8_flags_msgs()

This is propmpted by Encode's needs.  When called with the proper
parameter, it returns any warnings instead of displaying them directly.

6 years agoAPItest:t/utf8_warn_base.pl: Clarify some comments
Karl Williamson [Sun, 4 Feb 2018 05:09:28 +0000 (22:09 -0700)]
APItest:t/utf8_warn_base.pl: Clarify some comments

6 years agoAPItest:t/utf8_warn_base.pl: Move a variable outside sub()
Karl Williamson [Sun, 4 Feb 2018 05:06:35 +0000 (22:06 -0700)]
APItest:t/utf8_warn_base.pl: Move a variable outside sub()

This is in preparation for a future commit which will want to refer to
this variable independently.

6 years agoAPItest:t/utf8_warn_base.pl; Fix 'ok' tests
Karl Williamson [Fri, 2 Feb 2018 18:38:29 +0000 (11:38 -0700)]
APItest:t/utf8_warn_base.pl; Fix 'ok' tests

This was putting the condition for the ok in a string, which always
succeeds

6 years agoutf8.c: Extract code into separate function
Karl Williamson [Fri, 2 Feb 2018 17:43:33 +0000 (10:43 -0700)]
utf8.c: Extract code into separate function

This is in preparation for the next commit which will use this code in
multiple places

6 years agofix tr/// Deparse tests under EBCDIC
David Mitchell [Wed, 7 Feb 2018 10:34:02 +0000 (10:34 +0000)]
fix tr/// Deparse tests under EBCDIC

Some tests I recently added had A-Z in the replacement charlist, which
under EBCDIC gets deparsed as A-IJ-RS-Z, so original and deparsed don't
match.

Ideally the deparsing could be smart enough to coalesce those ranges,
but for now I've just changed the range to A-I which deparses ok on both
ASCII and EBCDIC.

The point of the test is for when there are more replacement chars than
search chars, and in this case A-I works just as well as A-Z.

Spotted by Karl.

6 years agolocale.c: Use same form of macro name
Karl Williamson [Tue, 6 Feb 2018 05:14:48 +0000 (22:14 -0700)]
locale.c: Use same form of macro name

This macro has synonyms; use the one prevailing in the adjacent code, so
that future maintainers think there is something strange going on that
is needed to investigate, only to find that nothing was going on.

6 years agoperldelta for bb4e4c3869d9
Tony Cook [Mon, 5 Feb 2018 23:57:26 +0000 (10:57 +1100)]
perldelta for bb4e4c3869d9

6 years ago(perl #125351) abort parsing if parse errors happen in a sub lex
Tony Cook [Tue, 30 Jan 2018 05:40:53 +0000 (16:40 +1100)]
(perl #125351) abort parsing if parse errors happen in a sub lex

We've had a few reports of segmentation faults and other misbehaviour
when sub-parsing, such as within interpolated expressions, fails.

This change aborts compilation if anything complex enough to not be
parsed by the lexer is compiled in a sub-parse *and* an error
occurs within the sub-parse.

An earlier version of this patch failed on simpler expressions,
which caused many test failures, which this version doesn't (which may
just mean we need more tests...)

6 years ago[perl #132799] Fix goto within block within expr
Father Chrysostomos [Mon, 5 Feb 2018 06:50:15 +0000 (22:50 -0800)]
[perl #132799] Fix goto within block within expr

When goto looks for a label, it builds up a list of ops to enter.  But
it begins its search a little too far out relative to the ‘goto’.
Hence, the first op gets skipped.

In 6d90e983841, I forbade same cases of inward goto-into-expression to
avoid stack corruption and crashes.  I did this by pushing a marker
on to the list of ops to enter, indicating that an error should be
thrown instead.

Because goto starts the search too far up the context stack, it would
sometimes end up looking inside an expression, which would cause the
first op on the entry list to be such a marker, meaning that the next
item, which should have been skipped, would not be.

That could really screw up the context stack for cases like:

    my $e = eval { goto label; label: }

because the entry list would be:

    <croak-marker> entertry

instead of the previous:

    entertry

Hence, entertry (which enters eval{}) would be executed from *within*
the eval, causing the exit of the eval to leave an eval on the context
stack.  Crashes ensued.

This commit fixes it by checking whether we have moved past the begin-
ning of the list of entry ops before pushing a croak-marker on to it.

Goto’s implementation is really complex, and always has been.  It
could be greatly simplified now thot ops have parent pointers.  But
that should wait for another developement cycle.

6 years agoAPItest: Add tests for utf8_to_bytes()
Karl Williamson [Mon, 5 Feb 2018 04:47:09 +0000 (21:47 -0700)]
APItest: Add tests for utf8_to_bytes()

6 years agoAPItest:t/utf8_setup.pl: Display printables as themselves
Karl Williamson [Mon, 5 Feb 2018 04:44:17 +0000 (21:44 -0700)]
APItest:t/utf8_setup.pl: Display printables as themselves

Instead of the harder to read \xXX

6 years agoregcomp.c: Comment, white-space only
Karl Williamson [Mon, 5 Feb 2018 02:15:00 +0000 (19:15 -0700)]
regcomp.c: Comment, white-space only

6 years agoregcomp.c: Simplify handling of varying loop increments
Karl Williamson [Mon, 5 Feb 2018 01:48:26 +0000 (18:48 -0700)]
regcomp.c: Simplify handling of varying loop increments

Prior to this commit, this loop added 1 to a variable each iteration as
part of the for(;;).  This created some issues for the few cases where
that increment should be something else.

Now, the addition is removed from the for(;;), and defaults to 1, so
that the code inside doesn't have to account for an automatic 1 in the
for().

6 years agoDisable CV-in-stash optimization
Father Chrysostomos [Sun, 4 Feb 2018 19:13:56 +0000 (11:13 -0800)]
Disable CV-in-stash optimization

outside of the main package.

Instead of actually reverting to the previous logic that excluded
packages other that main as a side effect of the logic being
faulty, this time I am checking for the main package explicitly.

6 years agoregcomp.c: Clarify comment
Karl Williamson [Sat, 3 Feb 2018 17:29:33 +0000 (10:29 -0700)]
regcomp.c: Clarify comment

6 years agoregcomp.c: Pack EXACTish nodes more fully
Karl Williamson [Sat, 3 Feb 2018 17:25:31 +0000 (10:25 -0700)]
regcomp.c: Pack EXACTish nodes more fully

Prior to this commit, nodes that are to match a string exactly, or
possibly case insensitively used only half the potential space available
(that being limited by the length field which is a U8).  (The optimizer
might later pack some together to make a larger node.)  Talking it over
with Yves, we suspect that this is a relic of an earlier time.  It makes
more sense to have longer nodes when possible to lower overhead in
the matching engine.

6 years agoSkip t/op/state.t tests that need attributes under miniperl
Hugo van der Sanden [Sat, 3 Feb 2018 16:04:08 +0000 (16:04 +0000)]
Skip t/op/state.t tests that need attributes under miniperl

6 years ago[perl #115814] skip layer test under miniperl
Hugo van der Sanden [Sat, 3 Feb 2018 10:43:11 +0000 (10:43 +0000)]
[perl #115814] skip layer test under miniperl

6 years agoMark new function utf8n_to_uvchr_msgs() as experimental
Karl Williamson [Fri, 2 Feb 2018 04:53:53 +0000 (21:53 -0700)]
Mark new function utf8n_to_uvchr_msgs() as experimental

This function was written specifically for Encode's needs.  My intent is
to eventually make it publicly usable, but since it's new, we should
give some time for it to prove itself.

6 years agoSpeed up finding non-UTF8 EXACTFish initial matches
Karl Williamson [Fri, 2 Feb 2018 03:49:03 +0000 (20:49 -0700)]
Speed up finding non-UTF8 EXACTFish initial matches

find_byclass() is used to scan through a target string looking for
something that matches a particular class.  This commit speeds that up
for patterns of the /foo/i type, where neither the target string nor
the pattern are UTF-8.

More precisely, it speeds up only finding the first byte of 'foo'
in the string.  The actual matching speed remains the same, once that
initial character that is a potential match is found.

But finding that first character is sped up immensely by this commit.

It does this by using memchr() when the character is caseless.  For
example in the pattern /:abcde/i, the colon is first, and is caseless.
On my system memchr is extremely fast, so the numbers below for this
case may not be as good on other systems.

And when the first character is cased, such as in /abcde/i, it uses the
techniques added in 2813d4adc971fbaa124b5322d4bccaa73e9df8e2 for the
ANYOFM regnode.  In both ASCII and EBCDIC machines, the case folds of
the cased letters are almost all of the form that these techniques work
on.  There are no tests in our current test suite that don't have this
form.  However, /il (locale) matching may very well violate this, and
will use the per-byte scheme that has been in effect until this commit.

The numbers below are for finding the first letter after a long string
that doesn't include that character.  Doing this isolates the speed up
attributable to this commit from ovehead.

The only downsides of this commit are that on some systems memchr() may
introduce function call overhead that won't pay off if the next
occurrence of the character is close by; and in the other case, a single
extra conditional is required to determine if there is at least a word's
worth of data to look at, plus some masking, shifting, and arithmetic
instructions associated with that conditional.  A static function is
called, so there may or may not be function call overhead, depending on
the compiler optimizer.

Key:
    Ir   Instruction read
    Dr   Data read
    Dw   Data write
    COND conditional branches
    IND  indirect branches

The numbers represent raw counts per loop iteration.

caseless first letter
('b' x 10000) . ':' =~ /:a/i

          blead    fast Ratio %
       -------- ------- -------
    Ir  72109.0  4819.0  1496.3
    Dr  20608.0  1237.5  1665.3
    Dw  10409.0   409.5  2541.9
  COND  20376.0   702.0  2902.6
   IND     15.0    16.0    93.8

cased first letter
('b' x 10000) . 'a' =~ /A/i

          blead    fast Ratio %
       -------- ------- -------
    Ir 103074.0 25704.6   401.0
    Dr  20896.5  2164.9   965.2
    Dw  10587.5   601.9  1759.0
  COND  30516.0  3036.2  1005.1
   IND     22.0    22.0   100.0

6 years agoregexec.c: Don't retest the same byte immediately
Karl Williamson [Fri, 2 Feb 2018 02:42:50 +0000 (19:42 -0700)]
regexec.c: Don't retest the same byte immediately

In this macro, COND has just returned true for the given byte.  We then
need to test that the rest of the relevant portion of the input string
and pattern match.  But before this commit, we started at the byte we
already know the answer for.  Change to test starting one position over.

6 years ago'if' module: clarify documentation and test more thoroughly.
James E Keenan [Tue, 23 Jan 2018 15:46:32 +0000 (10:46 -0500)]
'if' module: clarify documentation and test more thoroughly.

The documentation for 'if' made certain claims about the need to quote or not
quote a module name preceding a "fat arrow" ('=>') operator.  These claims
were shown to be unfounded in most cases when "use strict 'subs'" was in
effect.

In the course of writing better documentation, it was observed that the "no
if" case was very under-tested, poorly documented and hence poorly understood.
Hence, more tests have been added and the documentation has been extensively
revised.  However, there have been no changes in source code or functionality.

Make porting/podcheck.t happy.  Compensate for functions not available on
older perls.  Documentation touch-ups suggested by sisyphus.

For:  RT # 132732.

6 years agopp_warn: use MEXTEND rather than EXTEND
David Mitchell [Wed, 20 Dec 2017 13:07:46 +0000 (13:07 +0000)]
pp_warn: use MEXTEND rather than EXTEND

RT #132602

6 years agolocale.c: Do savepv() ASAP
Karl Williamson [Wed, 17 Jan 2018 20:54:27 +0000 (13:54 -0700)]
locale.c: Do savepv() ASAP

When this code is called on a threaded perl, it's possible that another
thread could zap the setlocale return buffer, if it's not reentrant.  I
suspect we would have seen this more often if that was the case, but
this commit improves things by doing the save immediately, reducing the
unsafe interval.

6 years agoPOSIX::localconv(): Prefer localeconv_l()
Karl Williamson [Wed, 17 Jan 2018 20:32:32 +0000 (13:32 -0700)]
POSIX::localconv(): Prefer localeconv_l()

This is a thread-safe version of localeconv(), so use it under threads.

6 years agoPOSIX.xs: Add mutex around localeconv()
Karl Williamson [Wed, 17 Jan 2018 18:22:02 +0000 (11:22 -0700)]
POSIX.xs: Add mutex around localeconv()

If another thread calls localeconv(), it can destroy the returned
buffer.  This adds a mutex around this call; the only other place in the
core that calls it already has this mutex, so they now are thread-safe.

6 years agolocale.c: Use %z for displaying Size_t operands
Karl Williamson [Wed, 31 Jan 2018 13:51:17 +0000 (06:51 -0700)]
locale.c: Use %z for displaying Size_t operands

This should fix [perl #132701]

6 years agoPOSIX.xs: Prefer mbrtowc() over mbtowc()
Karl Williamson [Thu, 11 Jan 2018 05:35:12 +0000 (22:35 -0700)]
POSIX.xs: Prefer mbrtowc() over mbtowc()

mbrtowc is reentrant, so use it on threaded perls if available when
POSIX::mbtowc() is called.

6 years agoPOSIX.xs: Prefer mbrlen() over mblen()
Karl Williamson [Thu, 11 Jan 2018 05:28:34 +0000 (22:28 -0700)]
POSIX.xs: Prefer mbrlen() over mblen()

mbrlen is reentrant, so use it on threaded perls if available when
POSIX::mblen() is called.

6 years agolocale.c: Avoid localeconv()
Karl Williamson [Sat, 6 Jan 2018 21:24:30 +0000 (14:24 -0700)]
locale.c: Avoid localeconv()

my_langinfo() is a recently added function which presents a better API
than localeconv, and returns the needed information here, and is easier
to make thread-safe.

6 years agolocale.c: White-space only
Karl Williamson [Tue, 9 Jan 2018 00:37:15 +0000 (17:37 -0700)]
locale.c: White-space only

This indents all this code, with no other changes, in preparation for a
future commit which will add a block around it.

6 years agolocale.c: Remove branch to label
Karl Williamson [Sun, 7 Jan 2018 22:58:52 +0000 (15:58 -0700)]
locale.c: Remove branch to label

The code at this label was branched to because it contained common
cleanup code.  But now that code is in a function, so the cleanup call
is trivial, so just skip this intermediate label.

6 years agolocale.c: Extract duplicated code into subroutines
Karl Williamson [Sat, 6 Jan 2018 19:42:35 +0000 (12:42 -0700)]
locale.c: Extract duplicated code into subroutines

These two paradigms are each repeated in 4 places.  Make into two
subroutines

6 years agolocale.c: Prefer mbrtowc(), as its reentrant
Karl Williamson [Sat, 6 Jan 2018 04:41:27 +0000 (21:41 -0700)]
locale.c: Prefer mbrtowc(), as its reentrant

If it's available and this is a threaded build, it's preferred.

6 years agolocale.c: White-space only
Karl Williamson [Sun, 7 Jan 2018 22:43:01 +0000 (15:43 -0700)]
locale.c: White-space only

Indent to correspond with new block from previous commit

6 years agolocale.c: Revamp finding if locale is UTF-8
Karl Williamson [Fri, 5 Jan 2018 21:09:40 +0000 (14:09 -0700)]
locale.c: Revamp finding if locale is UTF-8

This changes how this functionality works for the LC_CTYPE locale.  On
systems that have nl_langinfo() one can get a "definitive" answer from
just that.  Otherwise (or if that doesn't return properly) one can use
mbtowc() to check if the UTF-8 byte sequence for the Unicode REPLACEMENT
CHARACTER actually is considered to be that code point.  This is also
"definitive".  If the maximum byte string length for a character is too
short to handle all Unicode UTF-8, we know without further checking that
this isn't a UTF-8 locale, so can avoid the mbtowc check.

It turns out, from testing, that some locales are labelled UTF-8 by
nl_langinfo even though they depart from that at times.  Similarly for
mbtowc().  Perl assumes that a locale doesn't depart from this, and uses
its internal rules that it knows are UTF-8.  A future commit will warn
when this happens.

6 years agoChange some "shouldn't happen" failures into panics
Karl Williamson [Fri, 5 Jan 2018 18:35:00 +0000 (11:35 -0700)]
Change some "shouldn't happen" failures into panics

If the system is so broken that these libc calls are failing, soldiering
on won't lead to sane results.

THis rewords some existing panics, and adds the errno to the output for
all of them.

6 years agoForbid 'pig' locale
Karl Williamson [Sun, 28 Jan 2018 21:55:31 +0000 (14:55 -0700)]
Forbid 'pig' locale

This is a toy locale found on some systems, which isn't fully
implemented, and if one tries to switch to it can cause failures.

6 years agoAvoid changing locale when finding radix char
Karl Williamson [Thu, 18 Jan 2018 23:20:02 +0000 (16:20 -0700)]
Avoid changing locale when finding radix char

On systems that have the POSIX 2008 operations, including
nl_langinfo_l(), this commit causes them to not have to actually change
the locale when determining what the decimal point character is.

The locale may have to change during the printing/reading of numbers,
but eventually we can use sprintf_l(), if available, to avoid that too.

6 years agoPerl_sv_2pv_flags: Potentially avoid work
Karl Williamson [Thu, 18 Jan 2018 22:56:33 +0000 (15:56 -0700)]
Perl_sv_2pv_flags: Potentially avoid work

By using a macro that is private to the core, this code can avoid
thinking it has to deal with a non-dot radix character, as even if we
are using the locale radix, that is often a dot.

6 years agonumeric.c: Remove duplicate PERL_ARGS_ASSERT
Karl Williamson [Thu, 18 Jan 2018 22:53:42 +0000 (15:53 -0700)]
numeric.c: Remove duplicate PERL_ARGS_ASSERT

By moving the call to one instance of this macro, the other can be
removed.

6 years agolocale.c: White-space only
Karl Williamson [Thu, 18 Jan 2018 22:52:50 +0000 (15:52 -0700)]
locale.c: White-space only

Outdent to compensate for previous patch removing several blocks

6 years agoKeep PL_numeric_radix_sv always set
Karl Williamson [Thu, 18 Jan 2018 22:45:19 +0000 (15:45 -0700)]
Keep PL_numeric_radix_sv always set

Previously this was removed if the radix was dot.  By keeping it set to
a dot, we simplify some code, removing some branches.

6 years agolocale.c: Replace by function that does the same thing
Karl Williamson [Thu, 18 Jan 2018 22:32:45 +0000 (15:32 -0700)]
locale.c: Replace by function that does the same thing

This logic occurs often enough that a function has been created to do
it.  So use that.

6 years agoPOSIX::localeconv() Use new fcn; avoid recalcs
Karl Williamson [Wed, 17 Jan 2018 19:40:40 +0000 (12:40 -0700)]
POSIX::localeconv() Use new fcn; avoid recalcs

This calls strlen() once, instead of passing 0 to the the subsidiary
functions which causes them to call it each time.  It also uses the new
function is_utf8_non_invariant_string() instead of doing here what that
function does.

6 years agoPOSIX.xs: White space only
Karl Williamson [Wed, 17 Jan 2018 18:16:15 +0000 (11:16 -0700)]
POSIX.xs: White space only

Vertically align for readability

6 years agolocale.c: Move some mutex ops
Karl Williamson [Wed, 17 Jan 2018 18:07:42 +0000 (11:07 -0700)]
locale.c: Move some mutex ops

A future commit will add a mutex, and create the convention that this
mutex if used in combination with the new one always be tried after the
new one is in effect, in order to prevent the possibility of deadlock.
Do it now, before the new one gets added.

This also adds some comments about the reason for this mutex.

6 years agolocale.c: White-space only
Karl Williamson [Wed, 17 Jan 2018 17:12:30 +0000 (10:12 -0700)]
locale.c: White-space only

Indent code to account for previous commits adding some blocks

6 years agolocale.c: Use macro instead of its expansion
Karl Williamson [Wed, 17 Jan 2018 15:27:04 +0000 (08:27 -0700)]
locale.c: Use macro instead of its expansion

This macro in a future commit will become more complex.

6 years agolocale.c: Do common task in one place
Karl Williamson [Wed, 17 Jan 2018 05:09:27 +0000 (22:09 -0700)]
locale.c: Do common task in one place

This function in some cases may need to temporarily switch the
LC_NUMERIC code.  Instead of repeating the logic to determine if this is
needed, do it once.

6 years agoPOSIX.xs: Keep locale change to minimum span
Karl Williamson [Wed, 17 Jan 2018 00:38:45 +0000 (17:38 -0700)]
POSIX.xs: Keep locale change to minimum span

Move the restore to as close to the save as possible so that the locale
is in an unstable state for as short a time as possible.

6 years agoPOSIX::strftime: Add better fallback about UTF-8
Karl Williamson [Wed, 17 Jan 2018 20:24:46 +0000 (13:24 -0700)]
POSIX::strftime: Add better fallback about UTF-8

If the function returns a valid string that isn't completely UTF-8
invariant, the function assumes it is UTF-8 if we are in a UTF-8 locale.
This works, but in the unlikely event that the system has no LC_TIME, we
can't tesll if it is in a UTF-8 locale.  As a better fallback position,
this commit adds the check that there is just a single  script of the
time string, adding a measure of reassurance that out call that it is
UTF-8 is correct.

This is unlikely to be used, but now that there is a function to call
that determines if this is a script run, it's easy to add, and unlikely
to actually get compiled.

6 years agogrok_numeric_radix(): Avoid recalculating
Karl Williamson [Wed, 17 Jan 2018 20:18:50 +0000 (13:18 -0700)]
grok_numeric_radix(): Avoid recalculating

This function just determined that we are in the scope of 'use locale',
hence the underlying radix character should be used.  This commit
changes to use the macro that directly does that; previously the macro
that redundantly looks at if we are in the scope was used.

6 years agosv_vcatpvfn_flags() Balance LC_NUMERIC changes/restores
Karl Williamson [Wed, 17 Jan 2018 20:00:44 +0000 (13:00 -0700)]
sv_vcatpvfn_flags() Balance LC_NUMERIC changes/restores

Prior to this commit, the restore for LC_NUMERIC was getting called even
if there were no corresponding store.  Change so they are balanced; a
future commit will require this.

6 years agoperl.h: Remove some obsolete macros
Karl Williamson [Mon, 15 Jan 2018 23:39:44 +0000 (16:39 -0700)]
perl.h: Remove some obsolete macros

These no longer make sense; were for core internal use only

6 years agovutil.c: White_space only
Karl Williamson [Mon, 15 Jan 2018 22:56:43 +0000 (15:56 -0700)]
vutil.c: White_space only

Properly indent a block, and add spaces where C11++ deprecates not
having them

6 years agoSimplify some LC_NUMERIC macros
Karl Williamson [Mon, 15 Jan 2018 22:48:57 +0000 (15:48 -0700)]
Simplify some LC_NUMERIC macros

These macros are marked as subject to change and are not documented
externally.  I don't know what I was thinking when I named some of them,
but whatever no longer makes sense to me.  Simplify them, and change so
there is only one restore macro to remember.

6 years agotoke.c: Remove unnecessary macro calls
Karl Williamson [Mon, 15 Jan 2018 04:43:43 +0000 (21:43 -0700)]
toke.c: Remove unnecessary macro calls

These macros were to shift the LC_NUMERIC state into using a dot for the
radix character.  When I wrote this code, I assumed that parsing should
be using just the dot.  Since then, I have discovered that this wraps
other uses where the dot is not correct, so remove it.

6 years agoperl.h: Remove unused locale core macro
Karl Williamson [Mon, 15 Jan 2018 04:37:16 +0000 (21:37 -0700)]
perl.h: Remove unused locale core macro

This undocumented macro is unused in the core, and all these are
commented that they are subject to change.  And it confuses things, so
just remove it.

6 years agolocale.c: Windows will never be EBCDIC
Karl Williamson [Sun, 7 Jan 2018 22:30:06 +0000 (15:30 -0700)]
locale.c: Windows will never be EBCDIC

This adjusts the conditional compilation so that win32 is a subset of
non-EBCDIC.  This will be useful in the next commit.

6 years agolocale.c: Simplify expression
Karl Williamson [Fri, 5 Jan 2018 19:57:37 +0000 (12:57 -0700)]
locale.c: Simplify expression

Since this is operating on C strings, we don't have to check the
lengths, but can rely on the underlying functions to work.

6 years agoCache locale UTF8-ness lookups
Karl Williamson [Tue, 2 Jan 2018 23:54:28 +0000 (16:54 -0700)]
Cache locale UTF8-ness lookups

Some locales are UTF-8, some are not.  Knowledge of this is needed in
various circumstances.  This commit saves the results of the last
several lookups so they don't have to be recalculated each time.

The full generality of POSIX locales is such that you can have error
messages be displayed in one locale, say Spanish, while other things are
in French.  To accommodate this generality, the program can loop through
all the locale categories finding the UTF8ness of the locale it points
to.  However, in almost all instances, people are going to be in either
French or in Spanish, and not in some combination.  Suppose it is a
French UTF-8 locale for all categories.  This new cache will know that
the French locale is UTF-8, and the queries for all but the first
category can return that immediately.

This simple cache avoids the overhead of hashes.

This also fixes a bug I realized exists in threaded perls, but haven't
reproduced.  We do not support locales in such perls, and the user must
not change the locale or 'use locale'.  But perl itself could change the
locale behind the scenes, leading to segfaults or incorrect results.
One such instance is the determination of UTF8ness.  But this only could
happen if the full generality of locales is used so that the categories
are not all in the same locale.  This could only happen (if the user
doesn't change locales) if the environment is such that the perl program
is started up so that the categories are in such a state.  This commit
fixes this potential bug by caching the UTF8ness of each category at
startup, before any threads are instantiated, and so checking for it
later just looks it up in the cache, without perl changing the locale.

6 years agolocale.c: Avoid duplicate work
Karl Williamson [Tue, 2 Jan 2018 21:23:24 +0000 (14:23 -0700)]
locale.c: Avoid duplicate work

As the comments say, the needed value is already readily available

6 years agolocale.c: Avoid some work
Karl Williamson [Tue, 2 Jan 2018 20:38:16 +0000 (13:38 -0700)]
locale.c: Avoid some work

We've already worked out whether the decimal point is a dot or not.  We
can pass that information to the called routine so it doesn't have to
figure it out again.

6 years agolocale.c: Use non-control for a format dummy
Karl Williamson [Tue, 2 Jan 2018 20:19:03 +0000 (13:19 -0700)]
locale.c: Use non-control for a format dummy

We need a plain character here.  I used a '\e' before, but it would be
better to have something that isn't a control, so just change it to a
blank

6 years agolocale.c: Create a block around some code; indent
Karl Williamson [Thu, 25 Jan 2018 18:28:54 +0000 (11:28 -0700)]
locale.c: Create a block around some code; indent

Under some configurations depending on platform and Configure options,
these declarations are not at the beginning of a block. violating C
language rules.

6 years agolocale.c: Avoid some more locale changes
Karl Williamson [Tue, 2 Jan 2018 19:25:35 +0000 (12:25 -0700)]
locale.c: Avoid some more locale changes

In a few places here we can test if we are already in the locale we want
to be in, and not switch unnecessarily if so.

6 years agoAvoid some unnecessary changing of locales
Karl Williamson [Tue, 2 Jan 2018 06:03:34 +0000 (23:03 -0700)]
Avoid some unnecessary changing of locales

The LC_NUMERIC locale category is kept so that generally the decimal
point (radix) is a dot.  For some (mostly) output purposes, it needs to
be swapped into the program's current underlying locale so that a
non-dot can be printed.

This commit changes things so that if the current underlying locale uses
a decimal point, the swap doesn't happen, as it's not needed.

6 years agoTeach perl about more locale categories
Karl Williamson [Wed, 26 Jul 2017 14:59:33 +0000 (08:59 -0600)]
Teach perl about more locale categories

glibc has various other categories than the ones perl handles, for
example LC_PAPER.  This commit adds knowledge of these to perl, so that
one can set them, interrogate them, and have libraries work on them,
even though perl itself does not.

This is in preparation for future commits, where it becomes more
important than currently for perl to know about all the locale
categories on the system.

I looked through various other systems to try to find other categories,
but did not see any.  If a system does have such a category, it is
pretty easy to tell perl about it, and recompile.  Use the changes in
this commit as a template, and send an email to perlbug@perl.org, so
that the next Perl release will have it.

6 years agoperl.h: White-space only
Karl Williamson [Tue, 2 Jan 2018 05:20:25 +0000 (22:20 -0700)]
perl.h: White-space only

6 years agolocale.c: Add compile check for unimplemented behavior
Karl Williamson [Tue, 2 Jan 2018 03:41:21 +0000 (20:41 -0700)]
locale.c: Add compile check for unimplemented behavior

Instead of silently not working.

6 years agolocale.c: White-space only
Karl Williamson [Tue, 2 Jan 2018 03:30:39 +0000 (20:30 -0700)]
locale.c: White-space only

Indent because the previous commit created an enclosing block, and
add a blank line elsewhere

6 years agolocale.c: Refactor Ultrix code
Karl Williamson [Tue, 2 Jan 2018 03:00:03 +0000 (20:00 -0700)]
locale.c: Refactor Ultrix code

Examination shows that this code does nothing unless LC_ALL is defined.
So explicitly test at compile time for that.

Also, two variables don't have to be declared so globally, and by
reducing their scope, by creating a new block we don't have to have
PERL_UNUSED_ARG()s for them

6 years agolocale.c: Avoid rescanning a string
Karl Williamson [Tue, 2 Jan 2018 02:07:19 +0000 (19:07 -0700)]
locale.c: Avoid rescanning a string

We can use a parameter to find out where in the string the portion of
interest starts.  Do that to avoid starting again from scratch.

6 years agolocale.c: Use fcns instead of macros
Karl Williamson [Tue, 2 Jan 2018 01:33:59 +0000 (18:33 -0700)]
locale.c: Use fcns instead of macros

Here the macros being used expand into the functions being called,
without adding any value to using the macros, and making things slightly
less clear.

6 years agolocale.c: Add const to several variables
Karl Williamson [Tue, 2 Jan 2018 01:17:41 +0000 (18:17 -0700)]
locale.c: Add const to several variables

6 years agolocale.c: Improve, add comments
Karl Williamson [Tue, 2 Jan 2018 01:15:27 +0000 (18:15 -0700)]
locale.c: Improve, add comments

6 years agoperl.h: Add comment, rephrase another
Karl Williamson [Tue, 2 Jan 2018 01:01:45 +0000 (18:01 -0700)]
perl.h: Add comment, rephrase another

6 years agoPerl_langinfo: Teach about YESSTR and NOSTR
Karl Williamson [Sun, 19 Nov 2017 00:34:25 +0000 (17:34 -0700)]
Perl_langinfo: Teach about YESSTR and NOSTR

These are items that nl_langinfo() used to be required to return, but
are considered obsolete.  Nonetheless, this drop-in replacement for that
function should know about them for backward compatibility.

6 years agoAPItest/t/locale.t: Add some tests
Karl Williamson [Mon, 1 Jan 2018 22:07:45 +0000 (15:07 -0700)]
APItest/t/locale.t: Add some tests

This makes sure that the entries for which the expected return value may
legitimately vary from platform to platform get tested as returning
something,  skipping the test if the item isn't known on the platform.

A couple of comments are also added.

6 years agoAdd check that "$!" is correctly interpreted as UTF-8
Karl Williamson [Thu, 4 Jan 2018 03:41:29 +0000 (20:41 -0700)]
Add check that "$!" is correctly interpreted as UTF-8

We sometimes need to know if an error message is UTF-8 or not.
Previously we checked that it is syntactically valid UTF-8, and that the
LC_MESSAGES locale is UTF-8.  But some systems, notably Windows, do not
have LC_MESSAGES.  For those, this commit adds a different, semantic,
check that the text of the message when interpreted as UTF-8 is all in
the same Unicode script.  This is not foolproof, unlike the LC_MESSAGES
check, but it's better than what we have now for such systems.  It
likely is foolproof for non-Latin locales, as any message will have a
bunch of characters in that locale, and no ASCII Latin ones.  For a
Latin locale, these ASCII letters could be intermixed with the UTF-8
ones, causing potential ambiguity.

6 years agoRemove uncompilable code
Karl Williamson [Wed, 15 Nov 2017 05:27:06 +0000 (22:27 -0700)]
Remove uncompilable code

This code was never compiled because of a misspelling in the #ifdef.
No problem surfaced, so just remove it.  The next commit adds a different
check.

6 years agoperl.c: Move initialization of inversion lists
Karl Williamson [Tue, 9 Jan 2018 02:08:54 +0000 (19:08 -0700)]
perl.c: Move initialization of inversion lists

This is now done very early in the file, as it may be needed for
initializing the locale handling.

6 years agoisSCRIPT_RUN: Document in perlintern
Karl Williamson [Thu, 18 Jan 2018 21:09:24 +0000 (14:09 -0700)]
isSCRIPT_RUN: Document in perlintern