summaryrefslogtreecommitdiffstats
path: root/src/H5E.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2015-09-14 03:58:59 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2015-09-14 03:58:59 (GMT)
commit102337449220dfc29be1cce29147704b9c760832 (patch)
tree2f57d117f2bd934eac2768be18dcc866619f390f /src/H5E.c
parentf16361d5f1dc70c344d8143270aa4aeaa867f244 (diff)
downloadhdf5-102337449220dfc29be1cce29147704b9c760832.zip
hdf5-102337449220dfc29be1cce29147704b9c760832.tar.gz
hdf5-102337449220dfc29be1cce29147704b9c760832.tar.bz2
[svn-r27768] Description:
Complete revamp of package initialization/shutdown mechanism in the library. Each package now has a single init/term routine. This new way should avoid packages being re-initialized during library shutdown and is also be _much_ more proactive about giving feedback for resource leaks internal to the library. Introduces a new "module" header file for packages in the library (e.g src/H5Fmodule.h) which sets up some necessary package configuration macros for the FUNC_ENTER/LEAVE macros. (The VFL drivers have their own slightly modified version of this header, src/H5FDdrvr_module.h) Also cleaned up a bunch of resources leaks all across the library and tests, along with addressing many warnings, as I encountered them. Tested on: MacOSX/64 10.10.5 (amazon) w/serial & parallel Linux/64 3.10.x (kituo) w/serial & parallel Linux/64 2.6.x (ostrich) w/serial
Diffstat (limited to 'src/H5E.c')
-rw-r--r--src/H5E.c140
1 files changed, 69 insertions, 71 deletions
diff --git a/src/H5E.c b/src/H5E.c
index c3c7685..4374f1d 100644
--- a/src/H5E.c
+++ b/src/H5E.c
@@ -45,10 +45,7 @@
/* Module Setup */
/****************/
-#define H5E_PACKAGE /*suppress error about including H5Epkg */
-
-/* Interface initialization */
-#define H5_INTERFACE_INIT_FUNC H5E_init_interface
+#include "H5Emodule.h" /* This source code file is part of the H5E module */
/***********/
@@ -83,6 +80,7 @@
/* Local Prototypes */
/********************/
/* Static function declarations */
+static herr_t H5E_set_default_auto(H5E_t *stk);
static H5E_cls_t *H5E_register_class(const char *cls_name, const char *lib_name,
const char *version);
static herr_t H5E_unregister_class(H5E_cls_t *cls);
@@ -100,6 +98,9 @@ static ssize_t H5E_get_num(const H5E_t *err_stack);
/* Package Variables */
/*********************/
+/* Package initialization variable */
+hbool_t H5_PKG_INIT_VAR = FALSE;
+
/*****************************/
/* Library Private Variables */
@@ -173,45 +174,7 @@ done:
/*--------------------------------------------------------------------------
- * Function: H5E_set_default_auto
- *
- * Purpose: Initialize "automatic" error stack reporting info to library
- * default
- *
- * Return: Non-negative on success/Negative on failure
- *
- * Programmer: Quincey Koziol
- * Thursday, November 1, 2007
- *
- *--------------------------------------------------------------------------
- */
-static herr_t
-H5E_set_default_auto(H5E_t *stk)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
-#ifndef H5_NO_DEPRECATED_SYMBOLS
-#ifdef H5_USE_16_API_DEFAULT
- stk->auto_op.vers = 1;
-#else /* H5_USE_16_API */
- stk->auto_op.vers = 2;
-#endif /* H5_USE_16_API_DEFAULT */
-
- stk->auto_op.func1 = stk->auto_op.func1_default = (H5E_auto1_t)H5Eprint1;
- stk->auto_op.func2 = stk->auto_op.func2_default = (H5E_auto2_t)H5Eprint2;
- stk->auto_op.is_default = TRUE;
-#else /* H5_NO_DEPRECATED_SYMBOLS */
- stk->auto_op.func2 = (H5E_auto2_t)H5Eprint2;
-#endif /* H5_NO_DEPRECATED_SYMBOLS */
-
- stk->auto_data = NULL;
-
- FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5E_set_default_auto() */
-
-
-/*--------------------------------------------------------------------------
- * Function: H5E_init_interface
+ * Function: H5E__init_package
*
* Purpose: Initialize interface-specific information
*
@@ -222,15 +185,15 @@ H5E_set_default_auto(H5E_t *stk)
*
*--------------------------------------------------------------------------
*/
-static herr_t
-H5E_init_interface(void)
+herr_t
+H5E__init_package(void)
{
H5E_cls_t *cls; /* Pointer to error class */
H5E_msg_t *msg; /* Pointer to new error message */
char lib_vers[128]; /* Buffer to constructu library version within */
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_PACKAGE
/* Initialize the atom group for the error class IDs */
if(H5I_register_type(H5I_ERRCLS_CLS) < 0)
@@ -262,11 +225,11 @@ H5E_init_interface(void)
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5E_init_interface() */
+} /* end H5E__init_package() */
/*-------------------------------------------------------------------------
- * Function: H5E_term_interface
+ * Function: H5E_term_package
*
* Purpose: Terminates the H5E interface
*
@@ -281,13 +244,13 @@ done:
*-------------------------------------------------------------------------
*/
int
-H5E_term_interface(void)
+H5E_term_package(void)
{
int n = 0;
FUNC_ENTER_NOAPI_NOINIT_NOERR
- if(H5_interface_initialize_g) {
+ if(H5_PKG_INIT_VAR) {
int64_t ncls, nmsg, nstk;
/* Check if there are any open error stacks, classes or messages */
@@ -323,22 +286,57 @@ H5E_term_interface(void)
n++; /*H5I*/
} /* end if */
else {
- /* Close deprecated interface */
- n += H5E__term_deprec_interface();
-
/* Destroy the error class, message, and stack id groups */
- (void)H5I_dec_type_ref(H5I_ERROR_STACK);
- (void)H5I_dec_type_ref(H5I_ERROR_CLASS);
- (void)H5I_dec_type_ref(H5I_ERROR_MSG);
- n++; /*H5I*/
+ n += (H5I_dec_type_ref(H5I_ERROR_STACK) > 0);
+ n += (H5I_dec_type_ref(H5I_ERROR_CLASS) > 0);
+ n += (H5I_dec_type_ref(H5I_ERROR_MSG) > 0);
/* Mark closed */
- H5_interface_initialize_g = 0;
+ if(0 == n)
+ H5_PKG_INIT_VAR = FALSE;
} /* end else */
} /* end if */
FUNC_LEAVE_NOAPI(n)
-} /* end H5E_term_interface() */
+} /* end H5E_term_package() */
+
+
+/*--------------------------------------------------------------------------
+ * Function: H5E_set_default_auto
+ *
+ * Purpose: Initialize "automatic" error stack reporting info to library
+ * default
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * Thursday, November 1, 2007
+ *
+ *--------------------------------------------------------------------------
+ */
+static herr_t
+H5E_set_default_auto(H5E_t *stk)
+{
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
+
+#ifndef H5_NO_DEPRECATED_SYMBOLS
+#ifdef H5_USE_16_API_DEFAULT
+ stk->auto_op.vers = 1;
+#else /* H5_USE_16_API */
+ stk->auto_op.vers = 2;
+#endif /* H5_USE_16_API_DEFAULT */
+
+ stk->auto_op.func1 = stk->auto_op.func1_default = (H5E_auto1_t)H5Eprint1;
+ stk->auto_op.func2 = stk->auto_op.func2_default = (H5E_auto2_t)H5Eprint2;
+ stk->auto_op.is_default = TRUE;
+#else /* H5_NO_DEPRECATED_SYMBOLS */
+ stk->auto_op.func2 = (H5E_auto2_t)H5Eprint2;
+#endif /* H5_NO_DEPRECATED_SYMBOLS */
+
+ stk->auto_data = NULL;
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5E_set_default_auto() */
#ifdef H5_HAVE_THREADSAFE
@@ -360,7 +358,7 @@ H5E_term_interface(void)
H5E_t *
H5E_get_stack(void)
{
- H5E_t *estack;
+ H5E_t *estack = NULL;
FUNC_ENTER_NOAPI_NOINIT_NOERR
@@ -371,7 +369,7 @@ H5E_get_stack(void)
#ifdef H5_HAVE_WIN_THREADS
estack = (H5E_t *)LocalAlloc(LPTR, sizeof(H5E_t)); /* Win32 has to use LocalAlloc to match the LocalFree in DllMain */
#else
- estack = (H5E_t *)H5FL_MALLOC(H5E_t);
+ estack = (H5E_t *)HDmalloc(sizeof(H5E_t));
#endif /* H5_HAVE_WIN_THREADS */
HDassert(estack);
@@ -475,8 +473,8 @@ done:
static H5E_cls_t *
H5E_register_class(const char *cls_name, const char *lib_name, const char *version)
{
- H5E_cls_t *cls = NULL; /* Pointer to error class */
- H5E_cls_t *ret_value; /* Return value */
+ H5E_cls_t *cls = NULL; /* Pointer to error class */
+ H5E_cls_t *ret_value = NULL; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -631,7 +629,7 @@ done:
static ssize_t
H5E_get_class_name(const H5E_cls_t *cls, char *name, size_t size)
{
- ssize_t len; /* Length of error class's name */
+ ssize_t len = 0; /* Length of error class's name */
FUNC_ENTER_NOAPI_NOINIT_NOERR
@@ -812,8 +810,8 @@ done:
static H5E_msg_t *
H5E_create_msg(H5E_cls_t *cls, H5E_type_t msg_type, const char *msg_str)
{
- H5E_msg_t *msg = NULL; /* Pointer to new error message */
- H5E_msg_t *ret_value; /* Return value */
+ H5E_msg_t *msg = NULL; /* Pointer to new error message */
+ H5E_msg_t *ret_value = NULL; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -967,10 +965,10 @@ done:
static H5E_t *
H5E_get_current_stack(void)
{
- H5E_t *current_stack; /* Pointer to the current error stack */
- H5E_t *estack_copy=NULL; /* Pointer to new error stack to return */
- unsigned u; /* Local index variable */
- H5E_t *ret_value; /* Return value */
+ H5E_t *current_stack; /* Pointer to the current error stack */
+ H5E_t *estack_copy = NULL; /* Pointer to new error stack to return */
+ unsigned u; /* Local index variable */
+ H5E_t *ret_value = NULL; /* Return value */
FUNC_ENTER_NOAPI_NOINIT