Kaydet (Commit) dcc819a5 authored tarafından Neil Schemenauer's avatar Neil Schemenauer

Use pymalloc if it's enabled.

üst a1a9c51a
...@@ -829,7 +829,7 @@ _PyObject_GC_Malloc(PyTypeObject *tp, int nitems) ...@@ -829,7 +829,7 @@ _PyObject_GC_Malloc(PyTypeObject *tp, int nitems)
const size_t basicsize = _PyObject_VAR_SIZE(tp, nitems); const size_t basicsize = _PyObject_VAR_SIZE(tp, nitems);
#ifdef WITH_CYCLE_GC #ifdef WITH_CYCLE_GC
const size_t nbytes = sizeof(PyGC_Head) + basicsize; const size_t nbytes = sizeof(PyGC_Head) + basicsize;
PyGC_Head *g = PyObject_MALLOC(nbytes); PyGC_Head *g = _PyMalloc_MALLOC(nbytes);
if (g == NULL) if (g == NULL)
return (PyObject *)PyErr_NoMemory(); return (PyObject *)PyErr_NoMemory();
g->gc.gc_next = NULL; g->gc.gc_next = NULL;
...@@ -845,7 +845,7 @@ _PyObject_GC_Malloc(PyTypeObject *tp, int nitems) ...@@ -845,7 +845,7 @@ _PyObject_GC_Malloc(PyTypeObject *tp, int nitems)
} }
op = FROM_GC(g); op = FROM_GC(g);
#else #else
op = PyObject_MALLOC(basicsize); op = _PyMalloc_MALLOC(basicsize);
if (op == NULL) if (op == NULL)
return (PyObject *)PyErr_NoMemory(); return (PyObject *)PyErr_NoMemory();
...@@ -896,9 +896,9 @@ _PyObject_GC_Del(PyObject *op) ...@@ -896,9 +896,9 @@ _PyObject_GC_Del(PyObject *op)
if (allocated > 0) { if (allocated > 0) {
allocated--; allocated--;
} }
PyObject_FREE(g); _PyMalloc_FREE(g);
#else #else
PyObject_FREE(op); _PyMalloc_FREE(op);
#endif #endif
} }
...@@ -1914,7 +1914,7 @@ static PyObject * ...@@ -1914,7 +1914,7 @@ static PyObject *
dictiter_new(dictobject *dict, binaryfunc select) dictiter_new(dictobject *dict, binaryfunc select)
{ {
dictiterobject *di; dictiterobject *di;
di = PyObject_NEW(dictiterobject, &PyDictIter_Type); di = PyMalloc_New(dictiterobject, &PyDictIter_Type);
if (di == NULL) if (di == NULL)
return NULL; return NULL;
Py_INCREF(dict); Py_INCREF(dict);
...@@ -1929,7 +1929,7 @@ static void ...@@ -1929,7 +1929,7 @@ static void
dictiter_dealloc(dictiterobject *di) dictiter_dealloc(dictiterobject *di)
{ {
Py_DECREF(di->di_dict); Py_DECREF(di->di_dict);
PyObject_DEL(di); PyMalloc_Del(di);
} }
static PyObject * static PyObject *
......
...@@ -60,7 +60,7 @@ PyObject * ...@@ -60,7 +60,7 @@ PyObject *
PyRange_New(long start, long len, long step, int reps) PyRange_New(long start, long len, long step, int reps)
{ {
long totlen = -1; long totlen = -1;
rangeobject *obj = PyObject_NEW(rangeobject, &PyRange_Type); rangeobject *obj = PyMalloc_New(rangeobject, &PyRange_Type);
if (obj == NULL) if (obj == NULL)
return NULL; return NULL;
...@@ -104,7 +104,7 @@ PyRange_New(long start, long len, long step, int reps) ...@@ -104,7 +104,7 @@ PyRange_New(long start, long len, long step, int reps)
static void static void
range_dealloc(rangeobject *r) range_dealloc(rangeobject *r)
{ {
PyObject_DEL(r); PyMalloc_Del(r);
} }
static PyObject * static PyObject *
......
...@@ -60,7 +60,7 @@ PyObject _Py_EllipsisObject = { ...@@ -60,7 +60,7 @@ PyObject _Py_EllipsisObject = {
PyObject * PyObject *
PySlice_New(PyObject *start, PyObject *stop, PyObject *step) PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
{ {
PySliceObject *obj = PyObject_NEW(PySliceObject, &PySlice_Type); PySliceObject *obj = PyMalloc_New(PySliceObject, &PySlice_Type);
if (obj == NULL) if (obj == NULL)
return NULL; return NULL;
...@@ -115,7 +115,7 @@ slice_dealloc(PySliceObject *r) ...@@ -115,7 +115,7 @@ slice_dealloc(PySliceObject *r)
Py_DECREF(r->step); Py_DECREF(r->step);
Py_DECREF(r->start); Py_DECREF(r->start);
Py_DECREF(r->stop); Py_DECREF(r->stop);
PyObject_DEL(r); PyMalloc_Del(r);
} }
static PyObject * static PyObject *
......
...@@ -68,7 +68,7 @@ PyString_FromStringAndSize(const char *str, int size) ...@@ -68,7 +68,7 @@ PyString_FromStringAndSize(const char *str, int size)
/* PyObject_NewVar is inlined */ /* PyObject_NewVar is inlined */
op = (PyStringObject *) op = (PyStringObject *)
PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char)); _PyMalloc_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
if (op == NULL) if (op == NULL)
return PyErr_NoMemory(); return PyErr_NoMemory();
PyObject_INIT_VAR(op, &PyString_Type, size); PyObject_INIT_VAR(op, &PyString_Type, size);
...@@ -131,7 +131,7 @@ PyString_FromString(const char *str) ...@@ -131,7 +131,7 @@ PyString_FromString(const char *str)
/* PyObject_NewVar is inlined */ /* PyObject_NewVar is inlined */
op = (PyStringObject *) op = (PyStringObject *)
PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char)); _PyMalloc_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
if (op == NULL) if (op == NULL)
return PyErr_NoMemory(); return PyErr_NoMemory();
PyObject_INIT_VAR(op, &PyString_Type, size); PyObject_INIT_VAR(op, &PyString_Type, size);
...@@ -733,7 +733,7 @@ string_concat(register PyStringObject *a, register PyObject *bb) ...@@ -733,7 +733,7 @@ string_concat(register PyStringObject *a, register PyObject *bb)
size = a->ob_size + b->ob_size; size = a->ob_size + b->ob_size;
/* PyObject_NewVar is inlined */ /* PyObject_NewVar is inlined */
op = (PyStringObject *) op = (PyStringObject *)
PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char)); _PyMalloc_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
if (op == NULL) if (op == NULL)
return PyErr_NoMemory(); return PyErr_NoMemory();
PyObject_INIT_VAR(op, &PyString_Type, size); PyObject_INIT_VAR(op, &PyString_Type, size);
...@@ -780,7 +780,7 @@ string_repeat(register PyStringObject *a, register int n) ...@@ -780,7 +780,7 @@ string_repeat(register PyStringObject *a, register int n)
return NULL; return NULL;
} }
op = (PyStringObject *) op = (PyStringObject *)
PyObject_MALLOC(sizeof(PyStringObject) + nbytes); _PyMalloc_MALLOC(sizeof(PyStringObject) + nbytes);
if (op == NULL) if (op == NULL)
return PyErr_NoMemory(); return PyErr_NoMemory();
PyObject_INIT_VAR(op, &PyString_Type, size); PyObject_INIT_VAR(op, &PyString_Type, size);
...@@ -2789,7 +2789,7 @@ PyTypeObject PyString_Type = { ...@@ -2789,7 +2789,7 @@ PyTypeObject PyString_Type = {
0, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
string_new, /* tp_new */ string_new, /* tp_new */
_PyObject_Del, /* tp_free */ _PyMalloc_Del, /* tp_free */
}; };
void void
...@@ -2841,10 +2841,10 @@ _PyString_Resize(PyObject **pv, int newsize) ...@@ -2841,10 +2841,10 @@ _PyString_Resize(PyObject **pv, int newsize)
#endif #endif
_Py_ForgetReference(v); _Py_ForgetReference(v);
*pv = (PyObject *) *pv = (PyObject *)
PyObject_REALLOC((char *)v, _PyMalloc_REALLOC((char *)v,
sizeof(PyStringObject) + newsize * sizeof(char)); sizeof(PyStringObject) + newsize * sizeof(char));
if (*pv == NULL) { if (*pv == NULL) {
PyObject_DEL(v); PyMalloc_Del(v);
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
} }
......
...@@ -22,7 +22,7 @@ PyStructSequence_New(PyTypeObject *type) ...@@ -22,7 +22,7 @@ PyStructSequence_New(PyTypeObject *type)
{ {
PyStructSequence *obj; PyStructSequence *obj;
obj = PyObject_New(PyStructSequence, type); obj = PyMalloc_New(PyStructSequence, type);
obj->ob_size = VISIBLE_SIZE_TP(type); obj->ob_size = VISIBLE_SIZE_TP(type);
return (PyObject*) obj; return (PyObject*) obj;
...@@ -37,7 +37,7 @@ structseq_dealloc(PyStructSequence *obj) ...@@ -37,7 +37,7 @@ structseq_dealloc(PyStructSequence *obj)
for (i = 0; i < size; ++i) { for (i = 0; i < size; ++i) {
Py_XDECREF(obj->ob_item[i]); Py_XDECREF(obj->ob_item[i]);
} }
PyObject_FREE(obj); PyMalloc_Del(obj);
} }
static int static int
......
...@@ -201,7 +201,7 @@ PyUnicodeObject *_PyUnicode_New(int length) ...@@ -201,7 +201,7 @@ PyUnicodeObject *_PyUnicode_New(int length)
PyObject_INIT(unicode, &PyUnicode_Type); PyObject_INIT(unicode, &PyUnicode_Type);
} }
else { else {
unicode = PyObject_NEW(PyUnicodeObject, &PyUnicode_Type); unicode = PyMalloc_New(PyUnicodeObject, &PyUnicode_Type);
if (unicode == NULL) if (unicode == NULL)
return NULL; return NULL;
unicode->str = PyMem_NEW(Py_UNICODE, length + 1); unicode->str = PyMem_NEW(Py_UNICODE, length + 1);
...@@ -219,7 +219,7 @@ PyUnicodeObject *_PyUnicode_New(int length) ...@@ -219,7 +219,7 @@ PyUnicodeObject *_PyUnicode_New(int length)
onError: onError:
_Py_ForgetReference((PyObject *)unicode); _Py_ForgetReference((PyObject *)unicode);
PyObject_DEL(unicode); PyMalloc_Del(unicode);
return NULL; return NULL;
} }
...@@ -5711,7 +5711,7 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -5711,7 +5711,7 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
pnew->str = PyMem_NEW(Py_UNICODE, n+1); pnew->str = PyMem_NEW(Py_UNICODE, n+1);
if (pnew->str == NULL) { if (pnew->str == NULL) {
_Py_ForgetReference((PyObject *)pnew); _Py_ForgetReference((PyObject *)pnew);
PyObject_DEL(pnew); PyMalloc_Del(pnew);
return NULL; return NULL;
} }
Py_UNICODE_COPY(pnew->str, tmp->str, n+1); Py_UNICODE_COPY(pnew->str, tmp->str, n+1);
...@@ -5769,7 +5769,7 @@ PyTypeObject PyUnicode_Type = { ...@@ -5769,7 +5769,7 @@ PyTypeObject PyUnicode_Type = {
0, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
unicode_new, /* tp_new */ unicode_new, /* tp_new */
_PyObject_Del, /* tp_free */ _PyMalloc_Del, /* tp_free */
}; };
/* Initialize the Unicode implementation */ /* Initialize the Unicode implementation */
...@@ -5811,7 +5811,7 @@ _PyUnicode_Fini(void) ...@@ -5811,7 +5811,7 @@ _PyUnicode_Fini(void)
if (v->str) if (v->str)
PyMem_DEL(v->str); PyMem_DEL(v->str);
Py_XDECREF(v->defenc); Py_XDECREF(v->defenc);
PyObject_DEL(v); PyMalloc_Del(v);
} }
unicode_freelist = NULL; unicode_freelist = NULL;
unicode_freelist_size = 0; unicode_freelist_size = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment