diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-12-18 21:18:58 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-12-18 21:18:58 (GMT) |
commit | ad8c461e2cd4ca15b72448952f7a6a1ab2325207 (patch) | |
tree | d4057c3bb41302c56910b6950ad3b5ca6fe4d25d | |
parent | 5f11a00056aba124cdeba717b68c4145f96bcfc7 (diff) | |
parent | 202b60640bd873f00ee121cb24ee4a6409eb8993 (diff) | |
download | cpython-ad8c461e2cd4ca15b72448952f7a6a1ab2325207.zip cpython-ad8c461e2cd4ca15b72448952f7a6a1ab2325207.tar.gz cpython-ad8c461e2cd4ca15b72448952f7a6a1ab2325207.tar.bz2 |
Add sanity assertions in some import lock code (issue #15599).
-rw-r--r-- | Lib/test/test_threaded_import.py | 1 | ||||
-rw-r--r-- | 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 index 0528b13..93bfb2a 100644 --- a/Lib/test/test_threaded_import.py +++ b/Lib/test/test_threaded_import.py @@ -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 diff --git a/Python/import.c b/Python/import.c index 5026789..a50ef05 100644 --- a/Python/import.c +++ b/Python/import.c @@ -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); |