[Python-checkins] cpython: Issue #11915: threading.RLock()._release_save() raises a RuntimeError if the
victor.stinner
python-checkins at python.org
Sun Apr 24 23:42:25 CEST 2011
http://hg.python.org/cpython/rev/2c0da1c4f063
changeset: 69543:2c0da1c4f063
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Sun Apr 24 23:41:33 2011 +0200
summary:
Issue #11915: threading.RLock()._release_save() raises a RuntimeError if the
lock was not acquired.
files:
Lib/test/lock_tests.py | 2 ++
Lib/threading.py | 2 ++
Misc/NEWS | 3 +++
Modules/_threadmodule.c | 6 ++++++
4 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -247,6 +247,7 @@
# Cannot release an unacquired lock
lock = self.locktype()
self.assertRaises(RuntimeError, lock.release)
+ self.assertRaises(RuntimeError, lock._release_save)
lock.acquire()
lock.acquire()
lock.release()
@@ -254,6 +255,7 @@
lock.release()
lock.release()
self.assertRaises(RuntimeError, lock.release)
+ self.assertRaises(RuntimeError, lock._release_save)
def test_different_thread(self):
# Cannot release from a different thread
diff --git a/Lib/threading.py b/Lib/threading.py
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -157,6 +157,8 @@
def _release_save(self):
if __debug__:
self._note("%s._release_save()", self)
+ if self._count == 0:
+ raise RuntimeError("cannot release un-acquired lock")
count = self._count
self._count = 0
owner = self._owner
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -113,6 +113,9 @@
Library
-------
+- Issue #11915: threading.RLock()._release_save() raises a RuntimeError if the
+ lock was not acquired.
+
- Issue #11258: Speed up ctypes.util.find_library() under Linux by a factor
of 5 to 10. Initial patch by Jonas H.
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -414,6 +414,12 @@
long owner;
unsigned long count;
+ if (self->rlock_count == 0) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot release un-acquired lock");
+ return NULL;
+ }
+
owner = self->rlock_owner;
count = self->rlock_count;
self->rlock_count = 0;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list