develooper Front page | perl.perl5.porters | Postings from April 2000

Re: [ID 20000408.001] 'reftype' does not work through ties

Thread Previous | Thread Next
From:
Mark Contois
Date:
April 10, 2000 19:40
Subject:
Re: [ID 20000408.001] 'reftype' does not work through ties
Message ID:
200004110240.TAA96872@mail.desktop.com
This does for xsutils.c what Graham's patch did for Scalar::Util.

Mark


Index: xsutils.c
--- xsutils.c.orig	Mon Apr 10 19:24:55 2000
+++ xsutils.c	Mon Apr 10 18:52:12 2000
@@ -253,6 +253,8 @@
 
     rv = ST(0);
     ST(0) = TARG;
+    if (SvMAGICAL(rv))
+        mg_get(rv);
     if (!(SvOK(rv) && SvROK(rv)))
 	goto usage;
     sv = SvRV(rv);
End of Patch.


On Sat, Apr 08, 2000 at 07:11:45PM -0700, Jason Kirtland wrote:
> This is a bug report for perl from jason@desktop.com,
> generated with the help of perlbug 1.28 running under perl v5.6.0.
>
>
> -----------------------------------------------------------------
> [Please enter your report here]
>
> Problem: 'reftype' utilities don't work through ties.
>
> use Tie::Hash;  # Arrays also.
> use attributes;
> use Scalar::Util;
>
> tie %Tied, 'Tie::StdHash';
> %Tied  = ( ref => {} );
> %Plain = ( ref => {} );
>
> print 'P: ', ref($Plain{ref}), "\n";   # HASH
> print 'T: ', ref($Tied{ref}), "\n";    # HASH
>
> print 'P: ', Scalar::Util::reftype($Plain{ref}), "\n";  # HASH
> print 'T: ', Scalar::Util::reftype($Tied{ref}), "\n";   # undef
>
> print 'P: ', attributes::reftype($Plain{ref}), "\n"; # HASH
> print 'T: ', attributes::reftype($Tied{ref}), "\n";  # dies:
> # Usage: attributes::reftype $reference
>
> Here's the XS code from Scalar::Util.
>
> char *
> reftype(sv)
>     SV * sv
> PROTOTYPE: $
> CODE:
> {
>     if(!SvROK(sv)) {
>         XSRETURN_UNDEF;
>     }
>     RETVAL = sv_reftype(SvRV(sv),FALSE);
> }
> OUTPUT:
>     RETVAL

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About