Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: d59748b07250d679bbf8dedb90d978d9c1f287a2
      
https://github.com/Perl/perl5/commit/d59748b07250d679bbf8dedb90d978d9c1f287a2
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c
    M t/op/svleak.t

  Log Message:
  -----------
  fix leaks in new ${^HOOK}{require__*} facility

In the initial implementation, a few temporary SVs ended up with a ref
count one too high.


  Commit: 9b74bd3f22224f1d2a2e47e25ef61687cbc3e5e4
      
https://github.com/Perl/perl5/commit/9b74bd3f22224f1d2a2e47e25ef61687cbc3e5e4
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M perl.c
    M perl.h

  Log Message:
  -----------
  add PERL_RC_STACK define (not yet defined)

This macro turns on stack reference counting.
Add the macro, but commented out for now.

In addition, temporarily define and enable PERL_XXX_TMP_NORC.

This is a temporary transition measure: even in the presence of
PERL_RC_STACK, do not actually modify reference counts yet. So
PERL_RC_STACK will still define all the new static functions and code
behaviour, except for the bits that actually modify reference counts in
ways that assume the stack is reference counted. It allows this branch
to have many commits which incrementally deal with adding support for
PERL_RC_STACK, with each individual commit still working while half of
the core is still not yet "ref count aware".


  Commit: c667b0edd77d8680114ca249cf218b900572c019
      
https://github.com/Perl/perl5/commit/c667b0edd77d8680114ca249cf218b900572c019
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M lib/Internals.pod
    M universal.c

  Log Message:
  -----------
  add Internals::stack_refcounted()

This indicates whether perl has been built with PERL_RC_STACK.
For now this should only be used by core; It's not yet decided whether
CPAN modules have a use case too.


  Commit: 7940a0e70fa7645355cf910fa4d44e5453ca8734
      
https://github.com/Perl/perl5/commit/7940a0e70fa7645355cf910fa4d44e5453ca8734
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M ext/Devel-Peek/t/Peek.t

  Log Message:
  -----------
  ext/Devel-Peek/t/Peek.t: fixup top refcount

There are a few 'expected' Dump() output patterns which expect the
refcount of the top-most SV in the tree to be fixed number like

    REFCNT = 1

Change all those occurrences to

    REFCNT = \d+

or similar, since a reference-counted stack will cause higher values


  Commit: 3da065cacaf6028961d92445d6a5fc5e6e6877cc
      
https://github.com/Perl/perl5/commit/3da065cacaf6028961d92445d6a5fc5e6e6877cc
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c
    M scope.c

  Log Message:
  -----------
  pp_dbstate: skip SAVESTACK_POS()

On PERL_RC_STACK builds, skip the call to SAVESTACK_POS().
I suspect that saving the stack position is no longer
required. It was added in 5.001 by:

    NETaa13155: &DB::DB left trash on the stack.
    From: Thomas Koenig
    Files patched: lib/perl5db.pl pp_ctl.c
     The call by pp_dbstate() to &DB::DB left trash on the
     stack.  It now calls DB in list context, and DB returns
     ().

but the details of what bug it fixed are long lost to history.
SAVESTACK_POS() doesn't work well with stacks which may be split into
partly reference-counted and partly not halves, so skip it and hope it
doesn't cause any problems.

Also, assert that SAVEt_STACK_POS isn't used anywhere any more.


  Commit: 1936a1b0f76779b20892e733dd7180ca9e12a804
      
https://github.com/Perl/perl5/commit/1936a1b0f76779b20892e733dd7180ca9e12a804
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c

  Log Message:
  -----------
  pp_mapwhile(): null out holes in stack

>From time to time, pp_mapwhile() shifts up any remaining args on the
stack, in order to leave enough space to add the current results to any
accumulated results. This leaves a hole in the stack, which might not be
fully filled until the last iteration. As well as making the output of
perl -Ds confusing, any garbage left in the hole will double-count
towards the reference count of each SV once the stack becomes
reference-counted.

So fill the newly-created hole in the stack with NULL pointers.


  Commit: 765f7ac25b22bb53466e64b1019325d714d4b525
      
https://github.com/Perl/perl5/commit/765f7ac25b22bb53466e64b1019325d714d4b525
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M av.c
    M embed.fnc
    M embed.h
    M inline.h
    M proto.h

  Log Message:
  -----------
  Add av_remove_offset() core-only function

This function abstracts away removing any AvARRAY(av) - AvALLOC(av)
offset from an array (previously added by av_shift()).

Also use Zero() rather than a loop to NULL out any elements in the
offset area.


  Commit: ea8805edf6d02c8dfd281ff4b9a2f60f6b2aa925
      
