why does SWIG make illegal wrapper from in and arg

2019-08-06 02:23发布

I am trying to write an argout SWIG typemap.

From this interface foobar.i file, which seems perfectly legal to me:

%{
void f(int arg[2]) {}
%}

%typemap(in, numinputs = 0) int [ANY] {}

%typemap(argout) int arg[ANY] {
  PySequence_SetItem($input, 0, PyInt_FromLong(0));
}

void f(int arg[2]) {}

SWIG compiles an illegal foobar_wrap.cxx file, because it contains the following fragment:

PySequence_SetItem(, 0, PyInt_FromLong(0));

replacing $input with nothing. If I omit the in typemap, then the wrapper is correct.

Why?

I just want to ignore the input, and fill up the array on the output. The SWIG manual clearly says to use numinputs=0.

标签: swig
1条回答
beautiful°
2楼-- · 2019-08-06 03:06

OK I figured it out. I guess my beef here is with the manual. The manual does not say, how to output results, not as printout, but as filled in "output" arguments. For example, the manual clearly states that $input is available for argout typemap. Wrong, it is not available, if there is also a matching (in, numinputs) typemap.

查看更多
登录 后发表回答