summaryrefslogtreecommitdiff
path: root/cheetah/c/_namemapper.c
diff options
context:
space:
mode:
Diffstat (limited to 'cheetah/c/_namemapper.c')
-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);