[Update: Problem solved! See bottom of the post]
I need to allow python developers to pass an array of packed data (in this case vertices) into my API,
Not tested but you should give this a try and let us know if its fast enough for your needs.
On the python side, pack the vertices into a string instead of an object.
str = "" # byte stream for encoding data
str += struct.pack("5f i", vert1.x, vert1.y, vert1.z, vert1.u, vert1.v, vert1.color) # 5 floats and an int
# same for other vertices
device. ReadVertices( verts, 3) # send vertices to C library
On the C library/python wrapper, modify your PyArgs_ParseTuple to use the format string "si"
. This will convert your python string into a C string (char*) which you can then typecast as a pointer to your vector struct. At this point the C string is a stream of bytes/words/floats and should be what you're looking for.
Good luck!
The easiest thing I can see to do would be to just avoid the issue altogether and expose a Device_ReadVertex that takes in x, y, z, u, v and color as arguments. This has obvious drawbacks, like making the Python programmers feed it vertices one by one.
If that's not good enough (seems likely it isn't), then you could try defining a new Python type as described here. It's a bit more code but I think this is the "more architecturally sound" method, because you ensure your Python developers are using the same type definition as you are in the C code. It also allows for a bit more flexibility than a simple struct (it's really a class, with the potential to add methods, etc), which I'm not sure you actually need but it might come in handy later.