summaryrefslogtreecommitdiff
path: root/gv.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-05-23 01:05:20 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-05-23 06:01:23 -0700
commit3866ea3be51f0998b848d22c4ef960965bda7199 (patch)
tree0bdd788345c8cb865f6aa7c4358c6896c38867ea /gv.c
parent1204c818c5b6fdbe987017df9f2ce0e68463f315 (diff)
downloadperl-3866ea3be51f0998b848d22c4ef960965bda7199.tar.gz
[perl #113050] Put fallback back under "()"
Unfortunately, there is code all over CPAN that assumes fallback is stored under the "()" stash entry. And that code also assumes that the overloadedness flag (the existence of the CV) is in the same spot. So much for encapsulation. This commit changes overloading itself to use a different key, "((", while having it search for "()" first, and then "((" only if "()" is not found, to preserve compatibility with encapsulation-breaking code. So the "((" key will only be used by gv.c if there is no fallback value specified at all.
Diffstat (limited to 'gv.c')
-rw-r--r--gv.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/gv.c b/gv.c
index 8248bfefac..58025b3c91 100644
--- a/gv.c
+++ b/gv.c
@@ -2260,31 +2260,27 @@ Perl_Gv_AMupdate(pTHX_ HV *stash, bool destructing)
int filled = 0, have_ovl = 0;
int i, lim = 1;
- /* The first key in PL_AMG_names is the overloadedness indicator, which
- allows us to skip overloading entries for non-overloaded classes. */
+ /* Work with "fallback" key, which we assume to be first in PL_AMG_names */
/* Try to find via inheritance. */
GV *gv = gv_fetchmeth_pvn(stash, PL_AMG_names[0], 2, -1, 0);
+ SV * const sv = gv ? GvSV(gv) : NULL;
CV* cv;
if (!gv)
+ {
+ if (!gv_fetchmeth_pvn(stash, "((", 2, -1, 0))
lim = DESTROY_amg; /* Skip overloading entries. */
-
- else {
-
- /* The "fallback" key is special-cased here, being absent from the
- list in PL_AMG_names. */
-
- SV *sv;
- gv = gv_fetchmeth_pvn(stash, "(fallback", 9, -1, 0);
-
- if (!gv || !(sv = GvSV(gv)))
+ }
+#ifdef PERL_DONT_CREATE_GVSV
+ else if (!sv) {
NOOP; /* Equivalent to !SvTRUE and !SvOK */
- else if (SvTRUE(sv))
+ }
+#endif
+ else if (SvTRUE(sv))
amt.fallback=AMGfallYES;
- else if (SvOK(sv))
+ else if (SvOK(sv))
amt.fallback=AMGfallNEVER;
- }
for (i = 1; i < lim; i++)
amt.table[i] = NULL;