summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2014-01-09 10:49:40 -0800
committerCharles Harris <charlesr.harris@gmail.com>2014-01-09 10:49:40 -0800
commit42c8ced9257869a3897d84e2d5da570ddbb5fc59 (patch)
treea11bf80bf0bceea749a7498a41268ce5681b48c7 /numpy
parente58dc055e99ee88fa8d77acc89269a2cdc6cf406 (diff)
parent6834b3a2da002eccc279a9e9a594713a467cc483 (diff)
downloadnumpy-42c8ced9257869a3897d84e2d5da570ddbb5fc59.tar.gz
Merge pull request #4177 from juliantaylor/objmalloc
ENH: replace a few small allocations with PyObject_Malloc
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/arrayobject.c2
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c2
-rw-r--r--numpy/core/src/multiarray/nditer_constr.c12
-rw-r--r--numpy/core/src/multiarray/scalartypes.c.src10
4 files changed, 12 insertions, 14 deletions
diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c
index b91e84366..e3ac1e0d0 100644
--- a/numpy/core/src/multiarray/arrayobject.c
+++ b/numpy/core/src/multiarray/arrayobject.c
@@ -1678,7 +1678,7 @@ static PyObject *
array_alloc(PyTypeObject *type, Py_ssize_t NPY_UNUSED(nitems))
{
/* nitems will always be 0 */
- PyObject *obj = PyArray_malloc(type->tp_basicsize);
+ PyObject *obj = PyObject_Malloc(type->tp_basicsize);
PyObject_Init(obj, type);
return obj;
}
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index df08495f8..23cb7e368 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -4017,7 +4017,7 @@ PyMODINIT_FUNC initmultiarray(void) {
if (!d) {
goto err;
}
- PyArray_Type.tp_free = PyArray_free;
+ PyArray_Type.tp_free = PyObject_Free;
if (PyType_Ready(&PyArray_Type) < 0) {
return RETVAL;
}
diff --git a/numpy/core/src/multiarray/nditer_constr.c b/numpy/core/src/multiarray/nditer_constr.c
index a12457a1e..964b51e22 100644
--- a/numpy/core/src/multiarray/nditer_constr.c
+++ b/numpy/core/src/multiarray/nditer_constr.c
@@ -194,7 +194,7 @@ NpyIter_AdvancedNew(int nop, PyArrayObject **op_in, npy_uint32 flags,
/* Allocate memory for the iterator */
iter = (NpyIter*)
- PyArray_malloc(NIT_SIZEOF_ITERATOR(itflags, ndim, nop));
+ PyObject_Malloc(NIT_SIZEOF_ITERATOR(itflags, ndim, nop));
NPY_IT_TIME_POINT(c_malloc);
@@ -217,7 +217,7 @@ NpyIter_AdvancedNew(int nop, PyArrayObject **op_in, npy_uint32 flags,
flags,
op_flags, op_itflags,
&NIT_MASKOP(iter))) {
- PyArray_free(iter);
+ PyObject_Free(iter);
return NULL;
}
/* Set resetindex to zero as well (it's just after the resetdataptr) */
@@ -549,7 +549,7 @@ NpyIter_Copy(NpyIter *iter)
/* Allocate memory for the new iterator */
size = NIT_SIZEOF_ITERATOR(itflags, ndim, nop);
- newiter = (NpyIter*)PyArray_malloc(size);
+ newiter = (NpyIter*)PyObject_Malloc(size);
/* Copy the raw values to the new iterator */
memcpy(newiter, iter, size);
@@ -664,9 +664,7 @@ NpyIter_Deallocate(NpyIter *iter)
/* buffers */
buffers = NBF_BUFFERS(bufferdata);
for(iop = 0; iop < nop; ++iop, ++buffers) {
- if (*buffers) {
- PyArray_free(*buffers);
- }
+ PyArray_free(*buffers);
}
/* read bufferdata */
transferdata = NBF_READTRANSFERDATA(bufferdata);
@@ -691,7 +689,7 @@ NpyIter_Deallocate(NpyIter *iter)
}
/* Deallocate the iterator memory */
- PyArray_free(iter);
+ PyObject_Free(iter);
return NPY_SUCCEED;
}
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
index 719dcfff9..8b7269676 100644
--- a/numpy/core/src/multiarray/scalartypes.c.src
+++ b/numpy/core/src/multiarray/scalartypes.c.src
@@ -111,7 +111,7 @@ gentype_alloc(PyTypeObject *type, Py_ssize_t nitems)
PyObject *obj;
const size_t size = _PyObject_VAR_SIZE(type, nitems + 1);
- obj = (PyObject *)PyArray_malloc(size);
+ obj = (PyObject *)PyObject_Malloc(size);
memset(obj, 0, size);
if (type->tp_itemsize == 0) {
PyObject_INIT(obj, type);
@@ -1540,7 +1540,7 @@ gentype_byteswap(PyObject *self, PyObject *args)
gentype_getreadbuf(self, 0, (void **)&data);
descr = PyArray_DescrFromScalar(self);
- newmem = PyArray_malloc(descr->elsize);
+ newmem = PyObject_Malloc(descr->elsize);
if (newmem == NULL) {
Py_DECREF(descr);
return PyErr_NoMemory();
@@ -1549,7 +1549,7 @@ gentype_byteswap(PyObject *self, PyObject *args)
descr->f->copyswap(newmem, data, 1, NULL);
}
new = PyArray_Scalar(newmem, descr, NULL);
- PyArray_free(newmem);
+ PyObject_Free(newmem);
Py_DECREF(descr);
return new;
}
@@ -3985,7 +3985,7 @@ initialize_numeric_types(void)
PyGenericArrType_Type.tp_getset = gentype_getsets;
PyGenericArrType_Type.tp_new = NULL;
PyGenericArrType_Type.tp_alloc = gentype_alloc;
- PyGenericArrType_Type.tp_free = PyArray_free;
+ PyGenericArrType_Type.tp_free = PyObject_Free;
PyGenericArrType_Type.tp_repr = gentype_repr;
PyGenericArrType_Type.tp_str = gentype_str;
PyGenericArrType_Type.tp_richcompare = gentype_richcompare;
@@ -4009,7 +4009,7 @@ initialize_numeric_types(void)
PyBoolArrType_Type.tp_as_number->nb_index = (unaryfunc)bool_index;
PyStringArrType_Type.tp_alloc = NULL;
- PyStringArrType_Type.tp_free = NULL;
+ PyStringArrType_Type.tp_free = PyObject_Free;
PyStringArrType_Type.tp_repr = stringtype_repr;
PyStringArrType_Type.tp_str = stringtype_str;