diff options
author | Mark Shannon <mark@hotpy.org> | 2023-02-08 09:31:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-08 09:31:12 (GMT) |
commit | feec49c40736fc05626a183a8d14c4ebbea5ae28 (patch) | |
tree | 5af6110eca8c2a21a9f699b40a87e7567c603e98 /Objects/object.c | |
parent | 027adf42cd85db41fee05b0a40d89ef822876c97 (diff) | |
download | cpython-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 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Objects/object.c b/Objects/object.c index e940222..7817c04 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -2416,10 +2416,10 @@ _Py_Dealloc(PyObject *op) destructor dealloc = type->tp_dealloc; #ifdef Py_DEBUG PyThreadState *tstate = _PyThreadState_GET(); - PyObject *old_exc_type = tstate != NULL ? tstate->curexc_type : NULL; + PyObject *old_exc = tstate != NULL ? tstate->current_exception : NULL; // Keep the old exception type alive to prevent undefined behavior // on (tstate->curexc_type != old_exc_type) below - Py_XINCREF(old_exc_type); + Py_XINCREF(old_exc); // Make sure that type->tp_name remains valid Py_INCREF(type); #endif @@ -2432,12 +2432,12 @@ _Py_Dealloc(PyObject *op) #ifdef Py_DEBUG // gh-89373: The tp_dealloc function must leave the current exception // unchanged. - if (tstate != NULL && tstate->curexc_type != old_exc_type) { + if (tstate != NULL && tstate->current_exception != old_exc) { const char *err; - if (old_exc_type == NULL) { + if (old_exc == NULL) { err = "Deallocator of type '%s' raised an exception"; } - else if (tstate->curexc_type == NULL) { + else if (tstate->current_exception == NULL) { err = "Deallocator of type '%s' cleared the current exception"; } else { @@ -2448,7 +2448,7 @@ _Py_Dealloc(PyObject *op) } _Py_FatalErrorFormat(__func__, err, type->tp_name); } - Py_XDECREF(old_exc_type); + Py_XDECREF(old_exc); Py_DECREF(type); #endif } |