summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-05-09 18:15:04 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-05-09 18:15:04 (GMT)
commita5758c012001b1044d4a109b736c0406cdf8c9ec (patch)
tree562f1c9b048ce5812de50b67cee59707d5625fbb /Objects/abstract.c
parent8bc5b681599b66887f69ca54631d6e1ce4894252 (diff)
downloadcpython-a5758c012001b1044d4a109b736c0406cdf8c9ec.zip
cpython-a5758c012001b1044d4a109b736c0406cdf8c9ec.tar.gz
cpython-a5758c012001b1044d4a109b736c0406cdf8c9ec.tar.bz2
Merged revisions 72508 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r72508 | benjamin.peterson | 2009-05-09 11:36:39 -0500 (Sat, 09 May 2009) | 1 line convert some more special methods to use _PyObject_LookupSpecial ........
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 7679d5b..83f5367 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -75,7 +75,7 @@ Py_ssize_t
_PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
{
static PyObject *hintstrobj = NULL;
- PyObject *ro;
+ PyObject *ro, *hintmeth;
Py_ssize_t rv;
/* try o.__len__() */
@@ -89,20 +89,15 @@ _PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
PyErr_Clear();
}
- /* cache a hashed version of the attribute string */
- if (hintstrobj == NULL) {
- hintstrobj = PyUnicode_InternFromString("__length_hint__");
- if (hintstrobj == NULL)
- return -1;
- }
-
/* try o.__length_hint__() */
- ro = PyObject_CallMethodObjArgs(o, hintstrobj, NULL);
+ hintmeth = _PyObject_LookupSpecial(o, "__length_hint__", &hintstrobj);
+ if (hintmeth == NULL)
+ return defaultvalue;
+ ro = PyObject_CallFunctionObjArgs(hintmeth, NULL);
+ Py_DECREF(hintmeth);
if (ro == NULL) {
- if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
- !PyErr_ExceptionMatches(PyExc_AttributeError))
- return -1;
- PyErr_Clear();
+ if (!PyErr_ExceptionMatches(PyExc_TypeError))
+ return -1;
return defaultvalue;
}
rv = PyLong_Check(ro) ? PyLong_AsSsize_t(ro) : defaultvalue;