mirror of
https://github.com/python/cpython.git
synced 2024-11-24 02:15:30 +08:00
Use pymalloc if it's enabled.
This commit is contained in:
parent
a1a9c51a3e
commit
dcc819a5c9
@ -829,7 +829,7 @@ _PyObject_GC_Malloc(PyTypeObject *tp, int nitems)
|
||||
const size_t basicsize = _PyObject_VAR_SIZE(tp, nitems);
|
||||
#ifdef WITH_CYCLE_GC
|
||||
const size_t nbytes = sizeof(PyGC_Head) + basicsize;
|
||||
PyGC_Head *g = PyObject_MALLOC(nbytes);
|
||||
PyGC_Head *g = _PyMalloc_MALLOC(nbytes);
|
||||
if (g == NULL)
|
||||
return (PyObject *)PyErr_NoMemory();
|
||||
g->gc.gc_next = NULL;
|
||||
@ -845,7 +845,7 @@ _PyObject_GC_Malloc(PyTypeObject *tp, int nitems)
|
||||
}
|
||||
op = FROM_GC(g);
|
||||
#else
|
||||
op = PyObject_MALLOC(basicsize);
|
||||
op = _PyMalloc_MALLOC(basicsize);
|
||||
if (op == NULL)
|
||||
return (PyObject *)PyErr_NoMemory();
|
||||
|
||||
@ -896,9 +896,9 @@ _PyObject_GC_Del(PyObject *op)
|
||||
if (allocated > 0) {
|
||||
allocated--;
|
||||
}
|
||||
PyObject_FREE(g);
|
||||
_PyMalloc_FREE(g);
|
||||
#else
|
||||
PyObject_FREE(op);
|
||||
_PyMalloc_FREE(op);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1914,7 +1914,7 @@ static PyObject *
|
||||
dictiter_new(dictobject *dict, binaryfunc select)
|
||||
{
|
||||
dictiterobject *di;
|
||||
di = PyObject_NEW(dictiterobject, &PyDictIter_Type);
|
||||
di = PyMalloc_New(dictiterobject, &PyDictIter_Type);
|
||||
if (di == NULL)
|
||||
return NULL;
|
||||
Py_INCREF(dict);
|
||||
@ -1929,7 +1929,7 @@ static void
|
||||
dictiter_dealloc(dictiterobject *di)
|
||||
{
|
||||
Py_DECREF(di->di_dict);
|
||||
PyObject_DEL(di);
|
||||
PyMalloc_Del(di);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -60,7 +60,7 @@ PyObject *
|
||||
PyRange_New(long start, long len, long step, int reps)
|
||||
{
|
||||
long totlen = -1;
|
||||
rangeobject *obj = PyObject_NEW(rangeobject, &PyRange_Type);
|
||||
rangeobject *obj = PyMalloc_New(rangeobject, &PyRange_Type);
|
||||
|
||||
if (obj == NULL)
|
||||
return NULL;
|
||||
@ -104,7 +104,7 @@ PyRange_New(long start, long len, long step, int reps)
|
||||
static void
|
||||
range_dealloc(rangeobject *r)
|
||||
{
|
||||
PyObject_DEL(r);
|
||||
PyMalloc_Del(r);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -60,7 +60,7 @@ PyObject _Py_EllipsisObject = {
|
||||
PyObject *
|
||||
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)
|
||||
return NULL;
|
||||
@ -115,7 +115,7 @@ slice_dealloc(PySliceObject *r)
|
||||
Py_DECREF(r->step);
|
||||
Py_DECREF(r->start);
|
||||
Py_DECREF(r->stop);
|
||||
PyObject_DEL(r);
|
||||
PyMalloc_Del(r);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -68,7 +68,7 @@ PyString_FromStringAndSize(const char *str, int size)
|
||||
|
||||
/* PyObject_NewVar is inlined */
|
||||
op = (PyStringObject *)
|
||||
PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
|
||||
_PyMalloc_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
|
||||
if (op == NULL)
|
||||
return PyErr_NoMemory();
|
||||
PyObject_INIT_VAR(op, &PyString_Type, size);
|
||||
@ -131,7 +131,7 @@ PyString_FromString(const char *str)
|
||||
|
||||
/* PyObject_NewVar is inlined */
|
||||
op = (PyStringObject *)
|
||||
PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
|
||||
_PyMalloc_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
|
||||
if (op == NULL)
|
||||
return PyErr_NoMemory();
|
||||
PyObject_INIT_VAR(op, &PyString_Type, size);
|
||||
@ -733,7 +733,7 @@ string_concat(register PyStringObject *a, register PyObject *bb)
|
||||
size = a->ob_size + b->ob_size;
|
||||
/* PyObject_NewVar is inlined */
|
||||
op = (PyStringObject *)
|
||||
PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
|
||||
_PyMalloc_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
|
||||
if (op == NULL)
|
||||
return PyErr_NoMemory();
|
||||
PyObject_INIT_VAR(op, &PyString_Type, size);
|
||||
@ -780,7 +780,7 @@ string_repeat(register PyStringObject *a, register int n)
|
||||
return NULL;
|
||||
}
|
||||
op = (PyStringObject *)
|
||||
PyObject_MALLOC(sizeof(PyStringObject) + nbytes);
|
||||
_PyMalloc_MALLOC(sizeof(PyStringObject) + nbytes);
|
||||
if (op == NULL)
|
||||
return PyErr_NoMemory();
|
||||
PyObject_INIT_VAR(op, &PyString_Type, size);
|
||||
@ -2789,7 +2789,7 @@ PyTypeObject PyString_Type = {
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
string_new, /* tp_new */
|
||||
_PyObject_Del, /* tp_free */
|
||||
_PyMalloc_Del, /* tp_free */
|
||||
};
|
||||
|
||||
void
|
||||
@ -2841,10 +2841,10 @@ _PyString_Resize(PyObject **pv, int newsize)
|
||||
#endif
|
||||
_Py_ForgetReference(v);
|
||||
*pv = (PyObject *)
|
||||
PyObject_REALLOC((char *)v,
|
||||
_PyMalloc_REALLOC((char *)v,
|
||||
sizeof(PyStringObject) + newsize * sizeof(char));
|
||||
if (*pv == NULL) {
|
||||
PyObject_DEL(v);
|
||||
PyMalloc_Del(v);
|
||||
PyErr_NoMemory();
|
||||
return -1;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ PyStructSequence_New(PyTypeObject *type)
|
||||
{
|
||||
PyStructSequence *obj;
|
||||
|
||||
obj = PyObject_New(PyStructSequence, type);
|
||||
obj = PyMalloc_New(PyStructSequence, type);
|
||||
obj->ob_size = VISIBLE_SIZE_TP(type);
|
||||
|
||||
return (PyObject*) obj;
|
||||
@ -37,7 +37,7 @@ structseq_dealloc(PyStructSequence *obj)
|
||||
for (i = 0; i < size; ++i) {
|
||||
Py_XDECREF(obj->ob_item[i]);
|
||||
}
|
||||
PyObject_FREE(obj);
|
||||
PyMalloc_Del(obj);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -201,7 +201,7 @@ PyUnicodeObject *_PyUnicode_New(int length)
|
||||
PyObject_INIT(unicode, &PyUnicode_Type);
|
||||
}
|
||||
else {
|
||||
unicode = PyObject_NEW(PyUnicodeObject, &PyUnicode_Type);
|
||||
unicode = PyMalloc_New(PyUnicodeObject, &PyUnicode_Type);
|
||||
if (unicode == NULL)
|
||||
return NULL;
|
||||
unicode->str = PyMem_NEW(Py_UNICODE, length + 1);
|
||||
@ -219,7 +219,7 @@ PyUnicodeObject *_PyUnicode_New(int length)
|
||||
|
||||
onError:
|
||||
_Py_ForgetReference((PyObject *)unicode);
|
||||
PyObject_DEL(unicode);
|
||||
PyMalloc_Del(unicode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -5711,7 +5711,7 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
pnew->str = PyMem_NEW(Py_UNICODE, n+1);
|
||||
if (pnew->str == NULL) {
|
||||
_Py_ForgetReference((PyObject *)pnew);
|
||||
PyObject_DEL(pnew);
|
||||
PyMalloc_Del(pnew);
|
||||
return NULL;
|
||||
}
|
||||
Py_UNICODE_COPY(pnew->str, tmp->str, n+1);
|
||||
@ -5769,7 +5769,7 @@ PyTypeObject PyUnicode_Type = {
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
unicode_new, /* tp_new */
|
||||
_PyObject_Del, /* tp_free */
|
||||
_PyMalloc_Del, /* tp_free */
|
||||
};
|
||||
|
||||
/* Initialize the Unicode implementation */
|
||||
@ -5811,7 +5811,7 @@ _PyUnicode_Fini(void)
|
||||
if (v->str)
|
||||
PyMem_DEL(v->str);
|
||||
Py_XDECREF(v->defenc);
|
||||
PyObject_DEL(v);
|
||||
PyMalloc_Del(v);
|
||||
}
|
||||
unicode_freelist = NULL;
|
||||
unicode_freelist_size = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user