SystemError: <built-in function xxx_iterator> returns the result with the set of errors set

I am trying to go from: SWIG 2.0.11 and Python 2.7.12 to SWIG 3.0.12 and Python 3.6, but I get the following exception when I run tests on any iterator (automatically generated using the% pattern):

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

For example, even the simplest iteration fails:

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

Any ideas?

Again, all this works fine with SWIG 2.0.11 and Python 2.7.12 ....

Edit: adding a simpler example:

It can be ANY template iterator with a template, therefore, for example, this template defined in the .i file:

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

It will crash when using this simple code:

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

with a message similar to this:

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
+6
1

, . ( ):

Mytest.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

Source: https://habr.com/ru/post/1016804/


All Articles