This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
4 months agolocale.c: Move handling of LC_MESSAGES langinfo items
Karl Williamson [Thu, 28 Dec 2023 00:26:07 +0000 (17:26 -0700)]
locale.c: Move handling of LC_MESSAGES langinfo items

This commit moves the handling of langinfo items associated with the
LC_MESSAGES category to emulate_langinfo() when nl_langinfo() is not
available on the platform away from Perl_langinfo8().

This is a step in the process of handling all such items in
emulate_langinfo().

4 months agolocale.c: Consolidate handling of some langinfo items
Karl Williamson [Wed, 27 Dec 2023 23:13:10 +0000 (16:13 -0700)]
locale.c: Consolidate handling of some langinfo items

Without nl_langinfo(), some Configurations handled nl_langinfo() items
associated with the LC_CTYPE, LC_MONETARY, and LC_NUMERIC categories in
Perl_langinfo8(), and some Configurations in emulate_langinfo().  This
commit consolidates all the handling to emulate_langinfo().

This commit removes the only use of a macro, which is hence also
removed.

4 months agolocale.c: Move check for unknown langinfo items
Karl Williamson [Wed, 27 Dec 2023 22:33:06 +0000 (15:33 -0700)]
locale.c: Move check for unknown langinfo items

This moves this check into the lowest level function, so that no
duplication is needed.

4 months agolocale.c: Handle some ignored categories in langinfo emulation
Karl Williamson [Tue, 26 Dec 2023 14:13:55 +0000 (07:13 -0700)]
locale.c: Handle some ignored categories in langinfo emulation

It is possible to Configure perl to not allow any or all of the locale
categories on the platform to be changed away from the C locale,
generally due to libc limitations.  OpenBSD, for example, keeps every
category but one in C; so perl shouldn't even try to change any of
those.

On platforms without the libc nl_langinfo() function, perl emulates it.
Prior to this commit, the emulation did not properly handle the case
of categories needing to stay in C.  This did not lead to bugs, because
external to this file, any such calls were intercepted by
Perl_langinfo8(), and internally, we just didn't call it under those
circumstances.

But this leads to some awkwardness, and it is more maintainable to have
the handling in one place; which is this low-level emulation.

This commit causes the emulation to handle LC_CTYPE, LC_NUMERIC, and
LC_MONETARY needing to stay in the C locale.  Future commits will add
the other categories, and remove the redundant checks in
Perl_langinfo8().

4 months agolocale.c: Effectively white-space, comments only
Karl Williamson [Mon, 8 Jan 2024 17:55:21 +0000 (10:55 -0700)]
locale.c: Effectively white-space, comments only

The previous few commits have added/removed code blocks and #if
directives.  Adjust white space accordingly

This also adds explanatary comments

4 months agolocale.c: Compile S_emulate_langinfo() under more Configurations
Karl Williamson [Mon, 8 Jan 2024 17:49:03 +0000 (10:49 -0700)]
locale.c: Compile S_emulate_langinfo() under more Configurations

This is in preparation for some code to be consolidated into just this
one function.

4 months agolocale.c: Always compile save__to_buffer()
Karl Williamson [Mon, 1 Jan 2024 18:48:13 +0000 (11:48 -0700)]
locale.c: Always compile save__to_buffer()

The next commit will want to use it in more Configurations, and a future
commit in all Configurations.

4 months agolocale.c: Tighten circumstances some code is generated
Karl Williamson [Wed, 27 Dec 2023 22:10:42 +0000 (15:10 -0700)]
locale.c: Tighten circumstances some code is generated

This code need not be compiled except under the circumstances defined in
this commit.

4 months agolocale.c: Move GCC DIAG IGNORE
Karl Williamson [Tue, 26 Dec 2023 13:09:49 +0000 (06:09 -0700)]
locale.c: Move GCC DIAG IGNORE

The previous commit changed two nested switch() statements.  The inner
one turned off implicit switch() case statement fallthrough warnings.
This commit applies that to the entire outer switch().

4 months agolocale.c: Refactor two nested switch() statements
Karl Williamson [Tue, 26 Dec 2023 13:08:51 +0000 (06:08 -0700)]
locale.c: Refactor two nested switch() statements

This slightly refactors these so that many case labels are no longer
repeated.  It does this by making the nested one the default: of the
outer one, and the outer's previous default: becomes the inner's
default (which formerly was useless, so panicked).

4 months agolocale.c: Split a function in two
Karl Williamson [Thu, 21 Dec 2023 17:07:15 +0000 (10:07 -0700)]
locale.c: Split a function in two

Prior to this commit, the function was #ifdef'd so that one or the other
part would compile.  But future commits will cause them both to need to
be compiled in some circumstances, with the first part potentially
calling the second part.

Note that the 2nd part doesn't need the parameter 'cat_index' that the
first part does.

4 months agolocale.c: Recompute variable in 2nd part of function
Karl Williamson [Thu, 21 Dec 2023 15:20:43 +0000 (08:20 -0700)]
locale.c: Recompute variable in 2nd part of function

This is in preparation for the next commit splitting the function in
two, and the current 2nd part will not need or have this variable passed
in as an argument.

4 months agolocale.c: Move some functions to earlier in the file
Karl Williamson [Thu, 14 Dec 2023 17:48:35 +0000 (10:48 -0700)]
locale.c: Move some functions to earlier in the file

These are now more logically placed.

4 months agolocale.c: Remove PERL_UNUSED_ARG
Karl Williamson [Mon, 4 Dec 2023 15:27:26 +0000 (08:27 -0700)]
locale.c: Remove PERL_UNUSED_ARG

'which_mask' is now always used

