From 83b243fa48968f4349136fe6943f0c21313b217e Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Mon, 6 Sep 2021 15:09:49 +1000 Subject: test and fix using T_HVREF_REFCOUNT as an output parameter --- ext/XS-Typemap/Typemap.pm | 1 + ext/XS-Typemap/Typemap.xs | 6 ++++++ ext/XS-Typemap/t/Typemap.t | 10 +++++++++- lib/ExtUtils/typemap | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ext/XS-Typemap/Typemap.pm b/ext/XS-Typemap/Typemap.pm index c1b5505e8a..d6e86da86a 100644 --- a/ext/XS-Typemap/Typemap.pm +++ b/ext/XS-Typemap/Typemap.pm @@ -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 diff --git a/ext/XS-Typemap/Typemap.xs b/ext/XS-Typemap/Typemap.xs index d0703be2e5..353e04fb45 100644 --- a/ext/XS-Typemap/Typemap.xs +++ b/ext/XS-Typemap/Typemap.xs @@ -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 diff --git a/ext/XS-Typemap/t/Typemap.t b/ext/XS-Typemap/t/Typemap.t index 835b35caf0..33f4e45306 100644 --- a/ext/XS-Typemap/t/Typemap.t +++ b/ext/XS-Typemap/t/Typemap.t @@ -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 @@ -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"); diff --git a/lib/ExtUtils/typemap b/lib/ExtUtils/typemap index 0c943ef73f..4cedca4025 100644 --- a/lib/ExtUtils/typemap +++ b/lib/ExtUtils/typemap @@ -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 -- cgit v1.2.1