Skip to content

Commit 9a70c74

Browse files
committedNov 12, 2016
remove DOES's usage of SvSCREAM
Currently the SvSCREAM flag is set on a temporary SV whose string value is "isa", but where for the purposes of printing Can't call method "XXX" its name is treated as "DOES" rather than "isa". Instead, set the temp SV's PVX buffer to point to a special static string (PL_isa_DOES) whose value is "isa", but the where the error reporting code can compare the address with PL_isa_DOES and if so, print "DOES" instead. This is to reduce the number of odd special cases for the SvSCREAM flag.
1 parent 4c57ced commit 9a70c74

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed
 

‎pp_hot.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -4365,6 +4365,8 @@ Perl_vivify_ref(pTHX_ SV *sv, U32 to_what)
43654365
return sv;
43664366
}
43674367

4368+
extern char PL_isa_DOES[];
4369+
43684370
PERL_STATIC_INLINE HV *
43694371
S_opmethod_stash(pTHX_ SV* meth)
43704372
{
@@ -4443,7 +4445,7 @@ S_opmethod_stash(pTHX_ SV* meth)
44434445
&& SvOBJECT(ob))))
44444446
{
44454447
Perl_croak(aTHX_ "Can't call method \"%"SVf"\" on unblessed reference",
4446-
SVfARG((SvSCREAM(meth) && strEQ(SvPV_nolen_const(meth),"isa"))
4448+
SVfARG((SvPVX(meth) == PL_isa_DOES)
44474449
? newSVpvs_flags("DOES", SVs_TEMP)
44484450
: meth));
44494451
}

‎sv.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ perform the upgrade if necessary. See C<L</svtype>>.
369369
#define SVp_IOK 0x00001000 /* has valid non-public integer value */
370370
#define SVp_NOK 0x00002000 /* has valid non-public numeric value */
371371
#define SVp_POK 0x00004000 /* has valid non-public pointer value */
372-
#define SVp_SCREAM 0x00008000 /* method name is DOES */
372+
#define SVp_SCREAM 0x00008000 /* currently unused on plain scalars */
373373
#define SVphv_CLONEABLE SVp_SCREAM /* PVHV (stashes) clone its objects */
374374
#define SVpgv_GP SVp_SCREAM /* GV has a valid GP */
375375
#define SVprv_PCS_IMPORTED SVp_SCREAM /* RV is a proxy for a constant
@@ -443,7 +443,6 @@ perform the upgrade if necessary. See C<L</svtype>>.
443443
444444
SVf_POK, SVp_POK also set:
445445
0x00004400 Normal
446-
0x0000C400 method name for DOES (SvSCREAM)
447446
0x40004400 FBM compiled (SvVALID)
448447
0x4000C400 *** Formerly used for pad names ***
449448

‎universal.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ The SV can be a Perl object or the name of a Perl class.
184184

185185
#include "XSUB.h"
186186

187+
/* a special string address whose value is "isa", but whicb perl knows
188+
* to treat as if it were really "DOES" */
189+
char PL_isa_DOES[] = "isa";
190+
187191
bool
188192
Perl_sv_does_sv(pTHX_ SV *sv, SV *namesv, U32 flags)
189193
{
@@ -222,11 +226,14 @@ Perl_sv_does_sv(pTHX_ SV *sv, SV *namesv, U32 flags)
222226
PUSHs(namesv);
223227
PUTBACK;
224228

225-
methodname = newSVpvs_flags("isa", SVs_TEMP);
226-
/* ugly hack: use the SvSCREAM flag so S_method_common
227-
* can figure out we're calling DOES() and not isa(),
228-
* and report eventual errors correctly. --rgs */
229-
SvSCREAM_on(methodname);
229+
/* create a PV with value "isa", but with a special address
230+
* so that perl knows were' realling doing "DOES" instead */
231+
methodname = newSV_type(SVt_PV);
232+
SvLEN(methodname) = 0;
233+
SvCUR(methodname) = strlen(PL_isa_DOES);
234+
SvPVX(methodname) = PL_isa_DOES;
235+
SvPOK_on(methodname);
236+
sv_2mortal(methodname);
230237
call_sv(methodname, G_SCALAR | G_METHOD);
231238
SPAGAIN;
232239

0 commit comments

Comments
 (0)
Failed to load comments.