Discussion:
[Python-3000-checkins] r65871 - in python/branches/py3k: Lib/ctypes/test/test_pointers.py Misc/NEWS Modules/_ctypes/_ctypes.c
thomas.heller
2008-08-19 19:49:50 UTC
Permalink
Author: thomas.heller
Date: Tue Aug 19 21:49:49 2008
New Revision: 65871

Log:
Merged revisions 65868,65870 via svnmerge from
svn+ssh://pythondev at svn.python.org/python/trunk

........
r65868 | thomas.heller | 2008-08-19 21:25:04 +0200 (Di, 19 Aug 2008) | 3 lines

Fix a regression introduced by rev. 63792: ctypes function pointers
that are COM methods must have a boolean True value.
........
r65870 | thomas.heller | 2008-08-19 21:40:23 +0200 (Di, 19 Aug 2008) | 1 line

COM method code is windows specific
........


Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Lib/ctypes/test/test_pointers.py
python/branches/py3k/Misc/NEWS
python/branches/py3k/Modules/_ctypes/_ctypes.c

Modified: python/branches/py3k/Lib/ctypes/test/test_pointers.py
==============================================================================
--- python/branches/py3k/Lib/ctypes/test/test_pointers.py (original)
+++ python/branches/py3k/Lib/ctypes/test/test_pointers.py Tue Aug 19 21:49:49 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/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Tue Aug 19 21:49:49 2008
@@ -18,6 +18,9 @@
without relying on a particular implementation; remove the ill-named
PyMemoryView() function (PyMemoryView_GET_BUFFER() can be used instead).

+- ctypes function pointers that are COM methods have a boolean True
+ value again.
+
- Issue #1819: function calls with several named parameters are now on
average 35% faster (as measured by pybench).


Modified: python/branches/py3k/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/py3k/Modules/_ctypes/_ctypes.c (original)
+++ python/branches/py3k/Modules/_ctypes/_ctypes.c Tue Aug 19 21:49:49 2008
@@ -3858,12 +3858,16 @@
}

static int
-Pointer_bool(CDataObject *self)
+CFuncPtr_bool(CFuncPtrObject *self)
{
- return *(void **)self->b_ptr != NULL;
+ return ((*(void **)self->b_ptr != NULL)
+#ifdef MS_WIN32
+ || (self->index != 0)
+#endif
+ );
}

-static PyNumberMethods Pointer_as_number = {
+static PyNumberMethods CFuncPtr_as_number = {
0, /* nb_add */
0, /* nb_subtract */
0, /* nb_multiply */
@@ -3873,7 +3877,7 @@
0, /* nb_negative */
0, /* nb_positive */
0, /* nb_absolute */
- (inquiry)Pointer_bool, /* nb_bool */
+ (inquiry)CFuncPtr_bool, /* nb_bool */
};

PyTypeObject CFuncPtr_Type = {
@@ -3887,7 +3891,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 */
@@ -4960,6 +4964,25 @@
Pointer_subscript,
};

+static int
+Pointer_bool(CDataObject *self)
+{
+ return (*(void **)self->b_ptr != NULL);
+}
+
+static PyNumberMethods Pointer_as_number = {
+ 0, /* nb_add */
+ 0, /* nb_subtract */
+ 0, /* nb_multiply */
+ 0, /* nb_remainder */
+ 0, /* nb_divmod */
+ 0, /* nb_power */
+ 0, /* nb_negative */
+ 0, /* nb_positive */
+ 0, /* nb_absolute */
+ (inquiry)Pointer_bool, /* nb_bool */
+};
+
PyTypeObject Pointer_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes._Pointer",

Loading...