diff options
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 15 | ||||
-rw-r--r-- | Objects/typeobject.c | 8 |
2 files changed, 11 insertions, 12 deletions
diff --git a/Objects/object.c b/Objects/object.c index 6254dfa..3a76193 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -488,12 +488,6 @@ PyObject_Unicode(PyObject *v) return v; } - /* Try the __unicode__ method */ - if (unicodestr == NULL) { - unicodestr= PyString_InternFromString("__unicode__"); - if (unicodestr == NULL) - return NULL; - } if (PyInstance_Check(v)) { /* We're an instance of a classic class */ /* Try __unicode__ from the instance -- alas we have no type */ @@ -508,15 +502,12 @@ PyObject_Unicode(PyObject *v) } } else { - /* Not a classic class instance, try __unicode__ from type */ - /* _PyType_Lookup doesn't create a reference */ - func = _PyType_Lookup(Py_TYPE(v), unicodestr); + /* Not a classic class instance, try __unicode__. */ + func = _PyObject_LookupSpecial(v, "__unicode__", &unicodestr); if (func != NULL) { unicode_method_found = 1; res = PyObject_CallFunctionObjArgs(func, v, NULL); - } - else { - PyErr_Clear(); + Py_DECREF(func); } } diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 304066f..eb3560b 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1179,6 +1179,8 @@ PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b) when the _PyType_Lookup() call fails; - lookup_method() always raises an exception upon errors. + + - _PyObject_LookupSpecial() exported for the benefit of other places. */ static PyObject * @@ -1211,6 +1213,12 @@ lookup_method(PyObject *self, char *attrstr, PyObject **attrobj) return res; } +PyObject * +_PyObject_LookupSpecial(PyObject *self, char *attrstr, PyObject **attrobj) +{ + return lookup_maybe(self, attrstr, attrobj); +} + /* A variation of PyObject_CallMethod that uses lookup_method() instead of PyObject_GetAttrString(). This uses the same convention as lookup_method to cache the interned name string object. */ |