diff Objects/object.c @ 53904:1ecdca11eb9e legacy-trunk

add _PyObject_LookupSpecial to handle fetching special method lookup
author Benjamin Peterson <benjamin@python.org>
date Fri, 08 May 2009 03:06:00 +0000
parents 48bf42c2ff7a
children 37497a7793b2
line wrap: on
line diff
--- a/Objects/object.c	Fri May 08 02:28:39 2009 +0000
+++ b/Objects/object.c	Fri May 08 03:06:00 2009 +0000
@@ -488,12 +488,6 @@
 		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 @@
 		}
 	}
 	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);
 		}
 	}