diff --git a/newsfragments/6262.added.md b/newsfragments/6262.added.md new file mode 100644 index 00000000000..8c1452089dc --- /dev/null +++ b/newsfragments/6262.added.md @@ -0,0 +1 @@ +Add tss api to ffi crate diff --git a/pyo3-ffi/src/lib.rs b/pyo3-ffi/src/lib.rs index 7fdf12a0094..77a43cc2cf5 100644 --- a/pyo3-ffi/src/lib.rs +++ b/pyo3-ffi/src/lib.rs @@ -483,6 +483,7 @@ pub use self::pymem::*; pub use self::pyport::*; pub use self::pystate::*; pub use self::pystrtod::*; +pub use self::pythead::*; pub use self::pythonrun::*; pub use self::pytypedefs::*; pub use self::rangeobject::*; @@ -574,7 +575,7 @@ mod pythonrun; // skipped pystrhex.h // skipped pystrcmp.h mod pystrtod; -// skipped pythread.h +mod pythead; // skipped pytime.h mod pytypedefs; mod rangeobject; diff --git a/pyo3-ffi/src/pythead.rs b/pyo3-ffi/src/pythead.rs new file mode 100644 index 00000000000..75dfa2eb517 --- /dev/null +++ b/pyo3-ffi/src/pythead.rs @@ -0,0 +1,34 @@ +use core::ffi::{c_int, c_void}; + +#[cfg(Py_LIMITED_API)] +opaque_struct!(pub Py_tss_t); + +#[cfg(not(Py_LIMITED_API))] +#[repr(C)] +pub struct Py_tss_t { + _is_initialized: c_int, + _key: NATIVE_TSS_KEY_T, +} + +#[cfg(not(Py_LIMITED_API))] +pub const Py_tss_NEEDS_INIT: Py_tss_t = Py_tss_t { + _is_initialized: 0, + _key: 0, +}; + +#[cfg(all(windows, not(Py_LIMITED_API)))] +type NATIVE_TSS_KEY_T = core::ffi::c_ulong; + +#[cfg(all(not(windows), not(Py_LIMITED_API)))] +type NATIVE_TSS_KEY_T = libc::pthread_key_t; + +extern_libpython! { + pub fn PyThread_tss_alloc() -> *mut Py_tss_t; + pub fn PyThread_tss_free(key: *mut Py_tss_t); + + pub fn PyThread_tss_is_created(key: *mut Py_tss_t) -> c_int; + pub fn PyThread_tss_create(key: *mut Py_tss_t) -> c_int; + pub fn PyThread_tss_delete(key: *mut Py_tss_t); + pub fn PyThread_tss_set(key: *mut Py_tss_t, value: *mut c_void) -> c_int; + pub fn PyThread_tss_get(key: *mut Py_tss_t) -> *mut c_void; +}