diff --git a/piconumpy/_piconumpy_cpython_capi.c b/piconumpy/_piconumpy_cpython_capi.c index a9b0246..f13f579 100644 --- a/piconumpy/_piconumpy_cpython_capi.c +++ b/piconumpy/_piconumpy_cpython_capi.c @@ -31,8 +31,10 @@ static int Array_init(ArrayObject *self, PyObject *args, PyObject *kwds) { self->size = (int)PyList_Size(data); self->data = (double *)malloc(self->size * sizeof(double)); - if (self->data == NULL) - return PyErr_NoMemory(); + if (self->data == NULL) { + PyErr_NoMemory(); + return -1; + } for (index = 0; index < self->size; index++) { item = PyList_GET_ITEM(data, index); @@ -63,15 +65,15 @@ static ArrayObject *Array_empty(int size); static ArrayObject *Array_multiply(PyObject *o1, PyObject *o2) { int index; double number; - PyObject *obj_number; - ArrayObject *result = NULL, *arr; + PyObject *obj_number = NULL; + ArrayObject *result = NULL, *arr = NULL; if (PyNumber_Check(o2)) { obj_number = o2; - arr = o1; + arr = (ArrayObject *)o1; } else if (PyNumber_Check(o1)) { obj_number = o1; - arr = o2; + arr = (ArrayObject *)o2; } if (PyNumber_Check(o1) | PyNumber_Check(o2)) { @@ -88,8 +90,8 @@ static ArrayObject *Array_multiply(PyObject *o1, PyObject *o2) { static ArrayObject *Array_add(PyObject *o1, PyObject *o2) { int index; ArrayObject *result = NULL, *a1, *a2; - a1 = o1; - a2 = o2; + a1 = (ArrayObject *)o1; + a2 = (ArrayObject *)o2; if (a1->size != a2->size) return result; @@ -110,7 +112,7 @@ static ArrayObject *Array_divide(PyObject *o1, PyObject *o2) { if (!PyNumber_Check(o2)) { return result; } - a1 = o1; + a1 = (ArrayObject *)o1; number = PyFloat_AsDouble(o2); result = Array_empty(a1->size); for (index = 0; index < a1->size; index++) { @@ -125,9 +127,9 @@ Py_ssize_t Array_length(ArrayObject *arr) { return result; }; -PyFloatObject *Array_item(ArrayObject *arr, Py_ssize_t index) { - PyFloatObject *item = NULL; - if (index < 0 | index >= arr->size) { +PyObject *Array_item(ArrayObject *arr, Py_ssize_t index) { + PyObject *item = NULL; + if (index < 0 || index >= arr->size) { return item; } item = PyFloat_FromDouble(arr->data[index]); @@ -140,7 +142,7 @@ static PyMethodDef Array_methods[] = { {NULL} /* Sentinel */ }; -static const PyType_Slot Array_type_slots[] = { +static PyType_Slot Array_type_slots[] = { {Py_tp_new, PyType_GenericNew}, {Py_tp_init, (initproc)Array_init}, {Py_tp_dealloc, (destructor)Array_dealloc}, @@ -154,7 +156,7 @@ static const PyType_Slot Array_type_slots[] = { {0, NULL}, }; -static const PyType_Spec Array_type_spec = { +static PyType_Spec Array_type_spec = { .name = "_piconumpy_cpython_capi.array", .basicsize = sizeof(ArrayObject), .itemsize = 0, @@ -169,8 +171,10 @@ static ArrayObject *Array_empty(int size) { new_array = PyObject_New(ArrayObject, ptr_ArrayType); new_array->size = size; new_array->data = (double *)malloc(size * sizeof(double)); - if (new_array->data == NULL) - return PyErr_NoMemory(); + if (new_array->data == NULL) { + PyErr_NoMemory(); + return NULL; + } return new_array; }; diff --git a/setup.py b/setup.py index 2b00af7..64f67ca 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,10 @@ Extension( "piconumpy._piconumpy_cpython_capi", ["piconumpy/_piconumpy_cpython_capi.c"], + extra_compile_args = [ + '-Wfatal-errors', # stop after one error (unrelated to warnings) + '-Werror', # turn warnings into errors (all, for now) + ] ), *cythonize("piconumpy/_piconumpy_cython.pyx"), ],