https://github.com/Perl/perl5/commit/ea8805edf6d02c8dfd281ff4b9a2f60f6b2aa925
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M embed.fnc
    M embed.h
    M op.c
    M perl.c
    M pp_ctl.c
    M proto.h

  Log Message:
  -----------
  create_eval_scope(): parameterise the stack pos

Rather than always using PL_stack_sp to pass to cx_pushblock(),
allow the caller of create_eval_scope() to specify what stack position
is to be saved.

This will be used shortly to fix a bug.


  Commit: d9777c810433c84015dbbea821420d6066af4b74
      
https://github.com/Perl/perl5/commit/d9777c810433c84015dbbea821420d6066af4b74
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M perl.c

  Log Message:
  -----------
  Perl_call_sv(G_EVAL): set oldsp correctly

call_sv(cv, G_EVAL) pushes a CXt_EVAL context, fakes up an entersub op,
then runs it, letting entersub consume the arguments pushed onto the current
stack frame by call_sv()'s caller.

So the C-level

    PUSHMARK():
    PUSHs(arg1);
    ...
    PUSHs(argN);
    call_sv(cv, G_EVAL);

is about equivalent to the perl-level:

    eval { cv($arg1,..$argN) }

Except that in the latter, when the CXt_EVAL is pushed, it is done
*before* any of the arguments have been pushed, so the eval context's
blk_oldsp points to just before the arguments. Conversely in the case of
call_sv(), blk_oldsp gets set to just *after* the arguments.

During an exception, the context stack gets unwound until the CXt_EVAL
is reached, then PL_stack_sp is restored to the blk_oldsp value.

The difference currently makes no real functional difference, as
call_sv() resets PL_stack_sp immediately after an exception anyway, so
the bad just-restored value is discarded. But it does mean that
PL_stack_sp briefly points to junk on the stack. When the stack becomes
reference-counted, this will start to become important. So fix now.

This commit changes it so that call_sv()'s blk_oldsp gets set to just
before the arguments too. It also asserts that the stack was cleared
back to blk_oldsp.


  Commit: 8e4be094cb869a7a90b048d2e64f345dddc7ba3c
      
https://github.com/Perl/perl5/commit/8e4be094cb869a7a90b048d2e64f345dddc7ba3c
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M inline.h

  Log Message:
  -----------
  assert that cxstack[i].oldsp are increasing

The saved stack positions

    cxstack[0].oldsp
    cxstack[1].oldsp
    cxstack[2].oldsp
    ...

effectively divide the argument stack into a series of stack frames.
This unravels if an earlier oldsp is actually greater than a later one.
It didn't really matter before, but for a reference-counted stack it
becomes a mess when trying to unwind the stack after an exception.  So
assert that oldsp never decreases.

This assert found one failure in core, which was fixed by the previous
commit.


  Commit: 6c80d55020349eda8446f8d154f6c65401fb4808
      
https://github.com/Perl/perl5/commit/6c80d55020349eda8446f8d154f6c65401fb4808
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M autodoc.pl
    M embed.fnc
    M embed.h
    M inline.h
    M proto.h

  Log Message:
  -----------
  add rpp_foo() refcounted-stack manipulation fns

The various new inline functions like rpp_push_1() are intended to be
(approximate) replacements for the traditional PUSHs(), POPs() etc
macros, except that when compiled under PERL_RC_STACK, they understand
a reference-counted stack.

Except currently they assume the stack is still not reference-counted in
the presence of PERL_XXX_TMP_NORC. This will be turned off in a few
commits' time.


  Commit: 4db97938f197f3b1f7a27ed6857211a64c776890
      
https://github.com/Perl/perl5/commit/4db97938f197f3b1f7a27ed6857211a64c776890
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_hot.c

  Log Message:
  -----------
  use new rpp_is_lone() function

This inline function checks for whether an SV is only referenced
from the stack or temps stack. (Well, it only checks TEMPs currently, but
will shortly handle a ref-counted stack too). In particular it tests for:

    SvTEMP(sv) && && SvREFCNT(sv) == 1

This commit uses it in various places to replace where the conditions
are currently written out in full. This will allow those places to still
work correctly when the stack becomes reference-counted.


  Commit: 91db8a47f9d2eed918a313748f8321d8c45329ad
      
https://github.com/Perl/perl5/commit/91db8a47f9d2eed918a313748f8321d8c45329ad
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M doop.c
    M embed.fnc
    M makedef.pl
    M pp.c
    M pp.h
    M pp_ctl.c
    M pp_hot.c
    M pp_pack.c
    M pp_sys.c
    M proto.h

  Log Message:
  -----------
  wrap normal non-RC-stack-aware pp functions

In the presence of PERL_RC_STACK, wrap most pp functions with a function
that calls the real pp function with a (non-reference-counted) copy of
the stack arguments.  On return, the wrapper bumps up the reference
count of the returned list and, as appropriate, shifts them down the
stack.

This allows a pp function which is not aware of a reference-counted
stack to be called in a reference-counted stack environment.

About 250 such functions are wrappable; the remaining 50 or so need
individual handling and will be dealt with in the following few commits.

This is a temporary band-aid which slows down calls to pp() functions.
It is expected that over time these functions will be unwrapped and
updated to to understand a reference-counted stack. But by temporarily
wrapping them now, it allows perl to be (experimentally) shifted over to
a reference-counted stack without having to review and modify all 30K
lines of pp code first.

(Except currently, the wrapper assumes the stack is still not
reference-counted in the presence of PERL_XXX_TMP_NORC. This will be
turned off in a few commits' time.)

Note also that pp_wrap() is not yet complete. It simulates wrapping by
making a copy of the args on entry to the wrapped function and shifting
any returned values back down. But as well as being temporarily
inhibited from actually modifying reference counts by PERL_XXX_TMP_NORC,
there are extra considerations which will be taken account of by the
"Allow stacks to be reference-counted" commit coming later.


  Commit: cf1d0cf9de66820fc1ccf08cb02868583582799c
      
https://github.com/Perl/perl5/commit/cf1d0cf9de66820fc1ccf08cb02868583582799c
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_hot.c

  Log Message:
  -----------
  pp_method*: fixup wrapping

The various method ops are sometimes naughty and substitute a different
object at the base of the current stack frame. This is "below"
the area of the stack normally processed by pp_wrap(), so the reference
count adjusting must be done manually.


  Commit: 027b8dbe9a6ccd87b94377c4d91f4de26f8cf330
      
https://github.com/Perl/perl5/commit/027b8dbe9a6ccd87b94377c4d91f4de26f8cf330
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c

  Log Message:
  -----------
  make RC-stack-aware: regcomp

Update pp_regcomp() to handle a reference-counted stack environment in
the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.


  Commit: d320f2deafe66c6ee2c865b9bb18e763665d0725
      
https://github.com/Perl/perl5/commit/d320f2deafe66c6ee2c865b9bb18e763665d0725
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M embed.fnc
    M makedef.pl
    M pp_hot.c
    M proto.h

  Log Message:
  -----------
  make RC-stack-aware: entersub

Update pp_entersub() to handle a reference-counted stack environment in
the presence of PERL_RC_STACK.

As well as the expected changes to pp_entersub(), this commit also adds
a function, xs_wrap(),  which is similar in concept to pp_wrap(), but
which makes a non-reference-counted copy of the arguments on the stack
before calling any XS function which isn't RC-stack-aware yet (which is
currently all of them).

xs_wrap() will soon be used by pp_goto() too.

In the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.

Note also that xs_wrap() is not yet complete. It simulates wrapping by
making a copy of the args on entry to the wrapped function and shifting
any returned values back down. But as well as being temporarily
inhibited from actually modifying reference counts by PERL_XXX_TMP_NORC,
there are extra considerations which will be taken account of by the
"Allow stacks to be reference-counted" commit coming later.


  Commit: 40a56abf75d068063b16737e9acc3cea519ba57f
      
https://github.com/Perl/perl5/commit/40a56abf75d068063b16737e9acc3cea519ba57f
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c
    M pp_hot.c

  Log Message:
  -----------
  make RC-stack-aware: db/nextstate, unstack

Update pp_dbstate(), pp_nextstate() and pp_unstack() to handle a
reference-counted stack environment in the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.


  Commit: 5a00f5987ca1150e26214504c6070608c85f940f
      
https://github.com/Perl/perl5/commit/5a00f5987ca1150e26214504c6070608c85f940f
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c
    M pp_hot.c
    M t/op/grep.t

  Log Message:
  -----------
  make RC-stack-aware: map and grep

Update pp_grepstart(), pp_grepwhile() and pp_mapwhile() to handle a
reference-counted stack environment in the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.

