Skip to content

Commit

Permalink
Merge pull request #3 in ~VCHOI/my_third_fork from develop to bugfix/…
Browse files Browse the repository at this point in the history
…HDFFV-10579-h5arename-function-fails-when

* commit '52276f3713eec584044bc72d4724507848cfeba0':
  Modifications based on PR feedback: (1) Add H5Sdeprec.c to src/CMakeLists.txt (2) Add test for H5Sencode1.
  Modification for num_elem based on PR feedback.
  HDFFV-10365: Changes as described in the RFC: H5Sencode/H5Sdecode Format Change. This also addresses HDFFV-10255: H5Sencode/decode performance issue.
  • Loading branch information
vchoi-hdfgroup committed Apr 12, 2019
2 parents 74677ba + 52276f3 commit 66184e5
Show file tree
Hide file tree
Showing 29 changed files with 2,701 additions and 775 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@
./src/H5S.c
./src/H5Sall.c
./src/H5Sdbg.c
./src/H5Sdeprec.c
./src/H5Shyper.c
./src/H5Smodule.h
./src/H5Smpio.c
Expand Down
6 changes: 3 additions & 3 deletions fortran/src/H5Sf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ h5sdecode_c ( _fcd buf, hid_t_f *obj_id )
*/

int_f
h5sencode_c (_fcd buf, hid_t_f *obj_id, size_t_f *nalloc )
h5sencode_c (_fcd buf, hid_t_f *obj_id, size_t_f *nalloc, hid_t_f *fapl_id )
/******/
{
int ret_value = -1;
Expand All @@ -1162,7 +1162,7 @@ h5sencode_c (_fcd buf, hid_t_f *obj_id, size_t_f *nalloc )

if (*nalloc == 0) {

if(H5Sencode((hid_t)*obj_id, c_buf, &c_size) < 0)
if(H5Sencode2((hid_t)*obj_id, c_buf, &c_size, (hid_t)*fapl_id) < 0)
return ret_value;

*nalloc = (size_t_f)c_size;
Expand All @@ -1180,7 +1180,7 @@ h5sencode_c (_fcd buf, hid_t_f *obj_id, size_t_f *nalloc )
/*
* Call H5Sencode function.
*/
if(H5Sencode((hid_t)*obj_id, c_buf, &c_size) < 0){
if(H5Sencode2((hid_t)*obj_id, c_buf, &c_size, (hid_t)*fapl_id) < 0){
return ret_value;
}

Expand Down
13 changes: 10 additions & 3 deletions fortran/src/H5Sff.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1379,25 +1379,32 @@ END SUBROUTINE h5sdecode_f
! M. Scot Breitenfeld
! March 26, 2008
! SOURCE
SUBROUTINE h5sencode_f(obj_id, buf, nalloc, hdferr)
SUBROUTINE h5sencode_f(obj_id, buf, nalloc, hdferr, fapl_id)
IMPLICIT NONE
INTEGER(HID_T), INTENT(IN) :: obj_id
CHARACTER(LEN=*), INTENT(OUT) :: buf
INTEGER(SIZE_T), INTENT(INOUT) :: nalloc
INTEGER, INTENT(OUT) :: hdferr
INTEGER(HID_T), OPTIONAL, INTENT(IN) :: fapl_id ! File access property list
!*****
INTEGER(HID_T) :: fapl_id_default

INTERFACE
INTEGER FUNCTION h5sencode_c(buf, obj_id, nalloc) BIND(C,NAME='h5sencode_c')
INTEGER FUNCTION h5sencode_c(buf, obj_id, nalloc, fapl_id_default) BIND(C,NAME='h5sencode_c')
IMPORT :: C_CHAR
IMPORT :: HID_T, SIZE_T
INTEGER(HID_T), INTENT(IN) :: obj_id
CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(OUT) :: buf
INTEGER(SIZE_T), INTENT(INOUT) :: nalloc
INTEGER(HID_T) :: fapl_id_default
END FUNCTION h5sencode_c
END INTERFACE

hdferr = h5sencode_c(buf, obj_id, nalloc)
fapl_id_default = H5P_DEFAULT_F

IF(PRESENT(fapl_id)) fapl_id_default = fapl_id

hdferr = h5sencode_c(buf, obj_id, nalloc, fapl_id_default)

END SUBROUTINE h5sencode_f

Expand Down
2 changes: 1 addition & 1 deletion fortran/src/H5f90proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ H5_FCDLL int_f h5sselect_hyperslab_c( hid_t_f *space_id , int_f *op, hsize_t_f *
H5_FCDLL int_f h5sget_select_type_c( hid_t_f *space_id , int_f *op);
H5_FCDLL int_f h5sselect_elements_c( hid_t_f *space_id , int_f *op, size_t_f *nelements, hsize_t_f *coord);
H5_FCDLL int_f h5sdecode_c( _fcd buf, hid_t_f *obj_id );
H5_FCDLL int_f h5sencode_c(_fcd buf, hid_t_f *obj_id, size_t_f *nalloc );
H5_FCDLL int_f h5sencode_c(_fcd buf, hid_t_f *obj_id, size_t_f *nalloc, hid_t_f *fapl_id );
H5_FCDLL int_f h5sextent_equal_c( hid_t_f * space1_id, hid_t_f *space2_id, hid_t_f *c_equal);

/*
Expand Down
33 changes: 26 additions & 7 deletions fortran/test/tH5MISC_1_8.F90
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ SUBROUTINE test_h5s_encode(total_error)

INTEGER(hid_t) :: sid1, sid3! Dataspace ID
INTEGER(hid_t) :: decoded_sid1, decoded_sid3
INTEGER(hid_t) :: fapl ! File access property
INTEGER :: rank ! LOGICAL rank of dataspace
INTEGER(size_t) :: sbuf_size=0, scalar_size=0
INTEGER(size_t) :: new_size = 0, old_size = 0, orig_size=0, scalar_size=0

! Make sure the size is large
CHARACTER(LEN=288) :: sbuf
Expand Down Expand Up @@ -228,18 +229,36 @@ SUBROUTINE test_h5s_encode(total_error)

! Encode simple data space in a buffer

! First find the buffer size
CALL H5Sencode_f(sid1, sbuf, sbuf_size, error)
CALL check("H5Sencode", error, total_error)
! Find the buffer size without fapl
CALL H5Sencode_f(sid1, sbuf, orig_size, error)
CALL check("H5Sencode_f", error, total_error)
CALL verify("H5Sencode_f", INT(orig_size), 279, total_error)

! Create file access property list
CALL h5pcreate_f(H5P_FILE_ACCESS_F, fapl, error)
CALL check("h5pcreate_f", error, total_error)

! Find the buffer size with fapl (default old format)
CALL H5Sencode_f(sid1, sbuf, old_size, error, fapl)
CALL check("H5Sencode_f", error, total_error)
CALL verify("H5Sencode_f", INT(old_size), 279, total_error)

! Set fapl to latest file format
CALL H5Pset_libver_bounds_f(fapl, H5F_LIBVER_LATEST_F, H5F_LIBVER_LATEST_F, error)
CALL check("H5Pset_libver_bounds_f",error, total_error)

! Try decoding bogus buffer
! Find the buffer size with fapl set to latest format
CALL H5Sencode_f(sid1, sbuf, new_size, error, fapl)
CALL check("H5Sencode_f", error, total_error)
CALL verify("H5Sencode_f", INT(new_size), 101, total_error)

! Try decoding bogus buffer
CALL H5Sdecode_f(sbuf, decoded_sid1, error)
CALL verify("H5Sdecode", error, -1, total_error)

CALL H5Sencode_f(sid1, sbuf, sbuf_size, error)
CALL check("H5Sencode", error, total_error)
! Encode according to the latest file format
CALL H5Sencode_f(sid1, sbuf, new_size, error, fapl)
CALL check("H5Sencode_f", error, total_error)

! Decode from the dataspace buffer and return an object handle
CALL H5Sdecode_f(sbuf, decoded_sid1, error)
Expand Down
4 changes: 2 additions & 2 deletions java/src/jni/h5sImp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ Java_hdf_hdf5lib_H5_H5Sencode
if (obj_id < 0)
H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sencode: invalid object ID");

if ((status = H5Sencode(obj_id, NULL, &buf_size)) < 0)
if ((status = H5Sencode2(obj_id, NULL, &buf_size, H5P_DEFAULT)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

if (buf_size == 0)
Expand All @@ -1150,7 +1150,7 @@ Java_hdf_hdf5lib_H5_H5Sencode
if (NULL == (bufPtr = (unsigned char *) HDcalloc((size_t) 1, buf_size)))
H5_JNI_FATAL_ERROR(ENVONLY, "H5Sencode: failed to allocate encoding buffer");

if ((status = H5Sencode((hid_t) obj_id, bufPtr, &buf_size)) < 0)
if ((status = H5Sencode2((hid_t) obj_id, bufPtr, &buf_size, H5P_DEFAULT)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

if (NULL == (returnedArray = ENVPTR->NewByteArray(ENVONLY, (jsize) buf_size)))
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ set (H5S_SOURCES
${HDF5_SRC_DIR}/H5S.c
${HDF5_SRC_DIR}/H5Sall.c
${HDF5_SRC_DIR}/H5Sdbg.c
${HDF5_SRC_DIR}/H5Sdeprec.c
${HDF5_SRC_DIR}/H5Shyper.c
${HDF5_SRC_DIR}/H5Smpio.c
${HDF5_SRC_DIR}/H5Snone.c
Expand Down
3 changes: 3 additions & 0 deletions src/H5Dmpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2742,6 +2742,9 @@ H5D__chunk_redistribute_shared_chunks(const H5D_io_info_t *io_info, const H5D_ty
if ((mpi_size = H5F_mpi_get_size(io_info->dset->oloc.file)) < 0)
HGOTO_ERROR(H5E_IO, H5E_MPI, FAIL, "unable to obtain mpi size")

/* Set to latest format for encoding dataspace */
H5CX_set_libver_bounds(NULL);

if (*local_chunk_array_num_entries)
if (NULL == (send_requests = (MPI_Request *) H5MM_malloc(*local_chunk_array_num_entries * sizeof(MPI_Request))))
HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "couldn't allocate send requests buffer")
Expand Down
4 changes: 4 additions & 0 deletions src/H5Dvirtual.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ H5D__virtual_store_layout(H5F_t *f, H5O_layout_t *layout)

/* Create block if # of used entries > 0 */
if(layout->storage.u.virt.list_nused > 0) {

/* Set the low/high bounds according to 'f' for the API context */
H5CX_set_libver_bounds(f);

/* Allocate array for caching results of strlen */
if(NULL == (str_size = (size_t *)H5MM_malloc(2 * layout->storage.u.virt.list_nused * sizeof(size_t))))
HGOTO_ERROR(H5E_OHDR, H5E_RESOURCE, FAIL, "unable to allocate string length array")
Expand Down
19 changes: 13 additions & 6 deletions src/H5P.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,14 +817,17 @@ H5Pget_size(hid_t id, const char *name, size_t *size)

/*--------------------------------------------------------------------------
NAME
H5Pencode
H5Pencode2
PURPOSE
Routine to convert the property values in a property list into a binary buffer
Routine to convert the property values in a property list into a binary buffer.
The encoding of property values will be done according to the file format
setting in fapl_id.
USAGE
herr_t H5Pencode(plist_id, buf, nalloc)
herr_t H5Pencode(plist_id, buf, nalloc, fapl_id)
hid_t plist_id; IN: Identifier to property list to encode
void *buf: OUT: buffer to gold the encoded plist
size_t *nalloc; IN/OUT: size of buffer needed to encode plist
hid_t fapl_id; IN: File access property list ID
RETURNS
Returns non-negative on success, negative on failure.
DESCRIPTION
Expand All @@ -837,25 +840,29 @@ H5Pget_size(hid_t id, const char *name, size_t *size)
REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5Pencode(hid_t plist_id, void *buf, size_t *nalloc)
H5Pencode2(hid_t plist_id, void *buf, size_t *nalloc, hid_t fapl_id)
{
H5P_genplist_t *plist; /* Property list to query */
herr_t ret_value = SUCCEED; /* return value */

FUNC_ENTER_API(FAIL)
H5TRACE3("e", "i*x*z", plist_id, buf, nalloc);
H5TRACE4("e", "i*x*zi", plist_id, buf, nalloc, fapl_id);

/* Check arguments. */
if(NULL == (plist = (H5P_genplist_t *)H5I_object_verify(plist_id, H5I_GENPROP_LST)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list");

/* Verify access property list and set up collective metadata if appropriate */
if(H5CX_set_apl(&fapl_id, H5P_CLS_FACC, H5I_INVALID_HID, TRUE) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info")

/* Call the internal encode routine */
if((ret_value = H5P__encode(plist, TRUE, buf, nalloc)) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTENCODE, FAIL, "unable to encode property list");

done:
FUNC_LEAVE_API(ret_value)
} /* H5Pencode() */
} /* H5Pencode2() */


/*--------------------------------------------------------------------------
Expand Down
48 changes: 48 additions & 0 deletions src/H5Pdeprec.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,54 @@ H5Pget_version(hid_t plist_id, unsigned *super/*out*/, unsigned *freelist/*out*/
FUNC_LEAVE_API(ret_value)
} /* end H5Pget_version() */


/*--------------------------------------------------------------------------
NAME
H5Pencode1
PURPOSE
Routine to convert the property values in a property list into a binary buffer
USAGE
herr_t H5Pencode1(plist_id, buf, nalloc)
hid_t plist_id; IN: Identifier to property list to encode
void *buf: OUT: buffer to gold the encoded plist
size_t *nalloc; IN/OUT: size of buffer needed to encode plist
RETURNS
Returns non-negative on success, negative on failure.
DESCRIPTION
Encodes a property list into a binary buffer. If the buffer is NULL, then
the call will set the size needed to encode the plist in nalloc. Otherwise
the routine will encode the plist in buf.
GLOBAL VARIABLES
COMMENTS, BUGS, ASSUMPTIONS
EXAMPLES
REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5Pencode1(hid_t plist_id, void *buf, size_t *nalloc)
{
H5P_genplist_t *plist; /* Property list to query */
hid_t temp_fapl_id = H5P_DEFAULT;
herr_t ret_value = SUCCEED; /* return value */

FUNC_ENTER_API(FAIL)
H5TRACE3("e", "i*x*z", plist_id, buf, nalloc);

/* Check arguments. */
if(NULL == (plist = (H5P_genplist_t *)H5I_object_verify(plist_id, H5I_GENPROP_LST)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list");

/* Verify access property list and set up collective metadata if appropriate */
if(H5CX_set_apl(&temp_fapl_id, H5P_CLS_FACC, H5I_INVALID_HID, TRUE) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info")

/* Call the internal encode routine */
if((ret_value = H5P__encode(plist, TRUE, buf, nalloc)) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTENCODE, FAIL, "unable to encode property list");

done:
FUNC_LEAVE_API(ret_value)
} /* H5Pencode1() */

/*-------------------------------------------------------------------------
* Function: H5Pset_file_space
*
Expand Down
3 changes: 2 additions & 1 deletion src/H5Ppublic.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ H5_DLL herr_t H5Pinsert2(hid_t plist_id, const char *name, size_t size,
H5P_prp_compare_func_t prp_cmp, H5P_prp_close_func_t prp_close);
H5_DLL herr_t H5Pset(hid_t plist_id, const char *name, const void *value);
H5_DLL htri_t H5Pexist(hid_t plist_id, const char *name);
H5_DLL herr_t H5Pencode(hid_t plist_id, void *buf, size_t *nalloc);
H5_DLL herr_t H5Pencode2(hid_t plist_id, void *buf, size_t *nalloc, hid_t fapl_id);
H5_DLL hid_t H5Pdecode(const void *buf);
H5_DLL herr_t H5Pget_size(hid_t id, const char *name, size_t *size);
H5_DLL herr_t H5Pget_nprops(hid_t id, size_t *nprops);
Expand Down Expand Up @@ -536,6 +536,7 @@ H5_DLL herr_t H5Pinsert1(hid_t plist_id, const char *name, size_t size,
void *value, H5P_prp_set_func_t prp_set, H5P_prp_get_func_t prp_get,
H5P_prp_delete_func_t prp_delete, H5P_prp_copy_func_t prp_copy,
H5P_prp_close_func_t prp_close);
H5_DLL herr_t H5Pencode1(hid_t plist_id, void *buf, size_t *nalloc);
H5_DLL H5Z_filter_t H5Pget_filter1(hid_t plist_id, unsigned filter,
unsigned int *flags/*out*/, size_t *cd_nelmts/*out*/,
unsigned cd_values[]/*out*/, size_t namelen, char name[]);
Expand Down
3 changes: 3 additions & 0 deletions src/H5Rint.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ H5R__create(void *_ref, H5G_loc_t *loc, const char *name, H5R_type_t ref_type, H
obj_loc.path = &path;
H5G_loc_reset(&obj_loc);

/* Set the FAPL for the API context */
H5CX_set_libver_bounds(loc->oloc->file);

/* Find the object */
if(H5G_loc_find(loc, name, &obj_loc) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_NOTFOUND, FAIL, "object not found")
Expand Down
22 changes: 15 additions & 7 deletions src/H5S.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5CXprivate.h" /* API Contexts */
#include "H5Fprivate.h" /* Files */
#include "H5FLprivate.h" /* Free lists */
#include "H5Iprivate.h" /* IDs */
Expand Down Expand Up @@ -1487,13 +1488,15 @@ H5S_create_simple(unsigned rank, const hsize_t dims[/*rank*/],


/*-------------------------------------------------------------------------
* Function: H5Sencode
* Function: H5Sencode2
*
* Purpose: Given a dataspace ID, converts the object description
* (including selection) into binary in a buffer.
* The selection will be encoded according to the file
* format setting in fapl.
*
* Return: Success: non-negative
* Failure: negative
* Failure: negative
*
* Programmer: Raymond Lu
* [email protected]
Expand All @@ -1502,24 +1505,29 @@ H5S_create_simple(unsigned rank, const hsize_t dims[/*rank*/],
*-------------------------------------------------------------------------
*/
herr_t
H5Sencode(hid_t obj_id, void *buf, size_t *nalloc)
H5Sencode2(hid_t obj_id, void *buf, size_t *nalloc, hid_t fapl_id)
{
H5S_t *dspace;
herr_t ret_value=SUCCEED;

FUNC_ENTER_API(FAIL)
H5TRACE3("e", "i*x*z", obj_id, buf, nalloc);
H5TRACE4("e", "i*x*zi", obj_id, buf, nalloc, fapl_id);

/* Check argument and retrieve object */
if(NULL == (dspace = (H5S_t *)H5I_object_verify(obj_id, H5I_DATASPACE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace")

/* Verify access property list and set up collective metadata if appropriate */
if(H5CX_set_apl(&fapl_id, H5P_CLS_FACC, H5I_INVALID_HID, TRUE) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info")


if(H5S_encode(dspace, (unsigned char **)&buf, nalloc) < 0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode dataspace")
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode dataspace")

done:
FUNC_LEAVE_API(ret_value)
} /* end H5Sencode() */
} /* H5Sencode2() */


/*-------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/H5Sall.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ H5S__all_serialize(const H5S_t *space, uint8_t **p)

/* Store the preamble information */
UINT32ENCODE(pp, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */
UINT32ENCODE(pp, (uint32_t)1); /* Store the version number */
UINT32ENCODE(pp, (uint32_t)H5S_ALL_VERSION_1); /* Store the version number */
UINT32ENCODE(pp, (uint32_t)0); /* Store the un-used padding */
UINT32ENCODE(pp, (uint32_t)0); /* Store the additional information length */

Expand Down
Loading

0 comments on commit 66184e5

Please sign in to comment.