mirror of https://github.com/python/cpython
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
|
@ -4,6 +4,10 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef Py_BUILD_CORE
|
||||||
|
# error "Py_BUILD_CORE must be defined to include this header"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "pystate.h"
|
#include "pystate.h"
|
||||||
#include "pythread.h"
|
#include "pythread.h"
|
||||||
|
|
||||||
|
@ -214,6 +218,36 @@ PyAPI_FUNC(_PyInitError) _PyRuntime_Initialize(void);
|
||||||
(_PyRuntime.finalizing == tstate)
|
(_PyRuntime.finalizing == tstate)
|
||||||
|
|
||||||
|
|
||||||
|
/* Variable and macro for in-line access to current thread
|
||||||
|
and interpreter state */
|
||||||
|
|
||||||
|
/* Get the current Python thread state.
|
||||||
|
|
||||||
|
Efficient macro reading directly the 'gilstate.tstate_current' atomic
|
||||||
|
variable. The macro is unsafe: it does not check for error and it can
|
||||||
|
return NULL.
|
||||||
|
|
||||||
|
The caller must hold the GIL.
|
||||||
|
|
||||||
|
See also PyThreadState_Get() and PyThreadState_GET(). */
|
||||||
|
#define _PyThreadState_GET() \
|
||||||
|
((PyThreadState*)_Py_atomic_load_relaxed(&_PyRuntime.gilstate.tstate_current))
|
||||||
|
|
||||||
|
/* Redefine PyThreadState_GET() as an alias to _PyThreadState_GET() */
|
||||||
|
#undef PyThreadState_GET
|
||||||
|
#define PyThreadState_GET() _PyThreadState_GET()
|
||||||
|
|
||||||
|
/* Get the current interpreter state.
|
||||||
|
|
||||||
|
The macro is unsafe: it does not check for error and it can return NULL.
|
||||||
|
|
||||||
|
The caller must hold the GIL.
|
||||||
|
|
||||||
|
See also _PyInterpreterState_Get()
|
||||||
|
and _PyGILState_GetInterpreterStateUnsafe(). */
|
||||||
|
#define _PyInterpreterState_GET_UNSAFE() (_PyThreadState_GET()->interp)
|
||||||
|
|
||||||
|
|
||||||
/* Other */
|
/* Other */
|
||||||
|
|
||||||
PyAPI_FUNC(_PyInitError) _PyInterpreterState_Enable(_PyRuntimeState *);
|
PyAPI_FUNC(_PyInitError) _PyInterpreterState_Enable(_PyRuntimeState *);
|
||||||
|
|
|
@ -245,15 +245,17 @@ typedef struct _ts {
|
||||||
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
|
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
|
||||||
PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
|
PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
|
||||||
PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
|
PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
|
||||||
|
|
||||||
#if !defined(Py_LIMITED_API)
|
#if !defined(Py_LIMITED_API)
|
||||||
|
/* Get the current interpreter state.
|
||||||
|
|
||||||
|
Issue a fatal error if there no current Python thread state or no current
|
||||||
|
interpreter. It cannot return NULL.
|
||||||
|
|
||||||
|
The caller must hold the GIL.*/
|
||||||
PyAPI_FUNC(PyInterpreterState *) _PyInterpreterState_Get(void);
|
PyAPI_FUNC(PyInterpreterState *) _PyInterpreterState_Get(void);
|
||||||
#endif
|
#endif
|
||||||
#ifdef Py_BUILD_CORE
|
|
||||||
/* Macro which should only be used for performance critical code.
|
|
||||||
Need "#include "pycore_state.h". See also _PyInterpreterState_Get()
|
|
||||||
and _PyGILState_GetInterpreterStateUnsafe(). */
|
|
||||||
# define _PyInterpreterState_GET_UNSAFE() (PyThreadState_GET()->interp)
|
|
||||||
#endif
|
|
||||||
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000
|
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000
|
||||||
/* New in 3.7 */
|
/* New in 3.7 */
|
||||||
PyAPI_FUNC(int64_t) PyInterpreterState_GetID(PyInterpreterState *);
|
PyAPI_FUNC(int64_t) PyInterpreterState_GetID(PyInterpreterState *);
|
||||||
|
@ -286,11 +288,27 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
|
||||||
PyAPI_FUNC(void) _PyGILState_Reinit(void);
|
PyAPI_FUNC(void) _PyGILState_Reinit(void);
|
||||||
#endif /* !Py_LIMITED_API */
|
#endif /* !Py_LIMITED_API */
|
||||||
|
|
||||||
/* Return the current thread state. The global interpreter lock must be held.
|
/* Get the current thread state.
|
||||||
* When the current thread state is NULL, this issues a fatal error (so that
|
|
||||||
* the caller needn't check for NULL). */
|
When the current thread state is NULL, this issues a fatal error (so that
|
||||||
|
the caller needn't check for NULL).
|
||||||
|
|
||||||
|
The caller must hold the GIL.
|
||||||
|
|
||||||
|
See also PyThreadState_GET() and _PyThreadState_GET(). */
|
||||||
PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
|
PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
|
||||||
|
|
||||||
|
/* Get the current Python thread state.
|
||||||
|
|
||||||
|
Macro using PyThreadState_Get() or _PyThreadState_GET() depending if
|
||||||
|
pycore_state.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(). */
|
||||||
|
#define PyThreadState_GET() PyThreadState_Get()
|
||||||
|
|
||||||
#ifndef Py_LIMITED_API
|
#ifndef Py_LIMITED_API
|
||||||
/* Similar to PyThreadState_Get(), but don't issue a fatal error
|
/* Similar to PyThreadState_Get(), but don't issue a fatal error
|
||||||
* if it is NULL. */
|
* if it is NULL. */
|
||||||
|
@ -301,18 +319,6 @@ PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);
|
||||||
PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
|
PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
|
||||||
PyAPI_FUNC(int) PyThreadState_SetAsyncExc(unsigned long, PyObject *);
|
PyAPI_FUNC(int) PyThreadState_SetAsyncExc(unsigned long, PyObject *);
|
||||||
|
|
||||||
|
|
||||||
/* Variable and macro for in-line access to current thread state */
|
|
||||||
|
|
||||||
/* Assuming the current thread holds the GIL, this is the
|
|
||||||
PyThreadState for the current thread. */
|
|
||||||
#ifdef Py_BUILD_CORE
|
|
||||||
# define PyThreadState_GET() \
|
|
||||||
((PyThreadState*)_Py_atomic_load_relaxed(&_PyRuntime.gilstate.tstate_current))
|
|
||||||
#else
|
|
||||||
# define PyThreadState_GET() PyThreadState_Get()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef
|
typedef
|
||||||
enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
|
enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
|
||||||
PyGILState_STATE;
|
PyGILState_STATE;
|
||||||
|
@ -366,11 +372,11 @@ PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void);
|
||||||
The function returns 1 if _PyGILState_check_enabled is non-zero. */
|
The function returns 1 if _PyGILState_check_enabled is non-zero. */
|
||||||
PyAPI_FUNC(int) PyGILState_Check(void);
|
PyAPI_FUNC(int) PyGILState_Check(void);
|
||||||
|
|
||||||
/* Unsafe function to get the single PyInterpreterState used by this process'
|
/* Get the single PyInterpreterState used by this process' GILState
|
||||||
GILState implementation.
|
implementation.
|
||||||
|
|
||||||
Return NULL before _PyGILState_Init() is called and after _PyGILState_Fini()
|
This function doesn't check for error. Return NULL before _PyGILState_Init()
|
||||||
is called.
|
is called and after _PyGILState_Fini() is called.
|
||||||
|
|
||||||
See also _PyInterpreterState_Get() and _PyInterpreterState_GET_UNSAFE(). */
|
See also _PyInterpreterState_Get() and _PyInterpreterState_GET_UNSAFE(). */
|
||||||
PyAPI_FUNC(PyInterpreterState *) _PyGILState_GetInterpreterStateUnsafe(void);
|
PyAPI_FUNC(PyInterpreterState *) _PyGILState_GetInterpreterStateUnsafe(void);
|
||||||
|
|
|
@ -4160,7 +4160,7 @@ test_PyTime_AsMicroseconds(PyObject *self, PyObject *args)
|
||||||
static PyObject*
|
static PyObject*
|
||||||
get_recursion_depth(PyObject *self, PyObject *args)
|
get_recursion_depth(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = PyThreadState_Get();
|
||||||
|
|
||||||
/* subtract one to ignore the frame of the get_recursion_depth() call */
|
/* subtract one to ignore the frame of the get_recursion_depth() call */
|
||||||
return PyLong_FromLong(tstate->recursion_depth - 1);
|
return PyLong_FromLong(tstate->recursion_depth - 1);
|
||||||
|
|
|
@ -258,7 +258,7 @@ function_code_fastcall(PyCodeObject *co, PyObject *const *args, Py_ssize_t nargs
|
||||||
PyObject *globals)
|
PyObject *globals)
|
||||||
{
|
{
|
||||||
PyFrameObject *f;
|
PyFrameObject *f;
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
PyObject **fastlocals;
|
PyObject **fastlocals;
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
|
|
@ -1314,9 +1314,9 @@ PyDict_GetItem(PyObject *op, PyObject *key)
|
||||||
/* We can arrive here with a NULL tstate during initialization: try
|
/* We can arrive here with a NULL tstate during initialization: try
|
||||||
running "python -Wi" for an example related to string interning.
|
running "python -Wi" for an example related to string interning.
|
||||||
Let's just hope that no exception occurs then... This must be
|
Let's just hope that no exception occurs then... This must be
|
||||||
PyThreadState_GET() and not PyThreadState_Get() because the latter
|
_PyThreadState_GET() and not PyThreadState_Get() because the latter
|
||||||
abort Python if tstate is NULL. */
|
abort Python if tstate is NULL. */
|
||||||
tstate = PyThreadState_GET();
|
tstate = _PyThreadState_GET();
|
||||||
if (tstate != NULL && tstate->curexc_type != NULL) {
|
if (tstate != NULL && tstate->curexc_type != NULL) {
|
||||||
/* preserve the existing exception */
|
/* preserve the existing exception */
|
||||||
PyObject *err_type, *err_value, *err_tb;
|
PyObject *err_type, *err_value, *err_tb;
|
||||||
|
|
|
@ -151,7 +151,7 @@ gen_dealloc(PyGenObject *gen)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
|
gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
PyFrameObject *f = gen->gi_frame;
|
PyFrameObject *f = gen->gi_frame;
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
|
||||||
|
@ -1157,7 +1157,7 @@ PyCoro_New(PyFrameObject *f, PyObject *name, PyObject *qualname)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
int origin_depth = tstate->coroutine_origin_tracking_depth;
|
int origin_depth = tstate->coroutine_origin_tracking_depth;
|
||||||
|
|
||||||
if (origin_depth == 0) {
|
if (origin_depth == 0) {
|
||||||
|
@ -1267,7 +1267,7 @@ async_gen_init_hooks(PyAsyncGenObject *o)
|
||||||
|
|
||||||
o->ag_hooks_inited = 1;
|
o->ag_hooks_inited = 1;
|
||||||
|
|
||||||
tstate = PyThreadState_GET();
|
tstate = _PyThreadState_GET();
|
||||||
|
|
||||||
finalizer = tstate->async_gen_finalizer;
|
finalizer = tstate->async_gen_finalizer;
|
||||||
if (finalizer) {
|
if (finalizer) {
|
||||||
|
|
|
@ -2136,7 +2136,7 @@ _PyTrash_deposit_object(PyObject *op)
|
||||||
void
|
void
|
||||||
_PyTrash_thread_deposit_object(PyObject *op)
|
_PyTrash_thread_deposit_object(PyObject *op)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
_PyObject_ASSERT(op, PyObject_IS_GC(op));
|
_PyObject_ASSERT(op, PyObject_IS_GC(op));
|
||||||
_PyObject_ASSERT(op, !_PyObject_GC_IS_TRACKED(op));
|
_PyObject_ASSERT(op, !_PyObject_GC_IS_TRACKED(op));
|
||||||
_PyObject_ASSERT(op, op->ob_refcnt == 0);
|
_PyObject_ASSERT(op, op->ob_refcnt == 0);
|
||||||
|
@ -2174,7 +2174,7 @@ _PyTrash_destroy_chain(void)
|
||||||
void
|
void
|
||||||
_PyTrash_thread_destroy_chain(void)
|
_PyTrash_thread_destroy_chain(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
/* We need to increase trash_delete_nesting here, otherwise,
|
/* We need to increase trash_delete_nesting here, otherwise,
|
||||||
_PyTrash_thread_destroy_chain will be called recursively
|
_PyTrash_thread_destroy_chain will be called recursively
|
||||||
and then possibly crash. An example that may crash without
|
and then possibly crash. An example that may crash without
|
||||||
|
|
|
@ -1355,7 +1355,7 @@ static PyGetSetDef odict_getset[] = {
|
||||||
static void
|
static void
|
||||||
odict_dealloc(PyODictObject *self)
|
odict_dealloc(PyODictObject *self)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
|
|
||||||
PyObject_GC_UnTrack(self);
|
PyObject_GC_UnTrack(self);
|
||||||
Py_TRASHCAN_SAFE_BEGIN(self)
|
Py_TRASHCAN_SAFE_BEGIN(self)
|
||||||
|
|
|
@ -1115,7 +1115,7 @@ subtype_dealloc(PyObject *self)
|
||||||
{
|
{
|
||||||
PyTypeObject *type, *base;
|
PyTypeObject *type, *base;
|
||||||
destructor basedealloc;
|
destructor basedealloc;
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
int has_finalizer;
|
int has_finalizer;
|
||||||
|
|
||||||
/* Extract the type; we expect it to be a heap type */
|
/* Extract the type; we expect it to be a heap type */
|
||||||
|
@ -7678,7 +7678,7 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
|
||||||
PyFrameObject *f;
|
PyFrameObject *f;
|
||||||
PyCodeObject *co;
|
PyCodeObject *co;
|
||||||
Py_ssize_t i, n;
|
Py_ssize_t i, n;
|
||||||
f = PyThreadState_GET()->frame;
|
f = _PyThreadState_GET()->frame;
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
PyErr_SetString(PyExc_RuntimeError,
|
PyErr_SetString(PyExc_RuntimeError,
|
||||||
"super(): no current frame");
|
"super(): no current frame");
|
||||||
|
|
|
@ -301,7 +301,7 @@ PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
|
||||||
char *rv, *res;
|
char *rv, *res;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if (_PyOS_ReadlineTState == PyThreadState_GET()) {
|
if (_PyOS_ReadlineTState == _PyThreadState_GET()) {
|
||||||
PyErr_SetString(PyExc_RuntimeError,
|
PyErr_SetString(PyExc_RuntimeError,
|
||||||
"can't re-enter readline");
|
"can't re-enter readline");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -316,7 +316,7 @@ PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
|
||||||
_PyOS_ReadlineLock = PyThread_allocate_lock();
|
_PyOS_ReadlineLock = PyThread_allocate_lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
_PyOS_ReadlineTState = PyThreadState_GET();
|
_PyOS_ReadlineTState = _PyThreadState_GET();
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
PyThread_acquire_lock(_PyOS_ReadlineLock, 1);
|
PyThread_acquire_lock(_PyOS_ReadlineLock, 1);
|
||||||
|
|
||||||
|
|
|
@ -671,7 +671,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
|
||||||
PyObject *globals;
|
PyObject *globals;
|
||||||
|
|
||||||
/* Setup globals, filename and lineno. */
|
/* Setup globals, filename and lineno. */
|
||||||
PyFrameObject *f = PyThreadState_GET()->frame;
|
PyFrameObject *f = _PyThreadState_GET()->frame;
|
||||||
// Stack level comparisons to Python code is off by one as there is no
|
// Stack level comparisons to Python code is off by one as there is no
|
||||||
// warnings-related stack level to avoid.
|
// warnings-related stack level to avoid.
|
||||||
if (stack_level <= 0 || is_internal_frame(f)) {
|
if (stack_level <= 0 || is_internal_frame(f)) {
|
||||||
|
|
|
@ -157,7 +157,7 @@ PyEval_InitThreads(void)
|
||||||
if (gil_created())
|
if (gil_created())
|
||||||
return;
|
return;
|
||||||
create_gil();
|
create_gil();
|
||||||
take_gil(PyThreadState_GET());
|
take_gil(_PyThreadState_GET());
|
||||||
_PyRuntime.ceval.pending.main_thread = PyThread_get_thread_ident();
|
_PyRuntime.ceval.pending.main_thread = PyThread_get_thread_ident();
|
||||||
if (!_PyRuntime.ceval.pending.lock)
|
if (!_PyRuntime.ceval.pending.lock)
|
||||||
_PyRuntime.ceval.pending.lock = PyThread_allocate_lock();
|
_PyRuntime.ceval.pending.lock = PyThread_allocate_lock();
|
||||||
|
@ -175,7 +175,7 @@ _PyEval_FiniThreads(void)
|
||||||
void
|
void
|
||||||
PyEval_AcquireLock(void)
|
PyEval_AcquireLock(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (tstate == NULL)
|
if (tstate == NULL)
|
||||||
Py_FatalError("PyEval_AcquireLock: current thread state is NULL");
|
Py_FatalError("PyEval_AcquireLock: current thread state is NULL");
|
||||||
take_gil(tstate);
|
take_gil(tstate);
|
||||||
|
@ -185,10 +185,10 @@ void
|
||||||
PyEval_ReleaseLock(void)
|
PyEval_ReleaseLock(void)
|
||||||
{
|
{
|
||||||
/* This function must succeed when the current thread state is NULL.
|
/* 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.
|
in debug mode.
|
||||||
*/
|
*/
|
||||||
drop_gil(PyThreadState_GET());
|
drop_gil(_PyThreadState_GET());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -222,7 +222,7 @@ PyEval_ReleaseThread(PyThreadState *tstate)
|
||||||
void
|
void
|
||||||
PyEval_ReInitThreads(void)
|
PyEval_ReInitThreads(void)
|
||||||
{
|
{
|
||||||
PyThreadState *current_tstate = PyThreadState_GET();
|
PyThreadState *current_tstate = _PyThreadState_GET();
|
||||||
|
|
||||||
if (!gil_created())
|
if (!gil_created())
|
||||||
return;
|
return;
|
||||||
|
@ -462,7 +462,7 @@ Py_SetRecursionLimit(int new_limit)
|
||||||
int
|
int
|
||||||
_Py_CheckRecursiveCall(const char *where)
|
_Py_CheckRecursiveCall(const char *where)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
int recursion_limit = _PyRuntime.ceval.recursion_limit;
|
int recursion_limit = _PyRuntime.ceval.recursion_limit;
|
||||||
|
|
||||||
#ifdef USE_STACKCHECK
|
#ifdef USE_STACKCHECK
|
||||||
|
@ -543,7 +543,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
|
||||||
int oparg; /* Current opcode argument, if any */
|
int oparg; /* Current opcode argument, if any */
|
||||||
PyObject **fastlocals, **freevars;
|
PyObject **fastlocals, **freevars;
|
||||||
PyObject *retval = NULL; /* Return value */
|
PyObject *retval = NULL; /* Return value */
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
PyCodeObject *co;
|
PyCodeObject *co;
|
||||||
|
|
||||||
/* when tracing we set things up so that
|
/* when tracing we set things up so that
|
||||||
|
@ -3702,7 +3702,7 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the frame */
|
/* Create the frame */
|
||||||
tstate = PyThreadState_GET();
|
tstate = _PyThreadState_GET();
|
||||||
assert(tstate != NULL);
|
assert(tstate != NULL);
|
||||||
f = _PyFrame_New_NoTrack(tstate, co, globals, locals);
|
f = _PyFrame_New_NoTrack(tstate, co, globals, locals);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
|
@ -4003,7 +4003,7 @@ do_raise(PyObject *exc, PyObject *cause)
|
||||||
|
|
||||||
if (exc == NULL) {
|
if (exc == NULL) {
|
||||||
/* Reraise */
|
/* Reraise */
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
_PyErr_StackItem *exc_info = _PyErr_GetTopmostException(tstate);
|
_PyErr_StackItem *exc_info = _PyErr_GetTopmostException(tstate);
|
||||||
PyObject *tb;
|
PyObject *tb;
|
||||||
type = exc_info->exc_type;
|
type = exc_info->exc_type;
|
||||||
|
@ -4275,7 +4275,7 @@ call_trace(Py_tracefunc func, PyObject *obj,
|
||||||
PyObject *
|
PyObject *
|
||||||
_PyEval_CallTracing(PyObject *func, PyObject *args)
|
_PyEval_CallTracing(PyObject *func, PyObject *args)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
int save_tracing = tstate->tracing;
|
int save_tracing = tstate->tracing;
|
||||||
int save_use_tracing = tstate->use_tracing;
|
int save_use_tracing = tstate->use_tracing;
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
@ -4329,7 +4329,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
|
||||||
void
|
void
|
||||||
PyEval_SetProfile(Py_tracefunc func, PyObject *arg)
|
PyEval_SetProfile(Py_tracefunc func, PyObject *arg)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
PyObject *temp = tstate->c_profileobj;
|
PyObject *temp = tstate->c_profileobj;
|
||||||
Py_XINCREF(arg);
|
Py_XINCREF(arg);
|
||||||
tstate->c_profilefunc = NULL;
|
tstate->c_profilefunc = NULL;
|
||||||
|
@ -4346,7 +4346,7 @@ PyEval_SetProfile(Py_tracefunc func, PyObject *arg)
|
||||||
void
|
void
|
||||||
PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
|
PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
PyObject *temp = tstate->c_traceobj;
|
PyObject *temp = tstate->c_traceobj;
|
||||||
_Py_TracingPossible += (func != NULL) - (tstate->c_tracefunc != NULL);
|
_Py_TracingPossible += (func != NULL) - (tstate->c_tracefunc != NULL);
|
||||||
Py_XINCREF(arg);
|
Py_XINCREF(arg);
|
||||||
|
@ -4366,21 +4366,21 @@ void
|
||||||
_PyEval_SetCoroutineOriginTrackingDepth(int new_depth)
|
_PyEval_SetCoroutineOriginTrackingDepth(int new_depth)
|
||||||
{
|
{
|
||||||
assert(new_depth >= 0);
|
assert(new_depth >= 0);
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
tstate->coroutine_origin_tracking_depth = new_depth;
|
tstate->coroutine_origin_tracking_depth = new_depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_PyEval_GetCoroutineOriginTrackingDepth(void)
|
_PyEval_GetCoroutineOriginTrackingDepth(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
return tstate->coroutine_origin_tracking_depth;
|
return tstate->coroutine_origin_tracking_depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_PyEval_SetCoroutineWrapper(PyObject *wrapper)
|
_PyEval_SetCoroutineWrapper(PyObject *wrapper)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
|
|
||||||
Py_XINCREF(wrapper);
|
Py_XINCREF(wrapper);
|
||||||
Py_XSETREF(tstate->coroutine_wrapper, wrapper);
|
Py_XSETREF(tstate->coroutine_wrapper, wrapper);
|
||||||
|
@ -4389,14 +4389,14 @@ _PyEval_SetCoroutineWrapper(PyObject *wrapper)
|
||||||
PyObject *
|
PyObject *
|
||||||
_PyEval_GetCoroutineWrapper(void)
|
_PyEval_GetCoroutineWrapper(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
return tstate->coroutine_wrapper;
|
return tstate->coroutine_wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_PyEval_SetAsyncGenFirstiter(PyObject *firstiter)
|
_PyEval_SetAsyncGenFirstiter(PyObject *firstiter)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
|
|
||||||
Py_XINCREF(firstiter);
|
Py_XINCREF(firstiter);
|
||||||
Py_XSETREF(tstate->async_gen_firstiter, firstiter);
|
Py_XSETREF(tstate->async_gen_firstiter, firstiter);
|
||||||
|
@ -4405,14 +4405,14 @@ _PyEval_SetAsyncGenFirstiter(PyObject *firstiter)
|
||||||
PyObject *
|
PyObject *
|
||||||
_PyEval_GetAsyncGenFirstiter(void)
|
_PyEval_GetAsyncGenFirstiter(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
return tstate->async_gen_firstiter;
|
return tstate->async_gen_firstiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_PyEval_SetAsyncGenFinalizer(PyObject *finalizer)
|
_PyEval_SetAsyncGenFinalizer(PyObject *finalizer)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
|
|
||||||
Py_XINCREF(finalizer);
|
Py_XINCREF(finalizer);
|
||||||
Py_XSETREF(tstate->async_gen_finalizer, finalizer);
|
Py_XSETREF(tstate->async_gen_finalizer, finalizer);
|
||||||
|
@ -4421,7 +4421,7 @@ _PyEval_SetAsyncGenFinalizer(PyObject *finalizer)
|
||||||
PyObject *
|
PyObject *
|
||||||
_PyEval_GetAsyncGenFinalizer(void)
|
_PyEval_GetAsyncGenFinalizer(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
return tstate->async_gen_finalizer;
|
return tstate->async_gen_finalizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4465,7 +4465,7 @@ PyEval_GetGlobals(void)
|
||||||
PyFrameObject *
|
PyFrameObject *
|
||||||
PyEval_GetFrame(void)
|
PyEval_GetFrame(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
return _PyThreadState_GetFrame(tstate);
|
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.
|
presumed to be the most frequent callable object.
|
||||||
*/
|
*/
|
||||||
if (PyCFunction_Check(func)) {
|
if (PyCFunction_Check(func)) {
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
C_TRACE(x, _PyCFunction_FastCallKeywords(func, stack, nargs, kwnames));
|
C_TRACE(x, _PyCFunction_FastCallKeywords(func, stack, nargs, kwnames));
|
||||||
}
|
}
|
||||||
else if (Py_TYPE(func) == &PyMethodDescr_Type) {
|
else if (Py_TYPE(func) == &PyMethodDescr_Type) {
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (nargs > 0 && tstate->use_tracing) {
|
if (nargs > 0 && tstate->use_tracing) {
|
||||||
/* We need to create a temporary bound method as argument
|
/* We need to create a temporary bound method as argument
|
||||||
for profiling.
|
for profiling.
|
||||||
|
@ -4640,12 +4640,12 @@ do_call_core(PyObject *func, PyObject *callargs, PyObject *kwdict)
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
|
||||||
if (PyCFunction_Check(func)) {
|
if (PyCFunction_Check(func)) {
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));
|
C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else if (Py_TYPE(func) == &PyMethodDescr_Type) {
|
else if (Py_TYPE(func) == &PyMethodDescr_Type) {
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
Py_ssize_t nargs = PyTuple_GET_SIZE(callargs);
|
Py_ssize_t nargs = PyTuple_GET_SIZE(callargs);
|
||||||
if (nargs > 0 && tstate->use_tracing) {
|
if (nargs > 0 && tstate->use_tracing) {
|
||||||
/* We need to create a temporary bound method as argument
|
/* We need to create a temporary bound method as argument
|
||||||
|
|
|
@ -112,7 +112,7 @@ PyContext_Enter(PyObject *octx)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyThreadState *ts = PyThreadState_GET();
|
PyThreadState *ts = _PyThreadState_GET();
|
||||||
assert(ts != NULL);
|
assert(ts != NULL);
|
||||||
|
|
||||||
ctx->ctx_prev = (PyContext *)ts->context; /* borrow */
|
ctx->ctx_prev = (PyContext *)ts->context; /* borrow */
|
||||||
|
@ -138,7 +138,7 @@ PyContext_Exit(PyObject *octx)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyThreadState *ts = PyThreadState_GET();
|
PyThreadState *ts = _PyThreadState_GET();
|
||||||
assert(ts != NULL);
|
assert(ts != NULL);
|
||||||
|
|
||||||
if (ts->context != (PyObject *)ctx) {
|
if (ts->context != (PyObject *)ctx) {
|
||||||
|
@ -178,7 +178,7 @@ PyContextVar_Get(PyObject *ovar, PyObject *def, PyObject **val)
|
||||||
ENSURE_ContextVar(ovar, -1)
|
ENSURE_ContextVar(ovar, -1)
|
||||||
PyContextVar *var = (PyContextVar *)ovar;
|
PyContextVar *var = (PyContextVar *)ovar;
|
||||||
|
|
||||||
PyThreadState *ts = PyThreadState_GET();
|
PyThreadState *ts = _PyThreadState_GET();
|
||||||
assert(ts != NULL);
|
assert(ts != NULL);
|
||||||
if (ts->context == NULL) {
|
if (ts->context == NULL) {
|
||||||
goto not_found;
|
goto not_found;
|
||||||
|
@ -382,7 +382,7 @@ context_new_from_vars(PyHamtObject *vars)
|
||||||
static inline PyContext *
|
static inline PyContext *
|
||||||
context_get(void)
|
context_get(void)
|
||||||
{
|
{
|
||||||
PyThreadState *ts = PyThreadState_GET();
|
PyThreadState *ts = _PyThreadState_GET();
|
||||||
assert(ts != NULL);
|
assert(ts != NULL);
|
||||||
PyContext *current_ctx = (PyContext *)ts->context;
|
PyContext *current_ctx = (PyContext *)ts->context;
|
||||||
if (current_ctx == NULL) {
|
if (current_ctx == NULL) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ _Py_IDENTIFIER(stderr);
|
||||||
void
|
void
|
||||||
PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)
|
PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
PyObject *oldtype, *oldvalue, *oldtraceback;
|
PyObject *oldtype, *oldvalue, *oldtraceback;
|
||||||
|
|
||||||
if (traceback != NULL && !PyTraceBack_Check(traceback)) {
|
if (traceback != NULL && !PyTraceBack_Check(traceback)) {
|
||||||
|
@ -82,7 +82,7 @@ _PyErr_CreateException(PyObject *exception, PyObject *value)
|
||||||
void
|
void
|
||||||
PyErr_SetObject(PyObject *exception, PyObject *value)
|
PyErr_SetObject(PyObject *exception, PyObject *value)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
PyObject *exc_value;
|
PyObject *exc_value;
|
||||||
PyObject *tb = NULL;
|
PyObject *tb = NULL;
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ PyErr_SetString(PyObject *exception, const char *string)
|
||||||
PyObject* _Py_HOT_FUNCTION
|
PyObject* _Py_HOT_FUNCTION
|
||||||
PyErr_Occurred(void)
|
PyErr_Occurred(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
return tstate == NULL ? NULL : tstate->curexc_type;
|
return tstate == NULL ? NULL : tstate->curexc_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
|
||||||
void
|
void
|
||||||
PyErr_Fetch(PyObject **p_type, PyObject **p_value, PyObject **p_traceback)
|
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_type = tstate->curexc_type;
|
||||||
*p_value = tstate->curexc_value;
|
*p_value = tstate->curexc_value;
|
||||||
|
@ -354,7 +354,7 @@ PyErr_Clear(void)
|
||||||
void
|
void
|
||||||
PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback)
|
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);
|
_PyErr_StackItem *exc_info = _PyErr_GetTopmostException(tstate);
|
||||||
*p_type = exc_info->exc_type;
|
*p_type = exc_info->exc_type;
|
||||||
|
@ -371,7 +371,7 @@ void
|
||||||
PyErr_SetExcInfo(PyObject *p_type, PyObject *p_value, PyObject *p_traceback)
|
PyErr_SetExcInfo(PyObject *p_type, PyObject *p_value, PyObject *p_traceback)
|
||||||
{
|
{
|
||||||
PyObject *oldtype, *oldvalue, *oldtraceback;
|
PyObject *oldtype, *oldvalue, *oldtraceback;
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
|
|
||||||
oldtype = tstate->exc_info->exc_type;
|
oldtype = tstate->exc_info->exc_type;
|
||||||
oldvalue = tstate->exc_info->exc_value;
|
oldvalue = tstate->exc_info->exc_value;
|
||||||
|
|
|
@ -530,7 +530,7 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p,
|
||||||
/* bpo-34008: For backward compatibility reasons, calling Py_Main() after
|
/* bpo-34008: For backward compatibility reasons, calling Py_Main() after
|
||||||
Py_Initialize() ignores the new configuration. */
|
Py_Initialize() ignores the new configuration. */
|
||||||
if (_PyRuntime.core_initialized) {
|
if (_PyRuntime.core_initialized) {
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (!tstate) {
|
if (!tstate) {
|
||||||
return _Py_INIT_ERR("failed to read thread state");
|
return _Py_INIT_ERR("failed to read thread state");
|
||||||
}
|
}
|
||||||
|
@ -1009,7 +1009,7 @@ Py_FinalizeEx(void)
|
||||||
wait_for_thread_shutdown();
|
wait_for_thread_shutdown();
|
||||||
|
|
||||||
/* Get current thread state and interpreter pointer */
|
/* Get current thread state and interpreter pointer */
|
||||||
tstate = PyThreadState_GET();
|
tstate = _PyThreadState_GET();
|
||||||
interp = tstate->interp;
|
interp = tstate->interp;
|
||||||
|
|
||||||
/* The interpreter is still entirely intact at this point, and the
|
/* The interpreter is still entirely intact at this point, and the
|
||||||
|
@ -1406,7 +1406,7 @@ Py_EndInterpreter(PyThreadState *tstate)
|
||||||
{
|
{
|
||||||
PyInterpreterState *interp = tstate->interp;
|
PyInterpreterState *interp = tstate->interp;
|
||||||
|
|
||||||
if (tstate != PyThreadState_GET())
|
if (tstate != _PyThreadState_GET())
|
||||||
Py_FatalError("Py_EndInterpreter: thread is not current");
|
Py_FatalError("Py_EndInterpreter: thread is not current");
|
||||||
if (tstate->frame != NULL)
|
if (tstate->frame != NULL)
|
||||||
Py_FatalError("Py_EndInterpreter: thread still has a frame");
|
Py_FatalError("Py_EndInterpreter: thread still has a frame");
|
||||||
|
@ -1928,7 +1928,7 @@ fatal_error(const char *prefix, const char *msg, int status)
|
||||||
and holds the GIL */
|
and holds the GIL */
|
||||||
PyThreadState *tss_tstate = PyGILState_GetThisThreadState();
|
PyThreadState *tss_tstate = PyGILState_GetThisThreadState();
|
||||||
if (tss_tstate != NULL) {
|
if (tss_tstate != NULL) {
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (tss_tstate != tstate) {
|
if (tss_tstate != tstate) {
|
||||||
/* The Python thread does not hold the GIL */
|
/* The Python thread does not hold the GIL */
|
||||||
tss_tstate = NULL;
|
tss_tstate = NULL;
|
||||||
|
|
|
@ -307,7 +307,7 @@ _PyInterpreterState_DeleteExceptMain()
|
||||||
PyInterpreterState *
|
PyInterpreterState *
|
||||||
_PyInterpreterState_Get(void)
|
_PyInterpreterState_Get(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (tstate == NULL) {
|
if (tstate == NULL) {
|
||||||
Py_FatalError("_PyInterpreterState_Get(): no current thread state");
|
Py_FatalError("_PyInterpreterState_Get(): no current thread state");
|
||||||
}
|
}
|
||||||
|
@ -689,7 +689,7 @@ tstate_delete_common(PyThreadState *tstate)
|
||||||
void
|
void
|
||||||
PyThreadState_Delete(PyThreadState *tstate)
|
PyThreadState_Delete(PyThreadState *tstate)
|
||||||
{
|
{
|
||||||
if (tstate == PyThreadState_GET())
|
if (tstate == _PyThreadState_GET())
|
||||||
Py_FatalError("PyThreadState_Delete: tstate is still current");
|
Py_FatalError("PyThreadState_Delete: tstate is still current");
|
||||||
if (_PyRuntime.gilstate.autoInterpreterState &&
|
if (_PyRuntime.gilstate.autoInterpreterState &&
|
||||||
PyThread_tss_get(&_PyRuntime.gilstate.autoTSSkey) == tstate)
|
PyThread_tss_get(&_PyRuntime.gilstate.autoTSSkey) == tstate)
|
||||||
|
@ -703,7 +703,7 @@ PyThreadState_Delete(PyThreadState *tstate)
|
||||||
void
|
void
|
||||||
PyThreadState_DeleteCurrent()
|
PyThreadState_DeleteCurrent()
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (tstate == NULL)
|
if (tstate == NULL)
|
||||||
Py_FatalError(
|
Py_FatalError(
|
||||||
"PyThreadState_DeleteCurrent: no current tstate");
|
"PyThreadState_DeleteCurrent: no current tstate");
|
||||||
|
@ -758,14 +758,14 @@ _PyThreadState_DeleteExcept(PyThreadState *tstate)
|
||||||
PyThreadState *
|
PyThreadState *
|
||||||
_PyThreadState_UncheckedGet(void)
|
_PyThreadState_UncheckedGet(void)
|
||||||
{
|
{
|
||||||
return PyThreadState_GET();
|
return _PyThreadState_GET();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyThreadState *
|
PyThreadState *
|
||||||
PyThreadState_Get(void)
|
PyThreadState_Get(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (tstate == NULL)
|
if (tstate == NULL)
|
||||||
Py_FatalError("PyThreadState_Get: no current thread");
|
Py_FatalError("PyThreadState_Get: no current thread");
|
||||||
|
|
||||||
|
@ -776,7 +776,7 @@ PyThreadState_Get(void)
|
||||||
PyThreadState *
|
PyThreadState *
|
||||||
PyThreadState_Swap(PyThreadState *newts)
|
PyThreadState_Swap(PyThreadState *newts)
|
||||||
{
|
{
|
||||||
PyThreadState *oldts = PyThreadState_GET();
|
PyThreadState *oldts = _PyThreadState_GET();
|
||||||
|
|
||||||
_PyThreadState_SET(newts);
|
_PyThreadState_SET(newts);
|
||||||
/* It should not be possible for more than one thread state
|
/* It should not be possible for more than one thread state
|
||||||
|
@ -807,7 +807,7 @@ PyThreadState_Swap(PyThreadState *newts)
|
||||||
PyObject *
|
PyObject *
|
||||||
PyThreadState_GetDict(void)
|
PyThreadState_GetDict(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (tstate == NULL)
|
if (tstate == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -958,7 +958,7 @@ PyThreadState_IsCurrent(PyThreadState *tstate)
|
||||||
{
|
{
|
||||||
/* Must be the tstate for this thread */
|
/* Must be the tstate for this thread */
|
||||||
assert(PyGILState_GetThisThreadState()==tstate);
|
assert(PyGILState_GetThisThreadState()==tstate);
|
||||||
return tstate == PyThreadState_GET();
|
return tstate == _PyThreadState_GET();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Internal initialization/finalization functions called by
|
/* Internal initialization/finalization functions called by
|
||||||
|
@ -1085,7 +1085,7 @@ PyGILState_Check(void)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tstate = PyThreadState_GET();
|
tstate = _PyThreadState_GET();
|
||||||
if (tstate == NULL)
|
if (tstate == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
|
@ -265,7 +265,7 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
|
||||||
st->st_future = future;
|
st->st_future = future;
|
||||||
|
|
||||||
/* Setup recursion depth check counters */
|
/* Setup recursion depth check counters */
|
||||||
tstate = PyThreadState_GET();
|
tstate = _PyThreadState_GET();
|
||||||
if (!tstate) {
|
if (!tstate) {
|
||||||
PySymtable_Free(st);
|
PySymtable_Free(st);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -336,7 +336,7 @@ PyDoc_STRVAR(excepthook_doc,
|
||||||
static PyObject *
|
static PyObject *
|
||||||
sys_exc_info(PyObject *self, PyObject *noargs)
|
sys_exc_info(PyObject *self, PyObject *noargs)
|
||||||
{
|
{
|
||||||
_PyErr_StackItem *err_info = _PyErr_GetTopmostException(PyThreadState_GET());
|
_PyErr_StackItem *err_info = _PyErr_GetTopmostException(_PyThreadState_GET());
|
||||||
return Py_BuildValue(
|
return Py_BuildValue(
|
||||||
"(OOO)",
|
"(OOO)",
|
||||||
err_info->exc_type != NULL ? err_info->exc_type : Py_None,
|
err_info->exc_type != NULL ? err_info->exc_type : Py_None,
|
||||||
|
@ -565,7 +565,7 @@ function call. See the debugger chapter in the library manual."
|
||||||
static PyObject *
|
static PyObject *
|
||||||
sys_gettrace(PyObject *self, PyObject *args)
|
sys_gettrace(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
PyObject *temp = tstate->c_traceobj;
|
PyObject *temp = tstate->c_traceobj;
|
||||||
|
|
||||||
if (temp == NULL)
|
if (temp == NULL)
|
||||||
|
@ -603,7 +603,7 @@ and return. See the profiler chapter in the library manual."
|
||||||
static PyObject *
|
static PyObject *
|
||||||
sys_getprofile(PyObject *self, PyObject *args)
|
sys_getprofile(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
PyObject *temp = tstate->c_profileobj;
|
PyObject *temp = tstate->c_profileobj;
|
||||||
|
|
||||||
if (temp == NULL)
|
if (temp == NULL)
|
||||||
|
@ -722,7 +722,7 @@ sys_setrecursionlimit(PyObject *self, PyObject *args)
|
||||||
the new low-water mark. Otherwise it may not be possible anymore to
|
the new low-water mark. Otherwise it may not be possible anymore to
|
||||||
reset the overflowed flag to 0. */
|
reset the overflowed flag to 0. */
|
||||||
mark = _Py_RecursionLimitLowerWaterMark(new_limit);
|
mark = _Py_RecursionLimitLowerWaterMark(new_limit);
|
||||||
tstate = PyThreadState_GET();
|
tstate = _PyThreadState_GET();
|
||||||
if (tstate->recursion_depth >= mark) {
|
if (tstate->recursion_depth >= mark) {
|
||||||
PyErr_Format(PyExc_RecursionError,
|
PyErr_Format(PyExc_RecursionError,
|
||||||
"cannot set the recursion limit to %i at "
|
"cannot set the recursion limit to %i at "
|
||||||
|
@ -1362,7 +1362,7 @@ purposes only."
|
||||||
static PyObject *
|
static PyObject *
|
||||||
sys_getframe(PyObject *self, PyObject *args)
|
sys_getframe(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyFrameObject *f = PyThreadState_GET()->frame;
|
PyFrameObject *f = _PyThreadState_GET()->frame;
|
||||||
int depth = -1;
|
int depth = -1;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "|i:_getframe", &depth))
|
if (!PyArg_ParseTuple(args, "|i:_getframe", &depth))
|
||||||
|
@ -1745,7 +1745,7 @@ static int
|
||||||
_PySys_ReadPreInitOptions(void)
|
_PySys_ReadPreInitOptions(void)
|
||||||
{
|
{
|
||||||
/* Rerun the add commands with the actual sys module available */
|
/* Rerun the add commands with the actual sys module available */
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (tstate == NULL) {
|
if (tstate == NULL) {
|
||||||
/* Still don't have a thread state, so something is wrong! */
|
/* Still don't have a thread state, so something is wrong! */
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1796,7 +1796,7 @@ get_warnoptions(void)
|
||||||
void
|
void
|
||||||
PySys_ResetWarnOptions(void)
|
PySys_ResetWarnOptions(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (tstate == NULL) {
|
if (tstate == NULL) {
|
||||||
_clear_preinit_entries(&_preinit_warnoptions);
|
_clear_preinit_entries(&_preinit_warnoptions);
|
||||||
return;
|
return;
|
||||||
|
@ -1835,7 +1835,7 @@ PySys_AddWarnOptionUnicode(PyObject *option)
|
||||||
void
|
void
|
||||||
PySys_AddWarnOption(const wchar_t *s)
|
PySys_AddWarnOption(const wchar_t *s)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (tstate == NULL) {
|
if (tstate == NULL) {
|
||||||
_append_preinit_entry(&_preinit_warnoptions, s);
|
_append_preinit_entry(&_preinit_warnoptions, s);
|
||||||
return;
|
return;
|
||||||
|
@ -1922,7 +1922,7 @@ error:
|
||||||
void
|
void
|
||||||
PySys_AddXOption(const wchar_t *s)
|
PySys_AddXOption(const wchar_t *s)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (tstate == NULL) {
|
if (tstate == NULL) {
|
||||||
_append_preinit_entry(&_preinit_xoptions, s);
|
_append_preinit_entry(&_preinit_xoptions, s);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -189,7 +189,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
|
||||||
return PYTHREAD_INVALID_THREAD_ID;
|
return PYTHREAD_INVALID_THREAD_ID;
|
||||||
obj->func = func;
|
obj->func = func;
|
||||||
obj->arg = arg;
|
obj->arg = arg;
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
size_t stacksize = tstate ? tstate->interp->pythread_stacksize : 0;
|
size_t stacksize = tstate ? tstate->interp->pythread_stacksize : 0;
|
||||||
hThread = (HANDLE)_beginthreadex(0,
|
hThread = (HANDLE)_beginthreadex(0,
|
||||||
Py_SAFE_DOWNCAST(stacksize, Py_ssize_t, unsigned int),
|
Py_SAFE_DOWNCAST(stacksize, Py_ssize_t, unsigned int),
|
||||||
|
@ -334,13 +334,13 @@ _pythread_nt_set_stacksize(size_t size)
|
||||||
{
|
{
|
||||||
/* set to default */
|
/* set to default */
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
PyThreadState_GET()->interp->pythread_stacksize = 0;
|
_PyInterpreterState_GET_UNSAFE()->pythread_stacksize = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* valid range? */
|
/* valid range? */
|
||||||
if (size >= THREAD_MIN_STACKSIZE && size < THREAD_MAX_STACKSIZE) {
|
if (size >= THREAD_MIN_STACKSIZE && size < THREAD_MAX_STACKSIZE) {
|
||||||
PyThreadState_GET()->interp->pythread_stacksize = size;
|
_PyInterpreterState_GET_UNSAFE()->pythread_stacksize = size;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
|
||||||
return PYTHREAD_INVALID_THREAD_ID;
|
return PYTHREAD_INVALID_THREAD_ID;
|
||||||
#endif
|
#endif
|
||||||
#if defined(THREAD_STACK_SIZE)
|
#if defined(THREAD_STACK_SIZE)
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
size_t stacksize = tstate ? tstate->interp->pythread_stacksize : 0;
|
size_t stacksize = tstate ? tstate->interp->pythread_stacksize : 0;
|
||||||
tss = (stacksize != 0) ? stacksize : THREAD_STACK_SIZE;
|
tss = (stacksize != 0) ? stacksize : THREAD_STACK_SIZE;
|
||||||
if (tss != 0) {
|
if (tss != 0) {
|
||||||
|
@ -591,7 +591,7 @@ _pythread_pthread_set_stacksize(size_t size)
|
||||||
|
|
||||||
/* set to default */
|
/* set to default */
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
PyThreadState_GET()->interp->pythread_stacksize = 0;
|
_PyInterpreterState_GET_UNSAFE()->pythread_stacksize = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,7 +608,7 @@ _pythread_pthread_set_stacksize(size_t size)
|
||||||
rc = pthread_attr_setstacksize(&attrs, size);
|
rc = pthread_attr_setstacksize(&attrs, size);
|
||||||
pthread_attr_destroy(&attrs);
|
pthread_attr_destroy(&attrs);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
PyThreadState_GET()->interp->pythread_stacksize = size;
|
_PyInterpreterState_GET_UNSAFE()->pythread_stacksize = size;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue