From a822705d83797d5bc9cc4e0d5d90d2df383275cf Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Mon, 13 Nov 2023 21:05:17 +0800 Subject: [PATCH] gh-106905: avoid incorrect SystemError about recursion depth mismatch (GH-106906) * gh-106905: avoid incorrect SystemError about recursion depth mismatch * Update Misc/NEWS.d/next/Core and Builtins/2023-07-20-11-41-16.gh-issue-106905.AyZpuB.rst --------- (cherry picked from commit 1447af797048e62049d00bbd96d8daee3929f527) Co-authored-by: Markus Mohrhard Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Serhiy Storchaka --- .../2023-07-20-11-41-16.gh-issue-106905.AyZpuB.rst | 1 + Parser/asdl_c.py | 1 + Python/Python-ast.c | 14 ++++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-07-20-11-41-16.gh-issue-106905.AyZpuB.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-07-20-11-41-16.gh-issue-106905.AyZpuB.rst b/Misc/NEWS.d/next/Core and Builtins/2023-07-20-11-41-16.gh-issue-106905.AyZpuB.rst new file mode 100644 index 00000000000000..73b75833a71284 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-07-20-11-41-16.gh-issue-106905.AyZpuB.rst @@ -0,0 +1 @@ +Fix incorrect SystemError about AST constructor recursion depth mismatch. diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index aa093b30a74d70..afea6d1ace1cd8 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -1283,6 +1283,7 @@ def func_end(self): self.emit("state->recursion_depth--;", 1) self.emit("return result;", 1) self.emit("failed:", 0) + self.emit("state->recursion_depth--;", 1) self.emit("Py_XDECREF(value);", 1) self.emit("Py_XDECREF(result);", 1) self.emit("return NULL;", 1) diff --git a/Python/Python-ast.c b/Python/Python-ast.c index f8bb6124fa4878..e75505ac0b35bf 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -3847,6 +3847,7 @@ ast2obj_mod(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -4452,6 +4453,7 @@ ast2obj_stmt(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -4935,6 +4937,7 @@ ast2obj_expr(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -5074,6 +5077,7 @@ ast2obj_comprehension(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -5139,6 +5143,7 @@ ast2obj_excepthandler(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -5199,6 +5204,7 @@ ast2obj_arguments(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -5259,6 +5265,7 @@ ast2obj_arg(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -5314,6 +5321,7 @@ ast2obj_keyword(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -5369,6 +5377,7 @@ ast2obj_alias(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -5404,6 +5413,7 @@ ast2obj_withitem(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -5444,6 +5454,7 @@ ast2obj_match_case(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -5605,6 +5616,7 @@ ast2obj_pattern(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -5644,6 +5656,7 @@ ast2obj_type_ignore(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL; @@ -5723,6 +5736,7 @@ ast2obj_type_param(struct ast_state *state, void* _o) state->recursion_depth--; return result; failed: + state->recursion_depth--; Py_XDECREF(value); Py_XDECREF(result); return NULL;