Wendell Nichols, 27.02.2012 20:48:
I have a library that I want to wrap for Python (as part of an exercise to learn Python, and provide some public good at the same time :) The library is proprietary and I can't change it. Many of its functions modify a pointer provided via an address arg. Can python deal with functions that modify their arguments? If so (generally) how?
If there is no formalised way I'm may have to consider registering some sort of callback to alter the argument from within C... kind of awkward but since I'm code generating all the C so long as I have a workable approach it doesn't matter how much code it takes :)
Marc-Andre already pointed you to a couple of tools that do this for you. It's best to use an existing tool, because writing both a wrapping tool and then a wrapper with it means that you will end up having to maintain both the wrapping tool and the wrapper, whereas you'd normally only want to care about the wrapper in the long term.
Another (very) common tool to wrap C(++) libraries for Python is Cython. Specifically, it will allow you to not only write a thin 1:1 wrapper (as I guess you are doing here), but to actually write an efficient thicker wrapper that provides a more pythonic interface to the library you are wrapping. In most cases, this is largely preferable to a straight C-ish interface, especially when it comes to things like memory management for C data types or object oriented APIs.
Stefan