[Python-checkins] cpython (merge 3.3 -> default): Add sanity assertions in some import lock code (issue #15599).
antoine.pitrou
python-checkins at python.org
Tue Dec 18 22:23:43 CET 2012
http://hg.python.org/cpython/rev/7cfca9ede861
changeset: 80936:7cfca9ede861
parent: 80934:a6ea6f803017
parent: 80935:1ee9cf5a5351
user: Antoine Pitrou <solipsis at pitrou.net>
date: Tue Dec 18 22:18:58 2012 +0100
summary:
Add sanity assertions in some import lock code (issue #15599).
files:
Lib/test/test_threaded_import.py | 1 +
Python/import.c | 2 ++
2 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py
--- a/Lib/test/test_threaded_import.py
+++ b/Lib/test/test_threaded_import.py
@@ -68,6 +68,7 @@
# Simulate some thread-unsafe behaviour. If calls to find_module()
# are properly serialized, `x` will end up the same as `numcalls`.
# Otherwise not.
+ assert imp.lock_held()
with self.lock:
self.numcalls += 1
x = self.x
diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -169,6 +169,7 @@
PyThread_acquire_lock(import_lock, 1);
PyEval_RestoreThread(tstate);
}
+ assert(import_lock_level == 0);
import_lock_thread = me;
import_lock_level = 1;
}
@@ -182,6 +183,7 @@
if (import_lock_thread != me)
return -1;
import_lock_level--;
+ assert(import_lock_level >= 0);
if (import_lock_level == 0) {
import_lock_thread = -1;
PyThread_release_lock(import_lock);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list