summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2005-04-16 16:22:22 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2005-04-16 16:22:22 (GMT)
commitbbeca0723250c5cd66eba974a81375142a0cfe2d (patch)
tree245d59ff2e2c71b0ae0ca8fd5605b1c029696c14
parent9a14290d3059f1ad70655647977ed56254ee90ae (diff)
downloadhdf5-bbeca0723250c5cd66eba974a81375142a0cfe2d.zip
hdf5-bbeca0723250c5cd66eba974a81375142a0cfe2d.tar.gz
hdf5-bbeca0723250c5cd66eba974a81375142a0cfe2d.tar.bz2
[svn-r10621] Purpose:
Bug fix Description: Opening a dataset (or named datatype) with "." for the name and using a group ID for the location ID was not returning an error value. Solution: Check the type of the object before attempting to open it (internally, using a group ID and "." for the name maps to the group object). Platforms tested: FreeBSD 4.11 (sleipnir) Solaris 2.9 (shanti) Too minor to require h5committest
-rw-r--r--src/H5D.c14
-rw-r--r--src/H5T.c4
-rw-r--r--test/tfile.c124
3 files changed, 139 insertions, 3 deletions
diff --git a/src/H5D.c b/src/H5D.c
index 26269d6..c2874e5 100644
--- a/src/H5D.c
+++ b/src/H5D.c
@@ -1125,7 +1125,7 @@ done:
hid_t
H5Dopen(hid_t loc_id, const char *name)
{
- H5D_t *dset;
+ H5D_t *dset = NULL;
H5G_entry_t *loc = NULL; /*location holding the dataset */
H5G_entry_t ent; /*dataset symbol table entry */
hid_t dxpl_id = H5AC_dxpl_id; /* dxpl to use to open datset */
@@ -1144,6 +1144,10 @@ H5Dopen(hid_t loc_id, const char *name)
if (H5G_find(loc, name, NULL, &ent, dxpl_id) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_NOTFOUND, FAIL, "not found")
+ /* Check that the object found is the correct type */
+ if (H5G_get_type(&ent, dxpl_id) != H5G_DATASET)
+ HGOTO_ERROR(H5E_DATASET, H5E_BADTYPE, FAIL, "not a dataset")
+
/* Open the dataset */
if ((dset = H5D_open(&ent, dxpl_id))==NULL)
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't open dataset")
@@ -1153,6 +1157,10 @@ H5Dopen(hid_t loc_id, const char *name)
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "can't register dataset atom")
done:
+ if(ret_value < 0)
+ if(dset != NULL)
+ if(H5D_close(dset) < 0)
+ HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release dataset")
FUNC_LEAVE_API(ret_value)
}
@@ -2306,10 +2314,10 @@ done:
HDONE_ERROR(H5E_DATASET, H5E_CANTDEC, NULL, "unable to decrement ref count on property list")
} /* end if */
H5FL_FREE(H5D_shared_t,new_dset->shared);
- }
+ } /* end if */
new_dset->ent.file = NULL;
H5FL_FREE(H5D_t, new_dset);
- }
+ } /* end if */
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_create() */
diff --git a/src/H5T.c b/src/H5T.c
index 177bab8..b9cedce 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -1414,6 +1414,10 @@ H5Topen(hid_t loc_id, const char *name)
if (H5G_find (loc, name, NULL, &ent/*out*/, dxpl_id)<0)
HGOTO_ERROR (H5E_DATATYPE, H5E_NOTFOUND, FAIL, "not found");
+ /* Check that the object found is the correct type */
+ if (H5G_get_type(&ent, dxpl_id) != H5G_TYPE)
+ HGOTO_ERROR(H5E_DATASET, H5E_BADTYPE, FAIL, "not a named datatype")
+
/* Open it */
if ((type=H5T_open (&ent, dxpl_id)) ==NULL)
HGOTO_ERROR (H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to open named data type");
diff --git a/test/tfile.c b/test/tfile.c
index b15cc8b..b78b4ec 100644
--- a/test/tfile.c
+++ b/test/tfile.c
@@ -1303,6 +1303,129 @@ test_file_ishdf5(void)
/****************************************************************
**
+** test_file_open_dot(): low-level file test routine.
+** This test checks whether opening objects with "." for a name
+** works correctly in variuous situations.
+**
+*****************************************************************/
+static void
+test_file_open_dot(void)
+{
+ hid_t fid; /* File ID */
+ hid_t gid, gid2; /* Group IDs */
+ hid_t did; /* Dataset ID */
+ hid_t sid; /* Dataspace ID */
+ hid_t tid, tid2; /* Datatype IDs */
+ herr_t ret;
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing opening objects with \".\" for a name\n"));
+
+ /* Create a new HDF5 file to work with */
+ fid = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(fid, FAIL, "H5Fcreate");
+
+ /* Create a group in the HDF5 file */
+ gid = H5Gcreate(fid, GRP_NAME, 0);
+ CHECK(gid, FAIL, "H5Gcreate");
+
+ /* Create a dataspace for creating datasets */
+ sid = H5Screate(H5S_SCALAR);
+ CHECK(sid, FAIL, "H5Screate");
+
+ /* Create a dataset with no name using the file ID */
+ H5E_BEGIN_TRY {
+ did = H5Dcreate(fid, ".", H5T_NATIVE_INT, sid, H5P_DEFAULT);
+ } H5E_END_TRY;
+ VERIFY(did, FAIL, "H5Dcreate");
+
+ /* Create a dataset with no name using the group ID */
+ H5E_BEGIN_TRY {
+ did = H5Dcreate(gid, ".", H5T_NATIVE_INT, sid, H5P_DEFAULT);
+ } H5E_END_TRY;
+ VERIFY(did, FAIL, "H5Dcreate");
+
+ /* Open a dataset with no name using the file ID */
+ H5E_BEGIN_TRY {
+ did = H5Dopen(fid, ".");
+ } H5E_END_TRY;
+ VERIFY(did, FAIL, "H5Dopen");
+
+ /* Open a dataset with no name using the group ID */
+ H5E_BEGIN_TRY {
+ did = H5Dopen(gid, ".");
+ } H5E_END_TRY;
+ VERIFY(did, FAIL, "H5Dopen");
+
+ /* Make a copy of a datatype to use for creating a named datatype */
+ tid = H5Tcopy(H5T_NATIVE_INT);
+ CHECK(tid, FAIL, "H5Tcopy");
+
+ /* Create a named datatype with no name using the file ID */
+ H5E_BEGIN_TRY {
+ ret = H5Tcommit(fid, ".", tid);
+ } H5E_END_TRY;
+ VERIFY(ret, FAIL, "H5Tcommit");
+
+ /* Create a named datatype with no name using the group ID */
+ H5E_BEGIN_TRY {
+ ret = H5Tcommit(gid, ".", tid);
+ } H5E_END_TRY;
+ VERIFY(ret, FAIL, "H5Tcommit");
+
+ /* Open a named datatype with no name using the file ID */
+ H5E_BEGIN_TRY {
+ tid2 = H5Topen(fid, ".");
+ } H5E_END_TRY;
+ VERIFY(tid2, FAIL, "H5Topen");
+
+ /* Open a named datatype with no name using the group ID */
+ H5E_BEGIN_TRY {
+ tid2 = H5Topen(gid, ".");
+ } H5E_END_TRY;
+ VERIFY(tid2, FAIL, "H5Topen");
+
+ /* Create a group with no name using the file ID */
+ H5E_BEGIN_TRY {
+ gid2 = H5Gcreate(fid, ".", 0);
+ } H5E_END_TRY;
+ VERIFY(gid2, FAIL, "H5Gcreate");
+
+ /* Create a group with no name using the group ID */
+ H5E_BEGIN_TRY {
+ gid2 = H5Gcreate(gid, ".", 0);
+ } H5E_END_TRY;
+ VERIFY(gid2, FAIL, "H5Gcreate");
+
+ /* Open a group with no name using the file ID (should open the root group) */
+ gid2 = H5Gopen(fid, ".");
+ CHECK(gid2, FAIL, "H5Gopen");
+
+ ret = H5Gclose(gid2);
+ CHECK(ret, FAIL, "H5Gclose");
+
+ /* Open a group with no name using the group ID (should open the group again) */
+ gid2 = H5Gopen(gid, ".");
+ CHECK(gid2, FAIL, "H5Gopen");
+
+ ret = H5Gclose(gid2);
+ CHECK(ret, FAIL, "H5Gclose");
+
+
+ /* Close everything */
+ ret = H5Sclose(sid);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ ret = H5Gclose(gid);
+ CHECK(ret, FAIL, "H5Gclose");
+
+ ret = H5Fclose(fid);
+ CHECK(ret, FAIL, "H5Fclose");
+
+} /* end test_file_open_dot() */
+
+/****************************************************************
+**
** test_file(): Main low-level file I/O test routine.
**
****************************************************************/
@@ -1321,6 +1444,7 @@ test_file(void)
test_file_perm(); /* Test file access permissions */
test_file_freespace(); /* Test file free space information */
test_file_ishdf5(); /* Test detecting HDF5 files correctly */
+ test_file_open_dot(); /* Test opening objects with "." for a name */
} /* test_file() */