This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix XS types in typemap in order to deal with references with get magics correctly
[perl5.git] / lib / ExtUtils / typemap
index f888587..2024255 100644 (file)
@@ -58,33 +58,57 @@ INPUT
 T_SV
        $var = $arg
 T_SVREF
-       if (SvROK($arg))
-           $var = (SV*)SvRV($arg);
-       else
-           Perl_croak(aTHX_ \"%s: %s is not a reference\",
-                       ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
-                       \"$var\")
+       STMT_START {
+               SV* const xsub_tmp_sv = $arg;
+               SvGETMAGIC(xsub_tmp_sv);
+               if (SvROK(xsub_tmp_sv)){
+                   $var = SvRV(xsub_tmp_sv);
+               }
+               else{
+                   Perl_croak(aTHX_ \"%s: %s is not a reference\",
+                               ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
+                               \"$var\");
+               }
+       } STMT_END
 T_AVREF
-       if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV)
-           $var = (AV*)SvRV($arg);
-       else
-           Perl_croak(aTHX_ \"%s: %s is not an array reference\",
-                       ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
-                       \"$var\")
+       STMT_START {
+               SV* const xsub_tmp_sv = $arg;
+               SvGETMAGIC(xsub_tmp_sv);
+               if (SvROK(xsub_tmp_sv) && SvTYPE(SvRV(xsub_tmp_sv)) == SVt_PVAV){
+                   $var = (AV*)SvRV(xsub_tmp_sv);
+               }
+               else{
+                   Perl_croak(aTHX_ \"%s: %s is not an ARRAY reference\",
+                               ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
+                               \"$var\");
+               }
+       } STMT_END
 T_HVREF
-       if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVHV)
-           $var = (HV*)SvRV($arg);
-       else
-           Perl_croak(aTHX_ \"%s: %s is not a hash reference\",
-                       ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
-                       \"$var\")
+       STMT_START {
+               SV* const xsub_tmp_sv = $arg;
+               SvGETMAGIC(xsub_tmp_sv);
+               if (SvROK(xsub_tmp_sv) && SvTYPE(SvRV(xsub_tmp_sv)) == SVt_PVHV){
+                   $var = (AV*)SvRV(xsub_tmp_sv);
+               }
+               else{
+                   Perl_croak(aTHX_ \"%s: %s is not a HASH reference\",
+                               ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
+                               \"$var\");
+               }
+       } STMT_END
 T_CVREF
-       if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVCV)
-           $var = (CV*)SvRV($arg);
-       else
-           Perl_croak(aTHX_ \"%s: %s is not a code reference\",
-                       ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
-                       \"$var\")
+       STMT_START {
+               SV* const xsub_tmp_sv = $arg;
+               SvGETMAGIC(xsub_tmp_sv);
+               if (SvROK(xsub_tmp_sv) && SvTYPE(SvRV(xsub_tmp_sv)) == SVt_PVCV){
+                   $var = (AV*)SvRV(xsub_tmp_sv);
+               }
+               else{
+                   Perl_croak(aTHX_ \"%s: %s is not a CODE reference\",
+                               ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
+                               \"$var\");
+               }
+       } STMT_END
 T_SYSRET
        $var NOT IMPLEMENTED
 T_UV