From: Vipul R. <vip...@gm...> - 2011-08-11 18:51:26
|
Hi Stefan, Thanks for your reply. But I am now getting the following error on compiling the swig-generated .cxx file with g++ : master_wrap.cxx: In function ‘PyObject* _wrap_ossimInit_initialize__SWIG_0(PyObject*, PyObject*)’: master_wrap.cxx:5916: error: ‘size’ was not declared in this scope master_wrap.cxx:5917: error: ‘$2’ was not declared in this scope master_wrap.cxx:5926: error: invalid conversion from ‘char*’ to ‘int’ master_wrap.cxx:5947: error: ‘$2’ was not declared in this scope master_wrap.cxx: In function ‘PyObject* _wrap_ossimIrect_getBounds(PyObject*, PyObject*)’: master_wrap.cxx:21323: error: ‘size’ was not declared in this scope master_wrap.cxx:21324: error: ‘$2’ was not declared in this scope master_wrap.cxx:21333: error: invalid conversion from ‘char*’ to ‘int’ master_wrap.cxx:21353: error: ‘size’ was not declared in this scope master_wrap.cxx:21354: error: ‘$2’ was not declared in this scope master_wrap.cxx:21363: error: invalid conversion from ‘char*’ to ‘int’ master_wrap.cxx:21383: error: ‘size’ was not declared in this scope master_wrap.cxx:21384: error: ‘$2’ was not declared in this scope master_wrap.cxx:21393: error: invalid conversion from ‘char*’ to ‘int’ master_wrap.cxx:21413: error: ‘size’ was not declared in this scope master_wrap.cxx:21414: error: ‘$2’ was not declared in this scope master_wrap.cxx:21423: error: invalid conversion from ‘char*’ to ‘int’ I can't seem to figure it out. I have been trying my hand at this for quite some time but couldn't get anywhere. Please help. Thanks and regards, Vipul On Tue, Aug 9, 2011 at 6:15 PM, Stefan Zager <sz...@gm...> wrote: > On Sat, Aug 6, 2011 at 3:05 AM, Vipul Raheja <vip...@gm...> > wrote: > > > > Hi all, > > > > This question was asked on stackoverflow yesterday only, I am facing > > the same problem. > > > > I am trying to access a C++ function from Python and I'm facing a > > problem when I try to pass a Python list as an argument to a function. > > > > Here is the C++ function definition I'm trying to access (used to send > > command to OSSIM reader) : > > > > ossimInit initialize(int& argc, // No of arguments > > char** argv) // List of arguments > > For your method, you need a typemap that converts both the argc and > argv arguments; following is modified from the SWIG docs: > > // This tells SWIG to treat char ** as a special case > %typemap(in) int&, char ** (int size) { > /* Check if is a list */ > if (PyList_Check($input)) { > size = PyList_Size($input); > $2 = &size; > int i = 0; > $1 = (char **) malloc((size+1)*sizeof(char *)); > for (i = 0; i < size; i++) { > PyObject *o = PyList_GetItem($input,i); > if (PyString_Check(o)) > $1[i] = PyString_AsString(PyList_GetItem($input,i)); > else { > PyErr_SetString(PyExc_TypeError,"list must contain strings"); > free($1); > return NULL; > } > } > $1[i] = 0; > } else { > PyErr_SetString(PyExc_TypeError,"not a list"); > return NULL; > } > } > > // This cleans up the char ** array we malloc'd before the function call > %typemap(freearg) char ** { > free((char *) $1); > } > > > Stefan > -- *Vipul Raheja* Senior Undergraduate Computer Science and Engineering (Dual) Lab for Spatial Informatics IIIT Hyderabad |