]> granicus.if.org Git - python/commitdiff
Issue #12483: ctypes: Fix a crash when the destruction of a callback
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Mon, 12 Sep 2011 19:03:36 +0000 (21:03 +0200)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Mon, 12 Sep 2011 19:03:36 +0000 (21:03 +0200)
object triggers the garbage collector.

Lib/ctypes/test/test_callbacks.py
Misc/NEWS
Modules/_ctypes/callbacks.c

index 8801ccd1069f7dd8ee5bf06c18708e89377c5fb5..c7207eab9d25313e6e9ed86271b3e78c41ca70e6 100644 (file)
@@ -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:
index d9e8f4b3b08bf22a071209e32ef953941f2eecca..d52156d417ced2e3367db35ec675e7aaaa7f213d 100644 (file)
--- 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.
 
index d23509fbe2c5c2b4cdf23a555351f6a3053c5fde..34c46ad7a7eeaacbb95435121c2c14adaa91eb07 100644 (file)
@@ -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);