From 2f49e091100e7b834767a1a295c63938c6864e55 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 23 Mar 2016 00:10:24 +0100 Subject: Fix _tracemalloc start/stop Issue #26588: Fix _tracemalloc start/stop: don't play with the reentrant flag. set_reentrant(1) fails with an assertion error if tracemalloc_init() is called first in a thread A and tracemalloc_start() is called second in a thread B. The tracemalloc is imported in a thread A. Importing the module calls tracemalloc_init(). tracemalloc.start() is called in a thread B. --- Modules/_tracemalloc.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index fd520f3..0e5f846 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -740,10 +740,6 @@ tracemalloc_clear_traces(void) assert(PyGILState_Check()); #endif - /* Disable also reentrant calls to tracemalloc_malloc() to not add a new - trace while we are clearing traces */ - assert(get_reentrant()); - TABLES_LOCK(); _Py_hashtable_clear(tracemalloc_traces); tracemalloc_traced_memory = 0; @@ -823,11 +819,6 @@ tracemalloc_init(void) tracemalloc_empty_traceback.frames[0].lineno = 0; tracemalloc_empty_traceback.hash = traceback_hash(&tracemalloc_empty_traceback); - /* Disable tracing allocations until hooks are installed. Set - also the reentrant flag to detect bugs: fail with an assertion error - if set_reentrant(1) is called while tracing is disabled. */ - set_reentrant(1); - tracemalloc_config.initialized = TRACEMALLOC_INITIALIZED; return 0; } @@ -912,7 +903,6 @@ tracemalloc_start(int max_nframe) /* everything is ready: start tracing Python memory allocations */ tracemalloc_config.tracing = 1; - set_reentrant(0); return 0; } @@ -926,10 +916,6 @@ tracemalloc_stop(void) /* stop tracing Python memory allocations */ tracemalloc_config.tracing = 0; - /* set the reentrant flag to detect bugs: fail with an assertion error if - set_reentrant(1) is called while tracing is disabled. */ - set_reentrant(1); - /* unregister the hook on memory allocators */ #ifdef TRACE_RAW_MALLOC PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &allocators.raw); -- cgit v0.12 From d5871e62ddf1e826b3aa1fdc0cb888e6090e5408 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 23 Mar 2016 00:17:04 +0100 Subject: Enhance _tracemalloc debug mode Issue #26588: Enhance assertion in set_reentrant() --- Modules/_tracemalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 0e5f846..6327c95 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -189,7 +189,7 @@ get_reentrant(void) static void set_reentrant(int reentrant) { - assert(!reentrant || !get_reentrant()); + assert(reentrant != tracemalloc_reentrant); tracemalloc_reentrant = reentrant; } #endif -- cgit v0.12