From: Tomas W. <Tom...@hi...> - 2011-04-21 07:11:45
|
I have a C function that returns an array of char* and stores size of the allocated array in an argument: unsigned char **get_strings(Obj1* arg1, Obj2* arg2, int *size);https://webmail.hiq.se/owa/?ae=Item&a=Open&t=IPM.Note&s=Draft&id=RgAAAACAIdBd0UkXR5phtVVdmgHsBwBDNrXD3DOnT6OT9PiBUvTsAAABYxxeAABX4JHGHcgdQYmdYrhE4%2bLXABkY%2frcgAAAJ# I want to return this as a list of Python strings, so have written the following typemaps: %typemap(in, numinputs=0) int *size (int size) { $1 = &size; } %typemap(out) unsigned char **get_strings { int i; $result = PyList_New(size$argnum); for (i = 0; i < size$argnum; i++) { PyList_SetItem($result, i, PyString_FromString($1[i])); free($1[i]); } free($1); } But this doesn't work; $argnum is not replaced. I have to look in the genrated code and find that Swig has appended '3' to size and hard code this in the out typemap. Is this a bug or have I missed something? And why is Swig appending this number to the variable I have declared at all? It is not necessary. I think it should be up to me to select a C identifier that works for the given scope. Using Swig 2.0.1 /Tomas Walch |