Anonymous avatar Anonymous committed bd37a18

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

Comments (0)

Files changed (3)

Lib/ctypes/test/test_pointers.py

-import unittest
+import unittest, sys
 
 from ctypes import *
 import _ctypes_test
         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()
 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*.

Modules/_ctypes/_ctypes.c

 }
 
 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 */
 	0, /* nb_negative */
 	0, /* nb_positive */
 	0, /* nb_absolute */
-	(inquiry)Pointer_nonzero, /* nb_nonzero */
+	(inquiry)CFuncPtr_nonzero, /* nb_nonzero */
 };
 
 PyTypeObject CFuncPtr_Type = {
 	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 */
 	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",
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.