summaryrefslogtreecommitdiffstats
path: root/src/H5T.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1998-02-25 20:31:17 (GMT)
committerRobb Matzke <matzke@llnl.gov>1998-02-25 20:31:17 (GMT)
commitad73f18f5e759c4bd3d12c331659a24b54d0c39a (patch)
tree660a8bb32cc118a647757c5ae2321cf9b1ca9073 /src/H5T.c
parentc543632ba5cd609d2e6303fa9cf55685568fa851 (diff)
downloadhdf5-ad73f18f5e759c4bd3d12c331659a24b54d0c39a.zip
hdf5-ad73f18f5e759c4bd3d12c331659a24b54d0c39a.tar.gz
hdf5-ad73f18f5e759c4bd3d12c331659a24b54d0c39a.tar.bz2
[svn-r298] Changes since 19980219
---------------------- ./html/Files.html ./src/H5C.c ./src/H5Cpublic.h ./src/H5Ffamily.c ./src/H5Fprivate.h ./src/H5Fsplit.c ./test/tstab.c Added file-access property functions. The split driver takes file extensions as properties. ./src/H5A.c ./src/H5Aprivate.h Added some comments. Changed H5A_destroy() to call the free function on all the atoms that are destroyed. This fixes a bug where the file boot block isn't updated if the file isn't closed before calling exit(). Removed extra `*' and `&' from some places. ./src/H5AC.c Replaced an occurrence of NO_ADDR with NULL. ./src/H5Odtype.c ./src/H5T.c ./src/H5Tconv.c ./src/H5Tpkg.h Data types of compound members are pointers. ./H5private.h Some changes to make lseek64() work on Irix 5.3 where header files don't realize that `long long' works. ./acconfig.h ./configure.in Removed definition for PHDF5 since it looks like everyone is useing HAVE_PARALLEL now. ./configure.in ./src/H5detec.c Added checks for gethostname() and getpwuid().
Diffstat (limited to 'src/H5T.c')
-rw-r--r--src/H5T.c58
1 files changed, 33 insertions, 25 deletions
diff --git a/src/H5T.c b/src/H5T.c
index b34860b..e932e0f 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -1959,7 +1959,7 @@ H5Tget_member_type(hid_t type_id, int membno)
HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid member number");
}
/* Copy data type into an atom */
- if (NULL == (memb_dt = H5T_copy(&(dt->u.compnd.memb[membno].type)))) {
+ if (NULL == (memb_dt = H5T_copy(dt->u.compnd.memb[membno].type))) {
HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL,
"unable to copy member data type");
}
@@ -2464,10 +2464,10 @@ H5T_create(H5T_class_t type, size_t size)
*
*-------------------------------------------------------------------------
*/
-H5T_t *
+H5T_t *
H5T_copy(const H5T_t *old_dt)
{
- H5T_t *new_dt = NULL;
+ H5T_t *new_dt=NULL, *tmp=NULL;
intn i;
char *s;
@@ -2482,13 +2482,21 @@ H5T_copy(const H5T_t *old_dt)
new_dt->locked = FALSE;
if (H5T_COMPOUND == new_dt->type) {
+ /*
+ * Copy all member fields to new type, then overwrite the
+ * name and type fields of each new member with copied values.
+ * That is, H5T_copy() is a deep copy.
+ */
new_dt->u.compnd.memb = H5MM_xmalloc(new_dt->u.compnd.nmembs *
sizeof(H5T_member_t));
HDmemcpy(new_dt->u.compnd.memb, old_dt->u.compnd.memb,
new_dt->u.compnd.nmembs * sizeof(H5T_member_t));
+
for (i = 0; i < new_dt->u.compnd.nmembs; i++) {
s = new_dt->u.compnd.memb[i].name;
new_dt->u.compnd.memb[i].name = H5MM_xstrdup(s);
+ tmp = H5T_copy (old_dt->u.compnd.memb[i].type);
+ new_dt->u.compnd.memb[i].type = tmp;
}
}
FUNC_LEAVE(new_dt);
@@ -2497,7 +2505,8 @@ H5T_copy(const H5T_t *old_dt)
/*-------------------------------------------------------------------------
* Function: H5T_close
*
- * Purpose: Frees a data type and all associated memory.
+ * Purpose: Frees a data type and all associated memory. If the data
+ * type is locked then nothing happens.
*
* Return: Success: SUCCEED
*
@@ -2513,23 +2522,25 @@ H5T_copy(const H5T_t *old_dt)
herr_t
H5T_close(H5T_t *dt)
{
- intn i;
+ intn i;
FUNC_ENTER(H5T_close, FAIL);
assert(dt);
- assert(!dt->locked);
- if (dt && H5T_COMPOUND == dt->type) {
- for (i = 0; i < dt->u.compnd.nmembs; i++) {
- H5MM_xfree(dt->u.compnd.memb[i].name);
- }
- H5MM_xfree(dt->u.compnd.memb);
- H5MM_xfree(dt);
+ if (!dt->locked) {
+ if (dt && H5T_COMPOUND == dt->type) {
+ for (i = 0; i < dt->u.compnd.nmembs; i++) {
+ H5MM_xfree(dt->u.compnd.memb[i].name);
+ }
+ H5MM_xfree(dt->u.compnd.memb);
+ H5MM_xfree(dt);
- } else if (dt) {
- H5MM_xfree(dt);
+ } else if (dt) {
+ H5MM_xfree(dt);
+ }
}
+
FUNC_LEAVE(SUCCEED);
}
@@ -2611,7 +2622,6 @@ herr_t
H5T_insert(H5T_t *parent, const char *name, off_t offset, const H5T_t *member)
{
intn i;
- H5T_t *tmp = NULL;
FUNC_ENTER(H5T_insert, FAIL);
@@ -2635,7 +2645,7 @@ H5T_insert(H5T_t *parent, const char *name, off_t offset, const H5T_t *member)
offset + member->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].type.size > offset)) {
+ parent->u.compnd.memb[i].type->size > offset)) {
HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL,
"member overlaps with another member");
}
@@ -2648,15 +2658,13 @@ H5T_insert(H5T_t *parent, const char *name, off_t offset, const H5T_t *member)
(parent->u.compnd.nalloc *
sizeof(H5T_member_t)));
}
+
/* Add member to end of member array */
i = parent->u.compnd.nmembs;
parent->u.compnd.memb[i].name = H5MM_xstrdup(name);
parent->u.compnd.memb[i].offset = offset;
parent->u.compnd.memb[i].ndims = 0; /*defaults to scalar */
-
- tmp = H5T_copy(member);
- parent->u.compnd.memb[i].type = *tmp;
- H5MM_xfree(tmp);
+ parent->u.compnd.memb[i].type = H5T_copy (member);
parent->u.compnd.nmembs++;
FUNC_LEAVE(SUCCEED);
@@ -2693,7 +2701,7 @@ H5T_pack(H5T_t *dt)
if (H5T_COMPOUND == dt->type) {
/* Recursively pack the members */
for (i = 0; i < dt->u.compnd.nmembs; i++) {
- if (H5T_pack(&(dt->u.compnd.memb[i].type)) < 0) {
+ if (H5T_pack(dt->u.compnd.memb[i].type) < 0) {
HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL,
"unable to pack part of a compound data type");
}
@@ -2703,7 +2711,7 @@ H5T_pack(H5T_t *dt)
H5T_sort_by_offset(dt);
for (i = 0, offset = 0; i < dt->u.compnd.nmembs; i++) {
dt->u.compnd.memb[i].offset = offset;
- offset += dt->u.compnd.memb[i].type.size;
+ offset += H5T_get_size (dt->u.compnd.memb[i].type);
}
/* Change total size */
@@ -2880,8 +2888,8 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2)
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));
+ 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);
}
@@ -3340,7 +3348,7 @@ H5T_debug(H5T_t *dt, FILE * stream)
fprintf(stream, "]");
}
fprintf(stream, " ");
- H5T_debug(&(dt->u.compnd.memb[i].type), stream);
+ H5T_debug(dt->u.compnd.memb[i].type, stream);
}
fprintf(stream, "\n");
}