{
assert(reentrant == 0 || reentrant == 1);
if (reentrant) {
- assert(PyThread_get_key_value(tracemalloc_reentrant_key) == NULL);
+ assert(!get_reentrant());
PyThread_set_key_value(tracemalloc_reentrant_key, REENTRANT);
}
else {
- assert(PyThread_get_key_value(tracemalloc_reentrant_key) == REENTRANT);
+ assert(get_reentrant());
PyThread_set_key_value(tracemalloc_reentrant_key, NULL);
}
}
tracemalloc_init(void)
{
DEBUG("tracemalloc_init()");
+
+#ifdef WITH_THREAD
+ assert(PyGILState_Check());
+#endif
+
if (tracemalloc_config.initialized == TRACEMALLOC_FINALIZED) {
PyErr_SetString(PyExc_RuntimeError,
"the tracemalloc module has been unloaded");
size_t size;
DEBUG("tracemalloc_start()");
+
+#ifdef WITH_THREAD
+ assert(PyGILState_Check());
+#endif
+
if (tracemalloc_init() < 0) {
DEBUG("tracemalloc_start(): ERROR! init failed!");
return -1;
if (tracemalloc_config.tracing) {
/* hook already installed: do nothing */
DEBUG("tracemalloc_start(): exit (already tracing)");
+assert(!get_reentrant());
return 0;
}
+assert(get_reentrant());
assert(1 <= max_nframe && max_nframe <= MAX_NFRAME);
tracemalloc_config.max_nframe = max_nframe;
set_reentrant(0);
DEBUG("tracemalloc_start(): done");
+assert(!get_reentrant());
return 0;
}
tracemalloc_stop(void)
{
DEBUG("tracemalloc_stop()");
+
+#ifdef WITH_THREAD
+ assert(PyGILState_Check());
+#endif
+
if (!tracemalloc_config.tracing) {
DEBUG("tracemalloc_stop(): exit (not tracing)");
+assert(get_reentrant());
return;
}
+assert(!get_reentrant());
/* stop tracing Python memory allocations */
tracemalloc_config.tracing = 0;
raw_free(tracemalloc_traceback);
tracemalloc_traceback = NULL;
DEBUG("tracemalloc_stop(): done");
+assert(get_reentrant());
}
PyDoc_STRVAR(tracemalloc_is_tracing_doc,