Skip to content

Commit f0e9f18

Browse files
author
Father Chrysostomos
committed
Restore the package name to overload errors; fix crash
Commit bfcb351 (which was backported to 5.8.8) caused these error messages always to mention the overload package, instead of the pack- age involved: Can't resolve method "foo" overloading "+" in package "baz" Stub found while resolving method "foo" overloading "+" in package "baz" This commit fixes that. A compiler warning alerted me to the possi- bility of HvNAME being null, so I wrote a small test for that, found that it crashed, and incorporated the fix for the crash into the same commit (since it’s the same line of code).
1 parent 2e34687 commit f0e9f18

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

gv.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,9 +2056,10 @@ Perl_Gv_AMupdate(pTHX_ HV *stash, bool destructing)
20562056
gv = Perl_gv_fetchmeth(aTHX_ stash, cooky, l, -1);
20572057
cv = 0;
20582058
if (gv && (cv = GvCV(gv))) {
2059-
const char *hvname;
2060-
if (GvNAMELEN(CvGV(cv)) == 3 && strEQ(GvNAME(CvGV(cv)), "nil")
2061-
&& strEQ(hvname = HvNAME_get(GvSTASH(CvGV(cv))), "overload")) {
2059+
if(GvNAMELEN(CvGV(cv)) == 3 && strEQ(GvNAME(CvGV(cv)), "nil")){
2060+
const char * const hvname = HvNAME_get(GvSTASH(CvGV(cv)));
2061+
if (hvname && HEK_LEN(HvNAME_HEK(GvSTASH(CvGV(cv)))) == 8
2062+
&& strEQ(hvname, "overload")) {
20622063
/* This is a hack to support autoloading..., while
20632064
knowing *which* methods were declared as overloaded. */
20642065
/* GvSV contains the name of the method. */
@@ -2067,7 +2068,7 @@ Perl_Gv_AMupdate(pTHX_ HV *stash, bool destructing)
20672068

20682069
DEBUG_o( Perl_deb(aTHX_ "Resolving method \"%"SVf256\
20692070
"\" for overloaded \"%s\" in package \"%.256s\"\n",
2070-
(void*)GvSV(gv), cp, hvname) );
2071+
(void*)GvSV(gv), cp, HvNAME(stash)) );
20712072
if (!gvsv || !SvPOK(gvsv)
20722073
|| !(ngv = gv_fetchmethod_autoload(stash, SvPVX_const(gvsv),
20732074
FALSE)))
@@ -2082,10 +2083,11 @@ Perl_Gv_AMupdate(pTHX_ HV *stash, bool destructing)
20822083
"in package \"%.256s\"",
20832084
(GvCVGEN(gv) ? "Stub found while resolving"
20842085
: "Can't resolve"),
2085-
name, cp, hvname);
2086+
name, cp, HvNAME(stash));
20862087
}
20872088
}
20882089
cv = GvCV(gv = ngv);
2090+
}
20892091
}
20902092
DEBUG_o( Perl_deb(aTHX_ "Overloading \"%s\" in package \"%.256s\" via \"%.256s::%.256s\"\n",
20912093
cp, HvNAME_get(stash), HvNAME_get(GvSTASH(CvGV(cv))),

lib/overload.t

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ package main;
4848

4949
$| = 1;
5050
BEGIN { require './test.pl' }
51-
plan tests => 4982;
51+
plan tests => 4983;
5252

5353
use Scalar::Util qw(tainted);
5454

@@ -2173,7 +2173,7 @@ fresh_perl_is
21732173
use overload '+' => 'justice';
21742174
eval {bless[]};
21752175
::like $@, qr/^Can't resolve method "justice" overloading "\+" in p(?x:
2176-
)ackage "overload" at /,
2176+
)ackage "Justus" at /,
21772177
'Error message when explicitly named overload method does not exist';
21782178

21792179
package JustUs;
@@ -2182,8 +2182,16 @@ fresh_perl_is
21822182
"JustUs"->${\"(+"};
21832183
eval {bless []};
21842184
::like $@, qr/^Stub found while resolving method "\?{3}" overloadin(?x:
2185-
)g "\+" in package "overload" at /,
2185+
)g "\+" in package "JustUs" at /,
21862186
'Error message when sub stub is encountered';
21872187
}
21882188

2189+
{ # undefining the overload stash -- KEEP THIS TEST LAST
2190+
package ant;
2191+
use overload '+' => 'onion';
2192+
$_ = \&overload::nil;
2193+
undef %overload::;
2194+
::ok(1, 'no crash when undefining %overload::');
2195+
}
2196+
21892197
# EOF

0 commit comments

Comments
 (0)