diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/H5A.c | 2 | ||||
-rw-r--r-- | src/H5D.c | 7 | ||||
-rw-r--r-- | src/H5Edefin.h | 1 | ||||
-rw-r--r-- | src/H5Einit.h | 5 | ||||
-rw-r--r-- | src/H5Epubgen.h | 2 | ||||
-rw-r--r-- | src/H5Eterm.h | 3 | ||||
-rw-r--r-- | src/H5F.c | 38 | ||||
-rw-r--r-- | src/H5G.c | 7 | ||||
-rw-r--r-- | src/H5O.c | 477 | ||||
-rw-r--r-- | src/H5Oattr.c | 11 | ||||
-rw-r--r-- | src/H5Ocont.c | 39 | ||||
-rw-r--r-- | src/H5Odtype.c | 96 | ||||
-rw-r--r-- | src/H5Olayout.c | 8 | ||||
-rw-r--r-- | src/H5Omtime.c | 9 | ||||
-rw-r--r-- | src/H5Opkg.h | 3 | ||||
-rw-r--r-- | src/H5Oprivate.h | 14 | ||||
-rw-r--r-- | src/H5Oshared.c | 11 | ||||
-rw-r--r-- | src/H5Ostab.c | 10 | ||||
-rw-r--r-- | src/H5P.c | 33 | ||||
-rwxr-xr-x | src/H5Pocpl.c | 14 | ||||
-rw-r--r-- | src/H5Ppublic.h | 2 | ||||
-rw-r--r-- | src/H5T.c | 63 | ||||
-rw-r--r-- | src/H5Tarray.c | 9 | ||||
-rw-r--r-- | src/H5Tcommit.c | 4 | ||||
-rw-r--r-- | src/H5Tenum.c | 7 | ||||
-rw-r--r-- | src/H5Tpkg.h | 1 | ||||
-rw-r--r-- | src/H5Tvlen.c | 7 | ||||
-rw-r--r-- | src/H5detect.c | 17 | ||||
-rw-r--r-- | src/H5err.txt | 1 |
29 files changed, 608 insertions, 293 deletions
@@ -1455,7 +1455,7 @@ H5Adelete(hid_t loc_id, const char *name) HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "attribute not found") /* Delete the attribute from the location */ - if ((ret_value=H5O_remove(ent, H5O_ATTR_ID, found, H5AC_dxpl_id)) < 0) + if ((ret_value=H5O_remove(ent, H5O_ATTR_ID, found, TRUE, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete attribute header message") done: @@ -2161,7 +2161,7 @@ H5D_create(H5G_entry_t *loc, const char *name, hid_t type_id, const H5S_t *space if (NULL==(new_dset = H5FL_CALLOC(H5D_t))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - new_dset->ent.header=HADDR_UNDEF; + H5G_ent_reset(&(new_dset->ent)); /* Initialize the shared dataset space */ if(NULL == (new_dset->shared = H5D_new(dcpl_id,TRUE,has_vl_type))) @@ -2390,9 +2390,8 @@ H5D_create(H5G_entry_t *loc, const char *name, hid_t type_id, const H5S_t *space HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, NULL, "can't fill DCPL cache") /* - * Give the dataset a name. That is, create and add a new - * "H5G_entry_t" object to the group this dataset is being initially - * created in. + * Give the dataset a name. That is, create and add a new object to the + * group this dataset is being initially created in. */ if (H5G_insert(loc, name, &new_dset->ent, dxpl_id, dc_plist) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to name dataset") diff --git a/src/H5Edefin.h b/src/H5Edefin.h index a4acfbb..03065e6 100644 --- a/src/H5Edefin.h +++ b/src/H5Edefin.h @@ -88,6 +88,7 @@ hid_t H5E_VERSION_g = FAIL; /* Wrong version number */ hid_t H5E_ALIGNMENT_g = FAIL; /* Alignment error */ hid_t H5E_BADMESG_g = FAIL; /* Unrecognized message */ hid_t H5E_CANTDELETE_g = FAIL; /* Can't delete message */ +hid_t H5E_BADITER_g = FAIL; /* Iteration failed */ /* FPHDF5 errors */ hid_t H5E_CANTRECV_g = FAIL; /* Can't receive messages from processes */ diff --git a/src/H5Einit.h b/src/H5Einit.h index 4190c58..0efa7e6 100644 --- a/src/H5Einit.h +++ b/src/H5Einit.h @@ -310,6 +310,11 @@ if((msg = H5E_create_msg(cls, H5E_MINOR, "Can't delete message"))==NULL) HGOTO_ERROR(H5E_ERROR, H5E_CANTINIT, FAIL, "error message initialization failed") if((H5E_CANTDELETE_g = H5I_register(H5I_ERROR_MSG, msg))<0) HGOTO_ERROR(H5E_ERROR, H5E_CANTREGISTER, FAIL, "can't register error message") +assert(H5E_BADITER_g==(-1)); +if((msg = H5E_create_msg(cls, H5E_MINOR, "Iteration failed"))==NULL) + HGOTO_ERROR(H5E_ERROR, H5E_CANTINIT, FAIL, "error message initialization failed") +if((H5E_BADITER_g = H5I_register(H5I_ERROR_MSG, msg))<0) + HGOTO_ERROR(H5E_ERROR, H5E_CANTREGISTER, FAIL, "can't register error message") /* FPHDF5 errors */ assert(H5E_CANTRECV_g==(-1)); diff --git a/src/H5Epubgen.h b/src/H5Epubgen.h index 2e8a0e7..f694109 100644 --- a/src/H5Epubgen.h +++ b/src/H5Epubgen.h @@ -142,11 +142,13 @@ H5_DLLVAR hid_t H5E_DUPCLASS_g; /* Duplicate class name in parent class */ #define H5E_ALIGNMENT (H5OPEN H5E_ALIGNMENT_g) #define H5E_BADMESG (H5OPEN H5E_BADMESG_g) #define H5E_CANTDELETE (H5OPEN H5E_CANTDELETE_g) +#define H5E_BADITER (H5OPEN H5E_BADITER_g) H5_DLLVAR hid_t H5E_LINKCOUNT_g; /* Bad object header link count */ H5_DLLVAR hid_t H5E_VERSION_g; /* Wrong version number */ H5_DLLVAR hid_t H5E_ALIGNMENT_g; /* Alignment error */ H5_DLLVAR hid_t H5E_BADMESG_g; /* Unrecognized message */ H5_DLLVAR hid_t H5E_CANTDELETE_g; /* Can't delete message */ +H5_DLLVAR hid_t H5E_BADITER_g; /* Iteration failed */ /* FPHDF5 errors */ #define H5E_CANTRECV (H5OPEN H5E_CANTRECV_g) diff --git a/src/H5Eterm.h b/src/H5Eterm.h index 217a3c5..e36a5ab 100644 --- a/src/H5Eterm.h +++ b/src/H5Eterm.h @@ -89,7 +89,8 @@ H5E_LINKCOUNT_g= H5E_VERSION_g= H5E_ALIGNMENT_g= H5E_BADMESG_g= -H5E_CANTDELETE_g= +H5E_CANTDELETE_g= +H5E_BADITER_g= /* FPHDF5 errors */ H5E_CANTRECV_g= @@ -2412,6 +2412,25 @@ H5F_flush(H5F_t *f, hid_t dxpl_id, H5F_scope_t scope, unsigned flags) if (H5D_flush(f, dxpl_id, flags) < 0) HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "unable to flush dataset cache") + /* flush (and invalidate) the entire meta data cache */ + /* + * FIXME: This should be CLEAR_ONLY for non-captain processes. + * Need to fix the H5G_mkroot() call so that only the captain + * allocates object headers (calls the H5O_init function...via a + * lot of other functions first).... + */ + + H5AC_flags = 0; + + if ( (flags & H5F_FLUSH_INVALIDATE) != 0 ) + H5AC_flags |= H5AC__FLUSH_INVALIDATE_FLAG; + + if ( (flags & H5F_FLUSH_CLEAR_ONLY) != 0 ) + H5AC_flags |= H5AC__FLUSH_CLEAR_ONLY_FLAG; + + if (H5AC_flush(f, dxpl_id, H5AC_flags) < 0) + HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "unable to flush meta data cache") + /* * If we are invalidating everything (which only happens just before * the file closes), release the unused portion of the metadata and @@ -2467,25 +2486,6 @@ H5F_flush(H5F_t *f, hid_t dxpl_id, H5F_scope_t scope, unsigned flags) #endif /* H5_HAVE_FPHDF5 */ } /* end if */ - /* flush (and invalidate) the entire meta data cache */ - /* - * FIXME: This should be CLEAR_ONLY for non-captain processes. - * Need to fix the H5G_mkroot() call so that only the captain - * allocates object headers (calls the H5O_init function...via a - * lot of other functions first).... - */ - - H5AC_flags = 0; - - if ( (flags & H5F_FLUSH_INVALIDATE) != 0 ) - H5AC_flags |= H5AC__FLUSH_INVALIDATE_FLAG; - - if ( (flags & H5F_FLUSH_CLEAR_ONLY) != 0 ) - H5AC_flags |= H5AC__FLUSH_CLEAR_ONLY_FLAG; - - if (H5AC_flush(f, dxpl_id, H5AC_flags) < 0) - HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "unable to flush meta data cache") - /* Write the superblock to disk */ if (H5F_write_superblock(f, dxpl_id, NULL) != SUCCEED) HGOTO_ERROR(H5E_CACHE, H5E_WRITEERROR, FAIL, "unable to write superblock to file") @@ -1837,7 +1837,10 @@ H5G_mkroot (H5F_t *f, hid_t dxpl_id, H5G_entry_t *ent) H5FL_FREE(H5G_t, f->shared->root_grp); HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); } - f->shared->root_grp->ent = *ent; + /* Shallow copy (take ownership) of the group entry object */ + if(H5G_ent_copy(&(f->shared->root_grp->ent), ent, H5G_COPY_SHALLOW)<0) + HGOTO_ERROR (H5E_SYM, H5E_CANTCOPY, FAIL, "can't copy group entry") + f->shared->root_grp->shared->fo_count = 1; assert (1==f->nopen_objs); f->nopen_objs = 0; @@ -3096,7 +3099,7 @@ H5G_set_comment(H5G_entry_t *loc, const char *name, const char *buf, hid_t dxpl_ HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found"); /* Remove the previous comment message if any */ - if (H5O_remove(&obj_ent, H5O_NAME_ID, 0, dxpl_id)<0) + if (H5O_remove(&obj_ent, H5O_NAME_ID, 0, TRUE, dxpl_id)<0) H5E_clear_stack(NULL); /* Add the new message */ @@ -47,10 +47,28 @@ #include <sys/time.h> #endif /* H5_HAVE_GETTIMEOFDAY */ +/* Private typedefs */ + +/* User data for iteration while removing a message */ +typedef struct { + H5F_t *f; /* Pointer to file for insertion */ + hid_t dxpl_id; /* DXPL during iteration */ + int sequence; /* Sequence # to search for */ + unsigned nfailed; /* # of failed message removals */ + H5O_operator_t op; /* Callback routine for removal operations */ + void *op_data; /* Callback data for removal operations */ + hbool_t adj_link; /* Whether to adjust links when removing messages */ +} H5O_iter_ud1_t; + +/* Typedef for "internal" iteration operations */ +typedef herr_t (*H5O_operator_int_t)(H5O_mesg_t *mesg/*in,out*/, unsigned idx, + unsigned * oh_flags_ptr, void *operator_data/*in,out*/); + /* PRIVATE PROTOTYPES */ static herr_t H5O_init(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5G_entry_t *ent/*out*/, haddr_t header); static herr_t H5O_reset_real(const H5O_class_t *type, void *native); +static herr_t H5O_free_mesg(H5O_mesg_t *mesg); static void * H5O_copy_real(const H5O_class_t *type, const void *mesg, void *dst); static int H5O_count_real (H5G_entry_t *ent, const H5O_class_t *type, @@ -70,13 +88,14 @@ static int H5O_append_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, const H5O_class_t *type, unsigned flags, const void *mesg, unsigned * oh_flags_ptr); static herr_t H5O_remove_real(H5G_entry_t *ent, const H5O_class_t *type, - int sequence, hid_t dxpl_id); + int sequence, H5O_operator_t op, void *op_data, hbool_t adj_link, hid_t dxpl_id); static unsigned H5O_alloc(H5F_t *f, H5O_t *oh, const H5O_class_t *type, size_t size, unsigned * oh_flags_ptr); static unsigned H5O_alloc_extend_chunk(H5F_t *f, H5O_t *oh, unsigned chunkno, size_t size); static unsigned H5O_alloc_new_chunk(H5F_t *f, H5O_t *oh, size_t size); static herr_t H5O_delete_oh(H5F_t *f, hid_t dxpl_id, H5O_t *oh); -static herr_t H5O_delete_mesg(H5F_t *f, hid_t dxpl_id, H5O_mesg_t *mesg); +static herr_t H5O_delete_mesg(H5F_t *f, hid_t dxpl_id, H5O_mesg_t *mesg, + hbool_t adj_link); static unsigned H5O_new_mesg(H5F_t *f, H5O_t *oh, unsigned *flags, const H5O_class_t *orig_type, const void *orig_mesg, H5O_shared_t *sh_mesg, const H5O_class_t **new_type, const void **new_mesg, hid_t dxpl_id, @@ -84,6 +103,8 @@ static unsigned H5O_new_mesg(H5F_t *f, H5O_t *oh, unsigned *flags, static herr_t H5O_write_mesg(H5O_t *oh, unsigned idx, const H5O_class_t *type, const void *mesg, unsigned flags, unsigned update_flags, unsigned * oh_flags_ptr); +static herr_t H5O_iterate_real(const H5G_entry_t *ent, const H5O_class_t *type, + H5AC_protect_t prot, hbool_t internal, void *op, void *op_data, hid_t dxpl_id); /* Metadata cache callbacks */ static H5O_t *H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_udata1, @@ -846,10 +867,7 @@ H5O_dest(H5F_t UNUSED *f, H5O_t *oh) /* Verify that message is clean */ assert (oh->mesg[i].dirty==0); - if (oh->mesg[i].flags & H5O_FLAG_SHARED) - H5O_free_real(H5O_SHARED, oh->mesg[i].native); - else - H5O_free_real(oh->mesg[i].type, oh->mesg[i].native); + H5O_free_mesg(&oh->mesg[i]); } if(oh->mesg) oh->mesg = H5FL_SEQ_FREE(H5O_mesg_t,oh->mesg); @@ -1078,6 +1096,36 @@ done: /*------------------------------------------------------------------------- + * Function: H5O_free_mesg + * + * Purpose: Call H5O_free_real() on a message. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Tuesday, Sep 6, 2005 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5O_free_mesg(H5O_mesg_t *mesg) +{ + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_free_mesg) + + /* check args */ + HDassert(mesg); + + /* Free any native information */ + if(mesg->flags & H5O_FLAG_SHARED) + mesg->native = H5O_free_real(H5O_SHARED, mesg->native); + else + mesg->native = H5O_free_real(mesg->type, mesg->native); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5O_free_mesg() */ + + +/*------------------------------------------------------------------------- * Function: H5O_free_real * * Purpose: Similar to H5O_reset() except it also frees the message @@ -1095,24 +1143,22 @@ done: *------------------------------------------------------------------------- */ void * -H5O_free_real(const H5O_class_t *type, void *mesg) +H5O_free_real(const H5O_class_t *type, void *msg_native) { - void * ret_value=NULL; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_free_real); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_free_real) /* check args */ assert(type); - if (mesg) { - H5O_reset_real(type, mesg); + if (msg_native) { + H5O_reset_real(type, msg_native); if (NULL!=(type->free)) - (type->free)(mesg); + (type->free)(msg_native); else - H5MM_xfree (mesg); + H5MM_xfree (msg_native); } - FUNC_LEAVE_NOAPI(ret_value); + FUNC_LEAVE_NOAPI(NULL) } /* end H5O_free_real() */ @@ -1872,7 +1918,7 @@ H5O_modify_real(H5G_entry_t *ent, const H5O_class_t *type, int overwrite, H5O_shared_t sh_mesg; int ret_value; - FUNC_ENTER_NOAPI(H5O_modify_real, FAIL); + FUNC_ENTER_NOAPI_NOINIT(H5O_modify_real) /* check args */ assert(ent); @@ -2555,31 +2601,154 @@ done: *------------------------------------------------------------------------- */ herr_t -H5O_remove(H5G_entry_t *ent, unsigned type_id, int sequence, hid_t dxpl_id) +H5O_remove(H5G_entry_t *ent, unsigned type_id, int sequence, hbool_t adj_link, hid_t dxpl_id) { const H5O_class_t *type; /* Actual H5O class type for the ID */ herr_t ret_value; /* Return value */ - FUNC_ENTER_NOAPI(H5O_remove, FAIL); + FUNC_ENTER_NOAPI(H5O_remove, FAIL) /* check args */ - assert(ent); - assert(ent->file); - assert(H5F_addr_defined(ent->header)); - assert(type_id<NELMTS(message_type_g)); - type=message_type_g[type_id]; /* map the type ID to the actual type object */ - assert(type); + HDassert(ent); + HDassert(ent->file); + HDassert(H5F_addr_defined(ent->header)); + HDassert(type_id < NELMTS(message_type_g)); + type = message_type_g[type_id]; /* map the type ID to the actual type object */ + HDassert(type); /* Call the "real" remove routine */ - if((ret_value=H5O_remove_real(ent, type, sequence, dxpl_id))<0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "unable to remove object header message"); + if((ret_value = H5O_remove_real(ent, type, sequence, NULL, NULL, adj_link, dxpl_id))<0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "unable to remove object header message") done: - FUNC_LEAVE_NOAPI(ret_value); + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_remove() */ /*------------------------------------------------------------------------- + * Function: H5O_remove_op + * + * Purpose: Removes messages from the object header that a callback + * routine indicates should be removed. + * + * No attempt is made to join adjacent free areas of the + * object header into a single larger free area. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Sep 6 2005 + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_remove_op(H5G_entry_t *ent, unsigned type_id, + H5O_operator_t op, void *op_data, hbool_t adj_link, hid_t dxpl_id) +{ + const H5O_class_t *type; /* Actual H5O class type for the ID */ + herr_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_remove_op, FAIL) + + /* check args */ + HDassert(ent); + HDassert(ent->file); + HDassert(H5F_addr_defined(ent->header)); + HDassert(type_id < NELMTS(message_type_g)); + type = message_type_g[type_id]; /* map the type ID to the actual type object */ + HDassert(type); + + /* Call the "real" remove routine */ + if((ret_value = H5O_remove_real(ent, type, H5O_ALL, op, op_data, adj_link, dxpl_id))<0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "unable to remove object header message") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_remove_op() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_remove_cb + * + * Purpose: Object header iterator callback routine to remove messages + * of a particular type that match a particular sequence number, + * or all messages if the sequence number is H5O_ALL (-1). + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Sep 6 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +H5O_remove_cb(H5O_mesg_t *mesg/*in,out*/, unsigned idx, unsigned * oh_flags_ptr, + void *_udata/*in,out*/) +{ + H5O_iter_ud1_t *udata = (H5O_iter_ud1_t *)_udata; /* Operator user data */ + htri_t try_remove = FALSE; /* Whether to try removing a message */ + herr_t ret_value = H5O_ITER_CONT; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5O_remove_cb) + + /* check args */ + HDassert(mesg); + + /* Check for callback routine */ + if(udata->op) { + /* Call the iterator callback */ + if((try_remove = (udata->op)(mesg->native, idx, udata->op_data)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, H5O_ITER_ERROR, "unable to delete file space for object header message") + } /* end if */ + else { + /* If there's no callback routine, does the sequence # match? */ + if ((int)idx == udata->sequence || H5O_ALL == udata->sequence) + try_remove = TRUE; + } /* end else */ + + /* Try removing the message, if indicated */ + if(try_remove) { + /* + * Keep track of how many times we failed trying to remove constant + * messages. + */ + if (mesg->flags & H5O_FLAG_CONSTANT) { + udata->nfailed++; + } /* end if */ + else { + /* Free any space referred to in the file from this message */ + if(H5O_delete_mesg(udata->f, udata->dxpl_id, mesg, udata->adj_link)<0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, H5O_ITER_ERROR, "unable to delete file space for object header message") + + /* Free any native information */ + H5O_free_mesg(mesg); + + /* Change message type to nil and zero it */ + mesg->type = H5O_NULL; + HDmemset(mesg->raw, 0, mesg->raw_size); + + /* Indicate that the message was modified */ + mesg->dirty = TRUE; + + /* Indicate that the object header was modified */ + *oh_flags_ptr |= H5AC__DIRTIED_FLAG; + } /* end else */ + + /* Break out now, if we've found the correct message */ + if(udata->sequence != H5O_ALL) + HGOTO_DONE(H5O_ITER_STOP) + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_remove_cb() */ + + +/*------------------------------------------------------------------------- * Function: H5O_remove_real * * Purpose: Removes the specified message from the object header. @@ -2609,70 +2778,41 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_remove_real(H5G_entry_t *ent, const H5O_class_t *type, int sequence, hid_t dxpl_id) +H5O_remove_real(H5G_entry_t *ent, const H5O_class_t *type, int sequence, + H5O_operator_t op, void *op_data, hbool_t adj_link, hid_t dxpl_id) { - H5O_t *oh = NULL; - unsigned oh_flags = H5AC__NO_FLAGS_SET; - H5O_mesg_t *curr_msg; /* Pointer to current message being operated on */ - int seq, nfailed = 0; - unsigned u; - herr_t ret_value=SUCCEED; /* Return value */ + H5O_iter_ud1_t udata; /* User data for iterator */ + herr_t ret_value=SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5O_remove_real); + FUNC_ENTER_NOAPI_NOINIT(H5O_remove_real) /* check args */ - assert(ent); - assert(ent->file); - assert(H5F_addr_defined(ent->header)); - assert(type); + HDassert(ent); + HDassert(ent->file); + HDassert(type); if (0==(ent->file->intent & H5F_ACC_RDWR)) - HGOTO_ERROR (H5E_HEAP, H5E_WRITEERROR, FAIL, "no write intent on file"); - - /* load the object header */ - if (NULL == (oh = H5AC_protect(ent->file, dxpl_id, H5AC_OHDR, ent->header, NULL, NULL, H5AC_WRITE))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header"); + HGOTO_ERROR (H5E_HEAP, H5E_WRITEERROR, FAIL, "no write intent on file") - for (u = seq = 0, curr_msg=&oh->mesg[0]; u < oh->nmesgs; u++,curr_msg++) { - if (type->id != curr_msg->type->id) - continue; - if (seq++ == sequence || H5O_ALL == sequence) { - - /* - * Keep track of how many times we failed trying to remove constant - * messages. - */ - if (curr_msg->flags & H5O_FLAG_CONSTANT) { - nfailed++; - continue; - } /* end if */ + /* Set up iterator operator data */ + udata.f = ent->file; + udata.dxpl_id = dxpl_id; + udata.sequence = sequence; + udata.nfailed = 0; + udata.op = op; + udata.op_data = op_data; + udata.adj_link = adj_link; - /* Free any space referred to in the file from this message */ - if(H5O_delete_mesg(ent->file,dxpl_id,curr_msg)<0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "unable to delete file space for object header message"); - - /* change message type to nil and zero it */ - curr_msg->type = H5O_NULL; - HDmemset(curr_msg->raw, 0, curr_msg->raw_size); - if(curr_msg->flags & H5O_FLAG_SHARED) - curr_msg->native = H5O_free_real(H5O_SHARED, curr_msg->native); - else - curr_msg->native = H5O_free_real(type, curr_msg->native); - curr_msg->dirty = TRUE; - oh_flags |= H5AC__DIRTIED_FLAG; - H5O_touch_oh(ent->file, oh, FALSE, &oh_flags); - } - } + /* Iterate over the messages, deleting appropriate one(s) */ + if(H5O_iterate_real(ent, type, H5AC_WRITE, TRUE, (void *)H5O_remove_cb, &udata, dxpl_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "error iterating over messages") /* Fail if we tried to remove any constant messages */ - if (nfailed) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to remove constant message(s)"); + if (udata.nfailed) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to remove constant message(s)") done: - if (oh && H5AC_unprotect(ent->file, dxpl_id, H5AC_OHDR, ent->header, oh, oh_flags) < 0) - HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header"); - - FUNC_LEAVE_NOAPI(ret_value); + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_remove_real() */ @@ -3231,26 +3371,71 @@ H5O_raw_size(unsigned type_id, const H5F_t *f, const void *mesg) const H5O_class_t *type; /* Actual H5O class type for the ID */ size_t ret_value; /* Return value */ - FUNC_ENTER_NOAPI(H5O_raw_size,0); + FUNC_ENTER_NOAPI(H5O_raw_size,0) /* Check args */ - assert(type_id<NELMTS(message_type_g)); + HDassert(type_id<NELMTS(message_type_g)); type=message_type_g[type_id]; /* map the type ID to the actual type object */ - assert (type); - assert (type->raw_size); - assert (f); - assert (mesg); + HDassert(type); + HDassert(type->raw_size); + HDassert(f); + HDassert(mesg); /* Compute the raw data size for the mesg */ if ((ret_value = (type->raw_size)(f, mesg))==0) - HGOTO_ERROR (H5E_OHDR, H5E_CANTCOUNT, 0, "unable to determine size of message"); + HGOTO_ERROR (H5E_OHDR, H5E_CANTCOUNT, 0, "unable to determine size of message") done: - FUNC_LEAVE_NOAPI(ret_value); + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_raw_size() */ /*------------------------------------------------------------------------- + * Function: H5O_mesg_size + * + * Purpose: Calculate the final size of an encoded message in an object + * header. + * + * Return: Size of message on success, 0 on failure + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Sep 6 2005 + * + *------------------------------------------------------------------------- + */ +size_t +H5O_mesg_size(unsigned type_id, const H5F_t *f, const void *mesg) +{ + const H5O_class_t *type; /* Actual H5O class type for the ID */ + size_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_mesg_size,0) + + /* Check args */ + HDassert(type_id<NELMTS(message_type_g)); + type=message_type_g[type_id]; /* map the type ID to the actual type object */ + HDassert(type); + HDassert(type->raw_size); + HDassert(f); + HDassert(mesg); + + /* Compute the raw data size for the mesg */ + if((ret_value = (type->raw_size)(f, mesg)) == 0) + HGOTO_ERROR (H5E_OHDR, H5E_CANTCOUNT, 0, "unable to determine size of message") + + /* Adjust size for alignment, if necessary */ + ret_value = H5O_ALIGN(ret_value); + + /* Add space for message header */ + ret_value += H5O_SIZEOF_MSGHDR(f); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_mesg_size() */ + + +/*------------------------------------------------------------------------- * Function: H5O_get_share * * Purpose: Call the 'get_share' method for a @@ -3380,7 +3565,7 @@ H5O_delete_oh(H5F_t *f, hid_t dxpl_id, H5O_t *oh) */ for (u = 0, curr_msg=&oh->mesg[0]; u < oh->nmesgs; u++,curr_msg++) { /* Free any space referred to in the file from this message */ - if(H5O_delete_mesg(f,dxpl_id,curr_msg)<0) + if(H5O_delete_mesg(f, dxpl_id, curr_msg, TRUE)<0) HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "unable to delete file space for object header message"); } /* end for */ @@ -3426,7 +3611,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_delete_mesg(H5F_t *f, hid_t dxpl_id, H5O_mesg_t *mesg) +H5O_delete_mesg(H5F_t *f, hid_t dxpl_id, H5O_mesg_t *mesg, hbool_t adj_link) { const H5O_class_t *type; /* Type of object to free */ herr_t ret_value=SUCCEED; /* Return value */ @@ -3455,7 +3640,7 @@ H5O_delete_mesg(H5F_t *f, hid_t dxpl_id, H5O_mesg_t *mesg) HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, FAIL, "unable to decode message"); } /* end if */ - if ((type->del)(f, dxpl_id, mesg->native)<0) + if ((type->del)(f, dxpl_id, mesg->native, adj_link)<0) HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "unable to delete file space for object header message"); } /* end if */ @@ -3650,29 +3835,87 @@ herr_t H5O_iterate(const H5G_entry_t *ent, unsigned type_id, H5O_operator_t op, void *op_data, hid_t dxpl_id) { - H5O_t *oh=NULL; /* Pointer to actual object header */ const H5O_class_t *type; /* Actual H5O class type for the ID */ + herr_t ret_value=0; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_iterate, FAIL) + + /* check args */ + HDassert(ent); + HDassert(ent->file); + HDassert(H5F_addr_defined(ent->header)); + HDassert(type_id<NELMTS(message_type_g)); + type=message_type_g[type_id]; /* map the type ID to the actual type object */ + HDassert(type); + + /* Call the "real" iterate routine */ + if((ret_value=H5O_iterate_real(ent, type, H5AC_READ, FALSE, (void *)op, op_data, dxpl_id))<0) + HGOTO_ERROR(H5E_OHDR, H5E_BADITER, FAIL, "unable to iterate over object header messages") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_iterate() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_iterate_real + * + * Purpose: Iterate through object headers of a certain type. + * + * Return: Returns a negative value if something is wrong, the return + * value of the last operator if it was non-zero, or zero if all + * object headers were processed. + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Sep 6 2005 + * + * Description: + * This function interates over the object headers of an object + * specified with 'ent' of type 'type_id'. For each object header of the + * object, the 'op_data' and some additional information (specified below) are + * passed to the 'op' function. + * The operation receives a pointer to the object header message for the + * object being iterated over ('mesg'), and the pointer to the operator data + * passed in to H5O_iterate ('op_data'). The return values from an operator + * are: + * A. Zero causes the iterator to continue, returning zero when all + * object headers of that type have been processed. + * B. Positive causes the iterator to immediately return that positive + * value, indicating short-circuit success. + * C. Negative causes the iterator to immediately return that value, + * indicating failure. + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +H5O_iterate_real(const H5G_entry_t *ent, const H5O_class_t *type, H5AC_protect_t prot, + hbool_t internal, void *op, void *op_data, hid_t dxpl_id) +{ + H5O_t *oh=NULL; /* Pointer to actual object header */ + unsigned oh_flags = H5AC__NO_FLAGS_SET; /* Start iteration with no flags set on object header */ unsigned idx; /* Absolute index of current message in all messages */ unsigned sequence; /* Relative index of current message for messages of type */ H5O_mesg_t *idx_msg; /* Pointer to current message */ herr_t ret_value=0; /* Return value */ - FUNC_ENTER_NOAPI(H5O_iterate, FAIL); + FUNC_ENTER_NOAPI_NOINIT(H5O_iterate_real) /* check args */ - assert(ent); - assert(ent->file); - assert(H5F_addr_defined(ent->header)); - assert(type_id<NELMTS(message_type_g)); - type=message_type_g[type_id]; /* map the type ID to the actual type object */ - assert(type); + HDassert(ent); + HDassert(ent->file); + HDassert(H5F_addr_defined(ent->header)); + HDassert(type); + HDassert(op); /* Protect the object header to iterate over */ - if (NULL == (oh = H5AC_protect(ent->file, dxpl_id, H5AC_OHDR, ent->header, NULL, NULL, H5AC_READ))) + if (NULL == (oh = H5AC_protect(ent->file, dxpl_id, H5AC_OHDR, ent->header, NULL, NULL, prot))) HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header"); /* Iterate over messages */ - for (sequence=0, idx = 0, idx_msg=&oh->mesg[0]; idx < oh->nmesgs; idx++, idx_msg++) { + for (sequence = 0, idx = 0, idx_msg = &oh->mesg[0]; idx < oh->nmesgs; idx++, idx_msg++) { if (type->id == idx_msg->type->id) { /* * Decode the message if necessary. If the message is shared then decode @@ -3687,26 +3930,41 @@ H5O_iterate(const H5G_entry_t *ent, unsigned type_id, H5O_operator_t op, decode_type = type; /* Decode the message if necessary */ - assert(decode_type->decode); + HDassert(decode_type->decode); if (NULL == (idx_msg->native = (decode_type->decode) (ent->file, dxpl_id, idx_msg->raw, NULL))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, FAIL, "unable to decode message"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, FAIL, "unable to decode message") } /* end if */ - /* Call the iterator callback */ - if((ret_value=(op)(idx_msg->native,sequence,op_data))!=0) - break; + /* Check for making an "internal" (i.e. within the H5O package) callback */ + if(internal) { + /* Call the "internal" iterator callback */ + if((ret_value = ((H5O_operator_int_t)op)(idx_msg, sequence, &oh_flags, op_data)) != 0) + break; + } /* end if */ + else { + /* Call the iterator callback */ + if((ret_value = ((H5O_operator_t)op)(idx_msg->native, sequence, op_data)) != 0) + break; + } /* end else */ /* Increment sequence value for message type */ sequence++; } /* end if */ } /* end for */ + /* Check if object header was modified */ + if(oh_flags & H5AC__DIRTIED_FLAG) { + /* Shouldn't be able to modify object header if we don't have write access */ + HDassert(prot == H5AC_WRITE); + H5O_touch_oh(ent->file, oh, FALSE, &oh_flags); + } /* end if */ + done: - if (oh && H5AC_unprotect(ent->file, dxpl_id, H5AC_OHDR, ent->header, oh, H5AC__NO_FLAGS_SET) < 0) - HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header"); + if (oh && H5AC_unprotect(ent->file, dxpl_id, H5AC_OHDR, ent->header, oh, oh_flags) < 0) + HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") - FUNC_LEAVE_NOAPI(ret_value); -} /* end H5O_iterate() */ + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_iterate_real() */ /*------------------------------------------------------------------------- @@ -3914,6 +4172,7 @@ H5O_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int f if (oh->mesg[i].flags & H5O_FLAG_SHARED) { H5O_shared_t *shared = (H5O_shared_t*)(oh->mesg[i].native); void *mesg = NULL; + if (shared->in_gh) { void *p = H5HG_read (f, dxpl_id, oh->mesg[i].native, NULL); mesg = (oh->mesg[i].type->decode)(f, dxpl_id, p, oh->mesg[i].native); diff --git a/src/H5Oattr.c b/src/H5Oattr.c index d0ed251..abff4f3 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -33,7 +33,7 @@ static void *H5O_attr_copy (const void *_mesg, void *_dest, unsigned update_flag static size_t H5O_attr_size (const H5F_t *f, const void *_mesg); static herr_t H5O_attr_reset (void *_mesg); static herr_t H5O_attr_free (void *mesg); -static herr_t H5O_attr_delete (H5F_t *f, hid_t dxpl_id, const void *_mesg); +static herr_t H5O_attr_delete (H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link); static herr_t H5O_attr_link(H5F_t *f, hid_t dxpl_id, const void *_mesg); static herr_t H5O_attr_debug (H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int indent, int fwidth); @@ -532,7 +532,7 @@ H5O_attr_free (void *mesg) *------------------------------------------------------------------------- */ static herr_t -H5O_attr_delete(H5F_t UNUSED *f, hid_t dxpl_id, const void *_mesg) +H5O_attr_delete(H5F_t UNUSED *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link) { const H5A_t *attr = (const H5A_t *) _mesg; herr_t ret_value=SUCCEED; /* Return value */ @@ -545,9 +545,10 @@ H5O_attr_delete(H5F_t UNUSED *f, hid_t dxpl_id, const void *_mesg) /* Check whether datatype is shared */ if(H5T_committed(attr->dt)) { - /* Decrement the reference count on the shared datatype */ - if(H5T_link(attr->dt,-1,dxpl_id)<0) - HGOTO_ERROR (H5E_OHDR, H5E_LINK, FAIL, "unable to adjust shared datatype link count"); + /* Decrement the reference count on the shared datatype, if requested */ + if(adj_link) + if(H5T_link(attr->dt, -1, dxpl_id)<0) + HGOTO_ERROR (H5E_OHDR, H5E_LINK, FAIL, "unable to adjust shared datatype link count") } /* end if */ done: diff --git a/src/H5Ocont.c b/src/H5Ocont.c index b28186c..e62ca07 100644 --- a/src/H5Ocont.c +++ b/src/H5Ocont.c @@ -40,7 +40,8 @@ /* PRIVATE PROTOTYPES */ static void *H5O_cont_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p, H5O_shared_t *sh); static herr_t H5O_cont_encode(H5F_t *f, uint8_t *p, const void *_mesg); -static herr_t H5O_cont_free (void *mesg); +static size_t H5O_cont_size(const H5F_t *f, const void *_mesg); +static herr_t H5O_cont_free(void *mesg); static herr_t H5O_cont_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int indent, int fwidth); @@ -52,7 +53,7 @@ const H5O_class_t H5O_CONT[1] = {{ H5O_cont_decode, /*decode message */ H5O_cont_encode, /*encode message */ NULL, /*no copy method */ - NULL, /*no size method */ + H5O_cont_size, /*size of header continuation */ NULL, /*reset method */ H5O_cont_free, /* free method */ NULL, /* file delete method */ @@ -147,6 +148,40 @@ H5O_cont_encode(H5F_t *f, uint8_t *p, const void *_mesg) /*------------------------------------------------------------------------- + * Function: H5O_cont_size + * + * Purpose: Returns the size of the raw message in bytes not counting + * the message type or size fields, but only the data fields. + * This function doesn't take into account alignment. + * + * Return: Success: Message data size in bytes without alignment. + * + * Failure: zero + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Sep 6 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static size_t +H5O_cont_size(const H5F_t *f, const void UNUSED *_mesg) +{ + size_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_cont_size) + + /* Set return value */ + ret_value = H5F_SIZEOF_ADDR(f) + /* Continuation header address */ + H5F_SIZEOF_SIZE(f); /* Continuation header length */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_cont_size() */ + + +/*------------------------------------------------------------------------- * Function: H5O_cont_free * * Purpose: Free's the message diff --git a/src/H5Odtype.c b/src/H5Odtype.c index 7a7972b..0eed438 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -73,7 +73,7 @@ H5FL_EXTERN(H5T_shared_t); /*------------------------------------------------------------------------- * Function: H5O_dtype_decode_helper * - * Purpose: Decodes a data type + * Purpose: Decodes a datatype * * Return: Non-negative on success/Negative on failure * @@ -82,7 +82,7 @@ H5FL_EXTERN(H5T_shared_t); * * Modifications: * Robb Matzke, Thursday, May 20, 1999 - * Added support for bitfields and opaque data types. + * Added support for bitfields and opaque datatypes. *------------------------------------------------------------------------- */ static herr_t @@ -103,7 +103,7 @@ H5O_dtype_decode_helper(H5F_t *f, const uint8_t **pp, H5T_t *dt) UINT32DECODE(*pp, flags); version = (flags>>4) & 0x0f; if (version!=H5O_DTYPE_VERSION_COMPAT && version!=H5O_DTYPE_VERSION_UPDATED) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTLOAD, FAIL, "bad version number for data type message"); + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTLOAD, FAIL, "bad version number for datatype message"); dt->shared->type = (H5T_class_t)(flags & 0x0f); flags >>= 8; UINT32DECODE(*pp, dt->shared->size); @@ -180,7 +180,7 @@ H5O_dtype_decode_helper(H5F_t *f, const uint8_t **pp, H5T_t *dt) case H5T_COMPOUND: /* - * Compound data types... + * Compound datatypes... */ dt->shared->u.compnd.nmembs = flags & 0xffff; assert(dt->shared->u.compnd.nmembs > 0); @@ -227,13 +227,8 @@ H5O_dtype_decode_helper(H5F_t *f, const uint8_t **pp, H5T_t *dt) } /* end if */ /* Allocate space for the field's datatype */ - if(NULL== (temp_type = H5FL_CALLOC (H5T_t))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); - if(NULL== (temp_type->shared = H5FL_CALLOC (H5T_shared_t))) { - H5FL_FREE(H5T_t, temp_type); - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); - } - temp_type->ent.header = HADDR_UNDEF; + if(NULL == (temp_type = H5T_alloc())) + HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Decode the field's datatype information */ if (H5O_dtype_decode_helper(f, pp, temp_type)<0) { @@ -307,18 +302,13 @@ H5O_dtype_decode_helper(H5F_t *f, const uint8_t **pp, H5T_t *dt) case H5T_ENUM: /* - * Enumeration data types... + * Enumeration datatypes... */ dt->shared->u.enumer.nmembs = dt->shared->u.enumer.nalloc = flags & 0xffff; - if (NULL==(dt->shared->parent=H5FL_CALLOC(H5T_t))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); - if(NULL== (dt->shared->parent->shared= H5FL_CALLOC (H5T_shared_t))) { - H5FL_FREE(H5T_t, dt->shared->parent); - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); - } - dt->shared->parent->ent.header = HADDR_UNDEF; + if(NULL == (dt->shared->parent = H5T_alloc())) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") if (H5O_dtype_decode_helper(f, pp, dt->shared->parent)<0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "unable to decode parent data type"); + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "unable to decode parent datatype"); if (NULL==(dt->shared->u.enumer.name=H5MM_calloc(dt->shared->u.enumer.nalloc * sizeof(char*))) || NULL==(dt->shared->u.enumer.value=H5MM_calloc(dt->shared->u.enumer.nalloc * dt->shared->parent->shared->size))) @@ -336,7 +326,7 @@ H5O_dtype_decode_helper(H5F_t *f, const uint8_t **pp, H5T_t *dt) *pp += dt->shared->u.enumer.nmembs * dt->shared->parent->shared->size; break; - case H5T_REFERENCE: /* Reference data types... */ + case H5T_REFERENCE: /* Reference datatypes... */ dt->shared->u.atomic.order = H5T_ORDER_NONE; dt->shared->u.atomic.prec = 8 * dt->shared->size; dt->shared->u.atomic.offset = 0; @@ -379,14 +369,8 @@ H5O_dtype_decode_helper(H5F_t *f, const uint8_t **pp, H5T_t *dt) } /* end if */ /* Decode base type of VL information */ - if (NULL==(dt->shared->parent = H5FL_CALLOC(H5T_t))) - HGOTO_ERROR (H5E_DATATYPE, H5E_NOSPACE, FAIL, "memory allocation failed"); - if (NULL==(dt->shared->parent->shared = H5FL_CALLOC(H5T_shared_t))) - { - H5FL_FREE(H5T_t, dt->shared->parent); - HGOTO_ERROR (H5E_DATATYPE, H5E_NOSPACE, FAIL, "memory allocation failed"); - } - dt->shared->parent->ent.header = HADDR_UNDEF; + if(NULL == (dt->shared->parent = H5T_alloc())) + HGOTO_ERROR (H5E_DATATYPE, H5E_NOSPACE, FAIL, "memory allocation failed") if (H5O_dtype_decode_helper(f, pp, dt->shared->parent)<0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "unable to decode VL parent type"); @@ -422,13 +406,8 @@ H5O_dtype_decode_helper(H5F_t *f, const uint8_t **pp, H5T_t *dt) UINT32DECODE(*pp, dt->shared->u.array.perm[j]); /* Decode base type of array */ - if (NULL==(dt->shared->parent = H5FL_CALLOC(H5T_t))) - HGOTO_ERROR (H5E_DATATYPE, H5E_NOSPACE, FAIL, "memory allocation failed"); - if(NULL== (dt->shared->parent->shared = H5FL_CALLOC (H5T_shared_t))) { - H5FL_FREE(H5T_t, dt->shared->parent); - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); - } - dt->shared->parent->ent.header = HADDR_UNDEF; + if(NULL == (dt->shared->parent = H5T_alloc())) + HGOTO_ERROR (H5E_DATATYPE, H5E_NOSPACE, FAIL, "memory allocation failed") if (H5O_dtype_decode_helper(f, pp, dt->shared->parent)<0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "unable to decode VL parent type"); @@ -447,10 +426,11 @@ H5O_dtype_decode_helper(H5F_t *f, const uint8_t **pp, H5T_t *dt) done: if(ret_value <0) { - if(dt->shared != NULL) - H5FL_FREE(H5T_shared_t, dt->shared); - if(dt != NULL) + if(dt != NULL) { + if(dt->shared != NULL) + H5FL_FREE(H5T_shared_t, dt->shared); H5FL_FREE(H5T_t, dt); + } /* end if */ } FUNC_LEAVE_NOAPI(ret_value); } @@ -459,7 +439,7 @@ done: /*------------------------------------------------------------------------- * Function: H5O_dtype_encode_helper * - * Purpose: Encodes a data type. + * Purpose: Encodes a datatype. * * Return: Non-negative on success/Negative on failure * @@ -494,7 +474,7 @@ H5O_dtype_encode_helper(uint8_t **pp, const H5T_t *dt) switch (dt->shared->type) { case H5T_INTEGER: /* - * Integer data types... + * Integer datatypes... */ switch (dt->shared->u.atomic.order) { case H5T_ORDER_LE: @@ -542,7 +522,7 @@ H5O_dtype_encode_helper(uint8_t **pp, const H5T_t *dt) case H5T_BITFIELD: /* - * Bitfield data types... + * Bitfield datatypes... */ switch (dt->shared->u.atomic.order) { case H5T_ORDER_LE: @@ -580,7 +560,7 @@ H5O_dtype_encode_helper(uint8_t **pp, const H5T_t *dt) case H5T_OPAQUE: /* - * Opaque data types... The tag is stored in a field which is a + * Opaque datatypes... The tag is stored in a field which is a * multiple of eight characters and null padded (not necessarily * null terminated). */ @@ -669,7 +649,7 @@ H5O_dtype_encode_helper(uint8_t **pp, const H5T_t *dt) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't detect array class"); /* - * Compound data types... + * Compound datatypes... */ flags = dt->shared->u.compnd.nmembs & 0xffff; for (i=0; i<dt->shared->u.compnd.nmembs; i++) { @@ -716,13 +696,13 @@ H5O_dtype_encode_helper(uint8_t **pp, const H5T_t *dt) case H5T_ENUM: /* - * Enumeration data types... + * Enumeration datatypes... */ flags = dt->shared->u.enumer.nmembs & 0xffff; /* Parent type */ if (H5O_dtype_encode_helper(pp, dt->shared->parent)<0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "unable to encode parent data type"); + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "unable to encode parent datatype"); /* Names, each a multiple of eight bytes */ for (i=0; i<dt->shared->u.enumer.nmembs; i++) { @@ -826,7 +806,7 @@ done: NAME H5O_dtype_decode PURPOSE - Decode a datatype message and return a pointer to a memory struct + Decode a message and return a pointer to a memory struct with the decoded information USAGE void *H5O_dtype_decode(f, raw_size, p) @@ -852,11 +832,8 @@ H5O_dtype_decode(H5F_t *f, hid_t UNUSED dxpl_id, const uint8_t *p, /* check args */ assert(p); - if (NULL==(dt = H5FL_CALLOC(H5T_t))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - if (NULL==(dt->shared=H5FL_CALLOC(H5T_shared_t))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - dt->ent.header = HADDR_UNDEF; + if(NULL == (dt = H5T_alloc())) + HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") if (H5O_dtype_decode_helper(f, &p, dt) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, "can't decode type"); @@ -866,10 +843,11 @@ H5O_dtype_decode(H5F_t *f, hid_t UNUSED dxpl_id, const uint8_t *p, done: if(ret_value==NULL) { - if(dt->shared!=NULL) - H5FL_FREE(H5T_shared_t, dt->shared); - if(dt!=NULL) - H5FL_FREE(H5T_t,dt); + if(dt != NULL) { + if(dt->shared != NULL) + H5FL_FREE(H5T_shared_t, dt->shared); + H5FL_FREE(H5T_t, dt); + } /* end if */ } /* end if */ FUNC_LEAVE_NOAPI(ret_value); @@ -1058,7 +1036,7 @@ H5O_dtype_size(const H5F_t *f, const void *mesg) /*------------------------------------------------------------------------- * Function: H5O_dtype_reset * - * Purpose: Frees resources within a data type message, but doesn't free + * Purpose: Frees resources within a message, but doesn't free * the message itself. * * Return: Non-negative on success/Negative on failure @@ -1146,7 +1124,7 @@ H5O_dtype_get_share(H5F_t UNUSED *f, const void *_mesg, sh->in_gh = FALSE; sh->u.ent = dt->ent; } else - HGOTO_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, "data type is not sharable"); + HGOTO_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype is not sharable"); done: FUNC_LEAVE_NOAPI(ret_value); @@ -1196,7 +1174,7 @@ H5O_dtype_set_share (H5F_t UNUSED *f, void *_mesg/*in,out*/, NAME H5O_dtype_debug PURPOSE - Prints debugging information for a data type message + Prints debugging information for a message USAGE void *H5O_dtype_debug(f, mesg, stream, indent, fwidth) H5F_t *f; IN: pointer to the HDF5 file struct diff --git a/src/H5Olayout.c b/src/H5Olayout.c index b488e57..4a6fdfe 100644 --- a/src/H5Olayout.c +++ b/src/H5Olayout.c @@ -34,9 +34,9 @@ static void *H5O_layout_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p, H5O_sh static herr_t H5O_layout_encode(H5F_t *f, uint8_t *p, const void *_mesg); static void *H5O_layout_copy(const void *_mesg, void *_dest, unsigned update_flags); static size_t H5O_layout_size(const H5F_t *f, const void *_mesg); -static herr_t H5O_layout_reset (void *_mesg); -static herr_t H5O_layout_free (void *_mesg); -static herr_t H5O_layout_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg); +static herr_t H5O_layout_reset(void *_mesg); +static herr_t H5O_layout_free(void *_mesg); +static herr_t H5O_layout_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link); static herr_t H5O_layout_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int indent, int fwidth); @@ -560,7 +560,7 @@ H5O_layout_free (void *_mesg) *------------------------------------------------------------------------- */ static herr_t -H5O_layout_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg) +H5O_layout_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t UNUSED adj_link) { const H5O_layout_t *mesg = (const H5O_layout_t *) _mesg; herr_t ret_value=SUCCEED; /* Return value */ diff --git a/src/H5Omtime.c b/src/H5Omtime.c index c113676..d3c2f3c 100644 --- a/src/H5Omtime.c +++ b/src/H5Omtime.c @@ -114,9 +114,8 @@ static void * H5O_mtime_new_decode(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const uint8_t *p, H5O_shared_t UNUSED *sh) { - time_t *mesg, the_time; + time_t *mesg; uint32_t tmp_time; /* Temporary copy of the time */ - int version; /* Version of mtime information */ void *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_mtime_new_decode); @@ -127,8 +126,7 @@ H5O_mtime_new_decode(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const uint8_t *p, assert (!sh); /* decode */ - version = *p++; - if(version!=H5O_MTIME_VERSION) + if(*p++ != H5O_MTIME_VERSION) HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "bad version number for mtime message"); /* Skip reserved bytes */ @@ -136,12 +134,11 @@ H5O_mtime_new_decode(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const uint8_t *p, /* Get the time_t from the file */ UINT32DECODE(p, tmp_time); - the_time=(time_t)tmp_time; /* The return value */ if (NULL==(mesg = H5FL_MALLOC(time_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - *mesg = the_time; + *mesg = (time_t)tmp_time; /* Set return value */ ret_value=mesg; diff --git a/src/H5Opkg.h b/src/H5Opkg.h index df36d08..83889f6 100644 --- a/src/H5Opkg.h +++ b/src/H5Opkg.h @@ -33,7 +33,6 @@ /* Object header macros */ #define H5O_NMESGS 32 /*initial number of messages */ #define H5O_NCHUNKS 8 /*initial number of chunks */ -#define H5O_ALL (-1) /*delete all messages of type */ /* Version of object header structure */ #define H5O_VERSION 1 @@ -66,7 +65,7 @@ typedef struct H5O_class_t { size_t (*raw_size)(const H5F_t*, const void*);/*sizeof raw val */ herr_t (*reset)(void *); /*free nested data structs */ herr_t (*free)(void *); /*free main data struct */ - herr_t (*del)(H5F_t *, hid_t, const void *); /* Delete space in file referenced by this message */ + herr_t (*del)(H5F_t *, hid_t, const void *, hbool_t); /* Delete space in file referenced by this message */ herr_t (*link)(H5F_t *, hid_t, const void *); /* Increment any links in file reference by this message */ herr_t (*get_share)(H5F_t*, const void*, struct H5O_shared_t*); /* Get shared information */ herr_t (*set_share)(H5F_t*, void*, const struct H5O_shared_t*); /* Set shared information */ diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index 2e0d21f..1e3d3fc 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -43,6 +43,7 @@ #define H5O_MIN_SIZE H5O_ALIGN(32) /*min obj header data size */ #define H5O_MAX_SIZE 65536 /*max obj header data size */ #define H5O_NEW_MESG (-1) /*new message */ +#define H5O_ALL (-1) /* Operate on all messages of type */ /* Flags which are part of a message */ #define H5O_FLAG_CONSTANT 0x01u @@ -224,6 +225,14 @@ typedef struct H5O_stab_t { haddr_t heap_addr; /*address of name heap */ } H5O_stab_t; +/* Define return values from operator callback function for H5O_iterate */ +/* (Actually, any postive value will cause the iterator to stop and pass back + * that positive value to the function that called the iterator) + */ +#define H5O_ITER_ERROR (-1) +#define H5O_ITER_CONT (0) +#define H5O_ITER_STOP (1) + /* Typedef for iteration operations */ typedef herr_t (*H5O_operator_t)(const void *mesg/*in*/, unsigned idx, void *operator_data/*in,out*/); @@ -255,13 +264,16 @@ H5_DLL herr_t H5O_bogus_oh(H5F_t *f, struct H5O_t *oh, unsigned * oh_flags_ptr); #endif /* H5O_ENABLE_BOGUS */ H5_DLL herr_t H5O_remove(H5G_entry_t *ent, unsigned type_id, int sequence, - hid_t dxpl_id); + hbool_t adj_link, hid_t dxpl_id); +H5_DLL herr_t H5O_remove_op(H5G_entry_t *ent, unsigned type_id, + H5O_operator_t op, void *op_data, hbool_t adj_link, hid_t dxpl_id); H5_DLL herr_t H5O_reset(unsigned type_id, void *native); H5_DLL void *H5O_free(unsigned type_id, void *mesg); H5_DLL herr_t H5O_encode(H5F_t *f, unsigned char *buf, void *obj, unsigned type_id); H5_DLL void* H5O_decode(H5F_t *f, const unsigned char *buf, unsigned type_id); H5_DLL void *H5O_copy(unsigned type_id, const void *mesg, void *dst); H5_DLL size_t H5O_raw_size(unsigned type_id, const H5F_t *f, const void *mesg); +H5_DLL size_t H5O_mesg_size(unsigned type_id, const H5F_t *f, const void *mesg); H5_DLL herr_t H5O_get_share(unsigned type_id, H5F_t *f, const void *mesg, H5O_shared_t *share); H5_DLL herr_t H5O_delete(H5F_t *f, hid_t dxpl_id, haddr_t addr); H5_DLL herr_t H5O_get_info(H5G_entry_t *ent, H5O_stat_t *ostat, hid_t dxpl_id); diff --git a/src/H5Oshared.c b/src/H5Oshared.c index c898a10..8a0a291 100644 --- a/src/H5Oshared.c +++ b/src/H5Oshared.c @@ -40,7 +40,7 @@ static void *H5O_shared_decode (H5F_t*, hid_t dxpl_id, const uint8_t*, H5O_share static herr_t H5O_shared_encode (H5F_t*, uint8_t*, const void*); static void *H5O_shared_copy(const void *_mesg, void *_dest, unsigned update_flags); static size_t H5O_shared_size (const H5F_t*, const void *_mesg); -static herr_t H5O_shared_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg); +static herr_t H5O_shared_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link); static herr_t H5O_shared_link(H5F_t *f, hid_t dxpl_id, const void *_mesg); static herr_t H5O_shared_debug (H5F_t*, hid_t dxpl_id, const void*, FILE*, int, int); @@ -414,7 +414,7 @@ H5O_shared_size (const H5F_t *f, const void *_mesg) *------------------------------------------------------------------------- */ static herr_t -H5O_shared_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg) +H5O_shared_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link) { const H5O_shared_t *shared = (const H5O_shared_t *) _mesg; herr_t ret_value=SUCCEED; /* Return value */ @@ -425,9 +425,10 @@ H5O_shared_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg) assert(f); assert(shared); - /* Decrement the reference count on the shared object */ - if(H5O_shared_link_adj(f,dxpl_id,shared,-1)<0) - HGOTO_ERROR (H5E_OHDR, H5E_LINK, FAIL, "unable to adjust shared object link count"); + /* Decrement the reference count on the shared object, if requested */ + if(adj_link) + if(H5O_shared_link_adj(f, dxpl_id, shared, -1)<0) + HGOTO_ERROR (H5E_OHDR, H5E_LINK, FAIL, "unable to adjust shared object link count") done: FUNC_LEAVE_NOAPI(ret_value); diff --git a/src/H5Ostab.c b/src/H5Ostab.c index e5996c6..279b437 100644 --- a/src/H5Ostab.c +++ b/src/H5Ostab.c @@ -41,7 +41,7 @@ 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_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg); +static herr_t H5O_stab_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link); static herr_t H5O_stab_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int indent, int fwidth); @@ -317,12 +317,12 @@ H5O_stab_free (void *mesg) *------------------------------------------------------------------------- */ static herr_t -H5O_stab_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg) +H5O_stab_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link) { const H5O_stab_t *stab = (const H5O_stab_t *) _mesg; herr_t ret_value=SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5O_stab_delete); + FUNC_ENTER_NOAPI_NOINIT(H5O_stab_delete) /* check args */ assert(f); @@ -330,10 +330,10 @@ H5O_stab_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg) /* Free the file space for the symbol table */ if (H5G_stab_delete(f, dxpl_id, stab->btree_addr, stab->heap_addr)<0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "unable to free symbol table"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "unable to free symbol table") done: - FUNC_LEAVE_NOAPI(ret_value); + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_stab_delete() */ @@ -43,7 +43,7 @@ * H5P_init_interface() in this source file. */ hid_t H5P_CLS_NO_CLASS_g = FAIL; -hid_t H5P_CLS_OBJ_CLASS_g = FAIL; +hid_t H5P_CLS_OBJECT_CREATE_g = FAIL; hid_t H5P_CLS_FILE_CREATE_g = FAIL; hid_t H5P_CLS_FILE_ACCESS_g = FAIL; hid_t H5P_CLS_DATASET_CREATE_g = FAIL; @@ -225,11 +225,11 @@ static herr_t H5P_init_interface(void) { H5P_genclass_t *root_class; /* Pointer to root property list class created */ - H5P_genclass_t *obj_class; /* Pointer to object(dataset, group, or datatype) property list class created */ + H5P_genclass_t *ocrt_class; /* Pointer to object (dataset, group, or datatype) creation property list class created */ H5P_genclass_t *pclass; /* Pointer to property list class to create */ + unsigned intmd_group = H5G_CRT_INTERMEDIATE_GROUP_DEF; + size_t nprops; /* Number of properties */ herr_t ret_value = SUCCEED; - unsigned intmd_group = H5G_CRT_INTERMEDIATE_GROUP_DEF; - size_t nprops; /* Number of properties */ FUNC_ENTER_NOAPI_NOINIT(H5P_init_interface); @@ -256,25 +256,25 @@ H5P_init_interface(void) /* Create object property class */ /* Allocate the object class */ - assert(H5P_CLS_OBJ_CLASS_g==(-1)); - if (NULL==(obj_class = H5P_create_class (root_class,"object",1,NULL,NULL,NULL,NULL,NULL,NULL))) + assert(H5P_CLS_OBJECT_CREATE_g==(-1)); + if (NULL==(ocrt_class = H5P_create_class (root_class,"object create",1,NULL,NULL,NULL,NULL,NULL,NULL))) HGOTO_ERROR (H5E_PLIST, H5E_CANTINIT, FAIL, "class initialization failed"); /* Register the object class */ - if ((H5P_CLS_OBJ_CLASS_g = H5I_register (H5I_GENPROP_CLS, obj_class))<0) + if ((H5P_CLS_OBJECT_CREATE_g = H5I_register (H5I_GENPROP_CLS, ocrt_class))<0) HGOTO_ERROR (H5E_PLIST, H5E_CANTREGISTER, FAIL, "can't register property list class"); /* Get the number of properties in the object class */ - if(H5P_get_nprops_pclass(obj_class,&nprops,FALSE)<0) + if(H5P_get_nprops_pclass(ocrt_class,&nprops,FALSE)<0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "can't query number of properties") /* Assume that if there are properties in the class, they are the default ones */ if(nprops==0) { - /* register create intermediate groups */ - if(H5P_register(obj_class,H5G_CRT_INTERMEDIATE_GROUP_NAME,H5G_CRT_INTERMEDIATE_GROUP_SIZE, + /* Register create intermediate groups */ + if(H5P_register(ocrt_class,H5G_CRT_INTERMEDIATE_GROUP_NAME,H5G_CRT_INTERMEDIATE_GROUP_SIZE, &intmd_group,NULL,NULL,NULL,NULL,NULL,NULL,NULL)<0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - } + } /* end if */ /* Register the file creation and file access property classes */ @@ -300,7 +300,7 @@ H5P_init_interface(void) /* Allocate the dataset creation class */ assert(H5P_CLS_DATASET_CREATE_g==(-1)); - if (NULL==(pclass = H5P_create_class (obj_class,"dataset create",1,NULL,NULL,H5D_crt_copy,NULL,H5D_crt_close,NULL))) + if (NULL==(pclass = H5P_create_class (ocrt_class,"dataset create",1,NULL,NULL,H5D_crt_copy,NULL,H5D_crt_close,NULL))) HGOTO_ERROR (H5E_PLIST, H5E_CANTINIT, FAIL, "class initialization failed"); /* Register the dataset creation class */ @@ -335,11 +335,9 @@ H5P_init_interface(void) HGOTO_ERROR (H5E_PLIST, H5E_CANTREGISTER, FAIL, "can't register property list class"); - /* added by Peter Cao. To create missing groups. May 08, 2005 */ - /* Allocate the group creation class */ assert(H5P_CLS_GROUP_CREATE_g==(-1)); - if (NULL==(pclass = H5P_create_class (obj_class,"group create",1,NULL,NULL,NULL,NULL,NULL,NULL))) + if (NULL==(pclass = H5P_create_class (ocrt_class,"group create",1,NULL,NULL,NULL,NULL,NULL,NULL))) HGOTO_ERROR (H5E_PLIST, H5E_CANTINIT, FAIL, "class initialization failed"); /* Register the group creation class */ @@ -357,7 +355,7 @@ H5P_init_interface(void) /* Allocate the datatype creation class */ assert(H5P_CLS_DATATYPE_CREATE_g==(-1)); - if (NULL==(pclass = H5P_create_class (obj_class,"datatype create",1,NULL,NULL,NULL,NULL,NULL,NULL))) + if (NULL==(pclass = H5P_create_class (ocrt_class,"datatype create",1,NULL,NULL,NULL,NULL,NULL,NULL))) HGOTO_ERROR (H5E_PLIST, H5E_CANTINIT, FAIL, "class initialization failed"); /* Register the datatype creation class */ @@ -421,6 +419,7 @@ H5P_term_interface(void) /* Reset the default property lists, if they've been closed */ if(H5I_nmembers(H5I_GENPROP_LST)==0) { H5P_LST_NO_CLASS_g = + H5P_CLS_OBJECT_CREATE_g = H5P_LST_FILE_CREATE_g = H5P_LST_FILE_ACCESS_g = H5P_LST_DATASET_CREATE_g = @@ -441,7 +440,7 @@ H5P_term_interface(void) /* Reset the default property lists, if they've been closed */ if(H5I_nmembers(H5I_GENPROP_CLS)==0) { H5P_CLS_NO_CLASS_g = - H5P_CLS_OBJ_CLASS_g = + H5P_CLS_OBJECT_CREATE_g = H5P_CLS_FILE_CREATE_g = H5P_CLS_FILE_ACCESS_g = H5P_CLS_DATASET_CREATE_g = diff --git a/src/H5Pocpl.c b/src/H5Pocpl.c index 14a477d..7132a93 100755 --- a/src/H5Pocpl.c +++ b/src/H5Pocpl.c @@ -41,13 +41,13 @@ herr_t H5Pset_create_intermediate_group(hid_t plist_id, unsigned crt_intmd_group) { H5P_genplist_t *plist; /* Property list pointer */ - herr_t ret_value=SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(H5Pset_create_intermediate_group, FAIL); /* Get the plist structure */ - if(NULL == (plist = H5I_object(plist_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, NULL, "can't find object for ID") + if(NULL == (plist = H5P_object_verify(plist_id, H5P_OBJECT_CREATE))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Set value */ crt_intmd_group = crt_intmd_group > 0 ? 1 : 0; @@ -75,16 +75,16 @@ herr_t H5Pget_create_intermediate_group(hid_t plist_id, unsigned *crt_intmd_group /*out*/) { H5P_genplist_t *plist; /* Property list pointer */ - herr_t ret_value=SUCCEED; /* return value */ + herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_API(H5Pget_create_intermediate_group, FAIL); /* Get the plist structure */ - if(NULL == (plist = H5I_object(plist_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, NULL, "can't find object for ID") + if(NULL == (plist = H5P_object_verify(plist_id, H5P_OBJECT_CREATE))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Get values */ - if (crt_intmd_group) + if(crt_intmd_group) if(H5P_get(plist, H5G_CRT_INTERMEDIATE_GROUP_NAME, crt_intmd_group) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get intermediate group creation flag") diff --git a/src/H5Ppublic.h b/src/H5Ppublic.h index 1240d2d..cbf6b48 100644 --- a/src/H5Ppublic.h +++ b/src/H5Ppublic.h @@ -81,6 +81,7 @@ typedef herr_t (*H5P_iterate_t)(hid_t id, const char *name, void *iter_data); #endif /* _H5private_H */ #define H5P_NO_CLASS (H5OPEN H5P_CLS_NO_CLASS_g) +#define H5P_OBJECT_CREATE (H5OPEN H5P_CLS_OBJECT_CREATE_g) #define H5P_FILE_CREATE (H5OPEN H5P_CLS_FILE_CREATE_g) #define H5P_FILE_ACCESS (H5OPEN H5P_CLS_FILE_ACCESS_g) #define H5P_DATASET_CREATE (H5OPEN H5P_CLS_DATASET_CREATE_g) @@ -92,6 +93,7 @@ typedef herr_t (*H5P_iterate_t)(hid_t id, const char *name, void *iter_data); #define H5P_DATATYPE_CREATE (H5OPEN H5P_CLS_DATATYPE_CREATE_g) #define H5P_DATATYPE_ACCESS (H5OPEN H5P_CLS_DATATYPE_ACCESS_g) H5_DLLVAR hid_t H5P_CLS_NO_CLASS_g; +H5_DLLVAR hid_t H5P_CLS_OBJECT_CREATE_g; H5_DLLVAR hid_t H5P_CLS_FILE_CREATE_g; H5_DLLVAR hid_t H5P_CLS_FILE_ACCESS_g; H5_DLLVAR hid_t H5P_CLS_DATASET_CREATE_g; @@ -440,13 +440,8 @@ static H5T_t *H5T_decode(const unsigned char *buf); #define H5T_INIT_TYPE_ALLOC_CREATE(BASE) { \ /* Allocate new datatype info */ \ - if (NULL==(dt = H5FL_CALLOC(H5T_t))) \ + if (NULL==(dt = H5T_alloc())) \ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") \ - dt->ent.header = HADDR_UNDEF; \ - if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t))) { \ - H5FL_FREE(H5T_t, dt); \ - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") \ - } \ } @@ -2976,10 +2971,7 @@ H5T_create(H5T_class_t type, size_t size) case H5T_OPAQUE: case H5T_COMPOUND: - if (NULL==(dt = H5FL_CALLOC(H5T_t))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - dt->ent.header = HADDR_UNDEF; - if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t))) + if(NULL == (dt = H5T_alloc())) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); dt->shared->type = type; @@ -3005,11 +2997,8 @@ H5T_create(H5T_class_t type, size_t size) } else { HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "no applicable native integer type"); } - if (NULL==(dt = H5FL_CALLOC(H5T_t))) + if(NULL == (dt = H5T_alloc())) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - dt->ent.header = HADDR_UNDEF; - if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); dt->shared->type = type; if (NULL==(dt->shared->parent=H5T_copy(H5I_object(subtype), H5T_COPY_ALL))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy base data type"); @@ -3025,7 +3014,6 @@ H5T_create(H5T_class_t type, size_t size) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, NULL, "unknown data type class"); } - dt->ent.header = HADDR_UNDEF; dt->shared->size = size; /* Set return value */ @@ -3505,6 +3493,51 @@ done: /*------------------------------------------------------------------------- + * Function: H5T_alloc + * + * Purpose: Allocates a new H5T_t structure, initializing it correctly. + * + * Return: Pointer to new H5T_t on success/NULL on failure + * + * Programmer: Quincey Koziol + * Monday, August 29, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +H5T_t * +H5T_alloc(void) +{ + H5T_t *dt; /* Pointer to datatype allocated */ + H5T_t *ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5T_alloc, NULL) + + /* Allocate & initialize new datatype info */ + if(NULL == (dt = H5FL_CALLOC(H5T_t))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + H5G_ent_reset(&(dt->ent)); + if(NULL == (dt->shared = H5FL_CALLOC(H5T_shared_t))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + + /* Assign return value */ + ret_value = dt; + +done: + if(ret_value == NULL) { + if(dt != NULL) { + if(dt->shared != NULL) + H5FL_FREE(H5T_shared_t, dt->shared); + H5FL_FREE(H5T_t, dt); + } /* end if */ + } /* end if */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T_alloc() */ + + +/*------------------------------------------------------------------------- * Function: H5T_free * * Purpose: Frees all memory associated with a datatype, but does not diff --git a/src/H5Tarray.c b/src/H5Tarray.c index cb78a6f..5a63011 100644 --- a/src/H5Tarray.c +++ b/src/H5Tarray.c @@ -151,13 +151,8 @@ H5T_array_create(H5T_t *base, int ndims, const hsize_t dim[/* ndims */], assert(dim); /* Build new type */ - if (NULL==(ret_value = H5FL_CALLOC(H5T_t))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - if (NULL==(ret_value->shared=H5FL_CALLOC(H5T_shared_t))) { - H5FL_FREE(H5T_t, ret_value); - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - } - ret_value->ent.header = HADDR_UNDEF; + if(NULL == (ret_value = H5T_alloc())) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") ret_value->shared->type = H5T_ARRAY; /* Copy the base type of the array */ diff --git a/src/H5Tcommit.c b/src/H5Tcommit.c index c98543d..030701e 100644 --- a/src/H5Tcommit.c +++ b/src/H5Tcommit.c @@ -231,6 +231,10 @@ H5T_commit(H5G_entry_t *loc, const char *name, H5T_t *type, hid_t dxpl_id, if (NULL == (tc_plist = H5I_object(tcpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") + /* + * Give the datatype a name. That is, create and add a new object to the + * group this datatype is being initially created in. + */ if (H5G_insert (loc, name, &(type->ent), dxpl_id, tc_plist)<0) HGOTO_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to name datatype") diff --git a/src/H5Tenum.c b/src/H5Tenum.c index 2e0af76..be80563 100644 --- a/src/H5Tenum.c +++ b/src/H5Tenum.c @@ -134,17 +134,12 @@ H5T_enum_create(const H5T_t *parent) assert(parent); /* Build new type */ - if (NULL==(ret_value = H5FL_CALLOC(H5T_t))) + if(NULL == (ret_value = H5T_alloc())) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - if (NULL==(ret_value->shared=H5FL_CALLOC(H5T_shared_t))) { - H5FL_FREE(H5T_t, ret_value); - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - } ret_value->shared->type = H5T_ENUM; ret_value->shared->parent = H5T_copy(parent, H5T_COPY_ALL); assert(ret_value->shared->parent); ret_value->shared->size = ret_value->shared->parent->shared->size; - ret_value->ent.header = HADDR_UNDEF; done: FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5Tpkg.h b/src/H5Tpkg.h index 76d5e13..35c3781 100644 --- a/src/H5Tpkg.h +++ b/src/H5Tpkg.h @@ -427,6 +427,7 @@ H5_DLLVAR double H5T_NATIVE_LDOUBLE_NEG_INF_g; /* Common functions */ H5_DLL H5T_t *H5T_create(H5T_class_t type, size_t size); +H5_DLL H5T_t *H5T_alloc(void); H5_DLL herr_t H5T_free(H5T_t *dt); H5_DLL H5T_sign_t H5T_get_sign(H5T_t const *dt); H5_DLL H5T_t *H5T_get_super(H5T_t *dt); diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index 39f85c1..081d896 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -164,13 +164,8 @@ H5T_vlen_create(const H5T_t *base) assert(base); /* Build new type */ - if (NULL==(dt = H5FL_CALLOC(H5T_t))) + if(NULL == (dt = H5T_alloc())) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t))) { - H5FL_FREE(H5T_t, dt); - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,"memory allocation failed") - } - dt->ent.header = HADDR_UNDEF; dt->shared->type = H5T_VLEN; /* diff --git a/src/H5detect.c b/src/H5detect.c index 62bdd1f..d2b77ac 100644 --- a/src/H5detect.c +++ b/src/H5detect.c @@ -557,15 +557,9 @@ H5TN_init_interface(void)\n\ /* The part common to fixed and floating types */ printf("\ - if (NULL==(dt = H5FL_CALLOC (H5T_t)))\n\ - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,\"memory allocation failed\");\n\ - if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t)))\n\ - { \ - H5FL_FREE(H5T_t, dt);\ - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, \"memory allocation failed\");\n\ - } \ + if(NULL == (dt = H5T_alloc()))\n\ + HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,\"memory allocation failed\")\n\ dt->shared->state = H5T_STATE_IMMUTABLE;\n\ - dt->ent.header = HADDR_UNDEF;\n\ dt->shared->type = H5T_%s;\n\ dt->shared->size = %d;\n\ dt->shared->u.atomic.order = H5T_ORDER_%s;\n\ @@ -637,8 +631,11 @@ H5TN_init_interface(void)\n\ \n\ done:\n\ if(ret_value<0) {\n\ - if(dt!=NULL)\n\ - H5FL_FREE(H5T_t,dt);\n\ + if(dt != NULL) {\n\ + if(dt->shared != NULL)\n\ + H5FL_FREE(H5T_shared_t, dt->shared);\n\ + H5FL_FREE(H5T_t, dt);\n\ + } /* end if */\n\ }\n\ \n\ FUNC_LEAVE_NOAPI(ret_value);\n}\n"); diff --git a/src/H5err.txt b/src/H5err.txt index 17d981e..76a9de0 100644 --- a/src/H5err.txt +++ b/src/H5err.txt @@ -175,6 +175,7 @@ MINOR, OHDR, H5E_VERSION, Wrong version number MINOR, OHDR, H5E_ALIGNMENT, Alignment error MINOR, OHDR, H5E_BADMESG, Unrecognized message MINOR, OHDR, H5E_CANTDELETE, Can't delete message +MINOR, OHDR, H5E_BADITER, Iteration failed # Group related errors MINOR, GROUP, H5E_CANTOPENOBJ, Can't open object |