Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(72256)

Side by Side Diff: Objects/typeobject.c

Issue 21233: Add *Calloc functions to CPython memory allocation API
Patch Set: Created 5 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Objects/obmalloc.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Type object implementation */ 1 /* Type object implementation */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include "frameobject.h" 4 #include "frameobject.h"
5 #include "structmember.h" 5 #include "structmember.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 8
9 9
10 /* Support type attribute cache */ 10 /* Support type attribute cache */
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 PyObject * 879 PyObject *
880 PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) 880 PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
881 { 881 {
882 PyObject *obj; 882 PyObject *obj;
883 const size_t size = _PyObject_VAR_SIZE(type, nitems+1); 883 const size_t size = _PyObject_VAR_SIZE(type, nitems+1);
884 /* note that we need to add one, for the sentinel */ 884 /* note that we need to add one, for the sentinel */
885 885
886 if (PyType_IS_GC(type)) 886 if (PyType_IS_GC(type))
887 obj = _PyObject_GC_Malloc(size); 887 obj = _PyObject_GC_Malloc(size);
888 else 888 else
889 obj = (PyObject *)PyObject_MALLOC(size); 889 obj = (PyObject *)PyObject_Calloc(1, size);
890 890
891 if (obj == NULL) 891 if (obj == NULL)
892 return PyErr_NoMemory(); 892 return PyErr_NoMemory();
893 893
894 memset(obj, '\0', size);
895
896 if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) 894 if (type->tp_flags & Py_TPFLAGS_HEAPTYPE)
897 Py_INCREF(type); 895 Py_INCREF(type);
898 896
899 if (type->tp_itemsize == 0) 897 if (type->tp_itemsize == 0)
900 (void)PyObject_INIT(obj, type); 898 (void)PyObject_INIT(obj, type);
901 else 899 else
902 (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems); 900 (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);
903 901
904 if (PyType_IS_GC(type)) 902 if (PyType_IS_GC(type))
905 _PyObject_GC_TRACK(obj); 903 _PyObject_GC_TRACK(obj);
(...skipping 6172 matching lines...) Expand 10 before | Expand all | Expand 10 after
7078 0, /* tp_base */ 7076 0, /* tp_base */
7079 0, /* tp_dict */ 7077 0, /* tp_dict */
7080 super_descr_get, /* tp_descr_get */ 7078 super_descr_get, /* tp_descr_get */
7081 0, /* tp_descr_set */ 7079 0, /* tp_descr_set */
7082 0, /* tp_dictoffset */ 7080 0, /* tp_dictoffset */
7083 super_init, /* tp_init */ 7081 super_init, /* tp_init */
7084 PyType_GenericAlloc, /* tp_alloc */ 7082 PyType_GenericAlloc, /* tp_alloc */
7085 PyType_GenericNew, /* tp_new */ 7083 PyType_GenericNew, /* tp_new */
7086 PyObject_GC_Del, /* tp_free */ 7084 PyObject_GC_Del, /* tp_free */
7087 }; 7085 };
OLDNEW
« no previous file with comments | « Objects/obmalloc.c ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+