summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-07-21 16:55:11 +0200
committerJulian Andres Klode <jak@debian.org>2009-07-21 16:55:11 +0200
commita676f6a0e081e54a0a57dbfca2d14fee381e7d92 (patch)
tree7c2769082948b697d40d3814b51e3e31814d974a /python
parent6f7b3df8f590467e76e99189f6ac9a78f8bec65d (diff)
downloadpython-apt-a676f6a0e081e54a0a57dbfca2d14fee381e7d92.tar.gz
python/lock.cc: Fix refcount in systemlock_enter and behavior of systemlock_exit.
Diffstat (limited to 'python')
-rw-r--r--python/lock.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/python/lock.cc b/python/lock.cc
index aac2d25a..75665779 100644
--- a/python/lock.cc
+++ b/python/lock.cc
@@ -33,9 +33,18 @@ static PyObject *systemlock_exit(PyObject *self, PyObject *args)
&traceback)) {
return 0;
}
- if ((! exc_type || exc_type == Py_None) && _system->UnLock() == 0) {
- return HandleErrors();
+
+ if (_system->UnLock() == 0) {
+ // The unlock failed. If no exception happened within the suite, we
+ // will raise an error here. Otherwise, we just display the error, so
+ // Python can handle the original exception instead.
+ HandleErrors();
+ if (exc_type == Py_None)
+ return NULL;
+ else
+ PyErr_WriteUnraisable(self);
}
+ // Return False, as required by the context manager protocol.
Py_RETURN_FALSE;
}
@@ -45,6 +54,7 @@ static PyObject *systemlock_enter(PyObject *self, PyObject *args)
return NULL;
if (!_system->Lock())
return HandleErrors();
+ Py_INCREF(self);
return self;
}