diff options
author | Robert Schuppenies <okkotonushi@googlemail.com> | 2008-07-10 13:43:26 (GMT) |
---|---|---|
committer | Robert Schuppenies <okkotonushi@googlemail.com> | 2008-07-10 13:43:26 (GMT) |
commit | d2cd86ddd5c3d90911a98a1440563118297e45db (patch) | |
tree | 3380b02500cd76ba066e7de9494277380ea0003b /Python | |
parent | 548db58e0264385026c892c524522e82f8468fa5 (diff) | |
download | cpython-d2cd86ddd5c3d90911a98a1440563118297e45db.zip cpython-d2cd86ddd5c3d90911a98a1440563118297e45db.tar.gz cpython-d2cd86ddd5c3d90911a98a1440563118297e45db.tar.bz2 |
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/sysmodule.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 5cfb488..a4726bc 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -651,8 +651,15 @@ sys_getsizeof(PyObject *self, PyObject *args) return NULL; } - /* Type objects */ - if (PyType_Check(args)){ + /* Make sure the type is initialized. float gets initialized late */ + if (PyType_Ready(Py_TYPE(args)) < 0) + return NULL; + + /* Instance of old-style class */ + if (PyInstance_Check(args)) + return PyInt_FromSsize_t(PyInstance_Type.tp_basicsize); + /* all other objects */ + else { PyObject *method = _PyType_Lookup(Py_TYPE(args), str__sizeof__); if (method == NULL) { @@ -662,15 +669,7 @@ sys_getsizeof(PyObject *self, PyObject *args) return NULL; } return PyObject_CallFunctionObjArgs(method, args, NULL); - } - /* Instance of old-style classes */ - else if (PyInstance_Check(args)) - return PyInt_FromSsize_t(PyInstance_Type.tp_basicsize); - /* Old-style classes */ - else if (PyClass_Check(args)) - return PyInt_FromSsize_t(PyClass_Type.tp_basicsize); - else - return PyObject_CallMethod(args, "__sizeof__", NULL); + } } PyDoc_STRVAR(getsizeof_doc, |