0

I am wrapping a C module with SWIG for Python. Is there any way to turn all Python lists/tuples whose members are all of the same type (same kind of Swig object) to C arrays?

1 Answer 1

2

Typemaps. What you are most likely looking for is an "in" typemap, which maps Python types to C types. The declaration looks something like this:

%typemap(in) { /* C code to convert Python tuple object to C array */ }

Inside the typemap code you can use the variable $input to reference the PyObject* to convert, and assign your converted C array to $1.

http://docs.python.org/c-api/ has information on the Python/C API, which you'll need to unpack the tuple to get the items and convert them to C.

http://www.swig.org/Doc1.3/Typemaps.html has the SWIG documentation for typemaps.

The documentation can be hard to understand at first, so take a look at some example typemaps in /share. carrays.i in that directory might also serve as a good starting point.

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.