为什么 SWIG 从 in 和 argout 类型映射中制作非法包装器? [英] why does SWIG make illegal wrapper from in and argout typemaps?

查看:25
本文介绍了为什么 SWIG 从 in 和 argout 类型映射中制作非法包装器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个 argout SWIG 类型映射.

I am trying to write an argout SWIG typemap.

从这个界面 foobar.i 文件,这对我来说似乎完全合法:

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 编译了一个非法的 foobar_wrap.cxx 文件,因为它包含以下片段:

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

PySequence_SetItem(, 0, PyInt_FromLong(0));

$input 替换为空.如果我省略 in 类型映射,则包装器是正确的.

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

为什么?

我只想忽略输入,并在输出上填充数组.SWIG 手册明确指出使用 numinputs=0.

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

推荐答案

好的,我想通了.我想我的牛肉是手册.手册没有说,如何输出结果,不是作为打印输出,而是作为填充输出"参数.例如,手册明确指出 $input 可用于 argout typemap.错误,它不可用,如果还有匹配的 (in, numinputs) 类型映射.

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.

这篇关于为什么 SWIG 从 in 和 argout 类型映射中制作非法包装器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