8000 bpo-40334: Fix error location upon parsing an invalid string literal by lysnikolaou · Pull Request #19962 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-40334: Fix error location upon parsing an invalid string literal #19962

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

Merged
merged 5 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Call PyBytes_AsString in _PyPegen_parsestr instead of _PyPegen_concat…
…enate_strings
  • Loading branch information
lysnikolaou committed May 6, 2020
commit 8b5f2e8258b835cfed1b39fc5dd77686c6bf0e54
7 changes: 6 additions & 1 deletion Parser/pegen/parse_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,14 @@ decode_bytes_with_escapes(Parser *p, const char *s, Py_ssize_t len, Token *t)
If the string is an f-string, set *fstr and *fstrlen to the unparsed
string object. Return 0 if no errors occurred. */
int
_PyPegen_parsestr(Parser *p, const char *s, int *bytesmode, int *rawmode, PyObject **result,
_PyPegen_parsestr(Parser *p, int *bytesmode, int *rawmode, PyObject **result,
const char **fstr, Py_ssize_t *fstrlen, Token *t)
{
const char *s = PyBytes_AsString(t->bytes);
if (s == NULL) {
return -1;
}

size_t len;
int quote = Py_CHARMASK(*s);
int fmode = 0;
Expand Down
4 changes: 2 additions & 2 deletions Parser/pegen/parse_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ typedef struct {
} FstringParser;

void _PyPegen_FstringParser_Init(FstringParser *);
int _PyPegen_parsestr(Parser *, const char *, int *, int *, PyObject **,
const char **, Py_ssize_t *, Token *);
int _PyPegen_parsestr(Parser *, int *, int *, PyObject **,
const char **, Py_ssize_t *, Token *);
int _PyPegen_FstringParser_ConcatFstring(Parser *, FstringParser *, const char **,
const char *, int, int, Token *, Token *,
Token *);
Expand Down
7 changes: 1 addition & 6 deletions Parser/pegen/pegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1972,12 +1972,7 @@ _PyPegen_concatenate_strings(Parser *p, asdl_seq *strings)
const char *fstr;
Py_ssize_t fstrlen = -1;

char *this_str = PyBytes_AsString(t->bytes);
if (!this_str) {
goto error;
}

if (_PyPegen_parsestr(p, this_str, &this_bytesmode, &this_rawmode, &s, &fstr, &fstrlen, t) != 0) {
if (_PyPegen_parsestr(p, &this_bytesmode, &this_rawmode, &s, &fstr, &fstrlen, t) != 0) {
goto error;
}

Expand Down
0