summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-11-01 00:51:40 (GMT)
committerGitHub <noreply@github.com>2018-11-01 00:51:40 (GMT)
commit50b48572d9a90c5bb36e2bef6179548ea927a35a (patch)
tree3b77efe6c7182a3e0b98fcba9854198dbeca3a98 /Python/ceval.c
parent27e2d1f21975dfb8c0ddcb192fa0f45a51b7977e (diff)
downloadcpython-50b48572d9a90c5bb36e2bef6179548ea927a35a.zip
cpython-50b48572d9a90c5bb36e2bef6179548ea927a35a.tar.gz
cpython-50b48572d9a90c5bb36e2bef6179548ea927a35a.tar.bz2
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.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 5599b6e..ac9db15 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -157,7 +157,7 @@ PyEval_InitThreads(void)
if (gil_created())
return;
create_gil();
- take_gil(PyThreadState_GET());
+ take_gil(_PyThreadState_GET());
_PyRuntime.ceval.pending.main_thread = PyThread_get_thread_ident();
if (!_PyRuntime.ceval.pending.lock)
_PyRuntime.ceval.pending.lock = PyThread_allocate_lock();
@@ -175,7 +175,7 @@ _PyEval_FiniThreads(void)
void
PyEval_AcquireLock(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL)
Py_FatalError("PyEval_AcquireLock: current thread state is NULL");
take_gil(tstate);
@@ -185,10 +185,10 @@ void
PyEval_ReleaseLock(void)
{
/* This function must succeed when the current thread state is NULL.
- We therefore avoid PyThreadState_GET() which dumps a fatal error
+ We therefore avoid PyThreadState_Get() which dumps a fatal error
in debug mode.
*/
- drop_gil(PyThreadState_GET());
+ drop_gil(_PyThreadState_GET());
}
void
@@ -222,7 +222,7 @@ PyEval_ReleaseThread(PyThreadState *tstate)
void
PyEval_ReInitThreads(void)
{
- PyThreadState *current_tstate = PyThreadState_GET();
+ PyThreadState *current_tstate = _PyThreadState_GET();
if (!gil_created())
return;
@@ -462,7 +462,7 @@ Py_SetRecursionLimit(int new_limit)
int
_Py_CheckRecursiveCall(const char *where)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
int recursion_limit = _PyRuntime.ceval.recursion_limit;
#ifdef USE_STACKCHECK
@@ -543,7 +543,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
int oparg; /* Current opcode argument, if any */
PyObject **fastlocals, **freevars;
PyObject *retval = NULL; /* Return value */
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyCodeObject *co;
/* when tracing we set things up so that
@@ -3702,7 +3702,7 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
}
/* Create the frame */
- tstate = PyThreadState_GET();
+ tstate = _PyThreadState_GET();
assert(tstate != NULL);
f = _PyFrame_New_NoTrack(tstate, co, globals, locals);
if (f == NULL) {
@@ -4003,7 +4003,7 @@ do_raise(PyObject *exc, PyObject *cause)
if (exc == NULL) {
/* Reraise */
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
_PyErr_StackItem *exc_info = _PyErr_GetTopmostException(tstate);
PyObject *tb;
type = exc_info->exc_type;
@@ -4275,7 +4275,7 @@ call_trace(Py_tracefunc func, PyObject *obj,
PyObject *
_PyEval_CallTracing(PyObject *func, PyObject *args)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
int save_tracing = tstate->tracing;
int save_use_tracing = tstate->use_tracing;
PyObject *result;
@@ -4329,7 +4329,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
void
PyEval_SetProfile(Py_tracefunc func, PyObject *arg)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyObject *temp = tstate->c_profileobj;
Py_XINCREF(arg);
tstate->c_profilefunc = NULL;
@@ -4346,7 +4346,7 @@ PyEval_SetProfile(Py_tracefunc func, PyObject *arg)
void
PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
PyObject *temp = tstate->c_traceobj;
_Py_TracingPossible += (func != NULL) - (tstate->c_tracefunc != NULL);
Py_XINCREF(arg);
@@ -4366,21 +4366,21 @@ void
_PyEval_SetCoroutineOriginTrackingDepth(int new_depth)
{
assert(new_depth >= 0);
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
tstate->coroutine_origin_tracking_depth = new_depth;
}
int
_PyEval_GetCoroutineOriginTrackingDepth(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
return tstate->coroutine_origin_tracking_depth;
}
void
_PyEval_SetCoroutineWrapper(PyObject *wrapper)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
Py_XINCREF(wrapper);
Py_XSETREF(tstate->coroutine_wrapper, wrapper);
@@ -4389,14 +4389,14 @@ _PyEval_SetCoroutineWrapper(PyObject *wrapper)
PyObject *
_PyEval_GetCoroutineWrapper(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
return tstate->coroutine_wrapper;
}
void
_PyEval_SetAsyncGenFirstiter(PyObject *firstiter)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
Py_XINCREF(firstiter);
Py_XSETREF(tstate->async_gen_firstiter, firstiter);
@@ -4405,14 +4405,14 @@ _PyEval_SetAsyncGenFirstiter(PyObject *firstiter)
PyObject *
_PyEval_GetAsyncGenFirstiter(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
return tstate->async_gen_firstiter;
}
void
_PyEval_SetAsyncGenFinalizer(PyObject *finalizer)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
Py_XINCREF(finalizer);
Py_XSETREF(tstate->async_gen_finalizer, finalizer);
@@ -4421,7 +4421,7 @@ _PyEval_SetAsyncGenFinalizer(PyObject *finalizer)
PyObject *
_PyEval_GetAsyncGenFinalizer(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
return tstate->async_gen_finalizer;
}
@@ -4465,7 +4465,7 @@ PyEval_GetGlobals(void)
PyFrameObject *
PyEval_GetFrame(void)
{
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
return _PyThreadState_GetFrame(tstate);
}
@@ -4566,11 +4566,11 @@ call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames)
presumed to be the most frequent callable object.
*/
if (PyCFunction_Check(func)) {
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
C_TRACE(x, _PyCFunction_FastCallKeywords(func, stack, nargs, kwnames));
}
else if (Py_TYPE(func) == &PyMethodDescr_Type) {
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
if (nargs > 0 && tstate->use_tracing) {
/* We need to create a temporary bound method as argument
for profiling.
@@ -4640,12 +4640,12 @@ do_call_core(PyObject *func, PyObject *callargs, PyObject *kwdict)
PyObject *result;
if (PyCFunction_Check(func)) {
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));
return result;
}
else if (Py_TYPE(func) == &PyMethodDescr_Type) {
- PyThreadState *tstate = PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_GET();
Py_ssize_t nargs = PyTuple_GET_SIZE(callargs);
if (nargs > 0 && tstate->use_tracing) {
/* We need to create a temporary bound method as argument