mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
ctypes NULL function pointers have a boolean False value now.
This commit is contained in:
parent
a52b244cc1
commit
9287acf83d
3 changed files with 32 additions and 21 deletions
|
@ -175,5 +175,13 @@ class PointersTestCase(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, c_void_p, 3.14) # make sure floats are NOT accepted
|
self.assertRaises(TypeError, c_void_p, 3.14) # make sure floats are NOT accepted
|
||||||
self.assertRaises(TypeError, c_void_p, object()) # nor other objects
|
self.assertRaises(TypeError, c_void_p, object()) # nor other objects
|
||||||
|
|
||||||
|
def test_pointers_bool(self):
|
||||||
|
# NULL pointers have a boolean False value, non-NULL pointers True.
|
||||||
|
self.failUnlessEqual(bool(POINTER(c_int)()), False)
|
||||||
|
self.failUnlessEqual(bool(pointer(c_int())), True)
|
||||||
|
|
||||||
|
self.failUnlessEqual(bool(CFUNCTYPE(None)(0)), False)
|
||||||
|
self.failUnlessEqual(bool(CFUNCTYPE(None)(42)), True)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -63,6 +63,9 @@ Extension Modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #1797 (partial fix): ctypes NULL function pointers have a
|
||||||
|
False boolean value now.
|
||||||
|
|
||||||
- Issue #2985: Allow 64-bit integer responses (``<i8>``) in XMLRPC
|
- Issue #2985: Allow 64-bit integer responses (``<i8>``) in XMLRPC
|
||||||
transfers.
|
transfers.
|
||||||
|
|
||||||
|
|
|
@ -3784,6 +3784,26 @@ CFuncPtr_repr(CFuncPtrObject *self)
|
||||||
self);
|
self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 CFuncPtr_Type = {
|
PyTypeObject CFuncPtr_Type = {
|
||||||
PyVarObject_HEAD_INIT(NULL, 0)
|
PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
"_ctypes.CFuncPtr",
|
"_ctypes.CFuncPtr",
|
||||||
|
@ -3795,7 +3815,7 @@ PyTypeObject CFuncPtr_Type = {
|
||||||
0, /* tp_setattr */
|
0, /* tp_setattr */
|
||||||
0, /* tp_compare */
|
0, /* tp_compare */
|
||||||
(reprfunc)CFuncPtr_repr, /* tp_repr */
|
(reprfunc)CFuncPtr_repr, /* tp_repr */
|
||||||
0, /* tp_as_number */
|
&Pointer_as_number, /* tp_as_number */
|
||||||
0, /* tp_as_sequence */
|
0, /* tp_as_sequence */
|
||||||
0, /* tp_as_mapping */
|
0, /* tp_as_mapping */
|
||||||
0, /* tp_hash */
|
0, /* tp_hash */
|
||||||
|
@ -5003,26 +5023,6 @@ static PyMappingMethods Pointer_as_mapping = {
|
||||||
Pointer_subscript,
|
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 = {
|
PyTypeObject Pointer_Type = {
|
||||||
PyVarObject_HEAD_INIT(NULL, 0)
|
PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
"_ctypes._Pointer",
|
"_ctypes._Pointer",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue