From 916ec20a1c9bddafe7a23cda64aa0c01401046ca Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Fri, 27 Oct 2023 09:24:52 +0200 Subject: [PATCH] fixing warnings --- src/ClusterReader.c | 9 +++------ src/RawFileReader.c | 8 ++++---- src/cluster_reader.c | 39 ++++++++++++++++++++++----------------- src/cluster_reader.h | 4 ++-- src/raw_reader.c | 6 +++--- 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/ClusterReader.c b/src/ClusterReader.c index 5f8ad11..85d479d 100644 --- a/src/ClusterReader.c +++ b/src/ClusterReader.c @@ -6,7 +6,7 @@ //clang-format off typedef struct { PyObject_HEAD FILE *fp; - int n_left; + size_t n_left; Py_ssize_t chunk; } ClusterFileReader; //clang-format on @@ -18,7 +18,7 @@ static int ClusterFileReader_init(ClusterFileReader *self, PyObject *args, PyObject *kwds) { // Parse file name, accepts string or pathlike objects - const char *fname = NULL; + char *fname = NULL; self->n_left = 0; self->chunk = 0; PyObject *fname_obj = NULL; @@ -27,9 +27,6 @@ static int ClusterFileReader_init(ClusterFileReader *self, PyObject *args, static char *kwlist[] = {"fname", "chunk", NULL}; - // if (!PyArg_ParseTuple(args, "O&", PyUnicode_FSConverter, &buf)) - // return -1; - // PyBytes_AsStringAndSize(buf, &fname, &len); if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n", kwlist, &fname_obj, &self->chunk)) { @@ -45,7 +42,7 @@ static int ClusterFileReader_init(ClusterFileReader *self, PyObject *args, printf("Opening: %s\n chunk: %lu\n", fname, self->chunk); #endif - self->fp = fopen(fname, "rb"); + self->fp = fopen((const char*)fname, "rb"); // Keep the return code to not return before releasing buffer diff --git a/src/RawFileReader.c b/src/RawFileReader.c index 0b3084e..beaed49 100644 --- a/src/RawFileReader.c +++ b/src/RawFileReader.c @@ -22,7 +22,7 @@ static int RawFileReader_init(RawFileReader *self, PyObject *args, PyObject *kwds) { // Parse file name, accepts string or pathlike objects - const char *fname = NULL; + char *fname = NULL; PyObject *fname_obj = NULL; PyObject *fname_bytes = NULL; Py_ssize_t len; @@ -48,7 +48,7 @@ static int RawFileReader_init(RawFileReader *self, PyObject *args, printf("fname: %s\n read_header: %d detector type: %d\n", fname, self->read_header, self->detector); #endif - self->fp = fopen(fname, "rb"); + self->fp = fopen((const char*)fname, "rb"); // Keep the return code to not return before releasing buffer int rc = 0; @@ -110,12 +110,12 @@ static PyObject *RawFileReader_read(RawFileReader *self, PyObject *args) { switch (self->detector) { case DT_MOENCH_03: - n_read = read_raw_m03(self->fp, n_frames, out_buf, header_out); + n_read = read_raw_m03(self->fp, n_frames, out_buf, (Header*)header_out); break; case DT_MOENCH_04_A: case DT_MOENCH_04_AD: n_read = - read_raw_m04(self->fp, n_frames, out_buf, digital_out, header_out); + read_raw_m04(self->fp, n_frames, out_buf, digital_out, (Header*)header_out); break; default: break; diff --git a/src/cluster_reader.c b/src/cluster_reader.c index 7837482..6622e4e 100644 --- a/src/cluster_reader.c +++ b/src/cluster_reader.c @@ -1,9 +1,9 @@ #include "cluster_reader.h" #include -int read_clusters(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_left) { +size_t read_clusters(FILE *fp, size_t n_clusters, Cluster *buf, size_t *n_left) { int iframe = 0; - int nph = *n_left; + size_t nph = *n_left; size_t nph_read = 0; size_t nn = *n_left; @@ -44,23 +44,27 @@ int read_clusters(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_left) { return nph_read; } -int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf, - int *n_left, double *noise_map, int nx, int ny) { +size_t read_clusters_with_cut(FILE *fp, size_t n_clusters, Cluster *buf, + size_t *n_left, double *noise_map, int nx, int ny) { int iframe = 0; - int nph = *n_left; + size_t nph = *n_left; size_t nph_read = 0; - int32_t tot2[4], t2max, tot1; - int32_t val, tot3; + int32_t t2max, tot1; + int32_t tot3; Cluster *ptr = buf; int good = 1; double noise; // read photons left from previous frame if (nph) { - for (int iph = 0; iph < nph; iph++) { + for (size_t iph = 0; iph < nph; iph++) { // read photons 1 by 1 - fread((void *)(ptr), sizeof(Cluster), 1, fp); + size_t n_read = fread((void *)(ptr), sizeof(Cluster), 1, fp); + if (n_read != 1) { + return nph_read; + } + //TODO! error handling on read good = 1; if (noise_map) { if (ptr->x >= 0 && ptr->x < nx && ptr->y >= 0 && ptr->y < ny) { @@ -95,9 +99,12 @@ int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf, if (fread(&nph, sizeof(nph), 1, fp)) { //printf("** %d\n",nph); *n_left = nph; - for (int iph=0; iphx>=0 && ptr->xy>=0 && ptr->y