Let's say we have a following struct in C:
typedef struct buffer
{
uint8_t* const data;
const size_t maxSize;
size_t size;
} buffer_t;
How can I make a SWIG wrapper for this so that when buffer_t is created in Python it allocates given number of bytes to data pointer and sets maxSize accordingly?
Details
So basically the problem here is related to constant struct members. By default SWIG initializes structs with default values. This leads into problems:
StructWithConsts_t struct;
struct.constant = 5; // Error. This should've been set when creating the struct.
The accepted answer with constructors and destructors provide solution for this problem.