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 /Python | |
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 'Python')
-rw-r--r-- | Python/sysmodule.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 4e52282..6c22b8f 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -643,7 +643,7 @@ static PyObject * 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 @@ sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds) 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 @@ sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds) 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? */ |