[Numpy-discussion] Infinite recursion in numpy called from swig generated code
Robert Lupton
rhl at astro.princeton.edu
Tue Apr 18 13:07:04 EDT 2006
The latest version of swig (1.3.28 or 1.3.29) has broken my
multiple-inheritance-from-C-and-numpy application; more specifically,
it generates an infinite loop in numpy-land. I'm using numpy (0.9.6),
and here's the offending code. Ideas anyone? I've pasted the crucial
part of numpy.lib.UserArray onto the end of this message (how do I know?
because you can replace the "from numpy.lib.UserArray" with this, and
the problem persists).
#####################################################
from numpy.lib.UserArray import *
import types
class myImage(types.ObjectType):
def __init__(self, *args):
this = None
try: self.this.append(this)
except: self.this = this
class Image(UserArray, myImage):
def __init__(self, *args):
myImage.__init__(self, *args)
#####################################################
The symptoms are:
from recursionBug import *; Image(myImage())
------------------------------------------------------------
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "recursionBug.py", line 32, in __init__
myImage.__init__(self, *args)
File "recursionBug.py", line 26, in __init__
except: self.this = this
File "/sw/lib/python2.4/site-packages/numpy/lib/UserArray.py",
line 187, in __setattr__
self.array.__setattr__(attr, value)
File "/sw/lib/python2.4/site-packages/numpy/lib/UserArray.py",
line 193, in __getattr__
return self.array.__getattribute__(attr)
...
File "/sw/lib/python2.4/site-packages/numpy/lib/UserArray.py",
line 193, in __getattr__
return self.array.__getattribute__(attr)
File "/sw/lib/python2.4/site-packages/numpy/lib/UserArray.py",
line 193, in __getattr__
return self.array.__getattribute__(attr)
RuntimeError: maximum recursion depth exceeded
The following stripped down piece of numpy seems to be the problem:
class UserArray(object):
def __setattr__(self,attr,value):
try:
self.array.__setattr__(attr, value)
except AttributeError:
object.__setattr__(self, attr, value)
# Only called after other approaches fail.
def __getattr__(self,attr):
return self.array.__getattribute__(attr)
R
More information about the NumPy-Discussion
mailing list