4 months agoperl.h: #include locale_table.h even if NO_LOCALE
Karl Williamson [Wed, 3 Jan 2024 17:04:19 +0000 (10:04 -0700)]
perl.h: #include locale_table.h even if NO_LOCALE

It defines some symbols which help in this circumstance, and others
which would otherwise have to be #ifdef'd against in order to compile.

4 months ago-DNO_LOCALE implies -DNO_LOCALE_COLLATE
Karl Williamson [Wed, 3 Jan 2024 16:50:02 +0000 (09:50 -0700)]
-DNO_LOCALE implies -DNO_LOCALE_COLLATE

This is a follow-on to the following commit,
which somehow missed this category.

 commit 08123d87ea3adde7ae36a205b3262804532efbed
 Author: Karl Williamson <khw@cpan.org>
 Date:   Tue Dec 19 15:00:33 2023 -0700

   -DNO_LOCALE implies -DNO_LOCALE_CTYPE, etc.

     If we aren't to pay attention to locales in general; we certainly
     shouldn't be paying attention to individual locale categories.

     This commit allows for cleaner #ifdefs

4 months agolocale.c: Skip a debug check if no LC_CTYPE
Karl Williamson [Wed, 3 Jan 2024 16:55:48 +0000 (09:55 -0700)]
locale.c: Skip a debug check if no LC_CTYPE

This check is done only when DEBUGGING is active; but it makes no sense
if LC_CTYPE can only be the C locale.

4 months agolib/locale.t: Display thousands separator under debug
Karl Williamson [Wed, 3 Jan 2024 17:06:49 +0000 (10:06 -0700)]
lib/locale.t: Display thousands separator under debug

This allows someone to run this test, which exercises, every locale on
the system, and see at a glance what this value is.  There is special
code to handle this value, and it is helpful to see what the system has
for it.  This does not affect normal operation; only when the test is
run with a debugging environment variable set.

4 months agoallow some basic infrastructure to load with -Dusedefaultstrict
Tony Cook [Wed, 20 Dec 2023 03:58:05 +0000 (14:58 +1100)]
allow some basic infrastructure to load with -Dusedefaultstrict

The changes to t/test.pl appear to be real bugs.

This allows `make test_harness` to run, but many tests will still
fail under -Dusedefaultstrict

This addresses #21732 but does not fix it.  I'm unsure how
supported that build option is.

4 months agopp_backtick: remove RC_STACK wrapper and use the new APIs
Tony Cook [Thu, 28 Dec 2023 10:08:41 +0000 (21:08 +1100)]
pp_backtick: remove RC_STACK wrapper and use the new APIs

4 months agolocale.c: Adjust some #if, #else
Karl Williamson [Tue, 26 Dec 2023 13:36:05 +0000 (06:36 -0700)]
locale.c: Adjust some #if, #else

This removes the need for a FALLTHROUGH comment.

4 months agolocale.c: Reorder two more case: statements
Karl Williamson [Tue, 26 Dec 2023 13:34:01 +0000 (06:34 -0700)]
locale.c: Reorder two more case: statements

This is in preparation for future commits where the new order will make
more sense than the current one.

4 months agolocale.c: Reorder cases in a switch()
Karl Williamson [Fri, 29 Dec 2023 20:13:51 +0000 (13:13 -0700)]
locale.c: Reorder cases in a switch()

The CODESET case was kept last because it had by far the largest amount
of code of any of the cases.  But the majority of it has now been
shunted into a separate function.  There are, in contrast,  many LC_TIME
related case statements, and future commits will add significantly to
the amount of code implementing them; therefore they are better placed
last in the switch().

4 months agoperlguts: fix ref count in tie() example
David Mitchell [Wed, 3 Jan 2024 13:39:21 +0000 (13:39 +0000)]
perlguts: fix ref count in tie() example

Spotted by Marcel Telka.

4 months ago[MERGE] PERL_RC_STACK: add _IMM, unwrap, fix leaks
David Mitchell [Wed, 3 Jan 2024 12:57:09 +0000 (12:57 +0000)]
[MERGE] PERL_RC_STACK: add _IMM, unwrap, fix leaks

- unwrap the ops pp_prtf, pp_sprintf, pp_subst, pp_substcont, pp_bless
- fix a few PERL_RC_STACK-related leaks I noticed along the way
- add some _IMM variants of the rpp_ functions when the SV being pushed
  is an immortal
- make wide use of the _IMM and _NN rpp_ function variants
- optimise two-item stack pops and replaces

4 months agomake rpp_popfree_2_NN() use rpp_free_2_()
David Mitchell [Sat, 16 Dec 2023 16:50:41 +0000 (16:50 +0000)]
make rpp_popfree_2_NN() use rpp_free_2_()

Like for Perl_rpp_replace_2_1*, this means that freeing one or both SVs
being popped is done by a single function call.

4 months agoOptimise rpp_replace_2_{1,IMM}_NN()
David Mitchell [Wed, 13 Dec 2023 14:21:15 +0000 (14:21 +0000)]
Optimise rpp_replace_2_{1,IMM}_NN()

These two static functions are used in a lot of pp functions.
This commit does two main things. First, it makes the size of the inline
function smaller, and second, it uses a single branch (rather than two)
to decide whether either of the two SVs being popped need to be freed.

In detail: apart from the actual stack manipulation itself, the other
main action of these two functions:

    rpp_replace_2_1_NN()
    rpp_replace_2_IMM_NN()

is to do the equivalent of

    SvREFCNT_dec_NN(PL_stack[-1]);
    SvREFCNT_dec_NN(PL_stack[-0]);

Now, SvREFCNT_dec_NN() is an inline function which expands to
something like:

    U32 rc = SvREFCNT(sv);
    if (LIKELY(rc > 1))
        SvREFCNT(sv) = rc - 1;
    else
        Perl_sv_free2(aTHX_ sv, rc);

With this expanded *twice* within the body of rpp_replace_2_1_NN(),
there are two branch tests and two function calls - all of which are
expanded inline into the bodies of all 50+ pp functions which use it.
This commit makes this be changed to something equivalent to

    U32 rc1 = SvREFCNT(sv1);
    U32 rc2 = SvREFCNT(sv2);
    if (LIKELY(rc1 > 1 && rc2 > 1)) {
        SvREFCNT(sv1) = rc1 - 1;
        SvREFCNT(sv2) = rc2 - 1;
    }
    else
        Perl_rpp_free_2_(aTHX_ sv1, sv2, rc1, rc2);

Where Perl_rpp_free_2_() does the hard work of deciding whether either
or both SVs actually need freeing.

This approach assumes that, most of the time, rpp_replace_2_1_NN() won't
actually be freeing either of the two old args on the stack, because
often they are likely to be PADTMPs or lexicals or array elements or
or immortals or whatever, which have a longer lifetime. I.e.  this
commit is betting that

    $a + ($b * $c);   # RHS of '+' is a PADTMP

is more common than

    $a + f();         # RHS of '+' is a temporary SV with RC==1

4 months agomake RC-stack-aware: unwrap pp_bless()
David Mitchell [Tue, 12 Dec 2023 11:58:29 +0000 (11:58 +0000)]
make RC-stack-aware: unwrap pp_bless()

Remove the temporary wrapper from pp_bless().

4 months agopp_subst(): consolidate some duplicated code
David Mitchell [Tue, 12 Dec 2023 11:49:45 +0000 (11:49 +0000)]
pp_subst(): consolidate some duplicated code

There are a couple of places in pp_subst() which create a new mortal to
return the iteration count. Consolidate them into a single code block at
the end of the function.

4 months agomake RC-stack-aware: unwrap pp_subst, pp_substcont
David Mitchell [Tue, 12 Dec 2023 00:31:31 +0000 (00:31 +0000)]
make RC-stack-aware: unwrap pp_subst, pp_substcont

Remove the temporary wrappers from pp_subst() and pp_substcont().

Note that under s///e, any arguments that were on the stack on entry
to pp_subst() are now left on there until the final call to pp_substcont,
who's responsibility it is now to pop them. This is so that they don't
get prematurely freed on PERL_RC_STACK builds.

4 months agomake RC-stack-aware: unwrap pp_prtf, pp_sprintf
David Mitchell [Mon, 11 Dec 2023 21:40:50 +0000 (21:40 +0000)]
make RC-stack-aware: unwrap pp_prtf, pp_sprintf

Remove the temporary wrappers from pp_prtf() (which implements the perl
'printf' function but saves two whole letters!) and pp_sprintf.

4 months agouse rpp_foo_NN() and rpp_foo_IMM() widely
David Mitchell [Mon, 11 Dec 2023 11:36:55 +0000 (11:36 +0000)]
use rpp_foo_NN() and rpp_foo_IMM() widely

Make more use of the recently-added _NN and _IMM_NN variants of common
functions throughout the pp*.c files. The _NN ones assume anything being
popped of the stack is non-NULL, so that check can be skipped for each
SV being popped. The _IMM variants mean that the one item being put on
the stack is an immortal like &PL_sv_undef, so doesn't need its
reference count adjusting.

So these are all just small optimisations.

4 months agoadd _IMM variants to the rpp_foo() fns
David Mitchell [Mon, 11 Dec 2023 11:37:37 +0000 (11:37 +0000)]
add _IMM variants to the rpp_foo() fns

These new function variants assume that the item being put on the stack
is one of the immortals (PL_sv_undef/yes/no/zero), and so skips
incrementing their reference count. This is for a minor efficiency
saving, rather than being necessary for correct functioning of the code.

This commit also tidies up a few of the related rpp_ functions: in
particular moving asserts out of the PERL_RC_STACK-only code into the
general code: an rpp_foo_NN() function should assert fail on a null SV
regardless of whether perl has been compiled under PERL_RC_STACK or not.

4 months agoResurrect immortals before checking for SvTEMP()
David Mitchell [Wed, 6 Dec 2023 20:46:09 +0000 (20:46 +0000)]
Resurrect immortals before checking for SvTEMP()

sv_clear() and sv_free2() both do, in this order, (simplified):

    #ifdef DEBUGGING
        if (SvTEMP(sv))
            Perl_ck_warner_d(..., Attempt to free temp prematurely",...);
    #endif

    if (SvIMMORTAL(sv))
        SvREFCNT(sv) = SvREFCNT_IMMORTAL

Now, it so happens that under DEBUGGING PERL_RC_STACK builds,

a) immortals such s PL_sv_undef have their refcount set to only 10 to
deliberately trigger the edge case of them being freed more often;

b) PERL_RC_STACK builds increasingly don't bother to increment the
reference counts of immortals when pushing them on the stack - this
saves a bit of time, and just means that once every two billion times on
normal builds the ref count drops to zero and sv_clear() sets it back to
SvREFCNT_IMMORTAL.

The combination of these has suddenly made it much more likely that
an immortal on the stack which has also been mortalised, will be passed
to sv_clear() and thus spuriously output the warning message.

So this commit swaps the order of the checks.

In the SvIMMORTAL() branch, it now also turns off SvTEMP.

4 months agofix minor leak under use feature 'module_true'
David Mitchell [Sat, 9 Dec 2023 10:13:00 +0000 (10:13 +0000)]
fix minor leak under use feature 'module_true'

Under PERL_RC_STACK builds, any return value from the module, i.e.
the
    1;
or other final statement value, would leak.

4 months agofix obscure leak in sort { block } ...
David Mitchell [Fri, 8 Dec 2023 23:20:14 +0000 (23:20 +0000)]
fix obscure leak in sort { block } ...

This only leaked on PERL_RC_STACK builds, and only in the relatively
rare code path of a sort block which included a nested scope (such as
a for loop), and which then used 'return' to return the value.

4 months agofix leak in list const folding under PERL_RC_STACK
David Mitchell [Thu, 7 Dec 2023 18:43:05 +0000 (18:43 +0000)]
fix leak in list const folding under PERL_RC_STACK

S_gen_constant_list() wasn't taking account of the stack possibly being
reference-counted, and so when a list was being constant-folded into an
AV, that AV would leak, such as

    while (1) { my $x = eval '\(1..3)'; }

4 months agopp_sort: fix leak in PERL_RC_STACK inline sorting
David Mitchell [Tue, 5 Dec 2023 20:17:44 +0000 (20:17 +0000)]
pp_sort: fix leak in PERL_RC_STACK inline sorting

For the optimised case where the src and dst are both the same array,
e.g.
    @a = sort { ... } @a;

pp_sort() optimises this. When the code was modified to run under
PERL_RC_STACK, I introduced a leak: all the SVs on the stack after
sorting were then stored in the array and their ref counts incremented,
then the stack pointer was reset *without* decrementing the ref count of
each SV. So every SV in the array by the time pp_sort() returned had a
reference count one too high.

The fix is trivial - don't bump the ref counts when storing them in
the array.

4 months agolocale.c: handle codesets GB18030, EUC-TW
Karl Williamson [Wed, 27 Dec 2023 13:11:52 +0000 (06:11 -0700)]
locale.c: handle codesets GB18030, EUC-TW

These two codesets are multi-byte, like UTF-8.  Previously we sort of-of
looked for them, but not fully.  This commit rectifies that.  If the
code set matches one of those two, we don't create a bias towards the
locale being UTF-8.

I discovered this by testing in an unusual Configuration.

4 months agolocale.c: Minimize time spent with a toggled locale
Karl Williamson [Thu, 21 Dec 2023 15:25:23 +0000 (08:25 -0700)]
locale.c: Minimize time spent with a toggled locale

It's better to disturb things the least amount of time as possible.
Here it's just as convenient to reorder things so the untoggling is done
sooner.

4 months agolocale.c: toggle LC_CTYPE in S_override
Karl Williamson [Wed, 27 Dec 2023 13:10:57 +0000 (06:10 -0700)]
locale.c: toggle LC_CTYPE in S_override

Commit 0b60dbbe529b372662069aaadf3dfcf18f85c1cc missed this.  Most of
this function must be done in the requested locale so that the libc
functions work on the correct underlying locale.

4 months agolocale.c: toggling locales is a no-op if no locales
Karl Williamson [Wed, 27 Dec 2023 19:06:26 +0000 (12:06 -0700)]
locale.c: toggling locales is a no-op if no locales

When the only legal locale is C, toggling to another locale doesn't make
sense.  By #defining the macro that implements toggling this to do
nothing in this case, we can avoid some #ifdefs

4 months agolocale.c: C is the only locale under NO_LOCALE
Karl Williamson [Wed, 27 Dec 2023 17:37:09 +0000 (10:37 -0700)]
locale.c: C is the only locale under NO_LOCALE

It is possible to Configure perl to not pay attention to locales at all.
Effectively that means the only permissible locale is "C", which
underlies all C programs at startup.

Thus, when asked what the current locale is, the answer is always going
to be "C"; and we can define the macro that computes this info to just
return "C" instead of doing any lookup.

4 months agolocale.c: Be sure to toggle into dot radix locale
Karl Williamson [Sun, 31 Dec 2023 05:00:53 +0000 (22:00 -0700)]
locale.c: Be sure to toggle into dot radix locale

This fixes GH #21746

Perl keeps the LC_NUMERIC category in a locale where the radix character
is a dot, regardless of what the user has requested.  This is because
much XS code has been written with the dot assumption.  When the user's
actual radix character is desired, the locale is briefly toggled to that
one for the duration of the operation.

When the user changes the LC_NUMERIC locale, the new one is noted, but
the attempted change is otherwise ignored unless its radix is a dot.
The new one will be briefly toggled into when appropriate.

The blamed commit contains a logic error

commit 818cdb7aa9f85227c1c7313257c6204c872beb94
Author:     Karl Williamson <khw@cpan.org>
AuthorDate: Sun Apr 11 05:57:07 2021 -0600
Commit:     Karl Williamson <khw@cpan.org>
CommitDate: Thu Sep 1 09:02:04 2022 -0600

    locale.c: Skip code if will be a no-op

It decided it was a no-op if the new locale that the user is changing to
is the same as the previous locale.  But it didn't consider that what
actually happens is that the new locale does actually get changed, and
this code is supposed to make sure that, before returning control to the
user, that a dot radix locale is in effect.

If the new locale is a dot radix locale, then no harm is done by
skipping the code, but otherwise things can go wrong.

I am chagrined that I made this logic error without noticing before it
got pushed, and am surprised that it took this long for the error to
surrface.  There must be something else intervening to make this not a
problem in most circumstances, but I haven't analyzed what it might be.

The details as to why it happened in this test case are pretty obscure.
The locale in effect is looking for a comma radix, but what is being
checked for is a Perl version number, like 5.0936.  When converting that
to a floating point number, the dot is not recognized, and only the
initial '5' is found.  The failing code in a module has different
actions depending on the current perl version it is being called from,
and the conditional got the answer wrong because 5 is less than 5.0936,
whereas the actual version is above that.  So it did the wrong thing and
caused an error.

4 months agolocale.c: This label is only used in WIN32
Karl Williamson [Tue, 2 Jan 2024 20:31:00 +0000 (13:31 -0700)]
locale.c: This label is only used in WIN32

4 months agolocale.c: Refactor an #ifdef
Karl Williamson [Sun, 3 Dec 2023 17:47:42 +0000 (10:47 -0700)]
locale.c: Refactor an #ifdef

I have some #ifdef'd code that when enabled makes the locale handling
think it's running on a Windows MingW machine.  It doesn't emulate the
whole platform by any means, but it does reproduce the different logic
that is required for Windows in locale.c, and allows checking that
changes made likely will compile there without having to actually go to
a Windows machine.

It is mostly hidden from the rest of the code, except in the one spot
where it gets set up.  This makes it unobtrusive, but more importantly
maximizes the chances of it faithfully doing what Windows would do.

But there are two places in locale.c where I couldn't completely hide
it.  One is in teardown to avoid a leak, and the other is this spot in
the code where the codeset names are calculated.  There are big
differences in the Windows name syntax (integers) from the POSIX ones
(character strings).

This commit uses a macro to convert the integers into strings, so that
the required #ifdef doesn't interrupt the logic flow.

4 months agoDefine setlocale_i() on unsafe threaded builds
Karl Williamson [Tue, 4 Apr 2023 22:18:58 +0000 (16:18 -0600)]
Define setlocale_i() on unsafe threaded builds

On threaded Configurations where thread-safe locale handling is not
available, perl automatically does a modicum of prevention of races by
executing locale changes in a critical section, and copying the results
to a thread-safe location.

This commit defines setlocale_i() on such builds.  This macro is used to
bypass more complex handling required in fully thread-safe builds, and
is used where the libc setlocale() can be wrapped such that it works for
both querying what the existing locale is, and changing the locale.

4 months agolocale.c: Add a debugging statement
Karl Williamson [Fri, 7 Apr 2023 15:51:37 +0000 (09:51 -0600)]
locale.c: Add a debugging statement

This can be helpful in tracing what's happening with nl_langinfo()
calls.

4 months agolocale.c: Change some -DLv statements to -DL
Karl Williamson [Tue, 13 Jun 2023 17:38:56 +0000 (11:38 -0600)]
locale.c: Change some -DLv statements to -DL

These debug statements show something isn't quite normal, so shouldn't
require a verbose option to be displayed

4 months agolocale.c: Rmv duplicate strlen()
Karl Williamson [Tue, 2 Jan 2024 23:02:37 +0000 (16:02 -0700)]
locale.c: Rmv duplicate strlen()

Inadvertently introduced in 16c984f24273a831a74a01b900d5a400ae331c5d

4 months agoExperimentally enable glibc undocumented querylocale()
Karl Williamson [Mon, 25 Dec 2023 15:11:47 +0000 (08:11 -0700)]
Experimentally enable glibc undocumented querylocale()

This is querylocale() by another name, and is undocumented, hence we
haven't enabled it by default.  But it seems to work fine.  In order to
gain wider experience in using it, it is here default-enabled through
5.39.9 (unless we decide to end the experiment earlier), at which point
a compilation error will remind us to decide to keep it or take it out.

I put the check in locale.c instead of the more obvious perl.h, because
the definition would come earlier in perl.h than the PERL_VERSION macros
are defined, and I don't think its worth moving things around for just a
potential of a few releases.

4 months agoRevert "Experimentally enable glibc undocumented querylocale()"
Karl Williamson [Mon, 25 Dec 2023 14:42:51 +0000 (07:42 -0700)]
Revert "Experimentally enable glibc undocumented querylocale()"

This reverts commit 2ba88c8c7f1c33fe9f3145cbd2c4de3b1668efe9.
It turns out that that commit causes a porting test failure on the rare
Configuration where the POSIX 2008 locale API is used on a system
without threads.  (Someone might want to do that on platforms where
setlocale() is buggy.)

The next commit fixes this test.  Normally that would just be a
follow-on commit without this reversion.  But to ensure that when the
time comes to revert, the whole process is just one commit, this
reversion is done, and the next commit reinstates this reverted commit
plus adding the fix.

4 months agoHoist nl_item typedef definition
Karl Williamson [Tue, 19 Dec 2023 21:58:13 +0000 (14:58 -0700)]
Hoist nl_item typedef definition

nl_item is a typedef defined in <langinfo.h> for use by nl_langinfo().
But on platforms without this, perl emulates it, and hence needs to
create its own nl_item typedef.

Prior to this commit, the definition was in locale.c, which meant that
there needed to be two definitions in embed.fnc for each function that
has an argument of this type.

Simply putting it in "perl_langinfo.h" when there is no <langinfo.h>
allows those duplicate definitions to be removed

4 months agolocale.c: Move three functions within file
Karl Williamson [Sat, 16 Dec 2023 19:22:47 +0000 (12:22 -0700)]
locale.c: Move three functions within file

These are moved to where the other functions operating on the same thing
are.

4 months agolocale.c: Change variable name
Karl Williamson [Thu, 28 Dec 2023 15:23:47 +0000 (08:23 -0700)]
locale.c: Change variable name

Use the casing style that was otherwise uniformly used in this file.

4 months agolocale.c: Quit if strftime() returns EINVAL on Win32
Karl Williamson [Tue, 28 Nov 2023 15:47:45 +0000 (08:47 -0700)]
locale.c: Quit if strftime() returns EINVAL on Win32

It turns out that Windows sets errno to EINVAL when the libc
function strftime() finds the input format to be in error, though this
is not specified in the Standard (a defect there in my opinion).
Quit when an EINVAL errno is detected on Windows.

I chose not to change for Windows that the loop exits when the buffer
gets large.  It seems that it is best to keep a bound, and should it
ever be exceeded, we can raise the limit.

4 months agolocale.c: Remove obsolete comments
Karl Williamson [Wed, 20 Dec 2023 17:01:33 +0000 (10:01 -0700)]
locale.c: Remove obsolete comments

4 months agolocale.c: Delete erroneous comment
Karl Williamson [Tue, 2 Jan 2024 14:52:22 +0000 (07:52 -0700)]
locale.c: Delete erroneous comment

Part of the comment is correct, but is now documented elsewhere in the
file.  The part about it not being a problem with nl_langinfo() was long
ago found to be wrong; the code was corrected, but this comment wasn't
updated.

4 months agoFix an error in `perlvar`: `@+` may have *more* elements than `@-`.
Mathias Kende [Tue, 2 Jan 2024 11:53:27 +0000 (12:53 +0100)]
Fix an error in `perlvar`: `@+` may have *more* elements than `@-`.

4 months agofix the source link in the RMG to point to an existing document
Philippe Bruhat (BooK) [Tue, 2 Jan 2024 10:29:31 +0000 (11:29 +0100)]
fix the source link in the RMG to point to an existing document

4 months agoPrepare Module::Corelist for 5.39.7
Philippe Bruhat (BooK) [Tue, 2 Jan 2024 09:47:03 +0000 (10:47 +0100)]
Prepare Module::Corelist for 5.39.7

4 months agolocale.c: Fix bug in getting langinfo(CRNCYSTR)
Karl Williamson [Thu, 28 Dec 2023 19:51:34 +0000 (12:51 -0700)]
locale.c: Fix bug in getting langinfo(CRNCYSTR)

This does not affect platforms that have libc nl_langinfo().  Thus,
mainly Windows machines are affected.  The code was passing to
sv__setpvf() a pointer to the existing string of the passed in  SV.
This could lead to reallocating the SV with the pointer invalidated
before being used.

Tony Cook spotted the problem, and the fix used here, using sv_insert()
instead.

4 months agoI18N-Langinfo/t/Langinfo.t: Use like()
Karl Williamson [Fri, 29 Dec 2023 02:36:52 +0000 (19:36 -0700)]
I18N-Langinfo/t/Langinfo.t: Use like()

This changes some of the tests in this file to use like() vs is().  This
is in preparation for the next commit which adds a test where a pattern
is needed.

4 months agoFix tr/\N{latin1}...\N{above latin1}/
Karl Williamson [Mon, 25 Dec 2023 01:35:25 +0000 (18:35 -0700)]
Fix tr/\N{latin1}...\N{above latin1}/

When a string is being parsed, it isn't made UTF-8 until necessary; that
is, when it first finds a character that requires UTF-8 to represent.  If
all the characters prior to that one are ASCII, all that is needed is to
convert that one to UTF-8 and to turn on the UTF-8 flag, so that all
future characters encountered in the parse will be represented in UTF-8.

This is because all ASCII characters have the same representation in
UTF-8 as not; they are "UTF-8 invariant".  But if a UTF-8 *variant*
character was in the string prior to the UTF-8-required one, it must be
converted to its UTF-8 representation, when the string is converted.

All that is needed is to increment a count of variant characters as the
parse proceeds.

If nothing in the string requires UTF-8 by the end of the parse, the
count is ignored and the string remains non-UTF-8.

And if the count is zero when a UTF-8-required character is found, as
mentioned above, that character is converted to UTF-8, and the flag is
set to use UTF-8 going forward.

But a non-zero count at the first UTF-8-required character indicates
that before proceeding, the already-parsed string must be reparsed to
convert the variant characters already in it to UTF-8.

The count was not being incremented when the input notation used \N{};
this commit fixes that.  It was being incremented when the input
notation used \x{}, which is much more common in the field, so this bug
was unnoticed for a long time.

Fixes #21748

(Just for the record, on EBCDIC platforms more characters are UTF-8
invariant than ASCII platforms; the macros called here hide that from
the code.)

4 months agoop/tr.t: Suppress two warnings
Karl Williamson [Sat, 30 Dec 2023 17:38:10 +0000 (10:38 -0700)]
op/tr.t: Suppress two warnings

The warnings suppressed here are legitimate, but distract from the point
of the tests.

Spotted by Jim Keenan.

4 months agoFile-Glob: exercise GLOB_MARK, GLOB_NOCHECK, etc.
James E Keenan [Tue, 26 Dec 2023 13:35:58 +0000 (13:35 +0000)]
File-Glob: exercise GLOB_MARK, GLOB_NOCHECK, etc.

For GH #21744

t/basic.t:

* Exercise GLOB_NOCHECK flag, without and with GLOB_QUOTE flag.

* Move one particular assignment to '@a' was only used within
the subsequent SKIP block.  For consistency with other SKIP blocks, move
list assignment to within the block.

* Exercise GLOB_NOSORT flag, thereby confirming that it is the default
sorting mechanism.  There is, of course, a slight chance that using
GLOB_NOSORT will return names in the same order as the default
GLOB_ALPHASORT.  So the best we can do is to confirm that the same names
were returned in each instance.

* Explicitly test GLOB_ALPHASORT

t/global.t:

* Provide descriptions for two unit tests previously lacking
them.

Corrections:
* t/basic.t: Tidy leading whitespace
* Glob.pm: One-character typo
* Increment $VERSION.
* Correct count within SKIP block

4 months agolocale.c: Move macro definition to before first use
Karl Williamson [Wed, 20 Dec 2023 18:17:45 +0000 (11:17 -0700)]
locale.c: Move macro definition to before first use

4 months agoRemove references to nl_langinfo_l(), add comment
Karl Williamson [Wed, 20 Dec 2023 18:14:25 +0000 (11:14 -0700)]
Remove references to nl_langinfo_l(), add comment

