Version 3 (modified by 12 years ago) ( diff ) | ,
---|
Void Pointers Don't Adapt Well To Python
Having written a C function that returned a void pointer, I attempted to import it into Python using SWIG. Unfortunately, when asked to return the value of a SWIGged C pointer Python returns a string containing the object's memory address. SWIG and Python both describe options for dealing with this, but the SWIG documentation appears to be out of date and the Python options are either too complicated or require a more advanced version than the 2.3 build we use on nova
and orda
.
The solution in my case was just to write adapter functions in the C module that converted the void pointer output into standard non-pointer datatypes. I was using void pointers to avoid writing multiple functions that returned different datatypes, but the Chombo HDF format uses a small number of relatively simple datatypes, so I was able to circumvent the entire problem with three short conversion wrappers.