Neal Norwitz schrieb: > I'm glad to see Anthony ratcheting down. At this point, we need to be > fixing bugs and improving doc. Maybe Anthony and I should have a > contest to see who can revert the most changes. :-) > Neal (and/or Anthony),
I would like to ask about the possibility to add some improvements to ctypes in Python 2.5, although the feature freeze is now in effect. Hopefully former third-party libraries can have the freeze relaxed somewhat;-). I intend to do these changes, the first is a small and trivial one, but allows a lot of flexibility: - Remove the restriction that the argtypes attribute of foreign functions must be ctypes types. Instead they are only required to implement a .from_param class method. The advantage is that custom objects can be used as function parameters. One usecase is to allow numpy arrays as function parameters without any conversion - this change at least allows to code this in Python. The patch is attached as from_param.patch. The second one is more involved, and not yet complete. I can post the patch or a link to it for review when it is implemented completely: - Implement the __array_struct__ attribute as describes by the numpy pep at http://numpy.scipy.org/array_interface.html. The properties needed to implement the __array_struct__ attribute could be calculated from a given ctypes array type, however, it would be more efficient to calculate them at type creation time. This requires the StgDSictObject that holds information about the ctypes type to grow a few fields: 'int nd' - contains the number of dimensions, 'char typekind' - a struct-like character for the item type, and 'Py_intptr_t *shape' - an array of size 'nd' containing shape information. Thanks for investigating this, Thomas
Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.340 diff -u -r1.340 _ctypes.c --- _ctypes.c 22 Jun 2006 19:21:28 -0000 1.340 +++ _ctypes.c 4 Jul 2006 09:56:06 -0000 @@ -1633,9 +1633,8 @@ for (i = 0; i < nArgs; ++i) { PyObject *tp = PyTuple_GET_ITEM(ob, i); - StgDictObject *dict = PyType_stgdict(tp); PyObject *cnv = PyObject_GetAttrString(tp, "from_param"); - if (!dict || !cnv) + if (!cnv) goto argtypes_error_1; PyTuple_SET_ITEM(converters, i, cnv); }
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com