Skip to content

Commit 9f0a1b6

Browse files
committed
toke.c: Change S_scan_word parameter
Change it from being an array length, to being a pointer to the ending position of the array. This makes this function consistent with most of the others in this file. It allows us to usually use C_ARRAY_END() to wrap the parameter, which simplifies some expressions,
1 parent 5b7224a commit 9f0a1b6

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

embed.fnc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3072,7 +3072,7 @@ Adp |char * |scan_vstring |NN const char *s \
30723072
|NN SV *sv
30733073
EXpx |char * |scan_word |NN char *s \
30743074
|NN char *dest \
3075-
|STRLEN destlen \
3075+
|NN char *dest_end \
30763076
|int allow_package \
30773077
|NN STRLEN *slp
30783078
Cp |U32 |seed

proto.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

toke.c

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,7 +2277,9 @@ S_force_word(pTHX_ char *start, int token, int check_keyword, int allow_pack)
22772277
if ( isIDFIRST_lazy_if_safe(s, PL_bufend, UTF)
22782278
|| (allow_pack && *s == ':' && s[1] == ':') )
22792279
{
2280-
s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
2280+
s = scan_word(s,
2281+
PL_tokenbuf, C_ARRAY_END(PL_tokenbuf),
2282+
allow_pack, &len);
22812283
if (check_keyword) {
22822284
char *s2 = PL_tokenbuf;
22832285
STRLEN len2 = len;
@@ -4815,7 +4817,7 @@ S_intuit_method(pTHX_ char *start, SV *ioname, CV *cv)
48154817
return *s == '(' ? METHCALL : METHCALL0;
48164818
}
48174819

4818-
s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4820+
s = scan_word(s, tmpbuf, C_ARRAY_END(tmpbuf), TRUE, &len);
48194821
/* start is the beginning of the possible filehandle/object,
48204822
* and s is the end of it
48214823
* tmpbuf is a copy of it (but with single quotes as double colons)
@@ -5453,7 +5455,7 @@ yyl_dollar(pTHX_ char *s)
54535455
} while (isSPACE(*t));
54545456
if (isIDFIRST_lazy_if_safe(t, PL_bufend, UTF)) {
54555457
STRLEN len;
5456-
t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
5458+
t = scan_word(t, tmpbuf, C_ARRAY_END(tmpbuf), TRUE, &len);
54575459
while (isSPACE(*t))
54585460
t++;
54595461
if ( *t == ';'
@@ -5486,7 +5488,7 @@ yyl_dollar(pTHX_ char *s)
54865488
char tmpbuf[sizeof PL_tokenbuf];
54875489
int t2;
54885490
STRLEN len;
5489-
scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5491+
scan_word(s, tmpbuf, C_ARRAY_END(tmpbuf), TRUE, &len);
54905492
if ((t2 = keyword(tmpbuf, len, 0))) {
54915493
/* binary operators exclude handle interpretations */
54925494
switch (t2) {
@@ -5557,7 +5559,7 @@ yyl_sub(pTHX_ char *s, const int key)
55575559
{
55585560

55595561
PL_expect = XATTRBLOCK;
5560-
d = scan_word(s, tmpbuf, sizeof PL_tokenbuf - 1, TRUE, &len);
5562+
d = scan_word(s, tmpbuf, C_ARRAY_END(PL_tokenbuf), TRUE, &len);
55615563
if (key == KEY_format)
55625564
format_name = S_newSV_maybe_utf8(aTHX_ s, d - s);
55635565
*PL_tokenbuf = '&';
@@ -6164,7 +6166,9 @@ yyl_colon(pTHX_ char *s)
61646166
I32 tmp;
61656167
SV *sv;
61666168
STRLEN len;
6167-
char *d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
6169+
char *d = scan_word(s,
6170+
PL_tokenbuf, C_ARRAY_END(PL_tokenbuf),
6171+
FALSE, &len);
61686172
if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
61696173
if (tmp < 0) tmp = -tmp;
61706174
switch (tmp) {
@@ -6343,7 +6347,8 @@ yyl_leftcurly(pTHX_ char *s, const U8 formbrack)
63436347
}
63446348
if (d < PL_bufend && isIDFIRST_lazy_if_safe(d, PL_bufend, UTF)) {
63456349
STRLEN len;
6346-
d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
6350+
d = scan_word(d,
6351+
PL_tokenbuf + 1, C_ARRAY_END(PL_tokenbuf),
63476352
FALSE, &len);
63486353
while (d < PL_bufend && SPACE_OR_TAB(*d))
63496354
d++;
@@ -7161,7 +7166,9 @@ yyl_foreach(pTHX_ char *s)
71617166
/* skip optional package name, as in "for my abc $x (..)" */
71627167
if (UNLIKELY(isIDFIRST_lazy_if_safe(p, PL_bufend, UTF))) {
71637168
STRLEN len;
7164-
p = scan_word(p, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
7169+
p = scan_word(p,
7170+
PL_tokenbuf, C_ARRAY_END(PL_tokenbuf),
7171+
TRUE, &len);
71657172
p = skipspace(p);
71667173
paren_is_valid = FALSE;
71677174
}
@@ -7190,7 +7197,8 @@ yyl_do(pTHX_ char *s, I32 orig_keyword)
71907197
char *d;
71917198
STRLEN len;
71927199
*PL_tokenbuf = '&';
7193-
d = scan_word(s, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
7200+
d = scan_word(s,
7201+
PL_tokenbuf + 1, C_ARRAY_END(PL_tokenbuf),
71947202
1, &len);
71957203
if (len && memNEs(PL_tokenbuf+1, len, "CORE")
71967204
&& !keyword(PL_tokenbuf + 1, len, 0)) {
@@ -7246,7 +7254,9 @@ yyl_my(pTHX_ char *s, I32 my)
72467254
s = skipspace(s);
72477255
if (isIDFIRST_lazy_if_safe(s, PL_bufend, UTF)) {
72487256
STRLEN len;
7249-
s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
7257+
s = scan_word(s,
7258+
PL_tokenbuf, C_ARRAY_END(PL_tokenbuf),
7259+
TRUE, &len);
72507260
if (memEQs(PL_tokenbuf, len, "sub"))
72517261
/* my sub ... */
72527262
return yyl_sub(aTHX_ s, my);
@@ -7720,7 +7730,8 @@ yyl_just_a_word(pTHX_ char *s, STRLEN len, I32 orig_keyword, struct code c)
77207730
if ((*s == '\'' && FEATURE_APOS_AS_NAME_SEP_IS_ENABLED)
77217731
|| (*s == ':' && s[1] == ':')) {
77227732
STRLEN morelen;
7723-
s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
7733+
s = scan_word(s,
7734+
PL_tokenbuf + len, C_ARRAY_END(PL_tokenbuf),
77247735
TRUE, &morelen);
77257736
if (no_op_error) {
77267737
S_warn_expect_operator(aTHX_ "Bareword",s,FALSE);
@@ -8472,7 +8483,9 @@ yyl_word_or_keyword(pTHX_ char *s, STRLEN len, I32 key, I32 orig_keyword, struct
84728483
s = skipspace(s);
84738484
if (isIDFIRST_lazy_if_safe(s, PL_bufend, UTF)) {
84748485
const char *t;
8475-
char *d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
8486+
char *d = scan_word(s,
8487+
PL_tokenbuf, C_ARRAY_END(PL_tokenbuf),
8488+
FALSE, &len);
84768489
for (t=d; isSPACE(*t);)
84778490
t++;
84788491
if ( *t && memCHRs("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
@@ -8905,7 +8918,7 @@ yyl_key_core(pTHX_ char *s, STRLEN len, struct code c)
89058918
STRLEN olen = len;
89068919
char *d = s;
89078920
s += 2;
8908-
s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
8921+
s = scan_word(s, PL_tokenbuf, C_ARRAY_END(PL_tokenbuf), FALSE, &len);
89098922
if ((*s == ':' && s[1] == ':')
89108923
|| (!(key = keyword(PL_tokenbuf, len, 1)) && *s == '\'' &&
89118924
FEATURE_APOS_AS_NAME_SEP_IS_ENABLED))
@@ -8985,7 +8998,7 @@ yyl_keylookup(pTHX_ char *s, GV *gv)
89858998
c.gv = gv;
89868999

89879000
PL_bufptr = s;
8988-
s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
9001+
s = scan_word(s, PL_tokenbuf, C_ARRAY_END(PL_tokenbuf), FALSE, &len);
89899002

89909003
/* Some keywords can be followed by any delimiter, including ':' */
89919004
anydelim = word_takes_any_delimiter(PL_tokenbuf, len);
@@ -10341,12 +10354,12 @@ S_parse_ident(pTHX_ char **s, char **d, char * const e, int allow_package,
1034110354
}
1034210355

1034310356
char *
10344-
Perl_scan_word(pTHX_ char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10357+
Perl_scan_word(pTHX_ char *s, char *dest, char * dest_end, int allow_package, STRLEN *slp)
1034510358
{
1034610359
PERL_ARGS_ASSERT_SCAN_WORD;
1034710360

1034810361
char *d = dest;
10349-
char * const e = d + destlen - 3; /* two-character token, ending NUL */
10362+
char * const e = dest_end - 3; /* two-character token, ending NUL */
1035010363
bool is_utf8 = cBOOL(UTF);
1035110364

1035210365
parse_ident(&s, &d, e, allow_package, is_utf8, TRUE);
@@ -13815,7 +13828,7 @@ Perl_parse_label(pTHX_ U32 flags)
1381513828
t = s = PL_bufptr;
1381613829
if (!isIDFIRST_lazy_if_safe(s, PL_bufend, UTF))
1381713830
goto no_label;
13818-
t = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &wlen);
13831+
t = scan_word(s, PL_tokenbuf, C_ARRAY_END(PL_tokenbuf), FALSE, &wlen);
1381913832
if (word_takes_any_delimiter(s, wlen))
1382013833
goto no_label;
1382113834
bufptr_pos = s - SvPVX(PL_linestr);

0 commit comments

Comments
 (0)