summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-02-08 09:31:12 (GMT)
committerGitHub <noreply@github.com>2023-02-08 09:31:12 (GMT)
commitfeec49c40736fc05626a183a8d14c4ebbea5ae28 (patch)
tree5af6110eca8c2a21a9f699b40a87e7567c603e98 /Parser
parent027adf42cd85db41fee05b0a40d89ef822876c97 (diff)
downloadcpython-feec49c40736fc05626a183a8d14c4ebbea5ae28.zip
cpython-feec49c40736fc05626a183a8d14c4ebbea5ae28.tar.gz
cpython-feec49c40736fc05626a183a8d14c4ebbea5ae28.tar.bz2
GH-101578: Normalize the current exception (GH-101607)
* Make sure that the current exception is always normalized. * Remove redundant type and traceback fields for the current exception. * Add new API functions: PyErr_GetRaisedException, PyErr_SetRaisedException * Add new API functions: PyException_GetArgs, PyException_SetArgs
Diffstat (limited to 'Parser')
-rw-r--r--Parser/pegen.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c
index d84e068..94dd9de 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -643,13 +643,10 @@ _PyPegen_number_token(Parser *p)
PyThreadState *tstate = _PyThreadState_GET();
// The only way a ValueError should happen in _this_ code is via
// PyLong_FromString hitting a length limit.
- if (tstate->curexc_type == PyExc_ValueError &&
- tstate->curexc_value != NULL) {
- PyObject *type, *value, *tb;
- // This acts as PyErr_Clear() as we're replacing curexc.
- PyErr_Fetch(&type, &value, &tb);
- Py_XDECREF(tb);
- Py_DECREF(type);
+ if (tstate->current_exception != NULL &&
+ Py_TYPE(tstate->current_exception) == (PyTypeObject *)PyExc_ValueError
+ ) {
+ PyObject *exc = PyErr_GetRaisedException();
/* Intentionally omitting columns to avoid a wall of 1000s of '^'s
* on the error message. Nobody is going to overlook their huge
* numeric literal once given the line. */
@@ -659,8 +656,8 @@ _PyPegen_number_token(Parser *p)
t->end_lineno, -1 /* end_col_offset */,
"%S - Consider hexadecimal for huge integer literals "
"to avoid decimal conversion limits.",
- value);
- Py_DECREF(value);
+ exc);
+ Py_DECREF(exc);
}
return NULL;
}