summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-05-08 03:06:00 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-05-08 03:06:00 (GMT)
commit399e4c4f8f2570a342ac50e9500b12e86eb330a9 (patch)
tree46472e94ea46a4fbe8c3eebe3a30ef9fc529f6f8 /Objects
parentd846f1d4c21f4589966512f78a4a4d74f8399d6d (diff)
downloadcpython-399e4c4f8f2570a342ac50e9500b12e86eb330a9.zip
cpython-399e4c4f8f2570a342ac50e9500b12e86eb330a9.tar.gz
cpython-399e4c4f8f2570a342ac50e9500b12e86eb330a9.tar.bz2
add _PyObject_LookupSpecial to handle fetching special method lookup
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c15
-rw-r--r--Objects/typeobject.c8
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. */