diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-10-31 06:03:53 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2013-10-31 15:47:03 -0700 |
commit | c7ea825dcca16c97f7f2a13dbd247b4ee649703f (patch) | |
tree | 587b5cd997ac47818b1f68b388ea65d8ef2106b8 /pp.c | |
parent | 8d9dd4b93fdcb05efbddfcdc0ca729324cfb60c6 (diff) | |
download | perl-c7ea825dcca16c97f7f2a13dbd247b4ee649703f.tar.gz |
‘Attempt to bless into a ref’ with stale method caches
As of v5.16.0-81-g234df27, SvAMAGIC has only meant potentially over-
loaded. When method changes occur, the flag is turned on. When over-
loading tables are calculated (the first time overloading is used),
the flag is turned off if it turns out there is no overloading.
At the time I did that, I assumed that all uses of SvAMAGIC were to
avoid the inefficient code path for non-overloaded objects. What I
did not notice at the time was that SvAMAGIC is used in pp_bless to
determine whether an object used as a class name should be exempt from
‘Attempt to bless into a reference’.
Hence, the bizarre result:
$ ./perl -Ilib -e 'sub foo{} bless [], bless []'
$ ./perl -Ilib -e 'bless [], bless []'
Attempt to bless into a reference at -e line 1.
This commit makes both die consistently, as they did in 5.16.
Diffstat (limited to 'pp.c')
-rw-r--r-- | pp.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -617,9 +617,18 @@ PP(pp_bless) if (!ssv) goto curstash; SvGETMAGIC(ssv); - if (!SvAMAGIC(ssv) && SvROK(ssv)) + if (SvROK(ssv)) { + if (!SvAMAGIC(ssv)) { + frog: Perl_croak(aTHX_ "Attempt to bless into a reference"); - ptr = SvPV_nomg_const(ssv,len); + } + /* SvAMAGIC is on here, but it only means potentially overloaded, + so after stringification: */ + ptr = SvPV_nomg_const(ssv,len); + /* We need to check the flag again: */ + if (!SvAMAGIC(ssv)) goto frog; + } + else ptr = SvPV_nomg_const(ssv,len); if (len == 0) Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "Explicit blessing to '' (assuming package main)"); |