Skip to content

Commit cd48b4d

Browse files
committed
op.c toke.c add gv_override_pvs() change manual string lit. lens to macros
- manually counted string lengths is an anti-pattern, even if the lengths are correct, there is still a thought of "what if a mistake happened" - better tools exist in the Perl C API, this commit switches to using them - gv_override() is not exported from libperl on any OS - gv_overridepvs() is harder to read, gv_overrides() is an obfuscated name
1 parent 563689f commit cd48b4d

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

handy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ Perl_xxx(aTHX_ ...) form for any API calls where it's used.
468468
Perl_gv_fetchpvn_flags(aTHX_ STR_WITH_LEN(name), flags, sv_type)
469469
#define gv_fetchpvn gv_fetchpvn_flags
470470

471+
/* gv_override() is not exported from libperl */
472+
#ifdef PERL_CORE
473+
# define gv_override_pvs(name) Perl_gv_override(aTHX_ STR_WITH_LEN(name))
474+
#endif
471475

472476
/*
473477
=for apidoc_defn mx|void|lex_stuff_pvs|"pv"|U32 flags

op.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8506,7 +8506,7 @@ Perl_dofile(pTHX_ OP *term, I32 force_builtin)
85068506

85078507
PERL_ARGS_ASSERT_DOFILE;
85088508

8509-
if (!force_builtin && (gv = gv_override("do", 2))) {
8509+
if (!force_builtin && (gv = gv_override_pvs("do"))) {
85108510
doop = S_new_entersubop(aTHX_ gv, term);
85118511
}
85128512
else {
@@ -12482,7 +12482,7 @@ Perl_ck_backtick(pTHX_ OP *o)
1248212482
o = ck_fun(o);
1248312483
/* qx and `` have a null pushmark; CORE::readpipe has only one kid. */
1248412484
if (o->op_flags & OPf_KIDS && (sibl = OpSIBLING(cUNOPo->op_first))
12485-
&& (gv = gv_override("readpipe",8)))
12485+
&& (gv = gv_override_pvs("readpipe")))
1248612486
{
1248712487
/* detach rest of siblings from o and its first child */
1248812488
op_sibling_splice(o, cUNOPo->op_first, -1, NULL);
@@ -13441,7 +13441,7 @@ Perl_ck_glob(pTHX_ OP *o)
1344113441
if ((o->op_flags & OPf_KIDS) && !OpHAS_SIBLING(cLISTOPo->op_first))
1344213442
op_append_elem(OP_GLOB, o, newDEFSVOP()); /* glob() => glob($_) */
1344313443

13444-
if (!(o->op_flags & OPf_SPECIAL) && (gv = gv_override("glob", 4)))
13444+
if (!(o->op_flags & OPf_SPECIAL) && (gv = gv_override_pvs("glob")))
1344513445
{
1344613446
/* convert
1344713447
* glob
@@ -14118,7 +14118,7 @@ Perl_ck_require(pTHX_ OP *o)
1411814118

1411914119
if (!(o->op_flags & OPf_SPECIAL) /* Wasn't written as CORE::require */
1412014120
/* handle override, if any */
14121-
&& (gv = gv_override("require", 7))) {
14121+
&& (gv = gv_override_pvs("require"))) {
1412214122
OP *kid, *newop;
1412314123
if (o->op_flags & OPf_KIDS) {
1412414124
kid = cUNOPo->op_first;

toke.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11462,7 +11462,7 @@ S_scan_inputsymbol(pTHX_ char *start)
1146211462
Copy("ARGV",d,5,char);
1146311463

1146411464
/* Check whether readline() is overridden */
11465-
if ((gv_readline = gv_override("readline",8)))
11465+
if ((gv_readline = gv_override_pvs("readline")))
1146611466
readline_overridden = TRUE;
1146711467

1146811468
/* if <$fh>, create the ops to turn the variable into a

0 commit comments

Comments
 (0)