summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-05-08 03:25:19 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-05-08 03:25:19 (GMT)
commit224205fde2af8fdbbd11de0b219880df9a0edabd (patch)
tree85c6a9b1b07d31f712654d82b2e25cf5abeac92a /Objects
parentc04dad772c4c01a60b3c0e70e3ae3e53bf7f9b66 (diff)
downloadcpython-224205fde2af8fdbbd11de0b219880df9a0edabd.zip
cpython-224205fde2af8fdbbd11de0b219880df9a0edabd.tar.gz
cpython-224205fde2af8fdbbd11de0b219880df9a0edabd.tar.bz2
Merged revisions 72461 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r72461 | benjamin.peterson | 2009-05-07 22:06:00 -0500 (Thu, 07 May 2009) | 1 line add _PyObject_LookupSpecial to handle fetching special method lookup ........
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c11
-rw-r--r--Objects/typeobject.c8
2 files changed, 10 insertions, 9 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 57b4906..d8fc91e 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -474,12 +474,6 @@ PyObject_Bytes(PyObject *v)
PyObject *result, *func;
static PyObject *bytesstring = NULL;
- if (bytesstring == NULL) {
- bytesstring = PyUnicode_InternFromString("__bytes__");
- if (bytesstring == NULL)
- return NULL;
- }
-
if (v == NULL)
return PyBytes_FromString("<NULL>");
@@ -488,10 +482,10 @@ PyObject_Bytes(PyObject *v)
return v;
}
- /* Doesn't create a reference */
- func = _PyType_Lookup(Py_TYPE(v), bytesstring);
+ func = _PyObject_LookupSpecial(v, "__bytes__", &bytesstring);
if (func != NULL) {
result = PyObject_CallFunctionObjArgs(func, v, NULL);
+ Py_DECREF(func);
if (result == NULL)
return NULL;
if (!PyBytes_Check(result)) {
@@ -503,7 +497,6 @@ PyObject_Bytes(PyObject *v)
}
return result;
}
- PyErr_Clear();
return PyBytes_FromObject(v);
}
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 06d600e..7e81ce6 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1125,6 +1125,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 *
@@ -1157,6 +1159,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. */