summaryrefslogtreecommitdiffstats
path: root/src/H5T.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5T.c')
-rw-r--r--src/H5T.c135
1 files changed, 74 insertions, 61 deletions
diff --git a/src/H5T.c b/src/H5T.c
index 4041cd5..de917f6 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -1913,12 +1913,9 @@ 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 datatype class")
- /* 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);
+ /* Set return value */
+ if((ret_value = H5T_detect_class(dt, cls, TRUE)) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5T_NO_CLASS, "can't get datatype class")
done:
FUNC_LEAVE_API(ret_value)
@@ -1937,11 +1934,18 @@ done:
* 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)
+H5T_detect_class(const H5T_t *dt, H5T_class_t cls, hbool_t from_api)
{
unsigned i;
htri_t ret_value=FALSE; /* Return value */
@@ -1951,6 +1955,14 @@ H5T_detect_class (const H5T_t *dt, H5T_class_t cls)
assert(dt);
assert(cls>H5T_NO_CLASS && cls<H5T_NCLASSES);
+ /* Consider VL string as a string for API, as a VL for internal use. */
+ /* (note that this check must be performed before checking if the VL
+ * string belongs to the H5T_VLEN class, which would otherwise return
+ * true. -QAK)
+ */
+ if(from_api && H5T_IS_VL_STRING(dt->shared))
+ HGOTO_DONE(H5T_STRING == cls);
+
/* Check if this type is the correct type */
if(dt->shared->type==cls)
HGOTO_DONE(TRUE);
@@ -1967,7 +1979,7 @@ H5T_detect_class (const H5T_t *dt, H5T_class_t cls)
/* Recurse if it's VL, compound, enum or array */
if(H5T_IS_COMPLEX(dt->shared->u.compnd.memb[i].type->shared->type))
- if((nested_ret=H5T_detect_class(dt->shared->u.compnd.memb[i].type,cls))!=FALSE)
+ if((nested_ret=H5T_detect_class(dt->shared->u.compnd.memb[i].type, cls, from_api))!=FALSE)
HGOTO_DONE(nested_ret);
} /* end for */
break;
@@ -1975,7 +1987,7 @@ H5T_detect_class (const H5T_t *dt, H5T_class_t cls)
case H5T_ARRAY:
case H5T_VLEN:
case H5T_ENUM:
- HGOTO_DONE(H5T_detect_class(dt->shared->parent,cls));
+ HGOTO_DONE(H5T_detect_class(dt->shared->parent, cls, from_api));
default:
break;
@@ -3816,84 +3828,85 @@ H5T_get_size(const H5T_t *dt)
* Programmer: Robb Matzke
* Wednesday, December 10, 1997
*
- * Modifications:
- * Robb Matzke, 22 Dec 1998
- * Able to compare enumeration data types.
- *
- * Robb Matzke, 20 May 1999
- * Compares bitfields and opaque types.
- *
- * Quincey Koziol, 19 Mar 2005
- * Allow an enumerated datatypes to compare equal, if the "superset"
- * flag is set and dt2 has a superset of the enumerated values in dt1
*-------------------------------------------------------------------------
*/
int
H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset)
{
unsigned *idx1 = NULL, *idx2 = NULL;
- int ret_value = 0;
+ size_t base_size;
+ hbool_t swapped;
int i, j;
unsigned u;
int tmp;
- hbool_t swapped;
- size_t base_size;
+ int ret_value = 0;
- FUNC_ENTER_NOAPI(H5T_cmp, 0);
+ FUNC_ENTER_NOAPI(H5T_cmp, 0)
+ /* Sanity check */
+ HDassert(dt1);
+ HDassert(dt2);
+
/* the easy case */
- if (dt1 == dt2) HGOTO_DONE(0);
- assert(dt1);
- assert(dt2);
+ if(dt1 == dt2)
+ HGOTO_DONE(0);
/* compare */
- if (dt1->shared->type < dt2->shared->type) HGOTO_DONE(-1);
- if (dt1->shared->type > dt2->shared->type) HGOTO_DONE(1);
-
- if (dt1->shared->size < dt2->shared->size) HGOTO_DONE(-1);
- if (dt1->shared->size > dt2->shared->size) HGOTO_DONE(1);
-
- if (dt1->shared->parent && !dt2->shared->parent) HGOTO_DONE(-1);
- if (!dt1->shared->parent && dt2->shared->parent) HGOTO_DONE(1);
- if (dt1->shared->parent) {
+ if(dt1->shared->type < dt2->shared->type)
+ HGOTO_DONE(-1);
+ if(dt1->shared->type > dt2->shared->type)
+ HGOTO_DONE(1);
+
+ if(dt1->shared->size < dt2->shared->size)
+ HGOTO_DONE(-1);
+ if(dt1->shared->size > dt2->shared->size)
+ HGOTO_DONE(1);
+
+ if(dt1->shared->parent && !dt2->shared->parent)
+ HGOTO_DONE(-1);
+ if(!dt1->shared->parent && dt2->shared->parent)
+ HGOTO_DONE(1);
+ if(dt1->shared->parent) {
tmp = H5T_cmp(dt1->shared->parent, dt2->shared->parent, superset);
- if (tmp<0) HGOTO_DONE(-1);
- if (tmp>0) HGOTO_DONE(1);
- }
+ if(tmp < 0)
+ HGOTO_DONE(-1);
+ if(tmp > 0)
+ HGOTO_DONE(1);
+ } /* end if */
switch(dt1->shared->type) {
case H5T_COMPOUND:
/*
* Compound data types...
*/
- if (dt1->shared->u.compnd.nmembs < dt2->shared->u.compnd.nmembs)
+ if(dt1->shared->u.compnd.nmembs < dt2->shared->u.compnd.nmembs)
HGOTO_DONE(-1);
- if (dt1->shared->u.compnd.nmembs > dt2->shared->u.compnd.nmembs)
+ if(dt1->shared->u.compnd.nmembs > dt2->shared->u.compnd.nmembs)
HGOTO_DONE(1);
/* Build an index for each type so the names are sorted */
- if (NULL==(idx1 = H5MM_malloc(dt1->shared->u.compnd.nmembs * sizeof(unsigned))) ||
- NULL==(idx2 = H5MM_malloc(dt2->shared->u.compnd.nmembs * sizeof(unsigned))))
+ if(NULL == (idx1 = H5MM_malloc(dt1->shared->u.compnd.nmembs * sizeof(unsigned))) ||
+ NULL == (idx2 = H5MM_malloc(dt2->shared->u.compnd.nmembs * sizeof(unsigned))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed");
- for (u=0; u<dt1->shared->u.compnd.nmembs; u++)
+ for(u = 0; u < dt1->shared->u.compnd.nmembs; u++)
idx1[u] = idx2[u] = u;
if(dt1->shared->u.enumer.nmembs > 1) {
- for (i=dt1->shared->u.compnd.nmembs-1, swapped=TRUE; swapped && i>=0; --i)
- for (j=0, swapped=FALSE; j<i; j++)
- if (HDstrcmp(dt1->shared->u.compnd.memb[idx1[j]].name,
- dt1->shared->u.compnd.memb[idx1[j+1]].name) > 0) {
+ for(i = dt1->shared->u.compnd.nmembs - 1, swapped = TRUE; swapped && i >= 0; --i)
+ for(j = 0, swapped=FALSE; j < i; j++)
+ if(HDstrcmp(dt1->shared->u.compnd.memb[idx1[j]].name,
+ dt1->shared->u.compnd.memb[idx1[j + 1]].name) > 0) {
tmp = idx1[j];
- idx1[j] = idx1[j+1];
- idx1[j+1] = tmp;
+ idx1[j] = idx1[j + 1];
+ idx1[j + 1] = tmp;
swapped = TRUE;
}
- for (i=dt2->shared->u.compnd.nmembs-1, swapped=TRUE; swapped && i>=0; --i)
- for (j=0, swapped=FALSE; j<i; j++)
- if (HDstrcmp(dt2->shared->u.compnd.memb[idx2[j]].name,
- dt2->shared->u.compnd.memb[idx2[j+1]].name) > 0) {
+ for(i = dt2->shared->u.compnd.nmembs - 1, swapped = TRUE; swapped && i >= 0; --i)
+ for(j = 0, swapped = FALSE; j<i; j++)
+ if(HDstrcmp(dt2->shared->u.compnd.memb[idx2[j]].name,
+ dt2->shared->u.compnd.memb[idx2[j + 1]].name) > 0) {
tmp = idx2[j];
- idx2[j] = idx2[j+1];
- idx2[j+1] = tmp;
+ idx2[j] = idx2[j + 1];
+ idx2[j + 1] = tmp;
swapped = TRUE;
}
} /* end if */
@@ -4212,13 +4225,13 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset)
} /* end switch */
done:
- if(idx1!=NULL)
+ if(NULL != idx1)
H5MM_xfree(idx1);
- if(idx2!=NULL)
+ if(NULL != idx2)
H5MM_xfree(idx2);
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5T_cmp() */
/*-------------------------------------------------------------------------
@@ -5124,7 +5137,7 @@ H5T_is_relocatable(const H5T_t *dt)
HDassert(dt);
/* VL and reference datatypes are relocatable */
- if(H5T_detect_class(dt, H5T_VLEN) || H5T_detect_class(dt, H5T_REFERENCE))
+ if(H5T_detect_class(dt, H5T_VLEN, FALSE) || H5T_detect_class(dt, H5T_REFERENCE, FALSE))
ret_value = TRUE;
done: