From: Rafael Garcia-Suarez Date: Wed, 15 Jan 2003 20:34:52 +0000 (+0000) Subject: isa() and can() didn't work on magic variables X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=253ecd6d4a439a0600720c59c5e6516a269933d8;p=p5sagit%2Fp5-mst-13.2.git isa() and can() didn't work on magic variables see Message-Id: <20030114220737.2190ba7c.rgarciasuarez@free.fr> plus a test case by B. Goldberg p4raw-id: //depot/perl@18486 --- diff --git a/t/op/universal.t b/t/op/universal.t index fc53c39..7d5f59a 100755 --- a/t/op/universal.t +++ b/t/op/universal.t @@ -9,7 +9,7 @@ BEGIN { $| = 1; } -print "1..94\n"; +print "1..98\n"; $a = {}; bless $a, "Bob"; @@ -174,3 +174,16 @@ test ! UNIVERSAL::isa("\xff\xff\xff\0", 'HASH'); main::test can( "Pickup", "can" ) == \&UNIVERSAL::can; main::test VERSION "UNIVERSAL" ; } + +{ + # test isa() and can() on magic variables + "Human" =~ /(.*)/; + test $1->isa("Human"); + test $1->can("eat"); + package HumanTie; + sub TIESCALAR { bless {} } + sub FETCH { "Human" } + tie my($x), "HumanTie"; + ::test $x->isa("Human"); + ::test $x->can("eat"); +} diff --git a/universal.c b/universal.c index 7999757..3e8d8b1 100644 --- a/universal.c +++ b/universal.c @@ -232,7 +232,8 @@ XS(XS_UNIVERSAL_isa) if (SvGMAGICAL(sv)) mg_get(sv); - if (!SvOK(sv) || !(SvROK(sv) || (SvPOK(sv) && SvCUR(sv)))) + if (!SvOK(sv) || !(SvROK(sv) || (SvPOK(sv) && SvCUR(sv)) + || (SvGMAGICAL(sv) && SvPOKp(sv) && SvCUR(sv)))) XSRETURN_UNDEF; name = (char *)SvPV(ST(1),n_a); @@ -258,7 +259,8 @@ XS(XS_UNIVERSAL_can) if (SvGMAGICAL(sv)) mg_get(sv); - if (!SvOK(sv) || !(SvROK(sv) || (SvPOK(sv) && SvCUR(sv)))) + if (!SvOK(sv) || !(SvROK(sv) || (SvPOK(sv) && SvCUR(sv)) + || (SvGMAGICAL(sv) && SvPOKp(sv) && SvCUR(sv)))) XSRETURN_UNDEF; name = (char *)SvPV(ST(1),n_a);