summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-06-08 19:25:17 (GMT)
committerGitHub <noreply@github.com>2021-06-08 19:25:17 (GMT)
commit2a8d7122e0ceeb56b716cff7f8f31f13c26ad691 (patch)
treefce910543607885f4a4a519d013562125ee10571 /Parser
parentbd6f0d3eadfe5623657db6aeb69b94d21f86f4a0 (diff)
downloadcpython-2a8d7122e0ceeb56b716cff7f8f31f13c26ad691.zip
cpython-2a8d7122e0ceeb56b716cff7f8f31f13c26ad691.tar.gz
cpython-2a8d7122e0ceeb56b716cff7f8f31f13c26ad691.tar.bz2
bpo-44335: Ensure the tokenizer doesn't go into Python with the error set (GH-26608)
(cherry picked from commit bafe0aade5741ab0d13143ee261711fdd65e8a1f) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Parser')
-rw-r--r--Parser/pegen.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c
index c69a042..42a9922 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -1251,9 +1251,14 @@ _PyPegen_check_tokenizer_errors(Parser *p) {
return 0;
}
+ PyObject *type, *value, *traceback;
+ PyErr_Fetch(&type, &value, &traceback);
+
Token *current_token = p->known_err_token != NULL ? p->known_err_token : p->tokens[p->fill - 1];
Py_ssize_t current_err_line = current_token->lineno;
+ int ret = 0;
+
for (;;) {
const char *start;
const char *end;
@@ -1262,9 +1267,9 @@ _PyPegen_check_tokenizer_errors(Parser *p) {
if (p->tok->level != 0) {
int error_lineno = p->tok->parenlinenostack[p->tok->level-1];
if (current_err_line > error_lineno) {
- PyErr_Clear();
raise_unclosed_parentheses_error(p);
- return -1;
+ ret = -1;
+ goto exit;
}
}
break;
@@ -1276,7 +1281,16 @@ _PyPegen_check_tokenizer_errors(Parser *p) {
break;
}
- return 0;
+
+exit:
+ if (PyErr_Occurred()) {
+ Py_XDECREF(value);
+ Py_XDECREF(type);
+ Py_XDECREF(traceback);
+ } else {
+ PyErr_Restore(type, value, traceback);
+ }
+ return ret;
}
void *