Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5049fc

Browse files
author
Thomas Heller
committed
Merged revisions 65868,65870 via svnmerge from
svn+ssh://[email protected]/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 ........
1 parent 58ea9fe commit f5049fc

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

Lib/ctypes/test/test_pointers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import unittest
1+
import unittest, sys
22

33
from ctypes import *
44
import _ctypes_test
@@ -183,5 +183,10 @@ def test_pointers_bool(self):
183183
self.failUnlessEqual(bool(CFUNCTYPE(None)(0)), False)
184184
self.failUnlessEqual(bool(CFUNCTYPE(None)(42)), True)
185185

186+
# COM methods are boolean True:
187+
if sys.platform == "win32":
188+
mth = WINFUNCTYPE(None)(42, "name", (), None)
189+
self.failUnlessEqual(bool(mth), True)
190+
186191
if __name__ == '__main__':
187192
unittest.main()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Core and Builtins
1818
without relying on a particular implementation; remove the ill-named
1919
PyMemoryView() function (PyMemoryView_GET_BUFFER() can be used instead).
2020

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

Modules/_ctypes/_ctypes.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3858,12 +3858,16 @@ CFuncPtr_repr(CFuncPtrObject *self)
38583858
}
38593859

38603860
static int
3861-
Pointer_bool(CDataObject *self)
3861+
CFuncPtr_bool(CFuncPtrObject *self)
38623862
{
3863-
return *(void **)self->b_ptr != NULL;
3863+
return ((*(void **)self->b_ptr != NULL)
3864+
#ifdef MS_WIN32
3865+
|| (self->index != 0)
3866+
#endif
3867+
);
38643868
}
38653869

3866-
static PyNumberMethods Pointer_as_number = {
3870+
static PyNumberMethods CFuncPtr_as_number = {
38673871
0, /* nb_add */
38683872
0, /* nb_subtract */
38693873
0, /* nb_multiply */
@@ -3873,7 +3877,7 @@ static PyNumberMethods Pointer_as_number = {
38733877
0, /* nb_negative */
38743878
0, /* nb_positive */
38753879
0, /* nb_absolute */
3876-
(inquiry)Pointer_bool, /* nb_bool */
3880+
(inquiry)CFuncPtr_bool, /* nb_bool */
38773881
};
38783882

38793883
PyTypeObject CFuncPtr_Type = {
@@ -3887,7 +3891,7 @@ PyTypeObject CFuncPtr_Type = {
38873891
0, /* tp_setattr */
38883892
0, /* tp_compare */
38893893
(reprfunc)CFuncPtr_repr, /* tp_repr */
3890-
&Pointer_as_number, /* tp_as_number */
3894+
&CFuncPtr_as_number, /* tp_as_number */
38913895
0, /* tp_as_sequence */
38923896
0, /* tp_as_mapping */
38933897
0, /* tp_hash */
@@ -4960,6 +4964,25 @@ static PyMappingMethods Pointer_as_mapping = {
49604964
Pointer_subscript,
49614965
};
49624966

4967+
static int
4968+
Pointer_bool(CDataObject *self)
4969+
{
4970+
return (*(void **)self->b_ptr != NULL);
4971+
}
4972+
4973+
static PyNumberMethods Pointer_as_number = {
4974+
0, /* nb_add */
4975+
0, /* nb_subtract */
4976+
0, /* nb_multiply */
4977+
0, /* nb_remainder */
4978+
0, /* nb_divmod */
4979+
0, /* nb_power */
4980+
0, /* nb_negative */
4981+
0, /* nb_positive */
4982+
0, /* nb_absolute */
4983+
(inquiry)Pointer_bool, /* nb_bool */
4984+
};
4985+
49634986
PyTypeObject Pointer_Type = {
49644987
PyVarObject_HEAD_INIT(NULL, 0)
49654988
"_ctypes._Pointer",

0 commit comments

Comments
 (0)