Skip to content

Commit

Permalink
test and fix using T_SVREF_REFCOUNT as an output parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycoz committed Sep 7, 2021
1 parent 82e4a41 commit 77e7637
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions ext/XS-Typemap/Typemap.pm
Expand Up @@ -41,6 +41,7 @@ our @EXPORT = (qw/
T_SV_output
T_SVREF
T_SVREF_REFCOUNT_FIXED
T_SVREF_REFCOUNT_FIXED_output
T_AVREF
T_AVREF_REFCOUNT_FIXED
T_HVREF
Expand Down
5 changes: 5 additions & 0 deletions ext/XS-Typemap/Typemap.xs
Expand Up @@ -297,6 +297,11 @@ T_SVREF_REFCOUNT_FIXED( svref )
OUTPUT:
RETVAL

void
T_SVREF_REFCOUNT_FIXED_output( OUT svref )
SVREF_FIXED svref
CODE:
svref = newSVpvn("test", 4);

## T_AVREF

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

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

use strict;
#catch WARN_INTERNAL type errors, and anything else unexpected
Expand Down Expand Up @@ -55,6 +55,14 @@ is( ${ T_SVREF_REFCOUNT_FIXED($svref) }, $$svref );
eval { T_SVREF_REFCOUNT_FIXED( "fail - not ref" ) };
ok( $@ );

# output only
SKIP:{
my $svr;
is_deeply([ T_SVREF_REFCOUNT_FIXED_output($svr) ], [ ], "call with non-ref lvalue, no return value");
ok(ref $svr, "output parameter now a reference")
or skip "Not a reference", 1;
is($$svr, "test", "reference to correct value");
}

# T_AVREF - reference to a perl Array
note("T_AVREF");
Expand Down
2 changes: 1 addition & 1 deletion lib/ExtUtils/typemap
Expand Up @@ -319,7 +319,7 @@ T_SV
T_SVREF
$arg = newRV((SV*)$var);
T_SVREF_REFCOUNT_FIXED
$arg = newRV_noinc((SV*)$var);
${ "$var" eq "RETVAL" ? \"$arg = newRV_noinc((SV*)$var);" : \"sv_setrv_noinc($arg, (SV*)$var);" }
T_AVREF
$arg = newRV((SV*)$var);
T_AVREF_REFCOUNT_FIXED
Expand Down

0 comments on commit 77e7637

Please sign in to comment.