Also add some tests to op/grep.t to check for stuff being freed at an
appropriate time  (they weren't being at one iteration of this commit).


  Commit: ddfae2c6d59ba7a888631d68a12427ad1c467c14
      
https://github.com/Perl/perl5/commit/ddfae2c6d59ba7a888631d68a12427ad1c467c14
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c

  Log Message:
  -----------
  make RC-stack-aware: enteriter, leaveloop

Update pp_enteriter() and pp_leveloop() to handle a reference-counted
stack environment in the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.


  Commit: ac975285ebfa9cb8085d920a6cd9258ec2cdb269
      
https://github.com/Perl/perl5/commit/ac975285ebfa9cb8085d920a6cd9258ec2cdb269
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c
    M pp_hot.c

  Log Message:
  -----------
  make RC-stack-aware: pp_leavefoo()

Update some pp_leavefoo() functions to handle a reference-counted stack
environment in the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.


  Commit: 3c9ddd0abe1e9c5c595e63b65cedd0f4b9450416
      
https://github.com/Perl/perl5/commit/3c9ddd0abe1e9c5c595e63b65cedd0f4b9450416
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c

  Log Message:
  -----------
  make RC-stack-aware: last

Update pp_last() to handle a reference-counted stack environment in
the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.


  Commit: 14fb783a0ae9ae409f2293e303a1c01a4c7f9413
      
https://github.com/Perl/perl5/commit/14fb783a0ae9ae409f2293e303a1c01a4c7f9413
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c

  Log Message:
  -----------
  make RC-stack-aware: goto

Update pp_goto() to handle a reference-counted stack environment in
the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.


  Commit: 5abffa7ff8a6cee3e13e061f8332cf567427a21c
      
https://github.com/Perl/perl5/commit/5abffa7ff8a6cee3e13e061f8332cf567427a21c
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c

  Log Message:
  -----------
  make RC-stack-aware: require,eval

Update pp_entereval() et al to handle a reference-counted stack
environment in the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.


  Commit: d0b0195f544e5c2769b5a325c635a1eaec4ee765
      
https://github.com/Perl/perl5/commit/d0b0195f544e5c2769b5a325c635a1eaec4ee765
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c

  Log Message:
  -----------
  make RC-stack-aware: enter/leavegiven etc

Update pp_entergiven() et al to handle a reference-counted stack
environment in the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.


  Commit: 0b31aa7d181182ad24da460f8edd88ade2ed7e54
      
https://github.com/Perl/perl5/commit/0b31aa7d181182ad24da460f8edd88ade2ed7e54
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_sys.c

  Log Message:
  -----------
  make RC-stack-aware: enter/leavewrite

Update pp_enterwrite() and pp_leavewrite() to handle a reference-counted
stack environment in the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.


  Commit: 49799453fae6c5be810de9368d2349d7c008bf99
      
https://github.com/Perl/perl5/commit/49799453fae6c5be810de9368d2349d7c008bf99
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_sort.c
    M t/op/sort.t

  Log Message:
  -----------
  make RC-stack-aware: pp_sort()

Update pp_sort() to handle a reference-counted stack environment in
the presence of PERL_RC_STACK.

(But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.)

In addition to replacing all the POPs type stuff with rpp_foo() inline
function calls, three slight functional changes were done to make this
work.

1) The stack entry pointing to the SV containing the sort function name
   is now NULLed out rather than being left on the stack, just after
   being freed. It is usually overwritten later on in the process.
2) For an in-place sort (@a = sort @a), the AV is now left on the stack
   so that it isn't prematurely freed. This is okay, because...
3) Also for an in-place sort, after the results are stored in @a, the
   stack frame is cleared. This is safe because the optimisation is
   only ever done in void context. Previously the stack would be be
   cleared by the following nextstate op or similar anyway.


  Commit: bdd09b4238cb0dba1cda71a5dc109af86ffb917d
      
https://github.com/Perl/perl5/commit/bdd09b4238cb0dba1cda71a5dc109af86ffb917d
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_sort.c

  Log Message:
  -----------
  make RC-stack-aware: sort cmp function invokers

Update S_sortcv() etc to handle a reference-counted stack environment in
the presence of PERL_RC_STACK.

These three static functions are used by pp_sort() to invoke a suitable
comparison subroutine.

(But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.)


  Commit: f7c1bd60a91febf3e204512491bb05112b4e4495
      
https://github.com/Perl/perl5/commit/f7c1bd60a91febf3e204512491bb05112b4e4495
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M doio.c
    M pp_sys.c

  Log Message:
  -----------
  make RC-stack-aware: stat and filetest ops

Update the pp functions which do stat and filetest operations to handle
a reference-counted stack environment in the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.


  Commit: b32febe36381fd58fc5835504188e21fcfaf91d1
      
https://github.com/Perl/perl5/commit/b32febe36381fd58fc5835504188e21fcfaf91d1
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M inline.h
    M pp.c

  Log Message:
  -----------
  make RC-stack-aware: misc pp() functions

Update the remaining miscellaneous pp() functions to handle a
reference-counted stack environment in the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.


  Commit: 5ff0c5f0e40237273b8719ae8bbfab04b2b9805a
      
