This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
21 months agoSwap the ordering of two locale category indices
Karl Williamson [Sun, 21 Feb 2021 16:15:48 +0000 (09:15 -0700)]
Swap the ordering of two locale category indices

Perl internally uses a mapping of locale category values into a
consecutive sequence of indices starting at 0.  These are used as
indexes into arrays.  The reason is that the category numbers are
opaque, vary by platform, aren't necessarily sequential, and hence are
hard to make table driven code for.

This commit makes the LC_CTYPE index 0, and LC_NUMERIC equal to 1;
swapping them.  The reason is to cause LC_CTYPE to get done first in the
many loops through the categories.  The UTF8ness of categories is an
often needed value, and most of the time the categories will have the
same locale.  LC_CTYPE is needed to calculate the UTF8ness, then by doing
it first and caching the result, the other categories likely
automatically will use the same value, without having to recalculate.

21 months agolocale.c: Rmv unnecessary variable
Karl Williamson [Thu, 21 Jul 2022 17:07:58 +0000 (11:07 -0600)]
locale.c: Rmv unnecessary variable

Changes in this function mean this value has already been calculated
and saved under a different name.

21 months agolocale.c: Make sure newlocale() doesn't destroy arg
Karl Williamson [Thu, 21 Jul 2022 16:47:23 +0000 (10:47 -0600)]
locale.c: Make sure newlocale() doesn't destroy arg

newlocale() takes as one of its arguments, a starting locale.  It can
free that argument's space it if chooses.  I think the instances of this
happening have been already been fixed, but this commit makes it clear
that it won't destroy the wrong things.

21 months agolocale.c: panic if shouldn't-happen events do
Karl Williamson [Thu, 21 Jul 2022 16:28:35 +0000 (10:28 -0600)]
locale.c: panic if shouldn't-happen events do

If any of these cases occur, something is so wrong with the system that
we shouldn't continue.

21 months agolocale.c: Don't waste time executing a no-op
Karl Williamson [Wed, 20 Jul 2022 22:31:35 +0000 (16:31 -0600)]
locale.c: Don't waste time executing a no-op

If we're trying to change the locale to what it already is, that's a
no-op.  This skips that work.  As noted in the comments, this also led
to subtle bugs with newlocale() trying to free the basis operand, and
giving bad results.

21 months agolocale.c: Mv declarations closer to use in function
Karl Williamson [Wed, 20 Jul 2022 22:19:35 +0000 (16:19 -0600)]
locale.c: Mv declarations closer to use in function

This clarifies the underlying object.  This commit also adds one bit of
information to a debugging statement

This changes also to print the entry locale under DEBUGGING upon entry
to the top of the function

21 months agolocale.c: newlocale() can't handle disparate locales
Karl Williamson [Tue, 19 Jul 2022 14:49:00 +0000 (08:49 -0600)]
locale.c: newlocale() can't handle disparate locales

This is a follow on commit to d92b203c3251254039d9cb3b314646b5e894c21c.
querylocale() isn't required by Standards to handle LC_ALL, and it often
doesn't when the underlying locales aren't all set to the same thing.
That commit fixed that.

Overlooked by that commit was that newlocale() also doesn't necessarily
handle LC_ALL input of disparate locales.  This commit changes to use the
same mechanism to deal with this situation that is already in place for
non-querylocale() systems

21 months agolocale.c: Change outlier call to use macro
Karl Williamson [Mon, 18 Jul 2022 20:08:17 +0000 (14:08 -0600)]
locale.c: Change outlier call to use macro

This is the only occurrence of this in the program.  Change to match
everywhere else, so that people don't wonder if something special might
be going on.

21 months agolocale.c: Move DEBUG location info
Karl Williamson [Wed, 3 Mar 2021 14:40:50 +0000 (07:40 -0700)]
locale.c: Move DEBUG location info

This commit takes advantage of the mechanism to add common DEBUGGING
code to print the __FILE__ and __LINE__ of every debugging statement.
This allows those to be removed from each statement, and have them
implicitly added.

This make things consistent, and easier to read and add new statements.

21 months agolocale.c: Use DEBUG_(PRE|POST_)STMTS to save/restore errno
Karl Williamson [Thu, 4 Mar 2021 01:50:42 +0000 (18:50 -0700)]
locale.c: Use DEBUG_(PRE|POST_)STMTS to save/restore errno

Instead of explicitly saving the errno around debugging statements, the
more general mechanism is used.

21 months agoAdd a common locale panic macro and functions
Karl Williamson [Sun, 21 Feb 2021 17:03:14 +0000 (10:03 -0700)]
Add a common locale panic macro and functions

This will make sure that all the necessary clean up gets done.

21 months agoDon't discard locale info in starting P2008
Karl Williamson [Fri, 19 Feb 2021 16:12:46 +0000 (09:12 -0700)]
Don't discard locale info in starting P2008

The program is started in the global locale, and then is converted to
the POSIX 2008 per-thread locale API.  This is accomplished by adding a
duplocale of the global locale.  Prior to this commit the startup
locale was discarded.  It really should be the foundation for the 2008
locales.

And, as a defensive measure, if a locale change fails that otherwise
would have started per-thread locales, we set up our stored information
(that may never have been initialized) to the global locale information

21 months agolocale.c: Add DEBUGGING information
Karl Williamson [Sun, 14 Feb 2021 00:19:22 +0000 (17:19 -0700)]
locale.c: Add DEBUGGING information

These functions are called as expansions of macros.  It may be useful to
know where in the file the macro occurred.

21 months agolocale.c: Add fcn to hide edge case undefined behavior
Karl Williamson [Thu, 11 Feb 2021 19:33:23 +0000 (12:33 -0700)]
locale.c: Add fcn to hide edge case undefined behavior

The POSIX 2008 API has an edge case in that the result of most of the
functions when called with a global (as opposed to a per-thread) locale
is undefined.

The duplocale() function is the exception which will create a per-thread
locale containing the values copied from the global one.

This commit just calls duplocale, if needed, and the caller need not
concern itself with this possibility

21 months agosv.c: Duplicate more variables during cloning
Karl Williamson [Thu, 11 Feb 2021 18:17:48 +0000 (11:17 -0700)]
sv.c: Duplicate more variables during cloning

These locale-related ones should be getting initialized in the new
thread, but be certain.

21 months agoSplit off setting locale to "" from S_emulate_setlocale
Karl Williamson [Sat, 13 Feb 2021 20:54:23 +0000 (13:54 -0700)]
Split off setting locale to "" from S_emulate_setlocale

This is done for readability, to move the special casing of setting a
locale to the empty string (hence getting it from the environment) out
of the main line code.

21 months agolocale.c: locale "" can be disparate
Karl Williamson [Sat, 13 Feb 2021 21:34:13 +0000 (14:34 -0700)]
locale.c: locale "" can be disparate

Setting a locale "" means to get the value from environment variables.
These can set locale categories to different locales, and this needs to
be handled.  The logic before this commit only handled the disparate
case when the locale wasn't ""; but this was compensated for elsewhere.
A future commit will remove that compensation.

21 months agolocale.c: Split ancillary from S_emulate_setlocale
Karl Williamson [Sun, 28 Feb 2021 17:05:30 +0000 (10:05 -0700)]
locale.c: Split ancillary from S_emulate_setlocale

This takes the code to update LC_ALL, used only in some Configurations,
out of the main line, making the main line more readable.

It also allows the removal of temporary code added a few commits back

21 months agolocale.c: Clean up handling of a glibc bug
Karl Williamson [Sat, 13 Feb 2021 17:09:54 +0000 (10:09 -0700)]
locale.c: Clean up handling of a glibc bug

This commit moves all mention of this bug to just the code that requires
it, and inlines a macro, making it easier to comprehend

21 months agolocale.c: Change internal variable name
Karl Williamson [Sat, 13 Feb 2021 14:34:58 +0000 (07:34 -0700)]
locale.c: Change internal variable name

The new name better reflects its purpose, so is less confusing

21 months agolocale.c: Comments; move declarations to use point
Karl Williamson [Wed, 20 Jul 2022 19:38:31 +0000 (13:38 -0600)]
locale.c: Comments; move declarations to use point

Now that we are using C99, we can move declarations so that it makes
more sense.

21 months agolocale.c: Avoid loop; panic on unexpected condition.
Karl Williamson [Wed, 20 Jul 2022 19:34:36 +0000 (13:34 -0600)]
locale.c: Avoid loop; panic on unexpected condition.

If we can't change to the locale to C, something is seriously wrong; no
sense trying to soldier on.

