mirror of https://github.com/python/cpython
gh-108179: Add error message for parser stack overflows (#108256)
This commit is contained in:
parent
7f87ebbc3f
commit
86617518c4
|
@ -2335,7 +2335,7 @@ while 1:
|
||||||
source = "-" * 100000 + "4"
|
source = "-" * 100000 + "4"
|
||||||
for mode in ["exec", "eval", "single"]:
|
for mode in ["exec", "eval", "single"]:
|
||||||
with self.subTest(mode=mode):
|
with self.subTest(mode=mode):
|
||||||
with self.assertRaises(MemoryError):
|
with self.assertRaisesRegex(MemoryError, r"too complex"):
|
||||||
compile(source, "<string>", mode)
|
compile(source, "<string>", mode)
|
||||||
|
|
||||||
@support.cpython_only
|
@support.cpython_only
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -166,6 +166,8 @@ void *_PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
|
||||||
Py_ssize_t end_lineno, Py_ssize_t end_col_offset,
|
Py_ssize_t end_lineno, Py_ssize_t end_col_offset,
|
||||||
const char *errmsg, va_list va);
|
const char *errmsg, va_list va);
|
||||||
void _Pypegen_set_syntax_error(Parser* p, Token* last_token);
|
void _Pypegen_set_syntax_error(Parser* p, Token* last_token);
|
||||||
|
void _Pypegen_stack_overflow(Parser *p);
|
||||||
|
|
||||||
Py_LOCAL_INLINE(void *)
|
Py_LOCAL_INLINE(void *)
|
||||||
RAISE_ERROR_KNOWN_LOCATION(Parser *p, PyObject *errtype,
|
RAISE_ERROR_KNOWN_LOCATION(Parser *p, PyObject *errtype,
|
||||||
Py_ssize_t lineno, Py_ssize_t col_offset,
|
Py_ssize_t lineno, Py_ssize_t col_offset,
|
||||||
|
|
|
@ -454,3 +454,11 @@ _Pypegen_set_syntax_error(Parser* p, Token* last_token) {
|
||||||
// generic SyntaxError we just raised if errors are found.
|
// generic SyntaxError we just raised if errors are found.
|
||||||
_PyPegen_tokenize_full_source_to_check_for_errors(p);
|
_PyPegen_tokenize_full_source_to_check_for_errors(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_Pypegen_stack_overflow(Parser *p)
|
||||||
|
{
|
||||||
|
p->error_indicator = 1;
|
||||||
|
PyErr_SetString(PyExc_MemoryError,
|
||||||
|
"Parser stack overflowed - Python source too complex to parse");
|
||||||
|
}
|
||||||
|
|
|
@ -375,8 +375,7 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
|
||||||
def add_level(self) -> None:
|
def add_level(self) -> None:
|
||||||
self.print("if (p->level++ == MAXSTACK) {")
|
self.print("if (p->level++ == MAXSTACK) {")
|
||||||
with self.indent():
|
with self.indent():
|
||||||
self.print("p->error_indicator = 1;")
|
self.print("_Pypegen_stack_overflow(p);")
|
||||||
self.print("PyErr_NoMemory();")
|
|
||||||
self.print("}")
|
self.print("}")
|
||||||
|
|
||||||
def remove_level(self) -> None:
|
def remove_level(self) -> None:
|
||||||
|
|
Loading…
Reference in New Issue