mirror of
https://github.com/python/cpython.git
synced 2025-08-09 11:29:45 +00:00
[3.12] gh-109596: Ensure repeated rules in the grammar are not allowed and fix incorrect soft keywords (GH-109606). (#109752)
(cherry picked from commit b28ffaa193
)
This commit is contained in:
parent
c7cbd82e62
commit
f6cb2e4815
7 changed files with 1781 additions and 1797 deletions
|
@ -309,21 +309,6 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
|
|||
end_col_offset = p->tok->cur - p->tok->line_start;
|
||||
}
|
||||
|
||||
if (p->start_rule == Py_fstring_input) {
|
||||
const char *fstring_msg = "f-string: ";
|
||||
Py_ssize_t len = strlen(fstring_msg) + strlen(errmsg);
|
||||
|
||||
char *new_errmsg = PyMem_Malloc(len + 1); // Lengths of both strings plus NULL character
|
||||
if (!new_errmsg) {
|
||||
return (void *) PyErr_NoMemory();
|
||||
}
|
||||
|
||||
// Copy both strings into new buffer
|
||||
memcpy(new_errmsg, fstring_msg, strlen(fstring_msg));
|
||||
memcpy(new_errmsg + strlen(fstring_msg), errmsg, strlen(errmsg));
|
||||
new_errmsg[len] = 0;
|
||||
errmsg = new_errmsg;
|
||||
}
|
||||
errstr = PyUnicode_FromFormatV(errmsg, va);
|
||||
if (!errstr) {
|
||||
goto error;
|
||||
|
@ -362,11 +347,6 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
|
|||
}
|
||||
}
|
||||
|
||||
if (p->start_rule == Py_fstring_input) {
|
||||
col_offset -= p->starting_col_offset;
|
||||
end_col_offset -= p->starting_col_offset;
|
||||
}
|
||||
|
||||
Py_ssize_t col_number = col_offset;
|
||||
Py_ssize_t end_col_number = end_col_offset;
|
||||
|
||||
|
@ -397,17 +377,11 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
|
|||
|
||||
Py_DECREF(errstr);
|
||||
Py_DECREF(value);
|
||||
if (p->start_rule == Py_fstring_input) {
|
||||
PyMem_Free((void *)errmsg);
|
||||
}
|
||||
return NULL;
|
||||
|
||||
error:
|
||||
Py_XDECREF(errstr);
|
||||
Py_XDECREF(error_line);
|
||||
if (p->start_rule == Py_fstring_input) {
|
||||
PyMem_Free((void *)errmsg);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue