diff --git a/src/H5.c b/src/H5.c index 1d0c2cffc5f..cd6171468cc 100644 --- a/src/H5.c +++ b/src/H5.c @@ -58,6 +58,7 @@ static void H5__debug_mask(const char *); #ifdef H5_HAVE_PARALLEL static int H5__mpi_delete_cb(MPI_Comm comm, int keyval, void *attr_val, int *flag); #endif /*H5_HAVE_PARALLEL*/ +static herr_t H5_check_version(unsigned majnum, unsigned minnum, unsigned relnum); /*********************/ /* Package Variables */ @@ -143,6 +144,10 @@ H5_init_library(void) if (H5_INIT_GLOBAL || H5_TERM_GLOBAL) HGOTO_DONE(SUCCEED); + /* Check library version */ + /* (Will abort() on failure) */ + H5_check_version(H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE); + /* Set the 'library initialized' flag as early as possible, to avoid * possible re-entrancy. */ @@ -225,20 +230,27 @@ H5_init_library(void) } /* end if */ /* - * Initialize interfaces that might not be able to initialize themselves - * soon enough. The file & dataset interfaces must be initialized because - * calling H5P_create() might require the file/dataset property classes to be - * initialized. The property interface must be initialized before the file - * & dataset interfaces though, in order to provide them with the proper - * property classes. - * The link interface needs to be initialized so that link property lists - * have their properties registered. + * Initialize interfaces that use macros of the form "(H5OPEN )", so + * that the variable returned through the macros nas been initialized. + * Also initialize some interfaces that might not be able to initialize + * themselves soon enough. + * + * Interfaces returning variables through a macro: H5E, H5O, H5P, H5T + * + * The link interface needs to be initialized so that the external link + * class is registered. + * * The FS module needs to be initialized as a result of the fix for HDFFV-10160: * It might not be initialized during normal file open. * When the application does not close the file, routines in the module might * be called via H5_term_library() when shutting down the file. + * * The dataspace interface needs to be initialized so that future IDs for * dataspaces work. + * + * The VOL interface needs to be initialized so that the default VOL + * connector and the VOL-managed interfaces are set up. + * */ if (H5E_init() < 0) HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize error interface"); @@ -246,14 +258,16 @@ H5_init_library(void) 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 (H5O_init() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize object 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"); + if (H5T_init() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize datatype interface"); /* Finish initializing interfaces that depend on the interfaces above */ if (H5P_init_phase2() < 0) @@ -489,14 +503,14 @@ H5dont_atexit(void) { herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_API_NOINIT_NOERR_NOFS + FUNC_ENTER_API_NOINIT_NOERR if (H5_dont_atexit_g) ret_value = FAIL; else H5_dont_atexit_g = true; - FUNC_LEAVE_API_NOFS(ret_value) + FUNC_LEAVE_API_NOERR(ret_value) } /* end H5dont_atexit() */ /*------------------------------------------------------------------------- @@ -774,13 +788,10 @@ H5get_libversion(unsigned *majnum /*out*/, unsigned *minnum /*out*/, unsigned *r } /* end H5get_libversion() */ /*------------------------------------------------------------------------- - * Function: H5check_version + * Function: H5__check_version * - * Purpose: Verifies that the arguments match the version numbers - * compiled into the library. This function is intended to be - * called from user to verify that the versions of header files - * compiled into the application match the version of the hdf5 - * library. + * Purpose: Internal routine which Verifies that the arguments match the + * version numbers compiled into the library. * * Within major.minor.release version, the expectation * is that all release versions are compatible, exceptions to @@ -810,18 +821,18 @@ H5get_libversion(unsigned *majnum /*out*/, unsigned *minnum /*out*/, unsigned *r "You should recompile the application or check your shared library related\n" \ "settings such as 'LD_LIBRARY_PATH'.\n" -herr_t -H5check_version(unsigned majnum, unsigned minnum, unsigned relnum) +static herr_t +H5_check_version(unsigned majnum, unsigned minnum, unsigned relnum) { char lib_str[256]; char substr[] = H5_VERS_SUBRELEASE; - static int checked = 0; /* If we've already checked the version info */ + static bool checked = false; /* If we've already checked the version info */ static unsigned int disable_version_check = 0; /* Set if the version check should be disabled */ static const char *version_mismatch_warning = VERSION_MISMATCH_WARNING; static const char *release_mismatch_warning = RELEASE_MISMATCH_WARNING; herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_API_NOINIT_NOERR_NOFS + FUNC_ENTER_NOAPI_NOINIT_NOERR /* Don't check again, if we already have */ if (checked) @@ -918,7 +929,7 @@ H5check_version(unsigned majnum, unsigned minnum, unsigned relnum) } /* end if (H5_VERS_RELEASE != relnum) */ /* Indicate that the version check has been performed */ - checked = 1; + checked = true; if (!disable_version_check) { /* @@ -946,7 +957,21 @@ H5check_version(unsigned majnum, unsigned minnum, unsigned relnum) } done: - FUNC_LEAVE_API_NOFS(ret_value) + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5__check_version() */ + +herr_t +H5check_version(unsigned majnum, unsigned minnum, unsigned relnum) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API_NOINIT_NOERR + + /* Call internal routine */ + /* (Will abort() on failure) */ + H5_check_version(majnum, minnum, relnum); + + FUNC_LEAVE_API_NOERR(ret_value) } /* end H5check_version() */ /*------------------------------------------------------------------------- @@ -1029,11 +1054,11 @@ H5close(void) * whole library just to release it all right away. It is safe to call * this function for an uninitialized library. */ - FUNC_ENTER_API_NOINIT_NOERR_NOFS + FUNC_ENTER_API_NOINIT_NOERR H5_term_library(); - FUNC_LEAVE_API_NOFS(SUCCEED) + FUNC_LEAVE_API_NOERR(SUCCEED) } /* end H5close() */ /*------------------------------------------------------------------------- diff --git a/src/H5Fpublic.h b/src/H5Fpublic.h index 1e5a84cdb09..41da8296521 100644 --- a/src/H5Fpublic.h +++ b/src/H5Fpublic.h @@ -20,45 +20,23 @@ #include "H5ACpublic.h" /* Metadata Cache */ #include "H5Ipublic.h" /* Identifiers */ -/* When this header is included from a private header, don't make calls to H5check() */ -#undef H5CHECK -#ifndef H5private_H -#define H5CHECK H5check(), -#else /* H5private_H */ -#define H5CHECK -#endif /* H5private_H */ - -/* When this header is included from a private HDF5 header, don't make calls to H5open() */ -#undef H5OPEN -#ifndef H5private_H -#define H5OPEN H5open(), -#else /* H5private_H */ -#define H5OPEN -#endif /* H5private_H */ - /* * These are the bits that can be passed to the `flags' argument of * H5Fcreate() and H5Fopen(). Use the bit-wise OR operator (|) to combine - * them as needed. As a side effect, they call H5check_version() to make sure - * that the application is compiled with a version of the hdf5 header files - * which are compatible with the library to which the application is linked. - * We're assuming that these constants are used rather early in the hdf5 - * session. - */ -#define H5F_ACC_RDONLY (H5CHECK H5OPEN 0x0000u) /**< Absence of RDWR: read-only */ -#define H5F_ACC_RDWR (H5CHECK H5OPEN 0x0001u) /**< Open for read and write */ -#define H5F_ACC_TRUNC (H5CHECK H5OPEN 0x0002u) /**< Overwrite existing files */ -#define H5F_ACC_EXCL (H5CHECK H5OPEN 0x0004u) /**< Fail if file already exists*/ + * them as needed. + */ +#define H5F_ACC_RDONLY (0x0000u) /**< Absence of RDWR: read-only */ +#define H5F_ACC_RDWR (0x0001u) /**< Open for read and write */ +#define H5F_ACC_TRUNC (0x0002u) /**< Overwrite existing files */ +#define H5F_ACC_EXCL (0x0004u) /**< Fail if file already exists*/ /* NOTE: 0x0008u was H5F_ACC_DEBUG, now deprecated */ -#define H5F_ACC_CREAT (H5CHECK H5OPEN 0x0010u) /**< Create non-existing files */ -#define H5F_ACC_SWMR_WRITE \ - (H5CHECK 0x0020u) /**< Indicate that this file is open for writing in a \ +#define H5F_ACC_CREAT (0x0010u) /**< Create non-existing files */ +#define H5F_ACC_SWMR_WRITE (0x0020u) /**< Indicate that this file is open for writing in a \ * single-writer/multi-reader (SWMR) scenario. \ * Note that the process(es) opening the file for reading \ * must open the file with #H5F_ACC_RDONLY and use the \ * #H5F_ACC_SWMR_READ access flag. */ -#define H5F_ACC_SWMR_READ \ - (H5CHECK 0x0040u) /**< Indicate that this file is open for reading in a \ +#define H5F_ACC_SWMR_READ (0x0040u) /**< Indicate that this file is open for reading in a \ * single-writer/multi-reader (SWMR) scenario. Note that \ * the process(es) opening the file for SWMR reading must \ * also open the file with the #H5F_ACC_RDONLY flag. */ @@ -69,7 +47,7 @@ * \internal Value passed to H5Pset_elink_acc_flags to cause flags to be taken from the parent file. * \internal ignore setting on lapl */ -#define H5F_ACC_DEFAULT (H5CHECK H5OPEN 0xffffu) +#define H5F_ACC_DEFAULT (0xffffu) /* Flags for H5Fget_obj_count() & H5Fget_obj_ids() calls */ #define H5F_OBJ_FILE (0x0001u) /**< File objects */ @@ -78,9 +56,8 @@ #define H5F_OBJ_DATATYPE (0x0008u) /**< Datatype objects */ #define H5F_OBJ_ATTR (0x0010u) /**< Attribute objects */ #define H5F_OBJ_ALL (H5F_OBJ_FILE | H5F_OBJ_DATASET | H5F_OBJ_GROUP | H5F_OBJ_DATATYPE | H5F_OBJ_ATTR) -#define H5F_OBJ_LOCAL \ - (0x0020u) /**< Restrict search to objects opened through current file ID \ - (as opposed to objects opened through any file ID accessing this file) */ +#define H5F_OBJ_LOCAL (0x0020u) /**< Restrict search to objects opened through current file ID \ + (as opposed to objects opened through any file ID accessing this file) */ #define H5F_FAMILY_DEFAULT 0 /* (hsize_t) */ @@ -1878,7 +1855,7 @@ H5_DLL herr_t H5Fformat_convert(hid_t fid); #ifndef H5_NO_DEPRECATED_SYMBOLS /* Macros */ -#define H5F_ACC_DEBUG (H5CHECK H5OPEN 0x0000u) /**< Print debug info \deprecated In which version? */ +#define H5F_ACC_DEBUG (0x0000u) /**< Print debug info \deprecated In which version? */ /* Typedefs */ diff --git a/src/H5Oint.c b/src/H5Oint.c index b58c68d0547..444c42ef002 100644 --- a/src/H5Oint.c +++ b/src/H5Oint.c @@ -179,6 +179,28 @@ static const H5O_obj_class_t *const H5O_obj_class_g[] = { H5O_OBJ_GROUP, /* Group object (H5O_TYPE_GROUP - 0) */ }; +/*------------------------------------------------------------------------- + * Function: H5O_init + * + * Purpose: Initialize the interface from some other package. + * + * Return: Success: non-negative + * Failure: negative + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_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 H5O_init() */ + /*------------------------------------------------------------------------- * Function: H5O__init_package * diff --git a/src/H5private.h b/src/H5private.h index afdb7132429..4fc0ba1acdb 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1339,12 +1339,11 @@ H5_DLL herr_t H5CX_pop(bool update_dxpl_props); /* * Use this macro for API functions that shouldn't perform _any_ initialization - * of the library or an interface or push themselves on the function - * stack, just perform tracing, etc. Examples + * of the library or an interface and also don't return errors. Examples * are: H5close, H5check_version, etc. * */ -#define FUNC_ENTER_API_NOINIT_NOERR_NOFS \ +#define FUNC_ENTER_API_NOINIT_NOERR \ { \ { \ { \ @@ -1531,8 +1530,8 @@ H5_DLL herr_t H5CX_pop(bool update_dxpl_props); } \ } /*end scope from beginning of FUNC_ENTER*/ -/* Use this macro to match the FUNC_ENTER_API_NOINIT_NOERR_NOFS macro */ -#define FUNC_LEAVE_API_NOFS(ret_value) \ +/* Use this macro to match the FUNC_ENTER_API_NOINIT_NOERR macro */ +#define FUNC_LEAVE_API_NOERR(ret_value) \ ; \ } /*end scope from end of FUNC_ENTER*/ \ H5_API_UNLOCK \