comparison Python/sysmodule.c @ 47918:68c7964d2534 legacy-trunk

Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
author Robert Schuppenies <okkotonushi@googlemail.com>
date Thu, 10 Jul 2008 13:43:26 +0000
parents 0738119c1ef8
children fd054e73e2f2
comparison
equal deleted inserted replaced
47917:c32e91650c14 47918:68c7964d2534
649 str__sizeof__ = PyString_InternFromString("__sizeof__"); 649 str__sizeof__ = PyString_InternFromString("__sizeof__");
650 if (str__sizeof__ == NULL) 650 if (str__sizeof__ == NULL)
651 return NULL; 651 return NULL;
652 } 652 }
653 653
654 /* Type objects */ 654 /* Make sure the type is initialized. float gets initialized late */
655 if (PyType_Check(args)){ 655 if (PyType_Ready(Py_TYPE(args)) < 0)
656 return NULL;
657
658 /* Instance of old-style class */
659 if (PyInstance_Check(args))
660 return PyInt_FromSsize_t(PyInstance_Type.tp_basicsize);
661 /* all other objects */
662 else {
656 PyObject *method = _PyType_Lookup(Py_TYPE(args), 663 PyObject *method = _PyType_Lookup(Py_TYPE(args),
657 str__sizeof__); 664 str__sizeof__);
658 if (method == NULL) { 665 if (method == NULL) {
659 PyErr_Format(PyExc_TypeError, 666 PyErr_Format(PyExc_TypeError,
660 "Type %.100s doesn't define __sizeof__", 667 "Type %.100s doesn't define __sizeof__",
661 Py_TYPE(args)->tp_name); 668 Py_TYPE(args)->tp_name);
662 return NULL; 669 return NULL;
663 } 670 }
664 return PyObject_CallFunctionObjArgs(method, args, NULL); 671 return PyObject_CallFunctionObjArgs(method, args, NULL);
665 } 672 }
666 /* Instance of old-style classes */
667 else if (PyInstance_Check(args))
668 return PyInt_FromSsize_t(PyInstance_Type.tp_basicsize);
669 /* Old-style classes */
670 else if (PyClass_Check(args))
671 return PyInt_FromSsize_t(PyClass_Type.tp_basicsize);
672 else
673 return PyObject_CallMethod(args, "__sizeof__", NULL);
674 } 673 }
675 674
676 PyDoc_STRVAR(getsizeof_doc, 675 PyDoc_STRVAR(getsizeof_doc,
677 "getsizeof(object) -> int\n\ 676 "getsizeof(object) -> int\n\
678 \n\ 677 \n\