Get char** global variable

Ervin Hegedüs <[email protected]>
Newsgroups gmane.comp.programming.swig
Message-ID <[email protected]>
Hi there,

I have a global variable with list of C strings:

char ** custom_variables;

I'ld like to access to this var, so I followed the documentation:

http://www.swig.org/Doc4.0/Python.html#Python_nn59

and added the typemap(in) above, and the out:

%typemap(out) char ** {
  int len,i;
  len = 0;
  if ($input) {
    while ($input[len]) len++;
  }
  printf("input: %p\n", $input);
  printf("len: %d\n", len);
  $1 = PyList_New(len);
  for (i = 0; i < len; i++) {
    PyList_SetItem($1,i,PyUnicode_FromString($input[i]));
  }
}

bit it doesn't work:

print(mytest.cvar.custom_variables)

gives:

<Swig Object of type 'char **' at 0x7f8b22850ba0>

and

mytest.cvar.custom_variables = ["Foo", "bar"]

Traceback (most recent call last):
  File "./py3test.py", line 31, in <module>
    mytest.cvar.custom_variables = ["Foo", "bar"]
TypeError: in variable 'custom_variables' of type 'char **'


If I change the body of function in generated wrapper with name:

SWIGINTERN PyObject *Swig_var_custom_secrule_variables_get(void) {
....
}

by the code above, it works as I expect.

Looks like SWIG ignores the typemaps above.


What did I forgot?


Thanks,


a.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.