Message3439
The attached patch fixes this issue.
Some details: In my test case an old style class implements
__getattr__(self, name). An access of an otherwise undefined attribute
yields the following JAVA stack trace (just the interesting part):
at org.python.core.PyFunction.__call__(PyFunction.java:312)
at org.python.core.PyInstance.ifindfunction(PyInstance.java:238)
at org.python.core.PyInstance.__findattr__(PyInstance.java:217)
at org.python.core.PyInstance.__findattr_ex__(PyInstance.java:204)
at org.python.core.PyObject.__getattr__(PyObject.java:820)
at org.python.pycode._pyx0.f$0(testAttributeError.py)
Inspection of this code path shows:
- the call of a __findattr__-method, which indicates a problem,
because the __findattr__ methods never throw AttributeError
- org.python.core.PyInstance#ifindfunction(String) catches PyException
and returns null in case of an AttributeError. (In PyObject#__getattr__
this null return value yields an AttributeError.)
I looked at the clients of PyInstance#ifindfunction(String). The method
is only used within PyInstance. In every case, we see the same pattern
value=this.ifindfunction(name);
...
if (value==null)
noAttributeError(name);
Therefore it does not harm, to remove the try-catch clause from
ifindfunction. Of course we have to make sure, that the __findattr__
methods still return null instead of an AttributeError. Therefor I added
a new method PyInstance#__findattr_ex__(String name, boolean stopAtJava)
and changed PyInstance#__findattr__(String name, boolean stopAtJava) to
call the new method.
With the patch applied, the relevant parts of a stack trace look like this:
at org.python.core.PyFunction.__call__(PyFunction.java:312)
at org.python.core.PyInstance.ifindfunction(PyInstance.java:246)
at org.python.core.PyInstance.__findattr_ex__(PyInstance.java:226)
at org.python.core.PyInstance.__findattr_ex__(PyInstance.java:204)
at org.python.core.PyObject.__getattr__(PyObject.java:820)
at org.python.pycode._pyx0.f$0(testAttributeError.py)
No more __findattr__ methods. Looks good for me. |
|
Date |
User |
Action |
Args |
2008-08-19 11:58:38 | akruis | set | messageid: <1219147118.67.0.799494758901.issue1095@psf.upfronthosting.co.za> |
2008-08-19 11:58:38 | akruis | set | recipients:
+ akruis, leosoto |
2008-08-19 11:58:38 | akruis | link | issue1095 messages |
2008-08-19 11:58:37 | akruis | create | |
|