Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/6262.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add tss api to ffi crate
3 changes: 2 additions & 1 deletion pyo3-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 34 additions & 0 deletions pyo3-ffi/src/pythead.rs
Original file line number Diff line number Diff line change
@@ -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;
}