Skip to content

Commit

Permalink
test and fix using T_HVREF_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 77e7637 commit a587482
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 @@ -46,6 +46,7 @@ our @EXPORT = (qw/
T_AVREF_REFCOUNT_FIXED
T_HVREF
T_HVREF_REFCOUNT_FIXED
T_HVREF_REFCOUNT_FIXED_output
T_CVREF
T_CVREF_REFCOUNT_FIXED
T_SYSRET_fail T_SYSRET_pass
Expand Down
6 changes: 6 additions & 0 deletions ext/XS-Typemap/Typemap.xs
Expand Up @@ -348,6 +348,12 @@ T_HVREF_REFCOUNT_FIXED( hv )
OUTPUT:
RETVAL

void
T_HVREF_REFCOUNT_FIXED_output( OUT hvref)
HV_FIXED *hvref;
CODE:
hvref = newHV();
hv_stores(hvref, "test", newSVpvs("value"));

## T_CVREF

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

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

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

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

0 comments on commit a587482

Please sign in to comment.