-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c363b5
commit 400c8c5
Showing
5 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add FFI definitions from `pythread.h`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::mem; | ||
use std::os::raw::{c_int, c_longlong, c_ulong}; | ||
|
||
#[cfg(all(not(PyPy), not(Py_3_13), not(windows)))] | ||
pub const PY_TIMEOUT_MAX: c_longlong = c_longlong::MAX / 1000; | ||
#[cfg(all(not(PyPy), not(Py_3_11), windows))] | ||
pub const PY_TIMEOUT_MAX: c_longlong = (0xFFFFFFFF as c_longlong).saturating_mul(1000); | ||
#[cfg(all(not(PyPy), Py_3_11, not(Py_3_13), windows))] | ||
pub const PY_TIMEOUT_MAX: c_longlong = (0xFFFFFFFE as c_longlong).saturating_mul(1000); | ||
#[cfg(all(not(any(PyPy, GraalPy)), Py_3_13))] | ||
#[cfg_attr(windows, link(name = "pythonXY"))] | ||
extern "C" { | ||
pub static PY_TIMEOUT_MAX: c_longlong; | ||
} | ||
|
||
#[cfg(not(PyPy))] | ||
pub const PYTHREAD_INVALID_THREAD_ID: c_ulong = c_ulong::MAX; | ||
|
||
// skipped _PyThread_at_fork_reinit (removed 3.13) | ||
|
||
#[cfg(not(windows))] | ||
type NATIVE_TSS_KEY_T = libc::pthread_key_t; | ||
#[cfg(windows)] | ||
type NATIVE_TSS_KEY_T = c_ulong; | ||
|
||
#[repr(C)] | ||
#[derive(Copy, Clone, Debug, PartialEq, Eq)] | ||
pub struct Py_tss_t { | ||
_is_initialized: c_int, | ||
_key: NATIVE_TSS_KEY_T, | ||
} | ||
|
||
impl Default for Py_tss_t { | ||
fn default() -> Self { | ||
Py_tss_NEEDS_INIT | ||
} | ||
} | ||
|
||
pub const Py_tss_NEEDS_INIT: Py_tss_t = Py_tss_t { | ||
_is_initialized: 0, | ||
_key: 0, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use crate::object::PyObject; | ||
use std::os::raw::{c_int, c_longlong, c_ulong, c_void}; | ||
|
||
pub type PyThread_type_lock = *mut c_void; | ||
// skipped PyThread_type_sema (removed 3.9) | ||
|
||
#[cfg(not(PyPy))] | ||
#[repr(C)] | ||
#[derive(Copy, Clone, Debug, PartialEq, Eq)] | ||
pub enum PyLockStatus { | ||
PY_LOCK_FAILURE = 0, | ||
PY_LOCK_ACQUIRED = 1, | ||
PY_LOCK_INTR, | ||
} | ||
|
||
extern "C" { | ||
pub fn PyThread_init_thread(); | ||
pub fn PyThread_start_new_thread( | ||
arg1: Option<unsafe extern "C" fn(*mut c_void)>, | ||
arg2: *mut c_void, | ||
) -> c_ulong; | ||
|
||
#[cfg(not(PyPy))] | ||
pub fn PyThread_exit_thread() -> !; | ||
|
||
pub fn PyThread_get_thread_ident() -> c_ulong; | ||
|
||
#[cfg(all( | ||
not(PyPy), | ||
any( | ||
target_os = "ios", | ||
target_os = "macos", | ||
target_os = "tvos", | ||
target_os = "watchos", | ||
target_os = "android", | ||
target_os = "linux", | ||
target_os = "windows", | ||
target_os = "freebsd", | ||
target_os = "openbsd", | ||
target_os = "netbsd", | ||
all(not(GraalPy), Py_3_12, target_os = "dragonfly"), | ||
target_os = "aix" | ||
) | ||
))] | ||
pub fn PyThread_get_thread_native_id() -> c_ulong; | ||
|
||
pub fn PyThread_allocate_lock() -> PyThread_type_lock; | ||
pub fn PyThread_free_lock(arg1: PyThread_type_lock); | ||
pub fn PyThread_acquire_lock(arg1: PyThread_type_lock, arg2: c_int) -> c_int; | ||
} | ||
|
||
pub const WAIT_LOCK: c_int = 1; | ||
pub const NOWAIT_LOCK: c_int = 0; | ||
|
||
#[cfg(not(PyPy))] | ||
pub type PY_TIMEOUT_T = c_longlong; | ||
|
||
extern "C" { | ||
#[cfg(not(PyPy))] | ||
pub fn PyThread_acquire_lock_timed( | ||
arg1: PyThread_type_lock, | ||
microseconds: PY_TIMEOUT_T, | ||
intr_flag: c_int, | ||
) -> PyLockStatus; | ||
|
||
pub fn PyThread_release_lock(arg1: PyThread_type_lock); | ||
|
||
#[cfg(not(PyPy))] | ||
pub fn PyThread_get_stacksize() -> usize; | ||
|
||
#[cfg(not(PyPy))] | ||
pub fn PyThread_set_stacksize(arg1: usize) -> c_int; | ||
|
||
#[cfg(not(PyPy))] | ||
pub fn PyThread_GetInfo() -> *mut PyObject; | ||
|
||
// skipped PyThread_create_key (deprecated 3.7) | ||
// skipped PyThread_delete_key (deprecated 3.7) | ||
// skipped PyThread_set_key_value (deprecated 3.7) | ||
// skipped PyThread_get_key_value (deprecated 3.7) | ||
// skipped PyThread_delete_key_value (deprecated 3.7) | ||
// skipped PyThread_ReInitTLS (deprecated 3.7) | ||
} | ||
|
||
#[cfg(Py_LIMITED_API)] | ||
opaque_struct!(Py_tss_t); | ||
#[cfg(not(Py_LIMITED_API))] | ||
use crate::cpython::pythread::Py_tss_t; | ||
|
||
extern "C" { | ||
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; | ||
} |