Mercurial > cpython-lru_cache-weakref
diff Python/sysmodule.c @ 53947:f90b3eec7c32 legacy-trunk
convert some more special methods to use _PyObject_LookupSpecial
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 09 May 2009 16:36:39 +0000 |
| parents | 9b358eae532a |
| children | 150986ab3db2 |
line wrap: on
line diff
--- a/Python/sysmodule.c Sat May 09 12:07:17 2009 +0000 +++ b/Python/sysmodule.c Sat May 09 16:36:39 2009 +0000 @@ -643,7 +643,7 @@ sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds) { PyObject *res = NULL; - static PyObject *str__sizeof__, *gc_head_size = NULL; + static PyObject *str__sizeof__ = NULL, *gc_head_size = NULL; static char *kwlist[] = {"object", "default", 0}; PyObject *o, *dflt = NULL; @@ -651,13 +651,6 @@ kwlist, &o, &dflt)) return NULL; - /* Initialize static variable needed by _PyType_Lookup */ - if (str__sizeof__ == NULL) { - str__sizeof__ = PyString_InternFromString("__sizeof__"); - if (str__sizeof__ == NULL) - return NULL; - } - /* Initialize static variable for GC head size */ if (gc_head_size == NULL) { gc_head_size = PyInt_FromSsize_t(sizeof(PyGC_Head)); @@ -674,14 +667,16 @@ res = PyInt_FromSsize_t(PyInstance_Type.tp_basicsize); /* all other objects */ else { - PyObject *method = _PyType_Lookup(Py_TYPE(o), - str__sizeof__); + PyObject *method = _PyObject_LookupSpecial(o, "__sizeof__", + &str__sizeof__); if (method == NULL) PyErr_Format(PyExc_TypeError, "Type %.100s doesn't define __sizeof__", Py_TYPE(o)->tp_name); - else - res = PyObject_CallFunctionObjArgs(method, o, NULL); + else { + res = PyObject_CallFunctionObjArgs(method, NULL); + Py_DECREF(method); + } } /* Has a default value been given? */
