[svn-r22749] Description:

Undo of accidental check-in of H5T code in last check-in.

Tested on:
    jam w/ parallel enabled (revert to pre-existing code)
This commit is contained in:
Dana Robinson 2012-09-10 12:00:05 -05:00
parent d1060f63b7
commit b951fb9fe1
10 changed files with 874 additions and 745 deletions

329
src/H5T.c
View File

@ -1040,13 +1040,13 @@ H5T_init_interface(void)
fixedpt = native_int;
floatpt = native_float;
if (NULL == (compound = H5T__create(H5T_COMPOUND, (size_t)1)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
if (NULL == (enum_type = H5T__create(H5T_ENUM, (size_t)1)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
if (NULL == (vlen = H5T__vlen_create(native_int)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
if (NULL == (array = H5T__array_create(native_int, 1, dim)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
status = 0;
status |= H5T_register(H5T_PERS_SOFT, "i_i", fixedpt, fixedpt, H5T__conv_i_i, H5AC_dxpl_id, FALSE);
@ -1971,22 +1971,31 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T_detect_class
* Function: H5T_detect_class
*
* Purpose: Check whether a datatype contains (or is) a certain type of
* datatype.
* Purpose: Check whether a datatype contains (or is) a certain type of
* datatype.
*
* Return: TRUE (1) or FALSE (0) on success/Negative on failure
* Return: TRUE (1) or FALSE (0) on success/Negative on failure
*
* Programmer: Quincey Koziol
* Wednesday, November 29, 2000
* Programmer: Quincey Koziol
* Wednesday, November 29, 2000
*
* Modifications:
* Raymond Lu
* 4 December 2009
* Added a flag as a parameter to indicate whether the caller is
* H5Tdetect_class. I also added the check for VL string type
* just like the public function. Because we want to tell users
* VL string is a string type but we treat it as a VL type
* internally, H5T_detect_class needs to know where the caller
* is from.
*-------------------------------------------------------------------------
*/
htri_t
H5T_detect_class(const H5T_t *dt, H5T_class_t cls, hbool_t from_api)
{
unsigned i;
unsigned i;
htri_t ret_value = FALSE; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
@ -2139,33 +2148,33 @@ done:
/*-------------------------------------------------------------------------
* Function: H5Tset_size
* Function: H5Tset_size
*
* Purpose: Sets the total size in bytes for a datatype (this operation
* is not permitted on reference datatypes). If the size is
* decreased so that the significant bits of the datatype
* extend beyond the edge of the new size, then the `offset'
* property is decreased toward zero. If the `offset' becomes
* zero and the significant bits of the datatype still hang
* over the edge of the new size, then the number of significant
* bits is decreased.
* Purpose: Sets the total size in bytes for a datatype (this operation
* is not permitted on reference datatypes). If the size is
* decreased so that the significant bits of the datatype
* extend beyond the edge of the new size, then the `offset'
* property is decreased toward zero. If the `offset' becomes
* zero and the significant bits of the datatype still hang
* over the edge of the new size, then the number of significant
* bits is decreased.
*
* Adjusting the size of an H5T_STRING automatically sets the
* precision to 8*size.
* Adjusting the size of an H5T_STRING automatically sets the
* precision to 8*size.
*
* All datatypes have a positive size.
* All datatypes have a positive size.
*
* Return: SUCCEED/FAIL
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
*
*-------------------------------------------------------------------------
*/
herr_t
H5Tset_size(hid_t type_id, size_t size)
{
H5T_t *dt; /* Datatype to modify */
H5T_t *dt; /* Datatype to modify */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
@ -2173,21 +2182,21 @@ H5Tset_size(hid_t type_id, size_t size)
/* Check args */
if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
if(H5T_STATE_TRANSIENT!=dt->shared->state)
HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "datatype is read-only")
HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "datatype is read-only")
if(size <= 0 && size != H5T_VARIABLE)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "size must be positive")
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "size must be positive")
if(size == H5T_VARIABLE && !H5T_IS_STRING(dt->shared))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "only strings may be variable length")
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "only strings may be variable length")
if(H5T_ENUM == dt->shared->type && dt->shared->u.enumer.nmembs > 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined")
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined")
if(H5T_REFERENCE == dt->shared->type)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for this datatype")
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for this datatype")
/* Modify the datatype */
if(H5T_set_size(dt, size) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to set size for datatype")
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to set size for datatype")
done:
FUNC_LEAVE_API(ret_value)
@ -3122,6 +3131,27 @@ done:
* Programmer: Robb Matzke
* Thursday, December 4, 1997
*
* Modifications:
*
* Robb Matzke, 4 Jun 1998
* Added the METHOD argument. If it's H5T_COPY_TRANSIENT then the
* result will be an unlocked transient type. Otherwise if it's
* H5T_COPY_ALL then the result is a named type if the original is a
* named type, but the result is not opened. Finally, if it's
* H5T_COPY_REOPEN and the original type is a named type then the result
* is a named type and the type object header is opened again. The
* H5T_COPY_REOPEN method is used when returning a named type to the
* application.
*
* Robb Matzke, 22 Dec 1998
* Now able to copy enumeration data types.
*
* Robb Matzke, 20 May 1999
* Now able to copy opaque types.
*
* Pedro Vicente, <pvn@ncsa.uiuc.edu> 21 Sep 2002
* Added a deep copy of the symbol table entry
*
*-------------------------------------------------------------------------
*/
H5T_t *
@ -3474,23 +3504,23 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T__free
* Function: H5T__free
*
* Purpose: Frees all memory associated with a datatype, but does not
* Purpose: Frees all memory associated with a datatype, but does not
* free the H5T_t or H5T_shared_t structures (which should
* be done in H5T_close).
*
* Return: SUCCEED/FAIL
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Monday, January 6, 2003
* Programmer: Quincey Koziol
* Monday, January 6, 2003
*
*-------------------------------------------------------------------------
*/
herr_t
H5T__free(H5T_t *dt)
{
unsigned i;
unsigned i;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
@ -3522,8 +3552,8 @@ H5T__free(H5T_t *dt)
/*
* Don't free locked datatypes.
*/
if(H5T_STATE_IMMUTABLE == dt->shared->state)
HGOTO_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to close immutable datatype")
if(H5T_STATE_IMMUTABLE==dt->shared->state)
HGOTO_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to close immutable datatype")
/* Close the datatype */
switch(dt->shared->type) {
@ -3553,7 +3583,7 @@ H5T__free(H5T_t *dt)
/* Close the parent */
HDassert(dt->shared->parent != dt);
if(dt->shared->parent && H5T_close(dt->shared->parent) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close parent data type")
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close parent data type")
done:
FUNC_LEAVE_NOAPI(ret_value)
@ -3561,15 +3591,28 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T_close
* Function: H5T_close
*
* Purpose: Frees a data type and all associated memory. If the data
* type is locked then nothing happens.
* Purpose: Frees a data type and all associated memory. If the data
* type is locked then nothing happens.
*
* Return: SUCCEED/FAIL
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Monday, December 8, 1997
* Programmer: Robb Matzke
* Monday, December 8, 1997
*
* Modifications:
* Robb Matzke, 1999-04-27
* This function fails if the datatype state is IMMUTABLE.
*
* Robb Matzke, 1999-05-20
* Closes opaque types also.
*
* Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
* Added "ID to name" support
*
* Quincey Koziol, 2003-01-06
* Moved "guts" of function to H5T__free()
*
*-------------------------------------------------------------------------
*/
@ -3628,70 +3671,76 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T_set_size
* Function: H5T_set_size
*
* Purpose: Sets the total size in bytes for a data type (this operation
* is not permitted on reference data types). If the size is
* decreased so that the significant bits of the data type
* extend beyond the edge of the new size, then the 'offset'
* property is decreased toward zero. If the 'offset' becomes
* zero and the significant bits of the data type still hang
* over the edge of the new size, then the number of significant
* bits is decreased.
* Purpose: Sets the total size in bytes for a data type (this operation
* is not permitted on reference data types). If the size is
* decreased so that the significant bits of the data type
* extend beyond the edge of the new size, then the `offset'
* property is decreased toward zero. If the `offset' becomes
* zero and the significant bits of the data type still hang
* over the edge of the new size, then the number of significant
* bits is decreased.
*
* Adjusting the size of an H5T_STRING automatically sets the
* precision to 8 * size.
* Adjusting the size of an H5T_STRING automatically sets the
* precision to 8*size.
*
* All data types have a positive size.
* All data types have a positive size.
*
* Return: SUCCEED/FAIL
* Return: Success: non-negative
*
* Programmer: Robb Matzke
* Failure: nagative
*
* Programmer: Robb Matzke
* Tuesday, December 22, 1998
*
* Modifications:
* Robb Matzke, 22 Dec 1998
* Also works with derived data types.
*
*-------------------------------------------------------------------------
*/
static herr_t
H5T_set_size(H5T_t *dt, size_t size)
{
size_t prec, offset;
herr_t ret_value = SUCCEED; /* Return value */
size_t prec, offset;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
/* Check args */
HDassert(dt);
HDassert(size != 0);
HDassert(H5T_REFERENCE != dt->shared->type);
HDassert(!(H5T_ENUM == dt->shared->type && 0 == dt->shared->u.enumer.nmembs));
assert(dt);
assert(size!=0);
assert(H5T_REFERENCE!=dt->shared->type);
assert(!(H5T_ENUM==dt->shared->type && 0==dt->shared->u.enumer.nmembs));
if(dt->shared->parent) {
if(H5T_set_size(dt->shared->parent, size) < 0)
if (dt->shared->parent) {
if (H5T_set_size(dt->shared->parent, size)<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to set size for parent data type");
/* Adjust size of datatype appropriately */
if(dt->shared->type == H5T_ARRAY)
if(dt->shared->type==H5T_ARRAY)
dt->shared->size = dt->shared->parent->shared->size * dt->shared->u.array.nelem;
else if(dt->shared->type != H5T_VLEN)
else if(dt->shared->type!=H5T_VLEN)
dt->shared->size = dt->shared->parent->shared->size;
} else {
if(H5T_IS_ATOMIC(dt->shared)) {
if (H5T_IS_ATOMIC(dt->shared)) {
offset = dt->shared->u.atomic.offset;
prec = dt->shared->u.atomic.prec;
/* Decrement the offset and precision if necessary */
if (prec > 8 * size)
if (prec > 8*size)
offset = 0;
else
if (offset+prec > 8 * size)
if (offset+prec > 8*size)
offset = 8 * size - prec;
if (prec > 8 * size)
if (prec > 8*size)
prec = 8 * size;
} else {
prec = offset = 0;
} /* end else */
}
switch(dt->shared->type) {
switch (dt->shared->type) {
case H5T_INTEGER:
case H5T_TIME:
case H5T_BITFIELD:
@ -3701,34 +3750,33 @@ H5T_set_size(H5T_t *dt, size_t size)
case H5T_COMPOUND:
/* If decreasing size, check the last member isn't being cut. */
if(size < dt->shared->size) {
if(size<dt->shared->size) {
int num_membs = 0;
unsigned i, max_index = 0;
size_t memb_offset, max_offset = 0;
unsigned i, max_index=0;
size_t memb_offset, max_offset=0;
size_t max_size;
if((num_membs = H5T_get_nmembers(dt)) < 0)
if((num_membs = H5T_get_nmembers(dt))<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to get number of members");
if(num_membs) {
for(i = 0; i < (unsigned)num_membs; i++) {
memb_offset = H5T_get_member_offset(dt, i);
if(memb_offset > max_offset) {
max_offset = memb_offset;
max_index = i;
} /* end if */
} /* end for */
for(i=0; i<(unsigned)num_membs; i++) {
memb_offset = H5T_get_member_offset(dt, i);
if(memb_offset > max_offset) {
max_offset = memb_offset;
max_index = i;
}
}
max_size = H5T__get_member_size(dt, max_index);
max_size = H5T__get_member_size(dt, max_index);
if(size < (max_offset+max_size))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "size shrinking will cut off last member ");
} /* end if */
if(size<(max_offset+max_size))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "size shrinking will cut off last member ");
}
/* Compound must not have been packed previously.
* We will check if resizing changed the packed state of
* this type at the end of this function.
*/
/* Compound must not have been packed previously */
/* We will check if resizing changed the packed state of
* this type at the end of this function */
HDassert(!dt->shared->u.compnd.packed);
}
@ -3736,30 +3784,29 @@ H5T_set_size(H5T_t *dt, size_t size)
case H5T_STRING:
/* Convert string to variable-length datatype */
if(size == H5T_VARIABLE) {
H5T_t *base = NULL; /* base data type */
if(size==H5T_VARIABLE) {
H5T_t *base = NULL; /* base data type */
H5T_cset_t tmp_cset; /* Temp. cset info */
H5T_str_t tmp_strpad; /* Temp. strpad info */
/* Get a copy of unsigned char type as the base/parent type */
if(NULL == (base = (H5T_t *)H5I_object(H5T_NATIVE_UCHAR)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid base datatype");
dt->shared->parent = H5T_copy(base,H5T_COPY_ALL);
dt->shared->parent=H5T_copy(base,H5T_COPY_ALL);
/* change this datatype into a VL string */
dt->shared->type = H5T_VLEN;
/*
* Force conversions (i.e. memory to memory conversions
* should duplicate data, not point to the same VL strings)
* should duplicate data, not point to the same VL strings)
*/
dt->shared->force_conv = TRUE;
/* Before we mess with the info in the union, extract the
* values we need
*/
tmp_cset = dt->shared->u.atomic.u.s.cset;
tmp_strpad = dt->shared->u.atomic.u.s.pad;
/* Before we mess with the info in the union, extract the
* values we need */
tmp_cset=dt->shared->u.atomic.u.s.cset;
tmp_strpad=dt->shared->u.atomic.u.s.pad;
/* This is a string, not a sequence */
dt->shared->u.vlen.type = H5T_VLEN_STRING;
@ -3769,7 +3816,7 @@ H5T_set_size(H5T_t *dt, size_t size)
dt->shared->u.vlen.pad = tmp_strpad;
/* Set up VL information */
if(H5T_set_loc(dt, NULL, H5T_LOC_MEMORY) < 0)
if (H5T_set_loc(dt, NULL, H5T_LOC_MEMORY)<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location");
} else {
@ -3787,28 +3834,28 @@ H5T_set_size(H5T_t *dt, size_t size)
dt->shared->u.atomic.u.f.epos + dt->shared->u.atomic.u.f.esize > prec+offset ||
dt->shared->u.atomic.u.f.mpos + dt->shared->u.atomic.u.f.msize > prec+offset) {
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "adjust sign, mantissa, and exponent fields first");
} /* end if */
}
break;
case H5T_ENUM:
case H5T_VLEN:
case H5T_ARRAY:
case H5T_REFERENCE:
HDassert("can't happen" && 0);
assert("can't happen" && 0);
case H5T_NO_CLASS:
case H5T_NCLASSES:
HDassert("invalid type" && 0);
assert("invalid type" && 0);
default:
HDassert("not implemented yet" && 0);
assert("not implemented yet" && 0);
}
/* Commit (if we didn't convert this type to a VL string) */
if(dt->shared->type != H5T_VLEN) {
if(dt->shared->type!=H5T_VLEN) {
dt->shared->size = size;
if (H5T_IS_ATOMIC(dt->shared)) {
dt->shared->u.atomic.offset = offset;
dt->shared->u.atomic.prec = prec;
} /* end if */
}
} /* end if */
/* Check if the new compound type is packed */
@ -3822,18 +3869,20 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T_get_size
* Function: H5T_get_size
*
* Purpose: Determines the total size of a data type in bytes.
* Purpose: Determines the total size of a data type in bytes.
*
* Return: Success: Size of the data type in bytes. The size of
* the data type is the size of an instance of
* that data type.
* Return: Success: Size of the data type in bytes. The size of
* the data type is the size of an instance of
* that data type.
*
* Failure: 0 (valid data types are never zero size)
* Failure: 0 (valid data types are never zero size)
*
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
@ -4030,9 +4079,9 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset)
#ifdef H5T_DEBUG
/* I don't quite trust the code above yet :-) --RPM */
for (u=0; u<dt1->shared->u.enumer.nmembs-1; u++) {
HDassert(HDstrcmp(dt1->shared->u.enumer.name[idx1[u]],
assert(HDstrcmp(dt1->shared->u.enumer.name[idx1[u]],
dt1->shared->u.enumer.name[idx1[u+1]]));
HDassert(HDstrcmp(dt2->shared->u.enumer.name[idx2[u]],
assert(HDstrcmp(dt2->shared->u.enumer.name[idx2[u]],
dt2->shared->u.enumer.name[idx2[u+1]]));
}
#endif
@ -4950,24 +4999,26 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T_is_sensible
* Function: H5T_is_sensible
*
* Purpose: Determines if a data type is sensible to store on disk
* Purpose: Determines if a data type is sensible to store on disk
* (i.e. not partially initialized)
*
* Return: Success: TRUE, FALSE
* Return: Success: TRUE, FALSE
*
* Failure: Negative
* Failure: Negative
*
* Programmer: Quincey Koziol
* Tuesday, June 11, 2002
* Programmer: Quincey Koziol
* Tuesday, June 11, 2002
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
htri_t
H5T_is_sensible(const H5T_t *dt)
{
htri_t ret_value;
htri_t ret_value;
FUNC_ENTER_NOAPI(FAIL)
@ -4977,28 +5028,28 @@ H5T_is_sensible(const H5T_t *dt)
case H5T_COMPOUND:
/* Only allow compound datatypes with at least one member to be stored on disk */
if(dt->shared->u.compnd.nmembs > 0)
ret_value = TRUE;
ret_value=TRUE;
else
ret_value = FALSE;
ret_value=FALSE;
break;
case H5T_ENUM:
/* Only allow enum datatypes with at least one member to be stored on disk */
if(dt->shared->u.enumer.nmembs > 0)
ret_value = TRUE;
ret_value=TRUE;
else
ret_value = FALSE;
ret_value=FALSE;
break;
default:
/* Assume all other datatype are sensible to store on disk */
ret_value = TRUE;
ret_value=TRUE;
break;
} /* end switch */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T_is_sensible */
}
/*--------------------------------------------------------------------------
@ -5190,11 +5241,11 @@ done:
* Purpose: H5T__visit callback to Upgrade the version of a datatype
* (if there's any benefit to doing so)
*
* Note: The behavior below is tightly coupled with the "better"
* Note: The behavior below is tightly coupled with the "better"
* encodings for datatype messages in the datatype message
* encoding routine.
*
* Return: Non-negative on success/Negative on failure
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Thursday, July 19, 2007

View File

@ -2699,36 +2699,35 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T__conv_enum
* Function: H5T__conv_enum
*
* Purpose: Converts one type of enumerated data to another.
* Purpose: Converts one type of enumerated data to another.
*
* Return: SUCCEED/FAIL
* Return: Success: Non-negative
*
* Programmer: Robb Matzke
* Failure: negative
*
* Programmer: Robb Matzke
* Monday, January 4, 1999
*-------------------------------------------------------------------------
*/
herr_t
H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
size_t buf_stride, size_t UNUSED bkg_stride, void *_buf,
void UNUSED *bkg, hid_t UNUSED dxpl_id)
size_t buf_stride, size_t UNUSED bkg_stride, void *_buf,
void UNUSED *bkg, hid_t UNUSED dxpl_id)
{
uint8_t *buf = (uint8_t *)_buf; /* cast for ptr arithmetic */
H5T_t *src = NULL; /* src and dst datatypes */
H5T_t *dst = NULL;
H5T_t *src_super = NULL; /* src and dst parent types */
H5T_t *dst_super = NULL;
uint8_t *s = NULL; /* src and dst BUF pointers */
uint8_t *d = NULL;
int src_delta, dst_delta; /* conversion strides */
int n; /* src value cast as native int */
H5T_enum_struct_t *priv = (H5T_enum_struct_t*)(cdata->priv);
H5P_genplist_t *plist; /* property list pointer */
H5T_conv_cb_t cb_struct; /* conversion callback structure */
H5T_conv_ret_t except_ret; /* return of callback function */
size_t i; /* counters */
herr_t ret_value = SUCCEED; /* Return value */
uint8_t *buf = (uint8_t*)_buf; /*cast for pointer arithmetic */
H5T_t *src = NULL, *dst = NULL; /*src and dst datatypes */
H5T_t *src_super = NULL, *dst_super = NULL; /*parent types for src and dst*/
uint8_t *s = NULL, *d = NULL; /*src and dst BUF pointers */
int src_delta, dst_delta; /*conversion strides */
int n; /*src value cast as native int */
H5T_enum_struct_t *priv = (H5T_enum_struct_t*)(cdata->priv);
H5P_genplist_t *plist; /*property list pointer */
H5T_conv_cb_t cb_struct; /*conversion callback structure */
H5T_conv_ret_t except_ret; /*return of callback function */
size_t i; /*counters */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
@ -2737,7 +2736,7 @@ H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
/*
* Determine if this conversion function applies to the conversion
* path SRC_ID->DST_ID. If not return failure; otherwise initialize
* the 'priv' field of 'cdata' with information about the underlying
* the `priv' field of `cdata' with information about the underlying
* integer conversion.
*/
if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
@ -2777,8 +2776,7 @@ H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
/* priv->src2dst map was computed for certain sort keys. Make sure those same
* sort keys are used here during conversion. See H5T_conv_enum_init(). But
* we actually don't care about the source type's order when doing the O(1)
* conversion algorithm, which is turned on by non-zero priv->length
*/
* conversion algorithm, which is turned on by non-zero priv->length */
H5T__sort_name(dst, NULL);
if(!priv->length)
H5T__sort_value(src, NULL);
@ -2790,12 +2788,12 @@ H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
src_delta = dst_delta = (int)buf_stride;
s = d = buf;
} else if(dst->shared->size <= src->shared->size) {
src_delta = (int)src->shared->size; /* overflow shouldn't be possible */
dst_delta = (int)dst->shared->size; /* overflow shouldn't be possible */
src_delta = (int)src->shared->size; /*overflow shouldn't be possible*/
dst_delta = (int)dst->shared->size; /*overflow shouldn't be possible*/
s = d = buf;
} else {
src_delta = -(int)src->shared->size; /* overflow shouldn't be possible */
dst_delta = -(int)dst->shared->size; /* overflow shouldn't be possible */
src_delta = -(int)src->shared->size; /*overflow shouldn't be possible*/
dst_delta = -(int)dst->shared->size; /*overflow shouldn't be possible*/
s = buf + (nelmts-1) * src->shared->size;
d = buf + (nelmts-1) * dst->shared->size;
}
@ -2827,7 +2825,7 @@ H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
if(n < 0 || n >= priv->length || priv->src2dst[n] < 0) {
/*overflow*/
except_ret = H5T_CONV_UNHANDLED;
if(cb_struct.func) { /* If user's exception handler is present, use it */
if(cb_struct.func) { /*If user's exception handler is present, use it*/
except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id,
s, d, cb_struct.user_data);
}

View File

@ -34,9 +34,9 @@
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5Tpkg.h" /* Datatypes */
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5Tpkg.h" /* Datatypes */
/****************/
@ -372,25 +372,26 @@ H5T_debug(const H5T_t *dt, FILE *stream)
fprintf(stream, "\n");
} /* end else */
} else if(H5T_ENUM == dt->shared->type) {
size_t base_size;
size_t base_size;
/* Enumeration data type */
fprintf(stream, " ");
H5T_debug(dt->shared->parent, stream);
base_size = dt->shared->parent->shared->size;
for(i = 0; i < dt->shared->u.enumer.nmembs; i++) {
size_t k;
/* Enumeration data type */
fprintf(stream, " ");
H5T_debug(dt->shared->parent, stream);
base_size = dt->shared->parent->shared->size;
for(i = 0; i < dt->shared->u.enumer.nmembs; i++) {
size_t k;
fprintf(stream, "\n\"%s\" = 0x", dt->shared->u.enumer.name[i]);
for(k = 0; k < base_size; k++)
fprintf(stream, "%02lx", (unsigned long)(dt->shared->u.enumer.value + (i * base_size) + k));
} /* end for */
fprintf(stream, "\n");
fprintf(stream, "\n\"%s\" = 0x", dt->shared->u.enumer.name[i]);
for(k = 0; k < base_size; k++)
fprintf(stream, "%02lx",
(unsigned long)(dt->shared->u.enumer.value + (i * base_size) + k));
} /* end for */
fprintf(stream, "\n");
} else if(H5T_OPAQUE == dt->shared->type) {
fprintf(stream, ", tag=\"%s\"", dt->shared->u.opaque.tag);
fprintf(stream, ", tag=\"%s\"", dt->shared->u.opaque.tag);
} else {
/* Unknown */
fprintf(stream, "unknown class %d\n", (int)(dt->shared->type));
/* Unknown */
fprintf(stream, "unknown class %d\n", (int)(dt->shared->type));
}
fprintf(stream, "}");

View File

@ -24,17 +24,17 @@
#define H5_INTERFACE_INIT_FUNC H5T_init_enum_interface
#include "H5private.h" /* generic functions */
#include "H5Eprivate.h" /* error handling */
#include "H5Iprivate.h" /* ID functions */
#include "H5MMprivate.h" /* memory management */
#include "H5Tpkg.h" /* data-type functions */
#include "H5private.h" /*generic functions */
#include "H5Eprivate.h" /*error handling */
#include "H5Iprivate.h" /*ID functions */
#include "H5MMprivate.h" /*memory management */
#include "H5Tpkg.h" /*data-type functions */
/* Static local functions */
static char *H5T_enum_nameof(const H5T_t *dt, const void *value,
char *name/*out*/, size_t size);
static char *H5T_enum_nameof(const H5T_t *dt, const void *value, char *name/*out*/,
size_t size);
static herr_t H5T_enum_valueof(const H5T_t *dt, const char *name,
void *value/*out*/);
void *value/*out*/);
/*--------------------------------------------------------------------------
@ -60,40 +60,42 @@ H5T_init_enum_interface(void)
/*-------------------------------------------------------------------------
* Function: H5Tenum_create
* Function: H5Tenum_create
*
* Purpose: Create a new enumeration data type based on the specified
* TYPE, which must be an integer type.
* Purpose: Create a new enumeration data type based on the specified
* TYPE, which must be an integer type.
*
* Return: Success: ID of new enumeration data type
* Return: Success: ID of new enumeration data type
*
* Failure: Negative
* Failure: Negative
*
* Programmer: Robb Matzke
* Programmer: Robb Matzke
* Tuesday, December 22, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
hid_t
H5Tenum_create(hid_t parent_id)
{
H5T_t *parent = NULL; /* base integer data type */
H5T_t *dt = NULL; /* new enumeration data type */
hid_t ret_value; /* return value */
H5T_t *parent = NULL; /*base integer data type */
H5T_t *dt = NULL; /*new enumeration data type */
hid_t ret_value; /*return value */
FUNC_ENTER_API(FAIL)
H5TRACE1("i", "i", parent_id);
/* Check args */
if(NULL == (parent = (H5T_t *)H5I_object_verify(parent_id, H5I_DATATYPE)) || H5T_INTEGER != parent->shared->type)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an integer data type")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an integer data type")
/* Build new type */
if(NULL == (dt = H5T__enum_create(parent)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot create enum type")
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot create enum type")
/* Atomize the type */
if ((ret_value = H5I_register(H5I_DATATYPE, dt, TRUE)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register data type atom")
if ((ret_value=H5I_register(H5I_DATATYPE, dt, TRUE))<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register data type atom")
done:
FUNC_LEAVE_API(ret_value)
@ -101,25 +103,27 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T__enum_create
* Function: H5T__enum_create
*
* Purpose: Private function for H5Tenum_create. Create a new
* Purpose: Private function for H5Tenum_create. Create a new
* enumeration data type based on the specified
* TYPE, which must be an integer type.
* TYPE, which must be an integer type.
*
* Return: Success: new enumeration data type
* Return: Success: new enumeration data type
*
* Failure: NULL
* Failure: NULL
*
* Programmer: Raymond Lu
* Programmer: Raymond Lu
* October 9, 2002
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
H5T_t *
H5T__enum_create(const H5T_t *parent)
{
H5T_t *ret_value; /*new enumeration data type */
H5T_t *ret_value; /*new enumeration data type */
FUNC_ENTER_PACKAGE
@ -139,44 +143,48 @@ done:
/*-------------------------------------------------------------------------
* Function: H5Tenum_insert
* Function: H5Tenum_insert
*
* Purpose: Insert a new enumeration data type member into an enumeration
* type. TYPE is the enumeration type, NAME is the name of the
* new member, and VALUE points to the value of the new member.
* The NAME and VALUE must both be unique within the TYPE. VALUE
* points to data which is of the data type defined when the
* enumeration type was created.
* Purpose: Insert a new enumeration data type member into an enumeration
* type. TYPE is the enumeration type, NAME is the name of the
* new member, and VALUE points to the value of the new member.
* The NAME and VALUE must both be unique within the TYPE. VALUE
* points to data which is of the data type defined when the
* enumeration type was created.
*
* Return: SUCCEED/FAIL
* Return: Success: non-negative
*
* Programmer: Robb Matzke
* Failure: negative
*
* Programmer: Robb Matzke
* Wednesday, December 23, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5Tenum_insert(hid_t type, const char *name, const void *value)
{
H5T_t *dt = NULL;
herr_t ret_value = SUCCEED; /* Return value */
H5T_t *dt=NULL;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE3("e", "i*s*x", type, name, value);
/* Check args */
if(NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
if(H5T_ENUM != dt->shared->type)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
if (!name || !*name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name specified")
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name specified")
if (!value)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value specified")
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value specified")
/* Do work */
if(H5T__enum_insert(dt, name, value) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to insert new enumeration member")
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to insert new enumeration member")
done:
FUNC_LEAVE_API(ret_value)
@ -184,27 +192,31 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T__enum_insert
* Function: H5T__enum_insert
*
* Purpose: Insert a new member having a NAME and VALUE into an
* enumeration data TYPE. The NAME and VALUE must both be
* unique. The VALUE points to data of the data type defined for
* the enumeration base type.
* Purpose: Insert a new member having a NAME and VALUE into an
* enumeration data TYPE. The NAME and VALUE must both be
* unique. The VALUE points to data of the data type defined for
* the enumeration base type.
*
* Return: SUCCEED/FAIL
* Return: Success: non-negative
*
* Programmer: Robb Matzke
* Failure: negative
*
* Programmer: Robb Matzke
* Wednesday, December 23, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5T__enum_insert(const H5T_t *dt, const char *name, const void *value)
{
unsigned i;
char **names = NULL;
uint8_t *values = NULL;
herr_t ret_value = SUCCEED; /* Return value */
unsigned i;
char **names=NULL;
uint8_t *values=NULL;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
@ -213,32 +225,32 @@ H5T__enum_insert(const H5T_t *dt, const char *name, const void *value)
assert(value);
/* The name and value had better not already exist */
for (i = 0; i < dt->shared->u.enumer.nmembs; i++) {
if (!HDstrcmp(dt->shared->u.enumer.name[i], name))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "name redefinition")
if (!HDmemcmp(dt->shared->u.enumer.value+i*dt->shared->size, value, dt->shared->size))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "value redefinition")
for (i=0; i<dt->shared->u.enumer.nmembs; i++) {
if (!HDstrcmp(dt->shared->u.enumer.name[i], name))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "name redefinition")
if (!HDmemcmp(dt->shared->u.enumer.value+i*dt->shared->size, value, dt->shared->size))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "value redefinition")
}
/* Increase table sizes, if necessary */
/* Increase table sizes */
if(dt->shared->u.enumer.nmembs >= dt->shared->u.enumer.nalloc) {
unsigned n = MAX(32, 2 * dt->shared->u.enumer.nalloc);
unsigned n = MAX(32, 2*dt->shared->u.enumer.nalloc);
if(NULL == (names = (char **)H5MM_realloc(dt->shared->u.enumer.name, n * sizeof(char *))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
dt->shared->u.enumer.name = names;
if(NULL == (names = (char **)H5MM_realloc(dt->shared->u.enumer.name, n * sizeof(char *))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
dt->shared->u.enumer.name = names;
if(NULL == (values = (uint8_t *)H5MM_realloc(dt->shared->u.enumer.value, n * dt->shared->size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
dt->shared->u.enumer.value = values;
dt->shared->u.enumer.nalloc = n;
if(NULL == (values = (uint8_t *)H5MM_realloc(dt->shared->u.enumer.value, n * dt->shared->size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
dt->shared->u.enumer.value = values;
dt->shared->u.enumer.nalloc = n;
}
/* Insert new member at end of member arrays */
dt->shared->u.enumer.sorted = H5T_SORT_NONE;
i = dt->shared->u.enumer.nmembs++;
dt->shared->u.enumer.name[i] = H5MM_xstrdup(name);
HDmemcpy(dt->shared->u.enumer.value + (i * dt->shared->size), value, dt->shared->size);
HDmemcpy(dt->shared->u.enumer.value+i*dt->shared->size, value, dt->shared->size);
done:
FUNC_LEAVE_NOAPI(ret_value)
@ -246,61 +258,63 @@ done:
/*-------------------------------------------------------------------------
* Function: H5Tget_member_value
* Function: H5Tget_member_value
*
* Purpose: Return the value for an enumeration data type member.
* Purpose: Return the value for an enumeration data type member.
*
* Return: Success: SUCCEED
* VALUE memory contains member value.
* Return: Success: non-negative with the member value copied
* into the memory pointed to by VALUE.
*
* Failure: FAIL
* VALUE memory is undefined.
* Failure: negative, VALUE memory is undefined.
*
* Programmer: Robb Matzke
* Programmer: Robb Matzke
* Wednesday, December 23, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5Tget_member_value(hid_t type, unsigned membno, void *value/*out*/)
{
H5T_t *dt = NULL;
herr_t ret_value = SUCCEED; /* Return value */
H5T_t *dt=NULL;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE3("e", "iIux", type, membno, value);
if(NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
if(H5T_ENUM != dt->shared->type)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for data type class")
if (membno >= dt->shared->u.enumer.nmembs)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid member number")
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for data type class")
if (membno>=dt->shared->u.enumer.nmembs)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid member number")
if (!value)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "null value buffer")
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "null value buffer")
if(H5T__get_member_value(dt, membno, value) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get member value")
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get member value")
done:
FUNC_LEAVE_API(ret_value)
}
/*-------------------------------------------------------------------------
* Function: H5T__get_member_value
* Function: H5T__get_member_value
*
* Purpose: Private function for H5T__get_member_value. Return the
* Purpose: Private function for H5T__get_member_value. Return the
* value for an enumeration data type member.
*
* Return: Success: SUCCEED
* VALUE memory contains member value.
* Return: Success: non-negative with the member value copied
* into the memory pointed to by VALUE.
*
* Failure: FAIL
* VALUE memory is undefined.
* Failure: negative, VALUE memory is undefined.
*
* Programmer: Raymond Lu
* Programmer: Raymond Lu
* October 9, 2002
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
@ -319,46 +333,48 @@ H5T__get_member_value(const H5T_t *dt, unsigned membno, void *value/*out*/)
/*-------------------------------------------------------------------------
* Function: H5Tenum_nameof
* Function: H5Tenum_nameof
*
* Purpose: Finds the symbol name that corresponds to the specified VALUE
* of an enumeration data type TYPE. At most SIZE characters of
* the symbol name are copied into the NAME buffer. If the
* entire symbol anem and null terminator do not fit in the NAME
* buffer then as many characters as possible are copied (not
* null terminated) and the function fails.
* Purpose: Finds the symbol name that corresponds to the specified VALUE
* of an enumeration data type TYPE. At most SIZE characters of
* the symbol name are copied into the NAME buffer. If the
* entire symbol anem and null terminator do not fit in the NAME
* buffer then as many characters as possible are copied (not
* null terminated) and the function fails.
*
* Return: Success: SUCCEED
* Return: Success: Non-negative.
*
* Failure: FAIL
* name[0] is set to null if size > 0
* Failure: Negative, first character of NAME is set to
* null if SIZE allows it.
*
* Programmer: Robb Matzke
* Programmer: Robb Matzke
* Monday, January 4, 1999
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5Tenum_nameof(hid_t type, const void *value, char *name/*out*/, size_t size)
{
H5T_t *dt = NULL;
herr_t ret_value = SUCCEED; /* Return value */
H5T_t *dt = NULL;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE4("e", "i*xxz", type, value, name, size);
/* Check args */
if(NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
if(H5T_ENUM != dt->shared->type)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
if (!value)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value supplied")
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value supplied")
if (!name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name buffer supplied")
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name buffer supplied")
if (NULL == H5T_enum_nameof(dt, value, name, size))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "nameof query failed")
if (NULL==H5T_enum_nameof(dt, value, name, size))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "nameof query failed")
done:
FUNC_LEAVE_API(ret_value)
@ -366,37 +382,41 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T_enum_nameof
* Function: H5T_enum_nameof
*
* Purpose: Finds the symbol name that corresponds the the specified
* VALUE of an enumeration data type DT. At most SIZE characters
* of the symbol name are copied into the NAME buffer. If the
* entire symbol name and null terminator do not fit in the NAME
* buffer then as many characters as possible are copied and the
* function returns failure.
* Purpose: Finds the symbol name that corresponds the the specified
* VALUE of an enumeration data type DT. At most SIZE characters
* of the symbol name are copied into the NAME buffer. If the
* entire symbol name and null terminator do not fit in the NAME
* buffer then as many characters as possible are copied and the
* function returns failure.
*
* If NAME is the null pointer and SIZE is zero then enough
* space is allocated to hold the result and a pointer to that
* memory is returned.
* If NAME is the null pointer and SIZE is zero then enough
* space is allocated to hold the result and a pointer to that
* memory is returned.
*
* Return: Success: Pointer to NAME
* Return: Success: Pointer to NAME
*
* Failure: NULL
* name[0] is set to null if size > 0
* Failure: NULL, name[0] is set to null.
*
* Programmer: Robb Matzke
* Programmer: Robb Matzke
* Monday, January 4, 1999
*
* Modifications:
* Raymond Lu
* Wednesday, Febuary 9, 2005
* Made a copy of original datatype and do sorting and search
* on that copy, to protect the original order of members.
*-------------------------------------------------------------------------
*/
static char *
H5T_enum_nameof(const H5T_t *dt, const void *value, char *name/*out*/, size_t size)
{
H5T_t *copied_dt = NULL; /* Do sorting in copied datatype */
unsigned lt, md = 0, rt; /* Indices for binary search */
int cmp = -1; /* Comparison result */
hbool_t alloc_name = FALSE; /* Whether name has been allocated */
char *ret_value; /* Return value */
H5T_t *copied_dt = NULL; /* Do sorting in copied datatype */
unsigned lt, md = 0, rt; /* Indices for binary search */
int cmp = (-1); /* Comparison result */
hbool_t alloc_name = FALSE; /* Whether name has been allocated */
char *ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@ -415,36 +435,37 @@ H5T_enum_nameof(const H5T_t *dt, const void *value, char *name/*out*/, size_t si
/* Do a binary search over the values to find the correct one. Do sorting
* and search on the copied datatype to protect the original order. */
if(NULL == (copied_dt = H5T_copy(dt, H5T_COPY_ALL)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy data type")
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy data type")
if(H5T__sort_value(copied_dt, NULL) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOMPARE, NULL, "value sort failed")
lt = 0;
rt = copied_dt->shared->u.enumer.nmembs;
while(lt < rt) {
md = (lt + rt) / 2;
cmp = HDmemcmp(value, copied_dt->shared->u.enumer.value + (md * copied_dt->shared->size), copied_dt->shared->size);
if(cmp < 0)
rt = md;
else if(cmp > 0)
lt = md + 1;
else
break;
md = (lt + rt) / 2;
cmp = HDmemcmp(value, copied_dt->shared->u.enumer.value + md * copied_dt->shared->size, copied_dt->shared->size);
if(cmp < 0)
rt = md;
else if(cmp > 0)
lt = md + 1;
else
break;
} /* end while */
/* Value was not yet defined */
/* Value was not yet defined. This fixes bug # 774, 2002/06/05 EIP */
if(cmp != 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, "value is currently not defined")
/* Save result name */
if(!name) {
if(NULL == (name = (char *)H5MM_malloc(HDstrlen(copied_dt->shared->u.enumer.name[md]) + 1)))
if(NULL == (name = (char *)H5MM_malloc(
HDstrlen(copied_dt->shared->u.enumer.name[md]) + 1)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
alloc_name = TRUE;
} /* end if */
HDstrncpy(name, copied_dt->shared->u.enumer.name[md], size);
if(HDstrlen(copied_dt->shared->u.enumer.name[md]) >= size)
HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, NULL, "name has been truncated")
HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, NULL, "name has been truncated")
/* Set return value */
ret_value = name;
@ -461,41 +482,48 @@ done:
/*-------------------------------------------------------------------------
* Function: H5Tenum_valueof
* Function: H5Tenum_valueof
*
* Purpose: Finds the value that corresponds to the specified NAME f an
* enumeration TYPE. The VALUE argument should be at least as
* large as the value of H5Tget_size(type) in order to hold the
* result.
* Purpose: Finds the value that corresponds to the specified NAME f an
* enumeration TYPE. The VALUE argument should be at least as
* large as the value of H5Tget_size(type) in order to hold the
* result.
*
* Return: SUCCEED/FAIL
* Return: Success: Non-negative
*
* Programmer: Robb Matzke
* Failure: Negative
*
* Programmer: Robb Matzke
* Monday, January 4, 1999
*
* Modifications:
* Raymond Lu
* Wednesday, Febuary 9, 2005
* Made a copy of original datatype and do sorting and search
* on that copy, to protect the original order of members.
*-------------------------------------------------------------------------
*/
herr_t
H5Tenum_valueof(hid_t type, const char *name, void *value/*out*/)
{
H5T_t *dt;
herr_t ret_value = SUCCEED; /* Return value */
H5T_t *dt;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE3("e", "i*sx", type, name, value);
/* Check args */
if(NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
if(H5T_ENUM != dt->shared->type)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
if(!name || !*name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
if(!value)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value buffer")
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value buffer")
if(H5T_enum_valueof(dt, name, value) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "valueof query failed")
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "valueof query failed")
done:
FUNC_LEAVE_API(ret_value)
@ -503,31 +531,34 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T_enum_valueof
* Function: H5T_enum_valueof
*
* Purpose: Finds the value that corresponds the the specified symbol
* NAME of an enumeration data type DT and copy it to the VALUE
* result buffer. The VALUE should be allocated by the caller to
* be large enough for the result.
* Purpose: Finds the value that corresponds the the specified symbol
* NAME of an enumeration data type DT and copy it to the VALUE
* result buffer. The VALUE should be allocated by the caller to
* be large enough for the result.
*
* Return: Success: SUCCEED
* VALUE contains the enum value.
* Return: Success: Non-negative, value stored in VALUE.
*
* Failure: FAIL
* VALUE is undefined.
* Failure: Negative, VALUE is undefined.
*
* Programmer: Robb Matzke
* Programmer: Robb Matzke
* Monday, January 4, 1999
*
* Modifications:
* Raymond Lu
* Wednesday, Febuary 9, 2005
* Made a copy of original datatype and do sorting and search
* on that copy, to protect the original order of members.
*-------------------------------------------------------------------------
*/
static herr_t
H5T_enum_valueof(const H5T_t *dt, const char *name, void *value/*out*/)
{
unsigned lt, md = 0, rt; /* indices for binary search */
int cmp = -1; /* comparison result */
H5T_t *copied_dt = NULL; /* do sorting in copied datatype */
herr_t ret_value = SUCCEED; /* Return value */
unsigned lt, md=0, rt; /*indices for binary search */
int cmp=(-1); /*comparison result */
H5T_t *copied_dt = NULL; /*do sorting in copied datatype */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@ -542,27 +573,27 @@ H5T_enum_valueof(const H5T_t *dt, const char *name, void *value/*out*/)
/* Do a binary search over the names to find the correct one. Do sorting
* and search on the copied datatype to protect the original order. */
if (NULL == (copied_dt = H5T_copy(dt, H5T_COPY_ALL)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy data type");
if (NULL==(copied_dt=H5T_copy(dt, H5T_COPY_ALL)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy data type");
if(H5T__sort_name(copied_dt, NULL) < 0)
HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOMPARE, FAIL, "value sort failed")
lt = 0;
rt = copied_dt->shared->u.enumer.nmembs;
while (lt < rt) {
md = (lt + rt) / 2;
cmp = HDstrcmp(name, copied_dt->shared->u.enumer.name[md]);
if (cmp < 0) {
rt = md;
} else if (cmp>0) {
lt = md + 1;
} else {
break;
}
while (lt<rt) {
md = (lt+rt)/2;
cmp = HDstrcmp(name, copied_dt->shared->u.enumer.name[md]);
if (cmp<0) {
rt = md;
} else if (cmp>0) {
lt = md+1;
} else {
break;
}
}
/* Value was not yet defined. */
if (cmp != 0)
/* Value was not yet defined. This fixes bug # 774, 2002/06/05 EIP */
if (cmp!=0)
HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, FAIL, "string doesn't exist in the enumeration type")
HDmemcpy(value, copied_dt->shared->u.enumer.value+md*copied_dt->shared->size, copied_dt->shared->size);
@ -574,3 +605,4 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
}

View File

@ -18,17 +18,17 @@
* enumerated & compound datatypes in the H5T interface.
*/
#define H5T_PACKAGE /* suppress error about including H5Tpkg */
#define H5T_PACKAGE /*suppress error about including H5Tpkg */
/* Interface initialization */
#define H5_INTERFACE_INIT_FUNC H5T_init_fields_interface
#define H5_INTERFACE_INIT_FUNC H5T_init_fields_interface
#include "H5private.h" /* generic functions */
#include "H5Eprivate.h" /* error handling */
#include "H5Iprivate.h" /* ID functions */
#include "H5MMprivate.h" /* memory management */
#include "H5Tpkg.h" /* data-type functions */
#include "H5private.h" /*generic functions */
#include "H5Eprivate.h" /*error handling */
#include "H5Iprivate.h" /*ID functions */
#include "H5MMprivate.h" /*memory management */
#include "H5Tpkg.h" /*data-type functions */
/*--------------------------------------------------------------------------
@ -54,35 +54,40 @@ H5T_init_fields_interface(void)
/*-------------------------------------------------------------------------
* Function: H5Tget_nmembers
* Function: H5Tget_nmembers
*
* Purpose: Determines how many members TYPE_ID has. The type must be
* either a compound datatype or an enumeration datatype.
* Purpose: Determines how many members TYPE_ID has. The type must be
* either a compound datatype or an enumeration datatype.
*
* Return: Success: Number of members defined in the datatype.
* Return: Success: Number of members defined in the datatype.
*
* Failure: Negative
* Failure: Negative
*
* Programmer: Robb Matzke
* Monday, December 8, 1997
* Errors:
*
* Programmer: Robb Matzke
* Monday, December 8, 1997
*
* Modifications:
* Robb Matzke, 22 Dec 1998
* Also works with enumeration datatypes.
*-------------------------------------------------------------------------
*/
int
H5Tget_nmembers(hid_t type_id)
{
H5T_t *dt; /* Datatype to query */
int ret_value; /* Return value */
H5T_t *dt; /* Datatype to query */
int ret_value; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE1("Is", "i", type_id);
/* Check args */
if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
if((ret_value = H5T_get_nmembers(dt)) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "cannot return member number")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "cannot return member number")
done:
FUNC_LEAVE_API(ret_value)
@ -90,36 +95,40 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T_get_nmembers
* Function: H5T_get_nmembers
*
* Purpose: Private function for H5Tget_nmembers. Determines how many
* Purpose: Private function for H5Tget_nmembers. Determines how many
* members DTYPE has. The type must be either a compound data
* type or an enumeration datatype.
*
* Return: Success: Number of members defined in the datatype.
* Return: Success: Number of members defined in the datatype.
*
* Failure: Negative
* Failure: Negative
*
* Errors:
*
* Programmer: Raymond Lu
* October 8, 2002
* October 8, 2002
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
int
H5T_get_nmembers(const H5T_t *dt)
{
int ret_value;
int ret_value;
FUNC_ENTER_NOAPI(FAIL)
HDassert(dt);
if(H5T_COMPOUND == dt->shared->type)
ret_value = (int)dt->shared->u.compnd.nmembs;
ret_value = (int)dt->shared->u.compnd.nmembs;
else if(H5T_ENUM == dt->shared->type)
ret_value = (int)dt->shared->u.enumer.nmembs;
ret_value = (int)dt->shared->u.enumer.nmembs;
else
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "operation not supported for type class")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "operation not supported for type class")
done:
FUNC_LEAVE_NOAPI(ret_value)
@ -127,65 +136,69 @@ done:
/*-------------------------------------------------------------------------
* Function: H5Tget_member_name
* Function: H5Tget_member_name
*
* Purpose: Returns the name of a member of a compound or enumeration
* datatype. Members are stored in no particular order with
* numbers 0 through N-1 where N is the value returned by
* H5Tget_nmembers().
* Purpose: Returns the name of a member of a compound or enumeration
* datatype. Members are stored in no particular order with
* numbers 0 through N-1 where N is the value returned by
* H5Tget_nmembers().
*
* Return: Success: Ptr to a string allocated with malloc(). The
* caller is responsible for freeing the string.
* Return: Success: Ptr to a string allocated with malloc(). The
* caller is responsible for freeing the string.
*
* Failure: NULL
* Failure: NULL
*
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
*
* Modifications:
* Robb Matzke, 22 Dec 1998
* Also works with enumeration datatypes.
*-------------------------------------------------------------------------
*/
char *
H5Tget_member_name(hid_t type_id, unsigned membno)
{
H5T_t *dt = NULL;
char *ret_value;
H5T_t *dt = NULL;
char *ret_value;
FUNC_ENTER_API(NULL)
/* Check args */
if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a datatype")
if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a datatype")
if(NULL == (ret_value = H5T__get_member_name(dt, membno)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "unable to get member name")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Tget_member_name */
}
/*-------------------------------------------------------------------------
* Function: H5T__get_member_name
* Function: H5T__get_member_name
*
* Purpose: Private function for H5Tget_member_name. Returns the name
* Purpose: Private function for H5Tget_member_name. Returns the name
* of a member of a compound or enumeration datatype. Members
* are stored in no particular order with numbers 0 through
* N-1 where N is the value returned by H5Tget_nmembers().
*
* Return: Success: Ptr to a string allocated with malloc(). The
* caller is responsible for freeing the string.
* Return: Success: Ptr to a string allocated with malloc(). The
* caller is responsible for freeing the string.
*
* Failure: NULL
* Failure: NULL
*
* Programmer: Raymond Lu
* Programmer: Raymond Lu
* October 9, 2002
*
* Modifications:
*-------------------------------------------------------------------------
*/
char *
H5T__get_member_name(H5T_t const *dt, unsigned membno)
{
char *ret_value;
char *ret_value;
FUNC_ENTER_PACKAGE
@ -217,11 +230,11 @@ H5T__get_member_name(H5T_t const *dt, unsigned membno)
case H5T_NCLASSES:
default:
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "operation not supported for type class")
}
} /*lint !e788 All appropriate cases are covered */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T__get_member_name */
}
/*-------------------------------------------------------------------------
@ -291,30 +304,30 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T__sort_value
* Function: H5T__sort_value
*
* Purpose: Sorts the members of a compound datatype by their offsets;
* sorts the members of an enum type by their values. This even
* works for locked datatypes since it doesn't change the value
* of the type. MAP is an optional parallel integer array which
* is also swapped along with members of DT.
* Purpose: Sorts the members of a compound datatype by their offsets;
* sorts the members of an enum type by their values. This even
* works for locked datatypes since it doesn't change the value
* of the type. MAP is an optional parallel integer array which
* is also swapped along with members of DT.
*
* Return: SUCCEED/FAIL
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
*
*-------------------------------------------------------------------------
*/
herr_t
H5T__sort_value(const H5T_t *dt, int *map)
{
unsigned nmembs; /* Number of members for datatype */
size_t size;
hbool_t swapped; /* Whether we've swapped fields */
uint8_t tbuf[32];
unsigned i, j; /* Local index variables */
herr_t ret_value = SUCCEED; /* Return value */
unsigned nmembs; /* Number of members for datatype */
size_t size;
hbool_t swapped; /* Whether we've swapped fields */
uint8_t tbuf[32];
unsigned i, j; /* Local index variables */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE_NOERR
@ -324,69 +337,69 @@ H5T__sort_value(const H5T_t *dt, int *map)
/* Use a bubble sort because we can short circuit */
if(H5T_COMPOUND == dt->shared->type) {
if(H5T_SORT_VALUE != dt->shared->u.compnd.sorted) {
dt->shared->u.compnd.sorted = H5T_SORT_VALUE;
nmembs = dt->shared->u.compnd.nmembs;
for(i = nmembs - 1, swapped = TRUE; i > 0 && swapped; --i) {
for(j = 0, swapped = FALSE; j < i; j++) {
if(dt->shared->u.compnd.memb[j].offset > dt->shared->u.compnd.memb[j + 1].offset) {
if(H5T_SORT_VALUE != dt->shared->u.compnd.sorted) {
dt->shared->u.compnd.sorted = H5T_SORT_VALUE;
nmembs = dt->shared->u.compnd.nmembs;
for(i = nmembs - 1, swapped = TRUE; i > 0 && swapped; --i) {
for(j = 0, swapped = FALSE; j < i; j++) {
if(dt->shared->u.compnd.memb[j].offset > dt->shared->u.compnd.memb[j + 1].offset) {
H5T_cmemb_t tmp = dt->shared->u.compnd.memb[j];
dt->shared->u.compnd.memb[j] = dt->shared->u.compnd.memb[j + 1];
dt->shared->u.compnd.memb[j + 1] = tmp;
if(map) {
int x = map[j];
dt->shared->u.compnd.memb[j] = dt->shared->u.compnd.memb[j + 1];
dt->shared->u.compnd.memb[j + 1] = tmp;
if(map) {
int x = map[j];
map[j] = map[j + 1];
map[j + 1] = x;
} /* end if */
swapped = TRUE;
} /* end if */
} /* end for */
} /* end for */
map[j] = map[j + 1];
map[j + 1] = x;
} /* end if */
swapped = TRUE;
} /* end if */
} /* end for */
} /* end for */
#ifndef NDEBUG
/* I never trust a sort :-) -RPM */
for(i = 0; i < (nmembs - 1); i++)
HDassert(dt->shared->u.compnd.memb[i].offset < dt->shared->u.compnd.memb[i + 1].offset);
/* I never trust a sort :-) -RPM */
for(i = 0; i < (nmembs - 1); i++)
HDassert(dt->shared->u.compnd.memb[i].offset < dt->shared->u.compnd.memb[i + 1].offset);
#endif
} /* end if */
} /* end if */
} else if(H5T_ENUM == dt->shared->type) {
if(H5T_SORT_VALUE != dt->shared->u.enumer.sorted) {
dt->shared->u.enumer.sorted = H5T_SORT_VALUE;
nmembs = dt->shared->u.enumer.nmembs;
size = dt->shared->size;
HDassert(size <= sizeof(tbuf));
for(i = (nmembs - 1), swapped = TRUE; i > 0 && swapped; --i) {
for(j = 0, swapped = FALSE; j < i; j++) {
if(HDmemcmp(dt->shared->u.enumer.value + (j * size), dt->shared->u.enumer.value + ((j + 1) * size), size) > 0) {
/* Swap names */
char *tmp = dt->shared->u.enumer.name[j];
dt->shared->u.enumer.name[j] = dt->shared->u.enumer.name[j + 1];
dt->shared->u.enumer.name[j + 1] = tmp;
if(H5T_SORT_VALUE != dt->shared->u.enumer.sorted) {
dt->shared->u.enumer.sorted = H5T_SORT_VALUE;
nmembs = dt->shared->u.enumer.nmembs;
size = dt->shared->size;
HDassert(size <= sizeof(tbuf));
for(i = (nmembs - 1), swapped = TRUE; i > 0 && swapped; --i) {
for(j = 0, swapped = FALSE; j < i; j++) {
if(HDmemcmp(dt->shared->u.enumer.value + (j * size), dt->shared->u.enumer.value + ((j + 1) * size), size) > 0) {
/* Swap names */
char *tmp = dt->shared->u.enumer.name[j];
dt->shared->u.enumer.name[j] = dt->shared->u.enumer.name[j + 1];
dt->shared->u.enumer.name[j + 1] = tmp;
/* Swap values */
HDmemcpy(tbuf, dt->shared->u.enumer.value + (j * size), size);
HDmemcpy(dt->shared->u.enumer.value + (j * size),
dt->shared->u.enumer.value + ((j + 1) * size), size);
HDmemcpy(dt->shared->u.enumer.value + ((j + 1) * size), tbuf, size);
/* Swap values */
HDmemcpy(tbuf, dt->shared->u.enumer.value + (j * size), size);
HDmemcpy(dt->shared->u.enumer.value + (j * size),
dt->shared->u.enumer.value + ((j + 1) * size), size);
HDmemcpy(dt->shared->u.enumer.value + ((j + 1) * size), tbuf, size);
/* Swap map */
if(map) {
int x = map[j];
/* Swap map */
if(map) {
int x = map[j];
map[j] = map[j + 1];
map[j + 1] = x;
} /* end if */
map[j] = map[j + 1];
map[j + 1] = x;
} /* end if */
swapped = TRUE;
} /* end if */
} /* end for */
} /* end for */
swapped = TRUE;
} /* end if */
} /* end for */
} /* end for */
#ifndef NDEBUG
/* I never trust a sort :-) -RPM */
for(i = 0; i < (nmembs - 1); i++)
HDassert(HDmemcmp(dt->shared->u.enumer.value + (i * size), dt->shared->u.enumer.value + ((i + 1) * size), size) < 0);
/* I never trust a sort :-) -RPM */
for(i = 0; i < (nmembs - 1); i++)
HDassert(HDmemcmp(dt->shared->u.enumer.value + (i * size), dt->shared->u.enumer.value + ((i + 1) * size), size) < 0);
#endif
} /* end if */
} /* end if */
} /* end else */
FUNC_LEAVE_NOAPI(ret_value)
@ -394,97 +407,106 @@ H5T__sort_value(const H5T_t *dt, int *map)
/*-------------------------------------------------------------------------
* Function: H5T__sort_name
* Function: H5T__sort_name
*
* Purpose: Sorts members of a compound or enumeration datatype by their
* names. This even works for locked datatypes since it doesn't
* change the value of the types.
* Purpose: Sorts members of a compound or enumeration datatype by their
* names. This even works for locked datatypes since it doesn't
* change the value of the types.
*
* Return: SUCCEED (can't fail)
* Return: Success: Non-negative
*
* Programmer: Robb Matzke
* Failure: Negative
*
* Programmer: Robb Matzke
* Monday, January 4, 1999
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5T__sort_name(const H5T_t *dt, int *map)
{
unsigned i, j, nmembs;
size_t size;
hbool_t swapped;
uint8_t tbuf[32];
unsigned i, j, nmembs;
size_t size;
hbool_t swapped;
uint8_t tbuf[32];
FUNC_ENTER_PACKAGE_NOERR
/* Check args */
HDassert(dt);
HDassert(H5T_COMPOUND == dt->shared->type || H5T_ENUM == dt->shared->type);
assert(dt);
assert(H5T_COMPOUND==dt->shared->type || H5T_ENUM==dt->shared->type);
/* Use a bubble sort because we can short circuit */
if(H5T_COMPOUND == dt->shared->type) {
if(H5T_SORT_NAME != dt->shared->u.compnd.sorted) {
dt->shared->u.compnd.sorted = H5T_SORT_NAME;
nmembs = dt->shared->u.compnd.nmembs;
for(i = nmembs - 1, swapped = TRUE; i > 0 && swapped; --i) {
for(j = 0, swapped = FALSE; j < i; j++) {
if(HDstrcmp(dt->shared->u.compnd.memb[j].name, dt->shared->u.compnd.memb[j+1].name) > 0) {
H5T_cmemb_t tmp = dt->shared->u.compnd.memb[j];
dt->shared->u.compnd.memb[j] = dt->shared->u.compnd.memb[j+1];
dt->shared->u.compnd.memb[j+1] = tmp;
swapped = TRUE;
if(map) {
int x = map[j];
map[j] = map[j+1];
map[j+1] = x;
} /* end if */
} /* end if */
} /* end for */
} /* end for */
if (H5T_COMPOUND==dt->shared->type) {
if (H5T_SORT_NAME!=dt->shared->u.compnd.sorted) {
dt->shared->u.compnd.sorted = H5T_SORT_NAME;
nmembs = dt->shared->u.compnd.nmembs;
for (i=nmembs-1, swapped=TRUE; i>0 && swapped; --i) {
for (j=0, swapped=FALSE; j<i; j++) {
if (HDstrcmp(dt->shared->u.compnd.memb[j].name,
dt->shared->u.compnd.memb[j+1].name)>0) {
H5T_cmemb_t tmp = dt->shared->u.compnd.memb[j];
dt->shared->u.compnd.memb[j] = dt->shared->u.compnd.memb[j+1];
dt->shared->u.compnd.memb[j+1] = tmp;
swapped = TRUE;
if (map) {
int x = map[j];
map[j] = map[j+1];
map[j+1] = x;
}
}
}
}
#ifndef NDEBUG
/* I never trust a sort :-) -RPM */
for(i = 0; i < nmembs - 1; i++)
HDassert(HDstrcmp(dt->shared->u.compnd.memb[i].name, dt->shared->u.compnd.memb[i+1].name) < 0);
/* I never trust a sort :-) -RPM */
for (i=0; i<nmembs-1; i++) {
assert(HDstrcmp(dt->shared->u.compnd.memb[i].name,
dt->shared->u.compnd.memb[i+1].name)<0);
}
#endif
} /* end if */
} else if(H5T_ENUM == dt->shared->type) {
if(H5T_SORT_NAME != dt->shared->u.enumer.sorted) {
dt->shared->u.enumer.sorted = H5T_SORT_NAME;
nmembs = dt->shared->u.enumer.nmembs;
size = dt->shared->size;
HDassert(size <= sizeof(tbuf));
for(i = nmembs - 1, swapped = TRUE; i > 0 && swapped; --i) {
for(j = 0, swapped = FALSE; j < i; j++) {
if(HDstrcmp(dt->shared->u.enumer.name[j], dt->shared->u.enumer.name[j+1]) > 0) {
/* Swap names */
char *tmp = dt->shared->u.enumer.name[j];
dt->shared->u.enumer.name[j] = dt->shared->u.enumer.name[j+1];
dt->shared->u.enumer.name[j+1] = tmp;
}
} else if (H5T_ENUM==dt->shared->type) {
if (H5T_SORT_NAME!=dt->shared->u.enumer.sorted) {
dt->shared->u.enumer.sorted = H5T_SORT_NAME;
nmembs = dt->shared->u.enumer.nmembs;
size = dt->shared->size;
assert(size<=sizeof(tbuf));
for (i=nmembs-1, swapped=TRUE; i>0 && swapped; --i) {
for (j=0, swapped=FALSE; j<i; j++) {
if (HDstrcmp(dt->shared->u.enumer.name[j],
dt->shared->u.enumer.name[j+1])>0) {
/* Swap names */
char *tmp = dt->shared->u.enumer.name[j];
dt->shared->u.enumer.name[j] = dt->shared->u.enumer.name[j+1];
dt->shared->u.enumer.name[j+1] = tmp;
/* Swap values */
HDmemcpy(tbuf, dt->shared->u.enumer.value+j * size, size);
HDmemcpy(dt->shared->u.enumer.value + j * size,
dt->shared->u.enumer.value + (j+1) * size, size);
HDmemcpy(dt->shared->u.enumer.value + (j+1) * size, tbuf, size);
/* Swap values */
HDmemcpy(tbuf, dt->shared->u.enumer.value+j*size, size);
HDmemcpy(dt->shared->u.enumer.value+j*size,
dt->shared->u.enumer.value+(j+1)*size, size);
HDmemcpy(dt->shared->u.enumer.value+(j+1)*size, tbuf, size);
/* Swap map */
if(map) {
int x = map[j];
map[j] = map[j+1];
map[j+1] = x;
} /* end if */
/* Swap map */
if (map) {
int x = map[j];
map[j] = map[j+1];
map[j+1] = x;
}
swapped = TRUE;
} /* end if */
} /* end for */
}
swapped = TRUE;
}
}
}
#ifndef NDEBUG
/* I never trust a sort :-) -RPM */
for(i = 0; i < nmembs - 1; i++)
HDassert(HDstrcmp(dt->shared->u.enumer.name[i], dt->shared->u.enumer.name[i+1]) < 0);
/* I never trust a sort :-) -RPM */
for (i=0; i<nmembs-1; i++)
assert(HDstrcmp(dt->shared->u.enumer.name[i], dt->shared->u.enumer.name[i+1])<0);
#endif
} /* end if */
} /* end if */
}
}
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5T__sort_name() */
}

View File

@ -133,39 +133,43 @@ done:
/*-------------------------------------------------------------------------
* Function: H5Tset_sign
* Function: H5Tset_sign
*
* Purpose: Sets the sign property for an integer.
* Purpose: Sets the sign property for an integer.
*
* Return: SUCCEED/FAIL
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
*
* Modifications:
* Robb Matzke, 22 Dec 1998
* Also works with derived datatypes.
*
*-------------------------------------------------------------------------
*/
herr_t
H5Tset_sign(hid_t type_id, H5T_sign_t sign)
{
H5T_t *dt = NULL;
herr_t ret_value = SUCCEED; /* Return value */
H5T_t *dt = NULL;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE2("e", "iTs", type_id, sign);
/* Check args */
if(NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an integer datatype")
if(H5T_STATE_TRANSIENT != dt->shared->state)
HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "datatype is read-only")
if(sign < H5T_SGN_NONE || sign >= H5T_NSGN)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal sign type")
if(H5T_ENUM == dt->shared->type && dt->shared->u.enumer.nmembs > 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined")
while(dt->shared->parent)
if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an integer datatype")
if (H5T_STATE_TRANSIENT!=dt->shared->state)
HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "datatype is read-only")
if (sign < H5T_SGN_NONE || sign >= H5T_NSGN)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal sign type")
if (H5T_ENUM==dt->shared->type && dt->shared->u.enumer.nmembs>0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined")
while (dt->shared->parent)
dt = dt->shared->parent; /*defer to parent*/
if(H5T_INTEGER != dt->shared->type)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for datatype class")
if (H5T_INTEGER!=dt->shared->type)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for datatype class")
/* Commit */
dt->shared->u.atomic.u.i.sign = sign;

View File

@ -18,16 +18,16 @@
* the datatype offset for the H5T interface.
*/
#define H5T_PACKAGE /* suppress error about including H5Tpkg */
#define H5T_PACKAGE /*suppress error about including H5Tpkg */
/* Interface initialization */
#define H5_INTERFACE_INIT_FUNC H5T_init_offset_interface
#define H5_INTERFACE_INIT_FUNC H5T_init_offset_interface
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5Iprivate.h" /* IDs */
#include "H5Tpkg.h" /* Datatypes */
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5Iprivate.h" /* IDs */
#include "H5Tpkg.h" /* Datatypes */
/* Static local functions */
static herr_t H5T_set_offset(const H5T_t *dt, size_t offset);
@ -157,64 +157,68 @@ done:
/*-------------------------------------------------------------------------
* Function: H5Tset_offset
* Function: H5Tset_offset
*
* Purpose: Sets the bit offset of the first significant bit. The
* signficant bits of an atomic datum can be offset from the
* beginning of the memory for that datum by an amount of
* padding. The `offset' property specifies the number of bits
* of padding that appear to the "right of" the value. That is,
* if we have a 32-bit datum with 16-bits of precision having
* the value 0x1122 then it will be layed out in memory as (from
* small byte address toward larger byte addresses):
* Purpose: Sets the bit offset of the first significant bit. The
* signficant bits of an atomic datum can be offset from the
* beginning of the memory for that datum by an amount of
* padding. The `offset' property specifies the number of bits
* of padding that appear to the "right of" the value. That is,
* if we have a 32-bit datum with 16-bits of precision having
* the value 0x1122 then it will be layed out in memory as (from
* small byte address toward larger byte addresses):
*
* Big Big Little Little
* Endian Endian Endian Endian
* offset = 0 offset = 16 offset = 0 offset = 16
* Big Big Little Little
* Endian Endian Endian Endian
* offset=0 offset=16 offset=0 offset=16
*
* 0: [ pad] [0x11] [0x22] [ pad]
* 1: [ pad] [0x22] [0x11] [ pad]
* 2: [0x11] [ pad] [ pad] [0x22]
* 3: [0x22] [ pad] [ pad] [0x11]
* 0: [ pad] [0x11] [0x22] [ pad]
* 1: [ pad] [0x22] [0x11] [ pad]
* 2: [0x11] [ pad] [ pad] [0x22]
* 3: [0x22] [ pad] [ pad] [0x11]
*
* If the offset is incremented then the total size is
* incremented also if necessary to prevent significant bits of
* the value from hanging over the edge of the data type.
* If the offset is incremented then the total size is
* incremented also if necessary to prevent significant bits of
* the value from hanging over the edge of the data type.
*
* The offset of an H5T_STRING cannot be set to anything but
* zero.
* The offset of an H5T_STRING cannot be set to anything but
* zero.
*
* Return: SUCCEED/FAIL
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
*
* Modifications:
* Robb Matzke, 22 Dec 1998
* Moved real work to a private function.
*
*-------------------------------------------------------------------------
*/
herr_t
H5Tset_offset(hid_t type_id, size_t offset)
{
H5T_t *dt;
herr_t ret_value = SUCCEED; /* Return value */
H5T_t *dt;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE2("e", "iz", type_id, offset);
/* Check args */
if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an atomic data type")
if(H5T_STATE_TRANSIENT != dt->shared->state)
HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only")
if(H5T_STRING == dt->shared->type && offset != 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "offset must be zero for this type")
if(H5T_ENUM == dt->shared->type && dt->shared->u.enumer.nmembs > 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined")
if(H5T_COMPOUND == dt->shared->type || H5T_REFERENCE == dt->shared->type || H5T_OPAQUE == dt->shared->type)
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "operation not defined for this datatype")
if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an atomic data type")
if (H5T_STATE_TRANSIENT!=dt->shared->state)
HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only")
if (H5T_STRING == dt->shared->type && offset != 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "offset must be zero for this type")
if (H5T_ENUM==dt->shared->type && dt->shared->u.enumer.nmembs>0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined")
if (H5T_COMPOUND==dt->shared->type || H5T_REFERENCE==dt->shared->type || H5T_OPAQUE==dt->shared->type)
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "operation not defined for this datatype")
/* Do the real work */
if (H5T_set_offset(dt, offset) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to set offset")
if (H5T_set_offset(dt, offset)<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to set offset")
done:
FUNC_LEAVE_API(ret_value)
@ -222,66 +226,70 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T_set_offset
* Function: H5T_set_offset
*
* Purpose: Sets the bit offset of the first significant bit. The
* signficant bits of an atomic datum can be offset from the
* beginning of the memory for that datum by an amount of
* padding. The `offset' property specifies the number of bits
* of padding that appear to the "right of" the value. That is,
* if we have a 32-bit datum with 16-bits of precision having
* the value 0x1122 then it will be layed out in memory as (from
* small byte address toward larger byte addresses):
* Purpose: Sets the bit offset of the first significant bit. The
* signficant bits of an atomic datum can be offset from the
* beginning of the memory for that datum by an amount of
* padding. The `offset' property specifies the number of bits
* of padding that appear to the "right of" the value. That is,
* if we have a 32-bit datum with 16-bits of precision having
* the value 0x1122 then it will be layed out in memory as (from
* small byte address toward larger byte addresses):
*
* Big Big Little Little
* Endian Endian Endian Endian
* offset = 0 offset = 16 offset = 0 offset = 16
* Big Big Little Little
* Endian Endian Endian Endian
* offset=0 offset=16 offset=0 offset=16
*
* 0: [ pad] [0x11] [0x22] [ pad]
* 1: [ pad] [0x22] [0x11] [ pad]
* 2: [0x11] [ pad] [ pad] [0x22]
* 3: [0x22] [ pad] [ pad] [0x11]
* 0: [ pad] [0x11] [0x22] [ pad]
* 1: [ pad] [0x22] [0x11] [ pad]
* 2: [0x11] [ pad] [ pad] [0x22]
* 3: [0x22] [ pad] [ pad] [0x11]
*
* If the offset is incremented then the total size is
* incremented also if necessary to prevent significant bits of
* the value from hanging over the edge of the data type.
* If the offset is incremented then the total size is
* incremented also if necessary to prevent significant bits of
* the value from hanging over the edge of the data type.
*
* The offset of an H5T_STRING cannot be set to anything but
* zero.
* The offset of an H5T_STRING cannot be set to anything but
* zero.
*
* Return: SUCCEED/FAIL
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
*
* Modifications:
* Robb Matzke, 22 Dec 1998
* Also works for derived data types.
*
*-------------------------------------------------------------------------
*/
static herr_t
H5T_set_offset(const H5T_t *dt, size_t offset)
{
herr_t ret_value = SUCCEED; /* Return value */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Check args */
assert(dt);
assert(H5T_STRING != dt->shared->type || 0 == offset);
assert(H5T_REFERENCE != dt->shared->type);
assert(H5T_OPAQUE != dt->shared->type);
assert(H5T_COMPOUND != dt->shared->type);
assert(!(H5T_ENUM == dt->shared->type && 0 == dt->shared->u.enumer.nmembs));
assert(H5T_STRING!=dt->shared->type || 0==offset);
assert(H5T_REFERENCE!=dt->shared->type);
assert(H5T_OPAQUE!=dt->shared->type);
assert(H5T_COMPOUND!=dt->shared->type);
assert(!(H5T_ENUM==dt->shared->type && 0==dt->shared->u.enumer.nmembs));
if (dt->shared->parent) {
if (H5T_set_offset(dt->shared->parent, offset) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to set offset for base type")
if (H5T_set_offset(dt->shared->parent, offset)<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to set offset for base type")
/* Adjust size of datatype appropriately */
if(dt->shared->type == H5T_ARRAY)
if(dt->shared->type==H5T_ARRAY)
dt->shared->size = dt->shared->parent->shared->size * dt->shared->u.array.nelem;
else if(dt->shared->type != H5T_VLEN)
else if(dt->shared->type!=H5T_VLEN)
dt->shared->size = dt->shared->parent->shared->size;
} else {
if (offset + dt->shared->u.atomic.prec > 8 * dt->shared->size)
if (offset+dt->shared->u.atomic.prec > 8*dt->shared->size)
dt->shared->size = (offset + dt->shared->u.atomic.prec + 7) / 8;
dt->shared->u.atomic.offset = offset;
}

View File

@ -249,14 +249,14 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T_set_order
* Function: H5T_set_order
*
* Purpose: Private function to set the byte order for a datatype.
* Purpose: Private function to set the byte order for a datatype.
*
* Return: SUCCEED/FAIL
* Return: Non-negative on success/Negative on failure
*
* Programmer: Raymond Lu
* 13 August 2010
* Programmer: Raymond Lu
* 13 August 2010
*
*-------------------------------------------------------------------------
*/
@ -268,7 +268,7 @@ H5T_set_order(H5T_t *dtype, H5T_order_t order)
FUNC_ENTER_NOAPI(FAIL)
if(H5T_ENUM == dtype->shared->type && dtype->shared->u.enumer.nmembs > 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "operation not allowed after enum members are defined")
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "operation not allowed after enum members are defined")
/* For derived data type, defer to parent */
while(dtype->shared->parent)
@ -277,7 +277,7 @@ H5T_set_order(H5T_t *dtype, H5T_order_t order)
/* Check for setting order on inappropriate datatype */
if(order == H5T_ORDER_NONE && !(H5T_REFERENCE == dtype->shared->type ||
H5T_OPAQUE == dtype->shared->type || H5T_IS_FIXED_STRING(dtype->shared)))
HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "illegal byte order for type")
HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "illegal byte order for type")
/* For atomic data type */
if(H5T_IS_ATOMIC(dtype->shared))

View File

@ -99,39 +99,43 @@ done:
/*-------------------------------------------------------------------------
* Function: H5Tset_pad
* Function: H5Tset_pad
*
* Purpose: Sets the LSB and MSB pad types.
* Purpose: Sets the LSB and MSB pad types.
*
* Return: Non-negative on success/Negative on failure
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Friday, January 9, 1998
* Programmer: Robb Matzke
* Friday, January 9, 1998
*
* Modifications:
* Robb Matzke, 22 Dec 1998
* Also works with derived data types.
*
*-------------------------------------------------------------------------
*/
herr_t
H5Tset_pad(hid_t type_id, H5T_pad_t lsb, H5T_pad_t msb)
{
H5T_t *dt = NULL;
herr_t ret_value = SUCCEED; /* Return value */
H5T_t *dt = NULL;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE3("e", "iTpTp", type_id, lsb, msb);
/* Check args */
if(NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
if(H5T_STATE_TRANSIENT != dt->shared->state)
HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only")
if(lsb < H5T_PAD_ZERO || lsb >= H5T_NPAD || msb < H5T_PAD_ZERO || msb >= H5T_NPAD)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid pad type")
if(H5T_ENUM == dt->shared->type && dt->shared->u.enumer.nmembs > 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined")
while(dt->shared->parent)
if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
if (H5T_STATE_TRANSIENT!=dt->shared->state)
HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only")
if (lsb < H5T_PAD_ZERO || lsb >= H5T_NPAD || msb < H5T_PAD_ZERO || msb >= H5T_NPAD)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid pad type")
if (H5T_ENUM==dt->shared->type && dt->shared->u.enumer.nmembs>0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined")
while (dt->shared->parent)
dt = dt->shared->parent; /*defer to parent*/
if(!H5T_IS_ATOMIC(dt->shared))
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "operation not defined for specified data type")
if (!H5T_IS_ATOMIC(dt->shared))
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "operation not defined for specified data type")
/* Commit */
dt->shared->u.atomic.lsb_pad = lsb;
@ -140,3 +144,4 @@ H5Tset_pad(hid_t type_id, H5T_pad_t lsb, H5T_pad_t msb)
done:
FUNC_LEAVE_API(ret_value)
}

View File

@ -138,56 +138,60 @@ done:
/*-------------------------------------------------------------------------
* Function: H5Tset_precision
* Function: H5Tset_precision
*
* Purpose: Sets the precision of a datatype. The precision is
* the number of significant bits which, unless padding is
* present, is 8 times larger than the value returned by
* H5Tget_size().
* Purpose: Sets the precision of a datatype. The precision is
* the number of significant bits which, unless padding is
* present, is 8 times larger than the value returned by
* H5Tget_size().
*
* If the precision is increased then the offset is decreased
* and then the size is increased to insure that significant
* bits do not "hang over" the edge of the datatype.
* If the precision is increased then the offset is decreased
* and then the size is increased to insure that significant
* bits do not "hang over" the edge of the datatype.
*
* The precision property of strings is read-only.
* The precision property of strings is read-only.
*
* When decreasing the precision of a floating point type, set
* the locations and sizes of the sign, mantissa, and exponent
* fields first.
* When decreasing the precision of a floating point type, set
* the locations and sizes of the sign, mantissa, and exponent
* fields first.
*
* Return: SUCCEED/FAIL
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
*
* Modifications:
* Robb Matzke, 22 Dec 1998
* Moved real work to a private function.
*
*-------------------------------------------------------------------------
*/
herr_t
H5Tset_precision(hid_t type_id, size_t prec)
{
H5T_t *dt = NULL;
herr_t ret_value = SUCCEED; /* Return value */
H5T_t *dt = NULL;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE2("e", "iz", type_id, prec);
/* Check args */
if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
if (H5T_STATE_TRANSIENT != dt->shared->state)
HGOTO_ERROR(H5E_ARGS, H5E_CANTSET, FAIL, "datatype is read-only")
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
if (H5T_STATE_TRANSIENT!=dt->shared->state)
HGOTO_ERROR(H5E_ARGS, H5E_CANTSET, FAIL, "datatype is read-only")
if (prec == 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "precision must be positive")
if (H5T_ENUM == dt->shared->type && dt->shared->u.enumer.nmembs>0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "operation not allowed after members are defined")
if (H5T_STRING == dt->shared->type)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "precision must be positive")
if (H5T_ENUM==dt->shared->type && dt->shared->u.enumer.nmembs>0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "operation not allowed after members are defined")
if (H5T_STRING==dt->shared->type)
HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "precision for this type is read-only")
if (H5T_COMPOUND == dt->shared->type || H5T_OPAQUE==dt->shared->type)
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "operation not defined for specified datatype")
if (H5T_COMPOUND==dt->shared->type || H5T_OPAQUE==dt->shared->type)
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "operation not defined for specified datatype")
/* Do the work */
if (H5T_set_precision(dt, prec) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "unable to set precision")
if (H5T_set_precision(dt, prec)<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "unable to set precision")
done:
FUNC_LEAVE_API(ret_value)
@ -195,69 +199,73 @@ done:
/*-------------------------------------------------------------------------
* Function: H5T_set_precision
* Function: H5T_set_precision
*
* Purpose: Sets the precision of a datatype. The precision is
* the number of significant bits which, unless padding is
* present, is 8 times larger than the value returned by
* H5Tget_size().
* Purpose: Sets the precision of a datatype. The precision is
* the number of significant bits which, unless padding is
* present, is 8 times larger than the value returned by
* H5Tget_size().
*
* If the precision is increased then the offset is decreased
* and then the size is increased to insure that significant
* bits do not "hang over" the edge of the datatype.
* If the precision is increased then the offset is decreased
* and then the size is increased to insure that significant
* bits do not "hang over" the edge of the datatype.
*
* The precision property of strings is read-only.
* The precision property of strings is read-only.
*
* When decreasing the precision of a floating point type, set
* the locations and sizes of the sign, mantissa, and exponent
* fields first.
* When decreasing the precision of a floating point type, set
* the locations and sizes of the sign, mantissa, and exponent
* fields first.
*
* Return: Non-negative on success/Negative on failure
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
*
* Modifications:
* Robb Matzke, 22 Dec 1998
* Also works for derived datatypes.
*
*-------------------------------------------------------------------------
*/
static herr_t
H5T_set_precision(const H5T_t *dt, size_t prec)
{
size_t offset, size;
herr_t ret_value = SUCCEED; /* Return value */
size_t offset, size;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Check args */
assert(dt);
assert(prec > 0);
assert(H5T_OPAQUE != dt->shared->type);
assert(H5T_COMPOUND != dt->shared->type);
assert(H5T_STRING != dt->shared->type);
assert(!(H5T_ENUM == dt->shared->type && 0 == dt->shared->u.enumer.nmembs));
assert(prec>0);
assert(H5T_OPAQUE!=dt->shared->type);
assert(H5T_COMPOUND!=dt->shared->type);
assert(H5T_STRING!=dt->shared->type);
assert(!(H5T_ENUM==dt->shared->type && 0==dt->shared->u.enumer.nmembs));
if (dt->shared->parent) {
if (H5T_set_precision(dt->shared->parent, prec) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "unable to set precision for base type")
if (H5T_set_precision(dt->shared->parent, prec)<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "unable to set precision for base type")
/* Adjust size of datatype appropriately */
if(dt->shared->type == H5T_ARRAY)
if(dt->shared->type==H5T_ARRAY)
dt->shared->size = dt->shared->parent->shared->size * dt->shared->u.array.nelem;
else if(dt->shared->type != H5T_VLEN)
else if(dt->shared->type!=H5T_VLEN)
dt->shared->size = dt->shared->parent->shared->size;
} else {
if (H5T_IS_ATOMIC(dt->shared)) {
/* Adjust the offset and size */
offset = dt->shared->u.atomic.offset;
size = dt->shared->size;
if (prec > 8*size)
/* Adjust the offset and size */
offset = dt->shared->u.atomic.offset;
size = dt->shared->size;
if (prec > 8*size)
offset = 0;
else if (offset+prec > 8 * size)
else if (offset+prec > 8 * size)
offset = 8 * size - prec;
if (prec > 8*size)
if (prec > 8*size)
size = (prec+7) / 8;
/* Check that things are still kosher */
switch (dt->shared->type) {
/* Check that things are still kosher */
switch (dt->shared->type) {
case H5T_INTEGER:
case H5T_TIME:
case H5T_BITFIELD:
@ -277,13 +285,13 @@ H5T_set_precision(const H5T_t *dt, size_t prec)
break;
default:
HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "operation not defined for datatype class")
} /* end switch */ /*lint !e788 All appropriate cases are covered */
} /* end switch */ /*lint !e788 All appropriate cases are covered */
/* Commit */
dt->shared->size = size;
/* Commit */
dt->shared->size = size;
dt->shared->u.atomic.offset = offset;
dt->shared->u.atomic.prec = prec;
} /* end if */
} /* end if */
else
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for specified datatype")
} /* end else */