2017-04-26 52 views
6

我試圖從升級: SWIG 2.0.11和Python 2.7.12到 痛飲3.0.12和Python 3.6, 但我出現以下情況例外,當我在任何迭代器(使用模板%自動生成)運行測試:關於SystemError:<內置功能xxx_iterator>返回的結果有錯誤設置

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(Ints) std::list<int>; 

使用這個簡單的代碼時將失敗:,所以,例如,該模板,在.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 
+0

在不知道源代碼'Vertices_iterator'這是不可能得到任何幫助。 – MSeifert

+0

好點。我編輯了問題以顯示一些簡單的代碼。它發生在ALL%模板生成的代碼上,所以即使是最簡單的模板也會失敗。 –

+0

僅供參考,它看起來像這個提交(https://github.com/swig/swig/pull/560/files)試圖解決類似的問題... –

回答

0

也就是說奇怪,只是重新編譯一切從頭開始。然後,我測試了你簡單的例子(如果正確理解):

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的模塊蟒蛇後,一切就像一個魅力。

測試的配置:

  • dockerized Ubuntu16.04:Python的3.6.1,SWIG 3.0.12,克++ 5.4。
  • dockerized Centos6:Python的3.6.1,SWIG 3.0.12,克++(4.9.2和4.4.7)
+0

感謝您的測試。我應該提到我們在Centos 6上使用了g ++ 4.6和g ++ 4.9,在Windows上使用了MSVS Pro 2013。 –

+0

@DevanWilliams也適用於Centos6/g ++ 4.6。這個簡單的建議示例是否會產生完全相同的問題?有沒有編譯警告? – pe3k