From d5a31706c6273cbf24b64ac463a51f60460e27b8 Mon Sep 17 00:00:00 2001 From: ijl Date: Thu, 1 Dec 2022 15:25:56 +0000 Subject: [PATCH] Define _PyErr_ChainExceptions() FFI for CPython This appears to be the only way to chain exceptions via the FFI. It was introduced prior to CPython 3.7. It has some description of usage in PEP 490. There was a discussion of whether it should be made stable in BPO 44938. --- newsfragments/2788.added.md | 1 + pyo3-ffi/src/cpython/pyerrors.rs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 newsfragments/2788.added.md diff --git a/newsfragments/2788.added.md b/newsfragments/2788.added.md new file mode 100644 index 00000000..2c744cef --- /dev/null +++ b/newsfragments/2788.added.md @@ -0,0 +1 @@ +Define `_PyErr_ChainExceptions()` FFI for CPython. diff --git a/pyo3-ffi/src/cpython/pyerrors.rs b/pyo3-ffi/src/cpython/pyerrors.rs index afc5ae93..abbffc0b 100644 --- a/pyo3-ffi/src/cpython/pyerrors.rs +++ b/pyo3-ffi/src/cpython/pyerrors.rs @@ -150,6 +150,11 @@ pub struct PyStopIterationObject { pub value: *mut PyObject, } +extern "C" { + #[cfg(not(PyPy))] + pub fn _PyErr_ChainExceptions(typ: *mut PyObject, val: *mut PyObject, tb: *mut PyObject); +} + // skipped PyNameErrorObject // skipped PyAttributeErrorObject @@ -160,8 +165,6 @@ pub struct PyStopIterationObject { // skipped _PyErr_GetTopmostException // skipped _PyErr_GetExcInfo -// skipped _PyErr_ChainExceptions - // skipped PyErr_SetFromErrnoWithUnicodeFilename // skipped _PyErr_FormatFromCause