-
Notifications
You must be signed in to change notification settings - Fork 589
toke.c dont call libc's memcmp() to test 1 byte in Perl_scan_str() #23533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bulk88
wants to merge
1
commit into
Perl:blead
Choose a base branch
from
bulk88:toke_scan_str_no_1_byte_memcmps
base: blead
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11645,9 +11645,12 @@ Perl_scan_str(pTHX_ char *start, int keep_bracketed_quoted, int keep_delims, int | |
open_delim_str[0] = *s; | ||
delim_byte_len = 1; | ||
} | ||
else { | ||
else { /* don't let delim_byte_len escape and be a volatile mem addr */ | ||
STRLEN delim_byte_len_tmp; | ||
open_delim_code = utf8_to_uv_or_die((U8*)s, (U8*)PL_bufend, | ||
&delim_byte_len); | ||
&delim_byte_len_tmp); | ||
/* CC can safely keep delim_byte_len in a register until the end */ | ||
delim_byte_len = delim_byte_len_tmp; | ||
if (UNLIKELY(! is_grapheme((U8 *) start, | ||
(U8 *) s, | ||
(U8 *) PL_bufend, | ||
|
@@ -11764,9 +11767,9 @@ Perl_scan_str(pTHX_ char *start, int keep_bracketed_quoted, int keep_delims, int | |
s += delim_byte_len; | ||
for (;;) { | ||
/* extend sv if need be */ | ||
SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); | ||
char * pv = SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); | ||
/* set 'to' to the next character in the sv's string */ | ||
to = SvPVX(sv)+SvCUR(sv); | ||
to = pv + SvCUR(sv); | ||
|
||
/* read until we run out of string, or we find the closing delimiter */ | ||
while (s < PL_bufend) { | ||
|
@@ -11784,18 +11787,22 @@ Perl_scan_str(pTHX_ char *start, int keep_bracketed_quoted, int keep_delims, int | |
* discard those that escape the closing delimiter, just | ||
* discard this one */ | ||
if ( ! keep_bracketed_quoted | ||
&& ( memEQ(s + 1, open_delim_str, delim_byte_len) | ||
|| ( PL_multi_open == PL_multi_close | ||
&& re_reparse && s[1] == '\\') | ||
|| memEQ(s + 1, close_delim_str, delim_byte_len))) | ||
{ | ||
&& ((delim_byte_len == 1 | ||
? (s[1] == open_delim_str[0] | ||
|| s[1] == close_delim_str[0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unhappy that this and elsewhere reformats code that corresponds to Perl Best Practices to not conform. |
||
: (memEQ(s + 1, open_delim_str, delim_byte_len) | ||
|| memEQ(s + 1, close_delim_str, delim_byte_len))) | ||
|| (PL_multi_open == PL_multi_close | ||
&& re_reparse && s[1] == '\\'))) { | ||
s++; | ||
} | ||
else /* any other escapes are simply copied straight through */ | ||
*to++ = *s++; | ||
} | ||
else if ( s < PL_bufend - (delim_byte_len - 1) | ||
&& memEQ(s, close_delim_str, delim_byte_len) | ||
&& (delim_byte_len == 1 | ||
? s[0] == close_delim_str[0] | ||
: memEQ(s, close_delim_str, delim_byte_len)) | ||
&& --brackets <= 0) | ||
{ | ||
/* Found unescaped closing delimiter, unnested if we care about | ||
|
@@ -11824,7 +11831,9 @@ Perl_scan_str(pTHX_ char *start, int keep_bracketed_quoted, int keep_delims, int | |
/* No nesting if open eq close */ | ||
else if ( PL_multi_open != PL_multi_close | ||
&& s < PL_bufend - (delim_byte_len - 1) | ||
&& memEQ(s, open_delim_str, delim_byte_len)) | ||
&& (delim_byte_len == 1 | ||
? s[0] == open_delim_str[0] | ||
: memEQ(s, open_delim_str, delim_byte_len))) | ||
{ | ||
brackets++; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, but I think it would be better in a separate commit; one that wouldn't be reverted if the rest turned out to be.