
Jack Jansen wrote:
On Thursday, January 17, 2002, at 11:29 AM, M.-A. Lemburg wrote:
I am more in favour of exposing the pickle reduce API through "O@", that is have PyArgTuple_Parse() call the .__reduce__() method of the object. This will then return (factory, state_tuple) and these could then be exposed to the C function via two PyObject*.
You've suggested this before, but at that time I ignored it because it made absolutely no sense to me. "pickle" triggers one set of ideas for me, "reduce" triggers a different set, "factory function" yet another different set. None of these sets of ideas have the least resemblance to what I'm trying to do:-)
The idea is simple but extends what you are trying to achieve (I gave an example on how to use this somewhere in the "wrapper" thread). Basically, you'll just want to use the state tuple to access the underlying void* C pointer via a PyCObject which does the wrapping of the pointer. The "pickle" mechanism would store the PyCObject in the state tuple which you could then access to get at the C pointer. This may sound complicated at first, but it provides much more flexibility w/r to more complex objects, e.g. the method you have in mind only supports wrapping a single C pointer; the "pickle" mechanism can potentially handle any serializable object.
I gave a fairly complete example (using calldll from Python to wrap a function that returns a Mac WindowObject) last week, could you explain how you would implement this with pickle, reduce and factory functions?
Sorry, no time for that ... I've got an important business trip next week which needs to be prepared. Please bring this up again after next week. -- Marc-Andre Lemburg CEO eGenix.com Software GmbH ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/