Skip to content

Commit

Permalink
test and fix using T_SV as an OUTPUT parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycoz committed Sep 9, 2021
1 parent ac88bdf commit 0b71342
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions ext/XS-Typemap/Typemap.pm
Expand Up @@ -38,6 +38,7 @@ our $VERSION = '0.18';

our @EXPORT = (qw/
T_SV
T_SV_output
T_SVREF
T_SVREF_REFCOUNT_FIXED
T_AVREF
Expand Down
7 changes: 7 additions & 0 deletions ext/XS-Typemap/Typemap.xs
Expand Up @@ -267,6 +267,13 @@ T_SV( sv )
OUTPUT:
RETVAL

void
T_SV_output(sv)
SV *sv
CODE:
sv = sv_2mortal(newSVpvn("test", 4));
OUTPUT:
sv

## T_SVREF

Expand Down
6 changes: 5 additions & 1 deletion ext/XS-Typemap/t/Typemap.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
}
}

use Test::More tests => 156;
use Test::More tests => 158;

use strict;
#catch WARN_INTERNAL type errors, and anything else unexpected
Expand All @@ -33,6 +33,10 @@ note("T_SV");
my $sv = "Testing T_SV";
is( T_SV($sv), $sv);

# T_SV with output
is_deeply([ T_SV_output($sv) ], [], "T_SV_output: no return value");
is($sv, "test", "T_SV_output: output written to");

# T_SVREF - reference to Scalar
note("T_SVREF");
$sv .= "REF";
Expand Down
2 changes: 1 addition & 1 deletion lib/ExtUtils/typemap
Expand Up @@ -315,7 +315,7 @@ T_OUT
#############################################################################
OUTPUT
T_SV
$arg = $var;
${ "$var" eq "RETVAL" ? \"$arg = $var;" : \"sv_setsv_mg($arg, $var);" }
T_SVREF
$arg = newRV((SV*)$var);
T_SVREF_REFCOUNT_FIXED
Expand Down

0 comments on commit 0b71342

Please sign in to comment.