From 78cdc6d6ad8575dfef64d0d2055de4af93be7270 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Thu, 2 Jun 2022 16:30:07 +0100 Subject: [PATCH] ffi: many fixes caught by pyo3-ffi-check --- CHANGELOG.md | 6 + pyo3-ffi/src/compile.rs | 4 +- pyo3-ffi/src/cpython/compile.rs | 9 +- pyo3-ffi/src/{ => cpython}/genobject.rs | 6 +- pyo3-ffi/src/cpython/mod.rs | 4 + pyo3-ffi/src/cpython/object.rs | 385 ++++++++++++------------ pyo3-ffi/src/cpython/pyerrors.rs | 111 +++++++ pyo3-ffi/src/cpython/pystate.rs | 11 +- pyo3-ffi/src/lib.rs | 4 - pyo3-ffi/src/pyerrors.rs | 71 ----- pyo3-ffi/src/pythonrun.rs | 10 - 11 files changed, 340 insertions(+), 281 deletions(-) rename pyo3-ffi/src/{ => cpython}/genobject.rs (92%) create mode 100644 pyo3-ffi/src/cpython/pyerrors.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index afdcbe59..8fb9ded6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add macro `append_to_inittab`. [#2377](https://github.com/PyO3/pyo3/pull/2377) - Add FFI definition `PyFrame_GetCode`. [#2406](https://github.com/PyO3/pyo3/pull/2406) - Added `PyCode` and `PyFrame` high level objects. [#2408](https://github.com/PyO3/pyo3/pull/2408) +- Add FFI definitions `Py_fstring_input`, `sendfunc`, and `_PyErr_StackItem`. [#2423](https://github.com/PyO3/pyo3/pull/2423) ### Changed @@ -40,6 +41,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix compile failure when using `#[pyo3(from_py_with = "pouf")]` in on a field in a `#[derive(FromPyObject)]` struct. [#2414](https://github.com/PyO3/pyo3/pull/2414) - Fix FFI definitions `_PyDateTime_BaseTime` lacking leading underscores in their names. [#2421](https://github.com/PyO3/pyo3/pull/2421) - Remove FFI definition `PyArena` on Python 3.10 and up. [#2421](https://github.com/PyO3/pyo3/pull/2421) +- Fix FFI definition `PyCompilerFlags` missing member `cf_feature_version` on Python 3.8 and up. [#2423](https://github.com/PyO3/pyo3/pull/2423) +- Fix FFI definition `PyAsyncMethods` missing member `am_send` on Python 3.10 and up. [#2423](https://github.com/PyO3/pyo3/pull/2423) +- Fix FFI definition `PyGenObject` having multiple incorrect members on various Python versions. [#2423](https://github.com/PyO3/pyo3/pull/2423) +- Fix FFI definition `PySyntaxErrorObject` missing members `end_lineno` and `end_offset` on Python 3.10 and up. [#2423](https://github.com/PyO3/pyo3/pull/2423) +- Fix FFI definition `PyHeapTypeObject` missing member `ht_module` on Python 3.9 and up. [#2423](https://github.com/PyO3/pyo3/pull/2423) ## [0.16.5] - 2022-05-15 diff --git a/pyo3-ffi/src/compile.rs b/pyo3-ffi/src/compile.rs index 7f6fe3fe..189a1a8b 100644 --- a/pyo3-ffi/src/compile.rs +++ b/pyo3-ffi/src/compile.rs @@ -5,4 +5,6 @@ pub const Py_file_input: c_int = 257; pub const Py_eval_input: c_int = 258; #[cfg(Py_3_8)] pub const Py_func_type_input: c_int = 345; -// skipped Py_fstring_input + +#[cfg(Py_3_9)] +pub const Py_fstring_input: c_int = 800; diff --git a/pyo3-ffi/src/cpython/compile.rs b/pyo3-ffi/src/cpython/compile.rs index aa459d33..f7aa7f8f 100644 --- a/pyo3-ffi/src/cpython/compile.rs +++ b/pyo3-ffi/src/cpython/compile.rs @@ -20,7 +20,14 @@ use std::os::raw::c_int; // skipped non-limited PyCF_ALLOW_TOP_LEVEL_AWAIT // skipped non-limited PyCF_COMPILE_MASK -// skipped non-limited PyCompilerFlags +#[repr(C)] +#[derive(Copy, Clone)] +pub struct PyCompilerFlags { + pub cf_flags: c_int, + #[cfg(Py_3_8)] + pub cf_feature_version: c_int, +} + // skipped non-limited _PyCompilerFlags_INIT #[repr(C)] diff --git a/pyo3-ffi/src/genobject.rs b/pyo3-ffi/src/cpython/genobject.rs similarity index 92% rename from pyo3-ffi/src/genobject.rs rename to pyo3-ffi/src/cpython/genobject.rs index c13edb07..a9807118 100644 --- a/pyo3-ffi/src/genobject.rs +++ b/pyo3-ffi/src/cpython/genobject.rs @@ -1,6 +1,6 @@ use crate::object::*; use crate::pyport::Py_ssize_t; -use crate::PyFrameObject; +use crate::{PyFrameObject, _PyErr_StackItem}; use std::os::raw::c_int; #[repr(C)] @@ -13,9 +13,13 @@ pub struct PyGenObject { pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, pub gi_frame: *mut PyFrameObject, + #[cfg(not(Py_3_10))] pub gi_running: c_int, pub gi_code: *mut PyObject, pub gi_weakreflist: *mut PyObject, + pub gi_name: *mut PyObject, + pub gi_qualname: *mut PyObject, + pub gi_exc_state: _PyErr_StackItem, } #[cfg_attr(windows, link(name = "pythonXY"))] diff --git a/pyo3-ffi/src/cpython/mod.rs b/pyo3-ffi/src/cpython/mod.rs index 332b2b22..976cda00 100644 --- a/pyo3-ffi/src/cpython/mod.rs +++ b/pyo3-ffi/src/cpython/mod.rs @@ -11,6 +11,7 @@ pub(crate) mod dictobject; // skipped fileobject.h // skipped fileutils.h pub(crate) mod frameobject; +pub(crate) mod genobject; pub(crate) mod import; #[cfg(all(Py_3_8, not(PyPy)))] pub(crate) mod initconfig; @@ -18,6 +19,7 @@ pub(crate) mod initconfig; pub(crate) mod listobject; pub(crate) mod object; pub(crate) mod pydebug; +pub(crate) mod pyerrors; #[cfg(all(Py_3_8, not(PyPy)))] pub(crate) mod pylifecycle; pub(crate) mod pymem; @@ -37,12 +39,14 @@ pub use self::compile::*; #[cfg(not(PyPy))] pub use self::dictobject::*; pub use self::frameobject::*; +pub use self::genobject::*; pub use self::import::*; #[cfg(all(Py_3_8, not(PyPy)))] pub use self::initconfig::*; pub use self::listobject::*; pub use self::object::*; pub use self::pydebug::*; +pub use self::pyerrors::*; #[cfg(all(Py_3_8, not(PyPy)))] pub use self::pylifecycle::*; pub use self::pymem::*; diff --git a/pyo3-ffi/src/cpython/object.rs b/pyo3-ffi/src/cpython/object.rs index 6201b925..86865245 100644 --- a/pyo3-ffi/src/cpython/object.rs +++ b/pyo3-ffi/src/cpython/object.rs @@ -1,5 +1,7 @@ -use crate::PyObject; -use std::os::raw::c_int; +use crate::object; +use crate::{PyObject, Py_ssize_t}; +use std::mem; +use std::os::raw::{c_char, c_int, c_uint, c_ulong, c_void}; // skipped _Py_NewReference // skipped _Py_ForgetReference @@ -118,209 +120,208 @@ pub type vectorcallfunc = unsafe extern "C" fn( kwnames: *mut PyObject, ) -> *mut PyObject; -mod typeobject { - use crate::object; - use crate::{PyObject, Py_ssize_t}; - use std::mem; - use std::os::raw::{c_char, c_int, c_uint, c_ulong, c_void}; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct PyNumberMethods { + pub nb_add: Option, + pub nb_subtract: Option, + pub nb_multiply: Option, + pub nb_remainder: Option, + pub nb_divmod: Option, + pub nb_power: Option, + pub nb_negative: Option, + pub nb_positive: Option, + pub nb_absolute: Option, + pub nb_bool: Option, + pub nb_invert: Option, + pub nb_lshift: Option, + pub nb_rshift: Option, + pub nb_and: Option, + pub nb_xor: Option, + pub nb_or: Option, + pub nb_int: Option, + pub nb_reserved: *mut c_void, + pub nb_float: Option, + pub nb_inplace_add: Option, + pub nb_inplace_subtract: Option, + pub nb_inplace_multiply: Option, + pub nb_inplace_remainder: Option, + pub nb_inplace_power: Option, + pub nb_inplace_lshift: Option, + pub nb_inplace_rshift: Option, + pub nb_inplace_and: Option, + pub nb_inplace_xor: Option, + pub nb_inplace_or: Option, + pub nb_floor_divide: Option, + pub nb_true_divide: Option, + pub nb_inplace_floor_divide: Option, + pub nb_inplace_true_divide: Option, + pub nb_index: Option, + pub nb_matrix_multiply: Option, + pub nb_inplace_matrix_multiply: Option, +} - #[repr(C)] - #[derive(Copy, Clone)] - pub struct PyNumberMethods { - pub nb_add: Option, - pub nb_subtract: Option, - pub nb_multiply: Option, - pub nb_remainder: Option, - pub nb_divmod: Option, - pub nb_power: Option, - pub nb_negative: Option, - pub nb_positive: Option, - pub nb_absolute: Option, - pub nb_bool: Option, - pub nb_invert: Option, - pub nb_lshift: Option, - pub nb_rshift: Option, - pub nb_and: Option, - pub nb_xor: Option, - pub nb_or: Option, - pub nb_int: Option, - pub nb_reserved: *mut c_void, - pub nb_float: Option, - pub nb_inplace_add: Option, - pub nb_inplace_subtract: Option, - pub nb_inplace_multiply: Option, - pub nb_inplace_remainder: Option, - pub nb_inplace_power: Option, - pub nb_inplace_lshift: Option, - pub nb_inplace_rshift: Option, - pub nb_inplace_and: Option, - pub nb_inplace_xor: Option, - pub nb_inplace_or: Option, - pub nb_floor_divide: Option, - pub nb_true_divide: Option, - pub nb_inplace_floor_divide: Option, - pub nb_inplace_true_divide: Option, - pub nb_index: Option, - pub nb_matrix_multiply: Option, - pub nb_inplace_matrix_multiply: Option, - } +#[repr(C)] +#[derive(Clone)] +pub struct PySequenceMethods { + pub sq_length: Option, + pub sq_concat: Option, + pub sq_repeat: Option, + pub sq_item: Option, + pub was_sq_slice: *mut c_void, + pub sq_ass_item: Option, + pub was_sq_ass_slice: *mut c_void, + pub sq_contains: Option, + pub sq_inplace_concat: Option, + pub sq_inplace_repeat: Option, +} - #[repr(C)] - #[derive(Clone)] - pub struct PySequenceMethods { - pub sq_length: Option, - pub sq_concat: Option, - pub sq_repeat: Option, - pub sq_item: Option, - pub was_sq_slice: *mut c_void, - pub sq_ass_item: Option, - pub was_sq_ass_slice: *mut c_void, - pub sq_contains: Option, - pub sq_inplace_concat: Option, - pub sq_inplace_repeat: Option, - } +#[repr(C)] +#[derive(Clone, Default)] +pub struct PyMappingMethods { + pub mp_length: Option, + pub mp_subscript: Option, + pub mp_ass_subscript: Option, +} - #[repr(C)] - #[derive(Clone, Default)] - pub struct PyMappingMethods { - pub mp_length: Option, - pub mp_subscript: Option, - pub mp_ass_subscript: Option, - } +#[cfg(Py_3_10)] +pub type sendfunc = unsafe extern "C" fn( + iter: *mut PyObject, + value: *mut PyObject, + result: *mut *mut PyObject, +) -> object::PySendResult; - // skipped PySendResult +#[repr(C)] +#[derive(Clone, Default)] +pub struct PyAsyncMethods { + pub am_await: Option, + pub am_aiter: Option, + pub am_anext: Option, + #[cfg(Py_3_10)] + pub am_send: Option, +} - #[repr(C)] - #[derive(Clone, Default)] - pub struct PyAsyncMethods { - pub am_await: Option, - pub am_aiter: Option, - pub am_anext: Option, - } +#[repr(C)] +#[derive(Clone, Default)] +pub struct PyBufferProcs { + pub bf_getbuffer: Option, + pub bf_releasebuffer: Option, +} - #[repr(C)] - #[derive(Clone, Default)] - pub struct PyBufferProcs { - pub bf_getbuffer: Option, - pub bf_releasebuffer: Option, - } +pub type printfunc = + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut ::libc::FILE, arg3: c_int) -> c_int; - pub type printfunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut ::libc::FILE, arg3: c_int) -> c_int; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct PyTypeObject { + #[cfg(PyPy)] + pub ob_refcnt: Py_ssize_t, + #[cfg(PyPy)] + pub ob_pypy_link: Py_ssize_t, + #[cfg(PyPy)] + pub ob_type: *mut PyTypeObject, + #[cfg(PyPy)] + pub ob_size: Py_ssize_t, + #[cfg(not(PyPy))] + pub ob_base: object::PyVarObject, + pub tp_name: *const c_char, + pub tp_basicsize: Py_ssize_t, + pub tp_itemsize: Py_ssize_t, + pub tp_dealloc: Option, + #[cfg(not(Py_3_8))] + pub tp_print: Option, + #[cfg(Py_3_8)] + pub tp_vectorcall_offset: Py_ssize_t, + pub tp_getattr: Option, + pub tp_setattr: Option, + pub tp_as_async: *mut PyAsyncMethods, + pub tp_repr: Option, + pub tp_as_number: *mut PyNumberMethods, + pub tp_as_sequence: *mut PySequenceMethods, + pub tp_as_mapping: *mut PyMappingMethods, + pub tp_hash: Option, + pub tp_call: Option, + pub tp_str: Option, + pub tp_getattro: Option, + pub tp_setattro: Option, + pub tp_as_buffer: *mut PyBufferProcs, + pub tp_flags: c_ulong, + pub tp_doc: *const c_char, + pub tp_traverse: Option, + pub tp_clear: Option, + pub tp_richcompare: Option, + pub tp_weaklistoffset: Py_ssize_t, + pub tp_iter: Option, + pub tp_iternext: Option, + pub tp_methods: *mut crate::methodobject::PyMethodDef, + pub tp_members: *mut crate::structmember::PyMemberDef, + pub tp_getset: *mut crate::descrobject::PyGetSetDef, + pub tp_base: *mut PyTypeObject, + pub tp_dict: *mut object::PyObject, + pub tp_descr_get: Option, + pub tp_descr_set: Option, + pub tp_dictoffset: Py_ssize_t, + pub tp_init: Option, + pub tp_alloc: Option, + pub tp_new: Option, + pub tp_free: Option, + pub tp_is_gc: Option, + pub tp_bases: *mut object::PyObject, + pub tp_mro: *mut object::PyObject, + pub tp_cache: *mut object::PyObject, + pub tp_subclasses: *mut object::PyObject, + pub tp_weaklist: *mut object::PyObject, + pub tp_del: Option, + pub tp_version_tag: c_uint, + pub tp_finalize: Option, + #[cfg(Py_3_8)] + pub tp_vectorcall: Option, + #[cfg(PyPy)] + pub tp_pypy_flags: std::os::raw::c_long, + #[cfg(py_sys_config = "COUNT_ALLOCS")] + pub tp_allocs: Py_ssize_t, + #[cfg(py_sys_config = "COUNT_ALLOCS")] + pub tp_frees: Py_ssize_t, + #[cfg(py_sys_config = "COUNT_ALLOCS")] + pub tp_maxalloc: Py_ssize_t, + #[cfg(py_sys_config = "COUNT_ALLOCS")] + pub tp_prev: *mut PyTypeObject, + #[cfg(py_sys_config = "COUNT_ALLOCS")] + pub tp_next: *mut PyTypeObject, +} - #[repr(C)] - #[derive(Debug, Copy, Clone)] - pub struct PyTypeObject { - #[cfg(PyPy)] - pub ob_refcnt: Py_ssize_t, - #[cfg(PyPy)] - pub ob_pypy_link: Py_ssize_t, - #[cfg(PyPy)] - pub ob_type: *mut PyTypeObject, - #[cfg(PyPy)] - pub ob_size: Py_ssize_t, - #[cfg(not(PyPy))] - pub ob_base: object::PyVarObject, - pub tp_name: *const c_char, - pub tp_basicsize: Py_ssize_t, - pub tp_itemsize: Py_ssize_t, - pub tp_dealloc: Option, - #[cfg(not(Py_3_8))] - pub tp_print: Option, - #[cfg(Py_3_8)] - pub tp_vectorcall_offset: Py_ssize_t, - pub tp_getattr: Option, - pub tp_setattr: Option, - pub tp_as_async: *mut PyAsyncMethods, - pub tp_repr: Option, - pub tp_as_number: *mut PyNumberMethods, - pub tp_as_sequence: *mut PySequenceMethods, - pub tp_as_mapping: *mut PyMappingMethods, - pub tp_hash: Option, - pub tp_call: Option, - pub tp_str: Option, - pub tp_getattro: Option, - pub tp_setattro: Option, - pub tp_as_buffer: *mut PyBufferProcs, - pub tp_flags: c_ulong, - pub tp_doc: *const c_char, - pub tp_traverse: Option, - pub tp_clear: Option, - pub tp_richcompare: Option, - pub tp_weaklistoffset: Py_ssize_t, - pub tp_iter: Option, - pub tp_iternext: Option, - pub tp_methods: *mut crate::methodobject::PyMethodDef, - pub tp_members: *mut crate::structmember::PyMemberDef, - pub tp_getset: *mut crate::descrobject::PyGetSetDef, - pub tp_base: *mut PyTypeObject, - pub tp_dict: *mut object::PyObject, - pub tp_descr_get: Option, - pub tp_descr_set: Option, - pub tp_dictoffset: Py_ssize_t, - pub tp_init: Option, - pub tp_alloc: Option, - pub tp_new: Option, - pub tp_free: Option, - pub tp_is_gc: Option, - pub tp_bases: *mut object::PyObject, - pub tp_mro: *mut object::PyObject, - pub tp_cache: *mut object::PyObject, - pub tp_subclasses: *mut object::PyObject, - pub tp_weaklist: *mut object::PyObject, - pub tp_del: Option, - pub tp_version_tag: c_uint, - pub tp_finalize: Option, - #[cfg(Py_3_8)] - pub tp_vectorcall: Option, - #[cfg(PyPy)] - pub tp_pypy_flags: std::os::raw::c_long, - #[cfg(py_sys_config = "COUNT_ALLOCS")] - pub tp_allocs: Py_ssize_t, - #[cfg(py_sys_config = "COUNT_ALLOCS")] - pub tp_frees: Py_ssize_t, - #[cfg(py_sys_config = "COUNT_ALLOCS")] - pub tp_maxalloc: Py_ssize_t, - #[cfg(py_sys_config = "COUNT_ALLOCS")] - pub tp_prev: *mut PyTypeObject, - #[cfg(py_sys_config = "COUNT_ALLOCS")] - pub tp_next: *mut PyTypeObject, - } - - #[repr(C)] - #[derive(Clone)] - pub struct PyHeapTypeObject { - pub ht_type: PyTypeObject, - pub as_async: PyAsyncMethods, - pub as_number: PyNumberMethods, - pub as_mapping: PyMappingMethods, - pub as_sequence: PySequenceMethods, - pub as_buffer: PyBufferProcs, - pub ht_name: *mut object::PyObject, - pub ht_slots: *mut object::PyObject, - pub ht_qualname: *mut object::PyObject, - pub ht_cached_keys: *mut c_void, - } - - impl Default for PyHeapTypeObject { - #[inline] - fn default() -> Self { - unsafe { mem::zeroed() } - } - } +#[repr(C)] +#[derive(Clone)] +pub struct PyHeapTypeObject { + pub ht_type: PyTypeObject, + pub as_async: PyAsyncMethods, + pub as_number: PyNumberMethods, + pub as_mapping: PyMappingMethods, + pub as_sequence: PySequenceMethods, + pub as_buffer: PyBufferProcs, + pub ht_name: *mut object::PyObject, + pub ht_slots: *mut object::PyObject, + pub ht_qualname: *mut object::PyObject, + pub ht_cached_keys: *mut c_void, + #[cfg(Py_3_9)] + pub ht_module: *mut object::PyObject, +} +impl Default for PyHeapTypeObject { #[inline] - pub unsafe fn PyHeapType_GET_MEMBERS( - etype: *mut PyHeapTypeObject, - ) -> *mut crate::structmember::PyMemberDef { - let py_type = object::Py_TYPE(etype as *mut object::PyObject); - let ptr = etype.offset((*py_type).tp_basicsize); - ptr as *mut crate::structmember::PyMemberDef + fn default() -> Self { + unsafe { mem::zeroed() } } } -// The exported types depend on whether Py_LIMITED_API is set -pub use self::typeobject::*; +#[inline] +pub unsafe fn PyHeapType_GET_MEMBERS( + etype: *mut PyHeapTypeObject, +) -> *mut crate::structmember::PyMemberDef { + let py_type = object::Py_TYPE(etype as *mut object::PyObject); + let ptr = etype.offset((*py_type).tp_basicsize); + ptr as *mut crate::structmember::PyMemberDef +} // skipped _PyType_Name // skipped _PyType_Lookup diff --git a/pyo3-ffi/src/cpython/pyerrors.rs b/pyo3-ffi/src/cpython/pyerrors.rs new file mode 100644 index 00000000..3058be47 --- /dev/null +++ b/pyo3-ffi/src/cpython/pyerrors.rs @@ -0,0 +1,111 @@ +use crate::{PyObject, Py_ssize_t}; + +#[repr(C)] +#[derive(Debug)] +pub struct PyBaseExceptionObject { + pub ob_base: PyObject, + pub dict: *mut PyObject, + pub args: *mut PyObject, + pub traceback: *mut PyObject, + pub context: *mut PyObject, + pub cause: *mut PyObject, + pub suppress_context: char, +} + +#[repr(C)] +#[derive(Debug)] +pub struct PySyntaxErrorObject { + pub exception_base: PyBaseExceptionObject, + pub msg: *mut PyObject, + pub filename: *mut PyObject, + pub lineno: *mut PyObject, + pub offset: *mut PyObject, + #[cfg(Py_3_10)] + pub end_lineno: *mut PyObject, + #[cfg(Py_3_10)] + pub end_offset: *mut PyObject, + pub text: *mut PyObject, + pub print_file_and_line: *mut PyObject, +} + +#[repr(C)] +#[derive(Debug)] +pub struct PyImportErrorObject { + pub exception_base: PyBaseExceptionObject, + pub msg: *mut PyObject, + pub name: *mut PyObject, + pub path: *mut PyObject, +} + +#[repr(C)] +#[derive(Debug)] +pub struct PyUnicodeErrorObject { + pub exception_base: PyBaseExceptionObject, + pub encoding: *mut PyObject, + pub object: *mut PyObject, + pub start: Py_ssize_t, + pub end: Py_ssize_t, + pub reason: *mut PyObject, +} + +#[repr(C)] +#[derive(Debug)] +pub struct PySystemExitObject { + pub exception_base: PyBaseExceptionObject, + pub code: *mut PyObject, +} + +#[repr(C)] +#[derive(Debug)] +pub struct PyOSErrorObject { + pub exception_base: PyBaseExceptionObject, + pub myerrno: *mut PyObject, + pub strerror: *mut PyObject, + pub filename: *mut PyObject, + pub filename2: *mut PyObject, + #[cfg(windows)] + pub winerror: *mut PyObject, + pub written: Py_ssize_t, +} + +#[repr(C)] +#[derive(Debug)] +pub struct PyStopIterationObject { + pub exception_base: PyBaseExceptionObject, + pub value: *mut PyObject, +} + +// skipped PyNameErrorObject +// skipped PyAttributeErrorObject + +// skipped PyEnvironmentErrorObject +// skipped PyWindowsErrorObject + +// skipped _PyErr_SetKeyError +// skipped _PyErr_GetTopmostException +// skipped _PyErr_GetExcInfo + +// skipped _PyErr_ChainExceptions + +// 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_ProgramDecodedTextObject +// skipped _PyUnicodeTranslateError_Create +// skipped _PyErr_WriteUnraisableMsg +// skipped _Py_FatalErrorFunc +// skipped _Py_FatalErrorFormat +// skipped Py_FatalError diff --git a/pyo3-ffi/src/cpython/pystate.rs b/pyo3-ffi/src/cpython/pystate.rs index 232a5165..19f3a3d0 100644 --- a/pyo3-ffi/src/cpython/pystate.rs +++ b/pyo3-ffi/src/cpython/pystate.rs @@ -26,7 +26,16 @@ pub const PyTrace_OPCODE: c_int = 7; // skipped PyTraceInfo // skipped CFrame -// skipped _PyErr_StackItem + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct _PyErr_StackItem { + pub exc_type: *mut PyObject, + pub exc_value: *mut PyObject, + pub exc_traceback: *mut PyObject, + pub previous_item: *mut _PyErr_StackItem, +} + // skipped _PyStackChunk // skipped _ts (aka PyThreadState) diff --git a/pyo3-ffi/src/lib.rs b/pyo3-ffi/src/lib.rs index 7033c37e..04ad398c 100644 --- a/pyo3-ffi/src/lib.rs +++ b/pyo3-ffi/src/lib.rs @@ -301,8 +301,6 @@ pub use self::fileutils::*; pub use self::floatobject::*; #[cfg(not(Py_LIMITED_API))] pub use self::funcobject::*; -#[cfg(not(Py_LIMITED_API))] -pub use self::genobject::*; pub use self::import::*; pub use self::intrcheck::*; pub use self::iterobject::*; @@ -373,8 +371,6 @@ mod floatobject; #[cfg(not(Py_LIMITED_API))] pub(crate) mod funcobject; // skipped genericaliasobject.h -#[cfg(not(Py_LIMITED_API))] -mod genobject; mod import; // skipped interpreteridobject.h mod intrcheck; diff --git a/pyo3-ffi/src/pyerrors.rs b/pyo3-ffi/src/pyerrors.rs index 3d3bfd4f..57b1b424 100644 --- a/pyo3-ffi/src/pyerrors.rs +++ b/pyo3-ffi/src/pyerrors.rs @@ -2,77 +2,6 @@ use crate::object::*; use crate::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int}; -#[repr(C)] -#[derive(Debug)] -pub struct PyBaseExceptionObject { - pub ob_base: PyObject, - pub dict: *mut PyObject, - pub args: *mut PyObject, - pub traceback: *mut PyObject, - pub context: *mut PyObject, - pub cause: *mut PyObject, - pub suppress_context: char, -} - -#[repr(C)] -#[derive(Debug)] -pub struct PySyntaxErrorObject { - pub exception_base: PyBaseExceptionObject, - pub msg: *mut PyObject, - pub filename: *mut PyObject, - pub lineno: *mut PyObject, - pub offset: *mut PyObject, - pub text: *mut PyObject, - pub print_file_and_line: *mut PyObject, -} - -#[repr(C)] -#[derive(Debug)] -pub struct PyImportErrorObject { - pub exception_base: PyBaseExceptionObject, - pub msg: *mut PyObject, - pub name: *mut PyObject, - pub path: *mut PyObject, -} - -#[repr(C)] -#[derive(Debug)] -pub struct PyUnicodeErrorObject { - pub exception_base: PyBaseExceptionObject, - pub encoding: *mut PyObject, - pub object: *mut PyObject, - pub start: Py_ssize_t, - pub end: Py_ssize_t, - pub reason: *mut PyObject, -} - -#[repr(C)] -#[derive(Debug)] -pub struct PySystemExitObject { - pub exception_base: PyBaseExceptionObject, - pub code: *mut PyObject, -} - -#[repr(C)] -#[derive(Debug)] -pub struct PyOSErrorObject { - pub exception_base: PyBaseExceptionObject, - pub myerrno: *mut PyObject, - pub strerror: *mut PyObject, - pub filename: *mut PyObject, - pub filename2: *mut PyObject, - #[cfg(windows)] - pub winerror: *mut PyObject, - pub written: Py_ssize_t, -} - -#[repr(C)] -#[derive(Debug)] -pub struct PyStopIterationObject { - pub exception_base: PyBaseExceptionObject, - pub value: *mut PyObject, -} - extern "C" { #[cfg_attr(PyPy, link_name = "PyPyErr_SetNone")] pub fn PyErr_SetNone(arg1: *mut PyObject); diff --git a/pyo3-ffi/src/pythonrun.rs b/pyo3-ffi/src/pythonrun.rs index 5045abc1..d3784236 100644 --- a/pyo3-ffi/src/pythonrun.rs +++ b/pyo3-ffi/src/pythonrun.rs @@ -24,16 +24,6 @@ pub const PYOS_STACK_MARGIN: c_int = 2048; // skipped PyOS_CheckStack under Microsoft C -#[repr(C)] -#[derive(Copy, Clone)] -#[cfg(not(Py_LIMITED_API))] -pub struct PyCompilerFlags { - pub cf_flags: c_int, -} - -#[cfg(Py_LIMITED_API)] -opaque_struct!(PyCompilerFlags); - #[cfg(all(not(Py_LIMITED_API), not(Py_3_10)))] opaque_struct!(_mod);