mirror of
https://github.com/python/cpython.git
synced 2025-10-08 08:01:55 +00:00
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 ........
This commit is contained in:
parent
c04dad772c
commit
224205fde2
4 changed files with 63 additions and 9 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue