[Python-checkins] cpython (merge 3.2 -> default): Merge 3.2: Issue #12483: ctypes: Fix a crash when the destruction of a callback

amaury.forgeotdarc python-checkins at python.org
Mon Sep 12 21:20:20 CEST 2011


http://hg.python.org/cpython/rev/fe125a3fda54
changeset:   72367:fe125a3fda54
parent:      72364:a03da3dc478e
parent:      72366:eae8e4ab0455
user:        Amaury Forgeot d'Arc <amauryfa at gmail.com>
date:        Mon Sep 12 21:09:12 2011 +0200
summary:
  Merge 3.2: Issue #12483: ctypes: Fix a crash when the destruction of a callback
  object triggers the garbage collector.

files:
  Lib/ctypes/test/test_callbacks.py |  8 ++++++++
  Misc/NEWS                         |  3 +++
  Modules/_ctypes/callbacks.c       |  1 +
  3 files changed, 12 insertions(+), 0 deletions(-)


diff --git a/Lib/ctypes/test/test_callbacks.py b/Lib/ctypes/test/test_callbacks.py
--- a/Lib/ctypes/test/test_callbacks.py
+++ b/Lib/ctypes/test/test_callbacks.py
@@ -134,6 +134,14 @@
                 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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1274,6 +1274,9 @@
 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
--- a/Modules/_ctypes/callbacks.c
+++ b/Modules/_ctypes/callbacks.c
@@ -13,6 +13,7 @@
 CThunkObject_dealloc(PyObject *_self)
 {
     CThunkObject *self = (CThunkObject *)_self;
+    PyObject_GC_UnTrack(self);
     Py_XDECREF(self->converters);
     Py_XDECREF(self->callable);
     Py_XDECREF(self->restype);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list