Skip to content
Browse files

Added test and fix for segfault in namemapper where exception is thro…

…wn by __getattr__.
  • Loading branch information...
1 parent a969475 commit 0287a0833cc30e0e469f6a774770002128a0281f @js-cfl js-cfl committed with rtyler Sep 14, 2010
Showing with 21 additions and 6 deletions.
  1. +2 −1 buildandrun
  2. +13 −0 cheetah/Tests/NameMapper.py
  3. +6 −5 cheetah/c/_namemapper.c
View
3 buildandrun
@@ -58,7 +58,8 @@ def main():
os.putenv('PYTHONPATH', libdir)
rc = subprocess.call( ['python',] + args )
-
+ if rc == -11:
+ logging.error('Segmentation fault in test process. Test failed.')
if __name__ == '__main__':
View
13 cheetah/Tests/NameMapper.py
@@ -43,6 +43,10 @@ def meth3(self):
except:
raise
+class DummyClassGetAttrRaises(object):
+ def __getattr__(self, name):
+ raise ValueError
+
def dummyFunc(arg="Scooby"):
return arg
@@ -67,6 +71,7 @@ def funcThatRaises():
'aClass': DummyClass,
'aFunc': dummyFunc,
'anObj': DummyClass(),
+ 'anObjThatRaises': DummyClassGetAttrRaises(),
'aMeth': DummyClass().meth1,
'none': None,
'emptyString': '',
@@ -419,6 +424,14 @@ def test60(self):
for i in range(10):
self.get('aDict.nestedDict.funcThatRaises', False)
+ def test61(self):
+ """Accessing attribute where __getattr__ raises shouldn't segfault if something follows it"""
+
+ def test(self=self):
+ self.get('anObjThatRaises.willraise.anything')
+ self.assertRaises(ValueError, test)
+
+
class VFS(VFN):
_searchListLength = 1
View
11 cheetah/c/_namemapper.c
@@ -188,14 +188,15 @@ static PyObject *PyNamemapper_valueForName(PyObject *obj, char *nameChunks[], in
nextVal = PyObject_GetAttrString(currentVal, currentKey);
exc = PyErr_Occurred();
if (exc != NULL) {
- // if exception == AttributeError
+ // if exception == AttributeError, report our own exception
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
setNotFoundException(currentKey, currentVal);
- if (i > 0) {
- Py_DECREF(currentVal);
- }
- return NULL;
}
+ // any exceptions results in failure
+ if (i > 0) {
+ Py_DECREF(currentVal);
+ }
+ return NULL;
}
}
if (i > 0) {

0 comments on commit 0287a08

Please sign in to comment.
Something went wrong with that request. Please try again.