Need help with C extensions

Carl Bevil carl_bevil at yahoo.com
Sun Feb 9 16:23:45 EST 2003


Hello all.  I am attempting to wrap a C library so that I can use it in 
Python.  I've used SWIG on the header for this file, and am able to import and 
run functions from the library.

The problem is that the library makes use of pointers as arguments and as 
return values.  For example, a C function:

void GetValues(float* val1, float* val2)

This (hypothetical) function takes pointers to floating-point values and 
modifies the data they point to.

How do I represent this in Python?  I don't think it's possible to get the 
address of a variable using Python, as Python has no concept of this.  And 
once I get the value back, how do I examine its contents?

A related question has to do with return values.  For example, a function:

float* GetFloat()

In Python, I'd write:

myFloat = myModule.GetFloat()

SWIG sets the return value to be a string that has an address and a type 
embedded into it.  Again, how do I get the floating-point value out of this?  
And what if the return value is a pointer to an array of floating-point values?

Thanks!

Carl




More information about the Python-list mailing list