summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2002-09-25 14:50:49 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2002-09-25 14:50:49 (GMT)
commit12e30dc9b284cae8dd821ffec93c344b7fb0d96b (patch)
treeca1e34bd719276349c4f75a7c38d79d361ce2025 /src
parentf9c3920d286b9d18156d1b7d85f14852345b5e74 (diff)
downloadhdf5-12e30dc9b284cae8dd821ffec93c344b7fb0d96b.zip
hdf5-12e30dc9b284cae8dd821ffec93c344b7fb0d96b.tar.gz
hdf5-12e30dc9b284cae8dd821ffec93c344b7fb0d96b.tar.bz2
[svn-r5947] Purpose:
Code cleanup Description: Clean up ID->name code: - Reformat to better match library coding standard - Changed several algorithms to be more efficient - Integrated into library more smoothly Platforms tested: eirene w/FORTRAN & C++ arabica w/FORTRAN modi4 w/FORTRAN & parallel sleipnir
Diffstat (limited to 'src')
-rw-r--r--src/H5A.c18
-rw-r--r--src/H5D.c18
-rw-r--r--src/H5F.c61
-rw-r--r--src/H5G.c1277
-rw-r--r--src/H5Gent.c30
-rw-r--r--src/H5Gnode.c30
-rw-r--r--src/H5Gprivate.h44
-rw-r--r--src/H5Gstab.c58
-rw-r--r--src/H5I.c394
-rw-r--r--src/H5Ipublic.h5
-rw-r--r--src/H5MM.c14
-rw-r--r--src/H5O.c9
-rw-r--r--src/H5Odtype.c16
-rw-r--r--src/H5T.c52
14 files changed, 823 insertions, 1203 deletions
diff --git a/src/H5A.c b/src/H5A.c
index 6703a6f..be0f182 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -204,7 +204,7 @@ done:
*
* Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
* Added a deep copy of the symbol table entry
- *
+ *
*-------------------------------------------------------------------------
*/
static hid_t
@@ -244,9 +244,9 @@ H5A_create(const H5G_entry_t *ent, const char *name, const H5T_t *type,
/* Mark it initially set to initialized */
attr->initialized = TRUE; /*for now, set to false later*/
- /* Deep copy of the symbol table entry */
- if (H5G_ent_copy(ent,&(attr->ent))<0)
- HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to copy entry");
+ /* Deep copy of the symbol table entry */
+ if (H5G_ent_copy(ent,&(attr->ent))<0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to copy entry");
/* Compute the internal sizes */
attr->dt_size=(H5O_DTYPE[0].raw_size)(attr->ent.file,type);
@@ -477,9 +477,9 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
* Added a deep copy of the symbol table entry
- *
+ *
*-------------------------------------------------------------------------
*/
static hid_t
@@ -499,9 +499,9 @@ H5A_open(H5G_entry_t *ent, unsigned idx)
HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to load attribute info from dataset header");
attr->initialized=1;
- /* Deep copy of the symbol table entry */
- if (H5G_ent_copy(ent,&(attr->ent))<0)
- HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to copy entry");
+ /* Deep copy of the symbol table entry */
+ if (H5G_ent_copy(ent,&(attr->ent))<0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to copy entry");
/* Hold the symbol table entry (and file) open */
if (H5O_open(&(attr->ent)) < 0) {
diff --git a/src/H5D.c b/src/H5D.c
index f62fc21..d98c194 100644
--- a/src/H5D.c
+++ b/src/H5D.c
@@ -1905,8 +1905,8 @@ done:
* Quincey Koziol, 12 Oct 1998
* Moved guts of function into H5D_open_oid
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -1935,10 +1935,6 @@ H5D_open(H5G_entry_t *loc, const char *name)
ret_value = dataset;
done:
-
- /*Free the ID to name buffer */
- H5G_free_ent_name(&ent);
-
FUNC_LEAVE(ret_value);
}
@@ -1965,8 +1961,8 @@ done:
* Feb 26, 2002
* A new fill value message and two new properties are added.
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added a deep copy of the symbol table entry
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added a deep copy of the symbol table entry
*
*-------------------------------------------------------------------------
*/
@@ -1992,10 +1988,8 @@ H5D_open_oid(H5G_entry_t *ent)
if(NULL==(dataset = H5D_new(H5P_DEFAULT)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- /* Deep copy of the symbol table entry */
- if (H5G_ent_copy(ent,&(dataset->ent))<0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, NULL, "unable to copy entry");
-
+ /* Shallow copy (take ownership) of the group entry object */
+ HDmemcpy(&(dataset->ent),ent,sizeof(H5G_entry_t));
/* Find the dataset object */
if (H5O_open(&(dataset->ent)) < 0)
diff --git a/src/H5F.c b/src/H5F.c
index afd0efc..9ca7e12 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -1457,8 +1457,8 @@ done:
* H5FL_FREE() aborts if called with a null pointer (unlike the
* original H5MM_free()).
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -1476,10 +1476,10 @@ H5F_dest(H5F_t *f)
* the memory associated with it.
*/
if (f->shared->root_grp) {
-
- /*Free the ID to name buffer */
+ /* Free the ID to name buffer */
H5G_free_grp_name(f->shared->root_grp);
+ /* Free the memory for the root group */
H5FL_FREE(H5G_t,f->shared->root_grp);
f->shared->root_grp=NULL;
}
@@ -2813,6 +2813,9 @@ done:
* Robb Matzke, 1998-10-14
* The reference count for the mounted H5F_t is incremented.
*
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added `id to name' support.
+ *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -2894,6 +2897,11 @@ H5F_mount(H5G_entry_t *loc, const char *name, H5F_t *child,
child->mtab.parent = parent;
child->nrefs++;
+ /* Search the open IDs and replace names for mount operation */
+ /* We pass H5G_UNKNOWN as object type; search all IDs */
+ if (H5G_replace_name( H5G_UNKNOWN, loc, name, NULL, OP_MOUNT )<0)
+ HGOTO_ERROR(H5E_FILE, H5E_MOUNT, FAIL, "unable to replace name");
+
done:
if (ret_value<0 && mount_point)
H5G_close(mount_point);
@@ -2920,12 +2928,12 @@ done:
*
* Modifications:
*
- * Robb Matzke, 1998-10-14
- * The ref count for the child is decremented by calling H5F_close().
+ * Robb Matzke, 1998-10-14
+ * The ref count for the child is decremented by calling H5F_close().
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added `id to name' support.
- *
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added `id to name' support.
+ *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -2965,10 +2973,9 @@ H5F_unmount(H5G_entry_t *loc, const char *name)
parent = child->mtab.parent;
for (i=0; i<parent->mtab.nmounts; i++) {
if (parent->mtab.child[i].file==child) {
-
- /* Search the symbol table entry list and replace names through group IDs */
- if (H5G_replace_name( H5G_UNKNOWN, loc, name, NULL, OP_UNMOUNT )<0)
- HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to replace name ");
+ /* Search the open IDs replace names to reflect unmount operation */
+ if (H5G_replace_name( H5G_UNKNOWN, loc, name, NULL, OP_UNMOUNT )<0)
+ HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to replace name ");
/* Unmount the child */
parent->mtab.nmounts -= 1;
@@ -3038,9 +3045,9 @@ done:
* Tuesday, October 6, 1998
*
* Modifications:
- *
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added `id to name' support.
+ *
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -3051,7 +3058,6 @@ H5F_mountpoint(H5G_entry_t *find/*in,out*/)
int lt, rt, md=(-1), cmp;
H5G_entry_t *ent = NULL;
herr_t ret_value=SUCCEED; /* Return value */
- char *tmp;
FUNC_ENTER_NOAPI(H5F_mountpoint, FAIL);
@@ -3082,10 +3088,19 @@ H5F_mountpoint(H5G_entry_t *find/*in,out*/)
/* Copy root info over to ENT */
if (0==cmp) {
+ char *tmp_name, *tmp_old_name; /* Temporary string pointers for entry's name and "old name"*/
+
+ /* Get the entry for the root group in the child's file */
ent = H5G_entof(parent->mtab.child[md].file->shared->root_grp);
- tmp = find->name;
+
+ /* Don't lose the name of the group when we copy the root group's entry */
+ tmp_name = find->name;
+ tmp_old_name = find->old_name;
*find = *ent;
- find->name = tmp;
+ find->name = tmp_name;
+ find->old_name = tmp_old_name;
+
+ /* Switch to child's file */
parent = ent->file;
}
} while (!cmp);
@@ -3108,9 +3123,6 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added `id to name' support.
- *
*-------------------------------------------------------------------------
*/
herr_t
@@ -3139,11 +3151,6 @@ H5Fmount(hid_t loc_id, const char *name, hid_t child_id, hid_t plist_id)
if (H5F_mount(loc, name, child, plist_id)<0)
HGOTO_ERROR(H5E_FILE, H5E_MOUNT, FAIL, "unable to mount file");
- /* Search the symbol table entry list and replace names through group IDs */
- /* We pass H5G_UNKNOWN as object type; search all IDs */
- if (H5G_replace_name( H5G_UNKNOWN, loc, name, NULL, OP_MOUNT )<0)
- HRETURN_ERROR(H5E_FILE, H5E_MOUNT, FAIL, "unable to replace name ");
-
done:
FUNC_LEAVE(ret_value);
}
diff --git a/src/H5G.c b/src/H5G.c
index 96caf5f..bb13435 100644
--- a/src/H5G.c
+++ b/src/H5G.c
@@ -69,8 +69,8 @@
* Robb Matzke, 30 Aug 1997
* Added `Errors:' field to function prologues.
*
- * Pedro Vicente, 22 Aug 2002
- * Added `id to name' support.
+ * Pedro Vicente, 22 Aug 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -78,8 +78,6 @@
#define H5G_PACKAGE /*suppress error message about including H5Gpkg.h */
#define H5F_PACKAGE /*suppress error about including H5Fpkg */
-
-
/* Packages needed by this file... */
#include "H5private.h"
#include "H5Aprivate.h"
@@ -102,18 +100,27 @@
static int interface_initialize_g = 0;
#define INTERFACE_INIT H5G_init_interface
static herr_t H5G_init_interface(void);
+
+/* Local variables and typedefs */
static H5G_typeinfo_t *H5G_type_g = NULL; /*object typing info */
static size_t H5G_ntypes_g = 0; /*entries in type table */
static size_t H5G_atypes_g = 0; /*entries allocated */
static char *H5G_comp_g = NULL; /*component buffer */
static size_t H5G_comp_alloc_g = 0; /*sizeof component buffer */
+/* Struct only used by change name callback function */
+typedef struct H5G_names_t {
+ const char *src_name;
+ const char *dst_name;
+ H5G_entry_t *loc;
+ H5G_names_op_t op;
+} H5G_names_t;
+
/* Declare a free list to manage the H5G_t struct */
H5FL_DEFINE(H5G_t);
/* Private prototypes */
-static herr_t H5G_replace_ent(void *obj_ptr, hid_t obj_id, void *key);
-
+static herr_t H5G_replace_ent(void *obj_ptr, hid_t obj_id, const void *key);
/*-------------------------------------------------------------------------
@@ -497,9 +504,6 @@ done:
* Monday, April 6, 1998
*
* Modifications:
- *
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -508,7 +512,6 @@ H5Gunlink(hid_t loc_id, const char *name)
{
H5G_entry_t *loc = NULL;
herr_t ret_value=SUCCEED; /* Return value */
- H5G_stat_t statbuf;
FUNC_ENTER_API(H5Gunlink, FAIL);
H5TRACE2("e","is",loc_id,name);
@@ -519,19 +522,10 @@ H5Gunlink(hid_t loc_id, const char *name)
if (!name || !*name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name");
- /* Get object type before unlink */
- if (H5G_get_objinfo(loc, name, FALSE, &statbuf)<0) {
- HRETURN_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found");
- }
-
/* Unlink */
if (H5G_unlink(loc, name)<0)
HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to unlink object");
- /* Search the symbol table entry list and replace names through group IDs */
- if (H5G_replace_name( statbuf.type, loc, name, NULL, OP_UNLINK )<0)
- HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to replace name ");
-
done:
FUNC_LEAVE (ret_value);
}
@@ -1036,21 +1030,21 @@ H5G_basename(const char *name, size_t *size_p)
* Aug 11 1997
*
* Modifications:
- * Robb Matzke, 2002-03-28
- * The component name buffer on the stack has been replaced by
- * a dynamically allocated buffer on the heap in order to
- * remove limitations on the length of a name component.
- * There are two reasons that the buffer pointer is global:
- * (1) We want to be able to reuse the buffer without
- * allocating and freeing it each time this function is
- * called.
- * (2) We need to be able to free it from H5G_term_interface()
- * when the library terminates.
- *
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Modified to deep copies of symbol table entries
- * Added `id to name' support.
- *
+ * Robb Matzke, 2002-03-28
+ * The component name buffer on the stack has been replaced by
+ * a dynamically allocated buffer on the heap in order to
+ * remove limitations on the length of a name component.
+ * There are two reasons that the buffer pointer is global:
+ * (1) We want to be able to reuse the buffer without
+ * allocating and freeing it each time this function is
+ * called.
+ * (2) We need to be able to free it from H5G_term_interface()
+ * when the library terminates.
+ *
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Modified to deep copies of symbol table entries
+ * Added `id to name' support.
+ *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -1058,18 +1052,15 @@ H5G_namei(H5G_entry_t *loc_ent, const char *name, const char **rest/*out*/,
H5G_entry_t *grp_ent/*out*/, H5G_entry_t *obj_ent/*out*/,
unsigned target, int *nlinks)
{
- H5G_entry_t _grp_ent; /*entry for current group */
- H5G_entry_t _obj_ent; /*entry found */
- size_t nchars; /*component name length */
- int _nlinks = H5G_NLINKS;
+ H5G_entry_t _grp_ent; /*entry for current group */
+ H5G_entry_t _obj_ent; /*entry found */
+ size_t nchars; /*component name length */
+ int _nlinks = H5G_NLINKS;
const char *s = NULL;
- herr_t ret_value=SUCCEED;
-
- H5G_t *tmp_grp;
- const char *orig_name = name;
- unsigned int null_obj = obj_ent == NULL ? 1 : 0;
- unsigned int null_grp = grp_ent == NULL ? 1 : 0;
- unsigned int found_once = 0;
+ unsigned null_obj = obj_ent == NULL ? 1 : 0; /* Flag to indicate this function was called with obj_ent set to NULL */
+ unsigned null_grp = grp_ent == NULL ? 1 : 0; /* Flag to indicate this function was called with grp_ent set to NULL */
+ unsigned group_copy = 0; /* Flag to indicate that the group entry is copied */
+ herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOINIT(H5G_namei);
@@ -1078,37 +1069,39 @@ H5G_namei(H5G_entry_t *loc_ent, const char *name, const char **rest/*out*/,
if (!obj_ent) obj_ent = &_obj_ent;
if (!nlinks) nlinks = &_nlinks;
+ /* Check args */
+ if (!name || !*name)
+ HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "no name given");
+ if (!loc_ent)
+ HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "no current working group");
+
/*
* Where does the searching start? For absolute names it starts at the
* root of the file; for relative names it starts at CWG.
*/
- if (!name || !*name) {
- HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "no name given");
- } else if (!loc_ent) {
- HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "no current working group");
- } else if ('/' == *name) {
-
- tmp_grp=H5G_rootof(loc_ent->file);
-
- /* Deep copy of the symbol table entry */
- if (H5G_ent_copy( &(tmp_grp->ent), obj_ent )<0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to copy entry");
+ /* Check if we need to get the root group's entry */
+ if ('/' == *name) {
+ H5G_t *tmp_grp; /* Temporary pointer to root group of file */
-
- } else {
- /* Deep copy of the symbol table entry */
- if (H5G_ent_copy( loc_ent, obj_ent )<0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to copy entry");
-
- }
-
+ tmp_grp=H5G_rootof(loc_ent->file);
+ assert(tmp_grp);
+
+ /* Set the location entry to the root group's entry*/
+ loc_ent=&(tmp_grp->ent);
+ } /* end if */
+
+ /* Deep copy of the symbol table entry */
+ if (H5G_ent_copy( loc_ent, obj_ent )<0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to copy entry");
HDmemset(grp_ent, 0, sizeof(H5G_entry_t));
grp_ent->header = HADDR_UNDEF;
/* traverse the name */
- while ((name = H5G_component(name, &nchars)) && *name) {
- if (rest) *rest = name;
+ while ((name = H5G_component(name, &nchars)) && *name) {
+ /* Update the "rest of name" pointer */
+ if (rest)
+ *rest = name;
/*
* Copy the component name into a null-terminated buffer so
@@ -1136,17 +1129,19 @@ H5G_namei(H5G_entry_t *loc_ent, const char *name, const char **rest/*out*/,
/*
* Advance to the next component of the name.
*/
- if(found_once) {
- if(grp_ent->name)
- H5MM_xfree(grp_ent->name);
- if(grp_ent->old_name)
- H5MM_xfree(grp_ent->old_name);
- }
+ /* If we've already copied a new entry into the group entry,
+ * it needs to be freed before overwriting it with another entry
+ */
+ if(group_copy)
+ H5G_free_ent_name(grp_ent);
+
+ /* Transfer "ownership" of the entry's information to the group entry */
*grp_ent = *obj_ent;
HDmemset(obj_ent, 0, sizeof(H5G_entry_t));
obj_ent->header = HADDR_UNDEF;
- /* Set flag if at least one component was found */
- found_once =1;
+
+ /* Set flag that we've copied a new entry into the group entry */
+ group_copy =1;
if (H5G_stab_find(grp_ent, H5G_comp_g, obj_ent/*out*/ )<0) {
/*
@@ -1156,7 +1151,6 @@ H5G_namei(H5G_entry_t *loc_ent, const char *name, const char **rest/*out*/,
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "component not found");
}
-
/*
* If we found a symbolic link then we should follow it. But if this
* is the last component of the name and the H5G_TARGET_SLINK bit of
@@ -1185,24 +1179,20 @@ H5G_namei(H5G_entry_t *loc_ent, const char *name, const char **rest/*out*/,
name += nchars;
- }
+ } /* end while */
- if (rest)
- *rest = name; /*final null */
+ /* Update the "rest of name" pointer */
+ if (rest)
+ *rest = name; /*final null */
done:
- if(null_obj) {
- if(obj_ent->name)
- H5MM_xfree(obj_ent->name);
- if(obj_ent->old_name)
- H5MM_xfree(obj_ent->old_name);
- }
- if(null_grp && found_once) {
- if(grp_ent->name)
- H5MM_xfree(grp_ent->name);
- if(grp_ent->old_name)
- H5MM_xfree(grp_ent->old_name);
- }
+ /* If we started with a NULL obj_ent, free the entry information */
+ if(null_obj)
+ H5G_free_ent_name(obj_ent);
+ /* If we started with a NULL grp_ent and we copied something into it, free the entry information */
+ if(null_grp && group_copy)
+ H5G_free_ent_name(grp_ent);
+
FUNC_LEAVE(ret_value);
}
@@ -1224,9 +1214,9 @@ done:
* Friday, April 10, 1998
*
* Modifications:
- *
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added `id to name' support.
+ *
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -1237,12 +1227,10 @@ H5G_traverse_slink (H5G_entry_t *grp_ent/*in,out*/,
{
H5O_stab_t stab_mesg; /*info about local heap */
const char *clv = NULL; /*cached link value */
- char *linkval = NULL; /*the copied link value */
+ char *linkval = NULL; /*the copied link value */
+ H5G_entry_t tmp_grp_ent; /* Temporary copy of group entry */
+ char *tmp_name, *tmp_old_name; /* Temporary pointer to object's name & "old name" */
herr_t ret_value=SUCCEED; /* Return value */
- H5G_entry_t tmp;
-
- /*Store old name */
- char* old_name = H5MM_strdup(obj_ent->name);
FUNC_ENTER_NOAPI(H5G_traverse_slink, FAIL);
@@ -1253,29 +1241,37 @@ H5G_traverse_slink (H5G_entry_t *grp_ent/*in,out*/,
obj_ent->cache.slink.lval_offset)))
HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "unable to read symbolic link value");
linkval = H5MM_xstrdup (clv);
-
- /* Free the ID to name buffer */
- H5G_free_ent_name(obj_ent);
- H5G_free_ent_name(grp_ent);
+ /* Copy the entry's name (& old_name) to restore later, then free the names for the entries */
+ tmp_name= H5MM_xstrdup(obj_ent->name);
+ tmp_old_name= H5MM_xstrdup(obj_ent->old_name);
+ H5G_free_ent_name(obj_ent);
+ H5G_free_ent_name(grp_ent);
- H5G_ent_copy(grp_ent,&tmp);
+ /* Clone the group entry, so we can track the names properly */
+ H5G_ent_copy(grp_ent,&tmp_grp_ent);
/* Traverse the link */
- if (H5G_namei (&tmp, linkval, NULL, grp_ent, obj_ent, H5G_TARGET_NORMAL, nlinks))
+ if (H5G_namei (&tmp_grp_ent, linkval, NULL, grp_ent, obj_ent, H5G_TARGET_NORMAL, nlinks))
HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "unable to follow symbolic link");
-
-
- /* Free the ID to name buffer */
- H5G_free_ent_name(obj_ent);
- obj_ent->name = old_name;
+ /* Free the entry's names, we will use the original name for the object */
+ H5G_free_ent_name(obj_ent);
+
+ /* Restore previous name for object */
+ obj_ent->name = tmp_name;
+ obj_ent->old_name = tmp_old_name;
done:
+ /* Error cleanup */
+ if (ret_value == FAIL ) {
+ H5MM_xfree(tmp_name);
+ H5MM_xfree(tmp_old_name);
+ } /* end if */
+
+ /* Release cloned copy of group entry */
+ H5G_free_ent_name(&tmp_grp_ent);
- if ( ret_value == FAIL )
- H5MM_xfree (old_name);
- H5G_free_ent_name(&tmp);
H5MM_xfree (linkval);
FUNC_LEAVE (ret_value);
}
@@ -1299,8 +1295,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -1341,10 +1337,10 @@ H5G_mkroot (H5F_t *f, H5G_entry_t *ent)
H5O_reset (H5O_STAB, &stab);
}
- /*create the "/" name */
- ent->name = HDstrdup( "/" );
- ent->old_name = NULL;
-
+ /* Create the name for the root group's entry */
+ ent->name = HDstrdup("/");
+ assert(ent->name);
+ ent->old_name = NULL;
/*
* Create the group pointer. Also decrement the open object count so we
@@ -1383,8 +1379,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -1404,8 +1400,6 @@ H5G_create(H5G_entry_t *loc, const char *name, size_t size_hint)
assert(loc);
assert(name && *name);
- HDmemset(&grp_ent, 0, sizeof(H5G_entry_t));
-
/* lookup name */
if (0 == H5G_namei(loc, name, &rest, &grp_ent, NULL, H5G_TARGET_NORMAL, NULL))
HGOTO_ERROR(H5E_SYM, H5E_EXISTS, NULL, "already exists");
@@ -1448,12 +1442,11 @@ H5G_create(H5G_entry_t *loc, const char *name, size_t size_hint)
ret_value=grp;
done:
-
- /*Free the ID to name buffer */
+ /* Free the group entry created from H5G_namei() */
H5G_free_ent_name(&grp_ent);
- if(ret_value==NULL) {
- if(grp!=NULL)
+ if(ret_value==NULL) {
+ if(grp!=NULL)
H5FL_FREE(H5G_t,grp);
} /* end if */
@@ -1513,8 +1506,8 @@ done:
* Modifications:
* Modified to call H5G_open_oid - QAK - 3/17/99
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -1523,7 +1516,7 @@ H5G_open(H5G_entry_t *loc, const char *name)
{
H5G_t *grp = NULL;
H5G_t *ret_value = NULL;
- H5G_entry_t ent; /*dataset symbol table entry */
+ H5G_entry_t ent; /* group symbol table entry */
FUNC_ENTER_NOAPI(H5G_open, NULL);
@@ -1546,10 +1539,6 @@ done:
if (!ret_value && grp)
H5FL_FREE(H5G_t,grp);
- /*Free the ID to name buffer */
- H5G_free_ent_name(&ent);
-
-
FUNC_LEAVE(ret_value);
}
@@ -1569,8 +1558,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added a deep copy of the symbol table entry
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added a deep copy of the symbol table entry
*
*-------------------------------------------------------------------------
*/
@@ -1590,9 +1579,8 @@ H5G_open_oid(H5G_entry_t *ent)
if (NULL==(grp = H5FL_ALLOC(H5G_t,1)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- /*deep copy of the symbol table entry*/
- if (H5G_ent_copy(ent,&(grp->ent))<0)
- HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, NULL, "unable to copy entry");
+ /* Copy over (take ownership) of the group entry object */
+ HDmemcpy(&(grp->ent),ent,sizeof(H5G_entry_t));
/* Grab the object header */
if (H5O_open(&(grp->ent)) < 0)
@@ -1741,8 +1729,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -1798,7 +1786,7 @@ H5G_insert(H5G_entry_t *loc, const char *name, H5G_entry_t *ent)
}
done:
- /*Free the ID to name buffer */
+ /*Free the ID to name buffer */
H5G_free_ent_name(&grp);
FUNC_LEAVE(ret_value);
@@ -2007,8 +1995,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -2091,9 +2079,6 @@ H5G_link (H5G_entry_t *cur_loc, const char *cur_name, H5G_entry_t *new_loc,
*/
if (H5G_stab_insert (&grp_ent, rest, &cur_obj)<0)
HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL, "unable to create new name/link for object");
-
-
-
break;
case H5G_LINK_HARD:
@@ -2101,8 +2086,6 @@ H5G_link (H5G_entry_t *cur_loc, const char *cur_name, H5G_entry_t *new_loc,
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "source object not found");
if (H5G_insert (new_loc, new_name, &cur_obj)<0)
HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL, "unable to create new name/link for object");
-
-
break;
default:
@@ -2110,12 +2093,13 @@ H5G_link (H5G_entry_t *cur_loc, const char *cur_name, H5G_entry_t *new_loc,
}
done:
-
- if ( type == H5G_LINK_SOFT )
- /*Free the ID to name buffer */
- H5G_free_ent_name(&grp_ent);
+ /* Free the group's ID to name buffer, if creating a soft link */
+ if(type == H5G_LINK_SOFT)
+ H5G_free_ent_name(&grp_ent);
+ /* Free the ID to name buffer */
H5G_free_ent_name(&cur_obj);
+
FUNC_LEAVE (ret_value);
}
@@ -2177,8 +2161,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -2245,8 +2229,7 @@ H5G_get_objinfo (H5G_entry_t *loc, const char *name, hbool_t follow_link,
}
done:
-
- /*Free the ID to name buffer */
+ /* Free the ID to name buffers */
H5G_free_ent_name(&grp_ent);
H5G_free_ent_name(&obj_ent);
@@ -2272,8 +2255,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -2312,7 +2295,7 @@ H5G_linkval (H5G_entry_t *loc, const char *name, size_t size, char *buf/*out*/)
HDstrncpy (buf, s, size);
done:
- /*Free the ID to name buffer */
+ /* Free the ID to name buffers */
H5G_free_ent_name(&grp_ent);
H5G_free_ent_name(&obj_ent);
@@ -2332,8 +2315,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -2363,8 +2346,7 @@ H5G_set_comment(H5G_entry_t *loc, const char *name, const char *buf)
}
done:
-
- /*Free the ID to name buffer */
+ /* Free the ID to name buffer */
H5G_free_ent_name(&obj_ent);
FUNC_LEAVE(ret_value);
@@ -2387,8 +2369,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -2419,8 +2401,7 @@ H5G_get_comment(H5G_entry_t *loc, const char *name, size_t bufsize, char *buf)
}
done:
-
- /*Free the ID to name buffer */
+ /* Free the ID to name buffer */
H5G_free_ent_name(&obj_ent);
FUNC_LEAVE(ret_value);
@@ -2439,8 +2420,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -2450,12 +2431,21 @@ H5G_unlink(H5G_entry_t *loc, const char *name)
H5G_entry_t grp_ent, obj_ent;
size_t len;
const char *base=NULL;
+ H5G_stat_t statbuf; /* Info about object to unlink */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5G_unlink, FAIL);
assert(loc);
assert(name && *name);
+ /* Reset the group entries to known values in a portable way */
+ HDmemset(&grp_ent,0,sizeof(H5G_entry_t));
+ HDmemset(&obj_ent,0,sizeof(H5G_entry_t));
+
+ /* Get object type before unlink */
+ if (H5G_get_objinfo(loc, name, FALSE, &statbuf)<0)
+ HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found");
+
/* Get the entry for the group that contains the object to be unlinked */
if (H5G_namei(loc, name, NULL, &grp_ent, &obj_ent,
H5G_TARGET_SLINK|H5G_TARGET_MOUNT, NULL)<0)
@@ -2469,9 +2459,12 @@ H5G_unlink(H5G_entry_t *loc, const char *name)
if (H5G_stab_remove(&grp_ent, base)<0)
HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to unlink name from symbol table");
-done:
+ /* Search the open IDs and replace names for unlinked object */
+ if (H5G_replace_name(statbuf.type, loc, name, NULL, OP_UNLINK )<0)
+ HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to replace name");
- /*Free the ID to name buffer */
+done:
+ /* Free the ID to name buffers */
H5G_free_ent_name(&grp_ent);
H5G_free_ent_name(&obj_ent);
@@ -2494,8 +2487,8 @@ done:
* Raymond Lu
* Thursday, April 18, 2002
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -2542,18 +2535,17 @@ H5G_move(H5G_entry_t *src_loc, const char *src_name, H5G_entry_t *dst_loc,
HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to register new name for object");
}
+ /* Search the open ID list and replace names for the move operation
+ * This has to be done here because H5G_link and H5G_unlink have
+ * internal object entries, and do not modify the entries list
+ */
+ if (H5G_replace_name(sb.type, src_loc, src_name, dst_name, OP_MOVE )<0)
+ HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to replace name ");
+
/* Remove the old name */
if (H5G_unlink(src_loc, src_name)<0)
HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to deregister old object name");
- /*
- Search the symbol table entry list and replace names through group IDs
- This has to be done here because H5G_link and H5G_unlink have
- internal object entries , and do not modify the entries list
- */
- if (H5G_replace_name( sb.type, src_loc, src_name, dst_name, OP_MOVE )<0)
- HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to replace name ");
-
done:
FUNC_LEAVE(ret_value);
}
@@ -2575,8 +2567,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -2611,14 +2603,13 @@ H5G_insertion_file(H5G_entry_t *loc, const char *name)
ret_value=grp_ent.file;
done:
-
- /*Free the ID to name buffer */
+ /* Free the ID to name buffer */
H5G_free_ent_name(&grp_ent);
+
FUNC_LEAVE(ret_value);
}
-
-
+
/*-------------------------------------------------------------------------
* Function: H5G_free_grp_name
*
@@ -2630,7 +2621,7 @@ done:
*
* Date: August 22, 2002
*
- * Comments: Used now only on the root group close , on H5F_close
+ * Comments: Used now only on the root group close, in H5F_close()
*
* Modifications:
*
@@ -2639,26 +2630,27 @@ done:
herr_t
H5G_free_grp_name(H5G_t *grp)
{
- herr_t ret_value=SUCCEED; /* Return value */
- H5G_entry_t *ent;
+ H5G_entry_t *ent; /* Group object's entry */
+ herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5G_free_grp_name, FAIL);
+ FUNC_ENTER_NOAPI(H5G_free_grp_name, FAIL);
- /* Check args */
- assert(grp);
- assert(grp->nref > 0);
+ /* Check args */
+ assert(grp);
+ assert(grp->nref > 0);
- if (NULL==( ent = H5G_entof(grp)))
- HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL, "cannot get entry");
+ /* Get the entry for the group */
+ if (NULL==( ent = H5G_entof(grp)))
+ HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL, "cannot get entry");
+
+ /* Free the entry */
+ H5G_free_ent_name(ent);
- H5G_free_ent_name(ent);
-
-
done:
- FUNC_LEAVE(ret_value);
+ FUNC_LEAVE(ret_value);
}
-
+
/*-------------------------------------------------------------------------
* Function: H5G_free_ent_name
*
@@ -2679,23 +2671,23 @@ done:
herr_t
H5G_free_ent_name(H5G_entry_t *ent)
{
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5G_free_ent_name, FAIL);
+ FUNC_ENTER_NOAPI(H5G_free_ent_name, FAIL);
- /* Check args */
- assert(ent);
+ /* Check args */
+ assert(ent);
- if ( ent->name )
- ent->name = H5MM_xfree(ent->name);
- if ( ent->old_name )
- ent->old_name = H5MM_xfree(ent->old_name);
+ if ( ent->name )
+ ent->name = H5MM_xfree(ent->name);
+ if ( ent->old_name )
+ ent->old_name = H5MM_xfree(ent->old_name);
done:
- FUNC_LEAVE(ret_value);
+ FUNC_LEAVE(ret_value);
}
-
+
/*-------------------------------------------------------------------------
* Function: H5G_insert_name
*
@@ -2713,56 +2705,53 @@ done:
*
*-------------------------------------------------------------------------
*/
-
herr_t
H5G_insert_name(H5G_entry_t *loc, H5G_entry_t *obj, const char *name)
{
+ size_t loc_name_len, name_len; /* Length of location's name and name to append */
+ herr_t ret_value = SUCCEED;
- size_t len1, len2;
- herr_t ret_value = SUCCEED;
-
- FUNC_ENTER_NOAPI(H5G_insert_name, FAIL);
-
- if ( loc->name ) {
-
- len1 = HDstrlen(loc->name);
- len2 = HDstrlen(name);
- assert(len2>0&&len1>0);
- if(obj->name)
- obj->name=H5MM_xfree(obj->name);
-
- /* this is the root group */
- if ('/'==loc->name[len1-1])
- {
-
- if (NULL==(obj->name = H5MM_malloc (len1+len2+1)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
- HDstrcpy(obj->name, loc->name);
- HDstrcpy(obj->name+len1, name);
-
- }
- /* this is a subgroup */
- else
- {
- if (NULL==(obj->name = H5MM_malloc (len1+1+len2+1)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
- HDstrcpy(obj->name, loc->name);
- HDstrcpy(obj->name+len1, "/");
- HDstrcpy(obj->name+len1+1, name);
- }
- }
+ FUNC_ENTER_NOAPI(H5G_insert_name, FAIL);
+ /* Only attempt to build a new name if the location's name exists */
+ if(loc->name) {
+ loc_name_len = HDstrlen(loc->name);
+ name_len = HDstrlen(name);
+ assert(name_len>0 && loc_name_len>0);
+
+ /* Free the object's name, if it exists */
+ if(obj->name)
+ obj->name=H5MM_xfree(obj->name);
+
+ /* The location's name already has a '/' separator */
+ if ('/'==loc->name[loc_name_len-1]) {
+ if (NULL==(obj->name = H5MM_malloc (loc_name_len+name_len+1)))
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
+ HDstrcpy(obj->name, loc->name);
+ HDstrcat(obj->name, name);
+ } /* end if */
+ /* The location's name needs a separator */
+ else {
+ if (NULL==(obj->name = H5MM_malloc (loc_name_len+1+name_len+1)))
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
+ HDstrcpy(obj->name, loc->name);
+ HDstrcat(obj->name, "/");
+ HDstrcat(obj->name, name);
+ } /* end else */
+ } /* end if */
+
done:
- FUNC_LEAVE(ret_value);
-
+ FUNC_LEAVE(ret_value);
}
-
-
+
/*-------------------------------------------------------------------------
* Function: H5G_replace_name
*
- * Purpose: Search the symbol table entry list and replace names through group IDs
+ * Purpose: Search the list of open IDs and replace names according to a
+ * particular operation. The operation occured on the LOC
+ * entry, which had SRC_NAME previously. The new name (if there
+ * is one) is DST_NAME.
*
* Return: Success: 0, Failure: -1
*
@@ -2776,114 +2765,86 @@ done:
*
*-------------------------------------------------------------------------
*/
+herr_t
+H5G_replace_name( int type, H5G_entry_t *loc, const char *src_name,
+ const char *dst_name, H5G_names_op_t op )
+{
+ H5G_names_t names; /* Structure to hold operation information for callback */
+ unsigned search_group=0; /* Flag to indicate that groups are to be searched */
+ unsigned search_dataset=0; /* Flag to indicate that datasets are to be searched */
+ unsigned search_datatype=0; /* Flag to indicate that datatypes are to be searched */
+ herr_t ret_value = SUCCEED;
+
+ FUNC_ENTER_NOAPI(H5G_replace_name, FAIL);
+
+ /* Set up common information for callback */
+ names.src_name=src_name;
+ names.dst_name=dst_name;
+ names.loc=loc;
+ names.op=op;
+
+ /* Determine which types of IDs need to be operated on */
+ switch(type) {
+ /* Object is a group */
+ case H5G_GROUP:
+ /* Search and replace names through group IDs */
+ search_group=1;
+ break;
+
+ /* Object is a dataset */
+ case H5G_DATASET:
+ /* Search and replace names through dataset IDs */
+ search_dataset=1;
+ break;
+ /* Object is a named data type */
+ case H5G_TYPE:
+ /* Search and replace names through datatype IDs */
+ search_datatype=1;
+ break;
+ case H5G_UNKNOWN: /* We pass H5G_UNKNOWN as object type when we need to search all IDs */
+ case H5G_LINK: /* Symbolic links might resolve to any object, so we need to search all IDs */
+ /* Check if we will need to search groups */
+ if(H5I_nmembers(H5I_GROUP)>0)
+ search_group=1;
-herr_t H5G_replace_name( int type, H5G_entry_t *loc, const char *src_name,
- const char *dst_name, int op )
-{
-
- H5G_names_t names;
- herr_t ret_value = SUCCEED;
-
- FUNC_ENTER_NOAPI(H5G_replace_name, FAIL);
-
- names.src_name=src_name;
- names.dst_name=dst_name;
- names.loc=loc;
- names.op=op;
-
- switch ( type )
- {
-
- /* Object is a group */
- case H5G_GROUP:
-
- /* Search and replace names through group IDs */
- names.obj_type = H5I_GROUP;
- H5I_search(H5I_GROUP, (H5I_search_func_t)H5G_replace_ent, &names );
-
- break;
-
- /* Object is a dataset */
- case H5G_DATASET:
-
- /* Search and replace names through dataset IDs */
- names.obj_type = H5I_DATASET;
- H5I_search(H5I_DATASET, (H5I_search_func_t)H5G_replace_ent, &names );
-
- break;
-
- /* Object is a named data type */
- case H5G_TYPE:
-
- /* Search and replace names through datatype IDs */
- names.obj_type = H5I_DATATYPE;
- H5I_search(H5I_DATATYPE, (H5I_search_func_t)H5G_replace_ent, &names );
-
- break;
-
- /* We pass H5G_UNKNOWN as object type for the H5Fmount case; search all IDs */
- case H5G_UNKNOWN:
-
- /* Search through group IDs */
- if ( H5I_nmembers(H5I_GROUP) ) {
- names.obj_type = H5I_GROUP;
- H5I_search(H5I_GROUP, (H5I_search_func_t)H5G_replace_ent, &names );
- }
- /* Search through dataset IDs */
- if ( H5I_nmembers(H5I_DATASET) ) {
- names.obj_type = H5I_DATASET;
- H5I_search(H5I_DATASET, (H5I_search_func_t)H5G_replace_ent, &names );
- }
- /* Search through datatype IDs */
- if ( H5I_nmembers(H5I_DATATYPE) ) {
- names.obj_type = H5I_DATATYPE;
- H5I_search(H5I_DATATYPE, (H5I_search_func_t)H5G_replace_ent, &names );
- }
-
- break;
-
- /* Object is a symbolic link */
-
- case H5G_LINK:
-
- /* Search through group IDs */
- if ( H5I_nmembers(H5I_GROUP) ) {
- names.obj_type = H5I_GROUP;
- H5I_search(H5I_GROUP, (H5I_search_func_t)H5G_replace_ent, &names );
- }
- /* Search through dataset IDs */
- if ( H5I_nmembers(H5I_DATASET) ) {
- names.obj_type = H5I_DATASET;
- H5I_search(H5I_DATASET, (H5I_search_func_t)H5G_replace_ent, &names );
- }
- /* Search through datatype IDs */
- if ( H5I_nmembers(H5I_DATATYPE) ) {
- names.obj_type = H5I_DATATYPE;
- H5I_search(H5I_DATATYPE, (H5I_search_func_t)H5G_replace_ent, &names );
- }
-
- break;
-
- default:
- HRETURN_ERROR (H5E_DATATYPE, H5E_BADTYPE, FAIL,
- "not valid object type");
-
- };
-
-done:
- FUNC_LEAVE( SUCCEED );
-}
+ /* Check if we will need to search datasets */
+ if(H5I_nmembers(H5I_DATASET)>0)
+ search_dataset=1;
+
+ /* Check if we will need to search datatypes */
+ if(H5I_nmembers(H5I_DATATYPE)>0)
+ search_datatype=1;
+ break;
+
+ default:
+ HGOTO_ERROR (H5E_DATATYPE, H5E_BADTYPE, FAIL, "not valid object type");
+ } /* end switch */
+
+ /* Search through group IDs */
+ if(search_group)
+ H5I_search(H5I_GROUP, H5G_replace_ent, &names);
+
+ /* Search through dataset IDs */
+ if(search_dataset)
+ H5I_search(H5I_DATASET, H5G_replace_ent, &names);
+ /* Search through datatype IDs */
+ if(search_datatype)
+ H5I_search(H5I_DATATYPE, H5G_replace_ent, &names);
+done:
+ FUNC_LEAVE(ret_value);
+}
+
/*-------------------------------------------------------------------------
* Function: H5G_rest
*
* Purpose: Get the last component of the name
*
- * Return: SUCCEED
+ * Return: Pointer to the last component of a name, if found, otherwise NULL
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
@@ -2895,31 +2856,94 @@ done:
*
*-------------------------------------------------------------------------
*/
-
- static herr_t
- H5G_rest( const char *name, const char **rest/*out*/ )
- {
-
- size_t nchars;
- herr_t ret_value = SUCCEED;
+static const char *
+H5G_rest(const char *name)
+{
+ size_t nchars; /* Number of characters in component */
+ const char *rest=NULL; /* Pointer to last component, if found */
- FUNC_ENTER_NOAPI(H5G_rest, FAIL);
+ FUNC_ENTER_NOINIT(H5G_rest);
- /* traverse the name */
- while ((name = H5G_component(name, &nchars)) && *name)
- {
- if (rest) *rest = name;
+ /* traverse the name to find the last component */
+ while ((name = H5G_component(name, &nchars)) && *name) {
+ /* Get pointer to current component of name */
+ rest = name;
- /* next component */
- name += nchars;
- }
-
+ /* Advance to next component */
+ name = rest+nchars;
+ } /* end while */
+#ifdef LATER
done:
- FUNC_LEAVE(SUCCEED);
+#endif /* LATER */
+ FUNC_LEAVE(rest);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5G_common_path
+ *
+ * Purpose: Determine if one path is a valid prefix of another path
+ *
+ * Return: TRUE for valid prefix, FALSE for not a valid prefix, FAIL
+ * on error
+ *
+ * Programmer: Quincey Koziol, koziol@ncsa.uiuc.edu
+ *
+ * Date: September 24, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static htri_t
+H5G_common_path(const char *fullpath, const char *prefix)
+{
+ size_t nchars1,nchars2; /* Number of characters in components */
+ htri_t ret_value=FALSE; /* Return value */
+
+ FUNC_ENTER_NOINIT(H5G_common_path);
- }
+ /* Get component of each name */
+ fullpath=H5G_component(fullpath,&nchars1);
+ assert(fullpath);
+ prefix=H5G_component(prefix,&nchars2);
+ assert(prefix);
+
+ /* Check if we have a real string for each component */
+ while(*fullpath && *prefix) {
+ /* Check that the components we found are the same length */
+ if(nchars1==nchars2) {
+ /* Check that the two components are equal */
+ if(HDstrncmp(fullpath,prefix,nchars1)==0) {
+ /* Advance the pointers in the names */
+ fullpath+=nchars1;
+ prefix+=nchars2;
+
+ /* Get next component of each name */
+ fullpath=H5G_component(fullpath,&nchars1);
+ assert(fullpath);
+ prefix=H5G_component(prefix,&nchars2);
+ assert(prefix);
+ } /* end if */
+ else
+ HGOTO_DONE(FALSE);
+ } /* end if */
+ else
+ HGOTO_DONE(FALSE);
+ } /* end while */
+
+ /* If we reached the end of the prefix path to check, it must be a valid prefix */
+ if(*prefix=='\0')
+ ret_value=TRUE;
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
/*-------------------------------------------------------------------------
* Function: H5G_replace_ent
*
@@ -2937,353 +2961,198 @@ done:
*
*-------------------------------------------------------------------------
*/
- static herr_t
- H5G_replace_ent(void *obj_ptr, hid_t obj_id, void *key)
- {
- H5G_names_t *names = key;
- H5G_entry_t *ent = NULL;
- size_t len1, len2;
- char *tmp_buf;
- H5F_t *parent_file;
- H5F_t *child_file;
- H5F_mount_t *child_mnt;
- H5G_entry_t *child_grp_ent;
- unsigned i;
- size_t len;
- const char *rest = NULL; /*the base name */
- int cmp;
- char *new_src_name;
- char *new_dst_name;
- herr_t ret_value = FAIL;
+static herr_t
+H5G_replace_ent(void *obj_ptr, hid_t obj_id, const void *key)
+{
+ const H5G_names_t *names = (const H5G_names_t *)key; /* Get operation's information */
+ H5G_entry_t *ent = NULL; /* Group entry for object that the ID refers to */
+ const char *rest; /* The base name of an object */
+ unsigned i; /* Local index variable */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5G_replace_ent, FAIL);
+ FUNC_ENTER_NOINIT(H5G_replace_ent);
- assert(obj_ptr);
-
- /* avoid no named datatypes */
- if( names->obj_type==H5I_DATATYPE && !H5T_is_named((H5T_t*)obj_ptr))
- {
- /* Do not exit loop */
- ret_value = SUCCEED;
- goto done;
- }
+ assert(obj_ptr);
- /* Get the symbol table entry */
- switch(names->obj_type) {
- case H5I_GROUP:
- ent = H5G_entof((H5G_t*)obj_ptr);
- break;
- case H5I_DATASET:
- ent = H5D_entof((H5D_t*)obj_ptr);
- break;
- case H5I_DATATYPE:
- ent = H5T_entof((H5T_t*)obj_ptr);
- break;
- default:
- ret_value = FAIL;
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL,
- "unknown data object");
- }
-
- assert( ent );
+ /* Get the symbol table entry */
+ switch(H5I_GROUP(obj_id)) {
+ case H5I_GROUP:
+ ent = H5G_entof((H5G_t*)obj_ptr);
+ break;
+
+ case H5I_DATASET:
+ ent = H5D_entof((H5D_t*)obj_ptr);
+ break;
+
+ case H5I_DATATYPE:
+ /* Avoid non-named datatypes */
+ if(!H5T_is_named((H5T_t*)obj_ptr))
+ HGOTO_DONE(SUCCEED); /* Do not exit search over IDs */
-
- /* Check if is a mounted file */
- if(ent->file->mtab.parent) {
-
- if(ent->file->mtab.parent->shared != names->loc->file->shared )
- {
- /* Do not exit loop */
- ret_value = SUCCEED;
- goto done;
- }
-
-
- if ( names->op==OP_UNLINK || names->op==OP_MOVE ) {
- parent_file = ent->file->mtab.parent;
- for ( i = 0; i < parent_file->mtab.nmounts; i++ )
- {
- child_mnt = &parent_file->mtab.child[i];
- child_file = child_mnt->file;
-
- /* we found the right file */
- if( ent->file->shared == child_file->shared )
- {
- child_grp_ent = &child_mnt->group->ent;
- len = HDstrlen( child_grp_ent->name );
-
- /* Find the prefix of the name */
- cmp = HDstrncmp( child_grp_ent->name, names->src_name, len);
- if ( cmp == 0 )
- {
- new_src_name=H5MM_strdup(names->src_name+len);
-
- if (names->op==OP_UNLINK)
- new_dst_name=H5MM_strdup(names->dst_name);
- else if (names->op==OP_MOVE)
- new_dst_name=H5MM_strdup(names->dst_name+len);
-
- /* Search the symbol table entry list and replace names through group IDs */
- if (H5G_replace_name( H5G_UNKNOWN,
- child_grp_ent,
- new_src_name,
- new_dst_name,
- names->op )<0)
- HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to replace name ");
-
- H5MM_xfree(new_dst_name);
-
- H5MM_xfree(new_src_name);
-
- }/* if */
-
- }/* if */
-
- } /* for */
+ ent = H5T_entof((H5T_t*)obj_ptr);
+ break;
- }/* if */
-
- } /* if */
+ default:
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "unknown data object");
+ } /* end switch */
+ assert(ent);
- /* Verify if file IDs refer to the same file */
- else {
- if( ent->file->shared != names->loc->file->shared )
- {
- /* Do not exit loop */
- ret_value = SUCCEED;
- goto done;
- }
- }
+ /* Check if ID's entry is in a mounted file */
+ if(ent->file->mtab.parent) {
+ /* If the ID's entry's parent file is not in the file we operated on, skip it */
+ if(ent->file->mtab.parent->shared != names->loc->file->shared )
+ HGOTO_DONE(SUCCEED); /* Do not exit search over IDs */
+
+ /* We need to recurse into the child's file for unlink and move operations */
+ if(names->op==OP_UNLINK || names->op==OP_MOVE) {
+ H5F_t *parent_file=ent->file->mtab.parent; /* Pointer to the parent's file info */
+
+ /* Search through mounted files for the one which contains the ID's entry */
+ for(i=0; i<parent_file->mtab.nmounts; i++) {
+ H5F_mount_t *child_mnt = &parent_file->mtab.child[i]; /* Mount information for child file */
+ H5F_t *child_file = child_mnt->file; /* Child's file info */
+
+ /* we found the right file */
+ if(ent->file->shared == child_file->shared ) {
+ H5G_entry_t *child_grp_ent = &child_mnt->group->ent; /* Mount point's group entry */
+ size_t child_len; /* Length of mount point's name */
+ size_t dst_offset=0; /* Offset into destination name */
+
+ /* Get the length of the child group's name (i.e. the mount point's name in parent group) */
+ child_len = HDstrlen(child_grp_ent->name);
+
+ /* Find the prefix of the name */
+ if(HDstrncmp( child_grp_ent->name, names->src_name, child_len) == 0) {
+ /* Advance the offset in the destination also for moves in mounted files */
+ if (names->op==OP_MOVE)
+ dst_offset=child_len;
+
+ /* Search the open ID list and replace names */
+ if (H5G_replace_name( H5G_UNKNOWN, child_grp_ent,
+ names->src_name+child_len, names->dst_name+dst_offset,
+ names->op )<0)
+ HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to replace name");
+ } /* end if */
+ } /* end if */
+ } /* end for */
+ } /* end if */
+ } /* end if */
+ /* Verify if file IDs refer to the same file */
+ else {
+ /* If the ID's entry is not in the file we operated on, skip it */
+ if( ent->file->shared != names->loc->file->shared )
+ HGOTO_DONE(SUCCEED); /* Do not exit search over IDs */
+ } /* end else */
- /* Get the type of call we are doing */
- switch(names->op) {
-
- /*-------------------------------------------------------------------------
- * OP_MOUNT
- *-------------------------------------------------------------------------
- */
-
- case OP_MOUNT:
-
- /* Find entries that might contain part of this name */
- if ( HDstrstr( ent->name, names->src_name ))
- {
-
- /* Store the old name for unmount case */
- /*ent->old_name = ent->name;*/
- ent->old_name = HDstrdup(ent->name);
-
- if (names->dst_name) {
- len1 = HDstrlen( names->dst_name );
- ent->name = H5MM_malloc( len1+1 );
- HDstrcpy( ent->name, names->dst_name );
- }
- else
- HDstrcpy( ent->name, "" );
-
- }
-
- /* Do not exit loop */
- ret_value = 0;
- goto done;
- break;
-
- /*-------------------------------------------------------------------------
- * OP_UNMOUNT
- *-------------------------------------------------------------------------
- */
-
- case OP_UNMOUNT:
-
- if(ent->name){
- /* Find entries that might contain part of this name */
- if ( HDstrstr( ent->name, names->src_name ))
- {
-
- /* Delete the old name */
- ent->name=H5MM_xfree(ent->name);
-
- if (names->dst_name){
- len1 = HDstrlen( names->dst_name );
- ent->name = H5MM_malloc( len1+1 );
- HDstrcpy( ent->name, names->dst_name );
- }
- }
- }/*if*/
-
-
- /* See if the entry old name matches */
- if ( ent->old_name ) {
- if ( HDstrstr( ent->old_name, names->src_name ))
- {
-
- /* Delete the old name */
- if (ent->name )
- H5MM_xfree(ent->name);
-
- /* Copy the old name to the entry */
- ent->name = ent->old_name;
- ent->old_name = NULL;
- }
- }
-
-
- /* Do not exit loop */
- ret_value = 0;
-
-
- goto done;
- break;
-
- /*-------------------------------------------------------------------------
- * OP_UNLINK
- *-------------------------------------------------------------------------
- */
-
- case OP_UNLINK:
-
- /* H5Gunlink case */
-
- if (ent->name ){
- cmp = HDstrcmp( ent->name, names->src_name );
-
- /* Found the correct entry, just replace the name */
- if ( cmp==0 )
- {
- ent->name=H5MM_xfree(ent->name);
-
- if (names->dst_name){
- len1 = HDstrlen( names->dst_name );
- ent->name = H5MM_malloc( len1+1 );
- HDstrcpy( ent->name, names->dst_name );
- }
-
- }
-
- /* Find other entries that might contain part of this name */
- else if ( cmp>0 )
- {
-
- if ( HDstrstr( ent->name, names->src_name ))
- {
- /* Delete the old name and clear the entry */
- H5MM_xfree(ent->name);
- ent->name=NULL;
- }
-
- }
- }/*if*/
-
-
- /* Do not exit loop */
- ret_value = 0;
- goto done;
- break;
-
- /*-------------------------------------------------------------------------
- * OP_MOVE
- *-------------------------------------------------------------------------
- */
-
- case OP_MOVE:
-
- /* H5Gmove case, check for relative names case */
-
- /* Verify if we have the wanted entry */
- if ( HDstrcmp( ent->name, names->src_name )!=0 )
- {
-
- /* Do not exit loop */
- ret_value = SUCCEED;
-
- /* Get the last component of the name */
- H5G_rest( ent->name, &rest );
-
- /* Relative names case, build the full pathname */
- if ( rest && HDstrcmp( rest, names->src_name )==0 )
- {
-
- len1 = HDstrlen(ent->name);
- len2 = HDstrlen(rest);
- ent->name[len1-len2-1] = '\0';
-
- tmp_buf = HDstrdup(ent->name);
-
- len1 = HDstrlen(ent->name);
- len2 = HDstrlen(names->dst_name);
- assert(len1>0 && len2>0);
-
- H5MM_xfree(ent->name);
- ent->name = H5MM_malloc(len1+1+len2+1);
- HDstrcpy(ent->name, tmp_buf);
- HDstrcpy(ent->name+len1, "/");
- HDstrcpy(ent->name+len1+1, names->dst_name);
-
- HDfree(tmp_buf);
-
- /* Found entry, exit loop */
- ret_value = 1;
-
- } /* Relative names case */
-
- goto done;
-
- } /* wanted entry */
-
-
- break;
-
- /*-------------------------------------------------------------------------
- * OP_LINK
- *-------------------------------------------------------------------------
- */
-
- case OP_LINK:
-
- /* H5Glink case */
- cmp = HDstrcmp( ent->name, names->src_name );
-
- /* Found the correct entry, just replace the name */
- if ( cmp==0 )
- {
-
- if (ent->name )
- H5MM_xfree(ent->name);
-
- len1 = HDstrlen( names->dst_name );
- ent->name = H5MM_malloc( len1+1 );
- HDstrcpy( ent->name, names->dst_name );
- }
-
-
- /* Do not exit loop */
- ret_value = 0;
- goto done;
- break;
-
-
-
- default:
- ret_value = FAIL;
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL,
- "invalid call");
- }
-
-
-
- /* Delete the old name */
- if (ent->name )
- H5MM_xfree(ent->name);
-
- /* Add the new name */
- len1 = HDstrlen( names->dst_name );
- ent->name = H5MM_malloc( len1+1 );
- HDstrcpy( ent->name, names->dst_name );
-
- /* Found entry, exit loop */
- ret_value = 1;
+ /* Get the type of call we are doing */
+ switch(names->op) {
+ /*-------------------------------------------------------------------------
+ * OP_MOUNT
+ *-------------------------------------------------------------------------
+ */
+ case OP_MOUNT:
+ /* Find entries that might contain part of this name */
+ if(ent->name) {
+ if(HDstrstr(ent->name, names->src_name)) {
+ /* Keep the old name for when file is unmounted */
+ ent->old_name = ent->name;
+
+ /* Set the new name for the object */
+ ent->name=H5MM_xstrdup(names->dst_name);
+ } /* end if */
+ } /* end if */
+ break;
+
+ /*-------------------------------------------------------------------------
+ * OP_UNMOUNT
+ *-------------------------------------------------------------------------
+ */
+ case OP_UNMOUNT:
+ /* Find entries that might contain part of current name */
+ if(ent->name) {
+ if(HDstrstr(ent->name, names->src_name)) {
+ /* Delete the old name */
+ H5MM_xfree(ent->name);
+
+ /* Copy the new name */
+ ent->name=H5MM_xstrdup(names->dst_name);
+ } /* end if */
+ } /* end if*/
+
+ /* See if the entry old name matches */
+ if(ent->old_name) {
+ if(HDstrstr(ent->old_name, names->src_name)) {
+ /* Delete the old name */
+ H5MM_xfree(ent->name);
+
+ /* Copy the old name to the entry */
+ ent->name = ent->old_name;
+ ent->old_name = NULL;
+ } /* end if */
+ } /* end if */
+ break;
+
+ /*-------------------------------------------------------------------------
+ * OP_UNLINK
+ *-------------------------------------------------------------------------
+ */
+ case OP_UNLINK:
+ if(ent->name) {
+ /* Found the correct entry, just replace the name */
+ if(HDstrcmp(ent->name, names->src_name)==0) {
+ /* Delete the old name */
+ H5MM_xfree(ent->name);
+
+ /* Copy destination name */
+ ent->name=H5MM_xstrdup(names->dst_name);
+ } /* end if */
+ /* Find other entries that might contain part of this name */
+ else {
+ if(H5G_common_path(ent->name, names->src_name))
+ ent->name=H5MM_xfree(ent->name); /* Delete the old name and clear the entry */
+ } /* end else */
+ } /* end if*/
+ break;
+
+ /*-------------------------------------------------------------------------
+ * OP_MOVE
+ *-------------------------------------------------------------------------
+ */
+ case OP_MOVE: /* H5Gmove case, check for relative names case */
+ if(ent->name) {
+ /* Verify if we have the wanted entry */
+ if(HDstrcmp(ent->name, names->src_name)==0) {
+ /* Delete the old name */
+ H5MM_xfree(ent->name);
+
+ /* Set the new name */
+ ent->name=H5MM_xstrdup(names->dst_name);
+ } /* end if */
+ else {
+ /* Get the last component of the name */
+ rest=H5G_rest(ent->name);
+
+ /* Relative names case, build the full pathname */
+ if(rest && HDstrcmp(rest, names->src_name)==0) {
+ size_t ent_name_len = HDstrlen(ent->name); /* Length of entry's full pathname */
+ size_t rest_len = HDstrlen(rest); /* Length of entry's last component of pathname */
+
+ /* Reallocate buffer for entry's name */
+ ent->name=H5MM_realloc(ent->name,
+ ent_name_len+(HDstrlen(names->dst_name)-rest_len)+1);
+
+ /* Overwrite last component of name */
+ HDstrcpy(ent->name+(ent_name_len-rest_len),names->dst_name);
+ } /* Relative names case */
+ } /* wanted entry */
+ } /* end if */
+ break;
+
+ default:
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid call");
+ } /* end switch */
done:
- FUNC_LEAVE(ret_value);
+ FUNC_LEAVE(ret_value);
}
diff --git a/src/H5Gent.c b/src/H5Gent.c
index 30c082e..205f616 100644
--- a/src/H5Gent.c
+++ b/src/H5Gent.c
@@ -337,8 +337,7 @@ done:
FUNC_LEAVE(ret_value);
}
-
-
+
/*-------------------------------------------------------------------------
* Function: H5G_ent_copy
*
@@ -356,33 +355,28 @@ done:
*
*-------------------------------------------------------------------------
*/
-
herr_t
H5G_ent_copy( const H5G_entry_t *src, H5G_entry_t *dst )
{
+ herr_t ret_value=SUCCEED; /* Return value */
- herr_t ret_value=SUCCEED; /* Return value */
+ FUNC_ENTER_NOAPI(H5G_ent_copy, FAIL);
- FUNC_ENTER_NOAPI(H5G_ent_copy, FAIL);
+ /* check arguments */
+ assert( src );
+ assert( dst );
- assert( src );
- assert( dst );
+ /* Copy the top level information */
+ HDmemcpy(dst,src,sizeof(H5G_entry_t));
- HDmemcpy(dst,src,sizeof(H5G_entry_t));
+ /* Deep copy the names */
+ dst->name=H5MM_xstrdup(src->name);
+ dst->old_name=H5MM_xstrdup(src->old_name);
- if (src->name){
- dst->name=H5MM_strdup(src->name);
- }
- if (src->old_name){
- dst->old_name=H5MM_strdup(src->old_name);
- }
-
-
done:
- FUNC_LEAVE(SUCCEED);
+ FUNC_LEAVE(ret_value);
}
-
/*-------------------------------------------------------------------------
* Function: H5G_ent_debug
diff --git a/src/H5Gnode.c b/src/H5Gnode.c
index 7ad68e3..ff76674 100644
--- a/src/H5Gnode.c
+++ b/src/H5Gnode.c
@@ -324,9 +324,9 @@ done:
* Added dxpl parameter to allow more control over I/O from metadata
* cache.
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
- *
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
+ *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -401,11 +401,9 @@ H5G_node_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5G_node_
* preempted from the cache.
*/
if (destroy) {
-
- /*Free the ID to name buffer */
- for (i=0; i<sym->nsyms; i++) {
- H5G_free_ent_name(&(sym->entry[i]));
- }
+ /* Free the ID to name buffer */
+ for (i=0; i<sym->nsyms; i++)
+ H5G_free_ent_name(&(sym->entry[i]));
sym->entry = H5FL_ARR_FREE(H5G_entry_t,sym->entry);
H5FL_FREE(H5G_node_t,sym);
@@ -858,7 +856,7 @@ H5G_node_insert(H5F_t *f, haddr_t addr, void UNUSED *_lt_key,
HDmemmove(insert_into->entry + idx + 1,
insert_into->entry + idx,
(insert_into->nsyms - idx) * sizeof(H5G_entry_t));
- insert_into->entry[idx] = bt_udata->ent;
+ H5G_ent_copy(&(bt_udata->ent), &(insert_into->entry[idx])); /* Deep copy the entry */
insert_into->entry[idx].dirty = TRUE;
insert_into->nsyms += 1;
@@ -889,12 +887,12 @@ done:
* Thursday, September 24, 1998
*
* Modifications:
- * Robb Matzke, 1999-07-28
- * The ADDR argument is passed by value.
+ * Robb Matzke, 1999-07-28
+ * The ADDR argument is passed by value.
+ *
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
+ * Added `id to name' support.
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
- * Added `id to name' support.
- *
*-------------------------------------------------------------------------
*/
static H5B_ins_t
@@ -959,8 +957,8 @@ H5G_node_remove(H5F_t *f, haddr_t addr, void *_lt_key/*in,out*/,
H5HL_remove(f, bt_udata->heap_addr, sn->entry[idx].name_off, HDstrlen(s)+1);
H5E_clear(); /*no big deal*/
- /*Free the ID to name buffer */
- H5G_free_ent_name(sn->entry+idx);
+ /* Free the ID to name buffer for the entry being squeezed out */
+ H5G_free_ent_name(sn->entry+idx);
/* Remove the entry from the symbol table node */
if (1==sn->nsyms) {
diff --git a/src/H5Gprivate.h b/src/H5Gprivate.h
index 20ea00b..4b91daf 100644
--- a/src/H5Gprivate.h
+++ b/src/H5Gprivate.h
@@ -11,9 +11,9 @@
* Purpose: Library-visible declarations.
*
* Modifications: Aug 22, 2002
- * Pedro Vicente <pvn@ncsa.uiuc.edu>
- * Added 'names' field to H5G_entry_t
- * Added H5G_replace_name
+ * Pedro Vicente <pvn@ncsa.uiuc.edu>
+ * Added 'names' field to H5G_entry_t
+ * Added H5G_replace_name
*
*-------------------------------------------------------------------------
*/
@@ -112,24 +112,13 @@ typedef struct H5G_typeinfo_t {
char *desc; /*description of object type */
} H5G_typeinfo_t;
-
- typedef enum H5G_names_op_t {
- OP_MOVE = 0, /* H5*move call */
- OP_LINK = 1, /* H5Glink call */
- OP_UNLINK = 2, /* H5Gunlink call */
- OP_MOUNT = 3, /* H5Fmount call */
- OP_UNMOUNT= 4 /* H5Funmount call */
- }H5G_names_op_t;
-
-/* Struct only used by change name callback function */
-typedef struct H5G_names_t {
- H5I_type_t obj_type;
- const char *src_name;
- const char *dst_name;
- H5G_entry_t *loc;
- H5G_names_op_t op;
-} H5G_names_t;
-
+/* Type of operation being performed for call to H5G_replace_name() */
+typedef enum H5G_names_op_t {
+ OP_MOVE = 0, /* H5*move call */
+ OP_UNLINK, /* H5Gunlink call */
+ OP_MOUNT, /* H5Fmount call */
+ OP_UNMOUNT /* H5Funmount call */
+} H5G_names_op_t;
/*
* Library prototypes... These are the ones that other packages routinely
@@ -176,6 +165,12 @@ H5_DLL herr_t H5G_traverse_slink(H5G_entry_t *grp_ent/*in,out*/,
H5_DLL herr_t H5G_ent_encode(H5F_t *f, uint8_t **pp, const H5G_entry_t *ent);
H5_DLL herr_t H5G_ent_decode(H5F_t *f, const uint8_t **pp,
H5G_entry_t *ent/*out*/);
+H5_DLL herr_t H5G_replace_name(int type, H5G_entry_t *loc, const char *src_name,
+ const char *dst_name, H5G_names_op_t op);
+H5_DLL herr_t H5G_insert_name(H5G_entry_t *loc, H5G_entry_t *obj, const char *name);
+H5_DLL herr_t H5G_ent_copy(const H5G_entry_t *src, H5G_entry_t *dst );
+H5_DLL herr_t H5G_free_grp_name(H5G_t *grp);
+H5_DLL herr_t H5G_free_ent_name(H5G_entry_t *ent);
/*
* These functions operate on symbol table nodes.
@@ -192,11 +187,4 @@ H5_DLL H5G_cache_t *H5G_ent_cache(H5G_entry_t *ent, H5G_type_t *cache_type);
H5_DLL herr_t H5G_ent_modified(H5G_entry_t *ent, H5G_type_t cache_type);
H5_DLL herr_t H5G_ent_debug(H5F_t *f, const H5G_entry_t *ent, FILE * stream,
int indent, int fwidth, haddr_t heap);
-H5_DLL herr_t H5G_replace_name( int type, H5G_entry_t *loc, const char *src_name,
- const char *dst_name, int op );
-H5_DLL herr_t H5G_insert_name( H5G_entry_t *loc, H5G_entry_t *obj, const char *name);
-H5_DLL herr_t H5G_ent_copy( const H5G_entry_t *src, H5G_entry_t *dst );
-/*Free the ID to name buffer */
-H5_DLL herr_t H5G_free_grp_name(H5G_t *grp);
-H5_DLL herr_t H5G_free_ent_name(H5G_entry_t *ent);
#endif
diff --git a/src/H5Gstab.c b/src/H5Gstab.c
index 3f53464..bc7c949 100644
--- a/src/H5Gstab.c
+++ b/src/H5Gstab.c
@@ -121,9 +121,9 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added `id to name' support.
- * Added a deep copy of the symbol table entry
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added `id to name' support.
+ * Added a deep copy of the symbol table entry
*
*-------------------------------------------------------------------------
*/
@@ -135,8 +135,6 @@ H5G_stab_find(H5G_entry_t *grp_ent, const char *name,
H5O_stab_t stab; /*symbol table message */
herr_t ret_value=SUCCEED; /* Return value */
- obj_ent->name=NULL;
-
FUNC_ENTER_NOAPI(H5G_stab_find, FAIL);
/* Check arguments */
@@ -153,27 +151,20 @@ H5G_stab_find(H5G_entry_t *grp_ent, const char *name,
/* search the B-tree */
if (H5B_find(grp_ent->file, H5B_SNODE, stab.btree_addr, &udata) < 0) {
- HRETURN_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "not found");
- }
-
+ HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "not found");
+ } /* end if */
/* change OBJ_ENT only if found */
- else
- {
- if (obj_ent) {
-
- /* do a deep copy */
- if (H5G_ent_copy( &(udata.ent), obj_ent )<0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to copy entry");
-
- /* insert the name into the symbol entry OBJ_ENT */
- if (H5G_insert_name( grp_ent, obj_ent, name ) < 0) {
- HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL,
- "cannot insert name");
- }
-
- }
- }
-
+ else {
+ if (obj_ent) {
+ /* do a deep copy */
+ if (H5G_ent_copy( &(udata.ent), obj_ent )<0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to copy entry");
+
+ /* insert the name into the symbol entry OBJ_ENT */
+ if (H5G_insert_name( grp_ent, obj_ent, name ) < 0)
+ HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "cannot insert name");
+ } /* end if */
+ } /* end else */
done:
FUNC_LEAVE(ret_value);
@@ -197,8 +188,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -225,10 +216,7 @@ H5G_stab_insert(H5G_entry_t *grp_ent, const char *name, H5G_entry_t *obj_ent)
udata.operation = H5G_OPER_INSERT;
udata.name = name;
udata.heap_addr = stab.heap_addr;
-
- /* Deep copy */
- H5G_ent_copy(obj_ent, &udata.ent);
-
+ udata.ent = *obj_ent; /* Shallow copy here, deep copy happens in H5G_node_insert() callback() */
/* insert */
if (H5B_insert(grp_ent->file, H5B_SNODE, stab.btree_addr, split_ratios, &udata) < 0)
@@ -237,11 +225,9 @@ H5G_stab_insert(H5G_entry_t *grp_ent, const char *name, H5G_entry_t *obj_ent)
/* update the name offset in the entry */
obj_ent->name_off = udata.ent.name_off;
- /* insert the name into the symbol entry OBJ_ENT */
- if (H5G_insert_name( grp_ent, obj_ent, name ) < 0) {
- HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL,
- "cannot insert name");
- }
+ /* insert the name into the symbol entry OBJ_ENT */
+ if(H5G_insert_name(grp_ent, obj_ent, name) < 0)
+ HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "cannot insert name");
done:
FUNC_LEAVE(ret_value);
diff --git a/src/H5I.c b/src/H5I.c
index e86ce66..9ff40c5 100644
--- a/src/H5I.c
+++ b/src/H5I.c
@@ -37,15 +37,16 @@
#include "H5FLprivate.h" /*Free Lists */
#include "H5MMprivate.h"
+/* Define this to compile in support for dumping ID information */
+/* #define H5I_DEBUG_OUTPUT */
+#ifndef H5I_DEBUG_OUTPUT
+#include "H5Gprivate.h" /*symbol tables */
+#else /* H5I_DEBUG_OUTPUT */
#define H5G_PACKAGE /*suppress error message about including H5Gpkg.h */
-#define H5I_DEBUG_OUTPUT
-
-
-#include "H5Gprivate.h" /*symbol tables */
#include "H5Gpkg.h"
#include "H5Dprivate.h" /*datasets */
#include "H5Tprivate.h" /*data types */
-#include "H5Aprivate.h" /*attributes */
+#endif /* H5I_DEBUG_OUTPUT */
/* Interface initialialization? */
#define PABLO_MASK H5I_mask
@@ -1117,9 +1118,7 @@ done:
FUNC_LEAVE(ret_value);
}
-
-
-
+
/*-------------------------------------------------------------------------
* Function: H5Iget_name
*
@@ -1145,44 +1144,36 @@ done:
*
*-------------------------------------------------------------------------
*/
-
-ssize_t H5Iget_name(hid_t id, char *name/*out*/, size_t size)
+ssize_t
+H5Iget_name(hid_t id, char *name/*out*/, size_t size)
{
- H5G_entry_t *ent; /*symbol table entry */
- size_t len=0;
- size_t count;
- ssize_t ret_value;
-
- FUNC_ENTER_API (H5Iget_name, FAIL);
-
- /* get symbol table entry */
- if ( NULL== ( ent = H5G_loc( id )))
- goto done;
-
- if ( ent->name != NULL ) {
-
- len = HDstrlen(ent->name);
- count = MIN(len+1,size);
-
- if ( name ) {
- HDstrncpy( name, ent->name, count );
- if ( len >= size ) {
- name[size-1]='\0';
- }
- }
- }
- else
- {
- len = 0;
- }
-
-done:
- ret_value = len;
- FUNC_LEAVE( ret_value );
-}
+ H5G_entry_t *ent; /*symbol table entry */
+ size_t len=0;
+ ssize_t ret_value;
+ FUNC_ENTER_API (H5Iget_name, FAIL);
+ /* get symbol table entry */
+ if(NULL!=(ent = H5G_loc(id))) {
+ if (ent->name != NULL) {
+ len = HDstrlen(ent->name);
+ if(name) {
+ HDstrncpy(name, ent->name, MIN(len+1,size));
+ if(len >= size)
+ name[size-1]='\0';
+ } /* end if */
+ } /* end if */
+ } /* end if */
+
+ /* Set return value */
+ ret_value=len;
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
/*-------------------------------------------------------------------------
* Function: H5I_debug
*
@@ -1197,8 +1188,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -1206,265 +1197,70 @@ done:
static herr_t
H5I_debug(H5I_type_t grp)
{
- H5I_id_group_t *grp_ptr;
- H5I_id_info_t *cur;
- int is, js;
- unsigned int iu;
- herr_t ret_value; /* Return value */
-
-
- H5G_entry_t *ent = NULL;
-
- FUNC_ENTER_API(H5I_debug, FAIL);
-
- fprintf(stderr, "Dumping group %d\n", (int)grp);
- grp_ptr = H5I_id_group_list_g[grp];
-
- /* Header */
- fprintf(stderr, " count = %u\n", grp_ptr->count);
- fprintf(stderr, " reserved = %u\n", grp_ptr->reserved);
- fprintf(stderr, " wrapped = %u\n", grp_ptr->wrapped);
- fprintf(stderr, " hash_size = %lu\n",
- (unsigned long)grp_ptr->hash_size);
- fprintf(stderr, " ids = %u\n", grp_ptr->ids);
- fprintf(stderr, " nextid = %u\n", grp_ptr->nextid);
-
- /* Cache */
- fprintf(stderr, " Cache:\n");
- for (is=0; is<ID_CACHE_SIZE; is++) {
- if (H5I_cache_g[is] && H5I_GROUP(H5I_cache_g[is]->id)==grp) {
- fprintf(stderr, " Entry-%d, ID=%lu\n",
- is, (unsigned long)(H5I_cache_g[is]->id));
- }
- }
-
- /* List */
- fprintf(stderr, " List:\n");
- for (iu=0; iu<grp_ptr->hash_size; iu++) {
- for (js=0, cur=grp_ptr->id_list[iu]; cur; cur=cur->next, js++) {
- fprintf(stderr, " #%u.%d\n", iu, js);
- fprintf(stderr, " id = %lu\n",
- (unsigned long)(cur->id));
- fprintf(stderr, " count = %u\n", cur->count);
- fprintf(stderr, " obj = 0x%08lx\n",
- (unsigned long)(cur->obj_ptr));
-
-
- switch(grp) {
-
- case H5I_GROUP:
- ent = H5G_entof((H5G_t*)cur->obj_ptr);
- break;
- case H5I_DATASET:
- ent = H5D_entof((H5D_t*)cur->obj_ptr);
- break;
- case H5I_DATATYPE:
- ent = H5T_entof((H5T_t*)cur->obj_ptr);
- break;
- default:
- HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL,
- "unknown data object");
- }/* switch*/
-
- fprintf(stderr, "name = %s\n",ent->name);
-
-
-
- }
- }
-
-done:
- FUNC_LEAVE(SUCCEED);
-}
-#endif /* H5I_DEBUG_OUTPUT */
-
-
-/*-------------------------------------------------------------------------
- * Function: H5I_debug_grp
- *
- * Purpose: Dump the contents of a group to stderr for debugging
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: July 26, 2002
- *
- * Comments: Public function
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-
-#ifdef H5I_DEBUG_OUTPUT
-herr_t H5Idebug_grp(H5I_type_t grp)
-{
- H5I_id_group_t *grp_ptr;
- H5I_id_info_t *cur;
- int is, js;
- unsigned int iu;
- herr_t ret_value; /* Return value */
-
- FUNC_ENTER_API(H5Idebug_grp, FAIL);
-
- fprintf(stderr, "Dumping group %d\n", (int)grp);
- grp_ptr = H5I_id_group_list_g[grp];
-
- /* Header */
- fprintf(stderr, " count = %u\n", grp_ptr->count);
- fprintf(stderr, " reserved = %u\n", grp_ptr->reserved);
- fprintf(stderr, " wrapped = %u\n", grp_ptr->wrapped);
- fprintf(stderr, " hash_size = %lu\n",
- (unsigned long)grp_ptr->hash_size);
- fprintf(stderr, " ids = %u\n", grp_ptr->ids);
- fprintf(stderr, " nextid = %u\n", grp_ptr->nextid);
-
- /* Cache */
- fprintf(stderr, " Cache:\n");
- for (is=0; is<ID_CACHE_SIZE; is++) {
- if (H5I_cache_g[is] && H5I_GROUP(H5I_cache_g[is]->id)==grp) {
- fprintf(stderr, " Entry-%d, ID=%lu\n",
- is, (unsigned long)(H5I_cache_g[is]->id));
- }
- }
-
- /* List */
- fprintf(stderr, " List:\n");
- for (iu=0; iu<grp_ptr->hash_size; iu++) {
- for (js=0, cur=grp_ptr->id_list[iu]; cur; cur=cur->next, js++) {
-
- /* avoid no named datatypes */
- if( grp==H5I_DATATYPE && H5T_is_immutable((H5T_t*)cur->obj_ptr))
- break;
-
-
- fprintf(stderr, " #%u.%d\n", iu, js);
- fprintf(stderr, " id = %lu\n",
- (unsigned long)(cur->id));
- fprintf(stderr, " count = %u\n", cur->count);
- fprintf(stderr, " obj = 0x%08lx\n",
- (unsigned long)(cur->obj_ptr));
- }
- }
-
-done:
- FUNC_LEAVE(SUCCEED);
-}
-#endif /* H5I_DEBUG_OUTPUT */
+ H5I_id_group_t *grp_ptr;
+ H5I_id_info_t *cur;
+ H5G_entry_t *ent = NULL;
+ int is, js;
+ unsigned int iu;
+ herr_t ret_value; /* Return value */
+ FUNC_ENTER_API(H5I_debug, FAIL);
+ fprintf(stderr, "Dumping group %d\n", (int)grp);
+ grp_ptr = H5I_id_group_list_g[grp];
+ /* Header */
+ fprintf(stderr, " count = %u\n", grp_ptr->count);
+ fprintf(stderr, " reserved = %u\n", grp_ptr->reserved);
+ fprintf(stderr, " wrapped = %u\n", grp_ptr->wrapped);
+ fprintf(stderr, " hash_size = %lu\n", (unsigned long)grp_ptr->hash_size);
+ fprintf(stderr, " ids = %u\n", grp_ptr->ids);
+ fprintf(stderr, " nextid = %u\n", grp_ptr->nextid);
+
+ /* Cache */
+ fprintf(stderr, " Cache:\n");
+ for (is=0; is<ID_CACHE_SIZE; is++) {
+ if (H5I_cache_g[is] && H5I_GROUP(H5I_cache_g[is]->id)==grp) {
+ fprintf(stderr, " Entry-%d, ID=%lu\n",
+ is, (unsigned long)(H5I_cache_g[is]->id));
+ }
+ }
-/*-------------------------------------------------------------------------
- * Function: H5Idebug_name
- *
- * Purpose: Dump the contents of a group to stderr for debugging
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: July 26, 2002
- *
- * Comments: Public function
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+ /* List */
+ fprintf(stderr, " List:\n");
+ for (iu=0; iu<grp_ptr->hash_size; iu++) {
+ for (js=0, cur=grp_ptr->id_list[iu]; cur; cur=cur->next, js++) {
+ fprintf(stderr, " #%u.%d\n", iu, js);
+ fprintf(stderr, " id = %lu\n", (unsigned long)(cur->id));
+ fprintf(stderr, " count = %u\n", cur->count);
+ fprintf(stderr, " obj = 0x%08lx\n", (unsigned long)(cur->obj_ptr));
+
+ /* Get the symbol table entry, so we get get the name */
+ switch(grp) {
+ case H5I_GROUP:
+ ent = H5G_entof((H5G_t*)cur->obj_ptr);
+ break;
+ case H5I_DATASET:
+ ent = H5D_entof((H5D_t*)cur->obj_ptr);
+ break;
+ case H5I_DATATYPE:
+ ent = H5T_entof((H5T_t*)cur->obj_ptr);
+ break;
+ default:
+ continue; /* Other types of IDs are not stored in files */
+ } /* end switch*/
+
+ if(ent) {
+ if(ent->name)
+ fprintf(stderr, " name = %s\n",ent->name);
+ if(ent->old_name)
+ fprintf(stderr, " old_name = %s\n",ent->old_name);
+ } /* end if */
+ } /* end for */
+ } /* end for */
-#ifdef H5I_DEBUG_OUTPUT
-herr_t H5Idebug_name(hid_t id)
-{
-
- H5I_type_t grp_type; /* group type */
- H5I_id_group_t *grp_ptr; /* ptr to the atomic group */
- H5I_id_info_t *cur=NULL; /* Current node being worked with */
- H5I_id_info_t *next=NULL; /* Next node in list */
- unsigned i;
-
- H5G_entry_t *ent = NULL;
- H5G_t *group=NULL;
- H5T_t *dt=NULL;
- H5D_t *dset=NULL;
- herr_t ret_value; /* Return value */
-
- FUNC_ENTER_API (H5Idebug_name, FAIL);
-
- grp_type = H5I_get_type(id);
-
- /* Check it */
- if (grp_type <= H5I_BADID || grp_type >= H5I_NGROUPS) {
- HRETURN(FAIL);
- }
-
- grp_ptr = H5I_id_group_list_g[grp_type];
- if (grp_ptr == NULL || grp_ptr->count <= 0) {
- HRETURN(FAIL);
- }
-
- /* Cache */
- fprintf(stderr, "\n");
- fprintf(stderr, "Cache:\n");
- for (i=0; i<ID_CACHE_SIZE; i++) {
- if (H5I_cache_g[i] && H5I_GROUP(H5I_cache_g[i]->id)==grp_type) {
-
- cur = H5I_cache_g[i];
- fprintf(stderr, " Entry-%d, ID=%lu\n", i, cur->id);
-
- switch(grp_type) {
- case H5I_GROUP:
- ent = H5G_entof((H5G_t*)cur->obj_ptr);
- break;
- case H5I_DATASET:
- ent = H5D_entof((H5D_t*)cur->obj_ptr);
- break;
- case H5I_DATATYPE:
- ent = H5T_entof((H5T_t*)cur->obj_ptr);
- break;
- default:
- HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL,
- "unknown data object");
- }/* switch*/
-
- fprintf(stderr, "name = %s\n",ent->name);
-
- }
- }
-
- /* List */
- fprintf(stderr, "List:\n");
- for (i=0; i<grp_ptr->hash_size; i++) {
- for (cur=grp_ptr->id_list[i]; cur; cur=next) {
-
- switch(grp_type) {
-
- case H5I_GROUP:
- ent = H5G_entof((H5G_t*)cur->obj_ptr);
- break;
- case H5I_DATASET:
- ent = H5D_entof((H5D_t*)cur->obj_ptr);
- break;
- case H5I_DATATYPE:
- ent = H5T_entof((H5T_t*)cur->obj_ptr);
- break;
- default:
- HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL,
- "unknown data object");
- }/* switch*/
-
- /* can be NULL in case of named datatypes */
- if (ent)
- {
- fprintf(stderr, "id = %lu\n",(unsigned long)(cur->id));
- fprintf(stderr, "name = %s\n",ent->name);
- }
-
- }
- }
-
done:
- FUNC_LEAVE(SUCCEED);
+ FUNC_LEAVE(SUCCEED);
}
-#endif /* H5I_DEBUG_OUTPUT */ \ No newline at end of file
+#endif /* H5I_DEBUG_OUTPUT */
+
diff --git a/src/H5Ipublic.h b/src/H5Ipublic.h
index 9110004..07ccbaa 100644
--- a/src/H5Ipublic.h
+++ b/src/H5Ipublic.h
@@ -51,12 +51,9 @@ typedef int hid_t;
extern "C" {
#endif
+/* Public API functions */
H5_DLL H5I_type_t H5Iget_type(hid_t id);
H5_DLL ssize_t H5Iget_name(hid_t object_id, char *name/*out*/, size_t size);
-H5_DLL herr_t H5Idebug_name(hid_t id);
-H5_DLL herr_t H5Idebug_grp(H5I_type_t grp);
-
-
#ifdef __cplusplus
}
diff --git a/src/H5MM.c b/src/H5MM.c
index fbd66f7..d5fff2f 100644
--- a/src/H5MM.c
+++ b/src/H5MM.c
@@ -98,18 +98,20 @@ done:
char *
H5MM_xstrdup(const char *s)
{
- char *ret_value;
+ char *ret_value=NULL;
/* Use FUNC_ENTER_NOINIT here to avoid performance issues */
FUNC_ENTER_NOINIT(H5MM_xstrdup);
- if (!s)
- HGOTO_DONE(NULL);
- ret_value = H5MM_malloc(HDstrlen(s) + 1);
- assert (ret_value);
- HDstrcpy(ret_value, s);
+ if (s) {
+ ret_value = H5MM_malloc(HDstrlen(s) + 1);
+ assert (ret_value);
+ HDstrcpy(ret_value, s);
+ } /* end if */
+#ifdef LATER
done:
+#endif /* LATER */
FUNC_LEAVE(ret_value);
}
diff --git a/src/H5O.c b/src/H5O.c
index 0ce00e4..001e998 100644
--- a/src/H5O.c
+++ b/src/H5O.c
@@ -269,8 +269,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -311,10 +311,7 @@ H5O_close(H5G_entry_t *obj_ent)
/* Free the ID to name buffers */
- if ( obj_ent->name )
- obj_ent->name = H5MM_xfree(obj_ent->name);
- if ( obj_ent->old_name )
- obj_ent->old_name = H5MM_xfree(obj_ent->old_name);
+ H5G_free_ent_name(obj_ent);
done:
FUNC_LEAVE(ret_value);
diff --git a/src/H5Odtype.c b/src/H5Odtype.c
index 81ea37b..df0e88d 100644
--- a/src/H5Odtype.c
+++ b/src/H5Odtype.c
@@ -1108,8 +1108,8 @@ done:
*
* Modifications:
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added `id to name' support.
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added `id to name' support.
*
*-------------------------------------------------------------------------
*/
@@ -1126,13 +1126,15 @@ H5O_dtype_set_share (H5F_t UNUSED *f, void *_mesg/*in,out*/,
assert (sh);
assert (!sh->in_gh);
- dt->ent = sh->u.ent;
+ /* Shallow copy the symbol table entry */
+ dt->ent = sh->u.ent;
- dt->ent.name = NULL;
- dt->ent.old_name = NULL;
-
- dt->state = H5T_STATE_NAMED;
+ /* Reset the names of the copied symbol table entry */
+ dt->ent.name = NULL;
+ dt->ent.old_name = NULL;
+ /* Note that the datatype is a named datatype */
+ dt->state = H5T_STATE_NAMED;
done:
FUNC_LEAVE (ret_value);
diff --git a/src/H5T.c b/src/H5T.c
index 0218342..e297263 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -5360,7 +5360,7 @@ H5T_open_oid (H5G_entry_t *ent)
/* Mark the type as named and open */
dt->state = H5T_STATE_OPEN;
- dt->ent = *ent;
+ dt->ent = *ent;
/* Set return value */
ret_value=dt;
@@ -5406,9 +5406,9 @@ done:
* Robb Matzke, 20 May 1999
* Now able to copy opaque types.
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 21 Sep 2002
- * Added a deep copy of the symbol table entry
- *
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 21 Sep 2002
+ * Added a deep copy of the symbol table entry
+ *
*-------------------------------------------------------------------------
*/
H5T_t *
@@ -5428,8 +5428,8 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
if (NULL==(new_dt = H5FL_ALLOC(H5T_t,0)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- /* Copy actual information */
- *new_dt = *old_dt;
+ /* Copy actual information */
+ *new_dt = *old_dt;
/* Copy parent information */
if (new_dt->parent)
@@ -5576,10 +5576,9 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
break;
} /* end switch */
-
- /*deep copy of the symbol table entry*/
- if (H5G_ent_copy(&(old_dt->ent),&(new_dt->ent))<0)
- HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, NULL, "unable to copy entry");
+ /* Deep copy of the symbol table entry */
+ if (H5G_ent_copy(&(old_dt->ent),&(new_dt->ent))<0)
+ HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, NULL, "unable to copy entry");
/* Set return value */
ret_value=new_dt;
@@ -5720,15 +5719,15 @@ done:
* Monday, December 8, 1997
*
* Modifications:
- * Robb Matzke, 1999-04-27
- * This function fails if the datatype state is IMMUTABLE.
+ * Robb Matzke, 1999-04-27
+ * This function fails if the datatype state is IMMUTABLE.
*
- * Robb Matzke, 1999-05-20
- * Closes opaque types also.
+ * Robb Matzke, 1999-05-20
+ * Closes opaque types also.
+ *
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added "ID to name" support
*
- * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
- * Added "ID to name" support
- *
*-------------------------------------------------------------------------
*/
herr_t
@@ -5783,7 +5782,7 @@ H5T_close(H5T_t *dt)
break;
}
- /*Free the ID to name buffer */
+ /*Free the ID to name buffer */
H5G_free_ent_name(&(dt->ent));
/* Free the datatype struct */
@@ -7529,9 +7528,6 @@ done:
* Friday, Dec 7, 2001
*
* Modifications:
- * Pedro Vicente
- * Tuesday, Sep 3, 2002
- * Added 'else'
*
*-------------------------------------------------------------------------
*/
@@ -7545,14 +7541,13 @@ H5T_is_immutable(H5T_t *dt)
assert(dt);
if(dt->state == H5T_STATE_IMMUTABLE)
- ret_value = TRUE;
- else
- ret_value = FALSE;
+ ret_value = TRUE;
done:
FUNC_LEAVE(ret_value);
}
+
/*-------------------------------------------------------------------------
* Function: H5T_is_named
*
@@ -7569,7 +7564,6 @@ done:
*
*-------------------------------------------------------------------------
*/
-
htri_t
H5T_is_named(H5T_t *dt)
{
@@ -7579,17 +7573,13 @@ H5T_is_named(H5T_t *dt)
assert(dt);
- if( dt->state == H5T_STATE_OPEN || dt->state == H5T_STATE_NAMED )
- ret_value = TRUE;
- else
- ret_value = FALSE;
+ if(dt->state == H5T_STATE_OPEN || dt->state == H5T_STATE_NAMED)
+ ret_value = TRUE;
done:
FUNC_LEAVE(ret_value);
}
-
-
/*--------------------------------------------------------------------------
NAME