[Python-checkins] cpython (2.7): Issue #12483: ctypes: Fix a crash when the destruction of a callback

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


http://hg.python.org/cpython/rev/eb9f566fd8db
changeset: 72365:eb9f566fd8db
branch: 2.7
parent: 72363:18676f0118e4
user: Amaury Forgeot d'Arc <amauryfa at gmail.com>
date: Mon Sep 12 20:12:09 2011 +0200
summary:
 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
@@ -140,6 +140,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
@@ -192,6 +192,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
@@ -18,6 +18,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

AltStyle によって変換されたページ (->オリジナル) /