Skip to content

Commit

Permalink
64-bit stack: call_sv mark and return value handling
Browse files Browse the repository at this point in the history
call_sv() used I32 for a saved mark and the return value.

The XS::APItest call_sv() wrapper used an I32 index to reposition
the argument list supplied to call_sv().

I haven't created additional tests for call_argv(), call_pv() nor
call_method(), these simply pass the return value on, I don't think
it worth the extra tests.
  • Loading branch information
tonycoz committed Sep 24, 2023
1 parent 7921161 commit ac78ddd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
8 changes: 4 additions & 4 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ CTdpx |U8 * |bytes_from_utf8_loc \
|NULLOK const U8 **first_unconverted
Adpx |U8 * |bytes_to_utf8 |NN const U8 *s \
|NN STRLEN *lenp
AOdp |I32 |call_argv |NN const char *sub_name \
AOdp |SSize_t|call_argv |NN const char *sub_name \
|I32 flags \
|NN char **argv

Expand All @@ -765,13 +765,13 @@ Adp |const PERL_CONTEXT *|caller_cx \
|NULLOK const PERL_CONTEXT **dbcxp
Cp |void |call_list |I32 oldscope \
|NN AV *paramList
AOdp |I32 |call_method |NN const char *methname \
AOdp |SSize_t|call_method |NN const char *methname \
|I32 flags
CTadop |Malloc_t|calloc |MEM_SIZE elements \
|MEM_SIZE size
AOdp |I32 |call_pv |NN const char *sub_name \
AOdp |SSize_t|call_pv |NN const char *sub_name \
|I32 flags
AOdp |I32 |call_sv |NN SV *sv \
AOdp |SSize_t|call_sv |NN SV *sv \
|volatile I32 flags
: Used in several source files
Rp |bool |cando |Mode_t mode \
Expand Down
2 changes: 1 addition & 1 deletion ext/XS-APItest/APItest.xs
Original file line number Diff line number Diff line change
Expand Up @@ -2760,7 +2760,7 @@ call_sv(sv, flags, ...)
SV* sv
I32 flags
PREINIT:
I32 i;
SSize_t i;
PPCODE:
for (i=0; i<items-2; i++)
ST(i) = ST(i+2); /* pop first two args */
Expand Down
12 changes: 6 additions & 6 deletions perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2971,7 +2971,7 @@ Approximate Perl equivalent: C<&{"$sub_name"}(@$argv)>.
=cut
*/

I32
SSize_t
Perl_call_argv(pTHX_ const char *sub_name, I32 flags, char **argv)

/* See G_* flags in cop.h */
Expand Down Expand Up @@ -3005,7 +3005,7 @@ Performs a callback to the specified Perl sub. See L<perlcall>.
=cut
*/

I32
SSize_t
Perl_call_pv(pTHX_ const char *sub_name, I32 flags)
/* name of the subroutine */
/* See G_* flags in cop.h */
Expand All @@ -3024,7 +3024,7 @@ be on the stack. See L<perlcall>.
=cut
*/

I32
SSize_t
Perl_call_method(pTHX_ const char *methname, I32 flags)
/* name of the subroutine */
/* See G_* flags in cop.h */
Expand Down Expand Up @@ -3068,14 +3068,14 @@ See L<perlcall>.
=cut
*/

I32
SSize_t
Perl_call_sv(pTHX_ SV *sv, volatile I32 flags)
/* See G_* flags in cop.h */
{
LOGOP myop; /* fake syntax tree node */
METHOP method_op;
I32 oldmark;
volatile I32 retval = 0;
SSize_t oldmark;
volatile SSize_t retval = 0;
bool oldcatch = CATCH_GET;
int ret;
OP* const oldop = PL_op;
Expand Down
8 changes: 4 additions & 4 deletions proto.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions t/bigmem/stack.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ $Config{ptrsize} >= 8
my @x;
$x[0x8000_0000] = "Hello";

my $arg_count;

my @tests =
(
[ mark => sub
Expand Down Expand Up @@ -181,6 +183,20 @@ my @tests =
}
}
],
[
call_sv_args => sub {
undef $arg_count;
my $ret_count = XS::APItest::call_sv(\&arg_count, G_LIST, x());
is($ret_count, 0, "call_sv with 2G args - arg_count() returns nothing");
is($arg_count, scalar @x, "check call_sv argument handling - argument count");
},
],
[
call_sv_mark => sub {
my $ret_count = ( x(), XS::APItest::call_sv(\&list, G_LIST) )[-1];
is($ret_count, 2, "call_sv with deep stack - returned value count");
},
],
);

# these tests are slow, let someone debug them one at a time
Expand Down Expand Up @@ -228,6 +244,11 @@ sub list {
return shift() ? (1, 2) : (2, 1);
}

sub arg_count {
$arg_count = @_;
();
}

package ScalarTie;

sub TIESCALAR {
Expand Down

0 comments on commit ac78ddd

Please sign in to comment.