I'm trying to work with a Python module that was generated by SWIG. There's a C++ class defined that works like this (simplified):
namespace Foo
{
class Thing开发者_JAVA百科
{
public:
Thing();
~Thing();
bool DoSomething(uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer);
};
};
When I try to call it from Python, I get an error about the last argument needing to be of type 'uint32_t*'. Normal Python integers work just fine for the other arguments, so I can't understand why a list of ints wouldn't work for the buffer. Any suggestions?
The last parameter to DoSomething
is a pointer to uint32_t
, not uint32_t
. So unlike the other parameters, the function expects to receive a pointer to an integer or an array of integers (since arrays can be used wherever pointers are expected).
I suspect in this case (because it's called 'buffer') that the function expects an array. You should take a look at the SWIG documentation on Unbounded C arrays.
精彩评论