summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2023-01-11 23:55:23 +0000
committerYves Orton <demerphq@gmail.com>2023-02-28 20:53:51 +0800
commit2d08227e773ded77863cb5e92f5ef5862ffd287f (patch)
treeca29f79e59027c110713d05cef3016a2598ef8e2 /ext
parentfecade69c526caa9c157a2405486b9089047fc72 (diff)
downloadperl-2d08227e773ded77863cb5e92f5ef5862ffd287f.tar.gz
XS::APItest::test_EXTEND(): fixups
This XS function is for testing the stack-extending EXTEND() macro. This commit fixes two issues. 1) it uses a nested 'sp' variable declaration in addition to the one declared implicitly, which is confusing. Use a separate variable called new_sp instead. This changes the logic slightly, since the EXTEND() macro messes implicitly with sp, including updating it after a realloc. We have to do that manually now with new_sp. 2) The test function NULLs a couple of items near the top of the (potentially just extended) stack. Where the extend size is zero, it could be NULLing out one or two of the passed arguments on the stack. At the moment these values aren't used any more and are discarded on return; but it will get messy once the stack becomes reference-counted, so only NULL addresses if they're above PL_stack_sp.
Diffstat (limited to 'ext')
-rw-r--r--ext/XS-APItest/APItest.xs20
1 files changed, 14 insertions, 6 deletions
diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs
index 4a0aac0c8a..d06e7810f8 100644
--- a/ext/XS-APItest/APItest.xs
+++ b/ext/XS-APItest/APItest.xs
@@ -2566,19 +2566,27 @@ test_EXTEND(max_offset, nsv, use_ss)
SV *nsv;
bool use_ss;
PREINIT:
- SV **sp = PL_stack_max + max_offset;
+ SV **new_sp = PL_stack_max + max_offset;
+ SSize_t new_offset = new_sp - PL_stack_base;
PPCODE:
if (use_ss) {
SSize_t n = (SSize_t)SvIV(nsv);
- EXTEND(sp, n);
- *(sp + n) = NULL;
+ EXTEND(new_sp, n);
+ new_sp = PL_stack_base + new_offset;
+ assert(new_sp + n <= PL_stack_max);
+ if ((new_sp + n) > PL_stack_sp)
+ *(new_sp + n) = NULL;
}
else {
IV n = SvIV(nsv);
- EXTEND(sp, n);
- *(sp + n) = NULL;
+ EXTEND(new_sp, n);
+ new_sp = PL_stack_base + new_offset;
+ assert(new_sp + n <= PL_stack_max);
+ if ((new_sp + n) > PL_stack_sp)
+ *(new_sp + n) = NULL;
}
- *PL_stack_max = NULL;
+ if (PL_stack_max > PL_stack_sp)
+ *PL_stack_max = NULL;
void