[Python-checkins] r78381 - in python/branches/release26-maint: Lib/ctypes/test/test_callbacks.py Misc/NEWS Modules/_ctypes/callbacks.c

thomas.heller python-checkins at python.org
Tue Feb 23 21:17:14 CET 2010


Author: thomas.heller
Date: Tue Feb 23 21:17:14 2010
New Revision: 78381
Log:
Merged revisions 78380 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk
........
 r78380 | thomas.heller | 2010年02月23日 21:11:44 +0100 (Di, 23 Feb 2010) | 4 lines
 
 ctypes CThunkObject was not registered correctly with the cycle
 garbage collector, leading to possible leaks when using callback
 functions.
........
Modified:
 python/branches/release26-maint/ (props changed)
 python/branches/release26-maint/Lib/ctypes/test/test_callbacks.py
 python/branches/release26-maint/Misc/NEWS
 python/branches/release26-maint/Modules/_ctypes/callbacks.c
Modified: python/branches/release26-maint/Lib/ctypes/test/test_callbacks.py
==============================================================================
--- python/branches/release26-maint/Lib/ctypes/test/test_callbacks.py	(original)
+++ python/branches/release26-maint/Lib/ctypes/test/test_callbacks.py	Tue Feb 23 21:17:14 2010
@@ -118,6 +118,22 @@
 prototype = self.functype.im_func(object)
 self.assertRaises(TypeError, prototype, lambda: None)
 
+ def test_issue_7959(self):
+ proto = self.functype.im_func(None)
+
+ class X(object):
+ def func(self): pass
+ def __init__(self):
+ self.v = proto(self.func)
+
+ import gc
+ for i in range(32):
+ X()
+ gc.collect()
+ live = [x for x in gc.get_objects()
+ if isinstance(x, X)]
+ self.failUnlessEqual(len(live), 0)
+
 try:
 WINFUNCTYPE
 except NameError:
Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Tue Feb 23 21:17:14 2010
@@ -66,6 +66,9 @@
 Library
 -------
 
+- Issue #7959: ctypes callback functions are now registered correctly
+ with the cylce garbage collector.
+
 - Issue #6243: curses.getkey() can segfault when used with ungetch.
 Fix by Trundle and Jerry Chen.
 
Modified: python/branches/release26-maint/Modules/_ctypes/callbacks.c
==============================================================================
--- python/branches/release26-maint/Modules/_ctypes/callbacks.c	(original)
+++ python/branches/release26-maint/Modules/_ctypes/callbacks.c	Tue Feb 23 21:17:14 2010
@@ -23,7 +23,7 @@
 	Py_XDECREF(self->restype);
 	if (self->pcl)
 		FreeClosure(self->pcl);
-	PyObject_Del(self);
+	PyObject_GC_Del(self);
 }
 
 static int
@@ -66,7 +66,7 @@
 	0,					/* tp_getattro */
 	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT,			/* tp_flags */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,			/* tp_flags */
 	"CThunkObject",				/* tp_doc */
 	CThunkObject_traverse,			/* tp_traverse */
 	CThunkObject_clear,	 		/* tp_clear */
@@ -367,7 +367,7 @@
 	CThunkObject *p;
 	int i;
 
-	p = PyObject_NewVar(CThunkObject, &CThunk_Type, nArgs);
+	p = PyObject_GC_NewVar(CThunkObject, &CThunk_Type, nArgs);
 	if (p == NULL) {
 		PyErr_NoMemory();
 		return NULL;
@@ -382,6 +382,7 @@
 	
 	for (i = 0; i < nArgs + 1; ++i)
 		p->atypes[i] = NULL;
+	PyObject_GC_Track((PyObject *)p);
 	return p;
 }
 


More information about the Python-checkins mailing list

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