Author: thomas.heller Date: Sat Jan 19 23:25:14 2008 New Revision: 60112 Modified: python/branches/py3k-ctypes-pep3118/Lib/ctypes/test/test_pep3118.py python/branches/py3k-ctypes-pep3118/Modules/_ctypes/_ctypes.c Log: Fully implement tp_asbuffer for pointer types.
Modified: python/branches/py3k-ctypes-pep3118/Lib/ctypes/test/test_pep3118.py ============================================================================== --- python/branches/py3k-ctypes-pep3118/Lib/ctypes/test/test_pep3118.py (original) +++ python/branches/py3k-ctypes-pep3118/Lib/ctypes/test/test_pep3118.py Sat Jan 19 23:25:14 2008 @@ -47,5 +47,23 @@ self.failUnlessEqual((v.size, v.itemsize), (struct_size, struct_size)) + def test_pointertypes(self): + for fmt, typ in simple_types: + v = memoryview(POINTER(typ)()) + + # check the PEP3118 format string + self.failUnlessEqual(v.format, "&" + ENDIAN + fmt) + + # shape and strides are None for integral types + self.failUnlessEqual((v.shape, v.strides), + (None, None)) + + # size and itemsize must be what struct.calcsize reports + # for pointers + struct_size = struct.calcsize("P") + self.failUnlessEqual((v.size, v.itemsize), + (struct_size, struct_size)) + + if __name__ == "__main__": unittest.main() Modified: python/branches/py3k-ctypes-pep3118/Modules/_ctypes/_ctypes.c ============================================================================== --- python/branches/py3k-ctypes-pep3118/Modules/_ctypes/_ctypes.c (original) +++ python/branches/py3k-ctypes-pep3118/Modules/_ctypes/_ctypes.c Sat Jan 19 23:25:14 2008 @@ -635,6 +635,16 @@ return NULL; } + if (proto) { + StgDictObject *itemdict = PyType_stgdict(proto); + assert(itemdict); + stgdict->format = alloc_format_string("&", itemdict->format); + if (stgdict->format == NULL) { + Py_DECREF((PyObject *)stgdict); + return NULL; + } + } + /* create the new instance (which is a class, since we are a metatype!) */ result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); @@ -4659,7 +4669,7 @@ 0, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ - &CData_as_buffer, /* tp_as_buffer */ + &Simple_as_buffer, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ "XXX to be provided", /* tp_doc */ (traverseproc)CData_traverse, /* tp_traverse */ _______________________________________________ Python-3000-checkins mailing list Python-3000-checkins@python.org http://mail.python.org/mailman/listinfo/python-3000-checkins