title: SystemError: <built-in function xxx_iterator> returned a result with an error set
body: <p>I'm trying to upgrade 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 the tests on any iterator (automatically generated using %template):</p>
  
  <pre><code>SystemError: &lt;built-in function xxx_iterator&gt; returned a result with an error set
  </code></pre>
  
  <p>For example, even the simplest iteration fails:</p>
  
  <pre><code>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: &lt;built-in function Vertices_iterator&gt; returned a result with an error set
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Again, this was all working great with SWIG 2.0.11 and Python 2.7.12....</p>
  
  <p><strong>Edit: Adding simpler example:</strong></p>
  
  <p>It could be ANY %template-generated iterator, so, for example, this template, defined in the .i file:</p>
  
  <pre><code>%template(Ints) std::list&lt;int&gt;;
  </code></pre>
  
  <p>will fail when using this simple code:</p>
  
  <pre><code>intsList = ncore.Ints()
  intsList.append(1)
  intsList.append(2)
  for i in intsList:
      print(i)
  </code></pre>
  
  <p>with a message similar to this:</p>
  
  <pre><code>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: &lt;built-in function Ints_iterator&gt; returned a result with an error set
  </code></pre>