diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2025-01-25 13:00:23 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-25 13:00:23 +0000 |
commit | c39ae8922bad3e5ceeafa05891536c1584b6f3db (patch) | |
tree | 04eb746a11e49b7e2da5fc9992bffc0b0e39cbfb /Python | |
parent | 9e52e553f4a906c120f807e940891f7325011b67 (diff) | |
download | cpython-c39ae8922bad3e5ceeafa05891536c1584b6f3db.tar.gz cpython-c39ae8922bad3e5ceeafa05891536c1584b6f3db.zip |
gh-128799: Add frame of except* to traceback when wrapping a naked exception (#128971)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bytecodes.c | 2 | ||||
-rw-r--r-- | Python/ceval.c | 14 | ||||
-rw-r--r-- | Python/executor_cases.c.h | 2 | ||||
-rw-r--r-- | Python/generated_cases.c.h | 2 |
4 files changed, 15 insertions, 5 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c index b70ed7f4d10..12aae969340 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -2717,7 +2717,7 @@ dummy_func( PyObject *match_o = NULL; PyObject *rest_o = NULL; - int res = _PyEval_ExceptionGroupMatch(exc_value, match_type, + int res = _PyEval_ExceptionGroupMatch(frame, exc_value, match_type, &match_o, &rest_o); DECREF_INPUTS(); ERROR_IF(res < 0, error); diff --git a/Python/ceval.c b/Python/ceval.c index 5469874e978..100f99ea8e3 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -27,6 +27,7 @@ #include "pycore_range.h" // _PyRangeIterObject #include "pycore_setobject.h" // _PySet_Update() #include "pycore_sliceobject.h" // _PyBuildSlice_ConsumeRefs +#include "pycore_traceback.h" // _PyTraceBack_FromFrame #include "pycore_tuple.h" // _PyTuple_ITEMS() #include "pycore_uop_ids.h" // Uops #include "pycore_pyerrors.h" @@ -2074,8 +2075,8 @@ raise_error: */ int -_PyEval_ExceptionGroupMatch(PyObject* exc_value, PyObject *match_type, - PyObject **match, PyObject **rest) +_PyEval_ExceptionGroupMatch(_PyInterpreterFrame *frame, PyObject* exc_value, + PyObject *match_type, PyObject **match, PyObject **rest) { if (Py_IsNone(exc_value)) { *match = Py_NewRef(Py_None); @@ -2101,6 +2102,15 @@ _PyEval_ExceptionGroupMatch(PyObject* exc_value, PyObject *match_type, if (wrapped == NULL) { return -1; } + PyFrameObject *f = _PyFrame_GetFrameObject(frame); + if (f != NULL) { + PyObject *tb = _PyTraceBack_FromFrame(NULL, f); + if (tb == NULL) { + return -1; + } + PyException_SetTraceback(wrapped, tb); + Py_DECREF(tb); + } *match = wrapped; } *rest = Py_NewRef(Py_None); diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index d336f73c4a2..b253850e78d 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -3452,7 +3452,7 @@ PyObject *match_o = NULL; PyObject *rest_o = NULL; _PyFrame_SetStackPointer(frame, stack_pointer); - int res = _PyEval_ExceptionGroupMatch(exc_value, match_type, + int res = _PyEval_ExceptionGroupMatch(frame, exc_value, match_type, &match_o, &rest_o); stack_pointer = _PyFrame_GetStackPointer(frame); PyStackRef_CLOSE(exc_value_st); diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 4fb3ce6f6da..027849180a8 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -3201,7 +3201,7 @@ PyObject *match_o = NULL; PyObject *rest_o = NULL; _PyFrame_SetStackPointer(frame, stack_pointer); - int res = _PyEval_ExceptionGroupMatch(exc_value, match_type, + int res = _PyEval_ExceptionGroupMatch(frame, exc_value, match_type, &match_o, &rest_o); stack_pointer = _PyFrame_GetStackPointer(frame); PyStackRef_CLOSE(exc_value_st); |