| OLD | NEW |
| 1 | 1 |
| 2 /* System module */ | 2 /* System module */ |
| 3 | 3 |
| 4 /* | 4 /* |
| 5 Various bits of information used by the interpreter are collected in | 5 Various bits of information used by the interpreter are collected in |
| 6 module 'sys'. | 6 module 'sys'. |
| 7 Function member: | 7 Function member: |
| 8 - exit(sts): raise SystemExit | 8 - exit(sts): raise SystemExit |
| 9 Data members: | 9 Data members: |
| 10 - stdin, stdout, stderr: standard file objects | 10 - stdin, stdout, stderr: standard file objects |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 return NULL; | 635 return NULL; |
| 636 mallopt(M_DEBUG, flag); | 636 mallopt(M_DEBUG, flag); |
| 637 Py_INCREF(Py_None); | 637 Py_INCREF(Py_None); |
| 638 return Py_None; | 638 return Py_None; |
| 639 } | 639 } |
| 640 #endif /* USE_MALLOPT */ | 640 #endif /* USE_MALLOPT */ |
| 641 | 641 |
| 642 static PyObject * | 642 static PyObject * |
| 643 sys_getsizeof(PyObject *self, PyObject *args) | 643 sys_getsizeof(PyObject *self, PyObject *args) |
| 644 { | 644 { |
| 645 » static PyObject * str__sizeof__ = NULL; | 645 » PyObject *res = NULL; |
| 646 static PyObject *str__sizeof__ = NULL; |
| 647 static PyObject *gc_head_size = NULL; |
| 646 | 648 |
| 647 /* Initialize static variable needed by _PyType_Lookup */ | 649 /* Initialize static variable needed by _PyType_Lookup */ |
| 648 if (str__sizeof__ == NULL) { | 650 if (str__sizeof__ == NULL) { |
| 649 str__sizeof__ = PyString_InternFromString("__sizeof__"); | 651 str__sizeof__ = PyString_InternFromString("__sizeof__"); |
| 650 if (str__sizeof__ == NULL) | 652 if (str__sizeof__ == NULL) |
| 651 return NULL; | 653 return NULL; |
| 652 } | 654 } |
| 655 |
| 656 /* Initialize static variable for GC head size */ |
| 657 if (gc_head_size == NULL) { |
| 658 gc_head_size = PyInt_FromSsize_t(sizeof(PyGC_Head)); |
| 659 if (gc_head_size == NULL) { |
| 660 Py_DECREF(res); |
| 661 return NULL; |
| 662 } |
| 663 } |
| 653 | 664 |
| 654 /* Type objects */ | 665 /* Type objects */ |
| 655 if (PyType_Check(args)){ | 666 if (PyType_Check(args)){ |
| 656 PyObject *method = _PyType_Lookup(Py_TYPE(args), | 667 PyObject *method = _PyType_Lookup(Py_TYPE(args), |
| 657 str__sizeof__); | 668 str__sizeof__); |
| 658 if (method == NULL) { | 669 if (method == NULL) { |
| 659 PyErr_Format(PyExc_TypeError, | 670 PyErr_Format(PyExc_TypeError, |
| 660 "Type %.100s doesn't define __sizeof__", | 671 "Type %.100s doesn't define __sizeof__", |
| 661 Py_TYPE(args)->tp_name); | 672 Py_TYPE(args)->tp_name); |
| 662 return NULL; | 673 return NULL; |
| 663 } | 674 } |
| 664 » » return PyObject_CallFunctionObjArgs(method, args, NULL); | 675 » » res = PyObject_CallFunctionObjArgs(method, args, NULL); |
| 665 » } | 676 » } |
| 666 /* Instance of old-style classes */ | 677 /* Instance of old-style classes */ |
| 667 else if (PyInstance_Check(args)) | 678 else if (PyInstance_Check(args)) |
| 668 » » return PyInt_FromSsize_t(PyInstance_Type.tp_basicsize); | 679 » » res = PyInt_FromSsize_t(PyInstance_Type.tp_basicsize); |
| 669 /* Old-style classes */ | 680 /* Old-style classes */ |
| 670 else if (PyClass_Check(args)) | 681 else if (PyClass_Check(args)) |
| 671 » » return PyInt_FromSsize_t(PyClass_Type.tp_basicsize); | 682 » » res = PyInt_FromSsize_t(PyClass_Type.tp_basicsize); |
| 672 else | 683 else |
| 673 » » return PyObject_CallMethod(args, "__sizeof__", NULL); | 684 » » res = PyObject_CallMethod(args, "__sizeof__", NULL); |
| 685 |
| 686 » /* add gc_head size if object is tracked by gc */ |
| 687 » if (PyObject_IS_GC(args)) { |
| 688 res = PyNumber_Add(res, gc_head_size); |
| 689 Py_DECREF(gc_head_size); |
| 690 » } |
| 691 |
| 692 » return res; |
| 674 } | 693 } |
| 675 | 694 |
| 676 PyDoc_STRVAR(getsizeof_doc, | 695 PyDoc_STRVAR(getsizeof_doc, |
| 677 "getsizeof(object) -> int\n\ | 696 "getsizeof(object) -> int\n\ |
| 678 \n\ | 697 \n\ |
| 679 Return the size of object in bytes."); | 698 Return the size of object in bytes."); |
| 680 | 699 |
| 681 static PyObject * | 700 static PyObject * |
| 682 sys_getrefcount(PyObject *self, PyObject *arg) | 701 sys_getrefcount(PyObject *self, PyObject *arg) |
| 683 { | 702 { |
| (...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1676 | 1695 |
| 1677 void | 1696 void |
| 1678 PySys_WriteStderr(const char *format, ...) | 1697 PySys_WriteStderr(const char *format, ...) |
| 1679 { | 1698 { |
| 1680 va_list va; | 1699 va_list va; |
| 1681 | 1700 |
| 1682 va_start(va, format); | 1701 va_start(va, format); |
| 1683 mywrite("stderr", stderr, format, va); | 1702 mywrite("stderr", stderr, format, va); |
| 1684 va_end(va); | 1703 va_end(va); |
| 1685 } | 1704 } |
| OLD | NEW |