Skip to content

Commit

Permalink
Clean up off_t --> HDoff_t stragglers (HDFGroup#4555)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
derobins authored and byrnHDF committed Jun 26, 2024
1 parent 3fc58a3 commit f2f78b0
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 128 deletions.
4 changes: 2 additions & 2 deletions c++/src/C2Cppfunction_map.htm
Original file line number Diff line number Diff line change
Expand Up @@ -16851,7 +16851,7 @@
mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt'>
<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'>void DSetCreatPropList::setExternal(const char* name, off_t offset,
normal'>void DSetCreatPropList::setExternal(const char* name, HDoff_t offset,
hsize_t size)</p>
</td>
<td width=35 valign=top style='width:26.05pt;border-top:none;border-left:
Expand Down Expand Up @@ -16925,7 +16925,7 @@
mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt'>
<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'>void DSetCreatPropList::getExternal(unsigned idx, size_t name_size,
char* name, off_t&amp; offset, hsize_t&amp; size)</p>
char* name, HDoff_t&amp; offset, hsize_t&amp; size)</p>
</td>
<td width=35 valign=top style='width:26.05pt;border-top:none;border-left:
none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
Expand Down
19 changes: 13 additions & 6 deletions c++/src/H5DcreatProp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,14 @@ DSetCreatPropList::setFletcher32() const
/// the total size is larger than the size of a dataset then the
/// dataset can be extended (provided the data space also allows
/// the extending).
///\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.
//--------------------------------------------------------------------------
void
DSetCreatPropList::setExternal(const char *name, off_t offset, hsize_t size) const
DSetCreatPropList::setExternal(const char *name, HDoff_t offset, hsize_t size) const
{
herr_t ret_value = H5Pset_external(id, name, offset, size);
if (ret_value < 0) {
Expand Down Expand Up @@ -695,11 +698,15 @@ DSetCreatPropList::getExternalCount() const
/// external file name will not be returned. If \a offset or
/// \a size are null pointers then the corresponding information
/// will not be 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.
//--------------------------------------------------------------------------
void
DSetCreatPropList::getExternal(unsigned idx, size_t name_size, char *name, off_t &offset, hsize_t &size) const
DSetCreatPropList::getExternal(unsigned idx, size_t name_size, char *name, HDoff_t &offset,
hsize_t &size) const
{
herr_t ret_value = H5Pget_external(id, idx, name_size, name, &offset, &size);
if (ret_value < 0) {
Expand Down
4 changes: 2 additions & 2 deletions c++/src/H5DcreatProp.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class H5_DLLCPP DSetCreatPropList : public ObjCreatPropList {
void setChunk(int ndims, const hsize_t *dim) const;

// Returns information about an external file.
void getExternal(unsigned idx, size_t name_size, char *name, off_t &offset, hsize_t &size) const;
void getExternal(unsigned idx, size_t name_size, char *name, HDoff_t &offset, hsize_t &size) const;

// Returns the number of external files for a dataset.
int getExternalCount() const;
Expand Down Expand Up @@ -101,7 +101,7 @@ class H5_DLLCPP DSetCreatPropList : public ObjCreatPropList {
void setDeflate(int level) const;

// Adds an external file to the list of external files.
void setExternal(const char *name, off_t offset, hsize_t size) const;
void setExternal(const char *name, HDoff_t offset, hsize_t size) const;

// Adds a filter to the filter pipeline.
void setFilter(H5Z_filter_t filter, unsigned int flags = 0, size_t cd_nelmts = 0,
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2575,8 +2575,8 @@ case "X-$ASSERTS" in
esac

## Incorporate the potentially warning-to-error promoting flags after
## feature tests. Some of the tests (e.g., `off_t`) generate compilation
## errors with the flags we chose for the HDF5 library and tools.
## feature tests. Some of the tests generate compilation errors with the
## flags we chose for the HDF5 library and tools.
##
H5_CFLAGS="$H5_CFLAGS $H5_ECFLAGS"
H5_CXXFLAGS="$H5_CXXFLAGS $H5_ECXXFLAGS"
Expand Down
8 changes: 4 additions & 4 deletions java/src/jni/h5pDCPLImp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ Java_hdf_hdf5lib_H5_H5Pset_1external(JNIEnv *env, jclass clss, jlong plist, jstr

PIN_JAVA_STRING(ENVONLY, name, fileName, NULL, "H5Pset_external: file name not pinned");

if ((status = H5Pset_external((hid_t)plist, fileName, (off_t)offset, (hsize_t)size)) < 0)
if ((status = H5Pset_external((hid_t)plist, fileName, (HDoff_t)offset, (hsize_t)size)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

done:
Expand All @@ -1083,7 +1083,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1external(JNIEnv *env, jclass clss, jlong plist, jint
jboolean isCopy;
jstring str;
hsize_t s;
off_t o;
HDoff_t o;
jsize arrLen;
jlong *theArray = NULL;
char *file = NULL;
Expand All @@ -1105,8 +1105,8 @@ Java_hdf_hdf5lib_H5_H5Pget_1external(JNIEnv *env, jclass clss, jlong plist, jint
if (NULL == (file = (char *)malloc(sizeof(char) * (size_t)name_size)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Pget_external: memory allocation failed");

if ((status = H5Pget_external((hid_t)plist, (unsigned)idx, (size_t)name_size, file, (off_t *)&o,
(hsize_t *)&s)) < 0)
if ((status = H5Pget_external((hid_t)plist, (unsigned)idx, (size_t)name_size, file, &o, (hsize_t *)&s)) <
0)
H5_LIBRARY_ERROR(ENVONLY);

if (NULL != size) {
Expand Down
6 changes: 3 additions & 3 deletions src/H5FDsubfiling/H5FDioc_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ ioc_file_write_data(int fd, int64_t file_offset, void *data_buffer, int64_t data
(void)ioc_idx;
#endif

HDcompile_assert(H5_SIZEOF_OFF_T == sizeof(file_offset));
HDcompile_assert(sizeof(HDoff_t) == sizeof(file_offset));

while (bytes_remaining) {
errno = 0;
Expand Down Expand Up @@ -1066,7 +1066,7 @@ ioc_file_read_data(int fd, int64_t file_offset, void *data_buffer, int64_t data_
(void)ioc_idx;
#endif

HDcompile_assert(H5_SIZEOF_OFF_T == sizeof(file_offset));
HDcompile_assert(sizeof(HDoff_t) == sizeof(file_offset));

while (bytes_remaining) {
errno = 0;
Expand Down Expand Up @@ -1146,7 +1146,7 @@ ioc_file_truncate(sf_work_request_t *msg)

fd = sf_context->sf_fids[subfile_idx];

if (HDftruncate(fd, (off_t)length) != 0)
if (HDftruncate(fd, (HDoff_t)length) != 0)
H5_SUBFILING_SYS_GOTO_ERROR(H5E_FILE, H5E_SEEKERROR, -1, "HDftruncate failed");

/*
Expand Down
3 changes: 1 addition & 2 deletions src/H5Fmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,7 @@
* access property list for each member of the file family. memb_size specifies the logical size, in
* bytes, of each family member. memb_size is used only when creating a new file or truncating an
* existing file; otherwise the member size is determined by the size of the first member of the
* family being opened. Note: If the size of the off_t type is four bytes, the maximum family
* member size is usually 2^31-1 because the byte at offset 2,147,483,647 is generally inaccessible.
* family being opened.
*
* #H5Pget_fapl_family is used to retrieve file family properties. If the file access property list is set
* to use the Family driver, member_properties will be returned with a pointer to a copy of the
Expand Down
10 changes: 4 additions & 6 deletions src/H5Fquery.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,8 @@ H5F_get_fcpl(const H5F_t *f)
/*-------------------------------------------------------------------------
* Function: H5F_sizeof_addr
*
* Purpose: Quick and dirty routine to retrieve the size of the file's size_t
* (Mainly added to stop non-file routines from poking about in the
* H5F_t data structure)
* Purpose: Quick and dirty routine to retrieve the size of the file's size
* of addresses
*
* Return: 'sizeof_addr' on success/abort on failure (shouldn't fail)
*-------------------------------------------------------------------------
Expand All @@ -394,9 +393,8 @@ H5F_sizeof_addr(const H5F_t *f)
/*-------------------------------------------------------------------------
* Function: H5F_sizeof_size
*
* Purpose: Quick and dirty routine to retrieve the size of the file's off_t
* (Mainly added to stop non-file routines from poking about in the
* H5F_t data structure)
* Purpose: Quick and dirty routine to retrieve the size of the file's size
* of sizes
*
* Return: 'sizeof_size' on success/abort on failure (shouldn't fail)
*-------------------------------------------------------------------------
Expand Down
81 changes: 36 additions & 45 deletions src/H5Pdcpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1400,14 +1400,14 @@ H5P__dcrt_ext_file_list_get(hid_t H5_ATTR_UNUSED prop_id, const char H5_ATTR_UNU
} /* end H5P__dcrt_ext_file_list_get() */

/*-------------------------------------------------------------------------
* Function: H5P__dcrt_ext_file_list_enc
* Function: H5P__dcrt_ext_file_list_enc
*
* Purpose: Callback routine which is called whenever the efl
* property in the dataset creation property list is
* encoded.
* Purpose: Callback routine which is called whenever the efl
* property in the dataset creation property list is
* encoded.
*
* Return: Success: Non-negative
* Failure: Negative
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
Expand All @@ -1426,7 +1426,7 @@ H5P__dcrt_ext_file_list_enc(const void *value, void **_pp, size_t *size)
/* Sanity check */
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));
assert(size);

Expand Down Expand Up @@ -1459,14 +1459,14 @@ H5P__dcrt_ext_file_list_enc(const void *value, void **_pp, size_t *size)
*(*pp)++ = (uint8_t)enc_size;
UINT64ENCODE_VAR(*pp, enc_value, enc_size);

/* encode size */
/* Encode size */
enc_value = (uint64_t)efl->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));
Expand All @@ -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
*
*-------------------------------------------------------------------------
*/
Expand All @@ -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 */
Expand All @@ -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)++;
Expand All @@ -1545,21 +1545,21 @@ 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);
efl->slot[u].size = (hsize_t)enc_value;

efl->slot[u].name_offset = 0; /*not entered into heap yet*/
efl->nused++;
} /* end for */
}

done:
FUNC_LEAVE_NOAPI(ret_value)
Expand Down Expand Up @@ -2680,28 +2680,28 @@ H5Pget_external_count(hid_t plist_id)
} /* 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;
Expand All @@ -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;

Expand Down
15 changes: 10 additions & 5 deletions src/H5Ppublic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
*/
Expand Down
2 changes: 1 addition & 1 deletion test/dsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Loading

0 comments on commit f2f78b0

Please sign in to comment.