https://github.com/Perl/perl5/commit/5ff0c5f0e40237273b8719ae8bbfab04b2b9805a
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M perl.c

  Log Message:
  -----------
  make RC-stack-aware: call_sv() and similar

Update the functions which directly or indirectly call a CV, to handle
a reference-counted stack environment.

Note that call_sv(), eval_pv() etc are slightly unusual in that they can
be called from either a reference-counted or non-RC stack environment,
so must be able to handle either case. This is done mostly by relying on
CALLRUNOPS() to fix things up, but for anything pushed/pulled around
that, by checking rpp_stack_is_rc(): which currently always returns
false, but once ref-counting is enabled in a few commits' time, may
start returning true.


  Commit: 00fc1d567b0fefdc90e659aae2c44c33cbeed7b6
      
https://github.com/Perl/perl5/commit/00fc1d567b0fefdc90e659aae2c44c33cbeed7b6
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M perl.c

  Log Message:
  -----------
  make RC-stack-aware: eval_sv()

Similar to the previous commit which fixed up call_sv() and similar,
the commit updates eval_sv() to handle a reference-counted stack
environment.

Note that these functions are slightly unusual in that they can
be called from either a reference-counted or non-RC stack environment,
so must be able to handle either case. This is done mostly by relying on
CALLRUNOPS() to fix things up, but for anything pushed/pulled around
that, by checking rpp_stack_is_rc(): which currently always returns
false, but once ref-counting is enabled in a few commits' time, may
start returning true.


  Commit: 026a3845c25e9e0d5aca9ce5cc76f51cde381920
      
https://github.com/Perl/perl5/commit/026a3845c25e9e0d5aca9ce5cc76f51cde381920
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c

  Log Message:
  -----------
  make RC-stack-aware: defer

The defer keyword saves the address of an optree, which is then
run during leave_scope(). Since that can happen in unpredictable
places (e.g. during a croak), we won't know until runtime where the
stack is currently reference-counted. So handle both cases.


  Commit: 2fe263a83a681fe0487335b281f1f550728d8342
      
https://github.com/Perl/perl5/commit/2fe263a83a681fe0487335b281f1f550728d8342
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_hot.c

  Log Message:
  -----------
  make RC-stack-aware: unwrap pp_add()

Remove the temporary wrapper from pp_add() and update it to directly
work in a refcounted-stack environment.

This is mainly a proof of concept to check that all the new rpp_foo()
inline functions and macros are suitable for working with a typical
binary operator.


  Commit: 205fcd8410d3723b7bdb905ddd3e0e5deb0248ba
      
https://github.com/Perl/perl5/commit/205fcd8410d3723b7bdb905ddd3e0e5deb0248ba
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp.c

  Log Message:
  -----------
  make RC-stack-aware: unwrap pp_not()

Remove the temporary wrapper from pp_not() and update it to directly
work in a refcounted-stack environment.

This is mainly a proof of concept to check that rpp_tryAMAGICun_MG() and
its underlying Perl_try_amagic_un() work ok.


  Commit: d4138ab14e7bdae2da8851259b059ea6fc8ee217
      
https://github.com/Perl/perl5/commit/d4138ab14e7bdae2da8851259b059ea6fc8ee217
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M op.c

  Log Message:
  -----------
  make RC-stack-aware: S_fold_constants()

The folded SV it pops off the stack should be treated as
reference counted.


  Commit: f62a23a635e181bf56af87479beace1d0ef33165
      
https://github.com/Perl/perl5/commit/f62a23a635e181bf56af87479beace1d0ef33165
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M ext/Devel-Peek/Peek.pm
    M ext/Devel-Peek/Peek.xs

  Log Message:
  -----------
  make RC-stack-aware: Devel::Peek::Dump()

This function is implemented as a custom op rather than as a function
call, so it wasn't getting wrapped for reference-count purposes by
either pp_wrap() nor xs_wrap().

This commit makes it directly handle a reference-counted stack.

This was a particularly confusing one, as a failing test in t/op/eval.t
was reduced to

    use Devel::Peek;
    Dump($@);
    eval { die "boo\n"; };
    Dump($@);

which showed the ref count of $@ increasing after the eval {}. But it
was actually Dump(), not eval{} which was messing with the ref count.


  Commit: eaadb066beb5cd8f245e5d5509aa8446df083b82
      
https://github.com/Perl/perl5/commit/eaadb066beb5cd8f245e5d5509aa8446df083b82
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M sv.c

  Log Message:
  -----------
  make RC-stack-aware: perl_clone()

