◐ Shell
clean mode source ↗

bpo-35368: Add assertions in pymalloc to check GIL by vstinner · Pull Request #10866 · python/cpython

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