aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/pyme/core.py
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2016-05-27 10:25:59 +0000
committerJustus Winter <[email protected]>2016-05-27 10:25:59 +0000
commitebfe2300c33a3bad311e9ac1530e6c92636a08a4 (patch)
treefa0eadc62b574c5838664eb93c3dadc879ace5b1 /lang/python/pyme/core.py
parentImprove comments. (diff)
downloadgpgme-ebfe2300c33a3bad311e9ac1530e6c92636a08a4.tar.gz
gpgme-ebfe2300c33a3bad311e9ac1530e6c92636a08a4.zip
python: Fix object deallocation.
Handing a reference to the wrapper object created a non-trivial circular reference that Pythons garbage collector is unable to break. Explicitly break it by using a weak reference. * lang/python/helpers.c (pygpgme_stash_callback_exception): Retrieve object from weak reference. * lang/python/pyme/core.py (Context.__del__): Free status callback. (Context.set_passphrase_cb): Use a weak reference. (Context.set_progress_cb): Likewise. (Context.set_status_cb): Likewise. (Context.op_edit): Likewise. Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'lang/python/pyme/core.py')
-rw-r--r--lang/python/pyme/core.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py
index 0c2dd602..6ef2dabe 100644
--- a/lang/python/pyme/core.py
+++ b/lang/python/pyme/core.py
@@ -16,9 +16,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-# import generators for portability with python2.2
-
-
+import weakref
from . import pygpgme
from .errors import errorcheck, GPGMEError
from . import errors
@@ -149,6 +147,7 @@ class Context(GpgmeWrapper):
self._free_passcb()
self._free_progresscb()
+ self._free_statuscb()
if self.own and pygpgme.gpgme_release:
pygpgme.gpgme_release(self.wrapped)
@@ -252,9 +251,9 @@ class Context(GpgmeWrapper):
else:
self.last_passcb = pygpgme.new_PyObject_p_p()
if hook == None:
- hookdata = (self, func)
+ hookdata = (weakref.ref(self), func)
else:
- hookdata = (self, func, hook)
+ hookdata = (weakref.ref(self), func, hook)
pygpgme.pygpgme_set_passphrase_cb(self.wrapped, hookdata, self.last_passcb)
def set_progress_cb(self, func, hook=None):
@@ -275,9 +274,9 @@ class Context(GpgmeWrapper):
else:
self.last_progresscb = pygpgme.new_PyObject_p_p()
if hook == None:
- hookdata = (self, func)
+ hookdata = (weakref.ref(self), func)
else:
- hookdata = (self, func, hook)
+ hookdata = (weakref.ref(self), func, hook)
pygpgme.pygpgme_set_progress_cb(self.wrapped, hookdata, self.last_progresscb)
def set_status_cb(self, func, hook=None):
@@ -297,9 +296,9 @@ class Context(GpgmeWrapper):
else:
self.last_statuscb = pygpgme.new_PyObject_p_p()
if hook == None:
- hookdata = (self, func)
+ hookdata = (weakref.ref(self), func)
else:
- hookdata = (self, func, hook)
+ hookdata = (weakref.ref(self), func, hook)
pygpgme.pygpgme_set_status_cb(self.wrapped, hookdata,
self.last_statuscb)
@@ -333,9 +332,9 @@ class Context(GpgmeWrapper):
if key == None:
raise ValueError("op_edit: First argument cannot be None")
if fnc_value:
- opaquedata = (self, func, fnc_value)
+ opaquedata = (weakref.ref(self), func, fnc_value)
else:
- opaquedata = (self, func)
+ opaquedata = (weakref.ref(self), func)
result = pygpgme.gpgme_op_edit(self.wrapped, key, opaquedata, out)
if self._callback_excinfo: