diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2005-08-29 05:36:36 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2005-08-29 05:36:36 (GMT) |
commit | af6322d95ba8a89ae282360aa0202c479ebc9ed4 (patch) | |
tree | 51ee36701bb9a30ffd6a14ec8f16001a50076984 | |
parent | 9906d747bb82d1e34f6df33f689228a846f99892 (diff) | |
download | hdf5-af6322d95ba8a89ae282360aa0202c479ebc9ed4.zip hdf5-af6322d95ba8a89ae282360aa0202c479ebc9ed4.tar.gz hdf5-af6322d95ba8a89ae282360aa0202c479ebc9ed4.tar.bz2 |
[svn-r11308] Purpose:
Code cleanup
Description:
Clean up internals of group creation & iteration code.
Platforms tested:
FreeBSD 4.11 (sleipnir)
Mac OS X (nile)
Too minor to require h5committest
-rw-r--r-- | src/H5Fprivate.h | 10 | ||||
-rw-r--r-- | src/H5G.c | 11 | ||||
-rw-r--r-- | src/H5Gent.c | 7 | ||||
-rw-r--r-- | src/H5Gnode.c | 29 | ||||
-rw-r--r-- | src/H5Gpkg.h | 18 | ||||
-rw-r--r-- | src/H5Gstab.c | 50 | ||||
-rw-r--r-- | src/H5Opkg.h | 45 | ||||
-rw-r--r-- | src/H5Ostab.c | 7 |
8 files changed, 83 insertions, 94 deletions
diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index c819275..2cce29e 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -52,13 +52,13 @@ typedef struct H5F_t H5F_t; */ # define INT16ENCODE(p, i) { \ - *(p) = (uint8_t)( (unsigned)(i) & 0xff); (p)++; \ - *(p) = (uint8_t)(((unsigned)(i) >> 8) & 0xff); (p)++; \ + *(p) = (uint8_t)( (unsigned)(i) & 0xff); (p)++; \ + *(p) = (uint8_t)(((unsigned)(i) >> 8) & 0xff); (p)++; \ } # define UINT16ENCODE(p, i) { \ - *(p) = (uint8_t)( (i) & 0xff); (p)++; \ - *(p) = (uint8_t)(((unsigned)(i) >> 8) & 0xff); (p)++; \ + *(p) = (uint8_t)( (unsigned)(i) & 0xff); (p)++; \ + *(p) = (uint8_t)(((unsigned)(i) >> 8) & 0xff); (p)++; \ } # define INT32ENCODE(p, i) { \ @@ -417,6 +417,8 @@ H5_DLL herr_t H5F_init(void); #ifdef NOT_YET H5_DLL herr_t H5F_flush_all(hbool_t invalidate); #endif /* NOT_YET */ + +/* Functions than retrieve values from the file struct */ H5_DLL hid_t H5F_get_driver_id(const H5F_t *f); H5_DLL unsigned H5F_get_intent(const H5F_t *f); H5_DLL herr_t H5F_get_fileno(const H5F_t *f, unsigned long *filenum); @@ -1509,7 +1509,7 @@ H5G_namei(const H5G_entry_t *loc_ent, const char *name, const char **rest/*out*/ } /* end if */ else { did_insert = 1; - if (H5G_stab_insert(grp_ent, H5G_comp_g, ent, dxpl_id) < 0) + if (H5G_stab_insert(grp_ent, H5G_comp_g, ent, TRUE, dxpl_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINSERT, FAIL, "unable to insert name"); HGOTO_DONE(SUCCEED); } /* end else */ @@ -2215,11 +2215,6 @@ H5G_insert(H5G_entry_t *loc, const char *name, H5G_entry_t *ent, hid_t dxpl_id) if (H5G_namei(loc, name, NULL, NULL, NULL, H5G_TARGET_NORMAL, NULL, H5G_NAMEI_INSERT, ent, dxpl_id)<0) HGOTO_ERROR(H5E_SYM, H5E_EXISTS, FAIL, "already exists"); - /* - * Insert the object into a symbol table. - */ - if (H5O_link(ent, 1, dxpl_id) < 0) - HGOTO_ERROR(H5E_SYM, H5E_LINK, FAIL, "unable to increment hard link count"); done: FUNC_LEAVE_NOAPI(ret_value); @@ -2511,8 +2506,10 @@ H5G_link (H5G_entry_t *cur_loc, const char *cur_name, H5G_entry_t *new_loc, * exist and the file is writable (because the local heap is * writable). But if it does, the only side effect is that the local * heap has some extra garbage in it. + * + * Note: We don't increment the link count of the destination object */ - if (H5G_stab_insert (&grp_ent, rest, &cur_obj, dxpl_id)<0) + if (H5G_stab_insert (&grp_ent, rest, &cur_obj, FALSE, dxpl_id)<0) HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL, "unable to create new name/link for object"); break; diff --git a/src/H5Gent.c b/src/H5Gent.c index cd45d1e..7d7f250 100644 --- a/src/H5Gent.c +++ b/src/H5Gent.c @@ -377,7 +377,8 @@ H5G_ent_encode(H5F_t *f, uint8_t **pp, const H5G_entry_t *ent) * previous value in the destination. * H5G_COPY_SHALLOW - Copy all the fields from the source * to the destination, including the user path and - * canonical path. + * canonical path. (Destination "takes ownership" of + * user and canonical paths) * H5G_COPY_DEEP - Copy all the fields from the source to * the destination, deep copying the user and canonical * paths. @@ -416,8 +417,10 @@ H5G_ent_copy(H5G_entry_t *dst, const H5G_entry_t *src, H5G_ent_copy_depth_t dept dst->user_path_r=NULL; dst->canon_path_r=NULL; } else if(depth==H5G_COPY_SHALLOW) { +#ifndef NDEBUG /* Discarding 'const' qualifier OK - QAK */ - H5G_ent_reset(src); + H5G_ent_reset((H5G_entry_t *)src); +#endif /* NDEBUG */ } /* end if */ FUNC_LEAVE_NOAPI(SUCCEED); diff --git a/src/H5Gnode.c b/src/H5Gnode.c index f865906..d8492a5 100644 --- a/src/H5Gnode.c +++ b/src/H5Gnode.c @@ -983,14 +983,14 @@ H5G_node_found(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *_lt_key if (cmp) HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "not found"); - if (bt_udata->operation==H5G_OPER_FIND) - /* - * The caller is querying the symbol entry, copy it into the UDATA - * entry field. (Hmm... should this use H5G_ent_copy()? - QAK) - */ - bt_udata->ent = sn->entry[idx]; - else - HGOTO_ERROR(H5E_SYM, H5E_UNSUPPORTED, FAIL, "internal erorr (unknown symbol find operation)"); + /* + * The caller is querying the symbol entry, copy it into the UDATA + * entry field. + * + * (do a NULL copy, since the entry's name will be constructed later) + */ + if (H5G_ent_copy(bt_udata->ent, &sn->entry[idx], H5G_COPY_NULL)<0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to copy entry"); done: if (sn && H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, FALSE) < 0) @@ -1116,7 +1116,7 @@ H5G_node_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, void UNUSED *_lt_key, */ offset = H5HL_insert(f, dxpl_id, bt_udata->heap_addr, HDstrlen(bt_udata->name)+1, bt_udata->name); - bt_udata->ent.name_off = offset; + bt_udata->ent->name_off = offset; if (0==offset || (size_t)(-1)==offset) HGOTO_ERROR(H5E_SYM, H5E_CANTINSERT, H5B_INS_ERROR, "unable to insert symbol name into heap"); if ((size_t)(sn->nsyms) >= 2*H5F_SYM_LEAF_K(f)) { @@ -1173,12 +1173,19 @@ H5G_node_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, void UNUSED *_lt_key, } } - /* Move entries */ + /* Move entries down to make room for new entry */ HDmemmove(insert_into->entry + idx + 1, insert_into->entry + idx, (insert_into->nsyms - idx) * sizeof(H5G_entry_t)); - H5G_ent_copy(&(insert_into->entry[idx]), &(bt_udata->ent),H5G_COPY_NULL); + + /* Copy new entry into table */ + /* (use H5G_COPY_NULL because we don't track the object names in the table) */ + H5G_ent_copy(&(insert_into->entry[idx]), bt_udata->ent, H5G_COPY_NULL); + + /* Flag entry as dirty */ insert_into->entry[idx].dirty = TRUE; + + /* Increment # of symbols in table */ insert_into->nsyms += 1; done: diff --git a/src/H5Gpkg.h b/src/H5Gpkg.h index 2753a64..66087ba 100644 --- a/src/H5Gpkg.h +++ b/src/H5Gpkg.h @@ -65,30 +65,17 @@ struct H5G_t { }; /* - * These operations can be passed down from the H5G_stab layer to the - * H5G_node layer through the B-tree layer. - */ -typedef enum H5G_oper_t { - H5G_OPER_FIND = 0, /*find a symbol */ - H5G_OPER_INSERT = 1, /*insert a new symbol */ - H5G_OPER_REMOVE = 2 /*remove existing symbol */ -} H5G_oper_t; - -/* * Data exchange structure for symbol table nodes. This structure is * passed through the B-link tree layer to the methods for the objects * to which the B-link tree points. */ typedef struct H5G_bt_ud1_t { - /* downward */ - H5G_oper_t operation; /*what operation to perform */ const char *name; /*points to temporary memory */ haddr_t heap_addr; /*symbol table heap address */ /* downward for INSERT, upward for FIND */ - H5G_entry_t ent; /*entry to insert into table */ - + H5G_entry_t *ent; /*entry to insert into table */ } H5G_bt_ud1_t; /* @@ -105,7 +92,6 @@ typedef struct H5G_bt_ud2_t { /* upward */ int final_ent; /*final entry looked at */ - } H5G_bt_ud2_t; /* @@ -141,7 +127,7 @@ H5_DLL herr_t H5G_stab_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5_DLL herr_t H5G_stab_find(H5G_entry_t *grp_ent, const char *name, H5G_entry_t *obj_ent/*out*/, hid_t dxpl_id); H5_DLL herr_t H5G_stab_insert(H5G_entry_t *grp_ent, const char *name, - H5G_entry_t *obj_ent, hid_t dxpl_id); + H5G_entry_t *obj_ent, hbool_t inc_link, hid_t dxpl_id); H5_DLL herr_t H5G_stab_delete(H5F_t *f, hid_t dxpl_id, haddr_t btree_addr, haddr_t heap_addr); H5_DLL herr_t H5G_stab_remove(H5G_entry_t *grp_ent, const char *name, hid_t dxpl_id); diff --git a/src/H5Gstab.c b/src/H5Gstab.c index 66d9356..a41c588 100644 --- a/src/H5Gstab.c +++ b/src/H5Gstab.c @@ -33,7 +33,7 @@ H5FL_BLK_EXTERN(str_buf); /* Private prototypes */ -static herr_t H5G_insert_name(H5G_entry_t *loc, H5G_entry_t *obj, +static herr_t H5G_stab_insert_name(H5G_entry_t *loc, H5G_entry_t *obj, const char *name); @@ -155,31 +155,23 @@ H5G_stab_find(H5G_entry_t *grp_ent, const char *name, /* Check arguments */ assert(grp_ent); assert(grp_ent->file); + assert(obj_ent); assert(name && *name); /* set up the udata */ if (NULL == H5O_read(grp_ent, H5O_STAB_ID, 0, &stab, dxpl_id)) HGOTO_ERROR(H5E_SYM, H5E_BADMESG, FAIL, "can't read message"); - udata.operation = H5G_OPER_FIND; udata.name = name; udata.heap_addr = stab.heap_addr; + udata.ent = obj_ent; /* search the B-tree */ - if (H5B_find(grp_ent->file, dxpl_id, H5B_SNODE, stab.btree_addr, &udata) < 0) { + if (H5B_find(grp_ent->file, dxpl_id, H5B_SNODE, stab.btree_addr, &udata) < 0) HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "not found"); - } /* end if */ - /* change OBJ_ENT only if found */ - else { - if (obj_ent) { - /* do a NULL copy, since the obj_ent name will be constructed in H5G_insert_name() */ - if (H5G_ent_copy(obj_ent, &(udata.ent),H5G_COPY_NULL)<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 */ + + /* insert the name into the symbol entry OBJ_ENT */ + if (H5G_stab_insert_name( grp_ent, obj_ent, name ) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "cannot insert name"); done: FUNC_LEAVE_NOAPI(ret_value); @@ -209,7 +201,8 @@ done: *------------------------------------------------------------------------- */ herr_t -H5G_stab_insert(H5G_entry_t *grp_ent, const char *name, H5G_entry_t *obj_ent, hid_t dxpl_id) +H5G_stab_insert(H5G_entry_t *grp_ent, const char *name, H5G_entry_t *obj_ent, + hbool_t inc_link, hid_t dxpl_id) { H5O_stab_t stab; /*symbol table message */ H5G_bt_ud1_t udata; /*data to pass through B-tree */ @@ -225,24 +218,25 @@ H5G_stab_insert(H5G_entry_t *grp_ent, const char *name, H5G_entry_t *obj_ent, hi HGOTO_ERROR(H5E_SYM, H5E_LINK, FAIL, "interfile hard links are not allowed"); /* insert the name into the symbol entry OBJ_ENT */ - if(H5G_insert_name(grp_ent, obj_ent, name) < 0) + if(H5G_stab_insert_name(grp_ent, obj_ent, name) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "cannot insert name"); /* initialize data to pass through B-tree */ if (NULL == H5O_read(grp_ent, H5O_STAB_ID, 0, &stab, dxpl_id)) HGOTO_ERROR(H5E_SYM, H5E_BADMESG, FAIL, "not a symbol table"); - udata.operation = H5G_OPER_INSERT; udata.name = name; udata.heap_addr = stab.heap_addr; - H5G_ent_copy(&(udata.ent),obj_ent,H5G_COPY_NULL); /* NULL copy here, no copies happens in H5G_node_insert() callback() */ + udata.ent = obj_ent; /* insert */ if (H5B_insert(grp_ent->file, dxpl_id, H5B_SNODE, stab.btree_addr, &udata) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINSERT, FAIL, "unable to insert entry"); - /* update the name offset in the entry */ - obj_ent->name_off = udata.ent.name_off; + /* Increment link count on object, if appropriate */ + if(inc_link) + if (H5O_link(obj_ent, 1, dxpl_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_LINK, FAIL, "unable to increment hard link count") done: FUNC_LEAVE_NOAPI(ret_value); @@ -278,10 +272,9 @@ H5G_stab_remove(H5G_entry_t *grp_ent, const char *name, hid_t dxpl_id) /* initialize data to pass through B-tree */ if (NULL==H5O_read(grp_ent, H5O_STAB_ID, 0, &stab, dxpl_id)) HGOTO_ERROR(H5E_SYM, H5E_BADMESG, FAIL, "not a symbol table"); - udata.operation = H5G_OPER_REMOVE; udata.name = name; udata.heap_addr = stab.heap_addr; - HDmemset(&(udata.ent), 0, sizeof(udata.ent)); + udata.ent = NULL; /* remove */ if (H5B_remove(grp_ent->file, dxpl_id, H5B_SNODE, stab.btree_addr, &udata)<0) @@ -293,7 +286,7 @@ done: /*------------------------------------------------------------------------- - * Function: H5G_insert_name + * Function: H5G_stab_insert_name * * Purpose: Insert a name into the symbol entry OBJ, located at LOC * @@ -310,12 +303,12 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5G_insert_name(H5G_entry_t *loc, H5G_entry_t *obj, const char *name) +H5G_stab_insert_name(H5G_entry_t *loc, H5G_entry_t *obj, const char *name) { size_t name_len; /* Length of name to append */ herr_t ret_value = SUCCEED; - FUNC_ENTER_NOAPI_NOINIT(H5G_insert_name); + FUNC_ENTER_NOAPI_NOINIT(H5G_stab_insert_name); assert(loc); assert(obj); @@ -441,10 +434,9 @@ H5G_stab_delete(H5F_t *f, hid_t dxpl_id, haddr_t btree_addr, haddr_t heap_addr) assert(H5F_addr_defined(heap_addr)); /* Set up user data for B-tree deletion */ - HDmemset(&udata, 0, sizeof udata); - udata.operation = H5G_OPER_REMOVE; udata.name = NULL; udata.heap_addr = heap_addr; + udata.ent = NULL; /* Delete entire B-tree */ if(H5B_delete(f, dxpl_id, H5B_SNODE, btree_addr, &udata)<0) diff --git a/src/H5Opkg.h b/src/H5Opkg.h index 7217e53..df36d08 100644 --- a/src/H5Opkg.h +++ b/src/H5Opkg.h @@ -104,97 +104,100 @@ typedef struct H5O_t { } H5O_t; /* - * Null Message. + * Null Message. (0x0000) */ H5_DLLVAR const H5O_class_t H5O_NULL[1]; /* - * Simple Data Space Message. + * Simple Dataspace Message. (0x0001) */ H5_DLLVAR const H5O_class_t H5O_SDSPACE[1]; /* - * Data Type Message. + * Datatype Message. (0x0003) */ H5_DLLVAR const H5O_class_t H5O_DTYPE[1]; /* - * Old Fill Value Message. + * Old Fill Value Message. (0x0004) */ H5_DLLVAR const H5O_class_t H5O_FILL[1]; /* - * New Fill Value Message. The new fill value message is fill value plus + * New Fill Value Message. (0x0005) + * + * The new fill value message is fill value plus * space allocation time and fill value writing time and whether fill * value is defined. */ H5_DLLVAR const H5O_class_t H5O_FILL_NEW[1]; /* - * External File List Message + * External File List Message. (0x0007) */ H5_DLLVAR const H5O_class_t H5O_EFL[1]; /* - * Data Layout Message. + * Data Layout Message. (0x0008) */ H5_DLLVAR const H5O_class_t H5O_LAYOUT[1]; #ifdef H5O_ENABLE_BOGUS /* - * "Bogus" Message. + * "Bogus" Message. (0x0009) */ H5_DLLVAR const H5O_class_t H5O_BOGUS[1]; #endif /* H5O_ENABLE_BOGUS */ /* - * Filter pipeline message. + * Filter pipeline message. (0x000b) */ H5_DLLVAR const H5O_class_t H5O_PLINE[1]; /* - * Attribute Message. + * Attribute Message. (0x000c) */ H5_DLLVAR const H5O_class_t H5O_ATTR[1]; /* - * Object name message. + * Object name message. (0x000d) */ H5_DLLVAR const H5O_class_t H5O_NAME[1]; /* - * Modification time message. The message is just a `time_t'. + * Modification Time Message. (0x000e) + * + * The message is just a `time_t'. * (See also the "new" modification time message) */ H5_DLLVAR const H5O_class_t H5O_MTIME[1]; /* - * Shared object message. This message ID never really appears in an object + * Shared Object Message. (0x000f) + * + * This message ID never really appears in an object * header. Instead, bit 2 of the `Flags' field will be set and the ID field * will be the ID of the pointed-to message. */ H5_DLLVAR const H5O_class_t H5O_SHARED[1]; /* - * Object header continuation message. + * Object Header Continuation Message. (0x0010) */ H5_DLLVAR const H5O_class_t H5O_CONT[1]; /* - * Symbol table message. + * Symbol Table Message. (0x0011) */ H5_DLLVAR const H5O_class_t H5O_STAB[1]; /* - * New Modification time message. The message is just a `time_t'. + * New Modification Time Message. (0x0012) + * + * The message is just a `time_t'. */ H5_DLLVAR const H5O_class_t H5O_MTIME_NEW[1]; -/* - * Generic property list message. - */ -H5_DLLVAR const H5O_class_t H5O_PLIST[1]; - /* Package-local function prototypes */ H5_DLL void * H5O_read_real(const H5G_entry_t *ent, const H5O_class_t *type, int sequence, void *mesg, hid_t dxpl_id); diff --git a/src/H5Ostab.c b/src/H5Ostab.c index 7bb06d5..e5996c6 100644 --- a/src/H5Ostab.c +++ b/src/H5Ostab.c @@ -32,7 +32,6 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5FLprivate.h" /* Free lists */ #include "H5Gpkg.h" /* Groups */ -#include "H5MMprivate.h" /* Memory management */ #include "H5Opkg.h" /* Object headers */ @@ -41,7 +40,7 @@ static void *H5O_stab_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p, H5O_shar static herr_t H5O_stab_encode(H5F_t *f, uint8_t *p, const void *_mesg); static void *H5O_stab_copy(const void *_mesg, void *_dest, unsigned update_flags); static size_t H5O_stab_size(const H5F_t *f, const void *_mesg); -static herr_t H5O_stab_free (void *_mesg); +static herr_t H5O_stab_free(void *_mesg); static herr_t H5O_stab_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg); static herr_t H5O_stab_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int indent, int fwidth); @@ -72,7 +71,7 @@ H5FL_DEFINE_STATIC(H5O_stab_t); * Function: H5O_stab_decode * * Purpose: Decode a symbol table message and return a pointer to - * a new one created with malloc(). + * a newly allocated one. * * Return: Success: Ptr to new message in native order. * @@ -97,7 +96,7 @@ H5O_stab_decode(H5F_t *f, hid_t UNUSED dxpl_id, const uint8_t *p, H5O_shared_t U /* check args */ assert(f); assert(p); - assert (!sh); + assert(!sh); /* decode */ if (NULL==(stab = H5FL_CALLOC(H5O_stab_t))) |