[Python-checkins] r65868 - in python/trunk: Lib/ctypes/test/test_pointers.py Misc/NEWS Modules/_ctypes/_ctypes.c

thomas.heller python-checkins at python.org
Tue Aug 19 21:25:04 CEST 2008


Author: thomas.heller
Date: Tue Aug 19 21:25:04 2008
New Revision: 65868

Log:
Fix a regression introduced by rev. 63792: ctypes function pointers
that are COM methods must have a boolean True value.


Modified:
   python/trunk/Lib/ctypes/test/test_pointers.py
   python/trunk/Misc/NEWS
   python/trunk/Modules/_ctypes/_ctypes.c

Modified: python/trunk/Lib/ctypes/test/test_pointers.py
==============================================================================
--- python/trunk/Lib/ctypes/test/test_pointers.py	(original)
+++ python/trunk/Lib/ctypes/test/test_pointers.py	Tue Aug 19 21:25:04 2008
@@ -1,4 +1,4 @@
-import unittest
+import unittest, sys
 
 from ctypes import *
 import _ctypes_test
@@ -183,5 +183,10 @@
         self.failUnlessEqual(bool(CFUNCTYPE(None)(0)), False)
         self.failUnlessEqual(bool(CFUNCTYPE(None)(42)), True)
 
+        # COM methods are boolean True:
+        if sys.platform == "win32":
+            mth = WINFUNCTYPE(None)(42, "name", (), None)
+            self.failUnlessEqual(bool(mth), True)
+
 if __name__ == '__main__':
     unittest.main()

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Tue Aug 19 21:25:04 2008
@@ -12,6 +12,9 @@
 Core and Builtins
 -----------------
 
+- ctypes function pointers that are COM methods have a boolean True
+  value again.
+
 - Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
   by denying s# to parse objects that have a releasebuffer procedure,
   and introducing s*.

Modified: python/trunk/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/trunk/Modules/_ctypes/_ctypes.c	(original)
+++ python/trunk/Modules/_ctypes/_ctypes.c	Tue Aug 19 21:25:04 2008
@@ -3938,12 +3938,13 @@
 }
 
 static int
-Pointer_nonzero(CDataObject *self)
+CFuncPtr_nonzero(CFuncPtrObject *self)
 {
-	return *(void **)self->b_ptr != NULL;
+	return ((*(void **)self->b_ptr != NULL)
+		|| (self->index != 0));
 }
 
-static PyNumberMethods Pointer_as_number = {
+static PyNumberMethods CFuncPtr_as_number = {
 	0, /* nb_add */
 	0, /* nb_subtract */
 	0, /* nb_multiply */
@@ -3954,7 +3955,7 @@
 	0, /* nb_negative */
 	0, /* nb_positive */
 	0, /* nb_absolute */
-	(inquiry)Pointer_nonzero, /* nb_nonzero */
+	(inquiry)CFuncPtr_nonzero, /* nb_nonzero */
 };
 
 PyTypeObject CFuncPtr_Type = {
@@ -3968,7 +3969,7 @@
 	0,					/* tp_setattr */
 	0,					/* tp_compare */
 	(reprfunc)CFuncPtr_repr,		/* tp_repr */
-	&Pointer_as_number,			/* tp_as_number */
+	&CFuncPtr_as_number,			/* tp_as_number */
 	0,					/* tp_as_sequence */
 	0,					/* tp_as_mapping */
 	0,					/* tp_hash */
@@ -5176,6 +5177,26 @@
 	Pointer_subscript,
 };
 
+static int
+Pointer_nonzero(CDataObject *self)
+{
+	return (*(void **)self->b_ptr != NULL);
+}
+
+static PyNumberMethods Pointer_as_number = {
+	0, /* nb_add */
+	0, /* nb_subtract */
+	0, /* nb_multiply */
+	0, /* nb_divide */
+	0, /* nb_remainder */
+	0, /* nb_divmod */
+	0, /* nb_power */
+	0, /* nb_negative */
+	0, /* nb_positive */
+	0, /* nb_absolute */
+	(inquiry)Pointer_nonzero, /* nb_nonzero */
+};
+
 PyTypeObject Pointer_Type = {
 	PyVarObject_HEAD_INIT(NULL, 0)
 	"_ctypes._Pointer",


More information about the Python-checkins mailing list