summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR. Tyler Croy <tyler@monkeypox.org>2010-12-12 19:54:21 -0800
committerR. Tyler Croy <tyler@monkeypox.org>2010-12-12 19:58:24 -0800
commite8352935d01dbf1f20a8bc6aecc3c40592508435 (patch)
tree26ce13265a9442c5ba868f2f7d56081fbb38dd4a
parent86229c10e234813c19f49882ddd4a2321dc2edb9 (diff)
downloadpython-cheetah-e8352935d01dbf1f20a8bc6aecc3c40592508435.tar.gz
Check our call to PyObject_GetAttrString() to make sure it returns a non-NULL value
Should resolve issue: #6 Change-Id: Ie1fd42a9719d50e0baa600e3563ac50159201dc9
-rw-r--r--cheetah/c/_namemapper.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/cheetah/c/_namemapper.c b/cheetah/c/_namemapper.c
index a114658..ceca6e0 100644
--- a/cheetah/c/_namemapper.c
+++ b/cheetah/c/_namemapper.c
@@ -179,25 +179,36 @@ static PyObject *PyNamemapper_valueForName(PyObject *obj, char *nameChunks[], in
}
return NULL;
}
-
+
if (PyMapping_Check(currentVal) && PyMapping_HasKeyString(currentVal, currentKey)) {
nextVal = PyMapping_GetItemString(currentVal, currentKey);
- }
+ }
+
else {
- PyObject *exc;
- nextVal = PyObject_GetAttrString(currentVal, currentKey);
- exc = PyErr_Occurred();
- if (exc != NULL) {
- // if exception == AttributeError, report our own exception
- if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
- setNotFoundException(currentKey, currentVal);
+ PyObject *exc;
+ nextVal = PyObject_GetAttrString(currentVal, currentKey);
+ exc = PyErr_Occurred();
+
+ if (exc != NULL) {
+ // if exception == AttributeError, report our own exception
+ if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ setNotFoundException(currentKey, currentVal);
+ }
+ // any exceptions results in failure
+ if (i > 0) {
+ Py_DECREF(currentVal);
+ }
+ return NULL;
}
- // any exceptions results in failure
- if (i > 0) {
- Py_DECREF(currentVal);
+
+ if (nextVal == NULL) {
+ setNotFoundException(currentKey, currentVal);
+ // any exceptions results in failure
+ if (i > 0) {
+ Py_DECREF(currentVal);
+ }
+ return NULL;
}
- return NULL;
- }
}
if (i > 0) {
Py_DECREF(currentVal);