@@ -16,14 +16,7 @@ typedef struct {
16
16
} OneDimensionalArray;
17
17
18
18
static void OneDimensionalArray_dealloc (OneDimensionalArray *self) {
19
- if (self->_data ) {
20
- for (size_t i = 0 ; i < self->_size ; i++) {
21
- Py_XDECREF (self->_data [i]);
22
- }
23
- std::free (self->_data );
24
- self->_data = nullptr ;
25
- }
26
- Py_XDECREF (self->_dtype );
19
+ std::free (self->_data );
27
20
Py_TYPE (self)->tp_free (reinterpret_cast <PyObject*>(self));
28
21
}
29
22
@@ -112,7 +105,7 @@ static PyObject* OneDimensionalArray___new__(PyTypeObject* type, PyObject *args,
112
105
return NULL ;
113
106
}
114
107
self->_size = size;
115
- self->_data = reinterpret_cast <PyObject**>(std::calloc (size, sizeof (PyObject*)));
108
+ self->_data = reinterpret_cast <PyObject**>(std::malloc (size * sizeof (PyObject*)));
116
109
if (!self->_data ) {
117
110
Py_DECREF (args0);
118
111
Py_DECREF (args1);
@@ -171,32 +164,26 @@ static PyObject* OneDimensionalArray___new__(PyTypeObject* type, PyObject *args,
171
164
if (!init) {
172
165
PyErr_Clear ();
173
166
init = Py_None;
174
- Py_INCREF (init);
175
167
}
176
168
}
177
169
}
178
170
if (!init) {
179
171
init = Py_None;
180
- Py_INCREF (init);
181
172
}
182
173
if (init != Py_None && raise_exception_if_dtype_mismatch (init, self->_dtype )) {
183
- Py_DECREF (init);
184
174
Py_DECREF (args0);
185
175
return NULL ;
186
176
}
187
- self->_data = reinterpret_cast <PyObject**>(std::calloc (self->_size , sizeof (PyObject*)));
177
+ self->_data = reinterpret_cast <PyObject**>(std::malloc (self->_size * sizeof (PyObject*)));
188
178
if (!self->_data ) {
189
- Py_DECREF (init);
190
179
Py_DECREF (args0);
191
180
PyErr_NoMemory ();
192
181
return NULL ;
193
182
}
194
183
195
184
for (size_t i = 0 ; i < self->_size ; i++) {
196
- Py_INCREF (init);
197
185
self->_data [i] = init;
198
186
}
199
- Py_DECREF (init);
200
187
201
188
} else if (PyList_Check (args0) || PyTuple_Check (args0)) {
202
189
Py_ssize_t size_ssize = PyObject_Length (args0);
@@ -205,7 +192,7 @@ static PyObject* OneDimensionalArray___new__(PyTypeObject* type, PyObject *args,
205
192
return NULL ;
206
193
}
207
194
self->_size = (size_t )size_ssize;
208
- self->_data = reinterpret_cast <PyObject**>(std::calloc (self->_size , sizeof (PyObject*)));
195
+ self->_data = reinterpret_cast <PyObject**>(std::malloc (self->_size * sizeof (PyObject*)));
209
196
if (!self->_data ) {
210
197
Py_DECREF (args0);
211
198
PyErr_NoMemory ();
@@ -320,7 +307,7 @@ static PyObject* OneDimensionalArray_fill(OneDimensionalArray *self, PyObject *a
320
307
return NULL ;
321
308
}
322
309
323
- PyObject* value = PyTuple_GetItem (args, 0 ); // Borrowed reference
310
+ PyObject* value = PyTuple_GetItem (args, 0 );
324
311
if (!value) return NULL ;
325
312
326
313
if (value != Py_None && raise_exception_if_dtype_mismatch (value, self->_dtype )) {
0 commit comments