Skip to content
This repository has been archived by the owner on Mar 8, 2018. It is now read-only.

Commit

Permalink
Check our call to PyObject_GetAttrString() to make sure it returns a …
Browse files Browse the repository at this point in the history
…non-NULL value

Should resolve issue: #6

Change-Id: Ie1fd42a9719d50e0baa600e3563ac50159201dc9
  • Loading branch information
R. Tyler Croy committed Dec 13, 2010
1 parent 86229c1 commit e835293
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions cheetah/c/_namemapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e835293

Please sign in to comment.