From f44fa558f2a7637830bf085e7913118f35200759 Mon Sep 17 00:00:00 2001 From: Dana Robinson <43805+derobins@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:25:06 -0700 Subject: [PATCH] Clean up off_t --> HDoff_t stragglers (#4555) * off_t --> HDoff_t in test * off_t --> HDoff_t in h5ls, h5dump, & h5repack * Minor off_t tweak to configure.ac * off_t --> HDoff_t fixes in src This changes the type of the offset parameter in H5Pget_external() to HDoff_t to match H5Pset_external(), along with other minor tweaks. * off_t --> HDoff_t in C++ wrappers * Fix off_t usage in Java wrapper --- c++/src/C2Cppfunction_map.htm | 4 +- c++/src/H5DcreatProp.cpp | 19 ++++--- c++/src/H5DcreatProp.h | 4 +- configure.ac | 4 +- java/src/jni/h5pDCPLImp.c | 8 +-- src/H5FDsubfiling/H5FDioc_threads.c | 6 +-- src/H5Fmodule.h | 3 +- src/H5Fquery.c | 10 ++-- src/H5Pdcpl.c | 81 +++++++++++++---------------- src/H5Ppublic.h | 15 ++++-- test/dsets.c | 2 +- test/external.c | 22 ++++---- test/external_env.c | 2 +- test/set_extent.c | 2 +- tools/lib/h5tools_dump.c | 2 +- tools/src/h5ls/h5ls.c | 2 +- tools/src/misc/h5repart.c | 63 ++++++++++------------ 17 files changed, 121 insertions(+), 128 deletions(-) diff --git a/c++/src/C2Cppfunction_map.htm b/c++/src/C2Cppfunction_map.htm index 665bc63f3a3..4ea67544efe 100644 --- a/c++/src/C2Cppfunction_map.htm +++ b/c++/src/C2Cppfunction_map.htm @@ -16851,7 +16851,7 @@ normal'>

void DSetCreatPropList::setExternal(const char* name, off_t offset, + normal'>void DSetCreatPropList::setExternal(const char* name, HDoff_t offset, hsize_t size)

void DSetCreatPropList::getExternal(unsigned idx, size_t name_size, - char* name, off_t& offset, hsize_t& size)

+ char* name, HDoff_t& offset, hsize_t& size)

slot[u].size; enc_size = H5VM_limit_enc_size(enc_value); assert(enc_size < 256); *(*pp)++ = (uint8_t)enc_size; UINT64ENCODE_VAR(*pp, enc_value, enc_size); - } /* end for */ - } /* end if */ + } + } /* Calculate size needed for encoding */ *size += (1 + H5VM_limit_enc_size((uint64_t)efl->nused)); @@ -1476,20 +1476,20 @@ H5P__dcrt_ext_file_list_enc(const void *value, void **_pp, size_t *size) *size += len; *size += (1 + H5VM_limit_enc_size((uint64_t)efl->slot[u].offset)); *size += (1 + H5VM_limit_enc_size((uint64_t)efl->slot[u].size)); - } /* end for */ + } FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__dcrt_ext_file_list_enc() */ /*------------------------------------------------------------------------- - * Function: H5P__dcrt_ext_file_list_dec + * Function: H5P__dcrt_ext_file_list_dec * - * Purpose: Callback routine which is called whenever the efl - * property in the dataset creation property list is - * decoded. + * Purpose: Callback routine which is called whenever the efl + * property in the dataset creation property list is + * decoded. * - * Return: Success: Non-negative - * Failure: Negative + * Return: Success: Non-negative + * Failure: Negative * *------------------------------------------------------------------------- */ @@ -1510,7 +1510,7 @@ H5P__dcrt_ext_file_list_dec(const void **_pp, void *_value) assert(*pp); assert(efl); HDcompile_assert(sizeof(size_t) <= sizeof(uint64_t)); - HDcompile_assert(sizeof(off_t) <= sizeof(uint64_t)); + HDcompile_assert(sizeof(HDoff_t) <= sizeof(uint64_t)); HDcompile_assert(sizeof(hsize_t) <= sizeof(uint64_t)); /* Set property to default value */ @@ -1533,7 +1533,7 @@ H5P__dcrt_ext_file_list_dec(const void **_pp, void *_value) efl->nalloc = na; efl->slot = x; - } /* end if */ + } /* Decode length of slot name */ enc_size = *(*pp)++; @@ -1545,13 +1545,13 @@ H5P__dcrt_ext_file_list_dec(const void **_pp, void *_value) efl->slot[u].name = H5MM_xstrdup((const char *)(*pp)); *pp += len; - /* decode offset */ + /* Decode offset */ enc_size = *(*pp)++; assert(enc_size < 256); UINT64DECODE_VAR(*pp, enc_value, enc_size); efl->slot[u].offset = (HDoff_t)enc_value; - /* decode size */ + /* Decode size */ enc_size = *(*pp)++; assert(enc_size < 256); UINT64DECODE_VAR(*pp, enc_value, enc_size); @@ -1559,7 +1559,7 @@ H5P__dcrt_ext_file_list_dec(const void **_pp, void *_value) efl->slot[u].name_offset = 0; /*not entered into heap yet*/ efl->nused++; - } /* end for */ + } done: FUNC_LEAVE_NOAPI(ret_value) @@ -2680,28 +2680,28 @@ done: } /* end H5Pget_external_count() */ /*------------------------------------------------------------------------- - * Function: H5Pget_external + * Function: H5Pget_external * - * Purpose: Returns information about an external file. External files - * are numbered from zero to N-1 where N is the value returned - * by H5Pget_external_count(). At most NAME_SIZE characters are - * copied into the NAME array. If the external file name is - * longer than NAME_SIZE with the null terminator, then the - * return value is not null terminated (similar to strncpy()). + * Purpose: Returns information about an external file. External files + * are numbered from zero to N-1 where N is the value returned + * by H5Pget_external_count(). At most NAME_SIZE characters are + * copied into the NAME array. If the external file name is + * longer than NAME_SIZE with the null terminator, then the + * return value is not null terminated (similar to strncpy()). * - * If NAME_SIZE is zero or NAME is the null pointer then the - * external file name is not returned. If OFFSET or SIZE are - * null pointers then the corresponding information is not - * returned. + * If NAME_SIZE is zero or NAME is the null pointer then the + * external file name is not returned. If OFFSET or SIZE are + * null pointers then the corresponding information is not + * returned. * * See Also: H5Pset_external() * - * Return: Non-negative on success/Negative on failure + * Return: Non-negative on success/Negative on failure * *------------------------------------------------------------------------- */ herr_t -H5Pget_external(hid_t plist_id, unsigned idx, size_t name_size, char *name /*out*/, off_t *offset /*out*/, +H5Pget_external(hid_t plist_id, unsigned idx, size_t name_size, char *name /*out*/, HDoff_t *offset /*out*/, hsize_t *size /*out*/) { H5O_efl_t efl; @@ -2724,17 +2724,8 @@ H5Pget_external(hid_t plist_id, unsigned idx, size_t name_size, char *name /*out /* Return values */ if (name_size > 0 && name) strncpy(name, efl.slot[idx].name, name_size); - /* XXX: Badness! - * - * The offset parameter is of type off_t and the offset field of H5O_efl_entry_t - * is HDoff_t which is a different type on Windows (off_t is a 32-bit long, - * HDoff_t is __int64, a 64-bit type). - * - * In a future API reboot, we'll either want to make this parameter a haddr_t - * or define a 64-bit HDF5-specific offset type that is platform-independent. - */ if (offset) - *offset = (off_t)efl.slot[idx].offset; + *offset = efl.slot[idx].offset; if (size) *size = efl.slot[idx].size; diff --git a/src/H5Ppublic.h b/src/H5Ppublic.h index 53a2c3bbfb6..724893484a2 100644 --- a/src/H5Ppublic.h +++ b/src/H5Ppublic.h @@ -6033,15 +6033,17 @@ H5_DLL herr_t H5Pget_dset_no_attrs_hint(hid_t dcpl_id, hbool_t *minimize); * are null pointers then the corresponding information is not * returned. * - * \note On Windows, off_t is typically a 32-bit signed long value, which - * limits the valid offset that can be returned to 2 GiB. + * \note In 1.14.x and earlier, the offset parameter was of type off_t, + * which is a 32-bit signed long value on Windows, which limited + * the valid offset that can be returned to 2 GiB. * + * \version 1.16.0 \p offset parameter type changed to HDoff_t from off_t. * \version 1.6.4 \p idx parameter type changed to unsigned. * \since 1.0.0 * */ H5_DLL herr_t H5Pget_external(hid_t plist_id, unsigned idx, size_t name_size, char *name /*out*/, - off_t *offset /*out*/, hsize_t *size /*out*/); + HDoff_t *offset /*out*/, hsize_t *size /*out*/); /** * \ingroup DCPL * @@ -6527,9 +6529,12 @@ H5_DLL herr_t H5Pset_dset_no_attrs_hint(hid_t dcpl_id, hbool_t minimize); * when H5Dwrite() is called to write data to it, the library * will create the file. * - * \note On Windows, off_t is typically a 32-bit signed long value, which - * limits the valid offset that can be set to 2 GiB. * + * \note In 1.14.x and earlier, the offset parameter was of type off_t, + * which is a 32-bit signed long value on Windows, which limited + * the valid offset that can be set to 2 GiB. + * + * \version 1.16.0 \p offset parameter type changed to HDoff_t from off_t. * \since 1.0.0 * */ diff --git a/test/dsets.c b/test/dsets.c index 90b15dc4134..1c418ea6713 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -7189,7 +7189,7 @@ test_copy_dcpl(hid_t file, hid_t fapl) TEST_ERROR; if (H5Premove_filter(dcpl, H5Z_FILTER_FLETCHER32) < 0) TEST_ERROR; - if (H5Pset_external(dcpl, COPY_DCPL_EXTFILE_NAME, (off_t)0, (hsize_t)(500 * 4096 * sizeof(int))) < 0) + if (H5Pset_external(dcpl, COPY_DCPL_EXTFILE_NAME, 0, (hsize_t)(500 * 4096 * sizeof(int))) < 0) TEST_ERROR; /* Create second dataset of contiguous layout with external storage */ diff --git a/test/external.c b/test/external.c index efd24fa225b..13c5dfd0705 100644 --- a/test/external.c +++ b/test/external.c @@ -97,7 +97,7 @@ test_non_extendible(hid_t file) hsize_t cur_size[1] = {100}; /* data space current size */ hsize_t max_size[1] = {100}; /* data space maximum size */ int n = 0; /* number of external files */ - off_t file_offset = 0; /* external file offset */ + HDoff_t file_offset = 0; /* external file offset */ hsize_t file_size = 0; /* sizeof external file segment */ haddr_t dset_addr = HADDR_UNDEF; /* address of dataset */ @@ -363,7 +363,7 @@ test_unlimited(hid_t file) hsize_t cur_size[1] = {100}; /* data space current size */ hsize_t max_size[1] = {H5S_UNLIMITED}; /* data space maximum size */ int n; /* number of external files */ - off_t file_offset; /* external file offset */ + HDoff_t file_offset; /* external file offset */ hsize_t file_size; /* sizeof external file segment */ TESTING("unlimited dataspace, unlimited external storage"); @@ -446,7 +446,7 @@ error: *------------------------------------------------------------------------- */ static int -add_external_files(hid_t dcpl_id, unsigned int n_external_files, off_t offset, hsize_t max_ext_size) +add_external_files(hid_t dcpl_id, unsigned int n_external_files, HDoff_t offset, hsize_t max_ext_size) { char exname[AEF_EXNAME_MAX_LEN + 1]; unsigned int i = 0; @@ -704,7 +704,7 @@ test_read_file_set(hid_t fapl) FAIL_STACK_ERROR; for (i = 0; i < N_EXT_FILES; i++) { snprintf(filename, sizeof(filename), "extern_%dr.raw", (int)i + 1); - if (H5Pset_external(dcpl, filename, (off_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0) + if (H5Pset_external(dcpl, filename, (HDoff_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0) FAIL_STACK_ERROR; } @@ -823,7 +823,7 @@ test_write_file_set(hid_t fapl) else size = H5F_UNLIMITED; - if (H5Pset_external(dcpl, filename, (off_t)(i * GARBAGE_PER_FILE), size) < 0) + if (H5Pset_external(dcpl, filename, (HDoff_t)(i * GARBAGE_PER_FILE), size) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -946,9 +946,9 @@ test_path_absolute(hid_t fapl) if (i == 1) snprintf(filename, sizeof(filename), "%s%sextern_%zur.raw", cwdpath + 2, H5_DIR_SEPS, i + 1); #endif - if (H5Pset_external(dcpl, filename, (off_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0) + if (H5Pset_external(dcpl, filename, (HDoff_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0) FAIL_STACK_ERROR; - } /* end for */ + } /* create the dataspace */ cur_size = TOTAL_SIZE; @@ -1036,9 +1036,9 @@ test_path_relative(hid_t fapl) FAIL_STACK_ERROR; for (i = 0; i < N_EXT_FILES; i++) { snprintf(filename, sizeof(filename), "extern_%dr.raw", (int)i + 1); - if (H5Pset_external(dcpl, filename, (off_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0) + if (H5Pset_external(dcpl, filename, (HDoff_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0) FAIL_STACK_ERROR; - } /* end for */ + } cur_size = TOTAL_SIZE; if ((space = H5Screate_simple(1, &cur_size, NULL)) < 0) @@ -1130,9 +1130,9 @@ test_path_relative_cwd(hid_t fapl) FAIL_STACK_ERROR; for (i = 0; i < N_EXT_FILES; i++) { snprintf(filename, sizeof(filename), "..%sextern_%dr.raw", H5_DIR_SEPS, (int)i + 1); - if (H5Pset_external(dcpl, filename, (off_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0) + if (H5Pset_external(dcpl, filename, (HDoff_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0) FAIL_STACK_ERROR; - } /* end for */ + } cur_size = TOTAL_SIZE; if ((space = H5Screate_simple(1, &cur_size, NULL)) < 0) diff --git a/test/external_env.c b/test/external_env.c index 6d6146aed8c..1f8ff20797c 100644 --- a/test/external_env.c +++ b/test/external_env.c @@ -68,7 +68,7 @@ test_path_env(hid_t fapl) FAIL_STACK_ERROR; for (i = 0; i < N_EXT_FILES; i++) { snprintf(filename, sizeof(filename), "..%sextern_env_%dr.raw", H5_DIR_SEPS, (int)i + 1); - if (H5Pset_external(dcpl, filename, (off_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0) + if (H5Pset_external(dcpl, filename, (HDoff_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0) FAIL_STACK_ERROR; } /* end for */ diff --git a/test/set_extent.c b/test/set_extent.c index 696ef96f36d..f5840f90f7b 100644 --- a/test/set_extent.c +++ b/test/set_extent.c @@ -1839,7 +1839,7 @@ test_external(hid_t fapl, bool use_select_io) { char name[256]; /*external file name */ - off_t file_offset; /*external file offset */ + HDoff_t file_offset; /*external file offset */ hsize_t file_size; /*sizeof external file segment */ if (H5Pget_external(dcpl, 0, sizeof(name), name, &file_offset, &file_size) < 0) diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c index 5a8c4017a48..cbfa8ac8b71 100644 --- a/tools/lib/h5tools_dump.c +++ b/tools/lib/h5tools_dump.c @@ -3144,7 +3144,7 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_context_t * H5D_layout_t stl = H5D_LAYOUT_ERROR; size_t ncols = 80; /* available output width */ size_t cd_nelmts; /* filter client number of values */ - off_t offset; /* offset of external file */ + HDoff_t offset; /* offset of external file */ char f_name[256]; /* filter name */ char name[256]; /* external or virtual file name */ hsize_t chsize[64]; /* chunk size in elements */ diff --git a/tools/src/h5ls/h5ls.c b/tools/src/h5ls/h5ls.c index bef90cf9061..ac3835564bf 100644 --- a/tools/src/h5ls/h5ls.c +++ b/tools/src/h5ls/h5ls.c @@ -1841,7 +1841,7 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name) size_t cd_num; /* filter client data counter */ char f_name[256]; /* filter/file name */ char s[64]; /* temporary string buffer */ - off_t f_offset; /* offset in external file */ + HDoff_t f_offset; /* offset in external file */ hsize_t f_size; /* bytes used in external file */ hsize_t total, used; /* total size or offset */ int ndims; /* dimensionality */ diff --git a/tools/src/misc/h5repart.c b/tools/src/misc/h5repart.c index 70f53c6d716..5d3fa04b514 100644 --- a/tools/src/misc/h5repart.c +++ b/tools/src/misc/h5repart.c @@ -65,28 +65,28 @@ usage(const char *progname) /*------------------------------------------------------------------------- * Function: get_size * - * Purpose: Reads a size option of the form `-XNS' where `X' is any - * letter, `N' is a multi-character positive decimal number, and - * `S' is an optional suffix letter in the set [GgMmk]. The - * option may also be split among two arguments as: `-X NS'. - * The input value of ARGNO is the argument number for the - * switch in the ARGV vector and ARGC is the number of entries - * in that vector. + * Purpose: Reads a size option of the form `-XNS' where `X' is any + * letter, `N' is a multi-character positive decimal number, and + * `S' is an optional suffix letter in the set [GgMmk]. The + * option may also be split among two arguments as: `-X NS'. + * The input value of ARGNO is the argument number for the + * switch in the ARGV vector and ARGC is the number of entries + * in that vector. * - * Return: Success: The value N multiplied according to the - * suffix S. On return ARGNO will be the number - * of the next argument to process. + * Return: Success: The value N multiplied according to the + * suffix S. On return ARGNO will be the number + * of the next argument to process. * - * Failure: Calls usage() which exits with a non-zero - * status. + * Failure: Calls usage() which exits with a non-zero + * status. * *------------------------------------------------------------------------- */ -static off_t +static HDoff_t get_size(const char *progname, int *argno, int argc, char *argv[]) { - off_t retval = -1; - char *suffix = NULL; + HDoff_t retval = -1; + char *suffix = NULL; if (isdigit((int)(argv[*argno][2]))) { retval = strtol(argv[*argno] + 2, &suffix, 10); @@ -126,13 +126,6 @@ get_size(const char *progname, int *argno, int argc, char *argv[]) /*------------------------------------------------------------------------- * Function: main - * - * Purpose: Split an hdf5 file - * - * Return: Success: - * - * Failure: - * *------------------------------------------------------------------------- */ H5_GCC_CLANG_DIAG_OFF("format-nonliteral") @@ -163,12 +156,12 @@ main(int argc, char *argv[]) int dst_is_family; /*is dst name a family name? */ int dst_membno = 0; /*destination member number */ - off_t left_overs = 0; /*amount of zeros left over */ - off_t src_offset = 0; /*offset in source member */ - off_t dst_offset = 0; /*offset in destination member */ - off_t src_size; /*source logical member size */ - off_t src_act_size; /*source actual member size */ - off_t dst_size = 1 GB; /*destination logical memb size */ + HDoff_t left_overs = 0; /*amount of zeros left over */ + HDoff_t src_offset = 0; /*offset in source member */ + HDoff_t dst_offset = 0; /*offset in destination member */ + HDoff_t src_size; /*source logical member size */ + HDoff_t src_act_size; /*source actual member size */ + HDoff_t dst_size = 1 GB; /*destination logical memb size */ hid_t fapl; /*file access property list */ hid_t file; hsize_t hdsize; /*destination logical memb size */ @@ -283,14 +276,14 @@ main(int argc, char *argv[]) */ n = blk_size; if (dst_is_family) - n = (size_t)MIN((off_t)n, dst_size - dst_offset); + n = (size_t)MIN((HDoff_t)n, dst_size - dst_offset); if (left_overs) { - n = (size_t)MIN((off_t)n, left_overs); - left_overs = left_overs - (off_t)n; + n = (size_t)MIN((HDoff_t)n, left_overs); + left_overs = left_overs - (HDoff_t)n; need_write = false; } else if (src_offset < src_act_size) { - n = (size_t)MIN((off_t)n, src_act_size - src_offset); + n = (size_t)MIN((HDoff_t)n, src_act_size - src_offset); if ((nio = HDread(src, buf, n)) < 0) { perror("read"); exit(EXIT_FAILURE); @@ -343,16 +336,16 @@ main(int argc, char *argv[]) * loop. The destination offset must be updated so we can fix * trailing holes. */ - src_offset = src_offset + (off_t)n; + src_offset = src_offset + (HDoff_t)n; if (src_offset == src_act_size) { HDclose(src); if (!src_is_family) { - dst_offset = dst_offset + (off_t)n; + dst_offset = dst_offset + (HDoff_t)n; break; } snprintf(src_name, NAMELEN, src_gen_name, ++src_membno); if ((src = HDopen(src_name, O_RDONLY)) < 0 && ENOENT == errno) { - dst_offset = dst_offset + (off_t)n; + dst_offset = dst_offset + (HDoff_t)n; break; } else if (src < 0) {