mirror of
https://github.com/python/cpython.git
synced 2025-08-25 03:04:55 +00:00
bpo-35081: Add _PyThreadState_GET() internal macro (GH-10266)
If Py_BUILD_CORE is defined, the PyThreadState_GET() macro access _PyRuntime which comes from the internal pycore_state.h header. Public headers must not require internal headers. Move PyThreadState_GET() and _PyInterpreterState_GET_UNSAFE() from Include/pystate.h to Include/internal/pycore_state.h, and rename PyThreadState_GET() to _PyThreadState_GET() there. The PyThreadState_GET() macro of pystate.h is now redefined when pycore_state.h is included, to use the fast _PyThreadState_GET(). Changes: * Add _PyThreadState_GET() macro * Replace "PyThreadState_GET()->interp" with _PyInterpreterState_GET_UNSAFE() * Replace PyThreadState_GET() with _PyThreadState_GET() in internal C files (compiled with Py_BUILD_CORE defined), but keep PyThreadState_GET() in the public header files. * _testcapimodule.c: replace PyThreadState_GET() with PyThreadState_Get(); the module is not compiled with Py_BUILD_CORE defined. * pycore_state.h now requires Py_BUILD_CORE to be defined.
This commit is contained in:
parent
27e2d1f219
commit
50b48572d9
20 changed files with 144 additions and 104 deletions
|
@ -174,7 +174,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
|
|||
return PYTHREAD_INVALID_THREAD_ID;
|
||||
#endif
|
||||
#if defined(THREAD_STACK_SIZE)
|
||||
PyThreadState *tstate = PyThreadState_GET();
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
size_t stacksize = tstate ? tstate->interp->pythread_stacksize : 0;
|
||||
tss = (stacksize != 0) ? stacksize : THREAD_STACK_SIZE;
|
||||
if (tss != 0) {
|
||||
|
@ -591,7 +591,7 @@ _pythread_pthread_set_stacksize(size_t size)
|
|||
|
||||
/* set to default */
|
||||
if (size == 0) {
|
||||
PyThreadState_GET()->interp->pythread_stacksize = 0;
|
||||
_PyInterpreterState_GET_UNSAFE()->pythread_stacksize = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -608,7 +608,7 @@ _pythread_pthread_set_stacksize(size_t size)
|
|||
rc = pthread_attr_setstacksize(&attrs, size);
|
||||
pthread_attr_destroy(&attrs);
|
||||
if (rc == 0) {
|
||||
PyThreadState_GET()->interp->pythread_stacksize = size;
|
||||
_PyInterpreterState_GET_UNSAFE()->pythread_stacksize = size;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue