This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
8 months agofeatures: populate cop_features from a hints hash the hard way
Tony Cook [Wed, 23 Aug 2023 04:52:20 +0000 (14:52 +1000)]
features: populate cop_features from a hints hash the hard way

I originally optimised populating cop_features for eval by storing
the hints mask in "feature/bits" and then fetching that when
re-populating the hints for eval.

But that has turned out to be too fragile, so iterate over the
possible feature keys and populate cop_features from that.

I could perhaps have avoided this cost by ensuring "feature/bits" was
set where else it was needed, but this code already iterates to build
the hints hash, iterating again doesn't increase the scale of the work
we're doing.

8 months agoperldelta for newLISTOPn()
Paul "LeoNerd" Evans [Tue, 29 Aug 2023 10:57:18 +0000 (11:57 +0100)]
perldelta for newLISTOPn()

8 months agoOP_EMPTYAVHV: create ops in newANONHASH/newANONLIST rather than rpeep
Richard Leach [Sat, 19 Aug 2023 00:27:18 +0000 (00:27 +0000)]
OP_EMPTYAVHV: create ops in newANONHASH/newANONLIST rather than rpeep

The current implementation of the OP_EMPTYAVHV optimization does not
optimize instances of empty anonymous hashes/lists on the RHS of LOGOP
conditions, such as in `my $x = $y || {}`.

This commit addresses this by removing the peephole optimization in
favour of having EMPTYAVHV OPs produced directly whenever a call is
made to `newANONHASH` or `newANONLIST` with an empty child OP `o`.
The standard TARGMY optimization in `S_maybe_targlex` has been
slightly adapted to also optimize the `LVINTRO` case for this OP.

This commit also addresses some feedback nits from the last dev
cycle: EMPTYAVHV is no longer a LISTOP, now just a BASEOP, and it
does not use the OPf_SPECIAL flag. (Both were unnecessary carryovers
from the ANONHASH and ANONLIST OPs.)

8 months agoEmploy the new newLISTOPn() in op.c
Paul "LeoNerd" Evans [Thu, 24 Aug 2023 13:59:30 +0000 (14:59 +0100)]
Employ the new newLISTOPn() in op.c

8 months agoEmploy the new newLISTOPn() in class.c
Paul "LeoNerd" Evans [Thu, 24 Aug 2023 13:51:02 +0000 (14:51 +0100)]
Employ the new newLISTOPn() in class.c

8 months agoDefine a newLISTOPn() function
Paul "LeoNerd" Evans [Thu, 24 Aug 2023 13:38:01 +0000 (14:38 +0100)]
Define a newLISTOPn() function

A va_args-taking function that avoids the caller's need to perform the
three-step newLISTOP(OP_LIST), append children, op_convert_list()
sequence.

This often makes the code compact enough to embed inside "point-free"
optree generating code, by avoiding the need for that intermediate
variable.

8 months agoRMG: Remove Travis CI References
Elvin Aslanov [Wed, 23 Aug 2023 18:30:45 +0000 (20:30 +0200)]
RMG: Remove Travis CI References

Since it's obsolete.

Replace with GitHub Actions where appropriate

8 months agoPerlIOScalar_pushed: move SvUPGRADE to where it might apply
Richard Leach [Sun, 27 Aug 2023 20:15:14 +0000 (20:15 +0000)]
PerlIOScalar_pushed: move SvUPGRADE to where it might apply

`newSVpvs("")` returns an SV of type `SVt_PV`, therefore there's no
point in calling `SvUPGRADE(..., SVt_PV)` on it.

