diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-03-22 16:45:09 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-03-22 16:45:09 (GMT) |
commit | 4a06647534162c7a1bed0ec01d544758b56a446b (patch) | |
tree | 34c05359145161d218f86ee8f5767dda5da5c5c0 /Modules/_tracemalloc.c | |
parent | 0cfc058d619cea398baf34bfdd94b52620275f88 (diff) | |
download | cpython-4a06647534162c7a1bed0ec01d544758b56a446b.zip cpython-4a06647534162c7a1bed0ec01d544758b56a446b.tar.gz cpython-4a06647534162c7a1bed0ec01d544758b56a446b.tar.bz2 |
Add assertions on tracemalloc_reentrant_key
Issue #26588.
Diffstat (limited to 'Modules/_tracemalloc.c')
-rw-r--r-- | Modules/_tracemalloc.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index baeb58c..5c9f69e 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -167,7 +167,7 @@ tracemalloc_error(const char *format, ...) # error "need native thread local storage (TLS)" #endif -static int tracemalloc_reentrant_key; +static int tracemalloc_reentrant_key = -1; /* Any non-NULL pointer can be used */ #define REENTRANT Py_True @@ -175,7 +175,10 @@ static int tracemalloc_reentrant_key; static int get_reentrant(void) { - void *ptr = PyThread_get_key_value(tracemalloc_reentrant_key); + void *ptr; + + assert(tracemalloc_reentrant_key != -1); + ptr = PyThread_get_key_value(tracemalloc_reentrant_key); if (ptr != NULL) { assert(ptr == REENTRANT); return 1; @@ -188,6 +191,8 @@ static void set_reentrant(int reentrant) { assert(reentrant == 0 || reentrant == 1); + assert(tracemalloc_reentrant_key != -1); + if (reentrant) { assert(!get_reentrant()); PyThread_set_key_value(tracemalloc_reentrant_key, REENTRANT); @@ -1018,6 +1023,7 @@ DEBUG("tracemalloc_deinit(): exit (not initialized)"); DEBUG("tracemalloc_deinit(): delete reentrant key"); #ifdef REENTRANT_THREADLOCAL PyThread_delete_key(tracemalloc_reentrant_key); + tracemalloc_reentrant_key = -1; #endif Py_XDECREF(unknown_filename); |