Jack Jansen wrote:
Recently, "M.-A. Lemburg" email@example.com said:
Sounds like you want to introduce a "buffer" interface for these objects.
No, that is something completely different. I want a replacement for PyArg_Parse("O&", funcptr, void**) that has the form PyArg_Parse("O@", typeobject, void**) and similarly for Py_BuildValue.
Because the typeobject has a Python representation (whereas the function pointer does not) this would allow modules like struct and calldll to support objects that have this interface, because these modules are driven from specifications in Python. There is currently no way to get from the typeobject to the function pointer needed for O&.
If I'm not mistaken this looks like an interface which resembles the copyreg registry where you ask an object for a way to pickle itself and a way to restore itself from the pickle. (I think one of the ways pickle supports this more directly is by looking for a reduce method.)
That would be nice to have indeed. For the simple objects you have in mind, the void* could be wrapped into a PyCObject, BTW.
Could you write this up as a short PEP ?