It has some code that calls out to PACKAGE::CLONE(). Depending on how
the interpreter is being cloned, the code which assembles the args on
the stack for the CLONE() call may be operating on either a
reference-counted stack, or a non-RC one. So handle both cases


  Commit: 58414b7d1aec57e7211cf6d70f89c7610c0f7605
      
https://github.com/Perl/perl5/commit/58414b7d1aec57e7211cf6d70f89c7610c0f7605
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M gv.c

  Log Message:
  -----------
  make RC-stack-aware: Perl_try_amagic_un() & _bin()

Note that these two functions may be called both from PP functions aware
of a reference-counted stack and from wrapped (non-aware) functions,
hence the RC manipulation is runtime conditional.


  Commit: 09f6b93b4a71ec9bdb11f4608a0ce19feebef084
      
https://github.com/Perl/perl5/commit/09f6b93b4a71ec9bdb11f4608a0ce19feebef084
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M dist/threads/threads.xs

  Log Message:
  -----------
  make RC-stack-aware: threads.xs

S_ithread_run() starts running a new top-level perl interpreter, which
will have a ref-counted stack. So treat the stack as ref-counted.


  Commit: b44950fdad89c3ce3ebac0f60cf8be61a14cc712
      
https://github.com/Perl/perl5/commit/b44950fdad89c3ce3ebac0f60cf8be61a14cc712
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M t/cmd/for.t

  Log Message:
  -----------
  make RC-stack-aware: t/cmd/for.t

A test that expects to fail on a non reference-counted stack should no
longer do so if the stack is fully reference-counted


  Commit: 2cbade416bb3bddded5f599fd1cb59811471c46d
      
https://github.com/Perl/perl5/commit/2cbade416bb3bddded5f599fd1cb59811471c46d
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M op.c

  Log Message:
  -----------
  make RC-stack-aware: invoking DB::postponed()

Various places in core call DB::postponed(). This all happens in
places where the stack will be reference-counted, so fix the callers.


  Commit: ab041097fca4cc892503e7e4e894669a348621d2
      
https://github.com/Perl/perl5/commit/ab041097fca4cc892503e7e4e894669a348621d2
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M ext/XS-APItest/APItest.pm
    M ext/XS-APItest/APItest.xs
    M ext/XS-APItest/t/magic.t

  Log Message:
  -----------
  make RC-stack-aware: ext/XS-APItest/

APItest.xs mainly consists of XS functions - which are not aware of a
ref counted stack - but such functions are called via xs_wrap(), so
that's ok.

However, THX_pp_establish_cleanup() is actually a PP function attached
to an op, rather than an XS function - so it doesn't get automatically
wrapped. Update it to handle a reference-counted stack.

Also, use the standard CALLRUNOPS() macro to call a runops loop rather
than invoking directly; the former will allow a wrapper to be inserted.

Finally, parameterise the expected ref count in t/magic.t, as it will
change if the stack is ref counted.


  Commit: 6b845fdb7de5d41126ab6db7b64fa00ed132bee6
      
https://github.com/Perl/perl5/commit/6b845fdb7de5d41126ab6db7b64fa00ed132bee6
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M class.c

  Log Message:
  -----------
  make RC-stack-aware: class.c: pp_methstart etc


  Commit: 4f91780c40ea0d0b50a19c54d0d6d778894e0aba
      
https://github.com/Perl/perl5/commit/4f91780c40ea0d0b50a19c54d0d6d778894e0aba
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M av.c
    M inline.h
    M pp_hot.c

  Log Message:
  -----------
  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.


  Commit: 2c204b7a22984badae6690e397ae754a2b70bdb9
      
https://github.com/Perl/perl5/commit/2c204b7a22984badae6690e397ae754a2b70bdb9
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M cop.h
    M embed.fnc
    M embed.h
    M inline.h
    M pad.c
    M pp_ctl.c
    M pp_hot.c
    M pp_sort.c
    M proto.h
    M t/op/sub.t

  Log Message:
  -----------
  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.


  Commit: d724a264199e78928fd19ddd3168cb4ab4e3ff6d
      
https://github.com/Perl/perl5/commit/d724a264199e78928fd19ddd3168cb4ab4e3ff6d
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M cop.h
    M embed.fnc
    M embed.h
    M inline.h
    M pp.h
    M pp_sort.c
    M proto.h

  Log Message:
  -----------
  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.


  Commit: 026c6b9cdb9ce335714a4d3368c0ff3fafa5387a
      
