gh-112535: Add test on _Py_ThreadId() (#112709)

Add also test.support.Py_GIL_DISABLED constant.
This commit is contained in:
Victor Stinner 2023-12-04 23:40:06 +01:00 committed by GitHub
parent a8ce149628
commit c5fa8a54db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 8 deletions

View file

@ -1625,6 +1625,17 @@ get_type_module_name(PyObject *self, PyObject *type)
}
#ifdef Py_GIL_DISABLED
static PyObject *
get_py_thread_id(PyObject *self, PyObject *Py_UNUSED(ignored))
{
uintptr_t tid = _Py_ThreadId();
Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(tid));
return PyLong_FromUnsignedLongLong(tid);
}
#endif
static PyMethodDef module_functions[] = {
{"get_configs", get_configs, METH_NOARGS},
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
@ -1688,6 +1699,9 @@ static PyMethodDef module_functions[] = {
{"restore_crossinterp_data", restore_crossinterp_data, METH_VARARGS},
_TESTINTERNALCAPI_TEST_LONG_NUMBITS_METHODDEF
{"get_type_module_name", get_type_module_name, METH_O},
#ifdef Py_GIL_DISABLED
{"py_thread_id", get_py_thread_id, METH_NOARGS},
#endif
{NULL, NULL} /* sentinel */
};