And, instead of a loop, set all the categories to C in a single call
(which actually doesn't expand to a loop)

21 months agolocale.c: Split aggregate LC_ALL from emulate_setlocale
Karl Williamson [Sat, 13 Feb 2021 13:39:30 +0000 (06:39 -0700)]
locale.c: Split aggregate LC_ALL from emulate_setlocale

This splits into a separate function the code necessary in some
Configurations to calculate LC_ALL from a potentially disparate
aggregate of categories having different locales.

This is being done just for readability, as this extensive code in the
middle of something else distracts from the main point.

A goto is hence replaced by a recursive call.  This commit intends to do
the minimal changes involved in making this a function.  The next commit
will make some revisions.

21 months agosetlocale_failure_panic_i now used more generally
Karl Williamson [Tue, 12 Jul 2022 22:09:14 +0000 (16:09 -0600)]
setlocale_failure_panic_i now used more generally

This function was #ifdef'd out of being defined to silence a compiler
warning in some configurations.  It's about to be used more generally,
so needs to be generally accessible

21 months agolocale.c: Use setlocale() for init, not P2008
Karl Williamson [Thu, 11 Mar 2021 19:24:56 +0000 (12:24 -0700)]
locale.c: Use setlocale() for init, not P2008

We have found bugs in the POSIX 2008 libc implementations on various
platforms.  This code, which does the initialization of locale handling
has always been very conservative, expecting possible failures due to
bugs in it or the libc implementations, and backing out if necessary to
a crippled, but workable state, if something goes wrong.

I think we should use the oldest, most stable locale implementation in
these circumstances

21 months agolocale.c: Refactor some derived #defines
Karl Williamson [Sun, 28 Mar 2021 13:55:16 +0000 (07:55 -0600)]
locale.c: Refactor some derived #defines

The _c suffix is supposed to mean the category is known at compile time.
In some configurations this does not matter, and so I had named things
carelessly, so this might be confusing.  This commit fixes that.

21 months agolocale.c: Generalize stdize_locale()
Karl Williamson [Sun, 11 Apr 2021 01:44:16 +0000 (19:44 -0600)]
locale.c: Generalize stdize_locale()

This function is rewritten to handle LC_ALL, and to make it easier to
add new checks.

There is also a change, which I think is an improvement, in that everything
starting with a \n is trimmed, instead of just a trailing \n.

A couple of calls to stdize_locale() are removed, as they are redundant,
because they are called only as a result of Perl_setlocale() being
called, and that ends up calling stdize_locale always, early on.

The call to savepv() is also moved in a couple cases to after the result
is known to not be NULL

I originally had such a new check in mind, but it turned out that doing
it here didn't solve the problem, so this commit has been amended
(before ever being pushed) to not include that.
chomped.

21 months agoReorder some locale functions in embed.fnc
Karl Williamson [Wed, 20 Jul 2022 13:28:44 +0000 (07:28 -0600)]
Reorder some locale functions in embed.fnc

This allows the removal of some #ifdefs, and makes things easier to read

21 months agoMake two locale PL_ strings const char*
Karl Williamson [Tue, 16 Feb 2021 13:27:54 +0000 (06:27 -0700)]
Make two locale PL_ strings const char*

This adds some compile safety to these.

21 months agoTemporarily skip on Windows
Karl Williamson [Fri, 22 Jul 2022 01:05:26 +0000 (19:05 -0600)]
Temporarily skip on Windows

The next commits will expose an existing Windows bug which will get
fixed in a later set of commits

21 months agointrpvar.h: Fix when certain locale symbols get defined
Karl Williamson [Mon, 1 Aug 2022 22:42:31 +0000 (16:42 -0600)]
intrpvar.h: Fix when certain locale symbols get defined

Certain interpreter variables are needed only in certain Configurations.
This commit removes some that aren't needed everywhere to be generated
only where they are needed, and generates some that weren't being used
that are or will be needed everywhere by follow-up commits.

21 months agosv.c: Move some initialization inside #ifdef
Karl Williamson [Tue, 12 Jul 2022 22:46:41 +0000 (16:46 -0600)]
sv.c: Move some initialization inside #ifdef

If not using the feature, don't need to initialize it.

21 months agoUpdate version number listed for IO-Compress
James E Keenan [Tue, 9 Aug 2022 14:38:17 +0000 (14:38 +0000)]
Update version number listed for IO-Compress

21 months agoHTTP-Tiny: Sync with CPAN version 0.082
David Golden [Tue, 9 Aug 2022 13:31:43 +0000 (13:31 +0000)]
HTTP-Tiny: Sync with CPAN version 0.082

From Changes:

0.082 - No changes from 0.081-TRIAL.

0.081 [FIXED] - No longer deletes the 'headers' key from post_form arguments hashref.
      [DOCS]  - Noted that request/response content are handled as raw bytes.

21 months agoErrno.t: provide labels for tests lacking them 20055/head
James E Keenan [Sat, 6 Aug 2022 20:45:29 +0000 (20:45 +0000)]
Errno.t: provide labels for tests lacking them

Improve test descriptions, with feedback from Tony Cook.

21 months agoperl.[ch] - hash related setup affects binary compatibility
Yves Orton [Sun, 7 Aug 2022 14:03:35 +0000 (16:03 +0200)]
perl.[ch] - hash related setup affects binary compatibility

Our hash function is compiled into code which chooses to use it,
and is not linked in from the perl executable. That means that
the hash related settings can affect binary compatibility.

I proposed making the hash function linkable, but people said "there was
no need". But that means that the hash function config DOES affect
binary compatibility.

21 months agoperl.c - remove code for reporting state of non-existent defines in -V
Yves Orton [Sat, 6 Aug 2022 20:48:04 +0000 (22:48 +0200)]
perl.c - remove code for reporting state of non-existent defines in -V

Most of the hash based defines are no longer supported, so remove them.
Also at the same time introduce a new simpler way to track which hash
function we are using. Also add the info about if SBOX32 is in use.

This removes the need to keep the list of hash functions supported in
two places, hv_func.h and perl.c. Instead hv_func.h drives the whole
process and perl.c just does what it is told.

Previously the way to control SBOX32 was to use a define with a value
but our perl -V output currently doesnt support that, so this adds some
two new defines PERL_HASH_USE_SBOX32 and PERL_HASH_NO_SBOX32 which map
to the older PERL_HASH_USE_SBOX32_ALSO flag define (integer 1/0).
Both are still supported, this just makes everything more consistent.

This also includes minor doc changes to INSTALL to mention -Accflags
as being the way to set these defines during the Configure process.

21 months agohv_func.h - change _PERL style macros to PVT_ style macros
Yves Orton [Sat, 6 Aug 2022 20:46:14 +0000 (22:46 +0200)]
hv_func.h - change _PERL style macros to PVT_ style macros

C reserves identifiers starting with underbar, but I didnt realize that this
applies to defines as well when I set up this file. This renames the private
macros to start with PVT. It maintains the distinction between _PERL and __PERL
by converting them to PVT_PERL and PVT__PERL.

21 months agowin32.c: use _mkgmtime() instead of mktime() in stat()
Tomasz Konojacki [Sun, 7 Aug 2022 21:20:23 +0000 (23:20 +0200)]
win32.c: use _mkgmtime() instead of mktime() in stat()

Conversion to local time seems unnecessary and it apparently causes
issues with DST.

Fixes #20018, #20061

21 months agoSync JSON::PP with CPAN 4.11
Graham Knop [Mon, 8 Aug 2022 16:33:36 +0000 (11:33 -0500)]
Sync JSON::PP with CPAN 4.11

From Changes:

  - restored core boolean support

This changes how boolean values are serialized to use true or false for
values that perl thinks are booleans. This is likely to have some impact
on code that is expecting a specific encoding of structures including
these values.

21 months agoChange of upstream maintainer
James E Keenan [Sat, 6 Aug 2022 22:05:44 +0000 (22:05 +0000)]
Change of upstream maintainer

See: https://metacpan.org/dist/Pod-Usage

Discovered when running Porting/core-cpan-diff

21 months agoperlhacktips, perlguts: Fix typos
Karl Williamson [Mon, 8 Aug 2022 11:40:17 +0000 (05:40 -0600)]
perlhacktips, perlguts: Fix typos

21 months agoavoid dereferencing prog which may be NULL
Tony Cook [Tue, 12 Jul 2022 00:51:02 +0000 (10:51 +1000)]
avoid dereferencing prog which may be NULL

CID 353002

21 months agoexplicitly ignore the result of sv_utf8_downgrade()
Tony Cook [Tue, 12 Jul 2022 00:37:30 +0000 (10:37 +1000)]
explicitly ignore the result of sv_utf8_downgrade()

Coverity complains about this because most other calls are
checked.

CIDs 353483, 353003, 353000, 352998, 352995

21 months agoPrevent Coverity complaining about the mixed & and &&
Tony Cook [Tue, 12 Jul 2022 00:18:59 +0000 (10:18 +1000)]
Prevent Coverity complaining about the mixed & and &&

Also add parenthesis around uses of the phlags macro parameter.

CID 354620, 353482.

21 months agot/op/sselect.t: skip 4 tests under miniperl 20040/head
James E Keenan [Thu, 4 Aug 2022 13:36:09 +0000 (13:36 +0000)]
t/op/sselect.t: skip 4 tests under miniperl

Commit 85907e6fd46 (July 22 2022) added unit tests to t/op/sselect.t but
failed to take into consideration that this file is run as part of 'make
minitest'.  When we run that command, we get this result:

    t/op/sselect .... FAILED--unexpected output at test 17

... which is due in part to a quirk in t/TEST.  To avoid this problem we
should SKIP the block of tests in question if we're running with
miniperl.

Remove nested 'SKIP:' block declaration; Not needed, per review by
@LeonT.  Remove superfluous comma, spotted by @FGaspar.

21 months agoregen/regcomp.pl - Apparently this extra const breaks g++
Yves Orton [Sat, 6 Aug 2022 18:26:06 +0000 (20:26 +0200)]
regen/regcomp.pl - Apparently this extra const breaks g++

21 months agoregex engine - replace many attribute arrays with one
Yves Orton [Wed, 3 Aug 2022 14:19:38 +0000 (16:19 +0200)]
regex engine - replace many attribute arrays with one

This replaces PL_regnode_arg_len, PL_regnode_arg_len_varies,
PL_regnode_off_by_arg and PL_regnode_kind with a single PL_regnode_info
array, which is an array of struct regnode_meta, which contains the same
data but as a struct. Since PL_regnode_name is only used in debugging
builds of the regex engine we keep it separate. If we add more debug
properties it might be good to create a PL_regnode_debug_info[] to hold
that data instead.

This means when we add new properties we do not need to modify any
secondary sources to add new properites, just the struct definition
and regen/regcomp.pl

21 months agoregex engine - wrap PL_regnode_name with macro REGNODE_NAME()
Yves Orton [Wed, 3 Aug 2022 13:23:09 +0000 (15:23 +0200)]
regex engine - wrap PL_regnode_name with macro REGNODE_NAME()

21 months agoregex engine - wrap PL_regnode_arg_len_varies with macro REGNODE_ARG_LEN_VARIES()
Yves Orton [Wed, 3 Aug 2022 13:22:22 +0000 (15:22 +0200)]
regex engine - wrap PL_regnode_arg_len_varies with macro REGNODE_ARG_LEN_VARIES()

21 months agoregex engine - wrap PL_regnode_arg_len with macro REGNODE_ARG_LEN()
Yves Orton [Wed, 3 Aug 2022 13:19:51 +0000 (15:19 +0200)]
regex engine - wrap PL_regnode_arg_len with macro REGNODE_ARG_LEN()

21 months agoregex engine - wrap PL_regnode_off_by_arg with macro REGNODE_OFF_BY_ARG()
Yves Orton [Wed, 3 Aug 2022 13:18:52 +0000 (15:18 +0200)]
regex engine - wrap PL_regnode_off_by_arg with macro REGNODE_OFF_BY_ARG()

21 months agoregex engine - wrap PL_regnode_kind with macro REGNODE_TYPE()
Yves Orton [Wed, 3 Aug 2022 13:15:20 +0000 (15:15 +0200)]
regex engine - wrap PL_regnode_kind with macro REGNODE_TYPE()

The code confusing uses type and kind as synonyms. Lets end that bad habit

22 months agoReplace sv_2mortal(newSVhek( with newSVhek_mortal
Richard Leach [Thu, 28 Jul 2022 22:35:24 +0000 (22:35 +0000)]
Replace sv_2mortal(newSVhek( with newSVhek_mortal

The new Perl_newSVhek_mortal function is slightly more efficient.

22 months agosv.c - add Perl_newSVhek_mortal
Richard Leach [Thu, 28 Jul 2022 21:35:18 +0000 (21:35 +0000)]
sv.c - add Perl_newSVhek_mortal

This is a small wrapper function intended to replace use of
    sv_2mortal(newSVhek(...))

This provides some small optimization, since sv_2mortal performs
a number of checks for conditions that we know cannot be true.

22 months agoPerl_newRV_noinc - explicitly simplify, convert to inline func
Richard Leach [Tue, 2 Aug 2022 22:12:58 +0000 (22:12 +0000)]
Perl_newRV_noinc - explicitly simplify, convert to inline func

Perl_newRV_noinc creates a new SVt_IV, then calls sv_setrv_noinc,
which will check if the SVt_IV is SvTHINKFIRST (it won't be) and
if it is types other than SVt_IV (it won't be). If those checks
and associated branches are removed, all that remains is some flag
twiddling and setting the sv_u.svu_rv pointer.

A decent compiler *might* figure that all out and simplify
Perl_newRV_noinc right down to the essentials, but if we do that
directly, the entire function is small enough to move to sv_inline.h

22 months ago[doc] Link to module manual pages
Elvin Aslanov [Fri, 5 Aug 2022 09:57:10 +0000 (13:57 +0400)]
[doc] Link to module manual pages

As with the existing `Devel::NYTProf`, add `PadWalker`, `Term::ReadLine`, `Term::ReadLine` links to their respective manual pages.

Users can find and install these modules from CPAN to enhance the Perl Debugger with additional features (eg. completion, lexicals, and profiling).

https://perldoc.perl.org/ links to MetaCPAN if the module is not in core.
Example: https://perldoc.perl.org/Devel::NYTProf on [The Perl Profiler](https://perldoc.perl.org/perldebug#The-Perl-Profiler) section

22 months agopodcheck.t: Clarify syntax for --add-link
Elvin Aslanov [Fri, 5 Aug 2022 14:59:08 +0000 (18:59 +0400)]
podcheck.t: Clarify syntax for --add-link

It's `MODULE` or `man_page`, not both at the same time.

See:

:https://github.com/Perl/perl5/pull/20043

22 months agoperl5db.pl: Spelling
Elvin Aslanov [Fri, 5 Aug 2022 15:30:52 +0000 (19:30 +0400)]
perl5db.pl: Spelling

`R` command: pure man -> poor man

Probably meant that:
https://en.wiktionary.org/wiki/poor_man%27s#English

22 months agoMerge branch 'patch-2' into blead
James E Keenan [Thu, 4 Aug 2022 18:13:02 +0000 (18:13 +0000)]
Merge branch 'patch-2' into blead

22 months agoTypo in "y" (PadWalker) command description 20038/head
Elvin Aslanov [Thu, 4 Aug 2022 12:11:29 +0000 (16:11 +0400)]
Typo in "y" (PadWalker) command description

Fix: then -> them
Also corrected "dumpvar.pl" to be rendered as a file name in POD rather than code/command.
https://perldoc.perl.org/perlpod#F-used-for-filenames

Bumped Perl Debugger version to pass t/porting/cmp-version.t test

22 months agoEncode: sync with CPAN version 3.19
Dan Kogai [Thu, 4 Aug 2022 13:10:50 +0000 (13:10 +0000)]
Encode: sync with CPAN version 3.19

Correct one alias: ISO-8859-8-I -> ISO-8859-8.

22 months agoAdd tests for `do { ... } while 0;` and `do { ... } until 1;`
Nicholas Clark [Wed, 3 Aug 2022 20:08:44 +0000 (22:08 +0200)]
Add tests for `do { ... } while 0;` and `do { ... } until 1;`

Astoundingly, even though we had the perl code as a comment in the C code
which handles this special case in Perl_newLOOPOP(), we didn't actually have
a regression test for it. Father C added a test case for a variant in commit
fc39925ca702f4c8 in Dec 2013, where the value for until is a constant, but
constant folding fails, but the "simple" version never actually had a test
case.

This commit adds the missing test cases.

22 months agotoke.c: Variable should be decleared Size_t, not SSize_t
Karl Williamson [Thu, 4 Aug 2022 01:12:08 +0000 (19:12 -0600)]
toke.c: Variable should be decleared Size_t, not SSize_t

22 months agoRmv obsolete reference to C89
Karl Williamson [Thu, 4 Aug 2022 01:10:15 +0000 (19:10 -0600)]
Rmv obsolete reference to C89

22 months agoEmit __VA_ARGS__-using macros into embed.h when on PERL_CORE
Paul "LeoNerd" Evans [Thu, 7 Jul 2022 16:21:46 +0000 (17:21 +0100)]
Emit __VA_ARGS__-using macros into embed.h when on PERL_CORE

Now we're using C99, we can safely use the __VA_ARGS__ expansion in
these variable-list macros.

Unfortunately we can't just emit them unconditionally, because much
existing CPAN code exists that thinks it can call e.g. `warn()` without
an aTHX_ in scope (because they don't #define PERL_NO_GET_CONTEXT).

Therefore, we have to guard these new macro forms by

  ... || defined(PERL_CORE)

and continue to emit the "..._nocontext()" variants at the end of the
file, as we previously did.

It's not a great solution but it at least means we can use `croak()`,
`warn()`, et.al. within perl core source now.

22 months agoAvoid some confusion in regen/embed.pl by renaming the scalar $args to $argc
Paul "LeoNerd" Evans [Thu, 7 Jul 2022 15:53:03 +0000 (16:53 +0100)]
Avoid some confusion in regen/embed.pl by renaming the scalar $args to $argc

22 months agoregex engine - improved comments explaining REGNODE_AFTER()
Yves Orton [Sun, 31 Jul 2022 11:51:36 +0000 (13:51 +0200)]
regex engine - improved comments explaining REGNODE_AFTER()

This rewrites one comment to include more explanation of the difference
between Perl_regnext() and REGNODE_AFTER().

22 months agoregex engine - integrate regnode_after() support for EXACTish nodes
Yves Orton [Sat, 30 Jul 2022 17:42:08 +0000 (19:42 +0200)]
regex engine - integrate regnode_after() support for EXACTish nodes

This adds REGNODE_AFTER_varies() which is used when the called *knows*
that the current regnode is variable length. We then use it to handle
EXACTish style nodes as determined by PL_regnode_arg_len_varies.

As part of this patch Perl_regnext() Perl_regnode_after() and
Perl_check_regnode_after() are moved to reginline.h, which is loaded via
regcomp.c only when we are compiling the regex engine.

22 months agoregex engine - rename REGNODE_AFTER_dynamic() REGNODE_AFTER()
Yves Orton [Sat, 30 Jul 2022 17:36:07 +0000 (19:36 +0200)]
regex engine - rename REGNODE_AFTER_dynamic() REGNODE_AFTER()

Now that REGNODE_AFTER() can handle all cases it makes sense
to remove the dynamic() suffix.

22 months agoregcomp.c - initial support for EXACTish nodes in regnode_after()
Yves Orton [Sat, 30 Jul 2022 17:29:43 +0000 (19:29 +0200)]
regcomp.c - initial support for EXACTish nodes in regnode_after()

This is a first step, we add the support for EXACTish nodes
here, but we do not use it. In a following commit we will move
it to a new file. This patch is just to keep the move clean.

22 months agoglobvar.sym - sort PL_reg*
Yves Orton [Sat, 30 Jul 2022 17:07:25 +0000 (19:07 +0200)]
globvar.sym - sort PL_reg*

22 months agoregex engine - Rename PL_reg_name to PL_regnode_name
Yves Orton [Sat, 30 Jul 2022 17:06:35 +0000 (19:06 +0200)]
regex engine - Rename PL_reg_name to PL_regnode_name

22 months agoregex engine - Rename PL_reg_off_by_arg to PL_regnode_off_by_arg
Yves Orton [Sat, 30 Jul 2022 17:06:34 +0000 (19:06 +0200)]
regex engine - Rename PL_reg_off_by_arg to PL_regnode_off_by_arg

22 months agoregex engine - Rename PL_regkind to PL_regnode_kind
Yves Orton [Sat, 30 Jul 2022 17:06:33 +0000 (19:06 +0200)]
regex engine - Rename PL_regkind to PL_regnode_kind

22 months agoregex engine - Rename PL_regargvaries to PL_regnode_arg_len_varies
Yves Orton [Sat, 30 Jul 2022 17:06:32 +0000 (19:06 +0200)]
regex engine - Rename PL_regargvaries to PL_regnode_arg_len_varies

22 months agoregex engine - Rename PL_regarglen to PL_regnode_arg_len
Yves Orton [Sat, 30 Jul 2022 17:06:31 +0000 (19:06 +0200)]
regex engine - Rename PL_regarglen to PL_regnode_arg_len

22 months agoregen/regcomp.pl - add PL_regargvaries
Yves Orton [Sat, 30 Jul 2022 16:55:43 +0000 (18:55 +0200)]
regen/regcomp.pl - add PL_regargvaries

22 months agoregen/regcomp.pl - add a way to dump the node/state table
Yves Orton [Sat, 30 Jul 2022 16:55:01 +0000 (18:55 +0200)]
regen/regcomp.pl - add a way to dump the node/state table

For debugging and enhancements, etc.

22 months agoregen/regcomp.pl - fix documentation (add missing PL_ prefix)
Yves Orton [Sat, 30 Jul 2022 16:54:16 +0000 (18:54 +0200)]
regen/regcomp.pl - fix documentation (add missing PL_ prefix)

22 months agoregcomp.pl - use the regnode typedefs in EXTRA_SIZE calculations
Yves Orton [Sat, 30 Jul 2022 16:51:15 +0000 (18:51 +0200)]
regcomp.pl - use the regnode typedefs in EXTRA_SIZE calculations

22 months agoregex engine - Rename reg_off_by_arg to PL_reg_off_by_arg
Yves Orton [Sat, 30 Jul 2022 16:43:01 +0000 (18:43 +0200)]
regex engine - Rename reg_off_by_arg to PL_reg_off_by_arg

This is in preparation for a future patch, so we can access
PL_reg_off_by_arg() from an inline function in regexec.c

22 months agoregex engine rename -> reg_off_by_arg
Yves Orton [Sat, 30 Jul 2022 16:35:55 +0000 (18:35 +0200)]
regex engine rename -> reg_off_by_arg

22 months agoregcomp.c - rename NEXTOPER to REGNODE_AFTER and related logic
Yves Orton [Sat, 16 Jul 2022 10:20:00 +0000 (12:20 +0200)]
regcomp.c - rename NEXTOPER to REGNODE_AFTER and related logic

It is really easy to get confused about the difference between
NEXTOPER() and regnext() of a regnode. The two concepts are related,
similar, but importantly distinct. NEXTOPER() is also defined in such a
way that it is easy to abuse and misunderstand and encourages producing
code that is fragile to larger change, effectively "baking in"
assumptions to the code that are difficult to discover by searching.
Changing the type and storage requirements of a regnode may break things
in subtle and hard to debug ways.

An example of how NEXTOPER() is problematic is that this:
NEXTOPER(NEXTOPER(branch)) does not mean "find the second node after the
branch node", it means "jump forward by a regnode which happens to be
two regnodes large". In other words NEXTOPER is just a fancy way of
writing "node+1".

This patch replaces NEXTOPER() with three new macros:

    REGNODE_AFTER_dynamic(node)
    REGNODE_AFTER_opcode(node,op)
    REGNODE_AFTER_type(node,tregnode_OPNAME)

The first is the most generic case, it jumps forward by the size of the
node, and determines that size by consulting OP(node). The second is
where you have already extracted OP(node), and the third is where you
know the actual structure that you want to jump forward by. Every
regnode type has a corresponding type, which is known at compile time,
so using the third will produce the most efficient code. However in many
cases the code operates on one of several types, whose size may be the
same now, but may change in the future, in which case one of the other
forms is preferred. The run time logic in regexec.c should probably
only use the REGNODE_AFTER_type() interface.

Note that there is also a REGNODE_BEFORE() which replaces PREVOPER(),
which is used in a specific piece of legacy logic but should not be
used otherwise. It is not safe to go backwards from an arbitrary node,
we simply have no way to know how large the previous node is and thus
where it starts.

This patch includes some logic that validates assumptions during DEBUG
mode which should catch errors from resizing regnodes.

After this patch changing the size of an existing regnode should be
relatively safe and errors related to sizing should trigger assertion
fails.

This patch includes changes to perlreguts.pod to explain this stuff
better.

22 months agoregen/regcomp.pl - create typedefs for all regnode types
Yves Orton [Sun, 3 Apr 2022 13:48:20 +0000 (15:48 +0200)]
regen/regcomp.pl - create typedefs for all regnode types

Currently we hard code the struct used by the different regop types.
This makes it awkward to change the structure used by a specific regop
as the struct it uses might be used in many contexts, and each cases
of a regop using that structure must be reviewed to see if it needs
to be changed.

This patch adds a typedef for each regnode. The typedefs are named
'tregnode_OP', for instance 'tregnode_TRIE' is typedefed to 'struct
charclass' (at the time of this commit). This allows the code to do
things like 'sizeof(tregnode_TRIE)' and should the exact struct used
for TRIE regops change in the future then no code need be reviewed
or changed.

22 months agoregen/regcomp.pl - Make regarglen available as PL_regarglen in regexec.c
Yves Orton [Mon, 18 Apr 2022 07:57:51 +0000 (09:57 +0200)]
regen/regcomp.pl - Make regarglen available as PL_regarglen in regexec.c

In a follow up patch we will use this data from regexec.c which
currently cannot see the variable.

This changes a comment in regen/mk_invlists.pl which necessitated
rebuilding several files related to unicode. Only the hashes associated
with mk_invlists.pl were changed.

22 months agoregcomp.c - replace OP(n) macro with variable 'op' in S_dumpuntil()
Yves Orton [Sat, 16 Jul 2022 10:27:48 +0000 (12:27 +0200)]
regcomp.c - replace OP(n) macro with variable 'op' in S_dumpuntil()

This declutters the code and allows us to remove the casting as well.

As a byproduct the loop control logic is a bit simplified.

22 months agoregcomp.c - replace repeated OP(n) with variable 'op'.
Yves Orton [Sat, 16 Jul 2022 10:22:29 +0000 (12:22 +0200)]
regcomp.c - replace repeated OP(n) with variable 'op'.

Declutter code.

22 months agoregen/mk_invlists.pl - under DEBUG=1 show some progress output
Yves Orton [Sat, 30 Jul 2022 14:50:45 +0000 (16:50 +0200)]
regen/mk_invlists.pl - under DEBUG=1 show some progress output

22 months agoOP_RUNCV should be created by newSVOP()
Paul "LeoNerd" Evans [Tue, 26 Jul 2022 22:03:18 +0000 (23:03 +0100)]
OP_RUNCV should be created by newSVOP()

This is in case rpeep converts it into an OP_CONST; it will need the
space big enough to be a full SVOP.

Before this commit it called `newPVOP()` which wasn't technically
correct, but since sizeof(PVOP) == sizeof(SVOP) nothing actually broke
when the memory slab was reused. However if the definition of either op
type is changed so this is no longer the case, it may cause otherwise
hard-to-debug memory corruption.

22 months agoassert() in pp_gv and pp_gvsv that the GV really is a GV
Paul "LeoNerd" Evans [Tue, 26 Jul 2022 18:20:50 +0000 (19:20 +0100)]
assert() in pp_gv and pp_gvsv that the GV really is a GV

Or, in pp_gv it's also allowed to be a reference to a CV

22 months agoCreate a dedicated cMETHOPx_meth() macro
Paul "LeoNerd" Evans [Tue, 26 Jul 2022 16:26:30 +0000 (17:26 +0100)]
Create a dedicated cMETHOPx_meth() macro

Don't just reuse the cSVOPx_sv() one any more, so we no longer have to
keep the same storage shape for SVOPs vs METHOPs.

22 months agoDefine the remaining convenience cMETHOP* macros
Paul "LeoNerd" Evans [Tue, 26 Jul 2022 16:11:23 +0000 (17:11 +0100)]
Define the remaining convenience cMETHOP* macros

Several of these were missing:
  cMETHOP, cMETHOPo, kMETHOP

Also, the field-accessing ones:
  cMETHOP_meth cMETHOP_rclass cMETHOPo_meth cMETHOPo_rclass

This commit adds them all, and use them to neaten other code where
appropriate.

22 months agoFix some unit tests to use new refcount_is() function
Paul "LeoNerd" Evans [Tue, 2 Aug 2022 15:37:30 +0000 (16:37 +0100)]
Fix some unit tests to use new refcount_is() function

22 months agoAdd a refcount_is() helper to t/test.pl
Paul "LeoNerd" Evans [Tue, 2 Aug 2022 14:49:24 +0000 (15:49 +0100)]
Add a refcount_is() helper to t/test.pl

A handy helper function that can be used in unit test .t files, rather
than currently a weird mix of using Internals::SvREFCNT everywhere.

22 months agoConfigure should avoid looping infinitely repeating the same question
Nicholas Clark [Tue, 2 Aug 2022 14:40:39 +0000 (16:40 +0200)]
Configure should avoid looping infinitely repeating the same question

Configure's helper function ./myread is intended to loop until it gets an
acceptable answer. For a couple of cases, an empty string is not acceptable
(eg 'Where is your C library?', if all automated attempts at answering this
have failed). In these cases, if Configure's standard input is /dev/null (or
closed), the shell read returns an empty string, and ./myread repeats the
question.

Before this commit, it would loop infinitely (generating continuous terminal
output). With this commit, we add a retry counter - if it asks the same
question to many times, it aborts Configure. This means that unattended
./Configure runs should now always terminate, as termination with an error
is better than spinning forever.

22 months agoperlfunc - correct argument terminology for dbmopen
Dan Book [Tue, 2 Aug 2022 04:17:32 +0000 (00:17 -0400)]
perlfunc - correct argument terminology for dbmopen

The MODE argument was renamed to MASK in 5.6, but later verbiage was added that calls it MODE again. Change the reference to MASK for consistency.

22 months agoPerl_reg_named_buff_fetch - simpler retarray creation & push
Richard Leach [Mon, 1 Aug 2022 21:33:27 +0000 (21:33 +0000)]
Perl_reg_named_buff_fetch - simpler retarray creation & push

retarray is a straightforward array created and populated with
SvIVX(sv_dat) number of elements within this function. As the
number of elements is known and all elements will be used, a
correctly-sized array can be created using newAV_alloc_x.

Since it's a straightforward array, av_push_simple can be used in
place of av_push. This will be more efficient.

22 months agoFile::Find: fix "follow => 1" on Windows
A. Sinan Unur [Thu, 28 Jul 2022 08:21:10 +0000 (10:21 +0200)]
File::Find: fix "follow => 1" on Windows

File::Find's code expects unix-style paths and it manipulates them using
basic string operations. That code is very fragile, and ideally we
should make it use File::Spec, but that would involve rewriting almost
the whole module.

Instead, we made it convert backslashes to slashes and handle drive
letters.

Note from xenu: this commit was adapted from the PR linked in this
blogpost[1]. I have squashed it, written the commit message and slightly
modified the code.

[1] - https://www.nu42.com/2021/09/canonical-paths-file-find-way-forward.html

Fixes #19995

22 months agoFile::Find: normalise indentation
Tomasz Konojacki [Thu, 28 Jul 2022 08:21:10 +0000 (10:21 +0200)]
File::Find: normalise indentation

This commit doesn't contain any functional changes. If you're
seeing it in "git blame" output, try using -w switch, it will
hide whitespace-only changes.