Add FFI definitions from pythread.h
#4872
Open
+146
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds all definitions from
pythread.h
andcpython/pythread.h
that haven't been deprecated or removed as of CPython 3.13. Of the functions, some are fully documented, some are undocumented but still contained in the limited API list, and some are neither documented nor in the limited API. Some of the limited-API functions, such asPyThread_get_thread_ident()
, are widely used by 3rd-party code despite being undocumented, so it would be useful to include them in the bindings. The full breakdown:PyThread_tss_alloc
,PyThread_tss_create
,PyThread_tss_delete
,PyThread_tss_free
,PyThread_tss_get
,PyThread_tss_is_created
,PyThread_tss_set
; structPy_tss_t
.PyThread_GetInfo
,PyThread_acquire_lock
,PyThread_acquire_lock_timed
,PyThread_allocate_lock
,PyThread_exit_thread
,PyThread_free_lock
,PyThread_get_stacksize
,PyThread_get_thread_ident
,PyThread_get_thread_native_id
,PyThread_init_thread
,PyThread_release_lock
,PyThread_set_stacksize
,PyThread_start_new_thread
; enumPyLockStatus
; typedefsPY_TIMEOUT_T
,PyThread_type_lock
; constantsNOWAIT_LOCK
,PY_LOCK_ACQUIRED
,PY_LOCK_FAILURE
,PY_LOCK_INTR
,WAIT_LOCK
.Py_tss_NEEDS_INIT
.PY_TIMEOUT_MAX
; constantPYTHREAD_INVALID_THREAD_ID
.PyThread_get_thread_native_id()
is a particularly fiddly definition due to all the OS-based#ifdef
s guarding it: I've approximated them withcfg(target_os)
values to the best of my ability, but it would be much easier if we could directly check that thePY_HAVE_THREAD_NATIVE_ID
macro is defined. I've also gone through the PyPy and GraalPy versions of the headers to see which functions they support.