c++ 系统错误:〈内置函数xxx_iterator>返回了一个带有错误集的结果

gj3fmq9x  于 2022-11-19  发布在  其他
关注(0)|答案(2)|浏览(130)

我正在尝试升级:从SWIG 2.0.11和Python 2.7.12到SWIG 3.0.12和Python 3.6,但是当我在任何迭代器上运行测试时(使用%template自动生成),我得到了下面的异常:

SystemError: <built-in function xxx_iterator> returned a result with an error set

例如,即使最简单的迭代也会失败:

Traceback (most recent call last):
File "testRender.py", line 459, in testRender
    for v in vertices:
File "ncore.py", line 90833, in __iter__
    return self.iterator()
File "ncore.py", line 90830, in iterator
    return _ncore.Vertices_iterator(self)
SystemError: <built-in function Vertices_iterator> returned a result with an error set

有什么想法吗?
同样,这在SWIG 2.0.11和Python 2.7.12中也能很好地工作....

编辑:添加更简单的示例:

它可以是ANY %模板生成的迭代器,例如,在.i文件中定义的以下模板:

%template(Ints) std::list<int>;

使用以下简单代码时将失败:

intsList = ncore.Ints()
intsList.append(1)
intsList.append(2)
for i in intsList:
    print(i)

并显示类似以下的消息:

Traceback (most recent call last):
File "testRender.py", line 459, in testRender
    for i in intsList:
File "ncore.py", line 90833, in __iter__
    return self.iterator()
File "ncore.py", line 90830, in iterator
    return _ncore.Ints_iterator(self)
SystemError: <built-in function Ints_iterator> returned a result with an error set
qoefvg9y

qoefvg9y1#

这很奇怪,只是从头开始重新编译了所有内容。然后我测试了您的简化示例(如果理解正确的话):
我的测试:

%module mytest                                                                                             
%{                                                                                                       
    #include <list>
     using namespace std;                                                                                     
%}                                                                                                       

%include "std_list.i"
namespace std {                                                                                          
    %template(Ints) list<int>;                                                           
}

编译步骤:

swig -Wall -c++ -python -py3 -o mytest_wrap.cpp mytest.i
g++ -c -g -ansi mytest_wrap.cpp -I/usr/local/include/python3.6m/ -fPIC -o mytest_wrap.o
g++ -g -ansi -o _mytest.so mytest_wrap.o -shared

然后,在将mytest模块导入到python之后,一切都像魔咒一样工作。
测试配置:

  • 嵌入式Ubuntu 16.04:Python 3.6.1版,SWIG 3.0.12版,g++ 5.4版。
  • 对接Centos6:Python 3.6.1、SWIG 3.0.12、g++(4.9.2和4.4.7版)
iyzzxitl

iyzzxitl2#

虽然这是一个比较老的问题,但最近我在CentOS7 docker中处理SELinux和setools时遇到了类似的问题(<built-in function delete_qpol_iterator_t> returned a result with an error set),从source code构建和安装libsepol和libselinux可能会解决这个问题。
因此,我想更新相关的库和其他依赖项可能是有用的。

相关问题