[Python-3000-checkins] r63793 - in python/branches/py3k: Lib/ctypes/test/test_pointers.py Modules/_ctypes/_ctypes.c
thomas.heller
python-3000-checkins at python.org
Thu May 29 21:54:56 CEST 2008
Author: thomas.heller
Date: Thu May 29 21:54:39 2008
New Revision: 63793
Log:
Merged revisions 63791-63792 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63791 | thomas.heller | 2008-05-29 21:18:12 +0200 (Do, 29 Mai 2008) | 1 line
Fix compiler warning.
........
r63792 | thomas.heller | 2008-05-29 21:42:34 +0200 (Do, 29 Mai 2008) | 1 line
ctypes NULL function pointers have a boolean False value now.
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Lib/ctypes/test/test_pointers.py
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 Thu May 29 21:54:39 2008
@@ -175,5 +175,13 @@
self.assertRaises(TypeError, c_void_p, 3.14) # make sure floats are NOT accepted
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__':
unittest.main()
Modified: python/branches/py3k/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/py3k/Modules/_ctypes/_ctypes.c (original)
+++ python/branches/py3k/Modules/_ctypes/_ctypes.c Thu May 29 21:54:39 2008
@@ -474,7 +474,7 @@
static PyObject *
CDataType_from_buffer_copy(PyObject *type, PyObject *args)
{
- void *buffer;
+ const void *buffer;
Py_ssize_t buffer_len;
Py_ssize_t offset = 0;
PyObject *obj, *result;
@@ -3849,6 +3849,25 @@
self);
}
+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 CFuncPtr_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.CFuncPtr",
@@ -3860,7 +3879,7 @@
0, /* tp_setattr */
0, /* tp_compare */
(reprfunc)CFuncPtr_repr, /* tp_repr */
- 0, /* tp_as_number */
+ &Pointer_as_number, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
@@ -4933,25 +4952,6 @@
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",
More information about the Python-3000-checkins
mailing list