From 2d08227e773ded77863cb5e92f5ef5862ffd287f Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Wed, 11 Jan 2023 23:55:23 +0000 Subject: 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. --- ext/XS-APItest/APItest.xs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'ext') 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 -- cgit v1.2.1