From 9f4176a8b6b7f995ae5cc9e7e8a5982ecb53372a Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 27 Jul 2021 11:06:06 +0200 Subject: [PATCH] resolve major compiler warnings produced by distutils --- src/setup.py | 2 +- src/templates_front/templator_front.org | 12 +++++++----- src/templates_text/templator_text.org | 9 ++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/setup.py b/src/setup.py index ca9335d..901902a 100644 --- a/src/setup.py +++ b/src/setup.py @@ -12,7 +12,7 @@ pytrexio_module = Extension('_pytrexio', include_dirs=['/usr/include/hdf5/serial'], #runtime_library_dirs=['/usr/lib/x86_64-linux-gnu/hdf5/serial'], libraries=['hdf5', 'hdf5_hl'], - #extra_compile_args=['-I/usr/include/hdf5/serial'], + extra_compile_args=['-Wno-discarded-qualifiers'], extra_link_args=['-L/usr/lib/x86_64-linux-gnu/hdf5/serial'] ) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index be10704..eafc103 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -545,6 +545,10 @@ trexio_open(const char* file_name, const char mode, result->mode = mode; result->one_based = false; // Need to be flipped in Fortran interface int irc = pthread_mutex_init ( &(result->thread_lock), NULL); + if (irc != 0) { + free(result); + return NULL; + } assert (irc == 0); trexio_exit_code rc; @@ -1717,7 +1721,7 @@ trexio_read_$group_dset$ (trexio_t* const file, char** dset_out, const uint32_t } char * pch; - for (uint64_t i=0; i < dset_dim; i++) { + for (uint64_t i=0; i < (uint64_t) dset_dim; i++) { pch = i == 0 ? strtok(str_compiled, TREXIO_DELIM) : strtok(NULL, TREXIO_DELIM) ; if (pch == NULL) { @@ -1777,7 +1781,7 @@ trexio_write_$group_dset$_low (trexio_t* const file, const char* dset_in, const return TREXIO_FAILURE; } - pch_len = strlen(pch); + pch_len = strlen(pch) + 1; if (pch_len > max_str_len) { FREE(dset_str[0]); @@ -1837,7 +1841,7 @@ trexio_write_$group_dset$ (trexio_t* const file, const char** dset_in, const uin if (str_compiled == NULL) return TREXIO_ALLOCATION_FAILED; strcpy(str_compiled, ""); - for (uint64_t i=0; i < dset_dim; i++) { + for (uint64_t i=0; i < (uint64_t) dset_dim; i++) { strcat(str_compiled, dset_in[i]); strcat(str_compiled, TREXIO_DELIM); } @@ -1994,8 +1998,6 @@ trexio_read_$group_str$ (trexio_t* const file, char* const str, const uint32_t m if (str == NULL) return TREXIO_INVALID_ARG_2; if (max_str_len <= 0) return TREXIO_INVALID_ARG_3; - trexio_exit_code rc = TREXIO_FAILURE; - switch (file->back_end) { case TREXIO_TEXT: diff --git a/src/templates_text/templator_text.org b/src/templates_text/templator_text.org index aee64ba..27e0af7 100644 --- a/src/templates_text/templator_text.org +++ b/src/templates_text/templator_text.org @@ -456,8 +456,6 @@ trexio_text_read_$group$ (trexio_text_t* const file) } // END REPEAT GROUP_DSET_NUM - size_t tmp_len; - // START REPEAT GROUP_DSET_STR /* Allocate arrays */ $group$->$group_dset$ = CALLOC(size_$group_dset$, $group_dset_dtype$); @@ -485,7 +483,8 @@ trexio_text_read_$group$ (trexio_text_t* const file) ,*/ char* tmp_$group_dset$; if(size_$group_dset$ != 0) tmp_$group_dset$ = CALLOC(size_$group_dset$*32, char); - tmp_len = 0; + + size_t tmp_$group_dset$_len = 0; for (uint64_t i=0 ; i$group_dset$[i] = tmp_$group_dset$; /* conventional fcanf with "%s" only return the string before the first space character @@ -501,8 +500,8 @@ trexio_text_read_$group$ (trexio_text_t* const file) return NULL; } - tmp_len = strlen($group$->$group_dset$[i]); - tmp_$group_dset$ += tmp_len + 1; + tmp_$group_dset$_len = strlen($group$->$group_dset$[i]); + tmp_$group_dset$ += tmp_$group_dset$_len + 1; } // END REPEAT GROUP_DSET_STR