From 20d551a70bfaf40468dc4c41d3e55ebf99d3b631 Mon Sep 17 00:00:00 2001 From: q-posev Date: Thu, 6 May 2021 18:08:28 +0200 Subject: [PATCH] include inttypes to fix portability issues in text back end --- configure.ac | 6 +++--- src/templates_text/templator_text.org | 14 +++++++------- tools/generator.py | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 9e90985..ffc8572 100644 --- a/configure.ac +++ b/configure.ac @@ -40,7 +40,7 @@ AC_PROG_CC_C99 # Checks for basic libraries. AC_CHECK_LIB([m], [sqrt]) # Checks for basic header files. -AC_CHECK_HEADERS([fcntl.h stdint.h stdlib.h string.h unistd.h]) +AC_CHECK_HEADERS([fcntl.h inttypes.h stdint.h stdlib.h string.h unistd.h]) # Search for pthread have_pthreads=no @@ -154,8 +154,8 @@ AC_CHECK_FUNCS([memset mkdir strerror]) AC_CONFIG_FILES([Makefile src/Makefile - trexio.pc - tests/Makefile]) + tests/Makefile + trexio.pc]) AC_OUTPUT echo \ diff --git a/src/templates_text/templator_text.org b/src/templates_text/templator_text.org index 1619eeb..0737ec9 100644 --- a/src/templates_text/templator_text.org +++ b/src/templates_text/templator_text.org @@ -38,7 +38,7 @@ #include "trexio_private.h" #include "trexio_s.h" #include -#include +#include #include #include #include @@ -347,7 +347,7 @@ trexio_text_read_$group$ (trexio_text_t* const file) return NULL; } - rc = fscanf(f, "%lu\n", &($group$->dims_$group_dset$[i])); + rc = fscanf(f, "%" SCNu64 "\n", &($group$->dims_$group_dset$[i])); assert(!(rc != 1)); if (rc != 1) { FREE(buffer); @@ -373,7 +373,7 @@ trexio_text_read_$group$ (trexio_text_t* const file) return NULL; } - rc = fscanf(f, "%lu", &($group$->$group_num$)); + rc = fscanf(f, "%" SCNu64 "", &($group$->$group_num$)); assert(!(rc != 1)); if (rc != 1) { FREE(buffer); @@ -479,14 +479,14 @@ trexio_text_flush_$group$ (trexio_text_t* const file) if ($group$->rank_$group_dset$ != 0) size_$group_dset$ = 1; for (unsigned int i=0; i<$group$->rank_$group_dset$; ++i){ - fprintf(f, "dims_$group_dset$ %u %lu\n", i, $group$->dims_$group_dset$[i]); + fprintf(f, "dims_$group_dset$ %u %" PRIu64 "\n", i, $group$->dims_$group_dset$[i]); size_$group_dset$ *= $group$->dims_$group_dset$[i]; } // END REPEAT GROUP_DSET // START REPEAT GROUP_NUM - fprintf(f, "$group_num$ %lu\n", $group$->$group_num$); + fprintf(f, "$group_num$ %" PRIu64 "\n", $group$->$group_num$); // END REPEAT GROUP_NUM /* Write arrays */ @@ -758,7 +758,7 @@ rdm_t* trexio_text_read_rdm(trexio_text_t* const file) { assert (rc == 1); assert (strcmp(buffer, "dim_one_e") == 0); - rc = fscanf(f, "%lu", &(rdm->dim_one_e)); + rc = fscanf(f, "%" SCNu64 "", &(rdm->dim_one_e)); assert (rc == 1); /* Allocate arrays */ @@ -831,7 +831,7 @@ trexio_exit_code trexio_text_flush_rdm(trexio_text_t* const file) { fseek(f, 0L, SEEK_SET); /* Write the dimensioning variables */ - fprintf(f, "num %lu\n", rdm->dim_one_e); + fprintf(f, "num %" PRIu64 "\n", rdm->dim_one_e); /* Write arrays */ fprintf(f, "one_e\n"); diff --git a/tools/generator.py b/tools/generator.py index 3fd4501..1e004e3 100644 --- a/tools/generator.py +++ b/tools/generator.py @@ -151,8 +151,8 @@ for fname in files_funcs_groups: std_dtype_out = '24.16e' std_dtype_in = 'lf' elif params['dtype'] == 'int64_t': - std_dtype_out = 'ld' - std_dtype_in = 'ld' + std_dtype_out = '" PRId64 "' + std_dtype_in = '" SCNd64 "' templine1 = templine2.replace('$group_dset_std_dtype_out$', std_dtype_out) templine2 = templine1.replace('$group_dset_std_dtype_in$', std_dtype_in)