mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
pycore_pystate.h no longer redefines PyThreadState_GET() (GH-28921)
Redefining the PyThreadState_GET() macro in pycore_pystate.h is useless since it doesn't affect files not including it. Either use _PyThreadState_GET() directly, or don't use pycore_pystate.h internal C API. For example, the _testcapi extension don't use the internal C API, but use the public PyThreadState_Get() function instead. Replace PyThreadState_Get() with _PyThreadState_GET(). The _PyThreadState_GET() macro is more efficient than PyThreadState_Get() and PyThreadState_GET() function calls which call fail with a fatal Python error. posixmodule.c and _ctypes extension now include <windows.h> before pycore header files (like pycore_call.h). _PyTraceback_Add() now uses _PyErr_Fetch()/_PyErr_Restore() instead of PyErr_Fetch()/PyErr_Restore(). The _decimal and _xxsubinterpreters extensions are now built with the Py_BUILD_CORE_MODULE macro defined to get access to the internal C API.
This commit is contained in:
parent
7733307739
commit
7cdc2a0f4b
23 changed files with 87 additions and 77 deletions
|
@ -8,6 +8,8 @@ extern "C" {
|
|||
# error "this header requires Py_BUILD_CORE define"
|
||||
#endif
|
||||
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||
|
||||
PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(
|
||||
PyThreadState *tstate,
|
||||
PyObject *callable,
|
||||
|
@ -36,7 +38,7 @@ _PyObject_CallNoArgsTstate(PyThreadState *tstate, PyObject *func) {
|
|||
// Private static inline function variant of public PyObject_CallNoArgs()
|
||||
static inline PyObject *
|
||||
_PyObject_CallNoArgs(PyObject *func) {
|
||||
PyThreadState *tstate = PyThreadState_Get();
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@ extern "C" {
|
|||
struct pyruntimestate;
|
||||
struct _ceval_runtime_state;
|
||||
|
||||
#include "pycore_interp.h" /* PyInterpreterState.eval_frame */
|
||||
#include "pycore_interp.h" // PyInterpreterState.eval_frame
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||
|
||||
extern void _Py_FinishPendingCalls(PyThreadState *tstate);
|
||||
extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
|
||||
|
@ -93,7 +94,7 @@ static inline int _Py_EnterRecursiveCall(PyThreadState *tstate,
|
|||
}
|
||||
|
||||
static inline int _Py_EnterRecursiveCall_inline(const char *where) {
|
||||
PyThreadState *tstate = PyThreadState_GET();
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
return _Py_EnterRecursiveCall(tstate, where);
|
||||
}
|
||||
|
||||
|
@ -104,7 +105,7 @@ static inline void _Py_LeaveRecursiveCall(PyThreadState *tstate) {
|
|||
}
|
||||
|
||||
static inline void _Py_LeaveRecursiveCall_inline(void) {
|
||||
PyThreadState *tstate = PyThreadState_GET();
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
_Py_LeaveRecursiveCall(tstate);
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ _PyRuntimeState_GetThreadState(_PyRuntimeState *runtime)
|
|||
|
||||
The caller must hold the GIL.
|
||||
|
||||
See also PyThreadState_Get() and PyThreadState_GET(). */
|
||||
See also PyThreadState_Get() and _PyThreadState_UncheckedGet(). */
|
||||
static inline PyThreadState*
|
||||
_PyThreadState_GET(void)
|
||||
{
|
||||
|
@ -93,10 +93,6 @@ _PyThreadState_GET(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
/* Redefine PyThreadState_GET() as an alias to _PyThreadState_GET() */
|
||||
#undef PyThreadState_GET
|
||||
#define PyThreadState_GET() _PyThreadState_GET()
|
||||
|
||||
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalError_TstateNULL(const char *func);
|
||||
|
||||
static inline void
|
||||
|
|
|
@ -66,18 +66,10 @@ PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
|
|||
|
||||
The caller must hold the GIL.
|
||||
|
||||
See also PyThreadState_GET() and _PyThreadState_GET(). */
|
||||
See also _PyThreadState_UncheckedGet() and _PyThreadState_GET(). */
|
||||
PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
|
||||
|
||||
/* Get the current Python thread state.
|
||||
|
||||
Macro using PyThreadState_Get() or _PyThreadState_GET() depending if
|
||||
pycore_pystate.h is included or not (this header redefines the macro).
|
||||
|
||||
If PyThreadState_Get() is used, issue a fatal error if the current thread
|
||||
state is NULL.
|
||||
|
||||
See also PyThreadState_Get() and _PyThreadState_GET(). */
|
||||
// Alias to PyThreadState_Get()
|
||||
#define PyThreadState_GET() PyThreadState_Get()
|
||||
|
||||
PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue