why does SWIG make illegal wrapper from in and argout typemaps?

為{幸葍}努か 提交于 2020-01-06 04:05:04

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/21422148/why-does-swig-make-illegal-wrapper-from-in-and-argout-typemaps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!