passing PyIntType objects by reference

Larry Bates lbates at swamisoft.com
Thu Jun 10 12:51:05 EDT 2004


Why not do following:

result=mymod.myfunc(x)

That way you get a proper return value and I also think
it is clearer what you are doing.

You can pass a memory buffer (see dynawin's membuf)

from dynwin.windll import membuf
import struct

t=membuf(x)
mymod.myfunct(t.address())
x=struct.unpack('l',t.read())

I'm assuming x is a long (interger)

Normally I combine the two methods and return the value
passed back as a normal Python return value.

HTH,
Larry Bates
Syscon, Inc.


"Patrick Stinson" <ajole-1 at gci.net> wrote in message
news:10cgctu891gi127 at corp.supernews.com...
> when passing an python integer value to a C function
> ie.
> x = 1
> mymod.myfunc(x)
>
> is it possible to change the value of the python object "x" as happens in
c
> when you pass a pointer to an int? Is there something fundamentally wrong
> with this idea, as this does not happen in pure python anyway?
>
> Better yet, I'm wrapping a C api where some of the values are returned by
> passing values by reference. Is the only way to simulate this to return a
> list with the returned values?
>
> Cheers





More information about the Python-list mailing list