This was missed when we earlier removed the use of this function.  I
have since run experiments using it, and found using it slows things
down considerably in the context where we planned to use it.

4 months agolocale.c: Move declaration to first uses
Karl Williamson [Fri, 29 Dec 2023 20:33:12 +0000 (13:33 -0700)]
locale.c: Move declaration to first uses

C99 allows the clearer code of declaring a variable close to its use.

This also will be helpful in a future commit.

4 months agolocale.c: Slightly change wording of DEBUG messages
Karl Williamson [Mon, 22 May 2023 01:26:48 +0000 (19:26 -0600)]
locale.c: Slightly change wording of DEBUG messages

This makes them more consistent with the other messages in this file.

4 months ago-DNO_LOCALE implies -DNO_LOCALE_CTYPE, etc.
Karl Williamson [Tue, 19 Dec 2023 22:00:33 +0000 (15:00 -0700)]
-DNO_LOCALE implies -DNO_LOCALE_CTYPE, etc.

If we aren't to pay attention to locales in general; we certainly
shouldn't be paying attention to individual locale categories.

This commit allows for cleaner #ifdefs

4 months agopp_hot.c: Avoid DIE in void function S_aassign_uid
Craig A. Berry [Sun, 31 Dec 2023 14:06:04 +0000 (08:06 -0600)]
pp_hot.c: Avoid DIE in void function S_aassign_uid

f54903ed18841 moved some code from pp_aassign out to its own
function S_aassign_uid, but the new function is void and DIE
translates to "return Perl_die" which can lead to compiler
warnings about attempting to return a value from a void function.

So just call Perl_die directly without a return statement, which
is already a pretty common practice.

4 months agoDocument warning on previous declaration of 'field' variable
James E Keenan [Sun, 31 Dec 2023 13:44:08 +0000 (08:44 -0500)]
Document warning on previous declaration of 'field' variable

Fixes GH #21783.

4 months agocpan/Digest-MD5 - Update to version 2.59
Todd Rinaldo [Sat, 30 Dec 2023 21:43:17 +0000 (21:43 +0000)]
cpan/Digest-MD5 - Update to version 2.59

2.59 Sat Dec 30 2023
- Remove meaningless const type qualifier to silence HPUX builds.
- remove useless perl 5.6 check
- convert bits.t test to use Test::More
- Update Digest::MD5 Synopsis and Examples. Add `my` to synopsis
- MD5.xs: eliminate C++ guards

4 months agotag this annotation so it is easier to find it for later removal
Karen Etheridge [Sat, 30 Dec 2023 22:32:50 +0000 (14:32 -0800)]
tag this annotation so it is easier to find it for later removal

4 months agos/\t/ /
Karen Etheridge [Sat, 30 Dec 2023 22:32:05 +0000 (14:32 -0800)]
s/\t/    /

4 months agogenerate new perldelta for 5.39.7
Philippe Bruhat (BooK) [Sat, 30 Dec 2023 22:36:13 +0000 (23:36 +0100)]
generate new perldelta for 5.39.7

4 months agotick off release 5.39.6
Philippe Bruhat (BooK) [Sat, 30 Dec 2023 22:31:44 +0000 (23:31 +0100)]
tick off release 5.39.6

4 months agoadd epigraph for 5.39.6 release
Philippe Bruhat (BooK) [Sat, 30 Dec 2023 22:27:47 +0000 (23:27 +0100)]
add epigraph for 5.39.6 release

4 months agoRemove a forgotten piece of template
Philippe Bruhat (BooK) [Sat, 30 Dec 2023 22:21:12 +0000 (23:21 +0100)]
Remove a forgotten piece of template

4 months agoMerge branch 'release-5.39.6' into blead
Philippe Bruhat (BooK) [Sat, 30 Dec 2023 22:12:10 +0000 (23:12 +0100)]
Merge branch 'release-5.39.6' into blead

4 months agocpan/bignum - Update to version 0.67
Peter John Acklam [Sat, 30 Dec 2023 20:32:36 +0000 (15:32 -0500)]
cpan/bignum - Update to version 0.67

0.67 2023-12-30

 * Fix CPAN RT #147806 (cpanratings.perl.org no longer exists)

4 months agocpan/autodie - Update to version 2.37
Todd Rinaldo [Sat, 30 Dec 2023 20:24:26 +0000 (15:24 -0500)]
cpan/autodie - Update to version 2.37

2.37      2023-12-28 19:12:52+00:00 UTC

* #117 - Deprecate smartmatch handling

* #118 - Remove mention of cpanratings.perl.org

* #119 - Fix typo in changelog

4 months agoFindBin: Update $VERSION
James E Keenan [Sat, 30 Dec 2023 19:55:23 +0000 (19:55 +0000)]
FindBin: Update $VERSION

Per incline comments in Porting/Maintainers.PL:

(For dist/ distributions, which are blead-first, a request should be
placed with the releaser(s) to upload the corresponding cpan release,
and the entry in this file should only be updated when that release has
been done.)

FindBin-1.54 has been released on CPAN, so now we can update $VERSION in
core to keep Porting/core-cpan-diff -ax happy.

4 months agocpan/Math-BigInt-FastCalc - Update to version 0.5016
Peter John Acklam [Sat, 30 Dec 2023 19:31:53 +0000 (14:31 -0500)]
cpan/Math-BigInt-FastCalc - Update to version 0.5016

0.5016 2023-12-27

 * Sync test files with Math-BigInt.

4 months agoFix a wrong sigil used in a perlre example
Mathias Kende [Fri, 29 Dec 2023 12:23:41 +0000 (13:23 +0100)]
Fix a wrong sigil used in a perlre example

