系统错误:<built-in function xxx_iterator>返回带有错误集的结果

问题描述 投票:0回答:3

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

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 上都运行良好......

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

它可以是任何 %template 生成的迭代器,因此,例如,在 .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
python c++ swig
3个回答
0
投票

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

我的测试.i:

%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 中后,一切都顺利了。

测试配置:

  • dockerized Ubuntu16.04:Python 3.6.1、SWIG 3.0.12、g++ 5.4。
  • dockerized Centos6:Python 3.6.1、SWIG 3.0.12、g++(4.9.2 和 4.4.7)

0
投票

虽然这是一个相对较老的问题,但最近我在处理 CentOS7 docker 中的 SELinux 和 setools 时遇到了类似的问题(

<built-in function delete_qpol_iterator_t> returned a result with an error set
)。从源代码构建并安装 libsepol 和 libselinux 可能会解决问题。

所以我想更新相关的库和其他依赖项可能会有用。


0
投票

为什么我会收到错误消息: 系统错误:返回有错误的结果

因为 对于 pygame.event.get() 中的事件:

© www.soinside.com 2019 - 2024. All rights reserved.