[Python-checkins] cpython: Add assertions on tracemalloc_reentrant_key
victor.stinner
python-checkins at python.org
Tue Mar 22 12:48:42 EDT 2016
https://hg.python.org/cpython/rev/636fa01842f5
changeset: 100659:636fa01842f5
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Mar 22 17:45:09 2016 +0100
summary:
Add assertions on tracemalloc_reentrant_key
Issue #26588.
files:
Modules/_tracemalloc.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -167,7 +167,7 @@
# 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
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 @@
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(): delete reentrant key");
#ifdef REENTRANT_THREADLOCAL
PyThread_delete_key(tracemalloc_reentrant_key);
+ tracemalloc_reentrant_key = -1;
#endif
Py_XDECREF(unknown_filename);
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list