]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #12483: ctypes: Fix a crash when the destruction of a callback
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Mon, 12 Sep 2011 18:12:09 +0000 (20:12 +0200)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Mon, 12 Sep 2011 18:12:09 +0000 (20:12 +0200)
object triggers the garbage collector.

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

index 621a0192b3156fed1a6995f546b95fc3a932f1e0..901456df19cc2f0e528bb2ca38e2e8b944ede1ff 100644 (file)
@@ -140,6 +140,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 41328fd3e8313d80bcbba7641501e3e537d8a158..7984e174e9c672ad7e551992ef6f6f2464ed9864 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -192,6 +192,9 @@ Library
 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 2b54a85b8f3c9aaf8fcb505466ebf80c38c652f0..47dbe05a5159e0c8614f4dfdff092e92f8f5b00a 100644 (file)
@@ -18,6 +18,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);