Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ extern "C" {
/* GIL state */

struct _gilstate_runtime_state {
/* Issue #26558: Flag to disable PyGILState_Check().
If set to non-zero, PyGILState_Check() always return 1. */
int check_enabled;
/* Assuming the current thread holds the GIL, this is the
PyThreadState for the current thread. */
Expand All @@ -36,10 +38,6 @@ struct _gilstate_runtime_state {
/* hook for PyEval_GetFrame(), requested for Psyco */
#define _PyThreadState_GetFrame _PyRuntime.gilstate.getframe

/* Issue #26558: Flag to disable PyGILState_Check().
If set to non-zero, PyGILState_Check() always return 1. */
#define _PyGILState_check_enabled _PyRuntime.gilstate.check_enabled


/* interpreter state */

Expand Down
12 changes: 11 additions & 1 deletion Objects/obmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,9 @@ pymalloc_alloc(void *ctx, void **ptr_p, size_t nbytes)
poolp next;
uint size;

/* pymalloc is protected by the GIL */
assert(PyGILState_Check());

#ifdef WITH_VALGRIND
if (UNLIKELY(running_on_valgrind == -1)) {
running_on_valgrind = RUNNING_ON_VALGRIND;
Expand Down Expand Up @@ -1590,6 +1593,9 @@ pymalloc_free(void *ctx, void *p)

assert(p != NULL);

/* pymalloc is protected by the GIL */
assert(PyGILState_Check());

#ifdef WITH_VALGRIND
if (UNLIKELY(running_on_valgrind > 0)) {
return 0;
Expand Down Expand Up @@ -1824,6 +1830,9 @@ pymalloc_realloc(void *ctx, void **newptr_p, void *p, size_t nbytes)

assert(p != NULL);

/* pymalloc is protected by the GIL */
assert(PyGILState_Check());

#ifdef WITH_VALGRIND
/* Treat running_on_valgrind == -1 the same as 0 */
if (UNLIKELY(running_on_valgrind > 0)) {
Expand Down Expand Up @@ -2193,9 +2202,10 @@ _PyMem_DebugRawRealloc(void *ctx, void *p, size_t nbytes)
static void
_PyMem_DebugCheckGIL(void)
{
if (!PyGILState_Check())
if (!PyGILState_Check()) {
Py_FatalError("Python memory allocator called "
"without holding the GIL");
}
}

static void *
Expand Down
2 changes: 1 addition & 1 deletion Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ new_interpreter(PyThreadState **tstate_p)

/* Issue #10915, #15751: The GIL API doesn't work with multiple
interpreters: disable PyGILState_Check(). */
_PyGILState_check_enabled = 0;
_PyRuntime.gilstate.check_enabled = 0;

interp = PyInterpreterState_New();
if (interp == NULL) {
Expand Down
3 changes: 2 additions & 1 deletion Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,9 @@ PyGILState_Check(void)
{
PyThreadState *tstate;

if (!_PyGILState_check_enabled)
if (!_PyRuntime.gilstate.check_enabled) {
return 1;
}

if (!PyThread_tss_is_created(&_PyRuntime.gilstate.autoTSSkey)) {
return 1;
Expand Down