summaryrefslogtreecommitdiffstats
path: root/src/H5R.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/H5R.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/H5R.c')
-rw-r--r--src/H5R.c126
1 files changed, 72 insertions, 54 deletions
diff --git a/src/H5R.c b/src/H5R.c
index d96f5e6..61b45e1 100644
--- a/src/H5R.c
+++ b/src/H5R.c
@@ -17,10 +17,7 @@
/* Module Setup */
/****************/
-#define H5R_PACKAGE /*suppress error about including H5Rpkg */
-
-/* Interface initialization */
-#define H5_INTERFACE_INIT_FUNC H5R_init_interface
+#include "H5Rmodule.h" /* This source code file is part of the H5R module */
/***********/
@@ -63,6 +60,9 @@ static ssize_t H5R_get_name(H5F_t *file, hid_t lapl_id, hid_t dxpl_id, hid_t id,
/* Package Variables */
/*********************/
+/* Package initialization variable */
+hbool_t H5_PKG_INIT_VAR = FALSE;
+
/*****************************/
/* Library Private Variables */
@@ -81,39 +81,16 @@ static const H5I_class_t H5I_REFERENCE_CLS[1] = {{
NULL /* Callback routine for closing objects of this class */
}};
+/* Flag indicating "top" of interface has been initialized */
+static hbool_t H5R_top_package_initialize_s = FALSE;
-
-/*-------------------------------------------------------------------------
- * Function: H5R_init
- *
- * Purpose: Initialize the interface from some other package.
- *
- * Return: Success: non-negative
- * Failure: negative
- *
- * Programmer: Quincey Koziol
- * Thursday, September 13, 2007
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5R_init(void)
-{
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI(FAIL)
- /* FUNC_ENTER() does all the work */
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5R_init() */
/*--------------------------------------------------------------------------
NAME
- H5R_init_interface -- Initialize interface-specific information
+ H5R__init_package -- Initialize interface-specific information
USAGE
- herr_t H5R_init_interface()
+ herr_t H5R__init_package()
RETURNS
Non-negative on success/Negative on failure
@@ -121,33 +98,37 @@ DESCRIPTION
Initializes any interface-specific data or routines.
--------------------------------------------------------------------------*/
-static herr_t
-H5R_init_interface(void)
+herr_t
+H5R__init_package(void)
{
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
/* Initialize the atom group for the file IDs */
if(H5I_register_type(H5I_REFERENCE_CLS) < 0)
- HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINIT, FAIL, "unable to initialize interface");
+ HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINIT, FAIL, "unable to initialize interface")
+
+ /* Mark "top" of interface as initialized, too */
+ H5R_top_package_initialize_s = TRUE;
done:
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5R__init_package() */
/*--------------------------------------------------------------------------
NAME
- H5R_term_interface
+ H5R_top_term_package
PURPOSE
Terminate various H5R objects
USAGE
- void H5R_term_interface()
+ void H5R_top_term_package()
RETURNS
void
DESCRIPTION
- Release the atom group and any other resources allocated.
+ Release IDs for the atom group, deferring full interface shutdown
+ until later (in H5R_term_package).
GLOBAL VARIABLES
COMMENTS, BUGS, ASSUMPTIONS
Can't report errors...
@@ -155,32 +136,69 @@ done:
REVISION LOG
--------------------------------------------------------------------------*/
int
-H5R_term_interface(void)
+H5R_top_term_package(void)
{
int n = 0;
FUNC_ENTER_NOAPI_NOINIT_NOERR
- if (H5_interface_initialize_g) {
+ if(H5R_top_package_initialize_s) {
if(H5I_nmembers(H5I_REFERENCE) > 0) {
(void)H5I_clear_type(H5I_REFERENCE, FALSE, FALSE);
n++; /*H5I*/
} /* end if */
- else {
- /* Close deprecated interface */
- n += H5R__term_deprec_interface();
- /* Destroy the reference id group */
- (void)H5I_dec_type_ref(H5I_REFERENCE);
- n++; /*H5I*/
+ /* Mark closed */
+ if(0 == n)
+ H5R_top_package_initialize_s = FALSE;
+ } /* end if */
+
+ FUNC_LEAVE_NOAPI(n)
+} /* end H5R_top_term_package() */
+
+
+/*--------------------------------------------------------------------------
+ NAME
+ H5R_term_package
+ PURPOSE
+ Terminate various H5R objects
+ USAGE
+ void H5R_term_package()
+ RETURNS
+ void
+ DESCRIPTION
+ Release the atom group and any other resources allocated.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ Can't report errors...
+
+ Finishes shutting down the interface, after H5R_top_term_package()
+ is called
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+int
+H5R_term_package(void)
+{
+ int n = 0;
+
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
+
+ if(H5_PKG_INIT_VAR) {
+ /* Sanity checks */
+ HDassert(0 == H5I_nmembers(H5I_REFERENCE));
+ HDassert(FALSE == H5R_top_package_initialize_s);
+
+ /* Destroy the reference id group */
+ n += (H5I_dec_type_ref(H5I_REFERENCE) > 0);
- /* Mark closed */
- H5_interface_initialize_g = 0;
- } /* end else */
+ /* Mark closed */
+ if(0 == n)
+ H5_PKG_INIT_VAR = FALSE;
} /* end if */
FUNC_LEAVE_NOAPI(n)
-} /* end H5R_term_interface() */
+} /* end H5R_term_package() */
/*--------------------------------------------------------------------------
@@ -424,7 +442,7 @@ H5R_dereference(H5F_t *file, hid_t oapl_id, hid_t dxpl_id, H5R_type_t ref_type,
H5G_loc_t loc; /* Group location */
unsigned rc; /* Reference count of object */
H5O_type_t obj_type; /* Type of object */
- hid_t ret_value; /* Return value */
+ hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -902,9 +920,9 @@ static ssize_t
H5R_get_name(H5F_t *f, hid_t lapl_id, hid_t dxpl_id, hid_t id, H5R_type_t ref_type,
const void *_ref, char *name, size_t size)
{
- hid_t file_id = (-1); /* ID for file that the reference is in */
+ hid_t file_id = H5I_INVALID_HID; /* ID for file that the reference is in */
H5O_loc_t oloc; /* Object location describing object for reference */
- ssize_t ret_value; /* Return value */
+ ssize_t ret_value = -1; /* Return value */
FUNC_ENTER_NOAPI_NOINIT