Skip to content

Commit

Permalink
test and fix using T_AVREF_REFCOUNT 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 7d8e6a9 commit 08d4598
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions ext/XS-Typemap/Typemap.pm
Expand Up @@ -44,6 +44,7 @@ our @EXPORT = (qw/
T_SVREF_REFCOUNT_FIXED_output
T_AVREF
T_AVREF_REFCOUNT_FIXED
T_AVREF_REFCOUNT_FIXED_output
T_HVREF
T_HVREF_REFCOUNT_FIXED
T_HVREF_REFCOUNT_FIXED_output
Expand Down
6 changes: 6 additions & 0 deletions ext/XS-Typemap/Typemap.xs
Expand Up @@ -325,6 +325,12 @@ T_AVREF_REFCOUNT_FIXED( av )
OUTPUT:
RETVAL

void
T_AVREF_REFCOUNT_FIXED_output( OUT avref)
AV_FIXED *avref;
CODE:
avref = newAV();
av_push(avref, newSVpvs("test"));

## T_HVREF

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 => 164;
use Test::More tests => 167;

use strict;
#catch WARN_INTERNAL type errors, and anything else unexpected
Expand Down Expand Up @@ -79,6 +79,14 @@ is( T_AVREF_REFCOUNT_FIXED(\@array), \@array);
eval { T_AVREF_REFCOUNT_FIXED( \$sv ) };
ok( $@ );

# output only
SKIP:{
my $avr;
is_deeply([ T_AVREF_REFCOUNT_FIXED_output($avr) ], [ ], "call with non-ref lvalue, no return value");
ok(ref $avr, "output parameter now a reference")
or skip "Not a reference", 1;
is_deeply($avr, [ "test" ], "has expected entry");
}

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

0 comments on commit 08d4598

Please sign in to comment.