mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-03-13 16:47:58 +08:00
[svn-r9959] Purpose: Bug fix
Description: For variable-length string, H5Tget_class returned H5T_STRING as its class. But H5Tdetect_class and H5Tget_member_class considered it as H5T_VLEN. This is fixed to let all these 3 functions treat it as H5T_STRING. Some test cases have been added to dtypes.c Platforms tested: heping - already tested for v1.6 with h5committest Misc. update: RELEASE.txt
This commit is contained in:
parent
e31f8dfdc8
commit
70c0ba03ce
@ -201,6 +201,10 @@ Bug Fixes since HDF5-1.6.0 release
|
||||
|
||||
Library
|
||||
-------
|
||||
- For variable-length string, H5Tget_class returned H5T_STRING as its
|
||||
class. But H5Tdetect_class and H5Tget_member_class considered it
|
||||
as H5T_VLEN. This is fixed to let all these 3 functions treat it
|
||||
as H5T_STRING. SLU - 2005/02/08
|
||||
- The byte order of 1-byte integer types was fixed as little endian
|
||||
even on a big-endian machine. This has been corrected. SLU -
|
||||
2005/02/07
|
||||
|
@ -919,7 +919,7 @@ H5D_write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space,
|
||||
* to detect the type of the reference if it is nested... -QAK
|
||||
*/
|
||||
if (IS_H5FD_MPI(dataset->ent.file) &&
|
||||
H5T_get_class(mem_type)==H5T_REFERENCE &&
|
||||
H5T_get_class(mem_type, TRUE)==H5T_REFERENCE &&
|
||||
H5T_get_ref_type(mem_type)==H5R_DATASET_REGION)
|
||||
HGOTO_ERROR (H5E_DATASET, H5E_UNSUPPORTED, FAIL, "Parallel IO does not support writing region reference datatypes yet")
|
||||
|
||||
|
22
src/H5T.c
22
src/H5T.c
@ -1752,7 +1752,7 @@ H5Tget_class(hid_t type_id)
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_NO_CLASS, "not a data type");
|
||||
|
||||
/* Set return value */
|
||||
ret_value= H5T_get_class(dt);
|
||||
ret_value= H5T_get_class(dt, FALSE);
|
||||
|
||||
done:
|
||||
FUNC_LEAVE_API(ret_value);
|
||||
@ -1778,7 +1778,7 @@ done:
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
H5T_class_t
|
||||
H5T_get_class(const H5T_t *dt)
|
||||
H5T_get_class(const H5T_t *dt, htri_t internal)
|
||||
{
|
||||
H5T_class_t ret_value;
|
||||
|
||||
@ -1792,6 +1792,16 @@ H5T_get_class(const H5T_t *dt)
|
||||
else
|
||||
ret_value=dt->shared->type;
|
||||
|
||||
/* Externally, a VL string is a string; internally, a VL string is a VL. */
|
||||
if(internal) {
|
||||
ret_value=dt->shared->type;
|
||||
} else {
|
||||
if(H5T_IS_VL_STRING(dt->shared))
|
||||
ret_value=H5T_STRING;
|
||||
else
|
||||
ret_value=dt->shared->type;
|
||||
}
|
||||
|
||||
done:
|
||||
FUNC_LEAVE_NOAPI(ret_value);
|
||||
} /* end H5T_get_class() */
|
||||
@ -1827,8 +1837,12 @@ H5Tdetect_class(hid_t type, H5T_class_t cls)
|
||||
if (!(cls>H5T_NO_CLASS && cls<H5T_NCLASSES))
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_NO_CLASS, "not a data type class");
|
||||
|
||||
/* Set return value */
|
||||
ret_value=H5T_detect_class(dt,cls);
|
||||
/* Set return value. Consider VL string as a string for API, as a VL for
|
||||
* internal use. */
|
||||
if(H5T_IS_VL_STRING(dt->shared))
|
||||
ret_value = (H5T_STRING==cls);
|
||||
else
|
||||
ret_value=H5T_detect_class(dt,cls);
|
||||
|
||||
done:
|
||||
FUNC_LEAVE_API(ret_value);
|
||||
|
@ -170,8 +170,9 @@ H5Tget_member_class(hid_t type_id, unsigned membno)
|
||||
if (membno >= dt->shared->u.compnd.nmembs)
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5T_NO_CLASS, "invalid member number")
|
||||
|
||||
/* Value */
|
||||
ret_value = dt->shared->u.compnd.memb[membno].type->shared->type;
|
||||
/* Get the type's class. We have to use this function to get type class
|
||||
* because of the concern of variable-length string. */
|
||||
ret_value = H5T_get_class(dt->shared->u.compnd.memb[membno].type, FALSE);
|
||||
|
||||
done:
|
||||
FUNC_LEAVE_API(ret_value)
|
||||
|
@ -167,7 +167,7 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig
|
||||
|
||||
assert(dtype);
|
||||
|
||||
if((h5_class = H5T_get_class(dtype))==H5T_NO_CLASS)
|
||||
if((h5_class = H5T_get_class(dtype, FALSE))==H5T_NO_CLASS)
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a valid class")
|
||||
|
||||
if((size = H5T_get_size(dtype))==0)
|
||||
|
@ -71,7 +71,7 @@ H5_DLL H5T_t *H5T_open(H5G_entry_t *ent, hid_t dxpl_id);
|
||||
H5_DLL H5T_t *H5T_copy(const H5T_t *old_dt, H5T_copy_t method);
|
||||
H5_DLL herr_t H5T_lock(H5T_t *dt, hbool_t immutable);
|
||||
H5_DLL herr_t H5T_close(H5T_t *dt);
|
||||
H5_DLL H5T_class_t H5T_get_class(const H5T_t *dt);
|
||||
H5_DLL H5T_class_t H5T_get_class(const H5T_t *dt, htri_t internal);
|
||||
H5_DLL htri_t H5T_detect_class (const H5T_t *dt, H5T_class_t cls);
|
||||
H5_DLL size_t H5T_get_size(const H5T_t *dt);
|
||||
H5_DLL int H5T_cmp(const H5T_t *dt1, const H5T_t *dt2);
|
||||
|
149
test/dtypes.c
149
test/dtypes.c
@ -370,22 +370,80 @@ reset_hdf5(void)
|
||||
static int
|
||||
test_classes(void)
|
||||
{
|
||||
H5T_class_t tcls;
|
||||
|
||||
struct complex { /* Struct with complex fields */
|
||||
hvl_t vl_c;
|
||||
hvl_t vl_s;
|
||||
};
|
||||
hid_t cmpd_id; /* Compound datatype */
|
||||
hid_t vlc_id; /* VL type of char */
|
||||
hid_t vls_id; /* VL string */
|
||||
hid_t memb_id; /* Compound member datatype */
|
||||
H5T_class_t memb_cls;
|
||||
H5T_class_t tcls;
|
||||
int nmembs, i;
|
||||
|
||||
TESTING("H5Tget_class()");
|
||||
|
||||
if ((tcls=H5Tget_class(H5T_NATIVE_INT))<0) goto error;
|
||||
if (H5T_INTEGER!=tcls) {
|
||||
H5_FAILED();
|
||||
HDputs(" Invalid type class for H5T_NATIVE_INT");
|
||||
goto error;
|
||||
}
|
||||
if ((tcls=H5Tget_class(H5T_NATIVE_DOUBLE))<0) goto error;
|
||||
if (H5T_FLOAT!=tcls) {
|
||||
H5_FAILED();
|
||||
HDputs(" Invalid type class for H5T_NATIVE_DOUBLE");
|
||||
goto error;
|
||||
/*-------------------------------------------------------------
|
||||
* Check class of some atomic types.
|
||||
*-----------------------------------------------------------*/
|
||||
if ((tcls=H5Tget_class(H5T_NATIVE_INT))<0) TEST_ERROR
|
||||
if (H5T_INTEGER!=tcls) TEST_ERROR
|
||||
|
||||
if ((tcls=H5Tget_class(H5T_NATIVE_DOUBLE))<0) TEST_ERROR
|
||||
if (H5T_FLOAT!=tcls) TEST_ERROR
|
||||
|
||||
/* Create a VL datatype of char. It should be a VL, not a string class. */
|
||||
if((vlc_id=H5Tvlen_create(H5T_NATIVE_CHAR))<0) TEST_ERROR
|
||||
|
||||
/* Make certain that the correct classes can be detected */
|
||||
if ((tcls=H5Tget_class(vlc_id))<0) TEST_ERROR
|
||||
if (H5T_VLEN!=tcls) TEST_ERROR
|
||||
|
||||
/* Make certain that an incorrect class is not detected */
|
||||
if (H5T_STRING==tcls) TEST_ERROR
|
||||
|
||||
/* Create a VL string. It should be a string, not a VL class. */
|
||||
if((vls_id=H5Tcopy(H5T_C_S1))<0) TEST_ERROR
|
||||
if(H5Tset_size(vls_id, H5T_VARIABLE)<0) TEST_ERROR;
|
||||
|
||||
/* Make certain that the correct classes can be detected */
|
||||
if ((tcls=H5Tget_class(vls_id))<0) TEST_ERROR
|
||||
if (H5T_STRING!=tcls) TEST_ERROR
|
||||
|
||||
/* Make certain that an incorrect class is not detected */
|
||||
if (H5T_VLEN==tcls) TEST_ERROR
|
||||
|
||||
/*-------------------------------------------------------------
|
||||
* Check class for member types of compound type.
|
||||
*-----------------------------------------------------------*/
|
||||
/* Create a compound datatype and insert some complex types */
|
||||
if ((cmpd_id = H5Tcreate(H5T_COMPOUND, sizeof(struct complex)))<0) TEST_ERROR
|
||||
if (H5Tinsert(cmpd_id, "vl_c", HOFFSET(struct complex, vl_c), vlc_id)<0) TEST_ERROR
|
||||
if (H5Tinsert(cmpd_id, "vl_s", HOFFSET(struct complex, vl_s), vls_id)<0) TEST_ERROR
|
||||
|
||||
nmembs = H5Tget_nmembers(cmpd_id);
|
||||
|
||||
for (i=0;i<nmembs;i++)
|
||||
{
|
||||
/* Get member type ID */
|
||||
if((memb_id = H5Tget_member_type(cmpd_id, i))<0) TEST_ERROR
|
||||
|
||||
/* Get member type class */
|
||||
if((memb_cls = H5Tget_member_class (cmpd_id, i))<0) TEST_ERROR
|
||||
|
||||
/* Verify member class */
|
||||
if(H5Tdetect_class (memb_id, memb_cls)<0) TEST_ERROR
|
||||
|
||||
/* Close member type ID */
|
||||
if(H5Tclose(memb_id)<0) TEST_ERROR
|
||||
}
|
||||
|
||||
/* Close datatypes */
|
||||
if(H5Tclose(cmpd_id)<0) TEST_ERROR
|
||||
if(H5Tclose(vlc_id)<0) TEST_ERROR
|
||||
if(H5Tclose(vls_id)<0) TEST_ERROR
|
||||
|
||||
PASSED();
|
||||
return 0;
|
||||
|
||||
@ -475,13 +533,18 @@ test_detect(void)
|
||||
};
|
||||
hid_t atom_cmpd_id; /* Atomic Compound datatype */
|
||||
hid_t atom_arr_id; /* Atomic Array datatype */
|
||||
hid_t atom_vl_id; /* Atomic VL datatype */
|
||||
hid_t atom_vlf_id; /* Atomic VL datatype of float */
|
||||
hid_t atom_vlc_id; /* Atomic VL datatype of char */
|
||||
hid_t atom_vls_id; /* Atomic VL string datatype */
|
||||
hid_t cplx_cmpd_id; /* Complex Compound datatype */
|
||||
int rank=2; /* Rank for array datatype */
|
||||
hsize_t dims[2]={3,3}; /* Dimensions for array datatype */
|
||||
|
||||
TESTING("H5Tdetect_class()");
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Test class of some atomic types.
|
||||
*------------------------------------------------------------------------------*/
|
||||
/* Native integers should be in the integer class */
|
||||
if(H5Tdetect_class(H5T_NATIVE_INT,H5T_INTEGER)!=TRUE) TEST_ERROR
|
||||
|
||||
@ -490,7 +553,10 @@ test_detect(void)
|
||||
if(H5Tdetect_class(H5T_NATIVE_INT,H5T_ARRAY)!=FALSE) TEST_ERROR
|
||||
if(H5Tdetect_class(H5T_NATIVE_INT,H5T_ENUM)!=FALSE) TEST_ERROR
|
||||
|
||||
/* Create a compound datatype and insert some atomic types */
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Test class of a compound type with some atomic types as fields.
|
||||
*------------------------------------------------------------------------------*/
|
||||
/* Create a compound datatype and insert some atomic types */
|
||||
if ((atom_cmpd_id = H5Tcreate(H5T_COMPOUND, sizeof(struct atomic)))<0) TEST_ERROR
|
||||
if (H5Tinsert(atom_cmpd_id, "i", HOFFSET(struct atomic, i), H5T_NATIVE_INT)<0) TEST_ERROR
|
||||
if (H5Tinsert(atom_cmpd_id, "f", HOFFSET(struct atomic, f), H5T_NATIVE_FLOAT)<0) TEST_ERROR
|
||||
@ -506,6 +572,9 @@ test_detect(void)
|
||||
/* Make certain that an incorrect class is not detected */
|
||||
if(H5Tdetect_class(atom_cmpd_id,H5T_VLEN)!=FALSE) TEST_ERROR
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Test class of some complex types.
|
||||
*------------------------------------------------------------------------------*/
|
||||
/* Create an array datatype with an atomic base type */
|
||||
if((atom_arr_id=H5Tarray_create(H5T_STD_REF_OBJ, rank, dims, NULL))<0) TEST_ERROR
|
||||
|
||||
@ -518,22 +587,46 @@ test_detect(void)
|
||||
if(H5Tdetect_class(atom_arr_id,H5T_FLOAT)!=FALSE) TEST_ERROR
|
||||
if(H5Tdetect_class(atom_arr_id,H5T_INTEGER)!=FALSE) TEST_ERROR
|
||||
|
||||
/* Create a VL datatype with an atomic base type */
|
||||
if((atom_vl_id=H5Tvlen_create(H5T_NATIVE_FLOAT))<0) TEST_ERROR
|
||||
/* Create a VL datatype with an atomic base type of float*/
|
||||
if((atom_vlf_id=H5Tvlen_create(H5T_NATIVE_FLOAT))<0) TEST_ERROR
|
||||
|
||||
/* Make certain that the correct classes can be detected */
|
||||
if(H5Tdetect_class(atom_vl_id,H5T_VLEN)!=TRUE) TEST_ERROR
|
||||
if(H5Tdetect_class(atom_vl_id,H5T_FLOAT)!=TRUE) TEST_ERROR
|
||||
if(H5Tdetect_class(atom_vlf_id,H5T_VLEN)!=TRUE) TEST_ERROR
|
||||
if(H5Tdetect_class(atom_vlf_id,H5T_FLOAT)!=TRUE) TEST_ERROR
|
||||
|
||||
/* Make certain that an incorrect class is not detected */
|
||||
if(H5Tdetect_class(atom_vl_id,H5T_COMPOUND)!=FALSE) TEST_ERROR
|
||||
if(H5Tdetect_class(atom_vl_id,H5T_INTEGER)!=FALSE) TEST_ERROR
|
||||
if(H5Tdetect_class(atom_vlf_id,H5T_COMPOUND)!=FALSE) TEST_ERROR
|
||||
if(H5Tdetect_class(atom_vlf_id,H5T_INTEGER)!=FALSE) TEST_ERROR
|
||||
|
||||
/* Create a compound datatype and insert some atomic types */
|
||||
/* Create a VL datatype with an atomic base type of char. It should be a VL
|
||||
* but not a string class. */
|
||||
if((atom_vlc_id=H5Tvlen_create(H5T_NATIVE_CHAR))<0) TEST_ERROR
|
||||
|
||||
/* Make certain that the correct classes can be detected */
|
||||
if(H5Tdetect_class(atom_vlc_id,H5T_VLEN)!=TRUE) TEST_ERROR
|
||||
if(H5Tdetect_class(atom_vlc_id,H5T_INTEGER)!=TRUE) TEST_ERROR
|
||||
|
||||
/* Make certain that an incorrect class is not detected */
|
||||
if(H5Tdetect_class(atom_vlc_id,H5T_STRING)!=FALSE) TEST_ERROR
|
||||
|
||||
/* Create a VL string. It should be a string, not a VL class. */
|
||||
if((atom_vls_id=H5Tcopy(H5T_C_S1))<0) TEST_ERROR
|
||||
if(H5Tset_size(atom_vls_id, H5T_VARIABLE)<0) TEST_ERROR;
|
||||
|
||||
/* Make certain that the correct classes can be detected */
|
||||
if(H5Tdetect_class(atom_vls_id,H5T_STRING)!=TRUE) TEST_ERROR
|
||||
|
||||
/* Make certain that an incorrect class is not detected */
|
||||
if(H5Tdetect_class(atom_vls_id,H5T_VLEN)!=FALSE) TEST_ERROR
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Test class of a compound type with some complex types as fields.
|
||||
*------------------------------------------------------------------------------*/
|
||||
/* Create a compound datatype and insert some complex types */
|
||||
if ((cplx_cmpd_id = H5Tcreate(H5T_COMPOUND, sizeof(struct complex)))<0) TEST_ERROR
|
||||
if (H5Tinsert(cplx_cmpd_id, "arr_r", HOFFSET(struct complex, arr_r), atom_arr_id)<0) TEST_ERROR
|
||||
if (H5Tinsert(cplx_cmpd_id, "i", HOFFSET(struct complex, i), H5T_NATIVE_INT)<0) TEST_ERROR
|
||||
if (H5Tinsert(cplx_cmpd_id, "vl_f", HOFFSET(struct complex, vl_f), atom_vl_id)<0) TEST_ERROR
|
||||
if (H5Tinsert(cplx_cmpd_id, "vl_f", HOFFSET(struct complex, vl_f), atom_vlf_id)<0) TEST_ERROR
|
||||
if (H5Tinsert(cplx_cmpd_id, "c", HOFFSET(struct complex, c), H5T_NATIVE_CHAR)<0) TEST_ERROR
|
||||
if (H5Tinsert(cplx_cmpd_id, "s", HOFFSET(struct complex, s), H5T_NATIVE_SHORT)<0) TEST_ERROR
|
||||
|
||||
@ -553,8 +646,14 @@ test_detect(void)
|
||||
/* Close complex compound datatype */
|
||||
if(H5Tclose(cplx_cmpd_id)<0) TEST_ERROR
|
||||
|
||||
/* Close atomic VL datatype */
|
||||
if(H5Tclose(atom_vl_id)<0) TEST_ERROR
|
||||
/* Close atomic VL datatype of float */
|
||||
if(H5Tclose(atom_vlf_id)<0) TEST_ERROR
|
||||
|
||||
/* Close atomic VL datatype of char */
|
||||
if(H5Tclose(atom_vlc_id)<0) TEST_ERROR
|
||||
|
||||
/* Close atomic VL string datatype */
|
||||
if(H5Tclose(atom_vls_id)<0) TEST_ERROR
|
||||
|
||||
/* Close atomic array datatype */
|
||||
if(H5Tclose(atom_arr_id)<0) TEST_ERROR
|
||||
|
Loading…
x
Reference in New Issue
Block a user