In the description of the @^CAPTURE array, an example of demarcated
variable name uses the @ sigil. The $ sigil is probably more correct in
that case and raises less questions when reading this section (although
the @ sigil will give the same result in that case).

4 months ago[POD] `diagnostics.pm`: Remove indirect syntax
rwp0 [Fri, 29 Dec 2023 14:16:30 +0000 (15:16 +0100)]
[POD] `diagnostics.pm`: Remove indirect syntax

Convert the below indirect syntax in documentation:

```
enable diagnostics;
disable diagnostics;
```

Since `enable` and `disable` are only methods

It's confusing to see barewords in the documentation.

As a user I thought `diagnostics` should actually be a string argument
to exported-by-default separate `enable` and `disable` subroutines.

4 months agolocale.c: Avoid unnecessary malloc
Karl Williamson [Mon, 18 Dec 2023 14:19:45 +0000 (07:19 -0700)]
locale.c: Avoid unnecessary malloc

Here an SV is being created with a size, but immediately
sv_usepvn_flags() is called to place an already allocated and populated
PV into it, so that initial size is wasted.

4 months agoAdd new release to perlhist v5.39.6
Philippe Bruhat (BooK) [Sat, 30 Dec 2023 09:43:34 +0000 (10:43 +0100)]
Add new release to perlhist

4 months agoFix date math in Porting/cmpVERSION.pl
Philippe Bruhat (BooK) [Sat, 30 Dec 2023 09:39:58 +0000 (10:39 +0100)]
Fix date math in Porting/cmpVERSION.pl

The month value is expected to be in the range 0..11,
and the year the number of years since 1900.

4 months agofinalize perldelta
Philippe Bruhat (BooK) [Fri, 29 Dec 2023 17:32:02 +0000 (18:32 +0100)]
finalize perldelta

4 months agoupdate Module::CoreList for 5.39.6
Philippe Bruhat (BooK) [Fri, 29 Dec 2023 16:49:49 +0000 (17:49 +0100)]
update Module::CoreList for 5.39.6

4 months agoperlapi: Combine, sv_insert, sv_insert_flags entries
Karl Williamson [Thu, 28 Dec 2023 22:46:21 +0000 (15:46 -0700)]
perlapi: Combine, sv_insert, sv_insert_flags entries

4 months agoadd missing perldelta entries for recent commits
Philippe Bruhat (BooK) [Thu, 28 Dec 2023 16:16:03 +0000 (17:16 +0100)]
add missing perldelta entries for recent commits

0ee1ec4319: Perlvar: Add documentation for alternative to ${^CAPTURE}
d4848fd82e: `perllol`: Remove indirect object syntax in `Dumpvalue` example
539477602f: return doesn't allow an indirect object
d3f30b5b43: add sv_mark_arenas() and sv_sweep_arenas()
cc49ed3d25: Add some _NN variants of rpp_() functions.
2505eae6f1: add rpp_replace_at() API function
08368a773f: document ref assignment in list context
c9e6b691e2: perlport: -l is now meaningful on Win32
e453f6823e: perlport: windows strange behaviour with . at the end of names
1adeb0c341: perlport: -S on Win32 has been meaningful since 01052a1d7

4 months agoremove old SYNCINFO entries
Philippe Bruhat (BooK) [Thu, 28 Dec 2023 16:06:39 +0000 (17:06 +0100)]
remove old SYNCINFO entries

4 months agocpan/Math-BigInt - Update to version 2.003001
Philippe Bruhat (BooK) [Tue, 26 Dec 2023 21:46:09 +0000 (22:46 +0100)]
cpan/Math-BigInt - Update to version 2.003001

2.003001 2023-12-26

 * Add configuration methods trap_inf() and trap_nan(). Previously it was only
   possible to modify these properties by using the config() method.

 * Fix CPAN RT #150796 so that config() no longer modifies the input when it is
   a hash ref.

 * Fix CPAN RT #150797 so that both accuracy and precision can be set
   simultaneously with config().

 * Add the following methods to Math::BigInt

   - bilog2()   base 2 logarithm rounded downwards, i.e., int(log2(x))
   - bilog10()  base 10 logarithm rounded downwards, i.e., int(log10(x))
   - bclog2()   base 2 logarithm rounded upwards, i.e., ceil(log2(x))
   - bclog10()  base 10 logarithm rounded upwards, i.e., ceil(log10(x))

 * Add the following backend library methods to Math::BigInt::Lib. These
   methods do the core computations for the corresponding methods in
   Math::BigInt (see above).

   - _ilog2()   base 2 logarithm rounded downwards
   - _ilog10()  base 10 logarithm rounded downwards
   - _clog2()   base 2 logarithm rounded upwards
   - _clog10()  base 10 logarithm rounded upwards

4 months agoxsubpp.PL: add code comments saying what it does
David Mitchell [Sat, 23 Dec 2023 14:39:42 +0000 (14:39 +0000)]
xsubpp.PL: add code comments saying what it does

4 months agoPerlvar: Add documentation for alternative to ${^CAPTURE}
Scott Baker [Wed, 29 Nov 2023 23:33:33 +0000 (15:33 -0800)]
Perlvar: Add documentation for alternative to ${^CAPTURE}

4 months agoperldelta for 8fbf04a996, 7a39510b73, d06aed192c
Lukas Mai [Thu, 21 Dec 2023 18:08:03 +0000 (19:08 +0100)]
perldelta for 8fbf04a9967a39510b73d06aed192c

4 months agoMB_CUR_MAX is C89, change comment accordingly
Karl Williamson [Fri, 22 Dec 2023 17:31:15 +0000 (10:31 -0700)]
MB_CUR_MAX is C89, change comment accordingly

Spotted by Tony Cook.