]> granicus.if.org Git - python/commitdiff
Add sanity assertions in some import lock code (issue #15599).
authorAntoine Pitrou <solipsis@pitrou.net>
Tue, 18 Dec 2012 21:18:17 +0000 (22:18 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Tue, 18 Dec 2012 21:18:17 +0000 (22:18 +0100)
Lib/test/test_threaded_import.py
Python/import.c

index 0528b139f7b45fe30968796ea52171446176d49c..93bfb2a7581381304864a44aa5387a50f1a59977 100644 (file)
@@ -68,6 +68,7 @@ class Finder:
         # 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
index 2f71b97bc8b099d56e9ab071da1610d3345355be..5fc2523b268525c66d3374004cc18f07a7942fee 100644 (file)
@@ -169,6 +169,7 @@ _PyImport_AcquireLock(void)
         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 @@ _PyImport_ReleaseLock(void)
     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);