[capi-sig] C functions that modify their arguments.

M.-A. Lemburg mal at egenix.com
Tue Feb 28 15:59:19 CET 2012


Wendell Nichols wrote:
> 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 :)

You mean: The C functions write data into buffers your Python wrapper
has to provide ?

That's possible, but you'll have to manage memory allocation in your
wrapper. Alternatively, you could copy the data into Python objects
to have Python take over memory management.

PS: You might want to consider using a wrapper generator such as SWIG,
Boost or sip to help you with the wrapping of the library. They typically
take care of all this.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Feb 28 2012)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2012-02-13: Released eGenix pyOpenSSL 0.13        http://egenix.com/go26
2012-02-09: Released mxODBC.Zope.DA 2.0.2         http://egenix.com/go25
2012-02-06: Released eGenix mx Base 3.2.3         http://egenix.com/go24

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


More information about the capi-sig mailing list