Skip to content

Commit 19ea4cf

Browse files
committed
toke.c: S_is_existing_identifier: Handle lexicals
This code, looks for global variables, but it was not updated to also handle lexical variables when they were added to the language. This commit adds that handling
1 parent 5dee73f commit 19ea4cf

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

toke.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4472,23 +4472,26 @@ S_is_existing_identifier(pTHX_ char *s, char *e, bool is_utf8)
44724472
{
44734473
/* This checks if the string from 's' to (e - 1) with utf8ness 'is_utf8' is
44744474
* an identifier known to the program. If so, it returns the length of
4475-
* the identifier. If not, it returns 0
4476-
*
4477-
* khw: This only looks at global variables; lexicals came later, and this
4478-
* hasn't been updated. Ouch!! */
4475+
* the identifier. If not, it returns 0 */
44794476

44804477
ptrdiff_t size = e - s;
44814478

44824479
/* khw: scan_ident appears to need a 2-byte minimum; easiest to just add
4483-
* that than calculate a minimum. */
4484-
size += 2;
4480+
* that than calculate a minimum, Use 3 because we offset the output one
4481+
* byte to the right */
4482+
size += 3;
44854483
char * tmpbuf;
44864484
Newx(tmpbuf, size, char);
44874485

4488-
scan_ident(s, tmpbuf, size, FALSE);
4486+
/* scan_ident doesn't return the sigil, but pad_findmy_pv wants it */
4487+
scan_ident(s, tmpbuf + 1, size - 1, FALSE);
4488+
tmpbuf[0] = s[0];
4489+
4490+
Size_t len = strlen(tmpbuf) - 1; /* Doesn't include sigil */
44894491

4490-
Size_t len = strlen(tmpbuf);
4491-
if (! gv_fetchpvn_flags(tmpbuf, len,
4492+
PADOFFSET slot = pad_findmy_pv(tmpbuf, 0);
4493+
if ( slot == NOT_IN_PAD
4494+
&& ! gv_fetchpvn_flags(tmpbuf + 1, len,
44924495
(is_utf8) ? SVf_UTF8 : 0,
44934496
(s[0] == '@')
44944497
? SVt_PVAV

0 commit comments

Comments
 (0)