summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5A.c109
-rw-r--r--src/H5G.c2
-rw-r--r--src/H5O.c12
-rw-r--r--src/H5Oattr.c14
-rw-r--r--src/H5T.c1
-rw-r--r--test/tattr.c8
-rw-r--r--test/tstab.c6
7 files changed, 82 insertions, 70 deletions
diff --git a/src/H5A.c b/src/H5A.c
index 0c08dc8..f19732c 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -105,7 +105,7 @@ H5A_init_interface(void)
static void
H5A_term_interface(void)
{
- H5I_destroy_group (H5_ATTR);
+ H5I_destroy_group(H5_ATTR);
}
@@ -152,12 +152,14 @@ H5Acreate(hid_t loc_id, const char *name, hid_t datatype, hid_t dataspace,
H5T_t *type = NULL;
H5S_t *space = NULL;
const H5D_create_t *create_parms = NULL;
+ H5A_t found_attr;
+ intn seq=0;
hid_t ret_value = FAIL;
FUNC_ENTER(H5Acreate, FAIL);
/* check arguments */
- if (!(H5_DATASET != H5I_group(loc_id) || H5_GROUP != H5I_group(loc_id))) {
+ if (!(H5_DATASET == H5I_group(loc_id) || H5_GROUP == H5I_group(loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "attribute target not a dataset or group");
}
if (!name || !*name) {
@@ -189,6 +191,20 @@ H5Acreate(hid_t loc_id, const char *name, hid_t datatype, hid_t dataspace,
else
ent = H5G_entof ((H5G_t*)obj);
+ /* Read in the existing attributes to check for duplicates */
+ seq=0;
+ while(H5O_read(ent, H5O_ATTR, seq, &found_attr)!=NULL)
+ {
+ /* Compare found attribute name to new attribute name reject creation if names are the same */
+ if(HDstrcmp(found_attr.name,name)==0) {
+ H5O_reset (H5O_ATTR, &found_attr);
+ HRETURN_ERROR(H5E_ATTR, H5E_CANTCREATE, FAIL,
+ "attribute already exists");
+ }
+ seq++;
+ H5O_reset (H5O_ATTR, &found_attr);
+ } /* end while */
+
/* Go do the real work for attaching the attribute to the dataset */
ret_value=H5A_create(ent,name,type,space);
@@ -220,8 +236,6 @@ static hid_t
H5A_create(const H5G_entry_t *ent, const char *name, const H5T_t *type, const H5S_t *space)
{
H5A_t *attr = NULL;
- H5A_t found_attr;
- intn seq=0;
hid_t ret_value = FAIL;
FUNC_ENTER(H5A_create, FAIL);
@@ -254,22 +268,6 @@ H5A_create(const H5G_entry_t *ent, const char *name, const H5T_t *type, const H5
}
attr->ent_opened=1;
- /* Read in the existing attributes to check for duplicates */
- seq=0;
- while(H5O_read(&(attr->ent), H5O_ATTR, seq, &found_attr)!=NULL) {
- /*
- * Compare found attribute name to new attribute name reject creation
- * if names are the same.
- */
- if(HDstrcmp(found_attr.name,attr->name)==0) {
- H5O_reset (H5O_ATTR, &found_attr);
- HGOTO_ERROR(H5E_ATTR, H5E_CANTCREATE, FAIL,
- "attribute already exists");
- }
- H5O_reset (H5O_ATTR, &found_attr);
- seq++;
- } /* end while */
-
/* Create the attribute message and save the attribute index */
if (H5O_modify(&(attr->ent), H5O_ATTR, H5O_NEW_MESG, 0, attr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL,
@@ -324,24 +322,21 @@ H5A_get_index(H5G_entry_t *ent, const char *name)
/* Look up the attribute for the object */
i=0;
- while(H5O_read(ent, H5O_ATTR, i, &found_attr)!=NULL) {
- /*
- * Compare found attribute name to new attribute name reject creation
- * if names are the same.
- */
- if(HDstrcmp(found_attr.name,name)==0) {
- H5O_reset (H5O_ATTR, &found_attr);
- ret_value = i;
- break;
- }
- H5O_reset (H5O_ATTR, &found_attr);
- i++;
- } /* end while */
-
+ while(H5O_read(ent, H5O_ATTR, i, &found_attr)!=NULL)
+ {
+ /* Compare found attribute name to new attribute name reject creation if names are the same */
+ if(HDstrcmp(found_attr.name,name)==0) {
+ H5O_reset (H5O_ATTR, &found_attr);
+ ret_value=i;
+ break;
+ }
+ H5O_reset (H5O_ATTR, &found_attr);
+ i++;
+ } /* end while */
if(ret_value<0) {
HRETURN_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL,
"attribute not found");
- }
+ }
FUNC_LEAVE(ret_value);
} /* H5A_get_index() */
@@ -380,7 +375,7 @@ H5Aopen_name(hid_t loc_id, const char *name)
FUNC_ENTER(H5Aopen_name, FAIL);
/* check arguments */
- if (!(H5_DATASET != H5I_group(loc_id) || H5_GROUP != H5I_group(loc_id))) {
+ if (!(H5_DATASET == H5I_group(loc_id) || H5_GROUP == H5I_group(loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "attribute target not a dataset or group");
}
if (!name || !*name) {
@@ -440,7 +435,7 @@ H5Aopen_idx(hid_t loc_id, unsigned idx)
FUNC_ENTER(H5Aopen_idx, FAIL);
/* check arguments */
- if (!(H5_DATASET != H5I_group(loc_id) || H5_GROUP != H5I_group(loc_id))) {
+ if (!(H5_DATASET == H5I_group(loc_id) || H5_GROUP == H5I_group(loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "attribute target not a dataset or group");
}
@@ -613,7 +608,6 @@ H5A_write(H5A_t *attr, const H5T_t *mem_type, void *buf)
assert(mem_type);
assert(buf);
-
/* Create buffer for data to store on disk */
nelmts=H5S_get_npoints (attr->ds);
@@ -1021,7 +1015,7 @@ H5Anum_attrs(hid_t loc_id)
FUNC_ENTER(H5Anum_attrs, FAIL);
/* check arguments */
- if (!(H5_DATASET != H5I_group(loc_id) || H5_GROUP != H5I_group(loc_id))) {
+ if (!(H5_DATASET == H5I_group(loc_id) || H5_GROUP == H5I_group(loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "attribute target not a dataset or group");
}
@@ -1090,7 +1084,7 @@ H5Aiterate(hid_t loc_id, unsigned *attr_num, H5A_operator_t op, void *op_data)
FUNC_ENTER(H5Anum_attrs, FAIL);
/* check arguments */
- if (!(H5_DATASET != H5I_group(loc_id) || H5_GROUP != H5I_group(loc_id))) {
+ if (!(H5_DATASET == H5I_group(loc_id) || H5_GROUP == H5I_group(loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "attribute target not a dataset or group");
}
if (!attr_num) {
@@ -1117,9 +1111,9 @@ H5Aiterate(hid_t loc_id, unsigned *attr_num, H5A_operator_t op, void *op_data)
/* Compare found attribute name to new attribute name reject creation if names are the same */
(*attr_num)++;
if((ret_value=op(loc_id,found_attr.name,op_data))!=0) {
- H5O_reset (H5O_ATTR, &found_attr);
+ H5O_reset (H5O_ATTR, &found_attr);
break;
- }
+ }
H5O_reset (H5O_ATTR, &found_attr);
} /* end while */
@@ -1159,7 +1153,7 @@ H5Adelete(hid_t loc_id, const char *name)
FUNC_ENTER(H5Aopen_name, FAIL);
/* check arguments */
- if (!(H5_DATASET != H5I_group(loc_id) || H5_GROUP != H5I_group(loc_id))) {
+ if (!(H5_DATASET == H5I_group(loc_id) || H5_GROUP == H5I_group(loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "attribute target not a dataset or group");
}
if (!name || !*name) {
@@ -1178,20 +1172,18 @@ H5Adelete(hid_t loc_id, const char *name)
/* Look up the attribute for the object */
idx=0;
- while(H5O_read(ent, H5O_ATTR, idx, &found_attr)!=NULL) {
- /*
- * Compare found attribute name to new attribute name reject
- * creation if names are the same.
- */
- if(HDstrcmp(found_attr.name,name)==0) {
- H5O_reset (H5O_ATTR, &found_attr);
- found = idx;
- break;
- }
- H5O_reset (H5O_ATTR, &found_attr);
- idx++;
- } /* end while */
- if (found<0) {
+ while(H5O_read(ent, H5O_ATTR, idx, &found_attr)!=NULL)
+ {
+ /* Compare found attribute name to new attribute name reject creation if names are the same */
+ if(HDstrcmp(found_attr.name,name)==0) {
+ H5O_reset (H5O_ATTR, &found_attr);
+ found=idx;
+ break;
+ }
+ H5O_reset (H5O_ATTR, &found_attr);
+ idx++;
+ } /* end while */
+ if(found<0) {
HRETURN_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL,
"attribute not found");
}
@@ -1228,8 +1220,7 @@ H5Aclose(hid_t attr_id)
FUNC_ENTER(H5Aclose, FAIL);
/* check arguments */
- if (H5_ATTR != H5I_group(attr_id) ||
- NULL == H5I_object(attr_id)) {
+ if (H5_ATTR != H5I_group(attr_id) || NULL == H5I_object(attr_id)) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute");
}
diff --git a/src/H5G.c b/src/H5G.c
index 98399aa..295828e 100644
--- a/src/H5G.c
+++ b/src/H5G.c
@@ -1290,6 +1290,8 @@ H5G_close(H5G_t *grp)
}
}
--grp->nref;
+ if(grp->nref==0)
+ H5MM_xfree(grp);
FUNC_LEAVE(SUCCEED);
}
diff --git a/src/H5O.c b/src/H5O.c
index bdf2efd..0c3a146 100644
--- a/src/H5O.c
+++ b/src/H5O.c
@@ -1448,9 +1448,13 @@ H5O_alloc_new_chunk(H5F_t *f, H5O_t *oh, size_t size)
* that could be generated below.
*/
if (oh->nmesgs + 3 > oh->alloc_nmesgs) {
- oh->alloc_nmesgs += MAX(H5O_NMESGS, 3);
- oh->mesg = H5MM_xrealloc(oh->mesg,
+ int old_alloc=oh->alloc_nmesgs;
+
+ oh->alloc_nmesgs += MAX(H5O_NMESGS, 3);
+ oh->mesg = H5MM_xrealloc(oh->mesg,
oh->alloc_nmesgs * sizeof(H5O_mesg_t));
+ /* Set new object header info to zeros */
+ HDmemset(&oh->mesg[old_alloc],0,(oh->alloc_nmesgs-old_alloc)*sizeof(H5O_mesg_t));
}
/*
@@ -1592,9 +1596,13 @@ H5O_alloc(H5F_t *f, H5O_t *oh, const H5O_class_t *type, size_t size)
assert(oh->mesg[idx].raw_size - size >= H5O_SIZEOF_MSGHDR(f));
if (oh->nmesgs >= oh->alloc_nmesgs) {
+ int old_alloc=oh->alloc_nmesgs;
+
oh->alloc_nmesgs += H5O_NMESGS;
oh->mesg = H5MM_xrealloc(oh->mesg,
oh->alloc_nmesgs * sizeof(H5O_mesg_t));
+ /* Set new object header info to zeros */
+ HDmemset(&oh->mesg[old_alloc],0,(oh->alloc_nmesgs-old_alloc)*sizeof(H5O_mesg_t));
}
null_idx = oh->nmesgs++;
oh->mesg[null_idx].type = H5O_NULL;
diff --git a/src/H5Oattr.c b/src/H5Oattr.c
index 2671b38..320c713 100644
--- a/src/H5Oattr.c
+++ b/src/H5Oattr.c
@@ -95,23 +95,23 @@ H5O_attr_decode(H5F_t *f, const uint8 *p, H5HG_t __unused__ *hobj)
p+=name_len; /* advance the memory pointer */
/* decode the attribute datatype */
- if((attr->dt=(H5O_DTYPE[0].decode)(f,p,NULL))==NULL) {
+ if((attr->dt=(H5O_DTYPE->decode)(f,p,NULL))==NULL) {
HRETURN_ERROR(H5E_ATTR, H5E_CANTDECODE, NULL,
"can't decode attribute datatype");
}
- attr->dt_size=(H5O_DTYPE[0].raw_size)(f,attr->dt);
+ attr->dt_size=(H5O_DTYPE->raw_size)(f,attr->dt);
p+=attr->dt_size;
/* decode the attribute dataspace */
attr->ds = H5MM_xcalloc(1, sizeof(H5S_t));
- if((simple=(H5O_SDSPACE[0].decode)(f,p,NULL))!=NULL) {
+ if((simple=(H5O_SDSPACE->decode)(f,p,NULL))!=NULL) {
attr->ds->type = H5S_SIMPLE;
HDmemcpy(&(attr->ds->u.simple),simple, sizeof(H5S_simple_t));
H5MM_xfree(simple);
} else {
attr->ds->type = H5S_SCALAR;
} /* end else */
- attr->ds_size=(H5O_SDSPACE[0].raw_size)(f,&(attr->ds->u.simple));
+ attr->ds_size=(H5O_SDSPACE->raw_size)(f,&(attr->ds->u.simple));
p+=attr->ds_size;
/* Compute the size of the data */
@@ -170,14 +170,14 @@ H5O_attr_encode(H5F_t *f, uint8 *p, const void *mesg)
p+=name_len;
/* encode the attribute datatype */
- if((H5O_DTYPE[0].encode)(f,p,attr->dt)<0) {
+ if((H5O_DTYPE->encode)(f,p,attr->dt)<0) {
HRETURN_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL,
"can't encode attribute datatype");
}
p+=attr->dt_size;
/* encode the attribute dataspace */
- if((H5O_SDSPACE[0].encode)(f,p,&(attr->ds->u.simple))<0) {
+ if((H5O_SDSPACE->encode)(f,p,&(attr->ds->u.simple))<0) {
HRETURN_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL,
"can't encode attribute dataspace");
}
@@ -297,7 +297,7 @@ H5O_attr_reset(void *_mesg)
if (attr) {
tmp = H5MM_xmalloc(sizeof(H5A_t));
- *tmp = *attr;
+ HDmemcpy(tmp,attr,sizeof(H5A_t));
H5A_close(tmp);
HDmemset(attr, 0, sizeof(H5A_t));
}
diff --git a/src/H5T.c b/src/H5T.c
index 4e87d65..c2c6d9f 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -2765,6 +2765,7 @@ H5T_close(H5T_t *dt)
assert(dt);
+ /* Don't free locked datatypes unless we are shutting the interface down */
if (!dt->locked) {
if (dt && H5T_COMPOUND == dt->type) {
for (i = 0; i < dt->u.compnd.nmembs; i++) {
diff --git a/test/tattr.c b/test/tattr.c
index 400717d..4efb94e 100644
--- a/test/tattr.c
+++ b/test/tattr.c
@@ -117,6 +117,10 @@ test_attr_basic_write(void)
sid2 = H5Screate_simple(ATTR1_RANK, dims2, NULL);
CHECK(sid2, FAIL, "H5Screate_simple");
+ /* Try to create an attribute on the file (should fail) */
+ ret=H5Acreate(fid1,ATTR1_NAME,H5T_NATIVE_INT32,sid2,H5P_DEFAULT);
+ VERIFY(ret, FAIL, "H5Acreate");
+
/* Create an attribute for the dataset */
attr=H5Acreate(dataset,ATTR1_NAME,H5T_NATIVE_INT32,sid2,H5P_DEFAULT);
CHECK(attr, FAIL, "H5Acreate");
@@ -326,7 +330,7 @@ test_attr_complex_write(void)
CHECK(attr, FAIL, "H5Acreate");
/* Try to create the same attribute again (should fail) */
- ret=H5Acreate(dataset,ATTR4_NAME,H5T_NATIVE_INT32,sid2,H5P_DEFAULT);
+ ret=H5Acreate(dataset,ATTR4_NAME,tid1,sid2,H5P_DEFAULT);
VERIFY(ret, FAIL, "H5Acreate");
/* Write complex attribute data */
@@ -992,7 +996,7 @@ test_attr_delete(void)
/* Try to delete bogus attribute */
ret=H5Adelete(dataset,"Bogus");
- CHECK(ret, FAIL, "H5Adelete");
+ VERIFY(ret, FAIL, "H5Adelete");
/* Verify the correct number of attributes */
ret=H5Anum_attrs(dataset);
diff --git a/test/tstab.c b/test/tstab.c
index 291dbd4..21b9be4 100644
--- a/test/tstab.c
+++ b/test/tstab.c
@@ -118,6 +118,12 @@ test_2(void)
CHECK_I(status, "H5Gclose");
}
+ /* close the property lists */
+ status = H5Pclose(create_plist);
+ CHECK_I(status, "H5Pclose");
+ status = H5Pclose(access_plist);
+ CHECK_I(status, "H5Pclose");
+
/* close the file */
status = H5Fclose(fid);
CHECK_I(status, "H5Fclose");