diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/H5D.c | 29 | ||||
-rw-r--r-- | src/H5E.c | 4 | ||||
-rw-r--r-- | src/H5FP.c | 2 | ||||
-rw-r--r-- | src/H5FPserver.c | 10 | ||||
-rw-r--r-- | src/H5MM.c | 67 | ||||
-rw-r--r-- | src/H5MMprivate.h | 11 | ||||
-rw-r--r-- | src/H5config.h.in | 4 |
7 files changed, 97 insertions, 30 deletions
@@ -3419,19 +3419,22 @@ H5D_flush(const H5F_t *f, hid_t dxpl_id) if((num_dsets=H5F_get_obj_count(f, H5F_OBJ_DATASET))<0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to get dataset count") - H5_CHECK_OVERFLOW(num_dsets,int,size_t); - if(NULL==(id_list=H5MM_malloc((size_t)num_dsets*sizeof(hid_t)))) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to allocate memory for ID list") - if(H5F_get_obj_ids(f, H5F_OBJ_DATASET, -1, id_list)<0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to get dataset ID list") - for(j=0; j<num_dsets; j++) { - if(NULL==(dataset=H5I_object_verify(id_list[j], H5I_DATASET))) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to get dataset object") - if(dataset->layout.type==H5D_COMPACT && dataset->layout.dirty) - if(H5O_modify(&(dataset->ent), H5O_LAYOUT_ID, 0, 0, 1, &(dataset->layout), dxpl_id)<0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to update layout message") - dataset->layout.dirty = FALSE; - } + /* Check for something to do */ + if(num_dsets>0) { + H5_CHECK_OVERFLOW(num_dsets,int,size_t); + if(NULL==(id_list=H5MM_malloc((size_t)num_dsets*sizeof(hid_t)))) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to allocate memory for ID list") + if(H5F_get_obj_ids(f, H5F_OBJ_DATASET, -1, id_list)<0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to get dataset ID list") + for(j=0; j<num_dsets; j++) { + if(NULL==(dataset=H5I_object_verify(id_list[j], H5I_DATASET))) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to get dataset object") + if(dataset->layout.type==H5D_COMPACT && dataset->layout.dirty) + if(H5O_modify(&(dataset->ent), H5O_LAYOUT_ID, 0, 0, 1, &(dataset->layout), dxpl_id)<0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to update layout message") + dataset->layout.dirty = FALSE; + } + } /* end if */ done: if(id_list!=NULL) @@ -780,7 +780,7 @@ H5Eget_major(H5E_major_t maj) HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "Error message isn't a major one"); /* Don't know who is going to free it */ - msg_str = (char*)HDmalloc((++size)*sizeof(char)); + msg_str = (char*)H5MM_malloc((++size)*sizeof(char)); if(H5E_get_msg(msg, NULL, msg_str, (size_t)size)<0) HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text") @@ -830,7 +830,7 @@ H5Eget_minor(H5E_minor_t min) HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "Error message isn't a minor one"); /* Don't know who is going to free it */ - msg_str = (char*)HDmalloc((++size)*sizeof(char)); + msg_str = (char*)H5MM_malloc((++size)*sizeof(char)); if(H5E_get_msg(msg, NULL, msg_str, (size_t)size)<0) HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text") @@ -317,7 +317,7 @@ H5FP_read_metadata(char **mdata, int len, int from) * There is metadata associated with this request. Get it as a * string (requires another read). */ - if ((*mdata = (char *)HDmalloc((size_t)len + 1)) == NULL) + if ((*mdata = (char *)H5MM_malloc((size_t)len + 1)) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "out of memory"); HDmemset(*mdata, 0, (size_t)len + 1); diff --git a/src/H5FPserver.c b/src/H5FPserver.c index 06ac060..55ae3b3 100644 --- a/src/H5FPserver.c +++ b/src/H5FPserver.c @@ -350,7 +350,7 @@ H5FP_new_object_lock(hobj_ref_t oid, unsigned rank, H5FP_obj_t obj_type, if (MPI_Comm_size(H5FP_SAP_COMM, &comm_size) != MPI_SUCCESS) HGOTO_ERROR(H5E_INTERNAL, H5E_MPI, NULL, "MPI_Comm_size failed"); - if ((ret_value = (H5FP_object_lock *)HDmalloc(sizeof(H5FP_object_lock))) == NULL) + if ((ret_value = (H5FP_object_lock *)H5MM_malloc(sizeof(H5FP_object_lock))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "out of memory"); if ((ret_value->num_locks = (unsigned char *)HDcalloc(comm_size, 1)) == NULL) { @@ -505,7 +505,7 @@ H5FP_new_file_mod_node(unsigned UNUSED rank, H5FD_mem_t mem_type, FUNC_ENTER_NOINIT(H5FP_new_file_mod_node); - if ((ret_value = (H5FP_mdata_mod *)HDmalloc(sizeof(H5FP_mdata_mod))) == NULL) + if ((ret_value = (H5FP_mdata_mod *)H5MM_malloc(sizeof(H5FP_mdata_mod))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "out of memory"); ret_value->mem_type = mem_type; @@ -624,7 +624,7 @@ H5FP_new_file_info_node(unsigned file_id) FUNC_ENTER_NOINIT(H5FP_new_file_info_node); - if ((ret_value = (H5FP_file_info *)HDmalloc(sizeof(H5FP_file_info))) == NULL) + if ((ret_value = (H5FP_file_info *)H5MM_malloc(sizeof(H5FP_file_info))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "out of memory"); ret_value->file_id = file_id; @@ -965,7 +965,7 @@ H5FP_sap_handle_lock_request(H5FP_request_t *req) FUNC_ENTER_NOINIT(H5FP_sap_handle_lock_request); - if ((oids = (struct lock_group *)HDmalloc(list_size * + if ((oids = (struct lock_group *)H5MM_malloc(list_size * sizeof(struct lock_group))) == NULL) { exit_state = H5FP_STATUS_OOM; HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "out of memory"); @@ -1171,7 +1171,7 @@ H5FP_sap_handle_release_lock_request(H5FP_request_t *req) FUNC_ENTER_NOINIT(H5FP_sap_handle_release_lock_request); - if ((oids = (struct release_group *)HDmalloc(list_size * + if ((oids = (struct release_group *)H5MM_malloc(list_size * sizeof(struct release_group))) == NULL) { exit_state = H5FP_STATUS_OOM; HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "out of memory"); @@ -33,6 +33,73 @@ static int interface_initialize_g = 0; #define INTERFACE_INIT NULL +#ifndef NDEBUG + +/*------------------------------------------------------------------------- + * Function: H5MM_malloc + * + * Purpose: Just like the POSIX version of malloc(3). This routine + * specifically checks for allocations of 0 bytes and fails + * in that case. This routine is not called when NDEBUG is + * defined. + * + * Return: Success: Ptr to new memory + * + * Failure: NULL + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Nov 8 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void * +H5MM_malloc(size_t size) +{ + /* Use FUNC_ENTER_NOINIT here to avoid performance issues */ + FUNC_ENTER_NOINIT(H5MM_malloc); + + assert(size); + + FUNC_LEAVE_NOAPI(HDmalloc(size)); +} /* end H5MM_malloc() */ + + +/*------------------------------------------------------------------------- + * Function: H5MM_calloc + * + * Purpose: Similar to the POSIX version of calloc(3), except this routine + * just takes a 'size' parameter. This routine + * specifically checks for allocations of 0 bytes and fails + * in that case. This routine is not called when NDEBUG is + * defined. + * + * Return: Success: Ptr to new memory + * + * Failure: NULL + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Nov 8 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void * +H5MM_calloc(size_t size) +{ + /* Use FUNC_ENTER_NOINIT here to avoid performance issues */ + FUNC_ENTER_NOINIT(H5MM_calloc); + + assert(size); + + FUNC_LEAVE_NOAPI(HDcalloc(1,size)); +} /* end H5MM_calloc() */ +#endif /* NDEBUG */ + /*------------------------------------------------------------------------- * Function: H5MM_realloc diff --git a/src/H5MMprivate.h b/src/H5MMprivate.h index 54dfbfb..9aadd36 100644 --- a/src/H5MMprivate.h +++ b/src/H5MMprivate.h @@ -32,18 +32,19 @@ /* Private headers needed by this file */ #include "H5private.h" -#ifdef H5_MALLOC_WORKS +#ifdef NDEBUG #define H5MM_malloc(Z) HDmalloc(Z) #define H5MM_calloc(Z) HDcalloc(1,Z) -#else /* H5_MALLOC_WORKS */ -#define H5MM_malloc(Z) HDmalloc(MAX(1,Z)) -#define H5MM_calloc(Z) HDcalloc(1,MAX(1,Z)) -#endif /* H5_MALLOC_WORKS */ +#endif /* NDEBUG */ #define H5MM_free(Z) HDfree(Z) /* * Library prototypes... */ +#ifndef NDEBUG +H5_DLL void *H5MM_malloc(size_t size); +H5_DLL void *H5MM_calloc(size_t size); +#endif /* NDEBUG */ H5_DLL void *H5MM_realloc(void *mem, size_t size); H5_DLL char *H5MM_xstrdup(const char *s); H5_DLL char *H5MM_strdup(const char *s); diff --git a/src/H5config.h.in b/src/H5config.h.in index ded57d6..20ea728 100644 --- a/src/H5config.h.in +++ b/src/H5config.h.in @@ -349,10 +349,6 @@ /* Define if `__tm_gmtoff' is a member of `struct tm' */ #undef HAVE___TM_GMTOFF -/* Define if your system's `malloc' function returns a valid pointer for - 0-byte allocations. */ -#undef MALLOC_WORKS - /* Define if your system's `MPI_File_set_size' function works for files over 2GB. */ #undef MPI_FILE_SET_SIZE_BIG |