summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2005-07-23 19:58:13 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2005-07-23 19:58:13 (GMT)
commitc92ac941072e08b5e1196edac3dd98983b9def5e (patch)
tree243cbccc1628e3b97ccc16a6ffd42d99689379c0 /src
parent34bd25f361f81efc396314528f1824fe63af494e (diff)
downloadhdf5-c92ac941072e08b5e1196edac3dd98983b9def5e.zip
hdf5-c92ac941072e08b5e1196edac3dd98983b9def5e.tar.gz
hdf5-c92ac941072e08b5e1196edac3dd98983b9def5e.tar.bz2
[svn-r11145] Purpose:
Bug fix Description: If a named datatype is copied and the copy is used to create a dataset, the dataset would inadvertantly refer to the original named datatype instead of a local (possibly modified) copy of the named datatype. Solution: Fixed datatype copying routine. Platforms tested: FreeBSD 4.11 (sleipnir) Too minor to require h5committest
Diffstat (limited to 'src')
-rw-r--r--src/H5Odtype.c4
-rw-r--r--src/H5T.c45
2 files changed, 31 insertions, 18 deletions
diff --git a/src/H5Odtype.c b/src/H5Odtype.c
index 646a9b1..0ab8bc5 100644
--- a/src/H5Odtype.c
+++ b/src/H5Odtype.c
@@ -1140,8 +1140,8 @@ H5O_dtype_get_share(H5F_t UNUSED *f, const void *_mesg,
assert (sh);
if (H5F_addr_defined (dt->ent.header)) {
- if(H5T_STATE_NAMED!=dt->shared->state && H5T_STATE_OPEN!=dt->shared->state && H5T_STATE_TRANSIENT!=dt->shared->state)
- HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "datatype state is not valid");
+ /* If the address is defined, this had better be a named datatype */
+ HDassert (H5T_STATE_NAMED==dt->shared->state || H5T_STATE_OPEN==dt->shared->state);
sh->in_gh = FALSE;
sh->u.ent = dt->ent;
diff --git a/src/H5T.c b/src/H5T.c
index 575a9fe..0d3b830 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -442,10 +442,11 @@ static H5T_t *H5T_decode(const unsigned char *buf);
/* Allocate new datatype info */ \
if (NULL==(dt = H5FL_CALLOC(H5T_t))) \
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") \
- if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t))) { \
- H5FL_FREE(H5T_t, dt); \
+ dt->ent.header = HADDR_UNDEF; \
+ if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t))) { \
+ H5FL_FREE(H5T_t, dt); \
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") \
- } \
+ } \
}
@@ -2937,6 +2938,7 @@ H5T_create(H5T_class_t type, size_t size)
case H5T_COMPOUND:
if (NULL==(dt = H5FL_CALLOC(H5T_t)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ dt->ent.header = HADDR_UNDEF;
if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
dt->shared->type = type;
@@ -2965,6 +2967,7 @@ H5T_create(H5T_class_t type, size_t size)
}
if (NULL==(dt = H5FL_CALLOC(H5T_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ dt->ent.header = HADDR_UNDEF;
if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
dt->shared->type = type;
@@ -3218,8 +3221,7 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
if (NULL==(new_dt->shared = H5FL_MALLOC(H5T_shared_t)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- /* Copy actual information */
- new_dt->ent = old_dt->ent;
+ /* Copy shared information (entry information is copied last) */
*(new_dt->shared) = *(old_dt->shared);
/* Copy parent information */
@@ -3233,8 +3235,6 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
* Return an unlocked transient type.
*/
new_dt->shared->state = H5T_STATE_TRANSIENT;
- HDmemset (&(new_dt->ent), 0, sizeof(new_dt->ent));
- new_dt->ent.header = HADDR_UNDEF;
break;
case H5T_COPY_ALL:
@@ -3242,9 +3242,9 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
* 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->shared->state) {
+ if (H5T_STATE_OPEN==old_dt->shared->state) {
new_dt->shared->state = H5T_STATE_NAMED;
- } else if (H5T_STATE_IMMUTABLE==new_dt->shared->state) {
+ } else if (H5T_STATE_IMMUTABLE==old_dt->shared->state) {
new_dt->shared->state = H5T_STATE_RDONLY;
}
break;
@@ -3254,15 +3254,20 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
* Return a transient type (locked or unlocked) or an opened named
* type. Immutable transient types are degraded to read-only.
*/
- if (H5F_addr_defined(new_dt->ent.header)) {
+ if (H5F_addr_defined(old_dt->ent.header)) {
/* Check if the object is already open */
- if((reopened_fo=H5FO_opened(new_dt->ent.file,new_dt->ent.header))==NULL) {
+ if((reopened_fo=H5FO_opened(old_dt->ent.file, old_dt->ent.header))==NULL) {
/* Clear any errors from H5FO_opened() */
H5E_clear_stack(NULL);
- if (H5O_open (&(new_dt->ent))<0)
+
+ /* Open named datatype again */
+ if (H5O_open (&(old_dt->ent))<0)
HGOTO_ERROR (H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to reopen named data type");
- if(H5FO_insert(new_dt->ent.file, new_dt->ent.header,new_dt->shared)<0)
+
+ /* Insert opened named datatype into opened object list for the file */
+ if(H5FO_insert(old_dt->ent.file, old_dt->ent.header, new_dt->shared)<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, NULL, "can't insert datatype into list of open objects")
+
new_dt->shared->fo_count=1;
} else {
/* The object is already open. Free the H5T_shared_t struct
@@ -3270,10 +3275,11 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
* Not terribly efficient. */
H5FL_FREE(H5T_shared_t, new_dt->shared);
new_dt->shared = reopened_fo;
+
reopened_fo->fo_count++;
}
new_dt->shared->state = H5T_STATE_OPEN;
- } else if (H5T_STATE_IMMUTABLE==new_dt->shared->state) {
+ } else if (H5T_STATE_IMMUTABLE==old_dt->shared->state) {
new_dt->shared->state = H5T_STATE_RDONLY;
}
break;
@@ -3386,9 +3392,16 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
} /* end switch */
/* Deep copy of the symbol table entry, if there was one */
- if (H5F_addr_defined(old_dt->ent.header))
+ if ( new_dt->shared->state == H5T_STATE_NAMED || new_dt->shared->state == H5T_STATE_OPEN) {
+ if (!H5F_addr_defined(old_dt->ent.header))
+ HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, NULL, "named dataype with invalid address");
if (H5G_ent_copy(&(new_dt->ent), &(old_dt->ent),H5G_COPY_DEEP)<0)
HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, NULL, "unable to copy entry");
+ } /* end if */
+ else {
+ HDmemset (&(new_dt->ent), 0, sizeof(new_dt->ent));
+ new_dt->ent.header = HADDR_UNDEF;
+ } /* end else */
/* Set return value */
ret_value=new_dt;
@@ -3994,7 +4007,7 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset)
/* Compare the members */
base_size = dt1->shared->parent->shared->size;
for (u=0; u<dt1->shared->u.enumer.nmembs; u++) {
- unsigned idx;
+ unsigned idx = 0;
if(superset) {
unsigned lt = 0, rt; /* Final, left & right key indices */