From 59aa3afade89e18b7a3d3631cea46e2022a49e7e Mon Sep 17 00:00:00 2001 From: Jacob Smith Date: Sat, 28 Sep 2019 16:05:51 -0500 Subject: fix declaring variable in for statement --- test/external.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/external.c b/test/external.c index e2565de..4dc314a 100644 --- a/test/external.c +++ b/test/external.c @@ -447,13 +447,14 @@ test_unlimited(hid_t file) static int test_multiple_files(hid_t file) { - hid_t dcpl = -1; /* dataset creation properties */ - hid_t space = -1; /* dataspace */ - hid_t dset = -1; /* dataset */ - hsize_t cur_size[1] = {100}; /* data space current size */ - hsize_t max_size[1] = {100}; /* data space maximum size */ - hsize_t max_ext_size; /* maximum size of external files */ - unsigned n_external_files = 4; + hid_t dcpl = -1; /* dataset creation properties */ + hid_t space = -1; /* dataspace */ + hid_t dset = -1; /* dataset */ + hsize_t cur_size[1] = {100}; /* data space current size */ + hsize_t max_size[1] = {100}; /* data space maximum size */ + hsize_t max_ext_size; /* maximum size of external files */ + unsigned int n_external_files = 4; + unsigned int i = 0; TESTING("multiple external files"); @@ -462,7 +463,7 @@ test_multiple_files(hid_t file) max_ext_size = (hsize_t)(sizeof(int) * max_size[0] / n_external_files); - for (unsigned i = 0; i < n_external_files; i++) { + for (i = 0; i < n_external_files; i++) { char exname[9] = ""; HDsnprintf(exname, 9, "ext%d.data", i+1); if (H5Pset_external(dcpl, exname, (off_t)0, max_ext_size) < 0) { @@ -490,7 +491,7 @@ test_multiple_files(hid_t file) max_ext_size -= 1; - for (unsigned i = 0; i < n_external_files; i++) { + for (i = 0; i < n_external_files; i++) { char exname[9] = ""; HDsnprintf(exname, 9, "ext%d.data", i+1); if (H5Pset_external(dcpl, exname, (off_t)0, max_ext_size) < 0) { -- cgit v0.12 From 541f50616f5d5429f3c2a3aba467f99722291c1a Mon Sep 17 00:00:00 2001 From: Jacob Smith Date: Sun, 29 Sep 2019 18:52:55 -0500 Subject: Refactor external file addition loop to static function. --- test/external.c | 75 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/test/external.c b/test/external.c index 4dc314a..c33e10d 100644 --- a/test/external.c +++ b/test/external.c @@ -432,6 +432,58 @@ test_unlimited(hid_t file) /*------------------------------------------------------------------------- + * Function: __add_external_files + * + * Purpose: Add external file names to the DCPL with the given properties. + * Used in test_multiple_files(). + * Limit to no more than 999 external files. + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Jacob Smith + * 29 Sep 2019 + * + *------------------------------------------------------------------------- + */ +static int +__add_external_files( + hid_t dcpl_id, + unsigned int n_external_files, + off_t offset, + hsize_t max_ext_size) +{ +#define E_AEF_EXNAME_SIZE 12 + char exname[E_AEF_EXNAME_SIZE+1]; + unsigned int i = 0; + + if (dcpl_id < 0) { + return -1; + } + for (i = 0; i < n_external_files; i++) { + if (HDsnprintf( + exname, + E_AEF_EXNAME_SIZE, + "ext%d.data", + i+1) + > E_AEF_EXNAME_SIZE) + { + HDfprintf(stderr, "External file %d overflows name buffer\n", i+1); + fflush(stderr); + return -1; + } + if (H5Pset_external(dcpl_id, exname, offset, max_ext_size) < 0) { + HDfprintf(stderr, "Problem adding external file %s\n", exname); + fflush(stderr); + return -1; + } + } + return 0; +#undef E_AEF_EXNAME_SIZE +} /* end __add_external_files() */ + + +/*------------------------------------------------------------------------- * Function: test_multiple_files * * Purpose: Test multiple external files for a dataset. @@ -454,7 +506,6 @@ test_multiple_files(hid_t file) hsize_t max_size[1] = {100}; /* data space maximum size */ hsize_t max_ext_size; /* maximum size of external files */ unsigned int n_external_files = 4; - unsigned int i = 0; TESTING("multiple external files"); @@ -463,14 +514,8 @@ test_multiple_files(hid_t file) max_ext_size = (hsize_t)(sizeof(int) * max_size[0] / n_external_files); - for (i = 0; i < n_external_files; i++) { - char exname[9] = ""; - HDsnprintf(exname, 9, "ext%d.data", i+1); - if (H5Pset_external(dcpl, exname, (off_t)0, max_ext_size) < 0) { - HDfprintf(stderr, "Problem adding external file %s\n", exname); - fflush(stderr); - FAIL_STACK_ERROR - } + if (__add_external_files(dcpl, n_external_files, 0, max_ext_size) < 0) { + FAIL_STACK_ERROR; } if((space = H5Screate_simple(1, cur_size, max_size)) < 0) @@ -491,15 +536,9 @@ test_multiple_files(hid_t file) max_ext_size -= 1; - for (i = 0; i < n_external_files; i++) { - char exname[9] = ""; - HDsnprintf(exname, 9, "ext%d.data", i+1); - if (H5Pset_external(dcpl, exname, (off_t)0, max_ext_size) < 0) { - HDfprintf(stderr, "Problem adding external file %s\n", exname); - fflush(stderr); - FAIL_STACK_ERROR - } - } /* end for each external file */ + if (__add_external_files(dcpl, n_external_files, 0, max_ext_size) < 0) { + FAIL_STACK_ERROR; + } H5E_BEGIN_TRY { dset = H5Dcreate2(file, "dset7", H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT); -- cgit v0.12 From cab37f63144fd24d1ff39359e3d47a2c16198633 Mon Sep 17 00:00:00 2001 From: Jacob Smith Date: Mon, 30 Sep 2019 13:57:09 -0500 Subject: Move function-scope macro definition to file-scope. --- test/external.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/external.c b/test/external.c index c33e10d..4d9fef0 100644 --- a/test/external.c +++ b/test/external.c @@ -20,6 +20,9 @@ #include "external_common.h" #include "external_fname.h" +#define AEF_EXNAME_MAX_LEN 12 /* string buffer size for external file name */ + /* used in __add_external_files() */ + /*------------------------------------------------------------------------- * Function: files_have_same_contents @@ -453,8 +456,7 @@ __add_external_files( off_t offset, hsize_t max_ext_size) { -#define E_AEF_EXNAME_SIZE 12 - char exname[E_AEF_EXNAME_SIZE+1]; + char exname[AEF_EXNAME_MAX_LEN+1]; unsigned int i = 0; if (dcpl_id < 0) { @@ -463,10 +465,10 @@ __add_external_files( for (i = 0; i < n_external_files; i++) { if (HDsnprintf( exname, - E_AEF_EXNAME_SIZE, + AEF_EXNAME_MAX_LEN, "ext%d.data", i+1) - > E_AEF_EXNAME_SIZE) + > AEF_EXNAME_MAX_LEN) { HDfprintf(stderr, "External file %d overflows name buffer\n", i+1); fflush(stderr); @@ -479,7 +481,6 @@ __add_external_files( } } return 0; -#undef E_AEF_EXNAME_SIZE } /* end __add_external_files() */ -- cgit v0.12