diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-05-09 16:36:39 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-05-09 16:36:39 (GMT) |
commit | af1692a266d5c83d9367557f9642bbd618066318 (patch) | |
tree | b2b3628e8868a81e6b1b23fb330c1887529c7214 /Objects/abstract.c | |
parent | f9b01fe692515eabf555bbc40b458b195f46a807 (diff) | |
download | cpython-af1692a266d5c83d9367557f9642bbd618066318.zip cpython-af1692a266d5c83d9367557f9642bbd618066318.tar.gz cpython-af1692a266d5c83d9367557f9642bbd618066318.tar.bz2 |
convert some more special methods to use _PyObject_LookupSpecial
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r-- | Objects/abstract.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index cd14386..c2d8db7 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -93,7 +93,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__() */ @@ -107,20 +107,15 @@ _PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) PyErr_Clear(); } - /* cache a hashed version of the attribute string */ - if (hintstrobj == NULL) { - hintstrobj = PyString_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; |