diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 47fc1dcf751..7bb852d2fb4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -240,7 +240,6 @@ set (H5FD_SOURCES ${HDF5_SRC_DIR}/H5FDonion_header.c ${HDF5_SRC_DIR}/H5FDonion_history.c ${HDF5_SRC_DIR}/H5FDonion_index.c - ${HDF5_SRC_DIR}/H5FDperform.c ${HDF5_SRC_DIR}/H5FDros3.c ${HDF5_SRC_DIR}/H5FDs3comms.c ${HDF5_SRC_DIR}/H5FDsec2.c diff --git a/src/H5.c b/src/H5.c index 9dc9fca1022..9da0842eb44 100644 --- a/src/H5.c +++ b/src/H5.c @@ -32,8 +32,6 @@ #include "H5SLprivate.h" /* Skip lists */ #include "H5Tprivate.h" /* Datatypes */ -#include "H5FDsec2.h" /* for H5FD_sec2_init() */ - /****************/ /* Local Macros */ /****************/ @@ -65,6 +63,9 @@ static int H5__mpi_delete_cb(MPI_Comm comm, int keyval, void *attr_val, int *fla /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ @@ -91,30 +92,31 @@ static H5_atclose_node_t *H5_atclose_head = NULL; /* Declare a free list to manage the H5_atclose_node_t struct */ H5FL_DEFINE_STATIC(H5_atclose_node_t); -/*------------------------------------------------------------------------- - * Function: H5_default_vfd_init - * - * Purpose: Initialize the default VFD. - * - * Return: Success: non-negative - * Failure: negative - *------------------------------------------------------------------------- - */ -static herr_t -H5_default_vfd_init(void) +/*-------------------------------------------------------------------------- +NAME + H5__init_package -- Initialize interface-specific information +USAGE + herr_t H5__init_package() +RETURNS + Non-negative on success/Negative on failure +DESCRIPTION + Initializes any interface-specific data or routines. +--------------------------------------------------------------------------*/ +herr_t +H5__init_package(void) { - herr_t ret_value = SUCCEED; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT + + /* Run the library initialization routine, if it hasn't already ran */ + if (!H5_INIT_GLOBAL && !H5_TERM_GLOBAL) + if (H5_init_library() < 0) + HGOTO_ERROR(H5E_LIB, H5E_CANTINIT, FAIL, "unable to initialize library"); - FUNC_ENTER_NOAPI(FAIL) - /* Load the hid_t for the default VFD for the side effect - * it has of initializing the default VFD. - */ - if (H5FD_sec2_init() == H5I_INVALID_HID) { - HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to load default VFD ID"); - } done: FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5__init_package() */ /*-------------------------------------------------------------------------- * NAME @@ -133,7 +135,6 @@ H5_default_vfd_init(void) herr_t H5_init_library(void) { - size_t i; herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) @@ -239,35 +240,26 @@ H5_init_library(void) * The dataspace interface needs to be initialized so that future IDs for * dataspaces work. */ - { - /* clang-format off */ - struct { - herr_t (*func)(void); - const char *descr; - } initializer[] = { - {H5E_init, "error"} - , {H5VL_init_phase1, "VOL"} - , {H5SL_init, "skip lists"} - , {H5FD_init, "VFD"} - , {H5_default_vfd_init, "default VFD"} - , {H5P_init_phase1, "property list"} - , {H5AC_init, "metadata caching"} - , {H5L_init, "link"} - , {H5S_init, "dataspace"} - , {H5PL_init, "plugins"} - /* Finish initializing interfaces that depend on the interfaces above */ - , {H5P_init_phase2, "property list"} - , {H5VL_init_phase2, "VOL"} - }; - - for (i = 0; i < NELMTS(initializer); i++) { - if (initializer[i].func() < 0) { - HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, - "unable to initialize %s interface", initializer[i].descr); - } - } - /* clang-format on */ - } + if (H5E_init() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize error interface"); + if (H5VL_init_phase1() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize vol interface"); + if (H5P_init_phase1() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize property list interface"); + if (H5AC_init() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize metadata caching interface"); + if (H5L_init() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize link interface"); + if (H5FS_init() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize FS interface"); + if (H5S_init() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize dataspace interface"); + + /* Finish initializing interfaces that depend on the interfaces above */ + if (H5P_init_phase2() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize property list interface"); + if (H5VL_init_phase2() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize vol interface"); /* Debugging? */ H5__debug_mask("-all"); @@ -291,11 +283,9 @@ H5_init_library(void) void H5_term_library(void) { - int pending, ntries = 0; - char loop[1024], *next = loop; - size_t i; - size_t nleft = sizeof(loop); - int nprinted; + int pending, ntries = 0, n; + size_t at = 0; + char loop[1024]; H5E_auto2_t func; /* Acquire the API lock */ @@ -337,147 +327,114 @@ H5_term_library(void) H5_atclose_head = NULL; } /* end if */ - /* clang-format off */ - /* * Terminate each interface. The termination functions return a positive * value if they do something that might affect some other interface in a * way that would necessitate some cleanup work in the other interface. */ +#define DOWN(F) \ + (((n = H5##F##_term_package()) && (at + 8) < sizeof loop) \ + ? (sprintf(loop + at, "%s%s", (at ? "," : ""), #F), at += strlen(loop + at), n) \ + : ((n > 0 && (at + 5) < sizeof loop) ? (sprintf(loop + at, "..."), at += strlen(loop + at), n) : n)) - { -#define TERMINATOR(module, wait) { \ - .func = H5##module##_term_package \ - , .name = #module \ - , .completed = false \ - , .await_prior = wait \ - } + do { + pending = 0; - /* - * Termination is ordered by the `terminator` table so the "higher" level - * packages are shut down before "lower" level packages that they - * rely on: - */ - struct { - int (*func)(void); /* function to terminate the module; returns 0 - * on success, >0 if termination was not - * completed and we should try to terminate - * some dependent modules, first. + /* Try to organize these so the "higher" level components get shut + * down before "lower" level components that they might rely on. -QAK */ - const char *name; /* name of the module */ - bool completed; /* true iff this terminator was already - * completed - */ - const bool await_prior; /* true iff all prior terminators in the - * list must complete before this - * terminator is attempted - */ - } terminator[] = { + /* Close the event sets first, so that all asynchronous operations * complete before anything else attempts to shut down. */ - TERMINATOR(ES, false) - /* Do not attempt to close down package L until after event sets - * have finished closing down. - */ - , TERMINATOR(L, true) + pending += DOWN(ES); + + /* Close down the user-facing interfaces, after the event sets */ + if (pending == 0) { + /* Close the interfaces dependent on others */ + pending += DOWN(L); + /* Close the "top" of various interfaces (IDs, etc) but don't shut * down the whole interface yet, so that the object header messages * get serialized correctly for entries in the metadata cache and the * symbol table entry in the superblock gets serialized correctly, etc. * all of which is performed in the 'F' shutdown. - * - * The tops of packages A, D, G, M, S, T do not need to wait for L - * or previous packages to finish closing down. */ - , TERMINATOR(A_top, false) - , TERMINATOR(D_top, false) - , TERMINATOR(G_top, false) - , TERMINATOR(M_top, false) - , TERMINATOR(S_top, false) - , TERMINATOR(T_top, false) + pending += DOWN(A_top); + pending += DOWN(D_top); + pending += DOWN(G_top); + pending += DOWN(M_top); + pending += DOWN(S_top); + pending += DOWN(T_top); + } /* end if */ + /* Don't shut down the file code until objects in files are shut down */ - , TERMINATOR(F, true) + if (pending == 0) + pending += DOWN(F); + /* Don't shut down the property list code until all objects that might - * use property lists are shut down - */ - , TERMINATOR(P, true) + * use property lists are shut down */ + if (pending == 0) + pending += DOWN(P); + /* Wait to shut down the "bottom" of various interfaces until the * files are closed, so pieces of the file can be serialized * correctly. - * - * Shut down the "bottom" of the attribute, dataset, group, + */ + if (pending == 0) { + /* Shut down the "bottom" of the attribute, dataset, group, * reference, dataspace, and datatype interfaces, fully closing * out the interfaces now. */ - , TERMINATOR(A, true) - , TERMINATOR(D, false) - , TERMINATOR(G, false) - , TERMINATOR(M, false) - , TERMINATOR(S, false) - , TERMINATOR(T, false) - /* Wait to shut down low-level packages like AC until after - * the preceding high-level packages have shut down. This prevents - * low-level objects from closing "out from underneath" their - * reliant high-level objects. + pending += DOWN(A); + pending += DOWN(D); + pending += DOWN(G); + pending += DOWN(M); + pending += DOWN(R); + pending += DOWN(S); + pending += DOWN(T); + } /* end if */ + + /* Don't shut down "low-level" components until "high-level" components + * have successfully shut down. This prevents property lists and IDs + * from being closed "out from underneath" of the high-level objects + * that depend on them. -QAK */ - , TERMINATOR(AC, true) + if (pending == 0) { + pending += DOWN(AC); /* Shut down the "pluggable" interfaces, before the plugin framework */ - , TERMINATOR(Z, false) - , TERMINATOR(FD, false) - , TERMINATOR(VL, false) - /* Don't shut down the plugin code until all "pluggable" interfaces - * (Z, FD, PL) are shut down - */ - , TERMINATOR(PL, true) - /* Shut down the following packages in strictly the order given - * by the table. - */ - , TERMINATOR(E, true) - , TERMINATOR(I, true) - , TERMINATOR(SL, true) - , TERMINATOR(FL, true) - , TERMINATOR(CX, true) - }; - - do { - pending = 0; - for (i = 0; i < NELMTS(terminator); i++) { - if (terminator[i].completed) - continue; - if (pending != 0 && terminator[i].await_prior) - break; - if (terminator[i].func() == 0) { - terminator[i].completed = true; - continue; - } - - /* log a package when its terminator needs to be retried */ - pending++; - nprinted = snprintf(next, nleft, "%s%s", - (next != loop) ? "," : "", terminator[i].name); - if (nprinted < 0) - continue; - if ((size_t)nprinted >= nleft) - nprinted = snprintf(next, nleft, "..."); - if (nprinted < 0 || (size_t)nprinted >= nleft) - continue; - nleft -= (size_t)nprinted; - next += nprinted; - } - } while (pending && ntries++ < 100); - - /* clang-format on */ + pending += DOWN(Z); + pending += DOWN(FD); + pending += DOWN(VL); + /* Don't shut down the plugin code until all "pluggable" interfaces (Z, FD, PL) are shut down */ + if (pending == 0) + pending += DOWN(PL); + /* Don't shut down the error code until other APIs which use it are shut down */ + if (pending == 0) + pending += DOWN(E); + /* Don't shut down the ID code until other APIs which use them are shut down */ + if (pending == 0) + pending += DOWN(I); + /* Don't shut down the skip list code until everything that uses it is down */ + if (pending == 0) + pending += DOWN(SL); + /* Don't shut down the free list code until everything that uses it is down */ + if (pending == 0) + pending += DOWN(FL); + /* Don't shut down the API context code until _everything_ else is down */ + if (pending == 0) + pending += DOWN(CX); + } /* end if */ + } while (pending && ntries++ < 100); - if (pending) { - /* Only display the error message if the user is interested in them. */ - if (func) { - fprintf(stderr, "HDF5: infinite loop closing library\n"); - fprintf(stderr, " %s\n", loop); + if (pending) { + /* Only display the error message if the user is interested in them. */ + if (func) { + fprintf(stderr, "HDF5: infinite loop closing library\n"); + fprintf(stderr, " %s\n", loop); #ifndef NDEBUG - abort(); + abort(); #endif - } } } diff --git a/src/H5AC.c b/src/H5AC.c index 5f9df26aba1..f7bd2450991 100644 --- a/src/H5AC.c +++ b/src/H5AC.c @@ -67,6 +67,9 @@ static herr_t H5AC__verify_tag(const H5AC_class_t *type); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ @@ -134,7 +137,26 @@ H5AC_init(void) { herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) + /* FUNC_ENTER() does all the work */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5AC_init() */ + +/*------------------------------------------------------------------------- + * Function: H5AC__init_package + * + * Purpose: Initialize interface-specific information + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5AC__init_package(void) +{ + FUNC_ENTER_PACKAGE_NOERR #ifdef H5_HAVE_PARALLEL /* check whether to enable strict collective function calling @@ -151,8 +173,8 @@ H5AC_init(void) } #endif /* H5_HAVE_PARALLEL */ - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5AC_init() */ + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5AC__init_package() */ /*------------------------------------------------------------------------- * Function: H5AC_term_package @@ -170,6 +192,10 @@ H5AC_term_package(void) { FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) + /* Reset interface initialization flag */ + H5_PKG_INIT_VAR = FALSE; + FUNC_LEAVE_NOAPI(0) } /* end H5AC_term_package() */ diff --git a/src/H5ACmodule.h b/src/H5ACmodule.h index 1ce26f6b15f..25b80040418 100644 --- a/src/H5ACmodule.h +++ b/src/H5ACmodule.h @@ -24,5 +24,6 @@ #define H5AC_MODULE #define H5_MY_PKG H5AC #define H5_MY_PKG_ERR H5E_CACHE +#define H5_MY_PKG_INIT YES #endif /* H5ACmodule_H */ diff --git a/src/H5ACproxy_entry.c b/src/H5ACproxy_entry.c index 5ad1673dd5c..434ea2e464f 100644 --- a/src/H5ACproxy_entry.c +++ b/src/H5ACproxy_entry.c @@ -399,7 +399,7 @@ H5AC_proxy_entry_dest(H5AC_proxy_entry_t *pentry) { herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity checks */ assert(pentry); @@ -411,6 +411,7 @@ H5AC_proxy_entry_dest(H5AC_proxy_entry_t *pentry) /* Free the proxy entry object */ pentry = H5FL_FREE(H5AC_proxy_entry_t, pentry); +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5AC_proxy_entry_dest() */ diff --git a/src/H5Aint.c b/src/H5Aint.c index a459402f589..ffeea5e1d3f 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -88,6 +88,9 @@ static herr_t H5A__iterate_common(hid_t loc_id, H5_index_t idx_type, H5_iter_ord /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Format version bounds for attribute */ const unsigned H5O_attr_ver_bounds[] = { H5O_ATTR_VERSION_1, /* H5F_LIBVER_EARLIEST */ @@ -127,6 +130,9 @@ static const H5I_class_t H5I_ATTR_CLS[1] = {{ (H5I_free_t)H5A__close_cb /* Callback routine for closing objects of this class */ }}; +/* Flag indicating "top" of interface has been initialized */ +static hbool_t H5A_top_package_initialize_s = FALSE; + /*------------------------------------------------------------------------- * Function: H5A_init * @@ -143,6 +149,30 @@ H5A_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 H5A_init() */ + +/*-------------------------------------------------------------------------- +NAME + H5A__init_package -- Initialize interface-specific information +USAGE + herr_t H5A__init_package() + +RETURNS + Non-negative on success/Negative on failure +DESCRIPTION + Initializes any interface-specific data or routines. + +--------------------------------------------------------------------------*/ +herr_t +H5A__init_package(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE /* * Create attribute ID type. @@ -150,9 +180,12 @@ H5A_init(void) if (H5I_register_type(H5I_ATTR_CLS) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to initialize interface"); + /* Mark "top" of interface as initialized, too */ + H5A_top_package_initialize_s = TRUE; + done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5A_init() */ +} /* end H5A__init_package() */ /*-------------------------------------------------------------------------- NAME @@ -178,11 +211,17 @@ H5A_top_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5A_top_package_initialize_s) { if (H5I_nmembers(H5I_ATTR) > 0) { (void)H5I_clear_type(H5I_ATTR, false, false); n++; /*H5I*/ } /* end if */ + /* Mark closed */ + if (0 == n) + H5A_top_package_initialize_s = FALSE; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* H5A_top_term_package() */ @@ -212,11 +251,18 @@ H5A_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR - /* Sanity checks */ - assert(0 == H5I_nmembers(H5I_ATTR)); + if (H5_PKG_INIT_VAR) { + /* Sanity checks */ + assert(0 == H5I_nmembers(H5I_ATTR)); + assert(FALSE == H5A_top_package_initialize_s); + + /* Destroy the attribute object id group */ + n += (H5I_dec_type_ref(H5I_ATTR) > 0); - /* Destroy the attribute object id group */ - n += (H5I_dec_type_ref(H5I_ATTR) > 0); + /* Mark closed */ + if (0 == n) + H5_PKG_INIT_VAR = FALSE; + } /* end if */ FUNC_LEAVE_NOAPI(n) } /* H5A_term_package() */ @@ -1094,9 +1140,7 @@ H5A__get_create_plist(H5A_t *attr) herr_t H5A__get_info(const H5A_t *attr, H5A_info_t *ainfo) { - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_PACKAGE_NOERR /* Check args */ assert(attr); @@ -1114,7 +1158,7 @@ H5A__get_info(const H5A_t *attr, H5A_info_t *ainfo) ainfo->corder = attr->shared->crt_idx; } /* end else */ - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5A__get_info() */ /*------------------------------------------------------------------------- @@ -1318,13 +1362,14 @@ H5A_oloc(H5A_t *attr) { H5O_loc_t *ret_value = NULL; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(NULL) assert(attr); /* Set return value */ ret_value = &(attr->oloc); +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5A_oloc() */ @@ -1345,13 +1390,14 @@ H5A_nameof(H5A_t *attr) { H5G_name_t *ret_value = NULL; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(NULL) assert(attr); /* Set return value */ ret_value = &(attr->path); +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5A_nameof() */ @@ -1370,13 +1416,14 @@ H5A_type(const H5A_t *attr) { H5T_t *ret_value = NULL; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(NULL) assert(attr); /* Set return value */ ret_value = attr->shared->dt; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5A_type() */ @@ -1434,6 +1481,7 @@ H5A__exists_by_name(H5G_loc_t loc, const char *obj_name, const char *attr_name, * into table. * * Return: Non-negative on success/Negative on failure + * *------------------------------------------------------------------------- */ static herr_t diff --git a/src/H5Amodule.h b/src/H5Amodule.h index 42715535367..b19550d14d2 100644 --- a/src/H5Amodule.h +++ b/src/H5Amodule.h @@ -24,6 +24,7 @@ #define H5A_MODULE #define H5_MY_PKG H5A #define H5_MY_PKG_ERR H5E_ATTR +#define H5_MY_PKG_INIT YES /** \page H5A_UG HDF5 Attributes * diff --git a/src/H5B.c b/src/H5B.c index 30e39ef71a6..10e320c3dc9 100644 --- a/src/H5B.c +++ b/src/H5B.c @@ -153,6 +153,9 @@ static H5B_t *H5B__copy(const H5B_t *old_bt); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Declare a free list to manage the haddr_t sequence information */ H5FL_SEQ_DEFINE(haddr_t); diff --git a/src/H5B2.c b/src/H5B2.c index f49689911dc..d2140f77165 100644 --- a/src/H5B2.c +++ b/src/H5B2.c @@ -59,6 +59,9 @@ /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* v2 B-tree client ID to class mapping */ /* Remember to add client ID to H5B2_subid_t in H5B2private.h when adding a new diff --git a/src/H5B2module.h b/src/H5B2module.h index 8eaea2f266d..e5cf333680c 100644 --- a/src/H5B2module.h +++ b/src/H5B2module.h @@ -24,5 +24,6 @@ #define H5B2_MODULE #define H5_MY_PKG H5B2 #define H5_MY_PKG_ERR H5E_BTREE +#define H5_MY_PKG_INIT NO #endif /* H5B2module_H */ diff --git a/src/H5Bmodule.h b/src/H5Bmodule.h index 0ded7562a7f..52b7b5a62cb 100644 --- a/src/H5Bmodule.h +++ b/src/H5Bmodule.h @@ -24,5 +24,6 @@ #define H5B_MODULE #define H5_MY_PKG H5B #define H5_MY_PKG_ERR H5E_BTREE +#define H5_MY_PKG_INIT NO #endif /* H5Bmodule_H */ diff --git a/src/H5C.c b/src/H5C.c index 44d499df964..52ae2be86c9 100644 --- a/src/H5C.c +++ b/src/H5C.c @@ -84,6 +84,9 @@ /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Declare a free list to manage the tag info struct */ H5FL_DEFINE(H5C_tag_info_t); diff --git a/src/H5CX.c b/src/H5CX.c index 643c77f9c31..7c61b720980 100644 --- a/src/H5CX.c +++ b/src/H5CX.c @@ -449,6 +449,9 @@ static H5CX_node_t *H5CX__pop_common(bool update_dxpl_props); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*******************/ /* Local Variables */ /*******************/ @@ -481,17 +484,18 @@ H5FL_DEFINE_STATIC(H5CX_node_t); /* Declare a static free list to manage H5CX_state_t structs */ H5FL_DEFINE_STATIC(H5CX_state_t); -/*------------------------------------------------------------------------- - * Function: H5CX_init - * - * Purpose: Initialize the interface from some other layer. - * - * Return: Success: non-negative - * Failure: negative - *------------------------------------------------------------------------- - */ +/*-------------------------------------------------------------------------- +NAME + H5CX__init_package -- Initialize interface-specific information +USAGE + herr_t H5CX__init_package() +RETURNS + Non-negative on success/Negative on failure +DESCRIPTION + Initializes any interface-specific data or routines. +--------------------------------------------------------------------------*/ herr_t -H5CX_init(void) +H5CX__init_package(void) { H5P_genplist_t *dx_plist; /* Data transfer property list */ H5P_genplist_t *lc_plist; /* Link creation property list */ @@ -501,7 +505,7 @@ H5CX_init(void) H5P_genplist_t *fa_plist; /* File access property list */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(FAIL) + FUNC_ENTER_PACKAGE /* Reset the "default DXPL cache" information */ memset(&H5CX_def_dxpl_cache, 0, sizeof(H5CX_dxpl_cache_t)); @@ -685,9 +689,10 @@ H5CX_init(void) if (H5P_get(fa_plist, H5F_ACS_LIBVER_HIGH_BOUND_NAME, &H5CX_def_fapl_cache.high_bound) < 0) HGOTO_ERROR(H5E_CONTEXT, H5E_CANTGET, FAIL, "Can't retrieve dataset minimize flag"); + done: FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5CX__init_package() */ /*------------------------------------------------------------------------- * Function: H5CX_term_package @@ -705,6 +710,7 @@ H5CX_term_package(void) { FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { H5CX_node_t *cnode; /* Context node */ /* Pop the top context node from the stack */ @@ -719,6 +725,9 @@ H5CX_term_package(void) H5CX_head_g = NULL; #endif /* H5_HAVE_THREADSAFE */ + H5_PKG_INIT_VAR = false; + } /* end if */ + FUNC_LEAVE_NOAPI(0) } /* end H5CX_term_package() */ @@ -736,7 +745,7 @@ H5CX_pushed(void) { H5CX_node_t **head = NULL; /* Pointer to head of API context list */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI_NOINIT_NOERR head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ assert(head); @@ -1201,7 +1210,7 @@ H5CX_set_libver_bounds(H5F_t *f) H5CX_node_t **head = NULL; /* Pointer to head of API context list */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ @@ -1215,6 +1224,7 @@ H5CX_set_libver_bounds(H5F_t *f) (*head)->ctx.low_bound_valid = true; (*head)->ctx.high_bound_valid = true; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5CX_set_libver_bounds() */ @@ -1463,7 +1473,7 @@ H5CX_set_vol_wrap_ctx(void *vol_wrap_ctx) H5CX_node_t **head = NULL; /* Pointer to head of API context list */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ @@ -1475,6 +1485,7 @@ H5CX_set_vol_wrap_ctx(void *vol_wrap_ctx) /* Mark the value as valid */ (*head)->ctx.vol_wrap_ctx_valid = true; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5CX_set_vol_wrap_ctx() */ @@ -1493,7 +1504,7 @@ H5CX_set_vol_connector_prop(const H5VL_connector_prop_t *vol_connector_prop) H5CX_node_t **head = NULL; /* Pointer to head of API context list */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ @@ -1505,6 +1516,7 @@ H5CX_set_vol_connector_prop(const H5VL_connector_prop_t *vol_connector_prop) /* Mark the value as valid */ (*head)->ctx.vol_connector_prop_valid = true; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5CX_set_vol_connector_prop() */ @@ -1618,7 +1630,7 @@ H5CX_get_vol_connector_prop(H5VL_connector_prop_t *vol_connector_prop) H5CX_node_t **head = NULL; /* Pointer to head of API context list */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ assert(vol_connector_prop); @@ -1632,6 +1644,7 @@ H5CX_get_vol_connector_prop(H5VL_connector_prop_t *vol_connector_prop) else memset(vol_connector_prop, 0, sizeof(H5VL_connector_prop_t)); +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5CX_get_vol_connector_prop() */ @@ -1734,7 +1747,7 @@ H5CX_get_mpi_coll_datatypes(MPI_Datatype *btype, MPI_Datatype *ftype) H5CX_node_t **head = NULL; /* Pointer to head of API context list */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ assert(btype); @@ -1746,6 +1759,7 @@ H5CX_get_mpi_coll_datatypes(MPI_Datatype *btype, MPI_Datatype *ftype) *btype = (*head)->ctx.btype; *ftype = (*head)->ctx.ftype; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5CX_get_mpi_coll_datatypes() */ @@ -2954,10 +2968,9 @@ herr_t H5CX_set_mpi_coll_datatypes(MPI_Datatype btype, MPI_Datatype ftype) { H5CX_node_t **head = NULL; /* Pointer to head of API context list */ - herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ @@ -2967,6 +2980,7 @@ H5CX_set_mpi_coll_datatypes(MPI_Datatype btype, MPI_Datatype ftype) (*head)->ctx.btype = btype; (*head)->ctx.ftype = ftype; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5CX_set_mpi_coll_datatypes() */ @@ -2985,7 +2999,7 @@ H5CX_set_io_xfer_mode(H5FD_mpio_xfer_t io_xfer_mode) H5CX_node_t **head = NULL; /* Pointer to head of API context list */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ @@ -2997,6 +3011,7 @@ H5CX_set_io_xfer_mode(H5FD_mpio_xfer_t io_xfer_mode) /* Mark the value as valid */ (*head)->ctx.io_xfer_mode_valid = true; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5CX_set_io_xfer_mode() */ @@ -3015,7 +3030,7 @@ H5CX_set_mpio_coll_opt(H5FD_mpio_collective_opt_t mpio_coll_opt) H5CX_node_t **head = NULL; /* Pointer to head of API context list */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ @@ -3027,6 +3042,7 @@ H5CX_set_mpio_coll_opt(H5FD_mpio_collective_opt_t mpio_coll_opt) /* Mark the value as valid */ (*head)->ctx.mpio_coll_opt_valid = true; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5CX_set_mpio_coll_opt() */ @@ -3097,7 +3113,7 @@ H5CX_set_vlen_alloc_info(H5MM_allocate_t alloc_func, void *alloc_info, H5MM_free H5CX_node_t **head = NULL; /* Pointer to head of API context list */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ @@ -3112,6 +3128,7 @@ H5CX_set_vlen_alloc_info(H5MM_allocate_t alloc_func, void *alloc_info, H5MM_free /* Mark the value as valid */ (*head)->ctx.vl_alloc_info_valid = true; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5CX_set_vlen_alloc_info() */ @@ -3130,7 +3147,7 @@ H5CX_set_nlinks(size_t nlinks) H5CX_node_t **head = NULL; /* Pointer to head of API context list */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ @@ -3142,6 +3159,7 @@ H5CX_set_nlinks(size_t nlinks) /* Mark the value as valid */ (*head)->ctx.nlinks_valid = true; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5CX_set_nlinks() */ diff --git a/src/H5CXmodule.h b/src/H5CXmodule.h index ffb4804ab57..e82d1199605 100644 --- a/src/H5CXmodule.h +++ b/src/H5CXmodule.h @@ -24,5 +24,6 @@ #define H5CX_MODULE #define H5_MY_PKG H5CX #define H5_MY_PKG_ERR H5E_CONTEXT +#define H5_MY_PKG_INIT YES #endif /* H5CXmodule_H */ diff --git a/src/H5CXprivate.h b/src/H5CXprivate.h index 2a49d9ef031..1e4301fc40d 100644 --- a/src/H5CXprivate.h +++ b/src/H5CXprivate.h @@ -159,8 +159,6 @@ H5_DLL herr_t H5CX_set_vlen_alloc_info(H5MM_allocate_t alloc_func, void *alloc_i /* "Setter" routines for LAPL properties cached in API context */ H5_DLL herr_t H5CX_set_nlinks(size_t nlinks); -H5_DLL herr_t H5CX_init(void); - /* "Setter" routines for cached DXPL properties that must be returned to application */ H5_DLL void H5CX_set_no_selection_io_cause(uint32_t no_selection_io_cause); diff --git a/src/H5Cmodule.h b/src/H5Cmodule.h index 64c5279d92f..eebd6abc970 100644 --- a/src/H5Cmodule.h +++ b/src/H5Cmodule.h @@ -24,5 +24,6 @@ #define H5C_MODULE #define H5_MY_PKG H5C #define H5_MY_PKG_ERR H5E_CACHE +#define H5_MY_PKG_INIT NO #endif /* H5Cmodule_H */ diff --git a/src/H5D.c b/src/H5D.c index a50a2aceda6..90f5af26cad 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -63,6 +63,9 @@ static herr_t H5D__set_extent_api_common(hid_t dset_id, const hsize_t size[], vo /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ diff --git a/src/H5Dint.c b/src/H5Dint.c index 700d8306604..d9ebfc2c857 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -140,6 +140,9 @@ static const H5I_class_t H5I_DATASET_CLS[1] = {{ (H5I_free_t)H5D__close_cb /* Callback routine for closing objects of this class */ }}; +/* Flag indicating "top" of interface has been initialized */ +static bool H5D_top_package_initialize_s = false; + /* Prefixes of VDS and external file from the environment variables * HDF5_EXTFILE_PREFIX and HDF5_VDS_PREFIX */ static const char *H5D_prefix_ext_env = NULL; @@ -158,10 +161,37 @@ static const char *H5D_prefix_vds_env = NULL; herr_t H5D_init(void) { - H5P_genplist_t *def_dcpl; /* Default Dataset Creation Property list */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) + /* FUNC_ENTER() does all the work */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_init() */ + +/*-------------------------------------------------------------------------- +NAME + H5D__init_package -- Initialize interface-specific information +USAGE + herr_t H5D__init_package() + +RETURNS + Non-negative on success/Negative on failure +DESCRIPTION + Initializes any interface-specific data or routines. +NOTES + Care must be taken when using the H5P functions, since they can cause + a deadlock in the library when the library is attempting to terminate -QAK + +--------------------------------------------------------------------------*/ +herr_t +H5D__init_package(void) +{ + H5P_genplist_t *def_dcpl; /* Default Dataset Creation Property list */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE /* Initialize the ID group for the dataset IDs */ if (H5I_register_type(H5I_DATASET_CLS) < 0) @@ -191,13 +221,16 @@ H5D_init(void) if (H5P_get(def_dcpl, H5O_CRT_PIPELINE_NAME, &H5D_def_dset.dcpl_cache.pline) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't retrieve pipeline filter"); + /* Mark "top" of interface as initialized, too */ + H5D_top_package_initialize_s = true; + /* Retrieve the prefixes of VDS and external file from the environment variable */ H5D_prefix_vds_env = getenv("HDF5_VDS_PREFIX"); H5D_prefix_ext_env = getenv("HDF5_EXTFILE_PREFIX"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5D_init() */ +} /* end H5D__init_package() */ /*------------------------------------------------------------------------- * Function: H5D_top_term_package @@ -216,6 +249,7 @@ H5D_top_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5D_top_package_initialize_s) { if (H5I_nmembers(H5I_DATASET) > 0) { /* The dataset API uses the "force" flag set to true because it * is using the "file objects" (H5FO) API functions to track open @@ -241,7 +275,12 @@ H5D_top_term_package(void) */ (void)H5I_clear_type(H5I_DATASET, true, false); n++; /*H5I*/ - } + } /* end if */ + + /* Mark closed */ + if (0 == n) + H5D_top_package_initialize_s = false; + } /* end if */ FUNC_LEAVE_NOAPI(n) } /* end H5D_top_term_package() */ @@ -266,12 +305,19 @@ H5D_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { /* Sanity checks */ assert(0 == H5I_nmembers(H5I_DATASET)); + assert(FALSE == H5D_top_package_initialize_s); /* Destroy the dataset object id group */ n += (H5I_dec_type_ref(H5I_DATASET) > 0); + /* Mark closed */ + if (0 == n) + H5_PKG_INIT_VAR = false; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* end H5D_term_package() */ diff --git a/src/H5Dmodule.h b/src/H5Dmodule.h index 96c5b1a704e..d6f99551745 100644 --- a/src/H5Dmodule.h +++ b/src/H5Dmodule.h @@ -24,6 +24,7 @@ #define H5D_MODULE #define H5_MY_PKG H5D #define H5_MY_PKG_ERR H5E_DATASET +#define H5_MY_PKG_INIT YES /** \page H5D_UG HDF5 Datasets * diff --git a/src/H5Dmpio.c b/src/H5Dmpio.c index 84a0f25356f..6db0f8c043a 100644 --- a/src/H5Dmpio.c +++ b/src/H5Dmpio.c @@ -2716,13 +2716,16 @@ H5D__cmp_piece_addr(const void *piece_info1, const void *piece_info2) { haddr_t addr1; haddr_t addr2; + int ret_value = 0; FUNC_ENTER_PACKAGE_NOERR addr1 = (*((const H5D_piece_info_t *const *)piece_info1))->faddr; addr2 = (*((const H5D_piece_info_t *const *)piece_info2))->faddr; - FUNC_LEAVE_NOAPI(H5_addr_cmp(addr1, addr2)) + ret_value = H5_addr_cmp(addr1, addr2); + + FUNC_LEAVE_NOAPI(ret_value) } /* end H5D__cmp_chunk_addr() */ /*------------------------------------------------------------------------- @@ -2746,7 +2749,7 @@ H5D__cmp_filtered_collective_io_info_entry(const void *filtered_collective_io_in const H5D_filtered_collective_chunk_info_t *entry2; haddr_t addr1 = HADDR_UNDEF; haddr_t addr2 = HADDR_UNDEF; - int ret_value; + int ret_value = 0; FUNC_ENTER_PACKAGE_NOERR @@ -2803,7 +2806,7 @@ H5D__cmp_chunk_redistribute_info(const void *_entry1, const void *_entry2) const H5D_chunk_redistribute_info_t *entry2; haddr_t oloc_addr1; haddr_t oloc_addr2; - int ret_value; + int ret_value = 0; FUNC_ENTER_PACKAGE_NOERR @@ -2865,7 +2868,7 @@ H5D__cmp_chunk_redistribute_info_orig_owner(const void *_entry1, const void *_en const H5D_chunk_redistribute_info_t *entry2; int owner1 = -1; int owner2 = -1; - int ret_value; + int ret_value = 0; FUNC_ENTER_PACKAGE_NOERR diff --git a/src/H5Dvirtual.c b/src/H5Dvirtual.c index ac31231b1e8..c3b42010f20 100644 --- a/src/H5Dvirtual.c +++ b/src/H5Dvirtual.c @@ -1260,7 +1260,7 @@ H5D_virtual_free_parsed_name(H5O_storage_virtual_name_seg_t *name_seg) H5O_storage_virtual_name_seg_t *next_seg; herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Walk name segments, freeing them */ while (name_seg) { @@ -1270,6 +1270,7 @@ H5D_virtual_free_parsed_name(H5O_storage_virtual_name_seg_t *name_seg) name_seg = next_seg; } /* end while */ +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5D_virtual_free_parsed_name() */ diff --git a/src/H5E.c b/src/H5E.c index f1b865e7c17..0a5b68992fe 100644 --- a/src/H5E.c +++ b/src/H5E.c @@ -73,6 +73,9 @@ /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Declare extern the free list to manage the H5E_stack_t struct */ H5FL_EXTERN(H5E_stack_t); diff --git a/src/H5EA.c b/src/H5EA.c index 82b7da6cefa..63cf77eeb31 100644 --- a/src/H5EA.c +++ b/src/H5EA.c @@ -72,6 +72,9 @@ static H5EA_t *H5EA__new(H5F_t *f, haddr_t ea_addr, bool from_open, void *ctx_ud /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Extensible array client ID to class mapping */ /* Remember to add client ID to H5EA_cls_id_t in H5EAprivate.h when adding a new diff --git a/src/H5EAmodule.h b/src/H5EAmodule.h index f992393ed56..86d854663f8 100644 --- a/src/H5EAmodule.h +++ b/src/H5EAmodule.h @@ -24,5 +24,6 @@ #define H5EA_MODULE #define H5_MY_PKG H5EA #define H5_MY_PKG_ERR H5E_EARRAY +#define H5_MY_PKG_INIT NO #endif /* H5EAmodule_H */ diff --git a/src/H5ESint.c b/src/H5ESint.c index dab683913d6..9130dc73609 100644 --- a/src/H5ESint.c +++ b/src/H5ESint.c @@ -102,6 +102,9 @@ static int H5ES__close_failed_cb(H5ES_event_t *ev, void *_ctx); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ @@ -122,20 +125,22 @@ static const H5I_class_t H5I_EVENTSET_CLS[1] = {{ H5FL_DEFINE_STATIC(H5ES_t); /*------------------------------------------------------------------------- - * Function: H5ES_init + * Function: H5ES__init_package + * + * Purpose: Initializes any interface-specific data or routines. + * + * Return: Non-negative on success / Negative on failure * * Purpose: Initialize the interface from some other layer. * - * Return: Success: non-negative - * Failure: negative *------------------------------------------------------------------------- */ herr_t -H5ES_init(void) +H5ES__init_package(void) { herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(FAIL) + FUNC_ENTER_PACKAGE /* Initialize the ID group for the event set IDs */ if (H5I_register_type(H5I_EVENTSET_CLS) < 0) @@ -143,7 +148,7 @@ H5ES_init(void) done: FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5ES__init_package() */ /*------------------------------------------------------------------------- * Function: H5ES_term_package @@ -163,9 +168,15 @@ H5ES_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { /* Destroy the event set ID group */ n += (H5I_dec_type_ref(H5I_EVENTSET) > 0); + /* Mark closed */ + if (0 == n) + H5_PKG_INIT_VAR = false; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* end H5ES_term_package() */ diff --git a/src/H5ESmodule.h b/src/H5ESmodule.h index f63852db384..772d33632c1 100644 --- a/src/H5ESmodule.h +++ b/src/H5ESmodule.h @@ -24,6 +24,7 @@ #define H5ES_MODULE #define H5_MY_PKG H5ES #define H5_MY_PKG_ERR H5E_EVENTSET +#define H5_MY_PKG_INIT YES /** \page H5ES_UG HDF5 Event Set * @todo Under Construction diff --git a/src/H5ESprivate.h b/src/H5ESprivate.h index 52392fbfd44..f7e009601c5 100644 --- a/src/H5ESprivate.h +++ b/src/H5ESprivate.h @@ -49,6 +49,5 @@ typedef struct H5ES_t H5ES_t; /***************************************/ herr_t H5ES_insert(hid_t es_id, H5VL_t *connector, void *token, const char *caller, const char *caller_args, ...); -H5_DLL herr_t H5ES_init(void); #endif /* H5ESprivate_H */ diff --git a/src/H5Eint.c b/src/H5Eint.c index d01668e731d..19599376a3f 100644 --- a/src/H5Eint.c +++ b/src/H5Eint.c @@ -228,6 +228,30 @@ H5E_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 H5E_init() */ + +/*-------------------------------------------------------------------------- + * Function: H5E__init_package + * + * Purpose: Initialize interface-specific information + * + * Return: SUCCEED/FAIL + * + * Programmer: Raymond Lu + * Friday, July 11, 2003 + * + *-------------------------------------------------------------------------- + */ +herr_t +H5E__init_package(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE /* Initialize the ID group for the error class IDs */ if (H5I_register_type(H5I_ERRCLS_CLS) < 0) @@ -254,7 +278,7 @@ H5E_init(void) done: FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5E__init_package() */ /*------------------------------------------------------------------------- * Function: H5E_term_package @@ -275,6 +299,7 @@ H5E_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { int64_t ncls, nmsg, nstk; /* Check if there are any open error stacks, classes or messages */ @@ -329,7 +354,11 @@ H5E_term_package(void) n += (H5I_dec_type_ref(H5I_ERROR_CLASS) > 0); n += (H5I_dec_type_ref(H5I_ERROR_MSG) > 0); + /* Mark closed */ + if (0 == n) + H5_PKG_INIT_VAR = false; } /* end else */ + } /* end if */ FUNC_LEAVE_NOAPI(n) } /* end H5E_term_package() */ @@ -1774,7 +1803,7 @@ H5E_dump_api_stack(void) H5E_stack_t *estack = H5E__get_my_stack(); herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) assert(estack); @@ -1792,6 +1821,7 @@ H5E_dump_api_stack(void) } /* end else */ #endif /* H5_NO_DEPRECATED_SYMBOLS */ +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5E_dump_api_stack() */ @@ -1823,7 +1853,7 @@ H5E_pause_stack(void) { H5E_stack_t *estack = H5E__get_my_stack(); - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI_NOINIT_NOERR assert(estack); @@ -1861,7 +1891,7 @@ H5E_resume_stack(void) { H5E_stack_t *estack = H5E__get_my_stack(); - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI_NOINIT_NOERR assert(estack); assert(estack->paused); diff --git a/src/H5Emodule.h b/src/H5Emodule.h index f46456a1369..e357b9cc6cc 100644 --- a/src/H5Emodule.h +++ b/src/H5Emodule.h @@ -24,6 +24,7 @@ #define H5E_MODULE #define H5_MY_PKG H5E #define H5_MY_PKG_ERR H5E_ERROR +#define H5_MY_PKG_INIT YES /** \page H5E_UG HDF5 Error Handling * diff --git a/src/H5FA.c b/src/H5FA.c index d30ea60cce3..cbc8d3df6fb 100644 --- a/src/H5FA.c +++ b/src/H5FA.c @@ -61,6 +61,9 @@ static H5FA_t *H5FA__new(H5F_t *f, haddr_t fa_addr, bool from_open, void *ctx_ud /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Fixed array client ID to class mapping */ /* Remember to add client ID to H5FA_cls_id_t in H5FAprivate.h when adding a new diff --git a/src/H5FAmodule.h b/src/H5FAmodule.h index 8ef75820d57..cbd7726c31b 100644 --- a/src/H5FAmodule.h +++ b/src/H5FAmodule.h @@ -24,5 +24,6 @@ #define H5FA_MODULE #define H5_MY_PKG H5FA #define H5_MY_PKG_ERR H5E_FARRAY +#define H5_MY_PKG_INIT NO #endif /* H5FAmodule_H */ diff --git a/src/H5FD.c b/src/H5FD.c index a6f35ad6a87..c45d0c269b1 100644 --- a/src/H5FD.c +++ b/src/H5FD.c @@ -59,6 +59,9 @@ static herr_t H5FD__query(const H5FD_t *f, unsigned long *flags /*out*/); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ @@ -90,20 +93,20 @@ static const H5I_class_t H5I_VFL_CLS[1] = {{ }}; /*------------------------------------------------------------------------- - * Function: H5FD_init + * Function: H5FD__init_package + * + * Purpose: Initialize the virtual file layer. * - * Purpose: Initialize the interface from some other layer. + * Return: SUCCEED/FAIL * - * Return: Success: non-negative - * Failure: negative *------------------------------------------------------------------------- */ herr_t -H5FD_init(void) +H5FD__init_package(void) { herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(FAIL) + FUNC_ENTER_PACKAGE if (H5I_register_type(H5I_VFL_CLS) < 0) HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize interface"); @@ -113,7 +116,7 @@ H5FD_init(void) done: FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5FD__init_package() */ /*------------------------------------------------------------------------- * Function: H5FD_term_package @@ -137,6 +140,7 @@ H5FD_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { if (H5I_nmembers(H5I_VFL) > 0) { (void)H5I_clear_type(H5I_VFL, false, false); n++; /*H5I*/ @@ -144,7 +148,12 @@ H5FD_term_package(void) else { /* Destroy the VFL driver ID group */ n += (H5I_dec_type_ref(H5I_VFL) > 0); + + /* Mark closed */ + if (0 == n) + H5_PKG_INIT_VAR = false; } /* end else */ + } /* end if */ FUNC_LEAVE_NOAPI(n) } /* end H5FD_term_package() */ @@ -154,7 +163,7 @@ H5FD_term_package(void) * * Purpose: Frees a file driver class struct and returns an indication of * success. This function is used as the free callback for the - * virtual file layer object identifiers (cf H5FD_init). + * virtual file layer object identifiers (cf H5FD__init_package). * * Return: SUCCEED/FAIL * @@ -441,7 +450,7 @@ H5FD_sb_size(H5FD_t *file) { hsize_t ret_value = 0; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(0) /* Sanity checks */ assert(file); @@ -451,6 +460,7 @@ H5FD_sb_size(H5FD_t *file) if (file->cls->sb_size) ret_value = (file->cls->sb_size)(file); +done: FUNC_LEAVE_NOAPI(ret_value) } @@ -578,7 +588,7 @@ H5FD_fapl_get(H5FD_t *file) { void *ret_value = NULL; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(NULL) /* Sanity checks */ assert(file); @@ -588,6 +598,7 @@ H5FD_fapl_get(H5FD_t *file) if (file->cls->fapl_get) ret_value = (file->cls->fapl_get)(file); +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_fapl_get() */ @@ -945,7 +956,7 @@ H5FD_cmp(const H5FD_t *f1, const H5FD_t *f2) { int ret_value = -1; /* Return value */ - FUNC_ENTER_NOAPI_NOERR /* return value is arbitrary */ + FUNC_ENTER_NOAPI(-1) /* return value is arbitrary */ if ((!f1 || !f1->cls) && (!f2 || !f2->cls)) HGOTO_DONE(0); @@ -1299,7 +1310,7 @@ H5FD_get_maxaddr(const H5FD_t *file) { haddr_t ret_value = HADDR_UNDEF; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(HADDR_UNDEF) /* Sanity checks */ assert(file); @@ -1307,6 +1318,7 @@ H5FD_get_maxaddr(const H5FD_t *file) /* Set return value */ ret_value = file->maxaddr; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_get_maxaddr() */ diff --git a/src/H5FDcore.c b/src/H5FDcore.c index a05b1d037f0..db48e9596f8 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -443,23 +443,21 @@ H5FD__core_get_default_config(void) } /* end H5FD__core_get_default_config() */ /*------------------------------------------------------------------------- - * Function: H5FD_core_init + * Function: H5FD__init_package * - * Purpose: Initialize this driver by registering the driver with the - * library. + * Purpose: Initializes any interface-specific data or routines. * - * Return: Success: The driver ID for the core driver - * Failure: H5I_INVALID_HID + * Return: Non-negative on success/Negative on failure * *------------------------------------------------------------------------- */ -hid_t -H5FD_core_init(void) +static herr_t +H5FD__init_package(void) { - char *lock_env_var = NULL; /* Environment variable pointer */ - hid_t ret_value = H5I_INVALID_HID; /* Return value */ + char * lock_env_var = NULL; /* Environment variable pointer */ + herr_t ret_value = SUCCEED; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_PACKAGE /* Check the use disabled file locks environment variable */ lock_env_var = getenv(HDF5_USE_FILE_LOCKING); @@ -470,12 +468,38 @@ H5FD_core_init(void) else ignore_disabled_file_locks_s = FAIL; /* Environment variable not set, or not set correctly */ + if (H5FD_core_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize core VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__init_package() */ + +/*------------------------------------------------------------------------- + * Function: H5FD_core_init + * + * Purpose: Initialize this driver by registering the driver with the + * library. + * + * Return: Success: The driver ID for the core driver + * Failure: H5I_INVALID_HID + * + *------------------------------------------------------------------------- + */ +hid_t +H5FD_core_init(void) +{ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_NOAPI(H5I_INVALID_HID) + if (H5I_VFL != H5I_get_type(H5FD_CORE_g)) H5FD_CORE_g = H5FD_register(&H5FD_core_g, sizeof(H5FD_class_t), false); /* Set return value */ ret_value = H5FD_CORE_g; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_core_init() */ diff --git a/src/H5FDcore.h b/src/H5FDcore.h index cd45c8d6061..b472f42b5f9 100644 --- a/src/H5FDcore.h +++ b/src/H5FDcore.h @@ -16,10 +16,7 @@ #ifndef H5FDcore_H #define H5FDcore_H -/** Initializer for the core VFD */ -#define H5FD_CORE (H5FDperform_init(H5FD_core_init)) - -/** Identifier for the core VFD */ +#define H5FD_CORE (H5FD_core_init()) #define H5FD_CORE_VALUE H5_VFD_CORE #ifdef __cplusplus diff --git a/src/H5FDdevelop.h b/src/H5FDdevelop.h index 5f1be973d64..5b8d7533adb 100644 --- a/src/H5FDdevelop.h +++ b/src/H5FDdevelop.h @@ -359,7 +359,6 @@ typedef hid_t (*H5FD_init_t)(void); extern "C" { #endif -H5_DLL hid_t H5FDperform_init(H5FD_init_t op); H5_DLL hid_t H5FDregister(const H5FD_class_t *cls); H5_DLL htri_t H5FDis_driver_registered_by_name(const char *driver_name); H5_DLL htri_t H5FDis_driver_registered_by_value(H5FD_class_value_t driver_value); diff --git a/src/H5FDdirect.c b/src/H5FDdirect.c index b072eeeec08..fa8fa096279 100644 --- a/src/H5FDdirect.c +++ b/src/H5FDdirect.c @@ -183,6 +183,42 @@ static const H5FD_class_t H5FD_direct_g = { /* Declare a free list to manage the H5FD_direct_t struct */ H5FL_DEFINE_STATIC(H5FD_direct_t); +/*-------------------------------------------------------------------------- +NAME + H5FD__init_package -- Initialize interface-specific information +USAGE + herr_t H5FD__init_package() +RETURNS + Non-negative on success/Negative on failure +DESCRIPTION + Initializes any interface-specific data or routines. (Just calls + H5FD_direct_init currently). + +--------------------------------------------------------------------------*/ +static herr_t +H5FD__init_package(void) +{ + char * lock_env_var = NULL; /* Environment variable pointer */ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + /* Check the use disabled file locks environment variable */ + lock_env_var = getenv(HDF5_USE_FILE_LOCKING); + if (lock_env_var && !strcmp(lock_env_var, "BEST_EFFORT")) + ignore_disabled_file_locks_s = true; /* Override: Ignore disabled locks */ + else if (lock_env_var && (!strcmp(lock_env_var, "TRUE") || !strcmp(lock_env_var, "1"))) + ignore_disabled_file_locks_s = false; /* Override: Don't ignore disabled locks */ + else + ignore_disabled_file_locks_s = FAIL; /* Environment variable not set, or not set correctly */ + + if (H5FD_direct_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize direct VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__init_package() */ + /*------------------------------------------------------------------------- * Function: H5FD_direct_init * @@ -197,20 +233,10 @@ H5FL_DEFINE_STATIC(H5FD_direct_t); hid_t H5FD_direct_init(void) { - char *lock_env_var = NULL; /* Environment variable pointer */ hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_NOAPI(H5I_INVALID_HID) - /* Check the use disabled file locks environment variable */ - lock_env_var = getenv(HDF5_USE_FILE_LOCKING); - if (lock_env_var && !strcmp(lock_env_var, "BEST_EFFORT")) - ignore_disabled_file_locks_s = true; /* Override: Ignore disabled locks */ - else if (lock_env_var && (!strcmp(lock_env_var, "TRUE") || !strcmp(lock_env_var, "1"))) - ignore_disabled_file_locks_s = false; /* Override: Don't ignore disabled locks */ - else - ignore_disabled_file_locks_s = FAIL; /* Environment variable not set, or not set correctly */ - if (H5I_VFL != H5I_get_type(H5FD_DIRECT_g)) { H5FD_DIRECT_g = H5FD_register(&H5FD_direct_g, sizeof(H5FD_class_t), false); if (H5I_INVALID_HID == H5FD_DIRECT_g) diff --git a/src/H5FDdirect.h b/src/H5FDdirect.h index 1e60bb08119..e53cda8e7b2 100644 --- a/src/H5FDdirect.h +++ b/src/H5FDdirect.h @@ -19,7 +19,7 @@ #ifdef H5_HAVE_DIRECT /** Initializer for the direct VFD */ -#define H5FD_DIRECT (H5FDperform_init(H5FD_direct_init)) +#define H5FD_DIRECT (H5FD_direct_init()) /** Identifier for the direct VFD */ #define H5FD_DIRECT_VALUE H5_VFD_DIRECT diff --git a/src/H5FDdrvr_module.h b/src/H5FDdrvr_module.h index c984cf51004..b57e5fd08fa 100644 --- a/src/H5FDdrvr_module.h +++ b/src/H5FDdrvr_module.h @@ -22,6 +22,8 @@ * reporting macros. */ #define H5_MY_PKG H5FD -#define H5_MY_PKG_ERR H5E_FILE +#define H5_MY_PKG_ERR H5E_VFL +#define H5_MY_PKG_INIT YES +#define H5_PKG_SINGLE_SOURCE #endif /* H5FDdrvr_module_H */ diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c index 335c63a94f1..6d61b155841 100644 --- a/src/H5FDfamily.c +++ b/src/H5FDfamily.c @@ -266,6 +266,32 @@ H5FD__family_get_default_printf_filename(const char *old_filename) FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD__family_get_default_printf_filename() */ +/*-------------------------------------------------------------------------- +NAME + H5FD__init_package -- Initialize interface-specific information +USAGE + herr_t H5FD__init_package() +RETURNS + Non-negative on success/Negative on failure +DESCRIPTION + Initializes any interface-specific data or routines. (Just calls + H5FD_family_init currently). + +--------------------------------------------------------------------------*/ +static herr_t +H5FD__init_package(void) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + if (H5FD_family_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize family VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__init_package() */ + /*------------------------------------------------------------------------- * Function: H5FD_family_init * @@ -282,7 +308,7 @@ H5FD_family_init(void) { hid_t ret_value = H5I_INVALID_HID; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(H5I_INVALID_HID) if (H5I_VFL != H5I_get_type(H5FD_FAMILY_g)) H5FD_FAMILY_g = H5FD_register(&H5FD_family_g, sizeof(H5FD_class_t), false); @@ -290,6 +316,7 @@ H5FD_family_init(void) /* Set return value */ ret_value = H5FD_FAMILY_g; +done: FUNC_LEAVE_NOAPI(ret_value) } /* H5FD_family_init() */ diff --git a/src/H5FDfamily.h b/src/H5FDfamily.h index 32e885c422d..5e2b21f5614 100644 --- a/src/H5FDfamily.h +++ b/src/H5FDfamily.h @@ -17,7 +17,7 @@ #define H5FDfamily_H /** Initializer for the family VFD */ -#define H5FD_FAMILY (H5FDperform_init(H5FD_family_init)) +#define H5FD_FAMILY (H5FD_family_init()) /** Identifier for the family VFD */ #define H5FD_FAMILY_VALUE H5_VFD_FAMILY diff --git a/src/H5FDhdfs.c b/src/H5FDhdfs.c index 7f7a2950ae3..bfa9624e8cc 100644 --- a/src/H5FDhdfs.c +++ b/src/H5FDhdfs.c @@ -307,6 +307,29 @@ static const H5FD_class_t H5FD_hdfs_g = { /* Declare a free list to manage the H5FD_hdfs_t struct */ H5FL_DEFINE_STATIC(H5FD_hdfs_t); +/*------------------------------------------------------------------------- + * Function: H5FD__init_package + * + * Purpose: Initializes any interface-specific data or routines. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5FD__init_package(void) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + if (H5FD_hdfs_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize hdfs VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__init_package() */ + /*------------------------------------------------------------------------- * Function: H5FD_hdfs_init * diff --git a/src/H5FDhdfs.h b/src/H5FDhdfs.h index 3150a45801b..fb11eebf862 100644 --- a/src/H5FDhdfs.h +++ b/src/H5FDhdfs.h @@ -21,7 +21,7 @@ #ifdef H5_HAVE_LIBHDFS /** Initializer for the hdfs VFD */ -#define H5FD_HDFS (H5FDperform_init(H5FD_hdfs_init)) +#define H5FD_HDFS (H5FD_hdfs_init()) /** Identifier for the hdfs VFD */ #define H5FD_HDFS_VALUE H5_VFD_HDFS diff --git a/src/H5FDint.c b/src/H5FDint.c index a0b2c7d1ecb..7f2c610d086 100644 --- a/src/H5FDint.c +++ b/src/H5FDint.c @@ -3044,7 +3044,7 @@ H5FD_check_plugin_load(const H5FD_class_t *cls, const H5PL_key_t *key, bool *suc { herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity checks */ assert(cls); @@ -3066,6 +3066,7 @@ H5FD_check_plugin_load(const H5FD_class_t *cls, const H5PL_key_t *key, bool *suc *success = true; } +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_check_plugin_load() */ diff --git a/src/H5FDlog.c b/src/H5FDlog.c index e8131726fef..8a2efb98089 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -227,23 +227,21 @@ static const H5FD_log_fapl_t H5FD_log_default_config_g = {NULL, H5FD_LOG_LOC_IO H5FL_DEFINE_STATIC(H5FD_log_t); /*------------------------------------------------------------------------- - * Function: H5FD_log_init + * Function: H5FD__init_package * - * Purpose: Initialize this driver by registering the driver with the - * library. + * Purpose: Initializes any interface-specific data or routines. * - * Return: Success: The driver ID for the log driver - * Failure: H5I_INVALID_HID + * Return: Non-negative on success/Negative on failure * *------------------------------------------------------------------------- */ -hid_t -H5FD_log_init(void) +static herr_t +H5FD__init_package(void) { - char *lock_env_var = NULL; /* Environment variable pointer */ - hid_t ret_value = H5I_INVALID_HID; /* Return value */ + char * lock_env_var = NULL; /* Environment variable pointer */ + herr_t ret_value = SUCCEED; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_PACKAGE /* Check the use disabled file locks environment variable */ lock_env_var = getenv(HDF5_USE_FILE_LOCKING); @@ -254,12 +252,38 @@ H5FD_log_init(void) else ignore_disabled_file_locks_s = FAIL; /* Environment variable not set, or not set correctly */ + if (H5FD_log_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize log VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__init_package() */ + +/*------------------------------------------------------------------------- + * Function: H5FD_log_init + * + * Purpose: Initialize this driver by registering the driver with the + * library. + * + * Return: Success: The driver ID for the log driver + * Failure: H5I_INVALID_HID + * + *------------------------------------------------------------------------- + */ +hid_t +H5FD_log_init(void) +{ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_NOAPI(H5I_INVALID_HID) + if (H5I_VFL != H5I_get_type(H5FD_LOG_g)) H5FD_LOG_g = H5FD_register(&H5FD_log_g, sizeof(H5FD_class_t), false); /* Set return value */ ret_value = H5FD_LOG_g; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_log_init() */ diff --git a/src/H5FDlog.h b/src/H5FDlog.h index ca431bdc691..1e8b6b1aa2a 100644 --- a/src/H5FDlog.h +++ b/src/H5FDlog.h @@ -17,7 +17,7 @@ #define H5FDlog_H /** Initializer for the log VFD */ -#define H5FD_LOG (H5FDperform_init(H5FD_log_init)) +#define H5FD_LOG (H5FD_log_init()) /** Identifier for the log VFD */ #define H5FD_LOG_VALUE H5_VFD_LOG diff --git a/src/H5FDmirror.c b/src/H5FDmirror.c index d5b9c08186d..decc26a27a9 100644 --- a/src/H5FDmirror.c +++ b/src/H5FDmirror.c @@ -15,12 +15,12 @@ * a remote host. */ +#include "H5FDdrvr_module.h" /* This source code file is part of the H5FD driver module */ + #include "H5private.h" /* Generic Functions */ #ifdef H5_HAVE_MIRROR_VFD -#include "H5FDdrvr_module.h" /* This source code file is part of the H5FD driver module */ - #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* File access */ #include "H5FDprivate.h" /* File drivers */ @@ -211,6 +211,30 @@ H5FL_DEFINE_STATIC(H5FD_mirror_t); /* Declare a free list to manage the H5FD_mirror_xmit_open_t struct */ H5FL_DEFINE_STATIC(H5FD_mirror_xmit_open_t); +/* ------------------------------------------------------------------------- + * Function: H5FD__init_package + * + * Purpose: Initializes any interface-specific data or routines. + * + * Return: Non-negative on success/Negative on failure + *------------------------------------------------------------------------- + */ +static herr_t +H5FD__init_package(void) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + LOG_OP_CALL(__func__); + + if (H5FD_mirror_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize mirror VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__init_package() */ + /* ------------------------------------------------------------------------- * Function: H5FD_mirror_init * diff --git a/src/H5FDmirror.h b/src/H5FDmirror.h index 95ce936594d..b3759d3c98c 100644 --- a/src/H5FDmirror.h +++ b/src/H5FDmirror.h @@ -20,7 +20,7 @@ #ifdef H5_HAVE_MIRROR_VFD /** Initializer for the mirror VFD */ -#define H5FD_MIRROR (H5FDperform_init(H5FD_mirror_init)) +#define H5FD_MIRROR (H5FD_mirror_init()) /** Identifier for the mirror VFD */ #define H5FD_MIRROR_VALUE H5_VFD_MIRROR diff --git a/src/H5FDmodule.h b/src/H5FDmodule.h index 1e29ca912a6..eccfc7b8cfb 100644 --- a/src/H5FDmodule.h +++ b/src/H5FDmodule.h @@ -24,5 +24,6 @@ #define H5FD_MODULE #define H5_MY_PKG H5FD #define H5_MY_PKG_ERR H5E_VFL +#define H5_MY_PKG_INIT YES #endif /* H5FDmodule_H */ diff --git a/src/H5FDmpio.c b/src/H5FDmpio.c index 0819bd68f7e..6f50aef4af3 100644 --- a/src/H5FDmpio.c +++ b/src/H5FDmpio.c @@ -186,6 +186,35 @@ static int H5FD_mpio_debug_rank_s = -1; (H5FD_mpio_debug_rank_s < 0 || H5FD_mpio_debug_rank_s == (file)->mpi_rank) #endif +/*-------------------------------------------------------------------------- +NAME + H5FD__init_package -- Initialize interface-specific information + +USAGE + herr_t H5FD__init_package() + +RETURNS + SUCCEED/FAIL + +DESCRIPTION + Initializes any interface-specific data or routines. (Just calls + H5FD_mpio_init currently). + +--------------------------------------------------------------------------*/ +static herr_t +H5FD__init_package(void) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + if (H5FD_mpio_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize mpio VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__init_package() */ + #ifdef H5FDmpio_DEBUG /*--------------------------------------------------------------------------- diff --git a/src/H5FDmpio.h b/src/H5FDmpio.h index 5e7ecf30353..43f38502fb5 100644 --- a/src/H5FDmpio.h +++ b/src/H5FDmpio.h @@ -19,7 +19,7 @@ #ifdef H5_HAVE_PARALLEL /** Initializer for the mpio VFD */ -#define H5FD_MPIO (H5FDperform_init(H5FD_mpio_init)) +#define H5FD_MPIO (H5FD_mpio_init()) #else diff --git a/src/H5FDmulti.h b/src/H5FDmulti.h index 0bb86157f89..1f9c367cd93 100644 --- a/src/H5FDmulti.h +++ b/src/H5FDmulti.h @@ -17,7 +17,7 @@ #define H5FDmulti_H /** Initializer for the multi VFD */ -#define H5FD_MULTI (H5FDperform_init(H5FD_multi_init)) +#define H5FD_MULTI (H5FD_multi_init()) #ifdef __cplusplus extern "C" { diff --git a/src/H5FDonion.c b/src/H5FDonion.c index 96f9166b244..e3e79fe23f4 100644 --- a/src/H5FDonion.c +++ b/src/H5FDonion.c @@ -16,8 +16,8 @@ * Purpose: Provide in-file provenance and revision/version control. */ -/* This source code file is part of the H5FD driver module */ -#include "H5FDdrvr_module.h" +/* This source code file is part of the H5FD onion module */ +#include "H5FDonion_module.h" #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ @@ -31,7 +31,10 @@ #include "H5MMprivate.h" /* Memory management */ /* The driver identification number, initialized at runtime */ -static hid_t H5FD_ONION_g = 0; +static hid_t H5FD_ONION_g = H5I_INVALID_HID; + +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; /****************************************************************************** * @@ -217,6 +220,29 @@ static const H5FD_class_t H5FD_onion_g = { H5FD_FLMAP_DICHOTOMY /* fl_map */ }; +/*------------------------------------------------------------------------- + * Function: H5FD__onion__init_package + * + * Purpose: Initializes any interface-specific data or routines. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5FD__onion__init_package(void) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + if (H5FD_onion_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize onion VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__onion__init_package() */ + /*----------------------------------------------------------------------------- * Function: H5FD_onion_init * @@ -232,7 +258,7 @@ H5FD_onion_init(void) { hid_t ret_value = H5I_INVALID_HID; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(H5I_INVALID_HID) if (H5I_VFL != H5I_get_type(H5FD_ONION_g)) H5FD_ONION_g = H5FD_register(&H5FD_onion_g, sizeof(H5FD_class_t), false); @@ -240,6 +266,7 @@ H5FD_onion_init(void) /* Set return value */ ret_value = H5FD_ONION_g; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_onion_init() */ @@ -257,10 +284,9 @@ H5FD__onion_term(void) FUNC_ENTER_PACKAGE_NOERR /* Reset VFL ID */ - H5FD_ONION_g = 0; + H5FD_ONION_g = H5I_INVALID_HID; FUNC_LEAVE_NOAPI(SUCCEED) - } /* end H5FD__onion_term() */ /*----------------------------------------------------------------------------- diff --git a/src/H5FDonion.h b/src/H5FDonion.h index 4aaab6d3c3e..24f6d6d7957 100644 --- a/src/H5FDonion.h +++ b/src/H5FDonion.h @@ -17,7 +17,7 @@ #define H5FDonion_H /** Initializer for the onion VFD */ -#define H5FD_ONION (H5FDperform_init(H5FD_onion_init)) +#define H5FD_ONION (H5FD_onion_init()) /** Identifier for the onion VFD */ #define H5FD_ONION_VALUE H5_VFD_ONION diff --git a/src/H5FDonion_header.c b/src/H5FDonion_header.c index e6790b3290e..4dce530b9e0 100644 --- a/src/H5FDonion_header.c +++ b/src/H5FDonion_header.c @@ -16,8 +16,8 @@ * Purpose: Code for the onion file's header */ -/* This source code file is part of the H5FD driver module */ -#include "H5FDdrvr_module.h" +/* This source code file is part of the H5FD onion module */ +#include "H5FDonion_module.h" #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ diff --git a/src/H5FDonion_history.c b/src/H5FDonion_history.c index 32bf483ccda..7aaece1d6bd 100644 --- a/src/H5FDonion_history.c +++ b/src/H5FDonion_history.c @@ -16,8 +16,8 @@ * Purpose: Code for the onion file's history */ -/* This source code file is part of the H5FD driver module */ -#include "H5FDdrvr_module.h" +/* This source code file is part of the H5FD onion module */ +#include "H5FDonion_module.h" #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ diff --git a/src/H5FDonion_index.c b/src/H5FDonion_index.c index 4d1320ed809..cbbdd05352e 100644 --- a/src/H5FDonion_index.c +++ b/src/H5FDonion_index.c @@ -16,8 +16,8 @@ * Purpose: Code for the archival and revision indexes */ -/* This source code file is part of the H5FD driver module */ -#include "H5FDdrvr_module.h" +/* This source code file is part of the H5FD onion module */ +#include "H5FDonion_module.h" #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ diff --git a/src/H5FDonion_module.h b/src/H5FDonion_module.h new file mode 100644 index 00000000000..1fc965207dc --- /dev/null +++ b/src/H5FDonion_module.h @@ -0,0 +1,28 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://www.hdfgroup.org/licenses. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Purpose: This file contains declarations which define macros for the + * H5FD onion package. Including this header means that the source file + * is part of the H5FD onion package. + */ +#ifndef H5FDonion_module_H +#define H5FDonion_module_H + +/* Define the proper control macros for the generic FUNC_ENTER/LEAVE and error + * reporting macros. + */ +#define H5_MY_PKG H5FD__onion +#define H5_MY_PKG_ERR H5E_VFL +#define H5_MY_PKG_INIT YES + +#endif /* H5FDonion_module_H */ diff --git a/src/H5FDperform.c b/src/H5FDperform.c deleted file mode 100644 index 7d9f49afdd5..00000000000 --- a/src/H5FDperform.c +++ /dev/null @@ -1,57 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/****************/ -/* Module Setup */ -/****************/ - -#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ - -/***********/ -/* Headers */ -/***********/ -#include "H5private.h" /* Generic Functions */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5FDpkg.h" /* File Drivers */ -#include "H5Iprivate.h" /* IDs */ - -/*------------------------------------------------------------------------- - * Function: H5FDperform_init - * - * Purpose: Ensure that the library is initialized and then call - * the provided VFD initializer - * - * Return: Success: Identifier for the VFD just initialized - * Failure: H5I_INVALID_HID - *------------------------------------------------------------------------- - */ -hid_t -H5FDperform_init(H5FD_init_t op) -{ - hid_t ret_value = H5I_INVALID_HID; /* Return value */ - - FUNC_ENTER_API_NOINIT - - /* It is possible that an application will evaluate an - * `H5FD_*` symbol (`H5FD_FAMILY`, `H5FD_MULTI`, `H5FD_SEC2`, etc. - * before the library has had an opportunity to initialize. Call - * H5_init_library() to make sure that the library has been initialized - * before `init` is run. - */ - if (H5_init_library() < 0) - HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, H5I_INVALID_HID, "library initialization failed"); - - ret_value = op(); - -done: - FUNC_LEAVE_API_NOINIT(ret_value) -} diff --git a/src/H5FDprivate.h b/src/H5FDprivate.h index 942dc21e2e5..cd0326de516 100644 --- a/src/H5FDprivate.h +++ b/src/H5FDprivate.h @@ -197,7 +197,6 @@ H5_DLL herr_t H5FD_sort_selection_io_req(bool *selection_was_sorted, size_t coun H5_flexible_const_ptr_t bufs[], hid_t **s_mem_space_ids, hid_t **s_file_space_ids, haddr_t **s_offsets_ptr, size_t **s_element_sizes_ptr, H5_flexible_const_ptr_t **s_bufs_ptr); -H5_DLL herr_t H5FD_init(void); /* Function prototypes for MPI based VFDs*/ #ifdef H5_HAVE_PARALLEL diff --git a/src/H5FDros3.c b/src/H5FDros3.c index eebf9edca3c..0d9b1f50808 100644 --- a/src/H5FDros3.c +++ b/src/H5FDros3.c @@ -216,6 +216,29 @@ static const H5FD_class_t H5FD_ros3_g = { /* Declare a free list to manage the H5FD_ros3_t struct */ H5FL_DEFINE_STATIC(H5FD_ros3_t); +/*------------------------------------------------------------------------- + * Function: H5FD__init_package + * + * Purpose: Initializes any interface-specific data or routines. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5FD__init_package(void) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + if (H5FD_ros3_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize ros3 VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FD__init_package() */ + /*------------------------------------------------------------------------- * Function: H5FD_ros3_init * diff --git a/src/H5FDros3.h b/src/H5FDros3.h index f7d59c83c89..d9c41aabc00 100644 --- a/src/H5FDros3.h +++ b/src/H5FDros3.h @@ -18,7 +18,7 @@ #ifdef H5_HAVE_ROS3_VFD /** Initializer for the ros3 VFD */ -#define H5FD_ROS3 (H5FDperform_init(H5FD_ros3_init)) +#define H5FD_ROS3 (H5FD_ros3_init()) /** Identifier for the ros3 VFD */ #define H5FD_ROS3_VALUE H5_VFD_ROS3 diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c index 99ff8df6cfe..81b0e066a27 100644 --- a/src/H5FDsec2.c +++ b/src/H5FDsec2.c @@ -186,23 +186,21 @@ static const H5FD_class_t H5FD_sec2_g = { H5FL_DEFINE_STATIC(H5FD_sec2_t); /*------------------------------------------------------------------------- - * Function: H5FD_sec2_init + * Function: H5FD__init_package * - * Purpose: Initialize this driver by registering the driver with the - * library. + * Purpose: Initializes any interface-specific data or routines. * - * Return: Success: The driver ID for the sec2 driver - * Failure: H5I_INVALID_HID + * Return: Non-negative on success/Negative on failure * *------------------------------------------------------------------------- */ -hid_t -H5FD_sec2_init(void) +static herr_t +H5FD__init_package(void) { - char *lock_env_var = NULL; /* Environment variable pointer */ - hid_t ret_value = H5I_INVALID_HID; /* Return value */ + char * lock_env_var = NULL; /* Environment variable pointer */ + herr_t ret_value = SUCCEED; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_PACKAGE /* Check the use disabled file locks environment variable */ lock_env_var = getenv(HDF5_USE_FILE_LOCKING); @@ -213,12 +211,38 @@ H5FD_sec2_init(void) else ignore_disabled_file_locks_s = FAIL; /* Environment variable not set, or not set correctly */ + if (H5FD_sec2_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize sec2 VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__init_package() */ + +/*------------------------------------------------------------------------- + * Function: H5FD_sec2_init + * + * Purpose: Initialize this driver by registering the driver with the + * library. + * + * Return: Success: The driver ID for the sec2 driver + * Failure: H5I_INVALID_HID + * + *------------------------------------------------------------------------- + */ +hid_t +H5FD_sec2_init(void) +{ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_NOAPI(H5I_INVALID_HID) + if (H5I_VFL != H5I_get_type(H5FD_SEC2_g)) H5FD_SEC2_g = H5FD_register(&H5FD_sec2_g, sizeof(H5FD_class_t), false); /* Set return value */ ret_value = H5FD_SEC2_g; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_sec2_init() */ diff --git a/src/H5FDsec2.h b/src/H5FDsec2.h index dd0a4d8918d..d1a25d2a8e6 100644 --- a/src/H5FDsec2.h +++ b/src/H5FDsec2.h @@ -18,7 +18,7 @@ #define H5FDsec2_H /** Initializer for the sec2 VFD */ -#define H5FD_SEC2 (H5FDperform_init(H5FD_sec2_init)) +#define H5FD_SEC2 (H5FD_sec2_init()) /** Identifier for the sec2 VFD */ #define H5FD_SEC2_VALUE H5_VFD_SEC2 diff --git a/src/H5FDsplitter.c b/src/H5FDsplitter.c index 778d112822e..4f7e78cf808 100644 --- a/src/H5FDsplitter.c +++ b/src/H5FDsplitter.c @@ -186,6 +186,30 @@ H5FL_DEFINE_STATIC(H5FD_splitter_t); /* Declare a free list to manage the H5FD_splitter_fapl_t struct */ H5FL_DEFINE_STATIC(H5FD_splitter_fapl_t); +/*------------------------------------------------------------------------- + * Function: H5FD__init_package + * + * Purpose: Initializes any interface-specific data or routines. + * + * Return: SUCCEED/FAIL + *------------------------------------------------------------------------- + */ +static herr_t +H5FD__init_package(void) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + H5FD_SPLITTER_LOG_CALL(__func__); + + if (H5FD_splitter_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize splitter VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__init_package() */ + /*------------------------------------------------------------------------- * Function: H5FD_splitter_init * @@ -201,7 +225,7 @@ H5FD_splitter_init(void) { hid_t ret_value = H5I_INVALID_HID; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(H5I_INVALID_HID) H5FD_SPLITTER_LOG_CALL(__func__); @@ -210,6 +234,7 @@ H5FD_splitter_init(void) ret_value = H5FD_SPLITTER_g; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_splitter_init() */ diff --git a/src/H5FDsplitter.h b/src/H5FDsplitter.h index 99a471e5ce3..5c456237a05 100644 --- a/src/H5FDsplitter.h +++ b/src/H5FDsplitter.h @@ -18,7 +18,7 @@ #define H5FDsplitter_H /** Initializer for the splitter VFD */ -#define H5FD_SPLITTER (H5FDperform_init(H5FD_splitter_init)) +#define H5FD_SPLITTER (H5FD_splitter_init()) /** Identifier for the splitter VFD */ #define H5FD_SPLITTER_VALUE H5_VFD_SPLITTER diff --git a/src/H5FDstdio.h b/src/H5FDstdio.h index 794fe31bf61..d9ae5ff3d8f 100644 --- a/src/H5FDstdio.h +++ b/src/H5FDstdio.h @@ -19,7 +19,7 @@ #include "H5Ipublic.h" /** Initializer for the stdio VFD */ -#define H5FD_STDIO (H5FDperform_init(H5FD_stdio_init)) +#define H5FD_STDIO (H5FD_stdio_init()) #ifdef __cplusplus extern "C" { diff --git a/src/H5FDsubfiling/H5FDioc.c b/src/H5FDsubfiling/H5FDioc.c index 8ec066a0a68..df5e5d75618 100644 --- a/src/H5FDsubfiling/H5FDioc.c +++ b/src/H5FDsubfiling/H5FDioc.c @@ -178,6 +178,29 @@ H5FL_DEFINE_STATIC(H5FD_ioc_t); /* Declare a free list to manage the H5FD_ioc_config_t struct */ H5FL_DEFINE_STATIC(H5FD_ioc_config_t); +/*------------------------------------------------------------------------- + * Function: H5FD__init_package + * + * Purpose: Initializes any interface-specific data or routines. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5FD__init_package(void) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + if (H5FD_ioc_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize ioc VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__init_package() */ + /*------------------------------------------------------------------------- * Function: H5FD_ioc_init * diff --git a/src/H5FDsubfiling/H5FDioc.h b/src/H5FDsubfiling/H5FDioc.h index 8f0255c5583..08c561b74a4 100644 --- a/src/H5FDsubfiling/H5FDioc.h +++ b/src/H5FDsubfiling/H5FDioc.h @@ -27,7 +27,7 @@ * \def H5FD_IOC * Macro that returns the identifier for the #H5FD_IOC driver. \hid_t{file driver} */ -#define H5FD_IOC (H5FDperform_init(H5FD_ioc_init)) +#define H5FD_IOC (H5FD_ioc_init()) #else #define H5FD_IOC (H5I_INVALID_HID) #endif diff --git a/src/H5FDsubfiling/H5FDsubfiling.c b/src/H5FDsubfiling/H5FDsubfiling.c index 796654254ad..363eb4e9257 100644 --- a/src/H5FDsubfiling/H5FDsubfiling.c +++ b/src/H5FDsubfiling/H5FDsubfiling.c @@ -307,6 +307,29 @@ H5FD__subfiling_mpi_finalize(void) FUNC_LEAVE_NOAPI_VOID } +/*------------------------------------------------------------------------- + * Function: H5FD__init_package + * + * Purpose: Initializes any interface-specific data or routines. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5FD__init_package(void) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + if (H5FD_subfiling_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize subfiling VFD"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__init_package() */ + /*------------------------------------------------------------------------- * Function: H5FD_subfiling_init * @@ -342,8 +365,7 @@ H5FD_subfiling_init(void) if (MPI_SUCCESS != (mpi_code = MPI_Query_thread(&provided))) HMPI_GOTO_ERROR(H5I_INVALID_HID, "MPI_Query_thread failed", mpi_code); if (provided != MPI_THREAD_MULTIPLE) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, - "Subfiling VFD requires the use of MPI_Init_thread with MPI_THREAD_MULTIPLE"); + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, "Subfiling VFD requires the use of MPI_Init_thread with MPI_THREAD_MULTIPLE"); } else { int required = MPI_THREAD_MULTIPLE; @@ -354,12 +376,10 @@ H5FD_subfiling_init(void) H5FD_mpi_self_initialized = true; if (provided != required) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, - "MPI doesn't support MPI_Init_thread with MPI_THREAD_MULTIPLE"); + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, "MPI doesn't support MPI_Init_thread with MPI_THREAD_MULTIPLE"); if (atexit(H5FD__subfiling_mpi_finalize) < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, - "can't register atexit handler for MPI_Finalize"); + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, "can't register atexit handler for MPI_Finalize"); } /* @@ -418,8 +438,7 @@ H5FD__subfiling_term(void) } #ifdef H5_SUBFILING_DEBUG else - printf("** WARNING **: HDF5 is terminating the Subfiling VFD after MPI_Finalize() was called " - "- an HDF5 ID was probably left unclosed\n"); + printf("** WARNING **: HDF5 is terminating the Subfiling VFD after MPI_Finalize() was called " "- an HDF5 ID was probably left unclosed\n"); #endif } diff --git a/src/H5FDsubfiling/H5FDsubfiling.h b/src/H5FDsubfiling/H5FDsubfiling.h index d6d2ffd16da..56e0baf2306 100644 --- a/src/H5FDsubfiling/H5FDsubfiling.h +++ b/src/H5FDsubfiling/H5FDsubfiling.h @@ -19,7 +19,7 @@ * \def H5FD_SUBFILING * Macro that returns the identifier for the #H5FD_SUBFILING driver. \hid_t{file driver} */ -#define H5FD_SUBFILING (H5FDperform_init(H5FD_subfiling_init)) +#define H5FD_SUBFILING (H5FD_subfiling_init()) #else #define H5FD_SUBFILING (H5I_INVALID_HID) #endif diff --git a/src/H5FL.c b/src/H5FL.c index cdcdc0cbda9..670812c4c18 100644 --- a/src/H5FL.c +++ b/src/H5FL.c @@ -110,6 +110,9 @@ struct H5FL_fac_node_t { struct H5FL_fac_node_t *next; /* Pointer to next block in free list */ }; +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* The head of the list of factory things to garbage collect */ static H5FL_fac_gc_list_t H5FL_fac_gc_head = {0, NULL}; @@ -168,9 +171,9 @@ H5FL_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { /* Garbage collect any nodes on the free lists */ - (void) - H5FL_garbage_coll(); + (void)H5FL_garbage_coll(); /* Shut down the various kinds of free lists */ n += H5FL__reg_term(); @@ -178,6 +181,11 @@ H5FL_term_package(void) n += H5FL__arr_term(); n += H5FL__blk_term(); + /* Mark interface closed */ + if (0 == n) + H5_PKG_INIT_VAR = FALSE; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* end H5FL_term_package() */ diff --git a/src/H5FLmodule.h b/src/H5FLmodule.h index 5e9f15733f5..075e802326c 100644 --- a/src/H5FLmodule.h +++ b/src/H5FLmodule.h @@ -24,5 +24,6 @@ #define H5FL_MODULE #define H5_MY_PKG H5FL #define H5_MY_PKG_ERR H5E_RESOURCE +#define H5_MY_PKG_INIT NO #endif /* H5FLmodule_H */ diff --git a/src/H5FS.c b/src/H5FS.c index 64bf51f5d46..cc82b41d65a 100644 --- a/src/H5FS.c +++ b/src/H5FS.c @@ -58,6 +58,9 @@ static herr_t H5FS__sinfo_free_node_cb(void *item, void *key, void *op_data); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Declare a free list to manage the H5FS_section_class_t sequence information */ H5FL_SEQ_DEFINE(H5FS_section_class_t); diff --git a/src/H5FSint.c b/src/H5FSint.c index da9f9b85837..0d65d7cce27 100644 --- a/src/H5FSint.c +++ b/src/H5FSint.c @@ -64,6 +64,28 @@ /* Local Variables */ /*******************/ +/*------------------------------------------------------------------------- + * Function: H5FS_init + * + * Purpose: Initialize the interface in case it is unable to initialize + * itself soon enough. + * + * Return: Success: non-negative + * Failure: negative + * + *------------------------------------------------------------------------- + */ +herr_t +H5FS_init(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOERR + /* FUNC_ENTER() does all the work */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FS_init() */ + /*------------------------------------------------------------------------- * Function: H5FS__create_flush_depend * diff --git a/src/H5FSmodule.h b/src/H5FSmodule.h index 46bf8bf0c27..b8e36fe4df2 100644 --- a/src/H5FSmodule.h +++ b/src/H5FSmodule.h @@ -24,5 +24,6 @@ #define H5FS_MODULE #define H5_MY_PKG H5FS #define H5_MY_PKG_ERR H5E_FSPACE +#define H5_MY_PKG_INIT NO #endif /* H5FSmodule_H */ diff --git a/src/H5FSprivate.h b/src/H5FSprivate.h index f917a253944..25f730cf844 100644 --- a/src/H5FSprivate.h +++ b/src/H5FSprivate.h @@ -183,6 +183,9 @@ H5FL_SEQ_EXTERN(H5FS_section_class_t); /* Library-private Function Prototypes */ /***************************************/ +/* Package initialization routine */ +H5_DLL herr_t H5FS_init(void); + /* Free space manager routines */ H5_DLL H5FS_t *H5FS_create(H5F_t *f, haddr_t *fs_addr, const H5FS_create_t *fs_create, uint16_t nclasses, const H5FS_section_class_t *classes[], void *cls_init_udata, hsize_t alignment, diff --git a/src/H5Fcwfs.c b/src/H5Fcwfs.c index c946fa453e1..0185bd1a384 100644 --- a/src/H5Fcwfs.c +++ b/src/H5Fcwfs.c @@ -240,7 +240,7 @@ H5F_cwfs_advance_heap(H5F_t *f, H5HG_heap_t *heap, bool add_heap) unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Check args */ assert(f); @@ -260,6 +260,7 @@ H5F_cwfs_advance_heap(H5F_t *f, H5HG_heap_t *heap, bool add_heap) f->shared->cwfs[f->shared->ncwfs - 1] = heap; } /* end if */ +done: FUNC_LEAVE_NOAPI(ret_value) } /* H5F_cwfs_advance_heap() */ @@ -279,7 +280,7 @@ H5F_cwfs_remove_heap(H5F_shared_t *shared, H5HG_heap_t *heap) unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Check args */ assert(shared); @@ -294,5 +295,6 @@ H5F_cwfs_remove_heap(H5F_shared_t *shared, H5HG_heap_t *heap) } /* end if */ } /* end for */ +done: FUNC_LEAVE_NOAPI(ret_value) } /* H5F_cwfs_remove_heap() */ diff --git a/src/H5Fint.c b/src/H5Fint.c index f653e0b71f0..83c9d5d6185 100644 --- a/src/H5Fint.c +++ b/src/H5Fint.c @@ -91,6 +91,9 @@ static herr_t H5F__flush_phase2(H5F_t *f, bool closing); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Based on the value of the HDF5_USE_FILE_LOCKING environment variable. * true/false have obvious meanings. FAIL means the environment variable was * not set, so the code should ignore it and use the fapl value instead. @@ -136,6 +139,29 @@ H5F_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 H5F_init() */ + +/*-------------------------------------------------------------------------- +NAME + H5F__init_package -- Initialize interface-specific information +USAGE + herr_t H5F__init_package() +RETURNS + Non-negative on success/Negative on failure +DESCRIPTION + Initializes any interface-specific data or routines. + +--------------------------------------------------------------------------*/ +herr_t +H5F__init_package(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE /* Initialize the ID group for the file IDs */ if (H5I_register_type(H5I_FILE_CLS) < 0) @@ -147,7 +173,7 @@ H5F_init(void) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5F_init() */ +} /* H5F__init_package() */ /*------------------------------------------------------------------------- * Function: H5F_term_package @@ -171,6 +197,7 @@ H5F_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { if (H5I_nmembers(H5I_FILE) > 0) { (void)H5I_clear_type(H5I_FILE, false, false); n++; /*H5I*/ @@ -181,7 +208,12 @@ H5F_term_package(void) /* Destroy the file object id group */ n += (H5I_dec_type_ref(H5I_FILE) > 0); + + /* Mark closed */ + if (0 == n) + H5_PKG_INIT_VAR = FALSE; } /* end else */ + } /* end if */ FUNC_LEAVE_NOAPI(n) } /* end H5F_term_package() */ diff --git a/src/H5Fmodule.h b/src/H5Fmodule.h index c9f1b31ceac..ada925a49a2 100644 --- a/src/H5Fmodule.h +++ b/src/H5Fmodule.h @@ -24,6 +24,7 @@ #define H5F_MODULE #define H5_MY_PKG H5F #define H5_MY_PKG_ERR H5E_FILE +#define H5_MY_PKG_INIT YES /** \page H5F_UG HDF5 File * diff --git a/src/H5Fmpi.c b/src/H5Fmpi.c index 4e6ca64253d..892d702ff28 100644 --- a/src/H5Fmpi.c +++ b/src/H5Fmpi.c @@ -432,7 +432,7 @@ H5F_mpi_retrieve_comm(hid_t loc_id, hid_t acspl_id, MPI_Comm *mpi_comm) bool H5F_get_coll_metadata_reads(const H5F_t *file) { - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI_NOINIT_NOERR assert(file && file->shared); @@ -458,7 +458,7 @@ H5F_shared_get_coll_metadata_reads(const H5F_shared_t *f_sh) H5P_coll_md_read_flag_t file_flag = H5P_USER_FALSE; bool ret_value = false; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI_NOINIT_NOERR assert(f_sh); @@ -536,7 +536,7 @@ H5F_set_coll_metadata_reads(H5F_t *file, H5P_coll_md_read_flag_t *file_flag, boo H5P_coll_md_read_flag_t prev_file_flag = H5P_USER_FALSE; bool prev_context_flag = false; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI_NOINIT_NOERR assert(file && file->shared); assert(file_flag); diff --git a/src/H5Fquery.c b/src/H5Fquery.c index 63c96d531d0..5ac802804ab 100644 --- a/src/H5Fquery.c +++ b/src/H5Fquery.c @@ -1385,7 +1385,7 @@ H5F_get_use_file_locking(const H5F_t *f) bool H5F_has_vector_select_io(const H5F_t *f, bool is_write) { - bool ret_value; /* Return value */ + bool ret_value = false; /* Return value */ FUNC_ENTER_NOAPI_NOINIT_NOERR diff --git a/src/H5Gint.c b/src/H5Gint.c index 2580bf08ce0..228eaba7aaa 100644 --- a/src/H5Gint.c +++ b/src/H5Gint.c @@ -89,6 +89,9 @@ static herr_t H5G__close_cb(H5VL_object_t *grp_vol_obj, void **request); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Declare a free list to manage the H5G_t struct */ H5FL_DEFINE(H5G_t); H5FL_DEFINE(H5G_shared_t); @@ -112,6 +115,9 @@ static const H5I_class_t H5I_GROUP_CLS[1] = {{ (H5I_free_t)H5G__close_cb /* Callback routine for closing objects of this class */ }}; +/* Flag indicating "top" of interface has been initialized */ +static bool H5G_top_package_initialize_s = false; + /*------------------------------------------------------------------------- * Function: H5G_init * @@ -128,13 +134,48 @@ H5G_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 H5G_init() */ + +/*------------------------------------------------------------------------- + * Function: H5G__init_package + * + * Purpose: Initializes the H5G interface. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Robb Matzke + * Monday, January 5, 1998 + * + * Notes: The group creation properties are registered in the property + * list interface initialization routine (H5P_init_package) + * so that the file creation property class can inherit from it + * correctly. (Which allows the file creation property list to + * control the group creation properties of the root group of + * a file) QAK - 24/10/2005 + * + *------------------------------------------------------------------------- + */ +herr_t +H5G__init_package(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + /* Initialize the ID group for the group IDs */ if (H5I_register_type(H5I_GROUP_CLS) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to initialize interface"); + /* Mark "top" of interface as initialized, too */ + H5G_top_package_initialize_s = true; + done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5G_init() */ +} /* end H5G__init_package() */ /*------------------------------------------------------------------------- * Function: H5G_top_term_package @@ -154,11 +195,17 @@ H5G_top_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5G_top_package_initialize_s) { if (H5I_nmembers(H5I_GROUP) > 0) { (void)H5I_clear_type(H5I_GROUP, false, false); n++; } + /* Mark closed */ + if (0 == n) + H5G_top_package_initialize_s = FALSE; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* end H5G_top_term_package() */ @@ -183,12 +230,19 @@ H5G_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { /* Sanity checks */ assert(0 == H5I_nmembers(H5I_GROUP)); + assert(false == H5G_top_package_initialize_s); /* Destroy the group object id group */ n += (H5I_dec_type_ref(H5I_GROUP) > 0); + /* Mark closed */ + if (0 == n) + H5_PKG_INIT_VAR = false; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* end H5G_term_package() */ diff --git a/src/H5Gmodule.h b/src/H5Gmodule.h index 49fc9ed9472..e4d4c91225d 100644 --- a/src/H5Gmodule.h +++ b/src/H5Gmodule.h @@ -24,6 +24,7 @@ #define H5G_MODULE #define H5_MY_PKG H5G #define H5_MY_PKG_ERR H5E_SYM +#define H5_MY_PKG_INIT YES /** \page H5G_UG HDF5 Groups * diff --git a/src/H5HF.c b/src/H5HF.c index bbc5ce7e455..b158ded5920 100644 --- a/src/H5HF.c +++ b/src/H5HF.c @@ -59,6 +59,9 @@ /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ diff --git a/src/H5HFmodule.h b/src/H5HFmodule.h index c4fb437d4f1..3e369cc16bd 100644 --- a/src/H5HFmodule.h +++ b/src/H5HFmodule.h @@ -24,5 +24,6 @@ #define H5HF_MODULE #define H5_MY_PKG H5HF #define H5_MY_PKG_ERR H5E_HEAP +#define H5_MY_PKG_INIT NO #endif /* H5HFmodule_H */ diff --git a/src/H5HG.c b/src/H5HG.c index a859b40f100..de33b06c88d 100644 --- a/src/H5HG.c +++ b/src/H5HG.c @@ -81,6 +81,9 @@ static size_t H5HG__alloc(H5F_t *f, H5HG_heap_t *heap, size_t size, unsigned *h /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Declare a free list to manage the H5HG_heap_t struct */ H5FL_DEFINE(H5HG_heap_t); diff --git a/src/H5HGmodule.h b/src/H5HGmodule.h index 772ebe6163d..a9f3f628ec4 100644 --- a/src/H5HGmodule.h +++ b/src/H5HGmodule.h @@ -24,5 +24,6 @@ #define H5HG_MODULE #define H5_MY_PKG H5HG #define H5_MY_PKG_ERR H5E_HEAP +#define H5_MY_PKG_INIT NO #endif /* H5HGmodule_H */ diff --git a/src/H5HL.c b/src/H5HL.c index f6e589b016d..76f1d8a1a2e 100644 --- a/src/H5HL.c +++ b/src/H5HL.c @@ -64,6 +64,9 @@ static herr_t H5HL__dirty(H5HL_t *heap); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Declare a free list to manage the H5HL_free_t struct */ H5FL_DEFINE(H5HL_free_t); diff --git a/src/H5HLmodule.h b/src/H5HLmodule.h index 1a871abf745..ff76afcacff 100644 --- a/src/H5HLmodule.h +++ b/src/H5HLmodule.h @@ -24,5 +24,6 @@ #define H5HL_MODULE #define H5_MY_PKG H5HL #define H5_MY_PKG_ERR H5E_HEAP +#define H5_MY_PKG_INIT NO #endif /* H5HLmodule_H */ diff --git a/src/H5HLpkg.h b/src/H5HLpkg.h index 9d23049dd35..a0734d7f8fa 100644 --- a/src/H5HLpkg.h +++ b/src/H5HLpkg.h @@ -42,15 +42,6 @@ H5FL_BLK_EXTERN(lheap_chunk); /* Package Private Macros */ /**************************/ -/* If this package header is being included in one of the H5HL source files, - * define the proper control macros for the generic FUNC_ENTER/LEAVE and - * error reporting macros. - */ -#ifdef H5HL_PACKAGE -#define H5_MY_PKG H5HL -#define H5_MY_PKG_ERR H5E_HEAP -#endif - #define H5HL_SIZEOF_HDR(F) \ H5HL_ALIGN(H5_SIZEOF_MAGIC + /* heap signature */ \ 1 + /* version */ \ diff --git a/src/H5Iint.c b/src/H5Iint.c index 709b9450802..427c16000cd 100644 --- a/src/H5Iint.c +++ b/src/H5Iint.c @@ -84,6 +84,9 @@ static int H5I__find_id_cb(void *_item, void *_key, void *_udata); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Declared extern in H5Ipkg.h and documented there */ H5I_type_info_t *H5I_type_info_array_g[H5I_MAX_NUM_TYPES]; int H5I_next_type_g = (int)H5I_NTYPES; @@ -123,6 +126,7 @@ H5I_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { H5I_type_info_t *type_info = NULL; /* Pointer to ID type */ int i; @@ -142,6 +146,11 @@ H5I_term_package(void) in_use++; } } + + /* Mark interface closed */ + if (0 == in_use) + H5_PKG_INIT_VAR = false; + } } FUNC_LEAVE_NOAPI(in_use) diff --git a/src/H5Imodule.h b/src/H5Imodule.h index f8924d3df62..ad8c39703b8 100644 --- a/src/H5Imodule.h +++ b/src/H5Imodule.h @@ -24,6 +24,7 @@ #define H5I_MODULE #define H5_MY_PKG H5I #define H5_MY_PKG_ERR H5E_ID +#define H5_MY_PKG_INIT NO /** \page H5I_UG HDF5 Identifiers * @todo Under Construction diff --git a/src/H5Lint.c b/src/H5Lint.c index 10b935ab09d..7314a001c6d 100644 --- a/src/H5Lint.c +++ b/src/H5Lint.c @@ -174,6 +174,9 @@ static herr_t H5L__get_name_by_idx_cb(H5G_loc_t *grp_loc /*in*/, const char *nam /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ @@ -204,6 +207,27 @@ H5L_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 H5L_init() */ + +/*------------------------------------------------------------------------- + * Function: H5L__init_package + * + * Purpose: Initialize information specific to H5L interface. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5L__init_package(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE /* Initialize user-defined link classes */ if (H5L_register_external() < 0) @@ -211,12 +235,12 @@ H5L_init(void) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5L_init() */ +} /* end H5L_init_package() */ /*------------------------------------------------------------------------- * Function: H5L_term_package * - * Purpose: Terminate any resources allocated in H5L_init. + * Purpose: Terminate any resources allocated in H5L__init_package. * * Return: Non-negative on success/Negative on failure * @@ -229,6 +253,7 @@ H5L_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { /* Free the table of link types */ if (H5L_table_g) { H5L_table_g = (H5L_class_t *)H5MM_xfree(H5L_table_g); @@ -236,6 +261,11 @@ H5L_term_package(void) n++; } /* end if */ + /* Mark the interface as uninitialized */ + if (0 == n) + H5_PKG_INIT_VAR = false; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* H5L_term_package() */ diff --git a/src/H5Lmodule.h b/src/H5Lmodule.h index f29aa5c50c0..f31c860c7bb 100644 --- a/src/H5Lmodule.h +++ b/src/H5Lmodule.h @@ -24,6 +24,7 @@ #define H5L_MODULE #define H5_MY_PKG H5L #define H5_MY_PKG_ERR H5E_LINK +#define H5_MY_PKG_INIT YES /** \page H5L_UG HDF5 Links * @todo Under Construction diff --git a/src/H5M.c b/src/H5M.c index bb8b4d9882b..5402fa46179 100644 --- a/src/H5M.c +++ b/src/H5M.c @@ -57,6 +57,9 @@ static herr_t H5M__get_api_common(hid_t map_id, hid_t key_mem_type_id, const voi /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ @@ -73,6 +76,9 @@ static const H5I_class_t H5I_MAP_CLS[1] = {{ (H5I_free_t)H5M__close_cb /* Callback routine for closing objects of this class */ }}; +/* Flag indicating "top" of interface has been initialized */ +static bool H5M_top_package_initialize_s = false; + /*------------------------------------------------------------------------- * Function: H5M_init * @@ -89,14 +95,40 @@ H5M_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 H5M_init() */ + +/*------------------------------------------------------------------------- +NAME + H5M__init_package -- Initialize interface-specific information +USAGE + herr_t H5M__init_package() +RETURNS + Non-negative on success/Negative on failure +DESCRIPTION + Initializes any interface-specific data or routines. +--------------------------------------------------------------------------- +*/ +herr_t +H5M__init_package(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE /* Initialize the ID group for the map IDs */ if (H5I_register_type(H5I_MAP_CLS) < 0) HGOTO_ERROR(H5E_MAP, H5E_CANTINIT, FAIL, "unable to initialize interface"); + /* Mark "top" of interface as initialized, too */ + H5M_top_package_initialize_s = TRUE; + done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5M_init() */ +} /* end H5M__init_package() */ /*------------------------------------------------------------------------- * Function: H5M_top_term_package @@ -115,11 +147,17 @@ H5M_top_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5M_top_package_initialize_s) { if (H5I_nmembers(H5I_MAP) > 0) { (void)H5I_clear_type(H5I_MAP, false, false); n++; } + /* Mark closed */ + if (0 == n) + H5M_top_package_initialize_s = false; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* end H5M_top_term_package() */ @@ -143,12 +181,19 @@ H5M_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { /* Sanity checks */ assert(0 == H5I_nmembers(H5I_MAP)); + assert(false == H5M_top_package_initialize_s); /* Destroy the dataset object id group */ n += (H5I_dec_type_ref(H5I_MAP) > 0); + /* Mark closed */ + if (0 == n) + H5_PKG_INIT_VAR = FALSE; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* end H5M_term_package() */ diff --git a/src/H5MF.c b/src/H5MF.c index 2de3e7ad197..2c35703c5c8 100644 --- a/src/H5MF.c +++ b/src/H5MF.c @@ -111,6 +111,9 @@ static herr_t H5MF__sects_cb(H5FS_section_info_t *_sect, void *_udata); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ diff --git a/src/H5MFmodule.h b/src/H5MFmodule.h index dd32cdc210d..418b84fd3cf 100644 --- a/src/H5MFmodule.h +++ b/src/H5MFmodule.h @@ -24,5 +24,6 @@ #define H5MF_MODULE #define H5_MY_PKG H5MF #define H5_MY_PKG_ERR H5E_RESOURCE +#define H5_MY_PKG_INIT NO #endif /* H5MFmodule_H */ diff --git a/src/H5Mmodule.h b/src/H5Mmodule.h index 375399751b5..b6281f24dca 100644 --- a/src/H5Mmodule.h +++ b/src/H5Mmodule.h @@ -24,6 +24,7 @@ #define H5M_MODULE #define H5_MY_PKG H5M #define H5_MY_PKG_ERR H5E_MAP +#define H5_MY_PKG_INIT YES /** * \page H5M_UG HDF5 VOL Data Mapping diff --git a/src/H5Oint.c b/src/H5Oint.c index 2528fb93c68..b58c68d0547 100644 --- a/src/H5Oint.c +++ b/src/H5Oint.c @@ -82,6 +82,9 @@ static herr_t H5O__reset_info2(H5O_info2_t *oinfo); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Header message ID to class mapping * * Remember to increment H5O_MSG_TYPES in H5Opkg.h when adding a new @@ -177,20 +180,19 @@ static const H5O_obj_class_t *const H5O_obj_class_g[] = { }; /*------------------------------------------------------------------------- - * Function: H5O_init + * Function: H5O__init_package * - * Purpose: Initialize the interface from some other layer. + * Purpose: Initialize information specific to H5O interface. * * Return: Success: non-negative * Failure: negative + * *------------------------------------------------------------------------- */ herr_t -H5O_init(void) +H5O__init_package(void) { - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_PACKAGE_NOERR /* H5O interface sanity checks */ HDcompile_assert(H5O_MSG_TYPES == NELMTS(H5O_msg_class_g)); @@ -198,8 +200,8 @@ H5O_init(void) HDcompile_assert(H5O_UNKNOWN_ID < H5O_MSG_TYPES); - FUNC_LEAVE_NOAPI(ret_value) -} + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5O__init_package() */ /*------------------------------------------------------------------------- * Function: H5O__set_version @@ -545,7 +547,7 @@ H5O_open(H5O_loc_t *loc) { herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Check args */ assert(loc); @@ -557,6 +559,7 @@ H5O_open(H5O_loc_t *loc) else H5F_INCR_NOPEN_OBJS(loc->file); +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_open() */ diff --git a/src/H5Omodule.h b/src/H5Omodule.h index 1c1278a0e8a..8400cba377c 100644 --- a/src/H5Omodule.h +++ b/src/H5Omodule.h @@ -24,6 +24,7 @@ #define H5O_MODULE #define H5_MY_PKG H5O #define H5_MY_PKG_ERR H5E_OHDR +#define H5_MY_PKG_INIT YES /** \page H5O_UG HDF5 Objects * @todo Under Construction diff --git a/src/H5P.c b/src/H5P.c index f0ccc2fc4ef..886bf735a4c 100644 --- a/src/H5P.c +++ b/src/H5P.c @@ -52,6 +52,9 @@ typedef struct { /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ @@ -1492,7 +1495,7 @@ H5Pclose(hid_t plist_id) EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ -char * +H5_ATTR_MALLOC char * H5Pget_class_name(hid_t pclass_id) { H5P_genclass_t *pclass; /* Property class to query */ diff --git a/src/H5PB.c b/src/H5PB.c index 69707d14cba..4a718a44693 100644 --- a/src/H5PB.c +++ b/src/H5PB.c @@ -130,6 +130,9 @@ static herr_t H5PB__write_entry(H5F_shared_t *f_sh, H5PB_entry_t *page_entry); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ diff --git a/src/H5PBmodule.h b/src/H5PBmodule.h index 3a353dbd0b2..4183c78a83b 100644 --- a/src/H5PBmodule.h +++ b/src/H5PBmodule.h @@ -24,5 +24,6 @@ #define H5PB_MODULE #define H5_MY_PKG H5PB #define H5_MY_PKG_ERR H5E_RESOURCE +#define H5_MY_PKG_INIT NO #endif /* H5PBmodule_H */ diff --git a/src/H5PLint.c b/src/H5PLint.c index 6ee4603f63a..75978dd9781 100644 --- a/src/H5PLint.c +++ b/src/H5PLint.c @@ -45,6 +45,9 @@ /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ @@ -119,21 +122,22 @@ H5PL__set_plugin_control_mask(unsigned int mask) } /* end H5PL__set_plugin_control_mask() */ /*------------------------------------------------------------------------- - * Function: H5PL_init + * Function: H5PL__init_package * - * Purpose: Initialize the interface from some other layer. + * Purpose: Initialize any package-specific data and call any init + * routines for the package. * * Return: Success: non-negative * Failure: negative *------------------------------------------------------------------------- */ herr_t -H5PL_init(void) +H5PL__init_package(void) { char *env_var = NULL; herr_t ret_value = SUCCEED; - FUNC_ENTER_NOAPI(FAIL) + FUNC_ENTER_PACKAGE /* Check the environment variable to determine if the user wants * to ignore plugins. The special symbol H5PL_NO_PLUGIN (defined in @@ -155,7 +159,7 @@ H5PL_init(void) done: FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5PL__init_package() */ /*------------------------------------------------------------------------- * Function: H5PL_term_package @@ -178,17 +182,23 @@ H5PL_term_package(void) FUNC_ENTER_NOAPI_NOINIT - /* Close the plugin cache. - * We need to bump the return value if we did any real work here. - */ - if (H5PL__close_plugin_cache(&already_closed) < 0) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTFREE, (-1), "problem closing plugin cache"); - if (!already_closed) - ret_value++; + if (H5_PKG_INIT_VAR) { + /* Close the plugin cache. + * We need to bump the return value if we did any real work here. + */ + if (H5PL__close_plugin_cache(&already_closed) < 0) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTFREE, (-1), "problem closing plugin cache"); + if (!already_closed) + ret_value++; - /* Close the search path table and free the paths */ - if (H5PL__close_path_table() < 0) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTFREE, (-1), "problem closing search path table"); + /* Close the search path table and free the paths */ + if (H5PL__close_path_table() < 0) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTFREE, (-1), "problem closing search path table"); + + /* Mark the interface as uninitialized */ + if (0 == ret_value) + H5_PKG_INIT_VAR = FALSE; + } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -504,9 +514,10 @@ H5PL_iterate(H5PL_iterate_type_t iter_type, H5PL_iterate_t iter_op, void *op_dat { herr_t ret_value = H5_ITER_CONT; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(H5_ITER_ERROR) ret_value = H5PL__path_table_iterate(iter_type, iter_op, op_data); +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5PL_iterate() */ diff --git a/src/H5PLmodule.h b/src/H5PLmodule.h index 1aedc2783fe..7eea28196c9 100644 --- a/src/H5PLmodule.h +++ b/src/H5PLmodule.h @@ -25,6 +25,7 @@ #define H5PL_MODULE #define H5_MY_PKG H5PL #define H5_MY_PKG_ERR H5E_PLUGIN +#define H5_MY_PKG_INIT YES /** \page H5PL_UG HDF5 Plugins * diff --git a/src/H5PLprivate.h b/src/H5PLprivate.h index 0c71b176b73..a52720a50cd 100644 --- a/src/H5PLprivate.h +++ b/src/H5PLprivate.h @@ -82,6 +82,5 @@ typedef herr_t (*H5PL_iterate_t)(H5PL_type_t plugin_type, const void *plugin_inf /* Internal API routines */ H5_DLL const void *H5PL_load(H5PL_type_t plugin_type, const H5PL_key_t *key); H5_DLL herr_t H5PL_iterate(H5PL_iterate_type_t iter_type, H5PL_iterate_t iter_op, void *op_data); -H5_DLL herr_t H5PL_init(void); #endif /* H5PLprivate_H */ diff --git a/src/H5Pint.c b/src/H5Pint.c index f8c79bf022f..dfd1a9217a9 100644 --- a/src/H5Pint.c +++ b/src/H5Pint.c @@ -118,7 +118,7 @@ static herr_t H5P__free_del_name_cb(void *item, void H5_ATTR_UNUSED *key, void H /* * Predefined property list classes. These are initialized at runtime by - * H5P_init() in this source file. + * H5P__init_package() in this source file. */ hid_t H5P_CLS_ROOT_ID_g = H5I_INVALID_HID; H5P_genclass_t *H5P_CLS_ROOT_g = NULL; @@ -168,7 +168,7 @@ H5P_genclass_t *H5P_CLS_VOL_INITIALIZE_g = NULL; /* * Predefined property lists for each predefined class. These are initialized - * at runtime by H5P_init() in this source file. + * at runtime by H5P__init_package() in this source file. */ hid_t H5P_LST_ATTRIBUTE_ACCESS_ID_g = H5I_INVALID_HID; hid_t H5P_LST_ATTRIBUTE_CREATE_ID_g = H5I_INVALID_HID; @@ -421,13 +421,64 @@ static const H5I_class_t H5I_GENPROPLST_CLS[1] = {{ */ herr_t H5P_init_phase1(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 H5P_init_phase1() */ + +/*------------------------------------------------------------------------- + * Function: H5P_init_phase2 + * + * Purpose: Finish initializing the interface from some other package. + * + * Note: This is broken out as a separate routine so that the + * library's default VFL driver can be chosen and initialized + * after the entire H5P interface has been initialized. + * + * Return: Success: Non-negative + * Failure: Negative + * + *------------------------------------------------------------------------- + */ +herr_t +H5P_init_phase2(void) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(FAIL) + + /* Set up the default VFL driver */ + if (H5P__facc_set_def_driver() < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set default VFL driver"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P_init_phase2() */ + +/*-------------------------------------------------------------------------- +NAME + H5P__init_package -- Initialize interface-specific information +USAGE + herr_t H5P__init_package() +RETURNS + Non-negative on success/Negative on failure +DESCRIPTION + Initializes any interface-specific data or routines. +--------------------------------------------------------------------------*/ +herr_t +H5P__init_package(void) { size_t tot_init = 0; /* Total # of classes initialized */ size_t pass_init; /* # of classes initialized in each pass */ size_t u; herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(FAIL) + FUNC_ENTER_PACKAGE /* Sanity check */ HDcompile_assert(H5P_TYPE_REFERENCE_ACCESS == (H5P_TYPE_MAX_TYPE - 1)); @@ -518,36 +569,7 @@ H5P_init_phase1(void) } FUNC_LEAVE_NOAPI(ret_value) -} - -/*------------------------------------------------------------------------- - * Function: H5P_init_phase2 - * - * Purpose: Finish initializing the interface from some other package. - * - * Note: This is broken out as a separate routine so that the - * library's default VFL driver can be chosen and initialized - * after the entire H5P interface has been initialized. - * - * Return: Success: Non-negative - * Failure: Negative - * - *------------------------------------------------------------------------- - */ -herr_t -H5P_init_phase2(void) -{ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_NOAPI(FAIL) - - /* Set up the default VFL driver */ - if (H5P__facc_set_def_driver() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "unable to set default VFL driver"); - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5P_init_phase2() */ +} /* end H5P__init_package() */ /*-------------------------------------------------------------------------- NAME @@ -573,6 +595,7 @@ H5P_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { int64_t nlist, nclass; /* Destroy HDF5 library property classes & lists */ @@ -673,7 +696,12 @@ H5P_term_package(void) /* Destroy the property list and class id groups */ n += (H5I_dec_type_ref(H5I_GENPROP_LST) > 0); n += (H5I_dec_type_ref(H5I_GENPROP_CLS) > 0); + + /* Mark closed */ + if (0 == n) + H5_PKG_INIT_VAR = FALSE; } /* end else */ + } /* end if */ FUNC_LEAVE_NOAPI(n) } /* end H5P_term_package() */ @@ -3541,7 +3569,7 @@ H5P_get_nprops_pclass(const H5P_genclass_t *pclass, size_t *nprops, bool recurse { herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) assert(pclass); assert(nprops); @@ -3556,6 +3584,7 @@ H5P_get_nprops_pclass(const H5P_genclass_t *pclass, size_t *nprops, bool recurse *nprops += pclass->nprops; } /* end while */ +done: FUNC_LEAVE_NOAPI(ret_value) } /* H5P_get_nprops_pclass() */ @@ -3986,7 +4015,7 @@ H5P_class_isa(const H5P_genclass_t *pclass1, const H5P_genclass_t *pclass2) { htri_t ret_value = FAIL; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) assert(pclass1); assert(pclass2); @@ -5281,13 +5310,14 @@ H5P_get_class_name(H5P_genclass_t *pclass) { char *ret_value = NULL; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(NULL) assert(pclass); /* Get class name */ ret_value = H5MM_xstrdup(pclass->name); +done: FUNC_LEAVE_NOAPI(ret_value) } /* H5P_get_class_name() */ diff --git a/src/H5Pmodule.h b/src/H5Pmodule.h index 8ac6f86eed9..71a156ebffb 100644 --- a/src/H5Pmodule.h +++ b/src/H5Pmodule.h @@ -24,6 +24,7 @@ #define H5P_MODULE #define H5_MY_PKG H5P #define H5_MY_PKG_ERR H5E_PLIST +#define H5_MY_PKG_INIT YES /** \page H5P_UG Properties and Property Lists in HDF5 * diff --git a/src/H5RS.c b/src/H5RS.c index ad1f1d0c69e..d84ae970ab9 100644 --- a/src/H5RS.c +++ b/src/H5RS.c @@ -69,6 +69,9 @@ static herr_t H5RS__resize_for_append(H5RS_str_t *rs, size_t len); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ diff --git a/src/H5RSmodule.h b/src/H5RSmodule.h index ee6b7e80e51..85232a5a1de 100644 --- a/src/H5RSmodule.h +++ b/src/H5RSmodule.h @@ -24,5 +24,6 @@ #define H5RS_MODULE #define H5_MY_PKG H5RS #define H5_MY_PKG_ERR H5E_RS +#define H5_MY_PKG_INIT NO #endif /* H5RSmodule_H */ diff --git a/src/H5Rint.c b/src/H5Rint.c index 35fc78d83e7..ea24077ac46 100644 --- a/src/H5Rint.c +++ b/src/H5Rint.c @@ -135,6 +135,9 @@ static herr_t H5R__decode_string(const unsigned char *buf, size_t *nbytes, char /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ @@ -143,28 +146,60 @@ static herr_t H5R__decode_string(const unsigned char *buf, size_t *nbytes, char /* Local Variables */ /*******************/ -/*------------------------------------------------------------------------- - * Function: H5R_init - * - * Purpose: Initialize the interface from some other layer. - * - * Return: Success: non-negative - * Failure: negative - *------------------------------------------------------------------------- - */ +/*-------------------------------------------------------------------------- +NAME + H5R__init_package -- Initialize interface-specific information +USAGE + herr_t H5R__init_package() +RETURNS + Non-negative on success/Negative on failure +DESCRIPTION + Initializes any interface-specific data or routines. +--------------------------------------------------------------------------*/ herr_t -H5R_init(void) +H5R__init_package(void) { - herr_t ret_value = SUCCEED; - FUNC_ENTER_NOAPI_NOINIT_NOERR /* Sanity check, if assert fails, H5R_REF_BUF_SIZE must be increased */ HDcompile_assert(sizeof(H5R_ref_priv_t) <= H5R_REF_BUF_SIZE); - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5R__init_package() */ + +/*-------------------------------------------------------------------------- + NAME + H5R_term_package + PURPOSE + Terminate various H5R objects + USAGE + void H5R_term_package() + RETURNS + void + DESCRIPTION + Release the ID 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) +{ + FUNC_ENTER_NOAPI_NOINIT_NOERR + + if (H5_PKG_INIT_VAR) { + /* Mark closed */ + H5_PKG_INIT_VAR = false; } + FUNC_LEAVE_NOAPI(0) +} /* end H5R_term_package() */ + /*------------------------------------------------------------------------- * Function: H5R__create_object * diff --git a/src/H5Rmodule.h b/src/H5Rmodule.h index 443c4746d71..c9872c02023 100644 --- a/src/H5Rmodule.h +++ b/src/H5Rmodule.h @@ -23,6 +23,7 @@ #define H5R_MODULE #define H5_MY_PKG H5R #define H5_MY_PKG_ERR H5E_REFERENCE +#define H5_MY_PKG_INIT YES /** \page H5R_UG HDF5 References * diff --git a/src/H5Rprivate.h b/src/H5Rprivate.h index 43e476485fb..0f129d29fab 100644 --- a/src/H5Rprivate.h +++ b/src/H5Rprivate.h @@ -38,6 +38,4 @@ /* Library Private Prototypes */ /******************************/ -H5_DLL herr_t H5R_init(void); - #endif /* H5Rprivate_H */ diff --git a/src/H5S.c b/src/H5S.c index d6611654729..b12f4fac620 100644 --- a/src/H5S.c +++ b/src/H5S.c @@ -54,6 +54,9 @@ static htri_t H5S__is_simple(const H5S_t *sdim); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Format version bounds for dataspace */ const unsigned H5O_sdspace_ver_bounds[] = { H5O_SDSPACE_VERSION_1, /* H5F_LIBVER_EARLIEST */ @@ -94,6 +97,9 @@ static const H5I_class_t H5I_SPACE_SEL_ITER_CLS[1] = {{ (H5I_free_t)H5S__sel_iter_close_cb /* Callback routine for closing objects of this class */ }}; +/* Flag indicating "top" of interface has been initialized */ +static bool H5S_top_package_initialize_s = false; + /*------------------------------------------------------------------------- * Function: H5S_init * @@ -109,6 +115,28 @@ H5S_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 H5S_init() */ + +/*-------------------------------------------------------------------------- +NAME + H5S__init_package -- Initialize interface-specific information +USAGE + herr_t H5S__init_package() +RETURNS + Non-negative on success/Negative on failure +DESCRIPTION + Initializes any interface-specific data or routines. +--------------------------------------------------------------------------*/ +herr_t +H5S__init_package(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE /* Initialize the ID group for the dataspace IDs */ if (H5I_register_type(H5I_DATASPACE_CLS) < 0) @@ -119,9 +147,12 @@ H5S_init(void) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize dataspace selection iterator ID class"); + /* Mark "top" of interface as initialized, too */ + H5S_top_package_initialize_s = TRUE; + done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5S_init() */ +} /* end H5S__init_package() */ /*-------------------------------------------------------------------------- NAME @@ -148,6 +179,7 @@ H5S_top_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5S_top_package_initialize_s) { if (H5I_nmembers(H5I_DATASPACE) > 0) { (void)H5I_clear_type(H5I_DATASPACE, false, false); n++; @@ -157,6 +189,11 @@ H5S_top_term_package(void) n++; } + /* Mark "top" of interface as closed */ + if (0 == n) + H5S_top_package_initialize_s = FALSE; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* end H5S_top_term_package() */ @@ -187,9 +224,11 @@ H5S_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { /* Sanity checks */ assert(0 == H5I_nmembers(H5I_DATASPACE)); assert(0 == H5I_nmembers(H5I_SPACE_SEL_ITER)); + assert(false == H5S_top_package_initialize_s); /* Destroy the dataspace object id group */ n += (H5I_dec_type_ref(H5I_DATASPACE) > 0); @@ -197,6 +236,11 @@ H5S_term_package(void) /* Destroy the dataspace selection iterator object id group */ n += (H5I_dec_type_ref(H5I_SPACE_SEL_ITER) > 0); + /* Mark interface as closed */ + if (0 == n) + H5_PKG_INIT_VAR = false; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* end H5S_term_package() */ @@ -685,7 +729,7 @@ H5S_get_simple_extent_npoints(const H5S_t *ds) { hssize_t ret_value = -1; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(-1) /* check args */ assert(ds); @@ -693,6 +737,7 @@ H5S_get_simple_extent_npoints(const H5S_t *ds) /* Get the number of elements in extent */ ret_value = (hssize_t)ds->extent.nelem; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_get_simple_extent_npoints() */ @@ -1629,12 +1674,13 @@ H5S_get_simple_extent_type(const H5S_t *space) { H5S_class_t ret_value = H5S_NO_CLASS; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(H5S_NO_CLASS) assert(space); ret_value = H5S_GET_EXTENT_TYPE(space); +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_get_simple_extent_type() */ diff --git a/src/H5SL.c b/src/H5SL.c index 54e064962f5..19d1fcc7ebd 100644 --- a/src/H5SL.c +++ b/src/H5SL.c @@ -509,6 +509,9 @@ static H5SL_node_t *H5SL__insert_common(H5SL_t *slist, void *item, const void *k static herr_t H5SL__release_common(H5SL_t *slist, H5SL_operator_t op, void *op_data); static herr_t H5SL__close_common(H5SL_t *slist, H5SL_operator_t op, void *op_data); +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Declare a free list to manage the H5SL_t struct */ H5FL_DEFINE_STATIC(H5SL_t); @@ -520,21 +523,26 @@ static H5FL_fac_head_t **H5SL_fac_g; static size_t H5SL_fac_nused_g; static size_t H5SL_fac_nalloc_g; -/*------------------------------------------------------------------------- - * Function: H5SL_init - * - * Purpose: Initialize the interface from some other layer. - * - * Return: Success: non-negative - * Failure: negative - *------------------------------------------------------------------------- - */ +/*-------------------------------------------------------------------------- + NAME + H5SL__init_package + PURPOSE + Initialize interface-specific information + USAGE + herr_t H5SL__init_package() + RETURNS + Non-negative on success/Negative on failure + DESCRIPTION + Initializes any interface-specific data or routines. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ herr_t -H5SL_init(void) +H5SL__init_package(void) { - herr_t ret_value = SUCCEED; - - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_PACKAGE_NOERR /* Allocate space for array of factories */ H5SL_fac_g = (H5FL_fac_head_t **)H5MM_malloc(sizeof(H5FL_fac_head_t *)); @@ -546,8 +554,8 @@ H5SL_init(void) assert(H5SL_fac_g[0]); H5SL_fac_nused_g = 1; - FUNC_LEAVE_NOAPI(ret_value) -} + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5SL__init_package() */ /*-------------------------------------------------------------------------- NAME @@ -575,6 +583,7 @@ H5SL_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { /* Terminate all the factories */ if (H5SL_fac_nused_g > 0) { size_t i; @@ -597,6 +606,11 @@ H5SL_term_package(void) n++; } + /* Mark the interface as uninitialized */ + if (0 == n) + H5_PKG_INIT_VAR = FALSE; + } + FUNC_LEAVE_NOAPI(n) } /* H5SL_term_package() */ diff --git a/src/H5SLmodule.h b/src/H5SLmodule.h index b0b3064f15b..6d77c2cfc9f 100644 --- a/src/H5SLmodule.h +++ b/src/H5SLmodule.h @@ -24,5 +24,6 @@ #define H5SL_MODULE #define H5_MY_PKG H5SL #define H5_MY_PKG_ERR H5E_SLIST +#define H5_MY_PKG_INIT YES #endif /* H5SLmodule_H */ diff --git a/src/H5SLprivate.h b/src/H5SLprivate.h index d7eb5be8b83..903984f9f41 100644 --- a/src/H5SLprivate.h +++ b/src/H5SLprivate.h @@ -81,7 +81,6 @@ H5_DLL herr_t H5SL_release(H5SL_t *slist); H5_DLL herr_t H5SL_free(H5SL_t *slist, H5SL_operator_t op, void *op_data); H5_DLL herr_t H5SL_close(H5SL_t *slist); H5_DLL herr_t H5SL_destroy(H5SL_t *slist, H5SL_operator_t op, void *op_data); -H5_DLL herr_t H5SL_init(void); H5_DLL int H5SL_term_interface(void); #endif /* H5SLprivate_H */ diff --git a/src/H5SM.c b/src/H5SM.c index 1c2d4e6caa7..f295d122d3a 100644 --- a/src/H5SM.c +++ b/src/H5SM.c @@ -75,6 +75,9 @@ static herr_t H5SM__read_mesg(H5F_t *f, const H5SM_sohm_t *mesg, H5HF_t *fheap, /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + H5FL_DEFINE(H5SM_master_table_t); H5FL_ARR_DEFINE(H5SM_index_header_t, H5O_SHMESG_MAX_NINDEXES); H5FL_DEFINE(H5SM_list_t); diff --git a/src/H5SMmodule.h b/src/H5SMmodule.h index 1eaeea29e99..51a550e8533 100644 --- a/src/H5SMmodule.h +++ b/src/H5SMmodule.h @@ -24,5 +24,6 @@ #define H5SM_MODULE #define H5_MY_PKG H5SM #define H5_MY_PKG_ERR H5E_SOHM +#define H5_MY_PKG_INIT NO #endif /* H5SMmodule_H */ diff --git a/src/H5Shyper.c b/src/H5Shyper.c index bc5d6c3db96..83f4c832a7d 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -12099,7 +12099,7 @@ H5S_hyper_get_clip_extent(const H5S_t *clip_space, const H5S_t *match_space, boo hsize_t num_slices; /* Number of slices in unlimited dimension */ hsize_t ret_value = 0; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(0) /* Check parameters */ assert(clip_space); @@ -12121,6 +12121,7 @@ H5S_hyper_get_clip_extent(const H5S_t *clip_space, const H5S_t *match_space, boo /* Call "real" get_clip_extent function */ ret_value = H5S__hyper_get_clip_extent_real(clip_space, num_slices, incl_trail); +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_hyper_get_clip_extent() */ @@ -12156,7 +12157,7 @@ H5S_hyper_get_clip_extent_match(const H5S_t *clip_space, const H5S_t *match_spac hsize_t num_slices; /* Number of slices in unlimited dimension */ hsize_t ret_value = 0; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(0) /* Check parameters */ assert(clip_space); @@ -12202,6 +12203,7 @@ H5S_hyper_get_clip_extent_match(const H5S_t *clip_space, const H5S_t *match_spac /* Call "real" get_clip_extent function */ ret_value = H5S__hyper_get_clip_extent_real(clip_space, num_slices, incl_trail); +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_hyper_get_clip_extent_match() */ @@ -12317,7 +12319,7 @@ H5S_hyper_get_first_inc_block(const H5S_t *space, hsize_t clip_size, bool *parti H5S_hyper_dim_t *diminfo; /* Convenience pointer to diminfo in unlimited dimension */ hsize_t ret_value = 0; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(0) /* Check parameters */ assert(space); @@ -12347,6 +12349,7 @@ H5S_hyper_get_first_inc_block(const H5S_t *space, hsize_t clip_size, bool *parti } /* end if */ } /* end else */ +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_hyper_get_first_inc_block */ diff --git a/src/H5Smodule.h b/src/H5Smodule.h index b9897485405..b31d1d0b645 100644 --- a/src/H5Smodule.h +++ b/src/H5Smodule.h @@ -24,6 +24,7 @@ #define H5S_MODULE #define H5_MY_PKG H5S #define H5_MY_PKG_ERR H5E_DATASPACE +#define H5_MY_PKG_INIT YES /** \page H5S_UG Dataspaces and Partial I/O * diff --git a/src/H5T.c b/src/H5T.c index dcf0a679fed..bafcdfcc1a9 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -416,8 +416,11 @@ H5T_order_t H5T_native_order_g = H5T_ORDER_ERROR; /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* - * Predefined data types. These are initialized at runtime by H5T_init(). + * Predefined data types. These are initialized at runtime by H5T__init_package(). * * If more of these are added, the new ones must be added to the list of * types to reset in H5T_term_package(). @@ -641,6 +644,34 @@ static const H5I_class_t H5I_DATATYPE_CLS[1] = {{ (H5I_free_t)H5T__close_cb /* Callback routine for closing objects of this class */ }}; +/* Flag indicating "top" of interface has been initialized */ +static bool H5T_top_package_initialize_s = false; + +/*------------------------------------------------------------------------- + * Function: H5T_init + * + * Purpose: Initialize the interface from some other package. + * + * Return: Success: non-negative + * Failure: negative + * + * Programmer: Robb Matzke + * Wednesday, December 16, 1998 + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_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 H5T_init() */ + /*------------------------------------------------------------------------- * Function: H5T__init_inf * @@ -793,17 +824,18 @@ H5T__init_inf(void) FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__init_inf() */ -/*------------------------------------------------------------------------- - * Function: H5T_init - * - * Purpose: Initialize the interface from some other layer. - * - * Return: Success: non-negative - * Failure: negative - *------------------------------------------------------------------------- - */ +/*-------------------------------------------------------------------------- +NAME + H5T__init_package -- Initialize interface-specific information +USAGE + herr__t H5T_init_package() +RETURNS + Non-negative on success/Negative on failure +DESCRIPTION + Initializes any interface-specific data or routines. +--------------------------------------------------------------------------*/ herr_t -H5T_init(void) +H5T__init_package(void) { H5T_t *native_schar = NULL; /* Datatype structure for native signed char */ H5T_t *native_uchar = NULL; /* Datatype structure for native unsigned char */ @@ -847,7 +879,7 @@ H5T_init(void) #endif herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(FAIL) + FUNC_ENTER_NOAPI_NOINIT /* Initialize the ID group for the file IDs */ if (H5I_register_type(H5I_DATATYPE_CLS) < 0) @@ -1594,7 +1626,7 @@ H5T_init(void) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to register conversion function(s)"); /* Register datatype creation property class properties here. See similar - * code in H5D_init(), etc. for example. + * code in H5D__init_package(), etc. for example. */ /* Only register the default property list if it hasn't been created yet */ @@ -1607,6 +1639,9 @@ H5T_init(void) HGOTO_ERROR(H5E_PLIST, H5E_CANTREGISTER, FAIL, "can't insert property into class"); } /* end if */ + /* Mark "top" of interface as initialized, too */ + H5T_top_package_initialize_s = true; + done: /* General cleanup */ if (compound != NULL) @@ -1634,7 +1669,7 @@ H5T_init(void) } /* end if */ FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_init() */ +} /* end H5T__init_package() */ /*------------------------------------------------------------------------- * Function: H5T__unlock_cb @@ -1683,6 +1718,7 @@ H5T_top_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5T_top_package_initialize_s) { /* Unregister all conversion functions */ if (H5T_g.path) { H5T_conv_ctx_t conv_ctx = {0}; @@ -1822,6 +1858,11 @@ H5T_top_term_package(void) n++; } /* end if */ + /* Mark "top" of interface as closed */ + if (0 == n) + H5T_top_package_initialize_s = false; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* end H5T_top_term_package() */ @@ -1847,12 +1888,19 @@ H5T_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { /* Sanity check */ assert(0 == H5I_nmembers(H5I_DATATYPE)); + assert(false == H5T_top_package_initialize_s); /* Destroy the datatype object id group */ n += (H5I_dec_type_ref(H5I_DATATYPE) > 0); + /* Mark interface as closed */ + if (0 == n) + H5_PKG_INIT_VAR = false; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* end H5T_term_package() */ @@ -2247,7 +2295,7 @@ H5T_get_class(const H5T_t *dt, htri_t internal) { H5T_class_t ret_value = H5T_NO_CLASS; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(H5T_NO_CLASS) assert(dt); @@ -2262,6 +2310,7 @@ H5T_get_class(const H5T_t *dt, htri_t internal) ret_value = dt->shared->type; } +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T_get_class() */ @@ -2313,7 +2362,7 @@ H5T_detect_class(const H5T_t *dt, H5T_class_t cls, bool from_api) unsigned i; htri_t ret_value = false; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) assert(dt); assert(cls > H5T_NO_CLASS && cls < H5T_NCLASSES); @@ -6022,13 +6071,14 @@ H5T_is_immutable(const H5T_t *dt) { htri_t ret_value = false; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) assert(dt); if (dt->shared->state == H5T_STATE_IMMUTABLE) ret_value = true; +done: FUNC_LEAVE_NOAPI(ret_value) } @@ -6046,7 +6096,7 @@ H5T_is_named(const H5T_t *dt) { htri_t ret_value = false; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) assert(dt); @@ -6055,6 +6105,7 @@ H5T_is_named(const H5T_t *dt) else ret_value = (H5T_STATE_OPEN == dt->shared->state || H5T_STATE_NAMED == dt->shared->state); +done: FUNC_LEAVE_NOAPI(ret_value) } @@ -6130,13 +6181,14 @@ H5T_get_ref_type(const H5T_t *dt) { H5R_type_t ret_value = H5R_BADTYPE; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(H5R_BADTYPE) assert(dt); if (dt->shared->type == H5T_REFERENCE) ret_value = dt->shared->u.atomic.u.r.rtype; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T_get_ref_type() */ @@ -6157,7 +6209,7 @@ H5T_is_sensible(const H5T_t *dt) { htri_t ret_value = FAIL; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) assert(dt); @@ -6195,6 +6247,7 @@ H5T_is_sensible(const H5T_t *dt) break; } /* end switch */ +done: FUNC_LEAVE_NOAPI(ret_value) } @@ -6384,7 +6437,7 @@ H5T_is_relocatable(const H5T_t *dt) { htri_t ret_value = false; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ assert(dt); @@ -6393,6 +6446,7 @@ H5T_is_relocatable(const H5T_t *dt) if (H5T_detect_class(dt, H5T_VLEN, false) || H5T_detect_class(dt, H5T_REFERENCE, false)) ret_value = true; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T_is_relocatable() */ @@ -6477,7 +6531,7 @@ H5T_is_vl_storage(const H5T_t *dt) { htri_t ret_value = false; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ assert(dt); @@ -6490,6 +6544,7 @@ H5T_is_vl_storage(const H5T_t *dt) else ret_value = false; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T_is_vl_storage() */ @@ -6632,7 +6687,7 @@ H5T_patch_file(H5T_t *dt, H5F_t *f) { herr_t ret_value = SUCCEED; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ assert(dt); @@ -6643,6 +6698,7 @@ H5T_patch_file(H5T_t *dt, H5F_t *f) dt->sh_loc.file = f; } /* end if */ +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T_patch_file() */ diff --git a/src/H5TSint.c b/src/H5TSint.c index a2761bb2ad3..906f8b523aa 100644 --- a/src/H5TSint.c +++ b/src/H5TSint.c @@ -79,6 +79,9 @@ static H5TS_tinfo_node_t *H5TS__tinfo_create(void); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Per-thread info */ H5TS_key_t H5TS_thrd_info_key_g; diff --git a/src/H5TSmodule.h b/src/H5TSmodule.h index 2e8bb1d92a6..44347c23ae5 100644 --- a/src/H5TSmodule.h +++ b/src/H5TSmodule.h @@ -24,5 +24,6 @@ #define H5TS_MODULE #define H5_MY_PKG H5TS #define H5_MY_PKG_ERR H5E_THREADSAFE +#define H5_MY_PKG_INIT YES #endif /* H5TSmodule_H */ diff --git a/src/H5Tfields.c b/src/H5Tfields.c index 86c9e1eb51b..17d4d2470e0 100644 --- a/src/H5Tfields.c +++ b/src/H5Tfields.c @@ -106,7 +106,7 @@ H5T_get_nmembers(const H5T_t *dt) * *------------------------------------------------------------------------- */ -char * +H5_ATTR_MALLOC char * H5Tget_member_name(hid_t type_id, unsigned membno) { H5T_t *dt = NULL; diff --git a/src/H5Tmodule.h b/src/H5Tmodule.h index 3e121469108..d9d2fc01a35 100644 --- a/src/H5Tmodule.h +++ b/src/H5Tmodule.h @@ -24,6 +24,7 @@ #define H5T_MODULE #define H5_MY_PKG H5T #define H5_MY_PKG_ERR H5E_DATATYPE +#define H5_MY_PKG_INIT YES /** \page H5T_UG HDF5 Datatypes * diff --git a/src/H5Topaque.c b/src/H5Topaque.c index edaeb69e3d6..46f08470cc7 100644 --- a/src/H5Topaque.c +++ b/src/H5Topaque.c @@ -72,7 +72,7 @@ H5Tset_tag(hid_t type_id, const char *tag) * *------------------------------------------------------------------------- */ -char * +H5_ATTR_MALLOC char * H5Tget_tag(hid_t type_id) { H5T_t *dt = NULL; diff --git a/src/H5VLint.c b/src/H5VLint.c index 19a11e9b6b8..9277305fffb 100644 --- a/src/H5VLint.c +++ b/src/H5VLint.c @@ -103,6 +103,9 @@ static herr_t H5VL__free_vol_wrapper(H5VL_wrap_ctx_t *vol_wrap_ctx); /* Package Variables */ /*********************/ +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /*****************************/ /* Library Private Variables */ /*****************************/ @@ -155,9 +158,7 @@ H5VL_init_phase1(void) FUNC_ENTER_NOAPI(FAIL) - /* Initialize the ID group for the VL IDs */ - if (H5I_register_type(H5I_VOL_CLS) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "unable to initialize H5VL interface"); + /* FUNC_ENTER() does all the work */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -179,38 +180,23 @@ H5VL_init_phase1(void) herr_t H5VL_init_phase2(void) { - size_t i; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - /* clang-format off */ - struct { - herr_t (*func)(void); - const char *descr; - } initializer[] = { - {H5T_init, "datatype"} - , {H5O_init, "object header"} - , {H5D_init, "dataset"} - , {H5F_init, "file"} - , {H5G_init, "group"} - , {H5A_init, "attribute"} - , {H5M_init, "map"} - , {H5CX_init, "context"} - , {H5ES_init, "event set"} - , {H5Z_init, "transform"} - , {H5R_init, "reference"} - }; - /* Initialize all packages for VOL-managed objects */ - for (i = 0; i < NELMTS(initializer); i++) { - if (initializer[i].func() < 0) { - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, - "unable to initialize %s interface", initializer[i].descr); - } - } - - /* clang-format on */ + if (H5T_init() < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "unable to initialize datatype interface"); + if (H5D_init() < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "unable to initialize dataset interface"); + if (H5F_init() < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "unable to initialize file interface"); + if (H5G_init() < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "unable to initialize group interface"); + if (H5A_init() < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "unable to initialize attribute interface"); + if (H5M_init() < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "unable to initialize map interface"); /* Sanity check default VOL connector */ assert(H5VL_def_conn_s.connector_id == (-1)); @@ -224,6 +210,32 @@ H5VL_init_phase2(void) FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_init_phase2() */ +/*------------------------------------------------------------------------- + * Function: H5VL__init_package + * + * Purpose: Initialize interface-specific information + * + * Return: Success: Non-negative + * + * Failure: Negative + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL__init_package(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Initialize the ID group for the VL IDs */ + if (H5I_register_type(H5I_VOL_CLS) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "unable to initialize H5VL interface"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__init_package() */ + /*------------------------------------------------------------------------- * Function: H5VL_term_package * @@ -242,6 +254,7 @@ H5VL_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { if (H5VL_def_conn_s.connector_id > 0) { /* Release the default VOL connector */ (void)H5VL_conn_free(&H5VL_def_conn_s); @@ -264,9 +277,14 @@ H5VL_term_package(void) else { /* Destroy the VOL connector ID group */ n += (H5I_dec_type_ref(H5I_VOL) > 0); + + /* Mark interface as closed */ + if (0 == n) + H5_PKG_INIT_VAR = FALSE; } /* end else */ } /* end else */ } /* end else */ + } /* end if */ FUNC_LEAVE_NOAPI(n) } /* end H5VL_term_package() */ @@ -957,7 +975,7 @@ H5VL_conn_inc_rc(H5VL_t *connector) { int64_t ret_value = -1; - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(-1) /* Check arguments */ assert(connector); @@ -967,6 +985,7 @@ H5VL_conn_inc_rc(H5VL_t *connector) ret_value = connector->nrefs; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_conn_inc_rc() */ @@ -1021,7 +1040,7 @@ H5VL_conn_dec_rc(H5VL_t *connector) hsize_t H5VL_object_inc_rc(H5VL_object_t *vol_obj) { - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI_NOINIT_NOERR /* Check arguments */ assert(vol_obj); @@ -1077,7 +1096,7 @@ H5VL_object_is_native(const H5VL_object_t *obj, bool *is_native) { const H5VL_class_t *cls; /* VOL connector class structs for object */ const H5VL_class_t *native_cls; /* Native VOL connector class structs */ - int cmp_value; /* Comparison result */ + int cmp_value = 0; /* Comparison result */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -1990,7 +2009,7 @@ H5VL_cmp_connector_cls(int *cmp_value, const H5VL_class_t *cls1, const H5VL_clas { herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity checks */ assert(cls1); @@ -2497,7 +2516,7 @@ H5VL_check_plugin_load(const H5VL_class_t *cls, const H5PL_key_t *key, bool *suc { herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Sanity checks */ assert(cls); @@ -2523,6 +2542,7 @@ H5VL_check_plugin_load(const H5VL_class_t *cls, const H5PL_key_t *key, bool *suc if (*success && cls->version != H5VL_VERSION) *success = false; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_check_plugin_load() */ diff --git a/src/H5VLmodule.h b/src/H5VLmodule.h index 81321f6d787..6d89f22482c 100644 --- a/src/H5VLmodule.h +++ b/src/H5VLmodule.h @@ -25,6 +25,7 @@ #define H5VL_MODULE #define H5_MY_PKG H5VL #define H5_MY_PKG_ERR H5E_VOL +#define H5_MY_PKG_INIT YES /** \page H5VL_UG HDF5 Virtual Object Layer (VOL) * diff --git a/src/H5Z.c b/src/H5Z.c index 8ee679b3f54..cdb49ba804c 100644 --- a/src/H5Z.c +++ b/src/H5Z.c @@ -58,6 +58,9 @@ typedef enum { H5Z_PRELUDE_SET_LOCAL /* Call "set local" callback */ } H5Z_prelude_type_t; +/* Package initialization variable */ +bool H5_PKG_INIT_VAR = false; + /* Local variables */ static size_t H5Z_table_alloc_g = 0; static size_t H5Z_table_used_g = 0; @@ -75,23 +78,20 @@ static int H5Z__check_unregister_group_cb(void *obj_ptr, hid_t obj_id, void *key static int H5Z__flush_file_cb(void *obj_ptr, hid_t obj_id, void *key); /*------------------------------------------------------------------------- - * Function: H5Z_init + * Function: H5Z__init_package * - * Purpose: Initialize the interface from some other layer. + * Purpose: Initializes the data filter layer. * * Return: Success: non-negative * Failure: negative *------------------------------------------------------------------------- */ herr_t -H5Z_init(void) +H5Z__init_package(void) { herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(FAIL) - - if (H5_TERM_GLOBAL) - HGOTO_DONE(SUCCEED); + FUNC_ENTER_PACKAGE /* Internal filters */ if (H5Z_register(H5Z_SHUFFLE) < 0) @@ -122,7 +122,7 @@ H5Z_init(void) done: FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5Z__init_package() */ /*------------------------------------------------------------------------- * Function: H5Z_term_package @@ -139,6 +139,7 @@ H5Z_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR + if (H5_PKG_INIT_VAR) { #ifdef H5Z_DEBUG char comment[16], bandwidth[32]; int dir, nprint = 0; @@ -205,6 +206,11 @@ H5Z_term_package(void) n++; } /* end if */ + /* Mark interface as closed */ + if (0 == n) + H5_PKG_INIT_VAR = FALSE; + } /* end if */ + FUNC_LEAVE_NOAPI(n) } /* end H5Z_term_package() */ @@ -1571,7 +1577,7 @@ H5Z_filter_in_pline(const H5O_pline_t *pline, H5Z_filter_t filter) size_t idx; /* Index of filter in pipeline */ htri_t ret_value = true; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) assert(pline); assert(filter >= 0 && filter <= H5Z_FILTER_MAX); @@ -1585,6 +1591,7 @@ H5Z_filter_in_pline(const H5O_pline_t *pline, H5Z_filter_t filter) if (idx >= pline->nused) ret_value = false; +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5Z_filter_in_pline() */ @@ -1604,7 +1611,7 @@ H5Z_all_filters_avail(const H5O_pline_t *pline) size_t i, j; /* Local index variable */ htri_t ret_value = true; /* Return value */ - FUNC_ENTER_NOAPI_NOERR + FUNC_ENTER_NOAPI(FAIL) /* Check args */ assert(pline); diff --git a/src/H5Zmodule.h b/src/H5Zmodule.h index d1087b8bcd5..562aeb83c94 100644 --- a/src/H5Zmodule.h +++ b/src/H5Zmodule.h @@ -24,6 +24,7 @@ #define H5Z_MODULE #define H5_MY_PKG H5Z #define H5_MY_PKG_ERR H5E_PLINE +#define H5_MY_PKG_INIT YES /** \page H5Z_UG HDF5 Filters * @todo Under Construction diff --git a/src/H5module.h b/src/H5module.h index a0f1af77363..9589cd32576 100644 --- a/src/H5module.h +++ b/src/H5module.h @@ -24,6 +24,7 @@ #define H5_MODULE #define H5_MY_PKG H5 #define H5_MY_PKG_ERR H5E_LIB +#define H5_MY_PKG_INIT YES /** \page H5DM_UG HDF5 Data Model and File Structure * diff --git a/src/H5private.h b/src/H5private.h index 9950d0ccadc..afdb7132429 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -114,14 +114,8 @@ #include #endif -/* Define the default VFD for this platform. Since the removal of the - * Windows VFD, this is sec2 for all platforms. - * - * Note well: if you change the default, then be sure to change - * H5_default_vfd_init() to call that default's initializer. Also, - * make sure that the initializer for each *non*-default VFD calls - * H5_init_library(); also, make sure that the initializer for default - * VFD does *not* call H5_init_library(). +/* Define the default VFD for this platform. + * Since the removal of the Windows VFD, this is sec2 for all platforms. */ #define H5_DEFAULT_VFD H5FD_SEC2 #define H5_DEFAULT_VFD_NAME "sec2" @@ -1221,6 +1215,33 @@ extern bool H5_libterm_g; /* Is the library being shutdown? */ #define H5_INIT_GLOBAL (H5_libinit_g) #define H5_TERM_GLOBAL (H5_libterm_g) +/* Macros for referencing package initialization symbols */ +#define H5_PACKAGE_INIT_VAR(x) H5_GLUE(x, _init_g) +#define H5_PACKAGE_INIT_FUNC(x) H5_GLUE(x, __init_package) + +/* Macros for defining package initialization routines */ +#ifdef H5_MY_PKG +#define H5_PKG_INIT_VAR H5_PACKAGE_INIT_VAR(H5_MY_PKG) +#define H5_PKG_INIT_FUNC H5_PACKAGE_INIT_FUNC(H5_MY_PKG) +#define H5_PACKAGE_YES_INIT(err) \ + /* Initialize this interface or bust */ \ + if (!H5_PKG_INIT_VAR && !H5_TERM_GLOBAL) { \ + H5_PKG_INIT_VAR = TRUE; \ + if (H5_PKG_INIT_FUNC() < 0) { \ + H5_PKG_INIT_VAR = FALSE; \ + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, err, "interface initialization failed"); \ + } \ + } +#define H5_PACKAGE_NO_INIT(err) \ + /* Initialize this interface or bust */ \ + if (!H5_PKG_INIT_VAR && !H5_TERM_GLOBAL) \ + H5_PKG_INIT_VAR = TRUE; +#define H5_PACKAGE_INIT(pkg_init, err) H5_GLUE3(H5_PACKAGE_, pkg_init, _INIT)(err) +#else /* H5_MY_PKG */ +#define H5_PKG_INIT_VAR (TRUE) +#define H5_PACKAGE_INIT(pkg_init, err) +#endif /* H5_MY_PKG */ + /* Forward declaration of H5CXpush() / H5CXpop() */ /* (Including H5CXprivate.h creates bad circular dependencies - QAK, 3/18/2018) */ H5_DLL herr_t H5CX_push(void); @@ -1262,10 +1283,12 @@ H5_DLL herr_t H5CX_pop(bool update_dxpl_props); #define FUNC_ENTER_API_INIT(err) \ /* Initialize the library */ \ - if (H5_UNLIKELY(!H5_INIT_GLOBAL && !H5_TERM_GLOBAL)) { \ + if (H5_UNLIKELY(!H5_INIT_GLOBAL && !H5_TERM_GLOBAL)) \ if (H5_UNLIKELY(H5_init_library() < 0)) \ HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, err, "library initialization failed"); \ - } + \ + /* Initialize the package, if appropriate */ \ + H5_PACKAGE_INIT(H5_MY_PKG_INIT, err) #define FUNC_ENTER_API_PUSH(err) \ /* Push the API context */ \ @@ -1366,17 +1389,24 @@ H5_DLL herr_t H5CX_pop(bool update_dxpl_props); FUNC_ENTER_COMMON_NOERR(H5_IS_API(__func__)); \ { +/* Note: this macro only works when there's _no_ interface initialization routine for the module */ +#define FUNC_ENTER_NOAPI_INIT(err) \ + /* Initialize the package, if appropriate */ \ + H5_PACKAGE_INIT(H5_MY_PKG_INIT, err) + /* Use this macro for all "normal" non-API functions */ #define FUNC_ENTER_NOAPI(err) \ { \ FUNC_ENTER_COMMON(!H5_IS_API(__func__)); \ - { + FUNC_ENTER_NOAPI_INIT(err) \ + if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) { /* Use this macro for all non-API functions, which propagate errors, but don't issue them */ #define FUNC_ENTER_NOAPI_NOERR \ { \ FUNC_ENTER_COMMON_NOERR(!H5_IS_API(__func__)); \ - { + FUNC_ENTER_NOAPI_INIT(-) \ + if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) { /* * Use this macro for non-API functions which fall into these categories: @@ -1389,7 +1419,7 @@ H5_DLL herr_t H5CX_pop(bool update_dxpl_props); #define FUNC_ENTER_NOAPI_NOINIT \ { \ FUNC_ENTER_COMMON(!H5_IS_API(__func__)); \ - { + if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) { /* * Use this macro for non-API functions which fall into these categories: @@ -1403,7 +1433,7 @@ H5_DLL herr_t H5CX_pop(bool update_dxpl_props); #define FUNC_ENTER_NOAPI_NOINIT_NOERR \ { \ FUNC_ENTER_COMMON_NOERR(!H5_IS_API(__func__)); \ - { + if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) { /* * Use this macro for non-API functions that shouldn't perform _any_ initialization @@ -1425,7 +1455,8 @@ H5_DLL herr_t H5CX_pop(bool update_dxpl_props); \ FUNC_ENTER_COMMON(!H5_IS_API(__func__)); \ H5AC_tag(tag, &prev_tag); \ - { + FUNC_ENTER_NOAPI_INIT(err) \ + if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) { #define FUNC_ENTER_NOAPI_NOINIT_TAG(tag) \ { \ @@ -1433,19 +1464,19 @@ H5_DLL herr_t H5CX_pop(bool update_dxpl_props); \ FUNC_ENTER_COMMON(!H5_IS_API(__func__)); \ H5AC_tag(tag, &prev_tag); \ - { + if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) { /* Use this macro for all "normal" package-level functions */ #define FUNC_ENTER_PACKAGE \ { \ FUNC_ENTER_COMMON(H5_IS_PKG(__func__)); \ - { + if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) { /* Use this macro for package-level functions which propagate errors, but don't issue them */ #define FUNC_ENTER_PACKAGE_NOERR \ { \ FUNC_ENTER_COMMON_NOERR(H5_IS_PKG(__func__)); \ - { + if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) { /* Use the following macro as replacement for the FUNC_ENTER_PACKAGE * macro when the function needs to set up a metadata tag. */ @@ -1455,14 +1486,7 @@ H5_DLL herr_t H5CX_pop(bool update_dxpl_props); \ FUNC_ENTER_COMMON(H5_IS_PKG(__func__)); \ H5AC_tag(tag, &prev_tag); \ - { - -/* Use this macro for staticly-scoped functions which propagate errors, but don't issue them */ -/* And that shouldn't push their name on the function stack */ -#define FUNC_ENTER_PACKAGE_NOERR_NOFS \ - { \ - FUNC_ENTER_COMMON_NOERR(H5_IS_PKG(__func__)); \ - { + if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) { /* * Use this macro for non-API functions that shouldn't perform _any_ initialization @@ -1572,6 +1596,27 @@ H5_DLL herr_t H5CX_pop(bool update_dxpl_props); return (ret_value); \ } /*end scope from beginning of FUNC_ENTER*/ +/* Macros to declare package initialization function, if a package initialization routine is defined */ +#ifdef H5_PKG_SINGLE_SOURCE +#define H5_PKG_DECLARE_YES_FUNC(pkg) static herr_t H5_PACKAGE_INIT_FUNC(pkg)(void); +#else +#define H5_PKG_DECLARE_YES_FUNC(pkg) extern herr_t H5_PACKAGE_INIT_FUNC(pkg)(void); +#endif +#define H5_PKG_DECLARE_NO_FUNC(pkg) + +/* Declare package initialization symbols (if in a package) */ +#ifdef H5_PKG_SINGLE_SOURCE +#define H5_PKG_DECLARE_VAR(pkg) static bool H5_PACKAGE_INIT_VAR(pkg); +#else +#define H5_PKG_DECLARE_VAR(pkg) extern bool H5_PACKAGE_INIT_VAR(pkg); +#endif +#define H5_PKG_DECLARE_FUNC(pkg_init, pkg) H5_GLUE3(H5_PKG_DECLARE_, pkg_init, _FUNC)(pkg) + +#ifdef H5_MY_PKG +H5_PKG_DECLARE_VAR(H5_MY_PKG) +H5_PKG_DECLARE_FUNC(H5_MY_PKG_INIT, H5_MY_PKG) +#endif + /* Macro to begin/end tagging (when FUNC_ENTER_*TAG macros are insufficient). * Make sure to use HGOTO_ERROR_TAG and HGOTO_DONE_TAG between these macros! */ #define H5_BEGIN_TAG(tag) \ diff --git a/src/Makefile.am b/src/Makefile.am index 87b12d08b06..9d09893c3be 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -54,7 +54,7 @@ libhdf5_la_SOURCES= H5.c H5build_settings.c H5checksum.c H5dbg.c H5system.c \ H5FAint.c H5FAstat.c H5FAtest.c \ H5FD.c H5FDcore.c H5FDfamily.c H5FDint.c H5FDlog.c H5FDmulti.c \ H5FDonion.c H5FDonion_header.c H5FDonion_history.c H5FDonion_index.c \ - H5FDperform.c H5FDsec2.c H5FDspace.c \ + H5FDsec2.c H5FDspace.c \ H5FDsplitter.c H5FDstdio.c H5FDtest.c H5FDwindows.c \ H5FL.c H5FO.c H5FS.c H5FScache.c H5FSdbg.c H5FSint.c H5FSsection.c \ H5FSstat.c H5FStest.c \