Skip to content

Commit 02a9756

Browse files
committed
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".
1 parent d2ccb40 commit 02a9756

File tree

8 files changed

+43
-23
lines changed

8 files changed

+43
-23
lines changed

embed.fnc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,6 +2758,7 @@ APTdp |char * |rninstr |NN const char *big \
27582758
|NN const char *lend
27592759
p |void |rpeep |NULLOK OP *o
27602760
Adipx |void |rpp_extend |SSize_t n
2761+
Adipx |void |rpp_invoke_xs |NN CV *cv
27612762
Adipx |bool |rpp_is_lone |NN SV *sv
27622763
Cpx |void |rpp_obliterate_stack_to \
27632764
|I32 ix

embed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@
538538
# define require_pv(a) Perl_require_pv(aTHX_ a)
539539
# define rninstr Perl_rninstr
540540
# define rpp_extend(a) Perl_rpp_extend(aTHX_ a)
541+
# define rpp_invoke_xs(a) Perl_rpp_invoke_xs(aTHX_ a)
541542
# define rpp_is_lone(a) Perl_rpp_is_lone(aTHX_ a)
542543
# define rpp_obliterate_stack_to(a) Perl_rpp_obliterate_stack_to(aTHX_ a)
543544
# define rpp_pop_1_norc() Perl_rpp_pop_1_norc(aTHX)

inline.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,31 @@ Perl_rpp_is_lone(pTHX_ SV *sv)
766766
}
767767

768768

769+
/*
770+
=for apidoc rpp_invoke_xs
771+
772+
Call the XS function associated with C<cv>. Wraps the call if necessary to
773+
handle XS functions which are not aware of reference-counted stacks.
774+
775+
=cut
776+
*/
777+
778+
779+
PERL_STATIC_INLINE void
780+
Perl_rpp_invoke_xs(pTHX_ CV *cv)
781+
{
782+
PERL_ARGS_ASSERT_RPP_INVOKE_XS;
783+
784+
#ifdef PERL_RC_STACK
785+
Perl_xs_wrap(aTHX_ CvXSUB(cv), cv);
786+
#else
787+
CvXSUB(cv)(aTHX_ cv);
788+
#endif
789+
}
790+
791+
792+
793+
769794
/* ----------------------------- regexp.h ----------------------------- */
770795

771796
/* PVLVs need to act as a superset of all scalar types - they are basically

pod/perlguts.pod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4628,8 +4628,8 @@ the stack as:
46284628

46294629
... X+ Y+
46304630

4631-
In places like pp_entersub(), a similar wrapping (via the function
4632-
xs_wrap()) is done when calling XS subs.
4631+
In places like pp_entersub(), a similar wrapping (via the functions
4632+
rpp_invoke_xs() and then xs_wrap()) is done when calling XS subs.
46334633

46344634
When C<nlists> is positive, a similar action takes place, except that the
46354635
mark stack is examined (and adjusted) in order to determine the number of
@@ -4762,6 +4762,8 @@ in summary:
47624762
rpp_is_lone(sv) SvTEMP(sv) && SvREFCNT(sv) == 1
47634763
rpp_stack_is_rc() no equivalent
47644764

4765+
rpp_invoke_xs(cv) CvXSUB(cv)(aTHX_ cv);
4766+
47654767
(no replacement) dATARGET // just write the macro body in full
47664768

47674769
Other new C and perl functions related to reference-counted stacks are:
@@ -4868,6 +4870,9 @@ with rpp_try_AMAGIC_1() and _2() inline functions, which now rely on the
48684870
calling PP function to choose whether to return immediately rather than
48694871
the return being hidden away in the macro.
48704872

4873+
The rpp_invoke_xs() function calls the XS function associated with the CV,
4874+
but may do so via a wrapper function to adjust the stack as necessary.
4875+
48714876
In the spirit of hiding away less in macros, C<dATARGET> hasn't been given
48724877
a replacement; where its effect is needed, it is now written out in full;
48734878
see pp_add() for an example.

pp_ctl.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,12 +2381,7 @@ PP(pp_dbstate)
23812381
#endif
23822382
SAVETMPS;
23832383
PUSHMARK(PL_stack_sp);
2384-
#ifdef PERL_RC_STACK
2385-
Perl_xs_wrap(aTHX_ CvXSUB(cv), cv);
2386-
#else
2387-
CvXSUB(cv)(aTHX_ cv);
2388-
#endif
2389-
2384+
rpp_invoke_xs(cv);
23902385
FREETMPS;
23912386
LEAVE;
23922387
return NORMAL;
@@ -3361,11 +3356,7 @@ PP(pp_goto)
33613356

33623357
/* Push a mark for the start of arglist */
33633358
PUSHMARK(mark);
3364-
#ifdef PERL_RC_STACK
3365-
Perl_xs_wrap(aTHX_ CvXSUB(cv), cv);
3366-
#else
3367-
(void)(*CvXSUB(cv))(aTHX_ cv);
3368-
#endif
3359+
rpp_invoke_xs(cv);
33693360
LEAVE;
33703361
goto finish;
33713362
}

pp_hot.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5822,11 +5822,7 @@ PP(pp_entersub)
58225822
/* CvXSUB(cv) must not be NULL because newXS() refuses NULL xsub address */
58235823
assert(CvXSUB(cv));
58245824

5825-
#ifdef PERL_RC_STACK
5826-
Perl_xs_wrap(aTHX_ CvXSUB(cv), cv);
5827-
#else
5828-
CvXSUB(cv)(aTHX_ cv);
5829-
#endif
5825+
rpp_invoke_xs(cv);
58305826

58315827
#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY
58325828
/* This duplicates the check done in runops_debug(), but provides more

pp_sort.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,11 +1290,7 @@ S_sortcv_xsub(pTHX_ SV *const a, SV *const b)
12901290
PUSHMARK(PL_stack_sp);
12911291
rpp_xpush_2(a, b);
12921292

1293-
#ifdef PERL_RC_STACK
1294-
Perl_xs_wrap(aTHX_ CvXSUB(cv), cv);
1295-
#else
1296-
(void)(*CvXSUB(cv))(aTHX_ cv);
1297-
#endif
1293+
rpp_invoke_xs(cv);
12981294

12991295
/* entry zero of a stack is always PL_sv_undef, which
13001296
* simplifies converting a '()' return into undef in scalar context */

proto.h

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)