https://github.com/Perl/perl5/commit/026c6b9cdb9ce335714a4d3368c0ff3fafa5387a
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M cop.h
    M embed.fnc
    M embed.h
    M inline.h
    M perl.c
    M pp_sort.c
    M proto.h
    M scope.c

  Log Message:
  -----------
  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.


  Commit: ba1af285ef4f9b4a71183b7b4a1ffed410d1a7f5
      
https://github.com/Perl/perl5/commit/ba1af285ef4f9b4a71183b7b4a1ffed410d1a7f5
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M cop.h
    M embed.fnc
    M embed.h
    M inline.h
    M makedef.pl
    M perl.c
    M perl.h
    M pp_ctl.c
    M pp_hot.c
    M pp_pack.c
    M pp_sort.c
    M proto.h
    M run.c
    M scope.c
    M sv.c

  Log Message:
  -----------
  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.


  Commit: 1af84bbbb8a5031d40ed8bbe1b9de45d800ba849
      
https://github.com/Perl/perl5/commit/1af84bbbb8a5031d40ed8bbe1b9de45d800ba849
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c

  Log Message:
  -----------
  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 },
    );


  Commit: 771bb94c0c59166307c0096856765320b17e5d5f
      
https://github.com/Perl/perl5/commit/771bb94c0c59166307c0096856765320b17e5d5f
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M toke.c

  Log Message:
  -----------
  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.


  Commit: 66038c8c288110d80f59681ffb2de45a54d4827c
      
https://github.com/Perl/perl5/commit/66038c8c288110d80f59681ffb2de45a54d4827c
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M inline.h

  Log Message:
  -----------
  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


  Commit: f8fc6b095f80ea9931fba9eada56510a5189167f
      
https://github.com/Perl/perl5/commit/f8fc6b095f80ea9931fba9eada56510a5189167f
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M deb.c
    M embed.fnc
    M embed.h
    M proto.h

  Log Message:
  -----------
  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.


  Commit: 093e94b2e09673b2fc3aca4f864e66bdd66c5516
      
https://github.com/Perl/perl5/commit/093e94b2e09673b2fc3aca4f864e66bdd66c5516
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M perl.h

  Log Message:
  -----------
  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.


  Commit: 02e17f822a8073f2e38144146be8e6faf0e4671e
      
https://github.com/Perl/perl5/commit/02e17f822a8073f2e38144146be8e6faf0e4671e
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M inline.h
    M pp.h

  Log Message:
  -----------
  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.


  Commit: e9cb29cf526e6df4d77587dce2713ef6640b4330
      
https://github.com/Perl/perl5/commit/e9cb29cf526e6df4d77587dce2713ef6640b4330
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M dump.c

  Log Message:
  -----------
  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.


  Commit: eae22059a5c2197c7ed07a8a08b23bbc100b8aea
      
https://github.com/Perl/perl5/commit/eae22059a5c2197c7ed07a8a08b23bbc100b8aea
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_hot.c

  Log Message:
  -----------
  pp_wrap(), xs_wrap(): extract some common code

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


  Commit: 35f3543b3a60c9b9d47bc5adad937feaba1d0c3b
      
https://github.com/Perl/perl5/commit/35f3543b3a60c9b9d47bc5adad937feaba1d0c3b
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_hot.c

  Log Message:
  -----------
  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.


  Commit: c764d96b6be325a209fe6b63d35931e03794b404
      
https://github.com/Perl/perl5/commit/c764d96b6be325a209fe6b63d35931e03794b404
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M MANIFEST
    M ext/XS-APItest/APItest.xs
    A ext/XS-APItest/t/xsppwrap.t

  Log Message:
  -----------
  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


  Commit: cbcef76ee0c0d03d9ee77d1dbc53fdd62469fdc8
      
https://github.com/Perl/perl5/commit/cbcef76ee0c0d03d9ee77d1dbc53fdd62469fdc8
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M ext/XS-APItest/APItest.xs

  Log Message:
  -----------
  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.


  Commit: 9a5007947b1c3c4b9b2a12e1d689412c65be2e6f
      
https://github.com/Perl/perl5/commit/9a5007947b1c3c4b9b2a12e1d689412c65be2e6f
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M dist/threads/threads.xs
    M ext/XS-APItest/t/magic.t
    M inline.h
    M op.c
    M perl.c
    M perl.h
    M pp_ctl.c
    M pp_hot.c
    M pp_pack.c
    M pp_sort.c
    M run.c
    M t/cmd/for.t
    M universal.c

  Log Message:
  -----------
  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.


  Commit: a40b4738ef7afe79080c7f88d0b6a672f79fd3f8
      
https://github.com/Perl/perl5/commit/a40b4738ef7afe79080c7f88d0b6a672f79fd3f8
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pod/perlguts.pod

  Log Message:
  -----------
  add perlguts section on a reference-counted stack

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


  Commit: dbc9c91513baa428008d05122f046052a2adc647
      
https://github.com/Perl/perl5/commit/dbc9c91513baa428008d05122f046052a2adc647
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c

  Log Message:
  -----------
  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.


  Commit: ce8d75ef6b1fc2ff9f508e94e9855abe7a43a346
      
https://github.com/Perl/perl5/commit/ce8d75ef6b1fc2ff9f508e94e9855abe7a43a346
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M run.c
    M t/op/grep.t

  Log Message:
  -----------
  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.


  Commit: aaf1819a097eba2d6523860249b27e4dbd1ac716
      
https://github.com/Perl/perl5/commit/aaf1819a097eba2d6523860249b27e4dbd1ac716
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c

  Log Message:
  -----------
  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.


  Commit: d2cddbe1df3078717c41d2553f47eac6acad3f75
      
https://github.com/Perl/perl5/commit/d2cddbe1df3078717c41d2553f47eac6acad3f75
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_ctl.c
    M t/op/caller.t

  Log Message:
  -----------
  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.


  Commit: 648ce9b6ebd69de50d86aa933b90aa01c18b1ed4
      
https://github.com/Perl/perl5/commit/648ce9b6ebd69de50d86aa933b90aa01c18b1ed4
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M pp_hot.c
    M t/op/goto.t

  Log Message:
  -----------
  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


  Commit: 0398979cd6ba060efcdedf453ebf36bfe81a0c4b
      
https://github.com/Perl/perl5/commit/0398979cd6ba060efcdedf453ebf36bfe81a0c4b
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M inline.h
    M pod/perlguts.pod
    M pp.h

  Log Message:
  -----------
  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).


  Commit: a61d85e1067e42fbf7f12f686689ee0cd3ce41af
      
https://github.com/Perl/perl5/commit/a61d85e1067e42fbf7f12f686689ee0cd3ce41af
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M MANIFEST
    A t/op/refstack.t

  Log Message:
  -----------
  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


  Commit: 9d5d54aa83ef10ed1005499dacae885d016159d1
      
https://github.com/Perl/perl5/commit/9d5d54aa83ef10ed1005499dacae885d016159d1
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M embed.fnc
    M embed.h
    M inline.h
    M pod/perlguts.pod
    M pp_ctl.c
    M pp_hot.c
    M pp_sort.c
    M proto.h

  Log Message:
  -----------
  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".


  Commit: 8d69e95bc00f05baf1dcce7d6ac157c6dbdd42a4
      
https://github.com/Perl/perl5/commit/8d69e95bc00f05baf1dcce7d6ac157c6dbdd42a4
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M MANIFEST
    M cv.h
    M ext/XS-APItest/APItest.xs
    A ext/XS-APItest/t/rpp_invoke_xs.t
    M inline.h

  Log Message:
  -----------
  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.


  Commit: bd714d32207c46afe7146d7bb4d02667fe48767e
      
https://github.com/Perl/perl5/commit/bd714d32207c46afe7146d7bb4d02667fe48767e
  Author: David Mitchell <da...@iabyn.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M MANIFEST
    M autodoc.pl
    M av.c
    M class.c
    M cop.h
    M cv.h
    M deb.c
    M dist/threads/threads.xs
    M doio.c
    M doop.c
    M dump.c
    M embed.fnc
    M embed.h
    M ext/Devel-Peek/Peek.pm
    M ext/Devel-Peek/Peek.xs
    M ext/Devel-Peek/t/Peek.t
    M ext/XS-APItest/APItest.pm
    M ext/XS-APItest/APItest.xs
    M ext/XS-APItest/t/magic.t
    A ext/XS-APItest/t/rpp_invoke_xs.t
    A ext/XS-APItest/t/xsppwrap.t
    M gv.c
    M inline.h
    M lib/Internals.pod
    M makedef.pl
    M op.c
    M pad.c
    M perl.c
    M perl.h
    M pod/perlguts.pod
    M pp.c
    M pp.h
    M pp_ctl.c
    M pp_hot.c
    M pp_pack.c
    M pp_sort.c
    M pp_sys.c
    M proto.h
    M run.c
    M scope.c
    M sv.c
    M t/cmd/for.t
    M t/op/caller.t
    M t/op/goto.t
    M t/op/grep.t
    A t/op/refstack.t
    M t/op/sort.t
    M t/op/sub.t
    M t/op/svleak.t
    M toke.c
    M universal.c

  Log Message:
  -----------
  [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.


Compare: https://github.com/Perl/perl5/compare/2b2e69d1e79a...bd714d32207c

Reply via email to