res = instance_getattr1(inst, name);
if (res == NULL && (func = inst->in_class->cl_getattr) != NULL) {
PyObject *args;
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return NULL;
PyErr_Clear();
args = Py_BuildValue("(OO)", inst, name);
if (args == NULL)
reprstr = PyString_InternFromString("__repr__");
func = instance_getattr(inst, reprstr);
if (func == NULL) {
- PyObject *classname = inst->in_class->cl_name;
- PyObject *mod = PyDict_GetItemString(
- inst->in_class->cl_dict, "__module__");
+ PyObject *classname, *mod;
char *cname;
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return NULL;
+ PyErr_Clear();
+ classname = inst->in_class->cl_name;
+ mod = PyDict_GetItemString(inst->in_class->cl_dict,
+ "__module__");
if (classname != NULL && PyString_Check(classname))
cname = PyString_AsString(classname);
else
cname = "?";
- PyErr_Clear();
if (mod == NULL || !PyString_Check(mod))
return PyString_FromFormat("<?.%s instance at %p>",
cname, inst);
strstr = PyString_InternFromString("__str__");
func = instance_getattr(inst, strstr);
if (func == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return NULL;
PyErr_Clear();
return instance_repr(inst);
}
hashstr = PyString_InternFromString("__hash__");
func = instance_getattr(inst, hashstr);
if (func == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return -1;
+ PyErr_Clear();
/* If there is no __eq__ and no __cmp__ method, we hash on the
address. If an __eq__ or __cmp__ method exists, there must
be a __hash__. */
- PyErr_Clear();
if (eqstr == NULL)
eqstr = PyString_InternFromString("__eq__");
func = instance_getattr(inst, eqstr);
if (func == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return -1;
PyErr_Clear();
if (cmpstr == NULL)
cmpstr = PyString_InternFromString("__cmp__");
func = instance_getattr(inst, cmpstr);
if (func == NULL) {
+ if (!PyErr_ExceptionMatches(
+ PyExc_AttributeError))
+ return -1;
PyErr_Clear();
return _Py_HashPointer(inst);
}
func = instance_getattr(inst, getslicestr);
if (func == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return NULL;
PyErr_Clear();
if (getitemstr == NULL)
PyString_InternFromString("__delslice__");
func = instance_getattr(inst, delslicestr);
if (func == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return -1;
PyErr_Clear();
if (delitemstr == NULL)
delitemstr =
PyString_InternFromString("__setslice__");
func = instance_getattr(inst, setslicestr);
if (func == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return -1;
PyErr_Clear();
if (setitemstr == NULL)
setitemstr =
}
coercefunc = PyObject_GetAttr(v, coerce_obj);
if (coercefunc == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return NULL;
PyErr_Clear();
return generic_binary_op(v, w, opname);
}
coercefunc = PyObject_GetAttr(v, coerce_obj);
if (coercefunc == NULL) {
/* No __coerce__ method */
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return -1;
PyErr_Clear();
return 1;
}
cmp_func = PyObject_GetAttr(v, cmp_obj);
if (cmp_func == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return -2;
PyErr_Clear();
return 2;
}
if (nonzerostr == NULL)
nonzerostr = PyString_InternFromString("__nonzero__");
if ((func = instance_getattr(self, nonzerostr)) == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return -1;
PyErr_Clear();
if (lenstr == NULL)
lenstr = PyString_InternFromString("__len__");
if ((func = instance_getattr(self, lenstr)) == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return -1;
PyErr_Clear();
/* Fall back to the default behavior:
all instances are nonzero */
{
PyObject *func;
- if (iterstr == NULL)
+ if (iterstr == NULL) {
iterstr = PyString_InternFromString("__iter__");
- if (getitemstr == NULL)
+ if (iterstr == NULL)
+ return NULL;
+ }
+ if (getitemstr == NULL) {
getitemstr = PyString_InternFromString("__getitem__");
+ if (getitemstr == NULL)
+ return NULL;
+ }
if ((func = instance_getattr(self, iterstr)) != NULL) {
PyObject *res = PyEval_CallObject(func, (PyObject *)NULL);
}
return res;
}
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return NULL;
PyErr_Clear();
if ((func = instance_getattr(self, getitemstr)) == NULL) {
- PyErr_SetString(PyExc_TypeError, "iteration over non-sequence");
+ PyErr_SetString(PyExc_TypeError,
+ "iteration over non-sequence");
return NULL;
}
Py_DECREF(func);
PyObject *res, *call = PyObject_GetAttrString(func, "__call__");
if (call == NULL) {
PyInstanceObject *inst = (PyInstanceObject*) func;
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return NULL;
PyErr_Clear();
PyErr_Format(PyExc_AttributeError,
"%.200s instance has no __call__ method",
char *sfuncname = "?", *sklassname = "?";
funcname = PyObject_GetAttrString(func, "__name__");
- if (funcname == NULL)
+ if (funcname == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return NULL;
PyErr_Clear();
+ }
else if (!PyString_Check(funcname)) {
Py_DECREF(funcname);
funcname = NULL;
klassname = NULL;
else {
klassname = PyObject_GetAttrString(klass, "__name__");
- if (klassname == NULL)
+ if (klassname == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return NULL;
PyErr_Clear();
+ }
else if (!PyString_Check(klassname)) {
Py_DECREF(klassname);
klassname = NULL;
else
name = PyObject_GetAttrString(class, "__name__");
if (name == NULL) {
+ /* This function cannot return an exception */
PyErr_Clear();
return "?";
}
class = PyObject_GetAttrString(inst, "__class__");
if (class == NULL) {
+ /* This function cannot return an exception */
PyErr_Clear();
class = (PyObject *)(inst->ob_type);
Py_INCREF(class);