summaryrefslogtreecommitdiffstats
path: root/src/H5T.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>1999-11-17 21:59:53 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>1999-11-17 21:59:53 (GMT)
commit9e014467b62df66322de63e21be565ed59a079b3 (patch)
treee6b01ab36a0f2a67c1e3a68b5be10dc5e15f481d /src/H5T.c
parentcd313a16456934b336902ca509d10187b4d975de (diff)
downloadhdf5-9e014467b62df66322de63e21be565ed59a079b3.zip
hdf5-9e014467b62df66322de63e21be565ed59a079b3.tar.gz
hdf5-9e014467b62df66322de63e21be565ed59a079b3.tar.bz2
[svn-r1836] Mainly fixed a bug in VL datatype comparisons which was causing non-equal
VL types to compare as equal. Added some asserts to make certain nothing slips through again. Also cleaned up a few warnings from the SGI compiler.
Diffstat (limited to 'src/H5T.c')
-rw-r--r--src/H5T.c1192
1 files changed, 622 insertions, 570 deletions
diff --git a/src/H5T.c b/src/H5T.c
index 044441e..0f6e766 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -4085,161 +4085,163 @@ H5Tregister(H5T_pers_t pers, const char *name, hid_t src_id, hid_t dst_id,
/* Check args */
if (H5T_PERS_HARD!=pers && H5T_PERS_SOFT!=pers) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
"invalid function persistence");
}
if (!name || !*name) {
- HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
+ HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
"conversion must have a name for debugging");
}
if (H5I_DATATYPE!=H5I_get_type(src_id) ||
- NULL==(src=H5I_object(src_id)) ||
- H5I_DATATYPE!=H5I_get_type(dst_id) ||
- NULL==(dst=H5I_object(dst_id))) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+ NULL==(src=H5I_object(src_id)) ||
+ H5I_DATATYPE!=H5I_get_type(dst_id) ||
+ NULL==(dst=H5I_object(dst_id))) {
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
}
if (!func) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
"no conversion function specified");
}
if (H5T_PERS_HARD==pers) {
- /* Locate or create a new conversion path */
- if (NULL==(new_path=H5T_path_find(src, dst, name, func))) {
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL,
- "unable to locate/allocate conversion path");
- }
-
- /*
- * Notify all other functions to recalculate private data since some
- * functions might cache a list of conversion functions. For
- * instance, the compound type converter caches a list of conversion
- * functions for the members, so adding a new function should cause
- * the list to be recalculated to use the new function.
- */
- for (i=0; i<H5T_g.npaths; i++) {
- if (new_path != H5T_g.path[i]) {
- H5T_g.path[i]->cdata.recalc = TRUE;
- }
- }
-
+ /* Locate or create a new conversion path */
+ if (NULL==(new_path=H5T_path_find(src, dst, name, func))) {
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL,
+ "unable to locate/allocate conversion path");
+ }
+
+ /*
+ * Notify all other functions to recalculate private data since some
+ * functions might cache a list of conversion functions. For
+ * instance, the compound type converter caches a list of conversion
+ * functions for the members, so adding a new function should cause
+ * the list to be recalculated to use the new function.
+ */
+ for (i=0; i<H5T_g.npaths; i++) {
+ if (new_path != H5T_g.path[i])
+ H5T_g.path[i]->cdata.recalc = TRUE;
+ }
+
} else {
- /* Add function to end of soft list */
- if (H5T_g.nsoft>=H5T_g.asoft) {
- size_t na = MAX(32, 2*H5T_g.asoft);
- H5T_soft_t *x = H5MM_realloc(H5T_g.soft, na*sizeof(H5T_soft_t));
- if (!x) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
- H5T_g.asoft = (intn)na;
- H5T_g.soft = x;
- }
- HDstrncpy (H5T_g.soft[H5T_g.nsoft].name, name, H5T_NAMELEN);
- H5T_g.soft[H5T_g.nsoft].name[H5T_NAMELEN-1] = '\0';
- H5T_g.soft[H5T_g.nsoft].src = src->type;
- H5T_g.soft[H5T_g.nsoft].dst = dst->type;
- H5T_g.soft[H5T_g.nsoft].func = func;
- H5T_g.nsoft++;
+ /* Add function to end of soft list */
+ if (H5T_g.nsoft>=H5T_g.asoft) {
+ size_t na = MAX(32, 2*H5T_g.asoft);
+ H5T_soft_t *x = H5MM_realloc(H5T_g.soft, na*sizeof(H5T_soft_t));
- /*
- * Any existing path (except the no-op path) to which this new soft
- * conversion function applies should be replaced by a new path that
- * uses this function.
- */
- for (i=1; i<H5T_g.npaths; i++) {
- old_path = H5T_g.path[i];
- assert(old_path);
-
- /* Does the new soft conversion function apply to this path? */
- if (old_path->is_hard ||
- old_path->src->type!=src->type ||
- old_path->dst->type!=dst->type) {
- continue;
- }
- if ((tmp_sid = H5I_register(H5I_DATATYPE,
- H5T_copy(old_path->src,
- H5T_COPY_ALL)))<0 ||
- (tmp_did = H5I_register(H5I_DATATYPE,
- H5T_copy(old_path->dst,
- H5T_COPY_ALL)))<0) {
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL,
- "unable to register data types for conv query");
- }
- HDmemset(&cdata, 0, sizeof cdata);
- cdata.command = H5T_CONV_INIT;
- if ((func)(tmp_sid, tmp_did, &cdata, 0, 0, NULL, NULL, H5P_DEFAULT)<0) {
- H5I_dec_ref(tmp_sid);
- H5I_dec_ref(tmp_did);
- tmp_sid = tmp_did = -1;
- H5E_clear();
- continue;
- }
+ if (!x) {
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
+ H5T_g.asoft = (intn)na;
+ H5T_g.soft = x;
+ }
+ HDstrncpy (H5T_g.soft[H5T_g.nsoft].name, name, H5T_NAMELEN);
+ H5T_g.soft[H5T_g.nsoft].name[H5T_NAMELEN-1] = '\0';
+ H5T_g.soft[H5T_g.nsoft].src = src->type;
+ H5T_g.soft[H5T_g.nsoft].dst = dst->type;
+ H5T_g.soft[H5T_g.nsoft].func = func;
+ H5T_g.nsoft++;
- /* Create a new conversion path */
- if (NULL==(new_path=H5MM_calloc(sizeof(H5T_path_t)))) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
- HDstrncpy(new_path->name, name, H5T_NAMELEN);
- new_path->name[H5T_NAMELEN-1] = '\0';
- if (NULL==(new_path->src=H5T_copy(old_path->src, H5T_COPY_ALL)) ||
- NULL==(new_path->dst=H5T_copy(old_path->dst, H5T_COPY_ALL))) {
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL,
- "unable to copy data types");
- }
- new_path->func = func;
- new_path->is_hard = FALSE;
- new_path->cdata = cdata;
-
- /* Replace previous path */
- H5T_g.path[i] = new_path;
- new_path = NULL; /*so we don't free it on error*/
-
- /* Free old path */
- H5T_print_stats(old_path, &nprint);
- old_path->cdata.command = H5T_CONV_FREE;
- if ((old_path->func)(tmp_sid, tmp_did, &(old_path->cdata),
- 0, 0, NULL, NULL, H5P_DEFAULT)<0) {
+ /*
+ * Any existing path (except the no-op path) to which this new soft
+ * conversion function applies should be replaced by a new path that
+ * uses this function.
+ */
+ for (i=1; i<H5T_g.npaths; i++) {
+ old_path = H5T_g.path[i];
+ assert(old_path);
+
+ /* Does the new soft conversion function apply to this path? */
+ if (old_path->is_hard ||
+ old_path->src->type!=src->type ||
+ old_path->dst->type!=dst->type) {
+ continue;
+ }
+ if ((tmp_sid = H5I_register(H5I_DATATYPE,
+ H5T_copy(old_path->src, H5T_COPY_ALL)))<0 ||
+ (tmp_did = H5I_register(H5I_DATATYPE,
+ H5T_copy(old_path->dst, H5T_COPY_ALL)))<0) {
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL,
+ "unable to register data types for conv query");
+ }
+ HDmemset(&cdata, 0, sizeof cdata);
+ cdata.command = H5T_CONV_INIT;
+ if ((func)(tmp_sid, tmp_did, &cdata, 0, 0, NULL, NULL, H5P_DEFAULT)<0) {
+ H5I_dec_ref(tmp_sid);
+ H5I_dec_ref(tmp_did);
+ tmp_sid = tmp_did = -1;
+ H5E_clear();
+ continue;
+ }
+
+ /* Create a new conversion path */
+ if (NULL==(new_path=H5MM_calloc(sizeof(H5T_path_t)))) {
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
+ HDstrncpy(new_path->name, name, H5T_NAMELEN);
+ new_path->name[H5T_NAMELEN-1] = '\0';
+ if (NULL==(new_path->src=H5T_copy(old_path->src, H5T_COPY_ALL)) ||
+ NULL==(new_path->dst=H5T_copy(old_path->dst, H5T_COPY_ALL))) {
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL,
+ "unable to copy data types");
+ }
+ new_path->func = func;
+ new_path->is_hard = FALSE;
+ new_path->cdata = cdata;
+
+ /* Replace previous path */
+ H5T_g.path[i] = new_path;
+ new_path = NULL; /*so we don't free it on error*/
+
+ /* Free old path */
+ H5T_print_stats(old_path, &nprint);
+ old_path->cdata.command = H5T_CONV_FREE;
+ if ((old_path->func)(tmp_sid, tmp_did, &(old_path->cdata),
+ 0, 0, NULL, NULL, H5P_DEFAULT)<0) {
#ifdef H5T_DEBUG
- if (H5DEBUG(T)) {
- fprintf (H5DEBUG(T), "H5T: conversion function 0x%08lx "
- "failed to free private data for %s (ignored)\n",
- (unsigned long)(old_path->func), old_path->name);
- }
+ if (H5DEBUG(T)) {
+ fprintf (H5DEBUG(T), "H5T: conversion function 0x%08lx "
+ "failed to free private data for %s (ignored)\n",
+ (unsigned long)(old_path->func), old_path->name);
+ }
#endif
- }
- H5T_close(old_path->src);
- H5T_close(old_path->dst);
- H5MM_xfree(old_path);
+ }
+ H5T_close(old_path->src);
+ H5T_close(old_path->dst);
+ H5MM_xfree(old_path);
- /* Release temporary atoms */
- H5I_dec_ref(tmp_sid);
- H5I_dec_ref(tmp_did);
- tmp_sid = tmp_did = -1;
+ /* Release temporary atoms */
+ H5I_dec_ref(tmp_sid);
+ H5I_dec_ref(tmp_did);
+ tmp_sid = tmp_did = -1;
- /* We don't care about any failures during the freeing process */
- H5E_clear();
- }
+ /* We don't care about any failures during the freeing process */
+ H5E_clear();
+ }
}
ret_value = SUCCEED;
done:
if (ret_value<0) {
- if (new_path) {
- if (new_path->src) H5T_close(new_path->src);
- if (new_path->dst) H5T_close(new_path->dst);
- H5MM_xfree(new_path);
- }
- if (tmp_sid>=0) H5I_dec_ref(tmp_sid);
- if (tmp_did>=0) H5I_dec_ref(tmp_did);
+ if (new_path) {
+ if (new_path->src)
+ H5T_close(new_path->src);
+ if (new_path->dst)
+ H5T_close(new_path->dst);
+ H5MM_xfree(new_path);
+ }
+ if (tmp_sid>=0)
+ H5I_dec_ref(tmp_sid);
+ if (tmp_did>=0)
+ H5I_dec_ref(tmp_did);
}
FUNC_LEAVE(ret_value);
}
/*-------------------------------------------------------------------------
- * Function: H5Tunregister
+ * Function: H5T_unregister
*
* Purpose: Removes conversion paths that match the specified criteria.
* All arguments are optional. Missing arguments are wild cards.
@@ -4253,84 +4255,115 @@ H5Tregister(H5T_pers_t pers, const char *name, hid_t src_id, hid_t dst_id,
* Tuesday, January 13, 1998
*
* Modifications:
+ * Adapted to non-API function - QAK, 11/17/99
*
*-------------------------------------------------------------------------
*/
herr_t
-H5Tunregister(H5T_pers_t pers, const char *name, hid_t src_id, hid_t dst_id,
+H5T_unregister(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst,
H5T_conv_t func)
{
H5T_path_t *path = NULL; /*conversion path */
H5T_soft_t *soft = NULL; /*soft conversion information */
- H5T_t *src=NULL, *dst=NULL; /*data type descriptors */
intn nprint=0; /*number of paths shut down */
intn i; /*counter */
- FUNC_ENTER(H5Tunregister, FAIL);
- H5TRACE5("e","Tesiix",pers,name,src_id,dst_id,func);
-
- /* Check arguments */
- if (src_id>0 &&
- (H5I_DATATYPE!=H5I_get_type(src_id) ||
- NULL==(src=H5I_object(src_id)))) {
- HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "src is not a data type");
- }
- if (dst_id>0 &&
- (H5I_DATATYPE!=H5I_get_type(dst_id) ||
- NULL==(dst=H5I_object(dst_id)))) {
- HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dst is not a data type");
- }
+ FUNC_ENTER(H5T_unregister, FAIL);
/* Remove matching entries from the soft list */
if (H5T_PERS_DONTCARE==pers || H5T_PERS_SOFT==pers) {
- for (i=H5T_g.nsoft-1; i>=0; --i) {
- soft = H5T_g.soft+i;
- assert(soft);
- if (name && *name && HDstrcmp(name, soft->name)) continue;
- if (src && src->type!=soft->src) continue;
- if (dst && dst->type!=soft->dst) continue;
- if (func && func!=soft->func) continue;
-
- HDmemmove(H5T_g.soft+i, H5T_g.soft+i+1,
- (H5T_g.nsoft-(i+1)) * sizeof(H5T_soft_t));
- --H5T_g.nsoft;
- }
+ for (i=H5T_g.nsoft-1; i>=0; --i) {
+ soft = H5T_g.soft+i;
+ assert(soft);
+ if (name && *name && HDstrcmp(name, soft->name)) continue;
+ if (src && src->type!=soft->src) continue;
+ if (dst && dst->type!=soft->dst) continue;
+ if (func && func!=soft->func) continue;
+
+ HDmemmove(H5T_g.soft+i, H5T_g.soft+i+1,
+ (H5T_g.nsoft-(i+1)) * sizeof(H5T_soft_t));
+ --H5T_g.nsoft;
+ }
}
/* Remove matching conversion paths, except no-op path */
for (i=H5T_g.npaths-1; i>0; --i) {
- path = H5T_g.path[i];
- assert(path);
- if ((H5T_PERS_SOFT==pers && path->is_hard) ||
- (H5T_PERS_HARD==pers && !path->is_hard)) continue;
- if (name && *name && HDstrcmp(name, path->name)) continue;
- if (src && H5T_cmp(src, path->src)) continue;
- if (dst && H5T_cmp(dst, path->dst)) continue;
- if (func && func!=path->func) continue;
-
- /* Remove from table */
- HDmemmove(H5T_g.path+i, H5T_g.path+i+1,
- (H5T_g.npaths-(i+1))*sizeof(H5T_path_t*));
- --H5T_g.npaths;
-
- /* Shut down path */
- H5T_print_stats(path, &nprint);
- path->cdata.command = H5T_CONV_FREE;
- if ((path->func)(FAIL, FAIL, &(path->cdata), 0, 0, NULL, NULL, H5P_DEFAULT)<0) {
+ path = H5T_g.path[i];
+ assert(path);
+ if ((H5T_PERS_SOFT==pers && path->is_hard) ||
+ (H5T_PERS_HARD==pers && !path->is_hard)) continue;
+ if (name && *name && HDstrcmp(name, path->name)) continue;
+ if (src && H5T_cmp(src, path->src)) continue;
+ if (dst && H5T_cmp(dst, path->dst)) continue;
+ if (func && func!=path->func) continue;
+
+ /* Remove from table */
+ HDmemmove(H5T_g.path+i, H5T_g.path+i+1,
+ (H5T_g.npaths-(i+1))*sizeof(H5T_path_t*));
+ --H5T_g.npaths;
+
+ /* Shut down path */
+ H5T_print_stats(path, &nprint);
+ path->cdata.command = H5T_CONV_FREE;
+ if ((path->func)(FAIL, FAIL, &(path->cdata), 0, 0, NULL, NULL, H5P_DEFAULT)<0) {
#ifdef H5T_DEBUG
- if (H5DEBUG(T)) {
- fprintf(H5DEBUG(T), "H5T: conversion function 0x%08lx failed "
- "to free private data for %s (ignored)\n",
- (unsigned long)(path->func), path->name);
- }
+ if (H5DEBUG(T)) {
+ fprintf(H5DEBUG(T), "H5T: conversion function 0x%08lx failed "
+ "to free private data for %s (ignored)\n",
+ (unsigned long)(path->func), path->name);
+ }
#endif
- }
- H5T_close(path->src);
- H5T_close(path->dst);
- H5MM_xfree(path);
- H5E_clear(); /*ignore all shutdown errors*/
+ }
+ H5T_close(path->src);
+ H5T_close(path->dst);
+ H5MM_xfree(path);
+ H5E_clear(); /*ignore all shutdown errors*/
+ }
+
+ FUNC_LEAVE(SUCCEED);
+} /* end H5T_unregister() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5Tunregister
+ *
+ * Purpose: Removes conversion paths that match the specified criteria.
+ * All arguments are optional. Missing arguments are wild cards.
+ * The special no-op path cannot be removed.
+ *
+ * Return: Succeess: non-negative
+ *
+ * Failure: negative
+ *
+ * Programmer: Robb Matzke
+ * Tuesday, January 13, 1998
+ *
+ * Modifications:
+ * Changed to use H5T_unregister wrapper function - QAK, 11/17/99
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5Tunregister(H5T_pers_t pers, const char *name, hid_t src_id, hid_t dst_id,
+ H5T_conv_t func)
+{
+ H5T_t *src=NULL, *dst=NULL; /*data type descriptors */
+
+ FUNC_ENTER(H5Tunregister, FAIL);
+ H5TRACE5("e","Tesiix",pers,name,src_id,dst_id,func);
+
+ /* Check arguments */
+ if (src_id>0 && (H5I_DATATYPE!=H5I_get_type(src_id) ||
+ NULL==(src=H5I_object(src_id)))) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "src is not a data type");
+ }
+ if (dst_id>0 && (H5I_DATATYPE!=H5I_get_type(dst_id) ||
+ NULL==(dst=H5I_object(dst_id)))) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dst is not a data type");
}
+ if (H5T_unregister(pers,name,src,dst,func)<0)
+ HRETURN_ERROR(H5E_DATATYPE, H5E_CANTDELETE, FAIL, "internal unregister function failed");
+
FUNC_LEAVE(SUCCEED);
}
@@ -4439,7 +4472,7 @@ H5Tconvert(hid_t src_id, hid_t dst_id, size_t nelmts, void *buf,
}
if (H5T_convert(tpath, src_id, dst_id, nelmts, 0, buf, background, plist_id)<0) {
- HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL,
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL,
"data type conversion failed");
}
@@ -4771,52 +4804,52 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
/* copy */
if (NULL==(new_dt = H5MM_calloc(sizeof(H5T_t)))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
*new_dt = *old_dt;
/* copy parent */
if (new_dt->parent) {
- new_dt->parent = H5T_copy(new_dt->parent, method);
+ new_dt->parent = H5T_copy(new_dt->parent, method);
}
switch (method) {
- case H5T_COPY_TRANSIENT:
- /*
- * Return an unlocked transient type.
- */
- new_dt->state = H5T_STATE_TRANSIENT;
- HDmemset (&(new_dt->ent), 0, sizeof(new_dt->ent));
- new_dt->ent.header = HADDR_UNDEF;
- break;
-
- case H5T_COPY_ALL:
- /*
- * Return a transient type (locked or unlocked) or an unopened named
- * type. Immutable transient types are degraded to read-only.
- */
- if (H5T_STATE_OPEN==new_dt->state) {
- new_dt->state = H5T_STATE_NAMED;
- } else if (H5T_STATE_IMMUTABLE==new_dt->state) {
- new_dt->state = H5T_STATE_RDONLY;
- }
- break;
-
- case H5T_COPY_REOPEN:
- /*
- * Return a transient type (locked or unlocked) or an opened named
- * type.
- */
- if (H5F_addr_defined(new_dt->ent.header)) {
- if (H5O_open (&(new_dt->ent))<0) {
- H5MM_xfree (new_dt);
- HRETURN_ERROR (H5E_DATATYPE, H5E_CANTOPENOBJ, NULL,
- "unable to reopen named data type");
- }
- new_dt->state = H5T_STATE_OPEN;
- }
- break;
+ case H5T_COPY_TRANSIENT:
+ /*
+ * Return an unlocked transient type.
+ */
+ new_dt->state = H5T_STATE_TRANSIENT;
+ HDmemset (&(new_dt->ent), 0, sizeof(new_dt->ent));
+ new_dt->ent.header = HADDR_UNDEF;
+ break;
+
+ case H5T_COPY_ALL:
+ /*
+ * Return a transient type (locked or unlocked) or an unopened named
+ * type. Immutable transient types are degraded to read-only.
+ */
+ if (H5T_STATE_OPEN==new_dt->state) {
+ new_dt->state = H5T_STATE_NAMED;
+ } else if (H5T_STATE_IMMUTABLE==new_dt->state) {
+ new_dt->state = H5T_STATE_RDONLY;
+ }
+ break;
+
+ case H5T_COPY_REOPEN:
+ /*
+ * Return a transient type (locked or unlocked) or an opened named
+ * type.
+ */
+ if (H5F_addr_defined(new_dt->ent.header)) {
+ if (H5O_open (&(new_dt->ent))<0) {
+ H5MM_xfree (new_dt);
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTOPENOBJ, NULL,
+ "unable to reopen named data type");
+ }
+ new_dt->state = H5T_STATE_OPEN;
+ }
+ break;
}
if (H5T_COMPOUND == new_dt->type) {
@@ -4862,25 +4895,23 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
new_dt->size += accum_change;
} else if (H5T_ENUM == new_dt->type) {
- /*
- * Copy all member fields to new type, then overwrite the name fields
- * of each new member with copied values. That is, H5T_copy() is a
- * deep copy.
- */
- new_dt->u.enumer.name = H5MM_malloc(new_dt->u.enumer.nalloc *
- sizeof(char*));
- new_dt->u.enumer.value = H5MM_malloc(new_dt->u.enumer.nalloc *
- new_dt->size);
- if (NULL==new_dt->u.enumer.value) {
- HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed");
- }
- HDmemcpy(new_dt->u.enumer.value, old_dt->u.enumer.value,
- new_dt->u.enumer.nmembs * new_dt->size);
- for (i=0; i<new_dt->u.enumer.nmembs; i++) {
- s = old_dt->u.enumer.name[i];
- new_dt->u.enumer.name[i] = H5MM_xstrdup(s);
- }
+ /*
+ * Copy all member fields to new type, then overwrite the name fields
+ * of each new member with copied values. That is, H5T_copy() is a
+ * deep copy.
+ */
+ new_dt->u.enumer.name = H5MM_malloc(new_dt->u.enumer.nalloc * sizeof(char*));
+ new_dt->u.enumer.value = H5MM_malloc(new_dt->u.enumer.nalloc * new_dt->size);
+ if (NULL==new_dt->u.enumer.value) {
+ HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
+ HDmemcpy(new_dt->u.enumer.value, old_dt->u.enumer.value,
+ new_dt->u.enumer.nmembs * new_dt->size);
+ for (i=0; i<new_dt->u.enumer.nmembs; i++) {
+ s = old_dt->u.enumer.name[i];
+ new_dt->u.enumer.name[i] = H5MM_xstrdup(s);
+ }
} else if (H5T_VLEN == new_dt->type) {
if(method==H5T_COPY_TRANSIENT || method==H5T_COPY_REOPEN) {
/* H5T_copy converts any VL type into a memory VL type */
@@ -5524,59 +5555,60 @@ H5T_struct_insert(H5T_t *parent, const char *name, size_t offset, intn ndims,
assert(name && *name);
/* Does NAME already exist in PARENT? */
- for (i=0; i<parent->u.compnd.nmembs; i++) {
- if (!HDstrcmp(parent->u.compnd.memb[i].name, name)) {
- HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL,
- "member name is not unique");
- }
- }
+ for (i=0; i<parent->u.compnd.nmembs; i++)
+ if (!HDstrcmp(parent->u.compnd.memb[i].name, name)) {
+ HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL,
+ "member name is not unique");
+ }
/* Does the new member overlap any existing member ? */
- for (total_size=member->size, i=0; i<ndims; i++) total_size *= dim[i];
+ for (total_size=member->size, i=0; i<ndims; i++)
+ total_size *= dim[i];
for (i=0; i<parent->u.compnd.nmembs; i++) {
- if ((offset <= parent->u.compnd.memb[i].offset &&
- offset + total_size > parent->u.compnd.memb[i].offset) ||
- (parent->u.compnd.memb[i].offset <= offset &&
- parent->u.compnd.memb[i].offset +
- parent->u.compnd.memb[i].size > offset)) {
- HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL,
- "member overlaps with another member");
- }
+ if ((offset <= parent->u.compnd.memb[i].offset &&
+ offset + total_size > parent->u.compnd.memb[i].offset) ||
+ (parent->u.compnd.memb[i].offset <= offset &&
+ parent->u.compnd.memb[i].offset +
+ parent->u.compnd.memb[i].size > offset)) {
+ HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL,
+ "member overlaps with another member");
+ }
}
/* Are permutations correct? */
if (ndims>0 && perm) {
- if (NULL==(perm_check=H5MM_calloc(ndims*sizeof(hbool_t)))) {
- HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
- for (i=0; i<ndims; i++) {
- if (perm[i]<0 || perm[i]>=ndims) {
- H5MM_xfree(perm_check);
- HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "invalid permutation vector (out of range)");
- }
- if (perm_check[perm[i]]) {
- H5MM_xfree(perm_check);
- HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "invalid permutation vector (duplicate value)");
- }
- perm_check[perm[i]] = TRUE;
- }
- perm_check = H5MM_xfree(perm_check);
+ if (NULL==(perm_check=H5MM_calloc(ndims*sizeof(hbool_t)))) {
+ HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
+ for (i=0; i<ndims; i++) {
+ if (perm[i]<0 || perm[i]>=ndims) {
+ H5MM_xfree(perm_check);
+ HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
+ "invalid permutation vector (out of range)");
+ }
+ if (perm_check[perm[i]]) {
+ H5MM_xfree(perm_check);
+ HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
+ "invalid permutation vector (duplicate value)");
+ }
+ perm_check[perm[i]] = TRUE;
+ }
+ perm_check = H5MM_xfree(perm_check);
}
/* Increase member array if necessary */
if (parent->u.compnd.nmembs >= parent->u.compnd.nalloc) {
- size_t na = parent->u.compnd.nalloc + H5T_COMPND_INC;
- H5T_cmemb_t *x = H5MM_realloc (parent->u.compnd.memb,
- na * sizeof(H5T_cmemb_t));
- if (!x) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
- parent->u.compnd.nalloc = (intn)na;
- parent->u.compnd.memb = x;
+ size_t na = parent->u.compnd.nalloc + H5T_COMPND_INC;
+ H5T_cmemb_t *x = H5MM_realloc (parent->u.compnd.memb,
+ na * sizeof(H5T_cmemb_t));
+
+ if (!x) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
+ parent->u.compnd.nalloc = (intn)na;
+ parent->u.compnd.memb = x;
}
/* Add member to end of member array */
@@ -5587,8 +5619,8 @@ H5T_struct_insert(H5T_t *parent, const char *name, size_t offset, intn ndims,
parent->u.compnd.memb[idx].ndims = ndims;
parent->u.compnd.memb[idx].type = H5T_copy (member, H5T_COPY_ALL);
for (i=0; i<ndims; i++) {
- parent->u.compnd.memb[idx].dim[i] = dim[i];
- parent->u.compnd.memb[idx].perm[i] = perm?perm[i]:i;
+ parent->u.compnd.memb[idx].dim[i] = dim[i];
+ parent->u.compnd.memb[idx].perm[i] = perm ? perm[i] : i;
}
parent->u.compnd.sorted = H5T_SORT_NONE;
@@ -6124,169 +6156,184 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2)
if (dt1->parent && !dt2->parent) HGOTO_DONE(-1);
if (!dt1->parent && dt2->parent) HGOTO_DONE(1);
if (dt1->parent) {
- tmp = H5T_cmp(dt1->parent, dt2->parent);
- if (tmp<0) HGOTO_DONE(-1);
- if (tmp>0) HGOTO_DONE(1);
+ tmp = H5T_cmp(dt1->parent, dt2->parent);
+ if (tmp<0) HGOTO_DONE(-1);
+ if (tmp>0) HGOTO_DONE(1);
}
if (H5T_COMPOUND == dt1->type) {
- /*
- * Compound data types...
- */
- if (dt1->u.compnd.nmembs < dt2->u.compnd.nmembs) HGOTO_DONE(-1);
- if (dt1->u.compnd.nmembs > dt2->u.compnd.nmembs) HGOTO_DONE(1);
+ /*
+ * Compound data types...
+ */
+ if (dt1->u.compnd.nmembs < dt2->u.compnd.nmembs) HGOTO_DONE(-1);
+ if (dt1->u.compnd.nmembs > dt2->u.compnd.nmembs) HGOTO_DONE(1);
- /* Build an index for each type so the names are sorted */
- if (NULL==(idx1 = H5MM_malloc(dt1->u.compnd.nmembs * sizeof(intn))) ||
- NULL==(idx2 = H5MM_malloc(dt1->u.compnd.nmembs * sizeof(intn)))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, 0,
- "memory allocation failed");
- }
- for (i=0; i<dt1->u.compnd.nmembs; i++) idx1[i] = idx2[i] = i;
- for (i=dt1->u.compnd.nmembs-1, swapped=TRUE; swapped && i>=0; --i) {
- for (j=0, swapped=FALSE; j<i; j++) {
- if (HDstrcmp(dt1->u.compnd.memb[idx1[j]].name,
- dt1->u.compnd.memb[idx1[j+1]].name) > 0) {
- tmp = idx1[j];
- idx1[j] = idx1[j+1];
- idx1[j+1] = tmp;
- swapped = TRUE;
- }
- }
- }
- for (i=dt2->u.compnd.nmembs-1, swapped=TRUE; swapped && i>=0; --i) {
- for (j=0, swapped=FALSE; j<i; j++) {
- if (HDstrcmp(dt2->u.compnd.memb[idx2[j]].name,
- dt2->u.compnd.memb[idx2[j+1]].name) > 0) {
- tmp = idx2[j];
- idx2[j] = idx2[j+1];
- idx2[j+1] = tmp;
- swapped = TRUE;
- }
- }
- }
+ /* Build an index for each type so the names are sorted */
+ if (NULL==(idx1 = H5MM_malloc(dt1->u.compnd.nmembs * sizeof(intn))) ||
+ NULL==(idx2 = H5MM_malloc(dt1->u.compnd.nmembs * sizeof(intn)))) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, 0,
+ "memory allocation failed");
+ }
+ for (i=0; i<dt1->u.compnd.nmembs; i++)
+ idx1[i] = idx2[i] = i;
+ for (i=dt1->u.compnd.nmembs-1, swapped=TRUE; swapped && i>=0; --i) {
+ for (j=0, swapped=FALSE; j<i; j++) {
+ if (HDstrcmp(dt1->u.compnd.memb[idx1[j]].name,
+ dt1->u.compnd.memb[idx1[j+1]].name) > 0) {
+ tmp = idx1[j];
+ idx1[j] = idx1[j+1];
+ idx1[j+1] = tmp;
+ swapped = TRUE;
+ }
+ }
+ }
+ for (i=dt2->u.compnd.nmembs-1, swapped=TRUE; swapped && i>=0; --i) {
+ for (j=0, swapped=FALSE; j<i; j++) {
+ if (HDstrcmp(dt2->u.compnd.memb[idx2[j]].name,
+ dt2->u.compnd.memb[idx2[j+1]].name) > 0) {
+ tmp = idx2[j];
+ idx2[j] = idx2[j+1];
+ idx2[j+1] = tmp;
+ swapped = TRUE;
+ }
+ }
+ }
#ifdef H5T_DEBUG
- /* I don't quite trust the code above yet :-) --RPM */
- for (i=0; i<dt1->u.compnd.nmembs-1; i++) {
- assert(HDstrcmp(dt1->u.compnd.memb[idx1[i]].name,
- dt1->u.compnd.memb[idx1[i + 1]].name));
- assert(HDstrcmp(dt2->u.compnd.memb[idx2[i]].name,
- dt2->u.compnd.memb[idx2[i + 1]].name));
- }
+ /* I don't quite trust the code above yet :-) --RPM */
+ for (i=0; i<dt1->u.compnd.nmembs-1; i++) {
+ assert(HDstrcmp(dt1->u.compnd.memb[idx1[i]].name,
+ dt1->u.compnd.memb[idx1[i + 1]].name));
+ assert(HDstrcmp(dt2->u.compnd.memb[idx2[i]].name,
+ dt2->u.compnd.memb[idx2[i + 1]].name));
+ }
#endif
- /* Compare the members */
- for (i=0; i<dt1->u.compnd.nmembs; i++) {
- tmp = HDstrcmp(dt1->u.compnd.memb[idx1[i]].name,
- dt2->u.compnd.memb[idx2[i]].name);
- if (tmp < 0) HGOTO_DONE(-1);
- if (tmp > 0) HGOTO_DONE(1);
-
- if (dt1->u.compnd.memb[idx1[i]].offset <
- dt2->u.compnd.memb[idx2[i]].offset) HGOTO_DONE(-1);
- if (dt1->u.compnd.memb[idx1[i]].offset >
- dt2->u.compnd.memb[idx2[i]].offset) HGOTO_DONE(1);
-
- if (dt1->u.compnd.memb[idx1[i]].size <
- dt2->u.compnd.memb[idx2[i]].size) HGOTO_DONE(-1);
- if (dt1->u.compnd.memb[idx1[i]].size >
- dt2->u.compnd.memb[idx2[i]].size) HGOTO_DONE(1);
-
- if (dt1->u.compnd.memb[idx1[i]].ndims <
- dt2->u.compnd.memb[idx2[i]].ndims) HGOTO_DONE(-1);
- if (dt1->u.compnd.memb[idx1[i]].ndims >
- dt2->u.compnd.memb[idx2[i]].ndims) HGOTO_DONE(1);
-
- for (j=0; j<dt1->u.compnd.memb[idx1[i]].ndims; j++) {
- if (dt1->u.compnd.memb[idx1[i]].dim[j] <
- dt2->u.compnd.memb[idx2[i]].dim[j]) HGOTO_DONE(-1);
- if (dt1->u.compnd.memb[idx1[i]].dim[j] >
- dt2->u.compnd.memb[idx2[i]].dim[j]) HGOTO_DONE(1);
- }
+ /* Compare the members */
+ for (i=0; i<dt1->u.compnd.nmembs; i++) {
+ tmp = HDstrcmp(dt1->u.compnd.memb[idx1[i]].name,
+ dt2->u.compnd.memb[idx2[i]].name);
+ if (tmp < 0) HGOTO_DONE(-1);
+ if (tmp > 0) HGOTO_DONE(1);
+
+ if (dt1->u.compnd.memb[idx1[i]].offset <
+ dt2->u.compnd.memb[idx2[i]].offset) HGOTO_DONE(-1);
+ if (dt1->u.compnd.memb[idx1[i]].offset >
+ dt2->u.compnd.memb[idx2[i]].offset) HGOTO_DONE(1);
+
+ if (dt1->u.compnd.memb[idx1[i]].size <
+ dt2->u.compnd.memb[idx2[i]].size) HGOTO_DONE(-1);
+ if (dt1->u.compnd.memb[idx1[i]].size >
+ dt2->u.compnd.memb[idx2[i]].size) HGOTO_DONE(1);
+
+ if (dt1->u.compnd.memb[idx1[i]].ndims <
+ dt2->u.compnd.memb[idx2[i]].ndims) HGOTO_DONE(-1);
+ if (dt1->u.compnd.memb[idx1[i]].ndims >
+ dt2->u.compnd.memb[idx2[i]].ndims) HGOTO_DONE(1);
+
+ for (j=0; j<dt1->u.compnd.memb[idx1[i]].ndims; j++) {
+ if (dt1->u.compnd.memb[idx1[i]].dim[j] <
+ dt2->u.compnd.memb[idx2[i]].dim[j]) HGOTO_DONE(-1);
+ if (dt1->u.compnd.memb[idx1[i]].dim[j] >
+ dt2->u.compnd.memb[idx2[i]].dim[j]) HGOTO_DONE(1);
+ }
- for (j=0; j<dt1->u.compnd.memb[idx1[i]].ndims; j++) {
- if (dt1->u.compnd.memb[idx1[i]].perm[j] <
- dt2->u.compnd.memb[idx2[i]].perm[j]) HGOTO_DONE(-1);
- if (dt1->u.compnd.memb[idx1[i]].perm[j] >
- dt2->u.compnd.memb[idx2[i]].perm[j]) HGOTO_DONE(1);
- }
+ for (j=0; j<dt1->u.compnd.memb[idx1[i]].ndims; j++) {
+ if (dt1->u.compnd.memb[idx1[i]].perm[j] <
+ dt2->u.compnd.memb[idx2[i]].perm[j]) HGOTO_DONE(-1);
+ if (dt1->u.compnd.memb[idx1[i]].perm[j] >
+ dt2->u.compnd.memb[idx2[i]].perm[j]) HGOTO_DONE(1);
+ }
- tmp = H5T_cmp(dt1->u.compnd.memb[idx1[i]].type,
- dt2->u.compnd.memb[idx2[i]].type);
- if (tmp < 0) HGOTO_DONE(-1);
- if (tmp > 0) HGOTO_DONE(1);
- }
-
+ tmp = H5T_cmp(dt1->u.compnd.memb[idx1[i]].type,
+ dt2->u.compnd.memb[idx2[i]].type);
+ if (tmp < 0) HGOTO_DONE(-1);
+ if (tmp > 0) HGOTO_DONE(1);
+ }
+
} else if (H5T_ENUM==dt1->type) {
- /*
- * Enumeration data types...
- */
- if (dt1->u.enumer.nmembs < dt2->u.enumer.nmembs) HGOTO_DONE(-1);
- if (dt1->u.enumer.nmembs > dt2->u.enumer.nmembs) HGOTO_DONE(1);
+ /*
+ * Enumeration data types...
+ */
+ if (dt1->u.enumer.nmembs < dt2->u.enumer.nmembs) HGOTO_DONE(-1);
+ if (dt1->u.enumer.nmembs > dt2->u.enumer.nmembs) HGOTO_DONE(1);
- /* Build an index for each type so the names are sorted */
- if (NULL==(idx1 = H5MM_malloc(dt1->u.enumer.nmembs * sizeof(intn))) ||
- NULL==(idx2 = H5MM_malloc(dt1->u.enumer.nmembs * sizeof(intn)))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, 0,
- "memory allocation failed");
- }
- for (i=0; i<dt1->u.enumer.nmembs; i++) idx1[i] = idx2[i] = i;
- for (i=dt1->u.enumer.nmembs-1, swapped=TRUE; swapped && i>=0; --i) {
- for (j=0, swapped=FALSE; j<i; j++) {
- if (HDstrcmp(dt1->u.enumer.name[idx1[j]],
- dt1->u.enumer.name[idx1[j+1]]) > 0) {
- tmp = idx1[j];
- idx1[j] = idx1[j+1];
- idx1[j+1] = tmp;
- swapped = TRUE;
- }
- }
- }
- for (i=dt2->u.enumer.nmembs-1, swapped=TRUE; swapped && i>=0; --i) {
- for (j=0, swapped=FALSE; j<i; j++) {
- if (HDstrcmp(dt2->u.enumer.name[idx2[j]],
- dt2->u.enumer.name[idx2[j+1]]) > 0) {
- tmp = idx2[j];
- idx2[j] = idx2[j+1];
- idx2[j+1] = tmp;
- swapped = TRUE;
- }
- }
- }
+ /* Build an index for each type so the names are sorted */
+ if (NULL==(idx1 = H5MM_malloc(dt1->u.enumer.nmembs * sizeof(intn))) ||
+ NULL==(idx2 = H5MM_malloc(dt1->u.enumer.nmembs * sizeof(intn)))) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, 0,
+ "memory allocation failed");
+ }
+ for (i=0; i<dt1->u.enumer.nmembs; i++)
+ idx1[i] = idx2[i] = i;
+ for (i=dt1->u.enumer.nmembs-1, swapped=TRUE; swapped && i>=0; --i) {
+ for (j=0, swapped=FALSE; j<i; j++) {
+ if (HDstrcmp(dt1->u.enumer.name[idx1[j]],
+ dt1->u.enumer.name[idx1[j+1]]) > 0) {
+ tmp = idx1[j];
+ idx1[j] = idx1[j+1];
+ idx1[j+1] = tmp;
+ swapped = TRUE;
+ }
+ }
+ }
+ for (i=dt2->u.enumer.nmembs-1, swapped=TRUE; swapped && i>=0; --i) {
+ for (j=0, swapped=FALSE; j<i; j++) {
+ if (HDstrcmp(dt2->u.enumer.name[idx2[j]],
+ dt2->u.enumer.name[idx2[j+1]]) > 0) {
+ tmp = idx2[j];
+ idx2[j] = idx2[j+1];
+ idx2[j+1] = tmp;
+ swapped = TRUE;
+ }
+ }
+ }
#ifdef H5T_DEBUG
- /* I don't quite trust the code above yet :-) --RPM */
- for (i=0; i<dt1->u.enumer.nmembs-1; i++) {
- assert(HDstrcmp(dt1->u.enumer.name[idx1[i]],
- dt1->u.enumer.name[idx1[i+1]]));
- assert(HDstrcmp(dt2->u.enumer.name[idx2[i]],
- dt2->u.enumer.name[idx2[i+1]]));
- }
+ /* I don't quite trust the code above yet :-) --RPM */
+ for (i=0; i<dt1->u.enumer.nmembs-1; i++) {
+ assert(HDstrcmp(dt1->u.enumer.name[idx1[i]],
+ dt1->u.enumer.name[idx1[i+1]]));
+ assert(HDstrcmp(dt2->u.enumer.name[idx2[i]],
+ dt2->u.enumer.name[idx2[i+1]]));
+ }
#endif
- /* Compare the members */
- base_size = dt1->parent->size;
- for (i=0; i<dt1->u.enumer.nmembs; i++) {
- tmp = HDstrcmp(dt1->u.enumer.name[idx1[i]],
- dt2->u.enumer.name[idx2[i]]);
- if (tmp<0) HGOTO_DONE(-1);
- if (tmp>0) HGOTO_DONE(1);
-
- tmp = HDmemcmp(dt1->u.enumer.value+idx1[i]*base_size,
- dt2->u.enumer.value+idx2[i]*base_size,
- base_size);
- if (tmp<0) HGOTO_DONE(-1);
- if (tmp>0) HGOTO_DONE(1);
- }
-
+ /* Compare the members */
+ base_size = dt1->parent->size;
+ for (i=0; i<dt1->u.enumer.nmembs; i++) {
+ tmp = HDstrcmp(dt1->u.enumer.name[idx1[i]],
+ dt2->u.enumer.name[idx2[i]]);
+ if (tmp<0) HGOTO_DONE(-1);
+ if (tmp>0) HGOTO_DONE(1);
+
+ tmp = HDmemcmp(dt1->u.enumer.value+idx1[i]*base_size,
+ dt2->u.enumer.value+idx2[i]*base_size,
+ base_size);
+ if (tmp<0) HGOTO_DONE(-1);
+ if (tmp>0) HGOTO_DONE(1);
+ }
+
} else if (H5T_VLEN==dt1->type) {
- /* Arbitrarily sort memory VL datatypes before disk datatypes */
- if (dt1->u.vlen.type==H5T_VLEN_MEMORY &&
- dt2->u.vlen.type==H5T_VLEN_DISK) {
+ assert(dt1->u.vlen.type>H5T_VLEN_BADTYPE && dt1->u.vlen.type<H5T_VLEN_MAXTYPE);
+ assert(dt2->u.vlen.type>H5T_VLEN_BADTYPE && dt2->u.vlen.type<H5T_VLEN_MAXTYPE);
+ assert(dt1->u.vlen.loc>H5T_VLEN_BADLOC && dt1->u.vlen.loc<H5T_VLEN_MAXLOC);
+ assert(dt2->u.vlen.loc>H5T_VLEN_BADLOC && dt2->u.vlen.loc<H5T_VLEN_MAXLOC);
+
+ /* Arbitrarily sort sequence VL datatypes before string VL datatypes */
+ if (dt1->u.vlen.type==H5T_VLEN_SEQUENCE &&
+ dt2->u.vlen.type==H5T_VLEN_STRING) {
+ HGOTO_DONE(-1);
+ } else if (dt1->u.vlen.type==H5T_VLEN_STRING &&
+ dt2->u.vlen.type==H5T_VLEN_SEQUENCE) {
+ HGOTO_DONE(1);
+ }
+ /* Arbitrarily sort VL datatypes in memory before disk */
+ if (dt1->u.vlen.loc==H5T_VLEN_MEMORY &&
+ dt2->u.vlen.loc==H5T_VLEN_DISK) {
HGOTO_DONE(-1);
- } else if (dt1->u.vlen.type==H5T_VLEN_DISK &&
- dt2->u.vlen.type==H5T_VLEN_MEMORY) {
+ } else if (dt1->u.vlen.loc==H5T_VLEN_DISK &&
+ dt2->u.vlen.loc==H5T_VLEN_MEMORY) {
HGOTO_DONE(1);
}
@@ -6466,9 +6513,9 @@ H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name,
H5T_conv_t func)
{
intn lt, rt; /*left and right edges */
- intn md; /*middle */
+ intn md; /*middle */
intn cmp; /*comparison result */
- H5T_path_t *table=NULL; /*path existing in the table */
+ H5T_path_t *table=NULL; /*path existing in the table */
H5T_path_t *path=NULL; /*new path */
H5T_path_t *ret_value=NULL; /*return value */
hid_t src_id=-1, dst_id=-1; /*src and dst type identifiers */
@@ -6482,30 +6529,29 @@ H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name,
* Make sure the first entry in the table is the no-op conversion path.
*/
if (0==H5T_g.npaths) {
- if (NULL==(H5T_g.path=H5MM_malloc(128*sizeof(H5T_path_t*)))) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed for type conversion path "
- "table");
- }
- H5T_g.apaths = 128;
- if (NULL==(H5T_g.path[0]=H5MM_calloc(sizeof(H5T_path_t)))) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed for no-op conversion path");
- }
- HDstrcpy(H5T_g.path[0]->name, "no-op");
- H5T_g.path[0]->func = H5T_conv_noop;
- H5T_g.path[0]->cdata.command = H5T_CONV_INIT;
- if (H5T_conv_noop(FAIL, FAIL, &(H5T_g.path[0]->cdata), 0, 0,
- NULL, NULL, H5P_DEFAULT)<0) {
+ if (NULL==(H5T_g.path=H5MM_malloc(128*sizeof(H5T_path_t*)))) {
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed for type conversion path table");
+ }
+ H5T_g.apaths = 128;
+ if (NULL==(H5T_g.path[0]=H5MM_calloc(sizeof(H5T_path_t)))) {
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed for no-op conversion path");
+ }
+ HDstrcpy(H5T_g.path[0]->name, "no-op");
+ H5T_g.path[0]->func = H5T_conv_noop;
+ H5T_g.path[0]->cdata.command = H5T_CONV_INIT;
+ if (H5T_conv_noop(FAIL, FAIL, &(H5T_g.path[0]->cdata), 0, 0,
+ NULL, NULL, H5P_DEFAULT)<0) {
#ifdef H5T_DEBUG
- if (H5DEBUG(T)) {
- fprintf(H5DEBUG(T), "H5T: unable to initialize no-op "
- "conversion function (ignored)\n");
- }
+ if (H5DEBUG(T)) {
+ fprintf(H5DEBUG(T), "H5T: unable to initialize no-op "
+ "conversion function (ignored)\n");
+ }
#endif
- H5E_clear(); /*ignore the error*/
- }
- H5T_g.npaths = 1;
+ H5E_clear(); /*ignore the error*/
+ }
+ H5T_g.npaths = 1;
}
/*
@@ -6518,27 +6564,28 @@ H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name,
* are set
*/
if (src->force_conv==FALSE && dst->force_conv==FALSE && 0==H5T_cmp(src, dst)) {
- table = H5T_g.path[0];
- cmp = 0;
- md = 0;
+ table = H5T_g.path[0];
+ cmp = 0;
+ md = 0;
} else {
- lt = md = 1;
- rt = H5T_g.npaths;
- cmp = -1;
-
- while (cmp && lt<rt) {
- md = (lt+rt) / 2;
- assert(H5T_g.path[md]);
- cmp = H5T_cmp(src, H5T_g.path[md]->src);
- if (0==cmp) cmp = H5T_cmp(dst, H5T_g.path[md]->dst);
- if (cmp<0) {
- rt = md;
- } else if (cmp>0) {
- lt = md+1;
- } else {
- table = H5T_g.path[md];
- }
- }
+ lt = md = 1;
+ rt = H5T_g.npaths;
+ cmp = -1;
+
+ while (cmp && lt<rt) {
+ md = (lt+rt) / 2;
+ assert(H5T_g.path[md]);
+ cmp = H5T_cmp(src, H5T_g.path[md]->src);
+ if (0==cmp)
+ cmp = H5T_cmp(dst, H5T_g.path[md]->dst);
+ if (cmp<0) {
+ rt = md;
+ } else if (cmp>0) {
+ lt = md+1;
+ } else {
+ table = H5T_g.path[md];
+ }
+ }
}
/*
@@ -6547,23 +6594,23 @@ H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name,
* the path.
*/
if (!table || func) {
- if (NULL==(path=H5MM_calloc(sizeof(H5T_path_t)))) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed for type conversion path");
- }
- if (name && *name) {
- strncpy(path->name, name, H5T_NAMELEN);
- path->name[H5T_NAMELEN-1] = '\0';
- } else {
- strcpy(path->name, "NONAME");
- }
- if ((src && NULL==(path->src=H5T_copy(src, H5T_COPY_ALL))) ||
- (dst && NULL==(path->dst=H5T_copy(dst, H5T_COPY_ALL)))) {
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL,
- "unable to copy data type for conversion path");
- }
+ if (NULL==(path=H5MM_calloc(sizeof(H5T_path_t)))) {
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed for type conversion path");
+ }
+ if (name && *name) {
+ strncpy(path->name, name, H5T_NAMELEN);
+ path->name[H5T_NAMELEN-1] = '\0';
+ } else {
+ strcpy(path->name, "NONAME");
+ }
+ if ((src && NULL==(path->src=H5T_copy(src, H5T_COPY_ALL))) ||
+ (dst && NULL==(path->dst=H5T_copy(dst, H5T_COPY_ALL)))) {
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL,
+ "unable to copy data type for conversion path");
+ }
} else {
- path = table;
+ path = table;
}
/*
@@ -6571,31 +6618,30 @@ H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name,
* path then add it to the path and initialize its conversion data.
*/
if (func) {
- assert(path!=table);
- assert(NULL==path->func);
- if (path->src && (src_id=H5I_register(H5I_DATATYPE,
- H5T_copy(path->src,
- H5T_COPY_ALL)))<0) {
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL,
- "unable to register source conversion type for query");
- }
- if (path->dst && (dst_id=H5I_register(H5I_DATATYPE,
- H5T_copy(path->dst,
- H5T_COPY_ALL)))<0) {
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL,
- "unable to register destination conversion type for "
- "query");
- }
- path->cdata.command = H5T_CONV_INIT;
- if ((func)(src_id, dst_id, &(path->cdata), 0, 0, NULL, NULL, H5P_DEFAULT)<0) {
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL,
- "unable to initialize conversion function");
- }
- if (src_id>=0) H5I_dec_ref(src_id);
- if (dst_id>=0) H5I_dec_ref(dst_id);
- src_id = dst_id = -1;
- path->func = func;
- path->is_hard = TRUE;
+ assert(path!=table);
+ assert(NULL==path->func);
+ if (path->src && (src_id=H5I_register(H5I_DATATYPE,
+ H5T_copy(path->src, H5T_COPY_ALL)))<0) {
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL,
+ "unable to register source conversion type for query");
+ }
+ if (path->dst && (dst_id=H5I_register(H5I_DATATYPE,
+ H5T_copy(path->dst, H5T_COPY_ALL)))<0) {
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL,
+ "unable to register destination conversion type for query");
+ }
+ path->cdata.command = H5T_CONV_INIT;
+ if ((func)(src_id, dst_id, &(path->cdata), 0, 0, NULL, NULL, H5P_DEFAULT)<0) {
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL,
+ "unable to initialize conversion function");
+ }
+ if (src_id>=0)
+ H5I_dec_ref(src_id);
+ if (dst_id>=0)
+ H5I_dec_ref(dst_id);
+ src_id = dst_id = -1;
+ path->func = func;
+ path->is_hard = TRUE;
}
/*
@@ -6606,86 +6652,91 @@ H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name,
*/
assert(path->func || (src && dst));
for (i=H5T_g.nsoft-1; i>=0 && !path->func; --i) {
- if (src->type!=H5T_g.soft[i].src ||
- dst->type!=H5T_g.soft[i].dst) {
- continue;
- }
- if ((src_id=H5I_register(H5I_DATATYPE,
- H5T_copy(path->src, H5T_COPY_ALL)))<0 ||
- (dst_id=H5I_register(H5I_DATATYPE,
- H5T_copy(path->dst, H5T_COPY_ALL)))<0) {
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL,
- "unable to register conversion types for query");
- }
- path->cdata.command = H5T_CONV_INIT;
- if ((H5T_g.soft[i].func) (src_id, dst_id, &(path->cdata),
- 0, 0, NULL, NULL, H5P_DEFAULT)<0) {
- HDmemset (&(path->cdata), 0, sizeof(H5T_cdata_t));
- H5E_clear(); /*ignore the error*/
- } else {
- HDstrcpy (path->name, H5T_g.soft[i].name);
- path->func = H5T_g.soft[i].func;
- path->is_hard = FALSE;
- }
- H5I_dec_ref(src_id);
- H5I_dec_ref(dst_id);
- src_id = dst_id = -1;
+ if (src->type!=H5T_g.soft[i].src || dst->type!=H5T_g.soft[i].dst)
+ continue;
+ if ((src_id=H5I_register(H5I_DATATYPE,
+ H5T_copy(path->src, H5T_COPY_ALL)))<0 ||
+ (dst_id=H5I_register(H5I_DATATYPE,
+ H5T_copy(path->dst, H5T_COPY_ALL)))<0) {
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL,
+ "unable to register conversion types for query");
+ }
+ path->cdata.command = H5T_CONV_INIT;
+ if ((H5T_g.soft[i].func) (src_id, dst_id, &(path->cdata),
+ 0, 0, NULL, NULL, H5P_DEFAULT)<0) {
+ HDmemset (&(path->cdata), 0, sizeof(H5T_cdata_t));
+ H5E_clear(); /*ignore the error*/
+ } else {
+ HDstrcpy (path->name, H5T_g.soft[i].name);
+ path->func = H5T_g.soft[i].func;
+ path->is_hard = FALSE;
+ }
+ H5I_dec_ref(src_id);
+ H5I_dec_ref(dst_id);
+ src_id = dst_id = -1;
}
if (!path->func) {
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL,
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL,
"no appropriate function for conversion path");
}
/* Replace an existing table entry or add a new entry */
if (table && path!=table) {
- assert(table==H5T_g.path[md]);
- H5T_print_stats(table, &nprint/*in,out*/);
- table->cdata.command = H5T_CONV_FREE;
- if ((table->func)(FAIL, FAIL, &(table->cdata), 0, 0, NULL, NULL, H5P_DEFAULT)<0) {
+ assert(table==H5T_g.path[md]);
+ H5T_print_stats(table, &nprint/*in,out*/);
+ table->cdata.command = H5T_CONV_FREE;
+ if ((table->func)(FAIL, FAIL, &(table->cdata), 0, 0, NULL, NULL, H5P_DEFAULT)<0) {
#ifdef H5T_DEBUG
- if (H5DEBUG(T)) {
- fprintf(H5DEBUG(T), "H5T: conversion function 0x%08lx free "
- "failed for %s (ignored)\n",
- (unsigned long)(path->func), path->name);
- }
+ if (H5DEBUG(T)) {
+ fprintf(H5DEBUG(T), "H5T: conversion function 0x%08lx free "
+ "failed for %s (ignored)\n",
+ (unsigned long)(path->func), path->name);
+ }
#endif
- H5E_clear(); /*ignore the failure*/
- }
- if (table->src) H5T_close(table->src);
- if (table->dst) H5T_close(table->dst);
- H5MM_xfree(table);
- table = path;
- H5T_g.path[md] = path;
+ H5E_clear(); /*ignore the failure*/
+ }
+ if (table->src)
+ H5T_close(table->src);
+ if (table->dst)
+ H5T_close(table->dst);
+ H5MM_xfree(table);
+ table = path;
+ H5T_g.path[md] = path;
} else if (path!=table) {
- assert(cmp);
+ assert(cmp);
if (H5T_g.npaths >= H5T_g.apaths) {
size_t na = MAX(128, 2 * H5T_g.apaths);
H5T_path_t **x = H5MM_realloc (H5T_g.path,
na*sizeof(H5T_path_t*));
if (!x) {
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
H5T_g.apaths = (intn)na;
H5T_g.path = x;
}
- if (cmp>0) md++;
+ if (cmp>0)
+ md++;
HDmemmove(H5T_g.path+md+1, H5T_g.path+md,
(H5T_g.npaths-md) * sizeof(H5T_path_t*));
H5T_g.npaths++;
- H5T_g.path[md] = path;
- table = path;
+ H5T_g.path[md] = path;
+ table = path;
}
ret_value = path;
- done:
+done:
if (!ret_value && path && path!=table) {
- if (path->src) H5T_close(path->src);
- if (path->dst) H5T_close(path->dst);
- H5MM_xfree(path);
- }
- if (src_id>=0) H5I_dec_ref(src_id);
- if (dst_id>=0) H5I_dec_ref(dst_id);
+ if (path->src)
+ H5T_close(path->src);
+ if (path->dst)
+ H5T_close(path->dst);
+ H5MM_xfree(path);
+ }
+ if (src_id>=0)
+ H5I_dec_ref(src_id);
+ if (dst_id>=0)
+ H5I_dec_ref(dst_id);
FUNC_LEAVE(ret_value);
}
@@ -6731,19 +6782,20 @@ H5T_convert(H5T_path_t *tpath, hid_t src_id, hid_t dst_id, size_t nelmts,
FUNC_ENTER(H5T_convert, FAIL);
#ifdef H5T_DEBUG
- if (H5DEBUG(T)) H5_timer_begin(&timer);
+ if (H5DEBUG(T))
+ H5_timer_begin(&timer);
#endif
tpath->cdata.command = H5T_CONV_CONV;
if ((tpath->func)(src_id, dst_id, &(tpath->cdata), nelmts, stride, buf,
bkg, dset_xfer_plist)<0) {
- HRETURN_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL,
+ HRETURN_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL,
"data type conversion failed");
}
#ifdef H5T_DEBUG
if (H5DEBUG(T)) {
- H5_timer_end(&(tpath->stats.timer), &timer);
- tpath->stats.ncalls++;
- tpath->stats.nelmts += nelmts;
+ H5_timer_end(&(tpath->stats.timer), &timer);
+ tpath->stats.ncalls++;
+ tpath->stats.nelmts += nelmts;
}
#endif