If you want to fork this repository to propose merge requests, please send an email to tiago@skewed.de, and your project limit will be raised.

Commit 5f1c1364 authored by Tiago Peixoto's avatar Tiago Peixoto

numpy_bind.hh: Replace new with malloc

Numpy will use free() not delete, so we need to use malloc to avoid a

This fixes issue #579.
parent 803bf8ba
Pipeline #467 canceled with stage
......@@ -75,7 +75,7 @@ boost::python::object wrap_vector_owned(const std::vector<ValueType>& vec)
ValueType* new_data = new ValueType[vec.size()];
ValueType* new_data = (ValueType*) malloc(sizeof(ValueType) * vec.size());
memcpy(new_data, vec.data(), vec.size() * sizeof(ValueType));
ndarray = (PyArrayObject*) PyArray_SimpleNewFromData(1, size, val_type,
......@@ -118,7 +118,7 @@ boost::python::object wrap_vector_owned(const std::vector<std::array<ValueType,
ValueType* new_data = new ValueType[n];
ValueType* new_data = (ValueType*) malloc(sizeof(ValueType) * n);
memcpy(new_data, vec.data(), n * sizeof(ValueType));
npy_intp shape[2] = {int(vec.size()), int(Dim)};
ndarray = (PyArrayObject*) PyArray_SimpleNewFromData(Dim, shape,
......@@ -153,7 +153,8 @@ template <class ValueType, size_t Dim>
wrap_multi_array_owned(const boost::multi_array<ValueType,Dim>& array)
ValueType* new_data = new ValueType[array.num_elements()];
ValueType* new_data =
(ValueType*) malloc(sizeof(ValueType) * array.num_elements());
memcpy(new_data, array.data(), array.num_elements() * sizeof(ValueType));
size_t val_type = boost::mpl::at<numpy_types,ValueType>::type::value;
npy_intp shape[Dim];
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment