summaryrefslogtreecommitdiffstats
path: root/src/H5Oefl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Oefl.c')
-rw-r--r--src/H5Oefl.c81
1 files changed, 33 insertions, 48 deletions
diff --git a/src/H5Oefl.c b/src/H5Oefl.c
index a7ce31a..25ab753 100644
--- a/src/H5Oefl.c
+++ b/src/H5Oefl.c
@@ -18,7 +18,7 @@
* Tuesday, November 25, 1997
*/
-#define H5O_PACKAGE /*suppress error about including H5Opkg */
+#include "H5Omodule.h" /* This source code file is part of the H5O module */
#include "H5private.h" /* Generic Functions */
@@ -96,8 +96,8 @@ H5O_efl_decode(H5F_t *f, hid_t dxpl_id, H5O_t H5_ATTR_UNUSED *open_oh,
int version;
const char *s = NULL;
H5HL_t *heap;
- size_t u; /* Local index variable */
- void *ret_value; /* Return value */
+ size_t u; /* Local index variable */
+ void *ret_value = NULL; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -258,64 +258,47 @@ H5O_efl_copy(const void *_mesg, void *_dest)
{
const H5O_efl_t *mesg = (const H5O_efl_t *) _mesg;
H5O_efl_t *dest = (H5O_efl_t *) _dest;
- size_t u; /* Local index variable */
- void *ret_value; /* Return value */
+ size_t u; /* Local index variable */
+ hbool_t slot_allocated = FALSE; /* Flag to indicate that dynamic allocation has begun */
+ void *ret_value = NULL; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
/* check args */
HDassert(mesg);
- if(!dest) {
- if(NULL == (dest = (H5O_efl_t *)H5MM_calloc(sizeof(H5O_efl_t))))
- HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message")
- if(NULL == (dest->slot = (H5O_efl_entry_t *)H5MM_calloc(mesg->nalloc * sizeof(H5O_efl_entry_t))))
- HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slots")
- } /* end if */
- else if(dest->nalloc < mesg->nalloc) {
- H5O_efl_entry_t *temp_slot; /* Temporary pointer to new slot information */
- /* Allocate new 'slot' information */
- if(NULL == (temp_slot = (H5O_efl_entry_t *)H5MM_calloc(mesg->nalloc * sizeof(H5O_efl_entry_t))))
- HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slots")
+ /* Allocate destination message, if necessary */
+ if(!dest && NULL == (dest = (H5O_efl_t *)H5MM_calloc(sizeof(H5O_efl_t))))
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message")
- /* Release old 'slot' information */
- for(u = 0; u < dest->nused; u++)
- dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name);
- dest->slot = (H5O_efl_entry_t *)H5MM_xfree(dest->slot);
+ /* copy */
+ *dest = *mesg;
- /* Point to new 'slot' information */
- dest->slot = temp_slot;
+ /* Deep copy allocated information */
+ if(dest->nalloc > 0) {
+ if(NULL == (dest->slot = (H5O_efl_entry_t *)H5MM_calloc(dest->nalloc * sizeof(H5O_efl_entry_t))))
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slots")
+ slot_allocated = TRUE;
+ for(u = 0; u < mesg->nused; u++) {
+ dest->slot[u] = mesg->slot[u];
+ if(NULL == (dest->slot[u].name = H5MM_xstrdup(mesg->slot[u].name)))
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slot name")
+ } /* end for */
} /* end if */
- else {
- /* Release old 'slot' information */
- for(u = 0; u < dest->nused; u++)
- dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name);
- } /* end else */
- dest->heap_addr = mesg->heap_addr;
- dest->nalloc = mesg->nalloc;
- dest->nused = mesg->nused;
-
- for(u = 0; u < mesg->nused; u++) {
- dest->slot[u] = mesg->slot[u];
- if(NULL == (dest->slot[u].name = H5MM_xstrdup(mesg->slot[u].name)))
- HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slot name")
- } /* end for */
/* Set return value */
ret_value = dest;
done:
if(NULL == ret_value) {
- if(dest && NULL == _dest) {
- if(dest->slot) {
- for(u = 0; u < mesg->nused; u++) {
- if(dest->slot[u].name != NULL && dest->slot[u].name != mesg->slot[u].name)
- dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name);
- } /* end for */
- dest->slot = (H5O_efl_entry_t *)H5MM_xfree(dest->slot);
- } /* end if */
- dest = (H5O_efl_t *)H5MM_xfree(dest);
+ if(slot_allocated) {
+ for(u = 0; u < dest->nused; u++)
+ if(dest->slot[u].name != NULL && dest->slot[u].name != mesg->slot[u].name)
+ dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name);
+ dest->slot = (H5O_efl_entry_t *)H5MM_xfree(dest->slot);
} /* end if */
+ if(NULL == _dest)
+ dest = (H5O_efl_t *)H5MM_xfree(dest);
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
@@ -389,8 +372,10 @@ H5O_efl_reset(void *_mesg)
/* reset */
if(mesg->slot) {
- for(u = 0; u < mesg->nused; u++)
+ for(u = 0; u < mesg->nused; u++) {
mesg->slot[u].name = (char *)H5MM_xfree(mesg->slot[u].name);
+ mesg->slot[u].name_offset = 0;
+ } /* end for */
mesg->slot = (H5O_efl_entry_t *)H5MM_xfree(mesg->slot);
} /* end if */
mesg->heap_addr = HADDR_UNDEF;
@@ -460,9 +445,9 @@ H5O_efl_copy_file(H5F_t H5_ATTR_UNUSED *file_src, void *mesg_src, H5F_t *file_ds
{
H5O_efl_t *efl_src = (H5O_efl_t *) mesg_src;
H5O_efl_t *efl_dst = NULL;
- H5HL_t *heap = NULL; /* Pointer to local heap for EFL file names */
+ H5HL_t *heap = NULL; /* Pointer to local heap for EFL file names */
size_t idx, size, name_offset, heap_size;
- void *ret_value; /* Return value */
+ void *ret_value = NULL; /* Return value */
FUNC_ENTER_NOAPI_NOINIT_TAG(dxpl_id, H5AC__COPIED_TAG, NULL)