From: Amaury Forgeot d'Arc Date: Mon, 12 Sep 2011 19:03:36 +0000 (+0200) Subject: Issue #12483: ctypes: Fix a crash when the destruction of a callback X-Git-Tag: v3.2.3rc1~571 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bbe46d63ee9b624c011b4fe50978e2e7fa7cf82e;p=thirdparty%2FPython%2Fcpython.git Issue #12483: ctypes: Fix a crash when the destruction of a callback object triggers the garbage collector. --- diff --git a/Lib/ctypes/test/test_callbacks.py b/Lib/ctypes/test/test_callbacks.py index 8801ccd1069f..c7207eab9d25 100644 --- a/Lib/ctypes/test/test_callbacks.py +++ b/Lib/ctypes/test/test_callbacks.py @@ -134,6 +134,14 @@ class Callbacks(unittest.TestCase): if isinstance(x, X)] self.assertEqual(len(live), 0) + def test_issue12483(self): + import gc + class Nasty: + def __del__(self): + gc.collect() + CFUNCTYPE(None)(lambda x=Nasty(): None) + + try: WINFUNCTYPE except NameError: diff --git a/Misc/NEWS b/Misc/NEWS index d9e8f4b3b08b..d52156d417ce 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -65,6 +65,9 @@ Tests Extension Modules ----------------- +- Issue #12483: ctypes: Fix a crash when the destruction of a callback + object triggers the garbage collector. + - Issue #12950: Fix passing file descriptors in multiprocessing, under OpenIndiana/Illumos. diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index d23509fbe2c5..34c46ad7a7ee 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -13,6 +13,7 @@ static void CThunkObject_dealloc(PyObject *_self) { CThunkObject *self = (CThunkObject *)_self; + PyObject_GC_UnTrack(self); Py_XDECREF(self->converters); Py_XDECREF(self->callable); Py_XDECREF(self->restype);