diff --git a/newsfragments/5989.added.md b/newsfragments/5989.added.md new file mode 100644 index 00000000000..7dac86a49dc --- /dev/null +++ b/newsfragments/5989.added.md @@ -0,0 +1,13 @@ +Add `PyNameErrorObject` and `PyAttributeErrorObject` structs, and the following API functions: + +* pub fn PySignal_SetWakeupFd(fd: c_int) -> c_int +* pub fn PyErr_SyntaxLocationObject(filename: *mut PyObject, lineno: c_int, col_offset: c_int) +* pub fn PyErr_RangedSyntaxLocationObject + filename: *mut PyObject, + lineno: c_int, + col_offset: c_int, + end_lineno: c_int, + end_col_offset: c_int, + ) +* pub fn PyErr_ProgramTextObject(filename: *mut PyObject, lineno: c_int) -> *mut PyObject +* pub static PyExc_PythonFinalizationError: *mut PyObject diff --git a/pyo3-ffi/src/cpython/pyerrors.rs b/pyo3-ffi/src/cpython/pyerrors.rs index c9831669ac7..c90d440def8 100644 --- a/pyo3-ffi/src/cpython/pyerrors.rs +++ b/pyo3-ffi/src/cpython/pyerrors.rs @@ -1,6 +1,7 @@ use crate::PyObject; #[cfg(not(any(PyPy, GraalPy)))] use crate::Py_ssize_t; +use std::ffi::c_int; #[repr(C)] #[derive(Debug)] @@ -154,37 +155,69 @@ pub struct PyStopIterationObject { pub value: *mut PyObject, } -// skipped _PyErr_ChainExceptions +#[repr(C)] +#[derive(Debug)] +pub struct PyNameErrorObject { + pub ob_base: PyObject, + #[cfg(not(PyPy))] + pub dict: *mut PyObject, + #[cfg(not(PyPy))] + pub args: *mut PyObject, + #[cfg(all(Py_3_11, not(PyPy)))] + pub notes: *mut PyObject, + #[cfg(not(PyPy))] + pub traceback: *mut PyObject, + #[cfg(not(PyPy))] + pub context: *mut PyObject, + #[cfg(not(PyPy))] + pub cause: *mut PyObject, + #[cfg(not(PyPy))] + pub suppress_context: char, + pub name: *mut PyObject, +} -// skipped PyNameErrorObject -// skipped PyAttributeErrorObject +#[repr(C)] +#[derive(Debug)] +pub struct PyAttributeErrorObject { + pub ob_base: PyObject, + #[cfg(not(PyPy))] + pub dict: *mut PyObject, + #[cfg(not(PyPy))] + pub args: *mut PyObject, + #[cfg(all(Py_3_11, not(PyPy)))] + pub notes: *mut PyObject, + #[cfg(not(PyPy))] + pub traceback: *mut PyObject, + #[cfg(not(PyPy))] + pub context: *mut PyObject, + #[cfg(not(PyPy))] + pub cause: *mut PyObject, + #[cfg(not(PyPy))] + pub suppress_context: char, + pub obj: *mut PyObject, + pub name: *mut PyObject, +} // skipped PyEnvironmentErrorObject // skipped PyWindowsErrorObject -// skipped _PyErr_SetKeyError -// skipped _PyErr_GetTopmostException -// skipped _PyErr_GetExcInfo - -// skipped PyErr_SetFromErrnoWithUnicodeFilename - -// skipped _PyErr_FormatFromCause - -// skipped PyErr_SetFromWindowsErrWithUnicodeFilename -// skipped PyErr_SetExcFromWindowsErrWithUnicodeFilename - -// skipped _PyErr_TrySetFromCause - -// skipped PySignal_SetWakeupFd -// skipped _PyErr_CheckSignals - -// skipped PyErr_SyntaxLocationObject -// skipped PyErr_RangedSyntaxLocationObject -// skipped PyErr_ProgramTextObject +// skipped _PyErr_ChainExceptions +// skipped PyUnstable_Exc_PrepReraiseStar -// skipped _PyErr_ProgramDecodedTextObject -// skipped _PyUnicodeTranslateError_Create -// skipped _PyErr_WriteUnraisableMsg -// skipped _Py_FatalErrorFunc // skipped _Py_FatalErrorFormat // skipped Py_FatalError + +extern_libpython! { + pub fn PySignal_SetWakeupFd(fd: c_int) -> c_int; + pub fn PyErr_SyntaxLocationObject(filename: *mut PyObject, lineno: c_int, col_offset: c_int); + #[cfg(Py_3_10)] + pub fn PyErr_RangedSyntaxLocationObject( + filename: *mut PyObject, + lineno: c_int, + col_offset: c_int, + end_lineno: c_int, + end_col_offset: c_int, + ); + pub fn PyErr_ProgramTextObject(filename: *mut PyObject, lineno: c_int) -> *mut PyObject; + pub static PyExc_PythonFinalizationError: *mut PyObject; +}