diff --git a/ext/XS-Typemap/Typemap.pm b/ext/XS-Typemap/Typemap.pm index 9f838b44cb6c..721b476c06b0 100644 --- a/ext/XS-Typemap/Typemap.pm +++ b/ext/XS-Typemap/Typemap.pm @@ -38,6 +38,7 @@ our $VERSION = '0.18'; our @EXPORT = (qw/ T_SV + T_SV_output T_SVREF T_SVREF_REFCOUNT_FIXED T_AVREF diff --git a/ext/XS-Typemap/Typemap.xs b/ext/XS-Typemap/Typemap.xs index 397052d1cb5d..14417da3bea0 100644 --- a/ext/XS-Typemap/Typemap.xs +++ b/ext/XS-Typemap/Typemap.xs @@ -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 diff --git a/ext/XS-Typemap/t/Typemap.t b/ext/XS-Typemap/t/Typemap.t index 3e56b573d6c9..7422e6c5bd55 100644 --- a/ext/XS-Typemap/t/Typemap.t +++ b/ext/XS-Typemap/t/Typemap.t @@ -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 @@ -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"; diff --git a/lib/ExtUtils/typemap b/lib/ExtUtils/typemap index 8aa1e12135ec..adac80fd1ca5 100644 --- a/lib/ExtUtils/typemap +++ b/lib/ExtUtils/typemap @@ -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