From 50b48572d9a90c5bb36e2bef6179548ea927a35a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 1 Nov 2018 01:51:40 +0100 Subject: 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. --- Python/errors.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 14a70d9ce8e..4c6c34c74fa 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -28,7 +28,7 @@ _Py_IDENTIFIER(stderr); void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback) { - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); PyObject *oldtype, *oldvalue, *oldtraceback; if (traceback != NULL && !PyTraceBack_Check(traceback)) { @@ -82,7 +82,7 @@ _PyErr_CreateException(PyObject *exception, PyObject *value) void PyErr_SetObject(PyObject *exception, PyObject *value) { - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); PyObject *exc_value; PyObject *tb = NULL; @@ -175,7 +175,7 @@ PyErr_SetString(PyObject *exception, const char *string) PyObject* _Py_HOT_FUNCTION PyErr_Occurred(void) { - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); return tstate == NULL ? NULL : tstate->curexc_type; } @@ -334,7 +334,7 @@ PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb) void PyErr_Fetch(PyObject **p_type, PyObject **p_value, PyObject **p_traceback) { - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); *p_type = tstate->curexc_type; *p_value = tstate->curexc_value; @@ -354,7 +354,7 @@ PyErr_Clear(void) void PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback) { - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); _PyErr_StackItem *exc_info = _PyErr_GetTopmostException(tstate); *p_type = exc_info->exc_type; @@ -371,7 +371,7 @@ void PyErr_SetExcInfo(PyObject *p_type, PyObject *p_value, PyObject *p_traceback) { PyObject *oldtype, *oldvalue, *oldtraceback; - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); oldtype = tstate->exc_info->exc_type; oldvalue = tstate->exc_info->exc_value; -- cgit v1.2.3