2

I am trying to wrap a function written in C such that I can access it in Python using SWIG

The problem I have is that it expects a pointer to a pointer to a struct, not a pointer to a struct, e.g.

int update_tracks(track_t **hash_tracks);

if it were:

int update_tracks(track_t *hash_tracks);

I would have no problem as I can create the argument and call the function from python as follows:

hash_tracks = track_t()
n = update_tracks(hash_tracks)

track_t is a simple C struct containing some ints, floats, arrays etc.

but I can't figure out how to get the pointer to hash_tracks that I need as the argument to the first function (i.e. the one I am actually trying to wrap)

The reason I need a track_t** argument (not just a track_t* argument) is that hash_tracks is a hash-table (using the uthash library) and as such the pointer to the track table can change as the function adds and removes track_t structs within its implementation.

I am stumped how to call such a function from python. Maybe I need to implement some 'helper' functions in C or use some SWIG typemaps to make it possible?

1 Answer 1

1

I think you want to use the INOUT typemap, documented here:

http://www.swig.org/Doc2.0/Arguments.html#Arguments_nn6

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.