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

Wendell Nichols wcn00 at shaw.ca
Tue Feb 28 15:18:47 CET 2012


Thanks, that looks like it will work just fine!  The simples answers are 
the best :)
wcn

On 12-02-28 03:30 AM, Hrvoje Niksic wrote:
> Wendell Nichols<wcn00 at shaw.ca>  writes:
>
>> 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?
> I assume you're referring to the use of pointers to simulate
> pass-by-reference:
>
> void update_sample(Type1 **arg1, Type2 **arg2)
> {
>    *arg1 = new_type1();
>    *arg2 = new_type2();
>    ...
> }
>
> The standard way of implementing such out parameters in Python is to
> have the function return a tuple of values.  The function is then called
> like this:
>
> val1, val2 = sample.update(val1, val2)
>


More information about the capi-sig mailing list