The other nearby code paths _might_ set an SV that needs upgrading
(I haven't looked into the logic), so the `SvUPGRADE` statement has
been moved inside the relevant branch rather than being removed.

8 months agoPerl_ck_refassign: support refassigning into a state variable
Richard Leach [Tue, 25 Jul 2023 23:06:20 +0000 (23:06 +0000)]
Perl_ck_refassign: support refassigning into a state variable

Prior to this commit, Perl_ck_refassign did not check if the
target was a state variable and, if so, wrap it in a ONCE op
so that the RHS is only evaluated once.

8 months agoFix copypaste error on Renée's name in release_schedule.pod
Paul "LeoNerd" Evans [Fri, 25 Aug 2023 10:38:18 +0000 (11:38 +0100)]
Fix copypaste error on Renée's name in release_schedule.pod

8 months agoAdd Renée B and Max M to release_schedule.pod
Paul "LeoNerd" Evans [Fri, 25 Aug 2023 10:35:23 +0000 (11:35 +0100)]
Add Renée B and Max M to release_schedule.pod

8 months agoperlsyn: Fix typo
Jakub Wilk [Thu, 24 Aug 2023 19:17:03 +0000 (21:17 +0200)]
perlsyn: Fix typo

8 months agoloc_tools: Handle ignored positional categories
Karl Williamson [Fri, 7 Jul 2023 01:40:08 +0000 (19:40 -0600)]
loc_tools: Handle ignored positional categories

The previous commit changes locale.c to adequately handle categories on
a system that we have been told to ignore.  This commit updates
loc_tools to better handle them.

8 months agoFix ignoring locale categories
Karl Williamson [Sat, 19 Aug 2023 17:41:44 +0000 (11:41 -0600)]
Fix ignoring locale categories

There have long been Configure options like

    ./Configure -Accflags=-DNO_LOCALE_TIME

to tell perl to not pay attention to the LC_TIME category.  This feature
has never fully worked.  This commit fixes it.

One problem is that the when the libc does know about LC_TIME, but perl
is supposed to ignore that, it didn't have in place the logic to ignore
it in many circumstances.

This commit creates a boolean array for each locale category known to
the platform's libc, indicating whether that category is to be ignored
or not by perl.  If no category is to be ignored, the array and
ancillary code are not compiled, so perl works like it did before this
commit.

But if one or more categories are to be ignored, the code comes into
play.  A problem is that such categories really do exist on the
platform, and so ignoring them just doesn't work properly.  On a
platform with positional LC_ALL notation when not all categories have
the same locale, LC_ALL legally could look something like

    C/de_DE/nl_NL/en_GB/zh_TW.UTF-8/he_IL

Perl has to be smart enough to know which of those are categories to be
ignore.  Prior to this commit, it wasn't.  In fact, all ignored
categories do exist and do have a locale.  Those should all be C.
Therefore this commit doesn't actually ignore any locales; it instead
causes perl to refuse to change such ones away from C.

We don't currently have tests for these configurations.  I have
personally tested a couple hundred different combinations over and over,
but that's way too much for CI.

8 months agolocale_table.h: Use CTYPE instead of LC_CTYPE, etc
Karl Williamson [Sat, 19 Aug 2023 16:02:33 +0000 (10:02 -0600)]
locale_table.h: Use CTYPE instead of LC_CTYPE, etc

locale.c is changed to add 'LC_'.  This is in preparation for future
commits.

8 months agoMove code from perl.h to locale_table.h
Karl Williamson [Sat, 19 Aug 2023 13:52:31 +0000 (07:52 -0600)]
Move code from perl.h to locale_table.h

This is in preparation for future commits.  The layout of the new code
is also in preparation for those commits.

8 months agolocale.c: Change name of macro formal parameter
Karl Williamson [Sat, 19 Aug 2023 16:19:52 +0000 (10:19 -0600)]
locale.c: Change name of macro formal parameter

This makes all the definitions of this macro consistent.

8 months agoswitch_locale_context: Add aTHX
Karl Williamson [Wed, 3 May 2023 15:12:52 +0000 (09:12 -0600)]
switch_locale_context: Add aTHX

This fixes GH #21040

Instead of a dTHX, this passes aTHX automatically, and skips calling
this function if there is no valid context.

It moves that decision into the macro itself, avoiding some #ifdef
directives.

And it adds explanation

8 months agolocale.c: Change DEBUG statements to include non-0 errno
Karl Williamson [Fri, 30 Jun 2023 18:50:31 +0000 (12:50 -0600)]
locale.c: Change DEBUG statements to include non-0 errno

This is very helpful when things go wrong.

8 months agolocale.c: Move a macro definition earlier in the file
Karl Williamson [Fri, 7 Apr 2023 01:49:20 +0000 (19:49 -0600)]
locale.c: Move a macro definition earlier in the file

8 months agoperldelta for 72d0a0a0ea
Tony Cook [Wed, 23 Aug 2023 00:14:00 +0000 (10:14 +1000)]
perldelta for 72d0a0a0ea

8 months agot/op/magic.t: handle busybox ps
Tony Cook [Mon, 7 Aug 2023 06:05:13 +0000 (16:05 +1000)]
t/op/magic.t: handle busybox ps

There were two problems here:

- busybox ps doesn't support the ps -p option and produces an error
  and fails when it sees it.  This does no harm beyond noise.
- busybox ps ignores a PID parameter, always producing a complete
  list of processes, so the like()s around line 430 would include the
  entire ps list in their NAME values, producing a bunch of noise that
  TEST (but not harness) chokes on.

8 months agovarious: timespec/timeval.tv_sec is time_t, not long, according to POSIX
Alexander Kanavin [Tue, 15 Aug 2023 11:55:06 +0000 (13:55 +0200)]
various: timespec/timeval.tv_sec is time_t, not long, according to POSIX

This matters on 32 bit systems configured with 64 bit time_t
(so they survive beyond 2038). Casting them to long is causing loss of bits
and badly mismatched time data.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
8 months agointrpvar.h: Comments
Karl Williamson [Thu, 20 Apr 2023 15:22:03 +0000 (09:22 -0600)]
intrpvar.h: Comments

8 months agointrpvar.h: Initialize two variables
Karl Williamson [Sun, 2 Jul 2023 19:30:59 +0000 (13:30 -0600)]
intrpvar.h: Initialize two variables

This isn't a bug, as they currently get set up, but it is safer to
initialize variables when we know that what their initial value will
always be.  Here, we know that we are going to start out in the C
locale, which isn't UTF-8.

8 months agoSuppress -Wunused_variable warning during 'make'
James E Keenan [Mon, 21 Aug 2023 00:45:40 +0000 (20:45 -0400)]
Suppress -Wunused_variable warning during 'make'

Implement Dave Mitchell's suggestion: we don't really need the unused
variable.

For: https://github.com/Perl/perl5/issues/21393

8 months agoPrepare Module::CoreList for 5.39.3
Paul "LeoNerd" Evans [Mon, 21 Aug 2023 11:33:07 +0000 (12:33 +0100)]
Prepare Module::CoreList for 5.39.3

8 months agoremove template content from perl5390delta
Graham Knop [Sun, 20 Aug 2023 23:33:00 +0000 (01:33 +0200)]
remove template content from perl5390delta

The 5.39.0 release is identical to 5.38.0, so there is no content to
fill these sections with.

8 months agoBump version in lib/B/Op_private.pm for 5.39.3
Paul "LeoNerd" Evans [Sun, 20 Aug 2023 23:46:28 +0000 (00:46 +0100)]
Bump version in lib/B/Op_private.pm for 5.39.3

8 months agoFix version in latest added epigraph for 5.39.2
Paul "LeoNerd" Evans [Sun, 20 Aug 2023 23:31:29 +0000 (00:31 +0100)]
Fix version in latest added epigraph for 5.39.2

8 months agoBump version for 5.39.3
Paul "LeoNerd" Evans [Sun, 20 Aug 2023 23:26:30 +0000 (00:26 +0100)]
Bump version for 5.39.3

8 months agoNew perldelta for 5.39.3
Paul "LeoNerd" Evans [Sun, 20 Aug 2023 23:19:44 +0000 (00:19 +0100)]
New perldelta for 5.39.3

8 months agoTick release 5.39.2
Paul "LeoNerd" Evans [Sun, 20 Aug 2023 23:09:58 +0000 (00:09 +0100)]
Tick release 5.39.2

8 months agoAdd epigraph for 5.39.2
Paul "LeoNerd" Evans [Sun, 20 Aug 2023 23:08:00 +0000 (00:08 +0100)]
Add epigraph for 5.39.2

8 months agoMerge branch 'release-5.39.2' into blead
Paul "LeoNerd" Evans [Sun, 20 Aug 2023 23:02:53 +0000 (00:02 +0100)]
Merge branch 'release-5.39.2' into blead

8 months agoAdd 5.39.2 to perlhist.pod v5.39.2
Paul "LeoNerd" Evans [Sun, 20 Aug 2023 21:52:58 +0000 (22:52 +0100)]
Add 5.39.2 to perlhist.pod

8 months agoUpdated pod/perldelta.pod for 5.39.2
Paul "LeoNerd" Evans [Sun, 20 Aug 2023 00:10:23 +0000 (01:10 +0100)]
Updated pod/perldelta.pod for 5.39.2

8 months agoUpdate Module::CoreList for 5.39.2
Paul "LeoNerd" Evans [Sat, 19 Aug 2023 23:37:52 +0000 (00:37 +0100)]
Update Module::CoreList for 5.39.2

8 months agoperldelta.pod: Fix POD formatting '= item'
Paul "LeoNerd" Evans [Sun, 20 Aug 2023 20:57:54 +0000 (21:57 +0100)]
perldelta.pod: Fix POD formatting '= item'

8 months agoperldelta: Document new sv_strftime_foo functions
Karl Williamson [Sat, 19 Aug 2023 20:29:46 +0000 (14:29 -0600)]
perldelta: Document new sv_strftime_foo functions

8 months agoPOSIX: time.t: Add missing arg to shift
Karl Williamson [Sun, 20 Aug 2023 20:49:48 +0000 (14:49 -0600)]
POSIX: time.t: Add missing arg to shift

This would loop forever on boxes with only a C locale available

8 months agoAdd the next few months of volunteers to Porting/release_schedule.pod
Paul "LeoNerd" Evans [Sun, 20 Aug 2023 01:24:38 +0000 (02:24 +0100)]
Add the next few months of volunteers to Porting/release_schedule.pod

8 months agoAdd perldelta for Serenity OS support
Leon Timmermans [Sun, 20 Aug 2023 09:28:57 +0000 (11:28 +0200)]
Add perldelta for Serenity OS support

8 months agoPorting/corelist-perldelta.pm: Fix name of IO::Compress module (not dist)
Paul "LeoNerd" Evans [Sun, 20 Aug 2023 00:50:08 +0000 (01:50 +0100)]
Porting/corelist-perldelta.pm: Fix name of IO::Compress module (not dist)

8 months agocpan/IO-Socket-IP - Update to version 0.42
Paul Evans [Thu, 17 Aug 2023 01:34:46 +0000 (21:34 -0400)]
cpan/IO-Socket-IP - Update to version 0.42

0.42    2023-07-25
        [CHANGES]
         * Put error string in `$IO::Socket::errstr` as done by
           IO::Socket v1.45
         * Updated for Perl v5.14 - use `package NAME VERSION` syntax

        [BUGFIXES]
         * Fix typo 'behvior' (RT133467) (thanks ferivoz@riseup.net)
         * Fix for DragonflyBSD and IPV6_V6ONLY from core perl (RT148293)

Committer: Regenerate 'customized' database.

8 months agoDecustomize entry for IO::Socket::IP
James E Keenan [Thu, 17 Aug 2023 01:29:34 +0000 (21:29 -0400)]
Decustomize entry for IO::Socket::IP

IO-Socket-IP-0.46 Changes indicates that upstream maintainer has
incorporated patch submitted from core.  Hence, we should be able to
sync upstream version of cpan/IO-Socket-IP/lib/IO/Socket/IP.pm into
blead with no problems.

8 months agoperlguts: examples of ops being made PERL_RC_STACK
David Mitchell [Sat, 19 Aug 2023 19:43:27 +0000 (20:43 +0100)]
perlguts: examples of ops being made PERL_RC_STACK

Refer to the commits which upgraded pp_not() and pp_and(), as examples
of how to upgrade pp functions to work efficiently under PERL_RC_STACK.

8 months agoperlguts - tweak PERL_RC_STACK version status
David Mitchell [Sat, 19 Aug 2023 19:29:47 +0000 (20:29 +0100)]
perlguts - tweak PERL_RC_STACK version status

Remove the XXX which indicated that I wasn't sure which perl version it
would first appear in.

8 months agoperldelta entry for PERL_RC_STACK
David Mitchell [Sat, 19 Aug 2023 19:23:29 +0000 (20:23 +0100)]
perldelta entry for PERL_RC_STACK

8 months agoS_find_locale_from_environment(): Combine logic
Karl Williamson [Sun, 2 Apr 2023 16:54:20 +0000 (10:54 -0600)]
S_find_locale_from_environment(): Combine logic

Prior to this commit, the logic was repeated for non-LC_ALL versus
LC_ALL; the latter being executed in a loop.  The logic is not really
trivial and it would be better to have just one instance, so that it
can't get out-of-sync.  To do this, this commit moves everything to the
loop, but sets it up for the non-LC_ALL case to just do a single
iteration.

It also avoids going out to the environment and fetching LANG unless
needed.  The previous behavior got LANG unconditionally if the loop was
used.  It is quite likely that not every locale category would have a
corresponding environment variable set, so that fetch likely wasn't
wasted.  But in order to combine things, the checking for LANG is done
in the loop.

The bottom line is that there is extra code required to combine the two
pieces of logic, but I believe the combining of this into a single
paradigm is worth it.

8 months agoS_find_locale_from_environment(): Add comments
Karl Williamson [Sun, 2 Apr 2023 16:53:39 +0000 (10:53 -0600)]
S_find_locale_from_environment(): Add comments

8 months agoS_find_locale_from_environment(): Change var name
Karl Williamson [Sun, 2 Apr 2023 16:36:38 +0000 (10:36 -0600)]
S_find_locale_from_environment(): Change var name

This variable is really the LANG environment variable; change its name
to correspond.

8 months agoEnforce builtin.pm version bump when builtin.c is modified
Dagfinn Ilmari Mannsåker [Thu, 17 Aug 2023 21:57:51 +0000 (22:57 +0100)]
Enforce builtin.pm version bump when builtin.c is modified

universal.c is not listed, since it powers many different modules
besides UNIVERSAL.pm, and we can't know which one would need its
version bumped when it's modified.

8 months agotestsuite.yaml - Add testing of PERL_RC_STACK
David Mitchell [Thu, 17 Aug 2023 20:06:47 +0000 (21:06 +0100)]
testsuite.yaml - Add testing of PERL_RC_STACK

Include a debugging build with a reference-counted stack to shake
out places where modifications to pp() functions etc would pass on
normal builds, but break in the new environment. By including DEBUGGING,
this enables a bunch of assertions which check that the stack state is
sane at all times.

8 months agoRemove `experimental::builtin` warnings from most of the builtin.c functions
Paul "LeoNerd" Evans [Mon, 7 Aug 2023 13:11:31 +0000 (14:11 +0100)]
Remove `experimental::builtin` warnings from most of the builtin.c functions

Removes the experimental status and associated `experimental::builtin`
warning from most of the functions in the `builtin::` space.

Still remaining experimental are:

 * is_bool - because stable boolean tracking was only recently introduced and
   may not have been thoroughly tested yet

 * created_as_string, created_as_number - similar

 * export_lexically - because lexical export of subs is equally still
   quite new and may need more testing

8 months agoPOSIX/t/time.t: Remove TODO
Karl Williamson [Fri, 19 May 2023 20:00:49 +0000 (14:00 -0600)]
POSIX/t/time.t: Remove TODO

The past few commits have fixed this bug

8 months agoext/POSIX/t/time.t: Fix to work on crippled boxes
Karl Williamson [Sat, 17 Jun 2023 20:37:01 +0000 (14:37 -0600)]
ext/POSIX/t/time.t: Fix to work on crippled boxes

Some platforms donn't allow LC_TIME to be a UTF-8 locale; test for that
and skip these tests is so.

8 months agotime.t: Add more strftime tests
Karl Williamson [Fri, 12 May 2023 01:01:31 +0000 (19:01 -0600)]
time.t: Add more strftime tests

8 months agoPOSIX/t/time.t: Remove no longer necessary code
Karl Williamson [Thu, 4 May 2023 12:31:30 +0000 (06:31 -0600)]
POSIX/t/time.t: Remove no longer necessary code

POSIX::strftime() now automatically handles the case where the locales of
LC_TIME and LC_CTYPE aren't the same.  So no need to explicitly do this
in the test file.

8 months agoImplement sv_strftime_tm and sv_strftime_ints
Karl Williamson [Wed, 26 Apr 2023 21:36:54 +0000 (15:36 -0600)]
Implement sv_strftime_tm and sv_strftime_ints

These two functions are designed to free the caller from having to know
anything about the intricacies of handling UTF-8 in using strftime(), as
they take SV inputs and return an SV with the UTF-8 flag appropriately
set.

They differ only in that one takes a bunch of integer arguments that
define the various components of the time; and the other takes a pointer
to a struct tm.

The POSIX implementation of strftime is converted to use these.

8 months agolocale.c: Move my_strftime() within the file
Karl Williamson [Fri, 19 May 2023 20:48:59 +0000 (14:48 -0600)]
locale.c: Move my_strftime() within the file

This will be more logically placed after future commits

8 months agolocale.c: Split my_strftime into 2 functions
Karl Williamson [Fri, 19 May 2023 20:31:09 +0000 (14:31 -0600)]
locale.c: Split my_strftime into 2 functions

Future commits will want the individual functionality the two provided
separately.

8 months agolocale.c: Silence compiler warning on some platforms
Karl Williamson [Fri, 21 Apr 2023 15:10:07 +0000 (09:10 -0600)]
locale.c: Silence compiler warning on some platforms

This argument isn't used on some platforms.

8 months agolocale.c: Compile utf8ness on platforms that need it
Karl Williamson [Fri, 21 Apr 2023 15:00:57 +0000 (09:00 -0600)]
locale.c: Compile utf8ness on platforms that need it

These two functions need to be compiled on certain other platforms than
what was happening.

8 months agoSet builtin::indexed proto to "@"
James Raspass [Thu, 17 Aug 2023 00:19:22 +0000 (01:19 +0100)]
Set builtin::indexed proto to "@"

8 months agoRegenerate 'customized' database
James E Keenan [Thu, 17 Aug 2023 10:18:44 +0000 (06:18 -0400)]
Regenerate 'customized' database

Account for modification (removal) of CUSTOMIZED element for
Test::Harness in Porting/Maintainers.pl in d91c117aa9.

8 months agocpan/Test-Harness - Update to version 3.47
Leon Timmermans [Wed, 16 Aug 2023 22:28:36 +0000 (18:28 -0400)]
cpan/Test-Harness - Update to version 3.47

3.47 2023-08-13
        - Add missing negation in EINTR check
        - Fix HARNESS_PERL_SWITCHES=-I handling in TAP::Harness::Env

8 months agocpan/perlfaq - Update to version 5.20230812
Karen Etheridge [Wed, 16 Aug 2023 22:14:13 +0000 (18:14 -0400)]
cpan/perlfaq - Update to version 5.20230812

5.20230812  2023-08-12 21:30:12Z
  * some typo fixes to perlfaq4 (PR #103 and PR#104, brian d foy)
  * some wording improvements to perlfaq4 for "Why doesn't & work the way I want it to?"
    (PR#104, resolves issue #101, brian d foy)
  * some updates to perlfaq2 for perl magazines (PR#105, brian d foy)

8 months agoPermit attributed variables inside signatured subs (Fixes GH #21158)
Paul "LeoNerd" Evans [Mon, 19 Jun 2023 16:16:45 +0000 (17:16 +0100)]
Permit attributed variables inside signatured subs (Fixes GH #21158)

8 months agoMinor updates for release documentation
Richard Leach [Tue, 20 Dec 2022 21:25:02 +0000 (21:25 +0000)]
Minor updates for release documentation

These are mostly additions for clarity or extra examples.

Some advice has been removed from "update INSTALL", because the wording
within INSTALL has been made less version-specific, requiring fewer
updates per-release.

8 months agopod: eliminate references to `$a` and `$b` outside sort context
Dagfinn Ilmari Mannsåker [Wed, 16 Aug 2023 17:30:28 +0000 (18:30 +0100)]
pod: eliminate references to `$a` and `$b` outside sort context

This causes confusion for new users when they get told to not use
those variables because of how they interact with sort and friends.

This changes them to `$x` and `$y`, and also changes nearby variables
to keep things consistent, such as `$c` -> `$z` and `@a` -> `@x`.

I dind't touch `perlfilter.pod`, since that comes from the
Filter dist, which is upstream CPAN.

8 months ago[MERGE] add PERL_RC_STACK build option
David Mitchell [Wed, 16 Aug 2023 16:37:32 +0000 (17:37 +0100)]
[MERGE] add PERL_RC_STACK build option

This non-default build option creates a perl interpreter where SVs on
the argument stack have their reference counts incremented.

As of this commit, most pp() functions still haven't been updated to
handle this: so instead on PERL_RC_STACK builds, these functions are now
called via a temporary wrapper to adjust ref counts as appropriate. This
makes it it very slow; but over time, common pp() functions will be
modified to not need wrapping, and things should speed up.

Similarly, all XS functions are currently called via a wrapper.

Without the PERL_RC_STACK build option, the perl interpreter is largely
unchanged. There are a few subtle changes around the handling of @_ and
@DB::args in edge cases, and a few pp() functions have been rewritten to
use the new rpp_foo() API, which (in theory) should have no visible
change in behaviour on non-PERL_RC_STACK builds.

PERL_RC_STACK is currently not a configure option, just a define. So
perl needs to be configured as:

    sh Configure ... -Accflags='-DPERL_RC_STACK'

There is a new section, "Reference-counted argument stack " in
perlguts.pod which explains in detail what's changed.

8 months agosupport RC XS subs: add CVf_XS_RCSTACK flag
David Mitchell [Sat, 12 Aug 2023 20:04:47 +0000 (21:04 +0100)]
support RC XS subs: add CVf_XS_RCSTACK flag

Allow an XS sub to be flagged with CVf_XS_RCSTACK, which indicates that
it expects a reference-counted stack - and so pp_entersub() etc should
invoke it directly rather than via xs_wrap() on PERL_RC_STACK builds.

Note that there is not yet any syntax in an XS file which supports
marking an XS sub as 'RC-aware', so this facility is very much
in the early stages and "at your own risk", requiring the CV to
manually have its CVf_XS_RCSTACK flag set.

8 months agoadd rpp_invoke_xs() function
David Mitchell [Sat, 12 Aug 2023 12:17:54 +0000 (13:17 +0100)]
add rpp_invoke_xs() function

This function is just a neater version of:

    #ifdef PERL_RC_STACK
        Perl_xs_wrap(aTHX_ CvXSUB(cv), cv);
    #else
        (void)(*CvXSUB(cv))(aTHX_ cv);
    #endif

but shortly it will be extended to allow XS CVs to be flagged as
"RC-aware".

8 months agoadd t/op/refstack.t
David Mitchell [Sat, 12 Aug 2023 08:59:53 +0000 (09:59 +0100)]
add t/op/refstack.t

Add a suite of tests which check whether all the "stack not reference
counted" tickets are fixed when perl is built with PERL_RC_STACK

8 months agoRC_STACK asserts without DEBUG_LEAKING_SCALARS
David Mitchell [Fri, 4 Aug 2023 21:37:10 +0000 (22:37 +0100)]
RC_STACK asserts without DEBUG_LEAKING_SCALARS

An earlier commit added some asserts to the old-style and new-style
stack push/pop functions such as PUSHs() or rpp_popfree_1().  These
assert that the stack is reference-counted or not as appropriate.

These asserts were enabled only if perl was built with all of

    DEBUGGING && PERL_RC_STACK && DEBUG_LEAKING_SCALARS.

This commit makes the asserts available under just

    DEBUGGING && PERL_RC_STACK

Initially  I was worried about the performance implications (you expect
DEBUGGING builds to be slow, but not *too* slow), but they don't seem
too bad. So by making them more likely to be enabled, they're more
likely to help people spot code that needs fixing (e.g. code still doing
POPs when the stack is reference counted and the function hasn't been
wrapped).

8 months agowhen (re)creating @_, zero its elements
David Mitchell [Thu, 16 Mar 2023 21:58:22 +0000 (21:58 +0000)]
when (re)creating @_,  zero its elements

When a sub's @_ gets abandoned (e.g. when 'goto &bar' "donates" the
current @_ to the new sub), a new AV is created at pad[0] for the old
sub. Perl alloc()'s the AvARRAY() buffer for the new AV, but didn't zero
it. This didn't used to be a problem, because @_ AVs are created
!AvREAL(), so the first thing perl did when someone tries to modify @_,
is to call av_reify() on it.  And it just so happens that av_reify()
zeros out all the unused slots on the array first. So code like

    $_[1] = 1;
    do_something_with($_[0])

was fine.

However, on PERL_RC_STACK builds, @_ is AvREAL() by default now, so
av_reify() doesn't get called, so AvARRAY() can sometimes contain random
wild pointers.

The fix is simple: zero AvARRAY() when creating it.

This was showing as a failure in Test::Trap

8 months agocaller(): don't copy freed SV pointer to @DB::args
David Mitchell [Wed, 15 Mar 2023 11:14:10 +0000 (11:14 +0000)]
caller(): don't copy freed SV pointer to @DB::args

When pp_caller() aliases the elements of @_ to @DB::args, it may include
pointers to array elements which have been shifted away. So for example
in

    sub f { my $self = shift; ....; croak() }

it populates $DB::args[0] with the SV pointer one position below the
AvARRAY() of @_. This means that the argument lists in the stack
backtrace provided by croak() will include the original first arg,
which is nice, but is very fragile. There is no guarantee that that SV
hasn't been freed or reallocated in the meantime.

This commit adds a check for each SV pointer being copied to @DB::args,
which NULLs it if the SV has a refcount of 0.

This means that in something like:

    package DB:
    () = caller($i);
    my @args = @DB::args;

perl will no longer panic about copying a freed SV.

Note that this commit does not address the issue of the SV having already
been reallocated. In the example above, some elements of @args may
contain a copy of some other random variable. However, the previous
commit moved to earlier in the function, the block of code in
pp_caller() which populates @DB::args, to before pp_caller() allocates
new SVs for things like the package name. Which means the RC==0 test
added by this commit has a better chance of spotting SVs which have been
freed but not yet reallocated.

In summary, @DB::args is still a horrible, fragile hack, but these two
commits make it slightly less fragile in some circumstances.

8 months agopp_caller(): set @DB::args earlier
David Mitchell [Wed, 15 Mar 2023 11:03:11 +0000 (11:03 +0000)]
pp_caller(): set @DB::args earlier

Copy @_ SV pointers to @DB::args earlier, before pp_caller() has the
chance to create any new SVs (e.g. for the package name). This will give
the next commit a chance to discover and skip any freed elements in @_.

This commit makes no changes to the block of code that is moved;
that's saved for the next commit.

8 months agoPerl_runops_wrap((): don't mortalise NULLs
David Mitchell [Sat, 11 Mar 2023 22:14:28 +0000 (22:14 +0000)]
Perl_runops_wrap((): don't mortalise NULLs

This function was doing a delayed ref count decrement of all the SVs it
had previously temporarily incremented, by mortalising each one. For
efficiency it was just doing a Copy() of a block of SVs addresses from
the argument stack to the TEMPs stack.

However, the TEMPs stack can't cope with NULL pointers, while there are
sometimes NULL pointers on the argument stack - in particular, while
doing a map, any temporary holes in the stack are set to NULL on
PERL_RC_STACK builds.

The fix is simple - copy individual non-NULL addresses to the TEMPS
stack rather than doing a block copy.

8 months agopp_goto: fix macro-in-macro compile error
David Mitchell [Sun, 26 Feb 2023 15:35:09 +0000 (15:35 +0000)]
pp_goto: fix macro-in-macro compile error

Turns out MSVC 1.42 doesn't like

        FOO(bar,
    #ifdef X
            1
    #else
            0
    #endif
        );

where FOO is a macro.

8 months agoadd perlguts section on a reference-counted stack
David Mitchell [Tue, 14 Feb 2023 00:42:59 +0000 (00:42 +0000)]
add perlguts section on a reference-counted stack

Explain what all the new rpp_foo() functions are for.

8 months agoEliminate PERL_XXX_TMP_NORC
David Mitchell [Sat, 18 Feb 2023 00:03:08 +0000 (00:03 +0000)]
Eliminate PERL_XXX_TMP_NORC

This macro was disabled a few commits ago. Now remove all use of it
from the core.

It was just a temporary crutch that disabled actually adjusting the
reference count of things being pushed and popped off the stack, even on
PERL_RC_STACK builds. It allowed the core to be converted to support a
reference-counted stack as a bunch of incremental changes.

8 months agoXS::APItest::clone_with_stack(); check SI RC state
David Mitchell [Fri, 17 Feb 2023 21:53:11 +0000 (21:53 +0000)]
XS::APItest::clone_with_stack(); check SI RC state

In this test function, push a couple of stackinfos, one with a
ref-counted stack, and one without.
After cloning, pop the cloned stackinfos and assert that the cloned
argument stacks are also appropriately RC or non-RC.

This should probably have been done properly as some new tests rather
than a couple of asserts, but that would have involved a lot more
effort.

8 months agoadd tests for XSPP_wrapped() macro
David Mitchell [Fri, 10 Feb 2023 22:56:39 +0000 (22:56 +0000)]
add tests for XSPP_wrapped() macro

This new macro allows an old-style non-reference-counted PP-style
function to be used on a PERL_RC_STACK builds. It's intended for
non-core PP functions which are typically in an XS file and are used to
replace the PP function of an existing op, or to be attached to a custom
op.

It's virtually identical to the PP_wrapped() macro, except that it
uses the name as-is rather than prepending Perl_ to the name

8 months agotweak pp_wrap() and xs_wrap()
David Mitchell [Sat, 18 Feb 2023 08:55:47 +0000 (08:55 +0000)]
tweak pp_wrap() and xs_wrap()

After bumping up the reference counts of the returned values,
reset si_stack_nonrc_base earlier, so that if perl dies while
decrementing the original args, all reference counts will be properly
accounted for.

Also in xs_wrap(), only bother doing

    PL_markstack_ptr[0]  += nargs;

in the branch where nargs > 0.

8 months agopp_wrap(), xs_wrap(): extract some common code
David Mitchell [Fri, 3 Feb 2023 01:13:06 +0000 (01:13 +0000)]
pp_wrap(), xs_wrap(): extract some common code

and put it in a static function, S_pp_xs_wrap_return().

8 months agorunops_debug(): add RC-stack assertions
David Mitchell [Thu, 26 Jan 2023 21:03:51 +0000 (21:03 +0000)]
runops_debug(): add RC-stack assertions

on PERL_RC_STACK builds,
1) assert that the stack is reference-counted (rpp_stack_is_rc()).
2) assert the any split point (si_stack_nonrc_base) isn't above the
    top of the stack.

8 months agostack push/pops: assert rpp_stack_is_rc() state
David Mitchell [Fri, 17 Feb 2023 20:42:47 +0000 (20:42 +0000)]
stack push/pops: assert rpp_stack_is_rc() state

On perls built with both -DPERL_RC_STACK and -DDEBUG_LEAKING_SCALARS,
add asserts to the various old-style PUSHs() etc macros and new-style
rpp_push_1() etc functions that they're operating on the right sort of
stack. In particular:

PUSHs() and POPs() should only be used on stacks where rpp_stack_is_rc()
is false, since they don't modify the reference count of the SVs they
are pushing or popping.

Conversely, rpp_push_1(), rpp_popfree_1() etc should only be used on
stacks where rpp_stack_is_rc() is true, since they modify the reference
counts of the SVs they push and pop.

On perls not compiled with PERL_RC_STACK, the rpp_ functions don't
modify the reference counts, but on such builds the rpp_stack_is_rc()
assertions in the rpp_ functions are disabled, so it all works out
still.

8 months agodisable PERL_XXX_TMP_NORC
David Mitchell [Mon, 2 Jan 2023 13:10:01 +0000 (13:10 +0000)]
disable PERL_XXX_TMP_NORC

This macro was just a temporary crutch that disabled actually adjusting
the reference count of things being pushed and popped off the stack,
even on PERL_RC_STACK builds. It allowed the core to be converted to
support a reference-counted stack as a bunch of incremental changes.

This commit turns it off, enabling the stack to become actually
reference-counted on PERL_RC_STACK builds.

In a few commits' time, this macro will be completely eliminated from
the source code.

8 months agoPerl_debstack(): indicate stack refcount status
David Mitchell [Fri, 16 Dec 2022 15:17:29 +0000 (15:17 +0000)]
Perl_debstack(): indicate stack refcount status

When displaying the stack with perl -Ds or -Dsv, put a vertical bar (|)
at the boundary between the reference-counted part of the stack and the
non-reference-counted part, if any.

In addition with -Dsv, for each stack show its status;

    (real)         all items on the stack are reference-counted
    (partial real) items below si->si_stack_nonrc_base are RCed
    blank          no items are RCed

This commit switches to invoking S_deb_stack_n() directly, rather than
via the deb_stack_n() macro, as some compilers can't cope with the
'ifdef' amongst the calling args.

8 months agorpp_is_lone(): allow non-temp SV too
David Mitchell [Fri, 27 Jan 2023 15:45:40 +0000 (15:45 +0000)]
rpp_is_lone(): allow non-temp SV too

This function indicates whether an SV on the stack is kept alive only by
a single ref from the temps stack - which is often the case with stuff
pushed onto the stack by PP functions. Often this means that the SV can
be passed through rather then copied in places like returning from a
subroutine.

With a ref-counted stack, it's possible for a *non* SvTEMP SV to also be
stealable, if it has a refcount of 1, since that SV is being kept alive
purely by its (now refcounted) link from the stack.

So this commit adds that condition too (and also simplifies the
condition for efficiency).

In summary: originally perl (and then this function) did:

    if (SvTEMP(sv) && SvREFCNT(sv) == 1) { ... steal it ... }

Now this function's condition is the equivalent of

    #ifdef PERL_RC_STACK
        (    (SvREFCNT(sv) == 1)
        || (SvTEMP(sv) && SvREFCNT(sv) == 2))
    #else
        (SvTEMP(sv) && SvREFCNT(sv) == 1)
    #endif

8 months agomake RC-stack-aware: Perl_filter_read()
David Mitchell [Thu, 19 Jan 2023 19:42:18 +0000 (19:42 +0000)]
make RC-stack-aware: Perl_filter_read()

This function in toke.c calls out to a random C-level filter function
for each source input chunk. Because that function may in turn invoke
a Perl function via call_sv() -  and may itself push stuff onto or off the
stack for that call -  present that function with a
non-reference-counted stack environment for backwards compatibility.

8 months agoadd stack extend to Perl_die_unwind()
David Mitchell [Fri, 27 Jan 2023 20:12:54 +0000 (20:12 +0000)]
add stack extend to Perl_die_unwind()

When invoked via a scalar-context eval, die_unwind() was pushing
&PL_sv_undef without extending the stack first. It's been this way for
many years. Spotted by visual inspection while adding rpp_() code.

I could get a SEGV with the following code, but I haven't added it as a
test as it's highly sensitive to exactly what size stack is initially
allocated and the OS's malloc().

    my $x;
    my @a =
        ($x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         scalar eval { die },
    );

8 months agoAllow argument stacks to be reference-counted
David Mitchell [Mon, 23 Jan 2023 15:23:06 +0000 (15:23 +0000)]
Allow argument stacks to be reference-counted

When built with PERL_RC_STACK, this substantial commit:

* makes stacks AvREAL() by default.
* adds the si_stack_nonrc_base field to the stackinfo structure.
* adds the runops_wrap() wrapper

It also adds rpp_obliterate_stack_to() for clearing the stack on
exceptions

Collectively, this allows each stack to be in one of three states:

1) AvREAL(PL_curstack) && PL_curstackinfo->si_stack_nonrc_base == 0

(the new default) all the SVs pointed to from the stack are
reference-counted.

2) AvREAL(PL_curstack) && PL_curstackinfo->si_stack_nonrc_base > 0

items on the stack are reference-counted only below si_stack_nonrc_base.

3) !AvREAL(PL_curstack)

(existing behaviour) no items on the stack are reference-counted.

The way it generally works is that runops loops assume that all the PP
functions they call out to are reference-count-aware. Where this isn't
yet the case, the recently-added pp_wrap() and xs_wrap() functions
assume a reference-counted stack, but use the si_stack_nonrc_base
mechanism to call out to PP or XS functions which aren't aware of a
reference-counted stack.

Conversely, the runops_wrap() function added by this commit wraps calls
to runops loops, since such loops work only with an RC stack. So if
called with a non-RC or partially-RC stack, the wrapper temporarily
fixes up the stack to be fully-RC, calls the real runops loop, then on
return reverts the stack back to it's non-RC ways, mortalising any
return values if necessary.

This downgrading and upgrading by pp_wrap()/xs_wrap() and
runops_wrap() allows handling of multiple nesting of when, for
example, perl calls pp_entersub(), which calls XS code, which calls
call_sv(), which calls a runops loop, which calls pp_entersub(), which
calls XS code, and so on.

For si_stack_nonrc_base, this index value marks the lowest position on
the argument stack which is not reference-counted. The special (and
normal) value of 0 indicates that *all* items on the stack are
reference-counted.

The new function rpp_obliterate_stack_to() is a bit like
rpp_popfree_to(), except that it can handle stacks in all three of the
states listed above. It's intended to be used when dying, throwing
exceptions or exiting, since the stack could be in any state when that
happens.

Note that as of this commit, PERL_XXX_TMP_NORC is still defined, which
means that even in the presence of AvREAL(PL_curstack) etc, the stack
isn't yet actually reference counted. So with this commit, perl goes
through all the motions, (calling wrappers like runops_wrap()
etc), but skips actually manipulating any reference counts. There will
be a few more commits, fixing up a few more things, before
PERL_XXX_TMP_NORC will be removed.

8 months agoallow argument stack to be AvREAL()
David Mitchell [Thu, 29 Dec 2022 16:11:52 +0000 (16:11 +0000)]
allow argument stack to be AvREAL()

Add a _flags() variant of new_stackinfo() which indicates whether the
new stack AV should be created real or not.

Modify the new push_stackinfo() function to have a similar flag.

Then make the backcompat macros like PUSHSTACKi() still push a non-real
stack, while functions which have been updated to use the new
push_stackinfo() etc will be able get a real AV. The next commit makes
use of that.

This means that existing code (core and XS) which hasn't been updated to
the new ref-counted stack regime can do stuff like:

    PUSHSTACKi(FOO);
    PUSHMARK(sp)
    XPUSHs(sv);
    call_sv();

where call_sv() (or rather, the runops loop it invokes) will be able to
determine that it's been called from a non-RC environment and that the
args on the stack aren't reference-counted.

The next commit will update the runops loops etc to do exactly that.

8 months agoadd switch_argstack(), push/pop_stackinfo() fns
David Mitchell [Tue, 13 Dec 2022 11:04:40 +0000 (11:04 +0000)]
add switch_argstack(), push/pop_stackinfo() fns

These new inline functions are supposed to be near-identical
replacements for these macros:

    PUSHSTACKi(type)     push_stackinfo(type)
    POPSTACK()           pop_stackinfo()
    SWITCHSTACK(from,to) switch_argstack(to) // assumes (from == PL_curstack)

except that they don't require dSP to be in scope (they operate on
PL_stack_sp rather than sp) and their names more clearly specify what
sort of stack they manipulate.

The macros are now thin wrappers around the functions. I've kept most of
their uses in core for now as they are still used in places with dSP
present.

8 months agomake @_ AvREAL() on RC-stack
David Mitchell [Mon, 23 Jan 2023 13:49:05 +0000 (13:49 +0000)]
make @_ AvREAL() on RC-stack

Traditionally, the @_ AV has been marked as AvREAL_off(), but AvREIFY_on().

This commit changes it so that on PERL_RC_STACK builds, @_ is AvREAL().
This will mean that when the stack is ref-counted, the stack frame can
be directly moved to @_ while maintaining the correct ref count for each
argument (in the same way that !AvREAL() worked well with a
non-ref-counted stack).

Note that the stack will not actually be reference-counted for a few
more commits yet. In the meantime, this commit allows for that by
bumping up the reference count of SVs being transferred from the stack
to @_. This extra step will soon be skipped.

8 months agomake shift(@a) leave old pointer
David Mitchell [Sat, 10 Dec 2022 12:34:59 +0000 (12:34 +0000)]
make shift(@a) leave old pointer

Generally shifting is done by adjusting the start position of the
array, so that AvALLOC() and AvARRAY() no longer align. Previously if
the array was AvREAL(), perl NULL-ed out the old pointer at the same
time, i.e. doing the equivalent of AvARRAY(av)[-1] = NULL.

This commit changes it so that on PERL_RC_STACK builds, perl instead
keeps the old pointer there on AvREAL() arrays too, even if it now
points to a freed SV; and instead makes av_clear() and av_unshift()
responsible for NULL-ing out the slot only when actually reclaiming any
unused slots between AvALLOC() and AvARRAY().

The reason for this is because of the mechanism whereby @DB::args is
sometimes populated by caller(), as used by Carp.pm to display function
arguments in stack traces etc. For the common idiom of

    sub f {
        my $self = shift;
        ....;
    }

then previously, since @_ wasn't AvREAL(), the old pointer in @_ to
argument 0 was kept around and thus the hidden pointer value was still
available for caller() to add to @DB::args.

But since the next commit will change @_ to be AvREAL(), this will no
longer work.  Thus to keep the ability to debug stack traces etc (via
the awful @DB::args hack), we make shift keep the pointer even for the
AvREAL() case.

8 months agomake RC-stack-aware: class.c: pp_methstart etc
David Mitchell [Sun, 30 Jul 2023 22:01:55 +0000 (23:01 +0100)]
make RC-stack-aware: class.c: pp_methstart etc