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

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

Thread Previous
From:
Graham Barr
Date:
April 10, 2000 01:57
Subject:
Re: [ID 20000408.001] 'reftype' does not work through ties
Message ID:
20000410095322.C28725@pobox.com
Ah, thats because the argument is magical. Here is a patch for
Scalar::Util and a new release will be in CPAN shortly

Graham.

Index: utils/Util.xs
--- utils/Util.xs.~1~	Mon Apr 10 09:51:45 2000
+++ utils/Util.xs	Mon Apr 10 09:51:45 2000
@@ -258,6 +258,8 @@
 PROTOTYPE: $
 CODE:
 {
+    if (SvMAGICAL(sv))
+	mg_get(sv);
     if(!sv_isobject(sv)) {
 	XSRETURN_UNDEF;
     }
@@ -272,6 +274,8 @@
 PROTOTYPE: $
 CODE:
 {
+    if (SvMAGICAL(sv))
+	mg_get(sv);
     if(!SvROK(sv)) {
 	XSRETURN_UNDEF;
     }
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


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