Skip to content

Commit 628202f

Browse files
committed
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.
1 parent 8a82284 commit 628202f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

ext/XS-APItest/APItest.xs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5035,6 +5035,14 @@ sv_numeq_flags(nullable_SV sv1, nullable_SV sv2, U32 flags)
50355035
bool
50365036
sv_numne(nullable_SV sv1, nullable_SV sv2)
50375037

5038+
# deliberately void context
5039+
void
5040+
void_sv_numne(nullable_SV sv1, nullable_SV sv2, SV *out)
5041+
CODE:
5042+
sv_setbool(out, sv_numne(sv1, sv2));
5043+
OUTPUT:
5044+
out
5045+
50385046
bool
50395047
sv_numne_flags(nullable_SV sv1, nullable_SV sv2, U32 flags)
50405048

ext/XS-APItest/t/sv_numne.t

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!perl
22

3-
use Test::More tests => 22;
3+
use Test::More tests => 24;
44
use XS::APItest;
55
use Config;
66

@@ -43,7 +43,13 @@ ok !sv_numne_flags($1, 11, SV_GMAGIC), 'sv_numne_flags with SV_GMAGIC does';
4343
ok !sv_numne(12, $obj), 'AlwaysTwelve is 12 on right';
4444
ok sv_numne(11, $obj), 'AlwayeTwelve is not 11 on the right';
4545

46-
ok !sv_numne_flags($obj, 11, SV_SKIP_OVERLOAD), 'AlwaysTwelve is 12 with SV_SKIP_OVERLOAD'
46+
ok !sv_numne_flags($obj, 11, SV_SKIP_OVERLOAD), 'AlwaysTwelve is 12 with SV_SKIP_OVERLOAD';
47+
48+
my $result;
49+
void_sv_numne($obj, 11, $result);
50+
ok($result, "overloaded sv_numne() (ne) in void context");
51+
void_sv_numne($obj, 12, $result);
52+
ok(!$result, "overloaded sv_numne() (eq) in void context");
4753
}
4854

4955
# +0 overloading with large numbers and using fallback

0 commit comments

Comments
 (0)