summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5.c85
-rw-r--r--src/H5A.c61
-rw-r--r--src/H5Apublic.h4
-rw-r--r--src/H5C.c26
-rw-r--r--src/H5Cpublic.h1
-rw-r--r--src/H5D.c37
-rw-r--r--src/H5Dpublic.h1
-rw-r--r--src/H5E.c25
-rw-r--r--src/H5Epublic.h1
-rw-r--r--src/H5F.c25
-rw-r--r--src/H5Fpublic.h1
-rw-r--r--src/H5Osdim.c9
-rw-r--r--src/H5P.c32
-rw-r--r--src/H5Ppublic.h1
-rw-r--r--src/H5T.c25
-rw-r--r--src/H5Tpublic.h1
-rw-r--r--src/H5private.h2
17 files changed, 300 insertions, 37 deletions
diff --git a/src/H5.c b/src/H5.c
index 4d6d113..86f80bd 100644
--- a/src/H5.c
+++ b/src/H5.c
@@ -53,6 +53,13 @@ hbool_t library_initialize_g = FALSE;
hbool_t thread_initialize_g = FALSE;
hbool_t install_atexit_g = TRUE;
+typedef struct H5_exit {
+ void (*func)(void); /* Interface function to call during exit */
+ struct H5_exit *next; /* Pointer to next node with exit function */
+ } H5_exit_t;
+
+H5_exit_t *lib_exit_head; /* Pointer to the head of the list of 'atexit' functions */
+
/*------------------_-- Local function prototypes ----------------------------*/
static herr_t H5_init_interface(void);
@@ -82,6 +89,46 @@ herr_t H5_init_library(void)
/*--------------------------------------------------------------------------
NAME
+ H5_add_exit
+ PURPOSE
+ Add an exit routine to the list of routines to call during 'atexit'
+ USAGE
+ herr_t H5_add_exit(func)
+ void (*func)(void); IN: Function pointer of routine to add to chain
+
+ RETURNS
+ SUCCEED/FAIL
+ DESCRIPTION
+ Pre-pend the new function to the list of function to call during the exit
+ process. These routines are responsible for free'ing static buffers, etc.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ Don't make assumptions about the environment during the exit procedure...
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+herr_t
+H5_add_exit (void (*func)(void))
+{
+ herr_t ret_value = SUCCEED;
+ H5_exit_t *new;
+
+ FUNC_ENTER (H5_add_exit, NULL, FAIL);
+
+ assert(func);
+
+ if((new=HDcalloc(1,sizeof(H5_exit_t)))==NULL)
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL);
+
+ new->func=func;
+ new->next=lib_exit_head;
+ lib_exit_head=new;
+
+ FUNC_LEAVE(ret_value);
+} /* end H5_add_exit() */
+
+/*--------------------------------------------------------------------------
+ NAME
H5_term_library
PURPOSE
Terminate various static buffers and shutdown the library.
@@ -101,6 +148,16 @@ herr_t H5_init_library(void)
void
H5_term_library (void)
{
+ H5_exit_t *temp;
+
+ temp=lib_exit_head;
+ while(lib_exit_head!=NULL)
+ {
+ (*lib_exit_head->func)();
+ lib_exit_head=lib_exit_head->next;
+ HDfree(temp);
+ temp=lib_exit_head;
+ } /* end while */
} /* end H5_term_library() */
/*--------------------------------------------------------------------------
@@ -123,10 +180,38 @@ herr_t H5_init_thread(void)
if((thrderrid=H5Enew_err_stack(16))==FAIL)
HRETURN_ERROR (H5E_FUNC, H5E_CANTINIT, FAIL);
+ /* Add the "thread termination" routine to the exit chain */
+ if(H5_add_exit(&H5_term_thread)==FAIL)
+ HRETURN_ERROR (H5E_FUNC, H5E_CANTINIT, FAIL);
+
FUNC_LEAVE (SUCCEED);
} /* H5_init_thread */
/*--------------------------------------------------------------------------
+ NAME
+ H5_term_thread
+ PURPOSE
+ Terminate various thread-specific objects
+ USAGE
+ void H5_term_thread()
+ RETURNS
+ SUCCEED/FAIL
+ DESCRIPTION
+ Release the error stack and any other thread-specific resources allocated
+ on a "per thread" basis.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ Can't report errors...
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+void
+H5_term_thread (void)
+{
+ H5Edelete_err_stack(thrderrid);
+} /* end H5_term_thread() */
+
+/*--------------------------------------------------------------------------
NAME
H5_init_interface -- Initialize interface-specific information
USAGE
diff --git a/src/H5A.c b/src/H5A.c
index 81660a5..897d3c2 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -67,6 +67,9 @@ MODIFICATION HISTORY
#define PABLO_MASK H5A_mask
+/*-------------------- Locally scoped variables -----------------------------*/
+
+/* Is the interface initialized? */
static int interface_initialize_g = FALSE;
#ifdef ATOMS_ARE_CACHED
@@ -81,10 +84,32 @@ static atom_group_t *atom_group_list[MAXGROUP]={NULL};
/* Pointer to the atom node free list */
static atom_info_t *atom_free_list=NULL;
-/* PRIVATE PROTOTYPES */
+/*--------------------- Local function prototypes ---------------------------*/
static atom_info_t *H5A_find_atom(hatom_t atm);
static atom_info_t *H5A_get_atom_node(void);
static herr_t H5A_release_atom_node(atom_info_t *atm);
+static herr_t H5A_init_interface(void);
+
+/*--------------------------------------------------------------------------
+NAME
+ H5A_init_interface -- Initialize interface-specific information
+USAGE
+ herr_t H5A_init_interface()
+RETURNS
+ SUCCEED/FAIL
+DESCRIPTION
+ Initializes any interface-specific data or routines.
+--------------------------------------------------------------------------*/
+static herr_t H5A_init_interface(void)
+{
+ herr_t ret_value = SUCCEED;
+ FUNC_ENTER (H5A_init_interface, H5A_init_interface, FAIL);
+
+ /* Registers the cleanup routine with the exit chain */
+ ret_value=H5_add_exit(&H5A_term_interface);
+
+ FUNC_LEAVE(ret_value);
+} /* H5E_init_interface */
/******************************************************************************
NAME
@@ -111,7 +136,7 @@ intn H5Ainit_group(group_t grp, /* IN: Group to initialize */
atom_group_t *grp_ptr=NULL; /* ptr to the atomic group */
intn ret_value=SUCCEED;
- FUNC_ENTER (H5Ainit_group, NULL, FAIL);
+ FUNC_ENTER (H5Ainit_group, H5A_init_interface, FAIL);
if((grp<=BADGROUP || grp>=MAXGROUP) && hash_size>0)
HGOTO_DONE(FAIL);
@@ -192,7 +217,7 @@ intn H5Adestroy_group(group_t grp /* IN: Group to destroy */
atom_group_t *grp_ptr=NULL; /* ptr to the atomic group */
intn ret_value=SUCCEED;
- FUNC_ENTER (H5Adestroy_group, NULL, FAIL);
+ FUNC_ENTER (H5Adestroy_group, H5A_init_interface, FAIL);
if(grp<=BADGROUP || grp>=MAXGROUP)
HGOTO_DONE(FAIL);
@@ -258,7 +283,7 @@ hatom_t H5Aregister_atom(group_t grp, /* IN: Group to register the object in
uintn hash_loc; /* new item's hash table location */
hatom_t ret_value=SUCCEED;
- FUNC_ENTER (H5Aregister_atom, NULL, FAIL);
+ FUNC_ENTER (H5Aregister_atom, H5A_init_interface, FAIL);
if(grp<=BADGROUP || grp>=MAXGROUP)
HGOTO_DONE(FAIL);
@@ -352,7 +377,7 @@ VOIDP H5Aatom_object(hatom_t atm /* IN: Atom to retrieve object for */
atom_info_t *atm_ptr=NULL; /* ptr to the new atom */
VOIDP ret_value=NULL;
- FUNC_ENTER (H5Aatom_object, NULL, NULL);
+ FUNC_ENTER (H5Aatom_object, H5A_init_interface, NULL);
#ifdef ATOMS_ARE_CACHED
/* Look for the atom in the cache first */
@@ -408,7 +433,7 @@ group_t H5Aatom_group(hatom_t atm /* IN: Atom to retrieve group for */
{
group_t ret_value=BADGROUP;
- FUNC_ENTER (H5Aatom_group, NULL, FAIL);
+ FUNC_ENTER (H5Aatom_group, H5A_init_interface, FAIL);
ret_value=ATOM_TO_GROUP(atm);
if(ret_value<=BADGROUP || ret_value>=MAXGROUP)
@@ -448,7 +473,7 @@ VOIDP H5Aremove_atom(hatom_t atm /* IN: Atom to remove */
#endif /* ATOMS_ARE_CACHED */
VOIDP ret_value=NULL;
- FUNC_ENTER (H5Aremove_atom, NULL, NULL);
+ FUNC_ENTER (H5Aremove_atom, H5A_init_interface, NULL);
grp=ATOM_TO_GROUP(atm);
if(grp<=BADGROUP || grp>=MAXGROUP)
@@ -533,7 +558,7 @@ VOIDP H5Asearch_atom(group_t grp, /* IN: Group to search for the object i
intn i; /* local counting variable */
VOIDP ret_value=NULL;
- FUNC_ENTER (H5Asearch_atom, NULL, NULL);
+ FUNC_ENTER (H5Asearch_atom, H5A_init_interface, NULL);
if(grp<=BADGROUP || grp>=MAXGROUP)
HGOTO_DONE(NULL);
@@ -583,7 +608,7 @@ intn H5Ais_reserved(hatom_t atm /* IN: Group to search for the object in */
group_t grp; /* atom's atomic group */
hbool_t ret_value=BFAIL;
- FUNC_ENTER (H5Ais_reserved, NULL, FAIL);
+ FUNC_ENTER (H5Ais_reserved, H5A_init_interface, FAIL);
grp=ATOM_TO_GROUP(atm);
if(grp<=BADGROUP || grp>=MAXGROUP)
@@ -629,7 +654,7 @@ static atom_info_t *H5A_find_atom(hatom_t atm /* IN: Atom to retrieve atom for
uintn hash_loc; /* atom's hash table location */
atom_info_t *ret_value=NULL;
- FUNC_ENTER (H5A_find_atom, NULL, NULL);
+ FUNC_ENTER (H5A_find_atom, H5A_init_interface, NULL);
grp=ATOM_TO_GROUP(atm);
if(grp<=BADGROUP || grp>=MAXGROUP)
@@ -685,7 +710,7 @@ static atom_info_t *H5A_get_atom_node(void)
{
atom_info_t *ret_value=NULL;
- FUNC_ENTER (H5A_get_atom_node, NULL, NULL);
+ FUNC_ENTER (H5A_get_atom_node, H5A_init_interface, NULL);
if(atom_free_list!=NULL)
{
@@ -723,7 +748,7 @@ done:
static herr_t
H5A_release_atom_node(atom_info_t *atm)
{
- FUNC_ENTER (H5A_release_atom_node, NULL, FAIL);
+ FUNC_ENTER (H5A_release_atom_node, H5A_init_interface, FAIL);
/* Insert the atom at the beginning of the free list */
atm->next=atom_free_list;
@@ -734,11 +759,11 @@ H5A_release_atom_node(atom_info_t *atm)
/*--------------------------------------------------------------------------
NAME
- H5Ashutdown
+ H5A_term_interface
PURPOSE
Terminate various static buffers.
USAGE
- intn H5Ashutdown()
+ intn H5A_term_interface()
RETURNS
Returns SUCCEED/FAIL
DESCRIPTION
@@ -749,14 +774,11 @@ H5A_release_atom_node(atom_info_t *atm)
EXAMPLES
REVISION LOG
--------------------------------------------------------------------------*/
-intn
-H5Ashutdown(void)
+void H5A_term_interface(void)
{
atom_info_t *curr;
intn i;
- FUNC_ENTER (H5Ashutdown, NULL, FAIL);
-
/* Release the free-list if it exists */
if(atom_free_list!=NULL)
{
@@ -775,6 +797,5 @@ H5Ashutdown(void)
atom_group_list[i]=NULL;
} /* end if */
- FUNC_LEAVE (SUCCEED);
-} /* end H5Ashutdown() */
+} /* end H5A_term_interface() */
diff --git a/src/H5Apublic.h b/src/H5Apublic.h
index 3823b28..d9f79ef 100644
--- a/src/H5Apublic.h
+++ b/src/H5Apublic.h
@@ -190,7 +190,7 @@ intn H5Ais_reserved(hatom_t atm /* IN: Group to search for the object in */
/******************************************************************************
NAME
- H5Ashutdown - Terminate various static buffers.
+ H5A_term_interface - Terminate various static buffers.
DESCRIPTION
Free various buffers allocated in the H5A routines.
@@ -199,7 +199,7 @@ intn H5Ais_reserved(hatom_t atm /* IN: Group to search for the object in */
Returns SUCCEED/FAIL
*******************************************************************************/
-intn H5Ashutdown(void);
+void H5A_term_interface(void);
#ifdef __cplusplus
}
diff --git a/src/H5C.c b/src/H5C.c
index 23a0450..d19298c 100644
--- a/src/H5C.c
+++ b/src/H5C.c
@@ -83,13 +83,37 @@ static herr_t H5C_init_interface(void)
FUNC_ENTER (H5C_init_interface, NULL, FAIL);
/* Initialize the atom group for the file IDs */
- ret_value=H5Ainit_group(H5_TEMPLATE,H5A_TEMPID_HASHSIZE,0);
+ if((ret_value=H5Ainit_group(H5_TEMPLATE,H5A_TEMPID_HASHSIZE,0))!=FAIL)
+ ret_value=H5_add_exit(&H5C_term_interface);
FUNC_LEAVE(ret_value);
} /* H5C_init_interface */
/*--------------------------------------------------------------------------
NAME
+ H5C_term_interface
+ PURPOSE
+ Terminate various H5C objects
+ USAGE
+ void H5C_term_interface()
+ RETURNS
+ SUCCEED/FAIL
+ DESCRIPTION
+ Release the atom group and any other resources allocated.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ Can't report errors...
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+void H5C_term_interface (void)
+{
+ H5Aremove_atom(default_file_id);
+ H5Adestroy_group(H5_TEMPLATE);
+} /* end H5C_term_interface() */
+
+/*--------------------------------------------------------------------------
+ NAME
H5C_get_default_atom
PURPOSE
Retrive an atom for a default HDF5 template.
diff --git a/src/H5Cpublic.h b/src/H5Cpublic.h
index 98fa65f..ed7c777 100644
--- a/src/H5Cpublic.h
+++ b/src/H5Cpublic.h
@@ -47,6 +47,7 @@ typedef group_t hobjtype_t; /* Map the object in the "meta" interface to ato
/* Functions in H5C.c */
herr_t H5Cgetparm(hatom_t tid, file_create_param_t parm, VOIDP buf);
herr_t H5Csetparm(hatom_t tid, file_create_param_t parm, const VOIDP buf);
+void H5C_term_interface (void);
#ifdef __cplusplus
}
diff --git a/src/H5D.c b/src/H5D.c
index a5a2349..8ab6b19 100644
--- a/src/H5D.c
+++ b/src/H5D.c
@@ -69,13 +69,36 @@ static herr_t H5D_init_interface(void)
FUNC_ENTER (H5D_init_interface, NULL, FAIL);
/* Initialize the atom group for the file IDs */
- ret_value=H5Ainit_group(H5_DATASET,H5A_DATASETID_HASHSIZE,H5D_RESERVED_ATOMS);
+ if((ret_value=H5Ainit_group(H5_DATASET,H5A_DATASETID_HASHSIZE,H5D_RESERVED_ATOMS))!=FAIL)
+ ret_value=H5_add_exit(&H5D_term_interface);
FUNC_LEAVE(ret_value);
} /* H5D_init_interface */
/*--------------------------------------------------------------------------
NAME
+ H5D_term_interface
+ PURPOSE
+ Terminate various H5D objects
+ USAGE
+ void H5D_term_interface()
+ RETURNS
+ SUCCEED/FAIL
+ DESCRIPTION
+ Release the atom group and any other resources allocated.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ Can't report errors...
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+void H5D_term_interface (void)
+{
+ H5Adestroy_group(H5_DATASET);
+} /* end H5D_term_interface() */
+
+/*--------------------------------------------------------------------------
+ NAME
H5D_create
PURPOSE
Create a new HDF5 dataset object
@@ -190,14 +213,14 @@ hatom_t H5D_find_name(hatom_t grp_id, hobjtype_t type, const char *name)
HGOTO_ERROR(H5E_DATASET, H5E_NOTFOUND, FAIL);
/* Get the dataset's type (currently only atomic types) */
- if((dset->type=HDmalloc(sizeof(h5_datatype_t)))==NULL)
+ if((dset->type=HDcalloc(1,sizeof(h5_datatype_t)))==NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
if (NULL==H5O_read (dset->file, dset->ent.header, &(dset->ent),
H5O_SIM_DTYPE, 0, dset->type))
HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL);
/* Get the dataset's dimensionality (currently only simple dataspaces) */
- if((dset->dim=HDmalloc(sizeof(H5P_dim_t)))==NULL)
+ if((dset->dim=HDcalloc(1,sizeof(H5P_dim_t)))==NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
dset->dim->type=H5P_TYPE_SIMPLE; /* for now... */
if (NULL==(dset->dim->s=H5O_read (dset->file, dset->ent.header,
@@ -630,6 +653,14 @@ herr_t H5D_flush(hatom_t oid)
HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL);
}
}
+
+#ifdef ROBB
+ /* Flush dataset header to disk */
+ if (H5O_flush (dataset->file, FALSE, dataset->ent.header, NULL)<0) {
+ HRETURN_ERROR (H5E_OHDR, H5E_CANTFLUSH, FAIL);
+ }
+#endif /* ROBB */
+
dataset->modified = FALSE; /*it's clean now*/
}
diff --git a/src/H5Dpublic.h b/src/H5Dpublic.h
index 31b3080..6603d55 100644
--- a/src/H5Dpublic.h
+++ b/src/H5Dpublic.h
@@ -32,6 +32,7 @@ herr_t H5Dset_info(hatom_t oid, hatom_t tid, hatom_t did);
herr_t H5Dget_info(hatom_t oid, hatom_t *tid, hatom_t *sid);
herr_t H5Dwrite(hatom_t oid, hatom_t did, VOIDP buf);
herr_t H5Dread(hatom_t oid, hatom_t did, VOIDP buf);
+void H5D_term_interface (void);
#ifdef __cplusplus
}
diff --git a/src/H5E.c b/src/H5E.c
index d6474c2..2a586e1 100644
--- a/src/H5E.c
+++ b/src/H5E.c
@@ -133,12 +133,35 @@ static herr_t H5E_init_interface(void)
FUNC_ENTER (H5E_init_interface, NULL, FAIL);
/* Initialize the atom group for the error stacks */
- ret_value=H5Ainit_group(H5_ERR,H5A_ERRSTACK_HASHSIZE,0);
+ if((ret_value=H5Ainit_group(H5_ERR,H5A_ERRSTACK_HASHSIZE,0))!=FAIL)
+ ret_value=H5_add_exit(&H5E_term_interface);
FUNC_LEAVE(ret_value);
} /* H5E_init_interface */
/*--------------------------------------------------------------------------
+ NAME
+ H5E_term_interface
+ PURPOSE
+ Terminate various H5E objects
+ USAGE
+ void H5E_term_interface()
+ RETURNS
+ SUCCEED/FAIL
+ DESCRIPTION
+ Release the atom group and any other resources allocated.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ Can't report errors...
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+void H5E_term_interface (void)
+{
+ H5Adestroy_group(H5_ERR);
+} /* end H5E_term_interface() */
+
+/*--------------------------------------------------------------------------
NAME
H5Enew_err_stack -- Create a new error stack
USAGE
diff --git a/src/H5Epublic.h b/src/H5Epublic.h
index 4793994..101ad76 100644
--- a/src/H5Epublic.h
+++ b/src/H5Epublic.h
@@ -122,6 +122,7 @@ H5E_push_func_t H5Eset_push(H5E_push_func_t func);
#endif
herr_t H5Epush(hdf_maj_err_code_t maj, hdf_min_err_code_t min, const char *function_name, const char *file_name, intn line);
herr_t H5Eclear(int32 err_hand);
+void H5E_term_interface(void);
#ifdef __cplusplus
}
diff --git a/src/H5F.c b/src/H5F.c
index dfdd862..348e477 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -84,11 +84,34 @@ static herr_t H5F_init_interface(void)
FUNC_ENTER (H5F_init_interface, NULL, FAIL);
/* Initialize the atom group for the file IDs */
- ret_value=H5Ainit_group(H5_FILE,H5A_FILEID_HASHSIZE,0);
+ if((ret_value=H5Ainit_group(H5_FILE,H5A_FILEID_HASHSIZE,0))!=FAIL)
+ ret_value=H5_add_exit(&H5F_term_interface);
FUNC_LEAVE(ret_value);
} /* H5F_init_interface */
+/*--------------------------------------------------------------------------
+ NAME
+ H5F_term_interface
+ PURPOSE
+ Terminate various H5F objects
+ USAGE
+ void H5F_term_interface()
+ RETURNS
+ SUCCEED/FAIL
+ DESCRIPTION
+ Release the atom group and any other resources allocated.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ Can't report errors...
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+void H5F_term_interface (void)
+{
+ H5Adestroy_group(H5_FILE);
+} /* end H5F_term_interface() */
+
#ifdef LATER
/*--------------------------------------------------------------------------
NAME
diff --git a/src/H5Fpublic.h b/src/H5Fpublic.h
index 84bb359..b999b2d 100644
--- a/src/H5Fpublic.h
+++ b/src/H5Fpublic.h
@@ -38,6 +38,7 @@ hatom_t H5Fopen(const char *filename, uintn flags, hatom_t access_template);
herr_t H5Fclose(hatom_t fid);
herr_t H5Fflush (hatom_t fid, hbool_t invalidate);
hatom_t H5Fget_create_template(hatom_t fid);
+void H5F_term_interface (void);
#ifdef __cplusplus
}
diff --git a/src/H5Osdim.c b/src/H5Osdim.c
index 5549fc0..80b9735 100644
--- a/src/H5Osdim.c
+++ b/src/H5Osdim.c
@@ -333,18 +333,21 @@ H5O_sim_dim_copy (const void *mesg, void *dest)
HDmemcpy(dst,src,sizeof(H5O_sim_dim_t));
if(src->rank>0)
{
- dst->size = H5MM_xcalloc (src->rank, sizeof(uint32));
+ if(dst->size==NULL)
+ dst->size = H5MM_xcalloc (src->rank, sizeof(uint32));
HDmemcpy(dst->size,src->size,src->rank*sizeof(uint32));
/* Check for maximum dimensions and copy those */
if((src->dim_flags&0x01)>0)
{
- dst->max = H5MM_xcalloc (src->rank, sizeof(uint32));
+ if(dst->max==NULL)
+ dst->max = H5MM_xcalloc (src->rank, sizeof(uint32));
HDmemcpy(dst->max,src->max,src->rank*sizeof(uint32));
} /* end if */
/* Check for dimension permutation and copy those */
if((src->dim_flags&0x02)>0)
{
- dst->perm = H5MM_xcalloc (src->rank, sizeof(uint32));
+ if(dst->max==NULL)
+ dst->perm = H5MM_xcalloc (src->rank, sizeof(uint32));
HDmemcpy(dst->perm,src->perm,src->rank*sizeof(uint32));
} /* end if */
} /* end if */
diff --git a/src/H5P.c b/src/H5P.c
index e8a5d16..f643022 100644
--- a/src/H5P.c
+++ b/src/H5P.c
@@ -63,13 +63,36 @@ static herr_t H5P_init_interface(void)
FUNC_ENTER (H5P_init_interface, NULL, FAIL);
/* Initialize the atom group for the file IDs */
- ret_value=H5Ainit_group(H5_DATASPACE,H5A_DATASPACEID_HASHSIZE,H5P_RESERVED_ATOMS);
+ if((ret_value=H5Ainit_group(H5_DATASPACE,H5A_DATASPACEID_HASHSIZE,H5P_RESERVED_ATOMS))!=FAIL)
+ ret_value=H5_add_exit(&H5P_term_interface);
FUNC_LEAVE(ret_value);
} /* H5P_init_interface */
/*--------------------------------------------------------------------------
NAME
+ H5P_term_interface
+ PURPOSE
+ Terminate various H5P objects
+ USAGE
+ void H5P_term_interface()
+ RETURNS
+ SUCCEED/FAIL
+ DESCRIPTION
+ Release the atom group and any other resources allocated.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ Can't report errors...
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+void H5P_term_interface (void)
+{
+ H5Adestroy_group(H5_DATASPACE);
+} /* end H5P_term_interface() */
+
+/*--------------------------------------------------------------------------
+ NAME
H5P_create
PURPOSE
Create a new HDF5 dimensionality object
@@ -94,7 +117,7 @@ hatom_t H5P_create(hatom_t owner_id, hobjtype_t type, const char *name)
H5ECLEAR;
/* Allocate space for the new data-type */
- if((new_dim=HDmalloc(sizeof(H5P_dim_t)))==NULL)
+ if((new_dim=HDcalloc(1,sizeof(H5P_dim_t)))==NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
/* Initialize the dimensionality object */
@@ -284,7 +307,7 @@ herr_t H5Pset_space(hatom_t sid, uint32 rank, uint32 *dims)
/* Set the rank and copy the dims */
space->s->rank=rank;
- if((space->s->size=HDmalloc(sizeof(uint32)*rank))==NULL)
+ if((space->s->size=HDcalloc(sizeof(uint32),rank))==NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
HDmemcpy(space->s->size,dims,sizeof(uint32)*rank);
@@ -294,7 +317,7 @@ herr_t H5Pset_space(hatom_t sid, uint32 rank, uint32 *dims)
{
if(u>0) /* sanity check for unlimited dimensions not in the lowest dimensionality */
HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL);
- if((space->s->max=HDmalloc(sizeof(uint32)*rank))==NULL)
+ if((space->s->max=HDcalloc(sizeof(uint32),rank))==NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
HDmemcpy(space->s->max,dims,sizeof(uint32)*rank);
space->s->dim_flags|=H5P_VALID_MAX;
@@ -449,7 +472,6 @@ herr_t H5P_release(hatom_t oid)
if(dim->s->perm!=NULL)
HDfree(dim->s->perm);
HDfree(dim->s);
- dim->s=NULL;
} /* end if */
} /* end if */
HDfree(dim);
diff --git a/src/H5Ppublic.h b/src/H5Ppublic.h
index 538e850..076b52c 100644
--- a/src/H5Ppublic.h
+++ b/src/H5Ppublic.h
@@ -43,6 +43,7 @@ extern "C" {
/* Functions in H5P.c */
uintn H5Pnelem(hatom_t dim_id);
herr_t H5Pset_space(hatom_t sid, uint32 rank, uint32 *dims);
+void H5P_term_interface (void);
#ifdef __cplusplus
}
diff --git a/src/H5T.c b/src/H5T.c
index 2383c6b..840a08a 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -74,13 +74,36 @@ static herr_t H5T_init_interface(void)
FUNC_ENTER (H5T_init_interface, NULL, FAIL);
/* Initialize the atom group for the file IDs */
- ret_value=H5Ainit_group(H5_DATATYPE,H5A_DATATYPEID_HASHSIZE,H5T_RESERVED_ATOMS);
+ if((ret_value=H5Ainit_group(H5_DATATYPE,H5A_DATATYPEID_HASHSIZE,H5T_RESERVED_ATOMS))!=FAIL)
+ ret_value=H5_add_exit(&H5T_term_interface);
FUNC_LEAVE(ret_value);
} /* H5T_init_interface */
/*--------------------------------------------------------------------------
NAME
+ H5T_term_interface
+ PURPOSE
+ Terminate various H5T objects
+ USAGE
+ void H5T_term_interface()
+ RETURNS
+ SUCCEED/FAIL
+ DESCRIPTION
+ Release the atom group and any other resources allocated.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ Can't report errors...
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+void H5T_term_interface (void)
+{
+ H5Adestroy_group(H5_DATATYPE);
+} /* end H5T_term_interface() */
+
+/*--------------------------------------------------------------------------
+ NAME
H5T_create
PURPOSE
Create a new HDF5 data-type object
diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h
index daca824..3404115 100644
--- a/src/H5Tpublic.h
+++ b/src/H5Tpublic.h
@@ -74,6 +74,7 @@ uintn H5Tsize(hatom_t tid, uint8 len, uint8 arch, hbool_t mem_flag);
herr_t H5Tadd_field (hatom_t tid, const char *name, hatom_t base, uint8 len,
uint8 arch, hatom_t space);
herr_t H5Tget_fields(hatom_t tid, hatom_t *field_list);
+void H5T_term_interface (void);
#ifdef __cplusplus
}
diff --git a/src/H5private.h b/src/H5private.h
index a321f31..070dca9 100644
--- a/src/H5private.h
+++ b/src/H5private.h
@@ -468,6 +468,8 @@ extern hbool_t thread_initialize_g; /*don't decl interface_initialize_g */
/* Private functions, not part of the publicly documented API */
herr_t H5_init_library(void);
void H5_term_library(void);
+herr_t H5_add_exit (void (*func)(void));
herr_t H5_init_thread(void);
+void H5_term_thread(void);
#endif