Skip to content

Commit

Permalink
off_t --> HDoff_t fixes in src
Browse files Browse the repository at this point in the history
This changes the type of the offset parameter in H5Pget_external()
to HDoff_t to match H5Pset_external(), along with other minor tweaks.
  • Loading branch information
derobins committed Jun 7, 2024
1 parent 9c14007 commit 233b4cc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 61 deletions.
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

0 comments on commit 233b4cc

Please sign in to comment.