From 9edfa4656a881074208454d8712a1bd3f4dbc260 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Wed, 3 Dec 2025 09:52:23 +1100 Subject: [PATCH] add tests for void context calls to overloads Discovered while working on another module, in many amagic_call() will use the current context when calling the overload sub, but these APIs might be called in XS code that simply needs a comparison, regardless of the current OP context. --- ext/XS-APItest/APItest.xs | 8 ++++++++ ext/XS-APItest/t/sv_numne.t | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs index b48b7b4118..f8b36a291b 100644 --- a/ext/XS-APItest/APItest.xs +++ b/ext/XS-APItest/APItest.xs @@ -5058,6 +5058,14 @@ sv_numeq_flags(nullable_SV sv1, nullable_SV sv2, U32 flags) bool sv_numne(nullable_SV sv1, nullable_SV sv2) +# deliberately void context +void +void_sv_numne(nullable_SV sv1, nullable_SV sv2, SV *out) + CODE: + sv_setbool(out, sv_numne(sv1, sv2)); + OUTPUT: + out + bool sv_numne_flags(nullable_SV sv1, nullable_SV sv2, U32 flags) diff --git a/ext/XS-APItest/t/sv_numne.t b/ext/XS-APItest/t/sv_numne.t index 405b2ad552..938b52de74 100644 --- a/ext/XS-APItest/t/sv_numne.t +++ b/ext/XS-APItest/t/sv_numne.t @@ -1,6 +1,6 @@ #!perl -use Test::More tests => 22; +use Test::More tests => 24; use XS::APItest; use Config; @@ -44,7 +44,13 @@ ok !sv_numne_flags($1, 11, SV_GMAGIC), 'sv_numne_flags with SV_GMAGIC does'; ok !sv_numne(12, $obj), 'AlwaysTwelve is 12 on right'; ok sv_numne(11, $obj), 'AlwayeTwelve is not 11 on the right'; - ok !sv_numne_flags($obj, 11, SV_SKIP_OVERLOAD), 'AlwaysTwelve is 12 with SV_SKIP_OVERLOAD' + ok !sv_numne_flags($obj, 11, SV_SKIP_OVERLOAD), 'AlwaysTwelve is 12 with SV_SKIP_OVERLOAD'; + + my $result; + void_sv_numne($obj, 11, $result); + ok($result, "overloaded sv_numne() (ne) in void context"); + void_sv_numne($obj, 12, $result); + ok(!$result, "overloaded sv_numne() (eq) in void context"); } # +0 overloading with large numbers and using fallback