From d76c617c0b0aaf11895d9a03608cecf3c9c5bc60 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 3 Oct 2024 13:26:22 -0500 Subject: [PATCH] Avoid calling into H5open if the library is already initialized Signed-off-by: Quincey Koziol --- src/H5Epublic.h | 2 +- src/H5FDcore.h | 2 +- src/H5FDdirect.h | 2 +- src/H5FDfamily.h | 2 +- src/H5FDhdfs.h | 2 +- src/H5FDlog.h | 2 +- src/H5FDmirror.h | 2 +- src/H5FDmpio.h | 2 +- src/H5FDmulti.h | 2 +- src/H5FDonion.h | 2 +- src/H5FDros3.h | 2 +- src/H5FDsec2.h | 2 +- src/H5FDsplitter.h | 2 +- src/H5FDstdio.h | 2 +- src/H5FDsubfiling/H5FDioc.h | 2 +- src/H5FDsubfiling/H5FDsubfiling.h | 2 +- src/H5FDwindows.h | 2 +- src/H5Opublic.h | 8 ++++++++ src/H5Ppublic.h | 2 +- src/H5Tpublic.h | 2 +- src/H5private.h | 4 ---- src/H5public.h | 7 +++++++ 22 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/H5Epublic.h b/src/H5Epublic.h index 9263c3c96bf..186c97ce799 100644 --- a/src/H5Epublic.h +++ b/src/H5Epublic.h @@ -52,7 +52,7 @@ typedef struct H5E_error2_t { /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDcore.h b/src/H5FDcore.h index 3d1159e7700..aae78b32c02 100644 --- a/src/H5FDcore.h +++ b/src/H5FDcore.h @@ -22,7 +22,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDdirect.h b/src/H5FDdirect.h index 1b75d75d5b2..9217adadf4b 100644 --- a/src/H5FDdirect.h +++ b/src/H5FDdirect.h @@ -24,7 +24,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDfamily.h b/src/H5FDfamily.h index 644455268f9..74071299142 100644 --- a/src/H5FDfamily.h +++ b/src/H5FDfamily.h @@ -22,7 +22,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDhdfs.h b/src/H5FDhdfs.h index 5178de841b2..4b978e15765 100644 --- a/src/H5FDhdfs.h +++ b/src/H5FDhdfs.h @@ -26,7 +26,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDlog.h b/src/H5FDlog.h index b2cce4e45f1..aef7539b760 100644 --- a/src/H5FDlog.h +++ b/src/H5FDlog.h @@ -23,7 +23,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDmirror.h b/src/H5FDmirror.h index beee959a8f3..3bcbdc4ec7f 100644 --- a/src/H5FDmirror.h +++ b/src/H5FDmirror.h @@ -25,7 +25,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDmpio.h b/src/H5FDmpio.h index f2bd5b1fa8e..94facfede5e 100644 --- a/src/H5FDmpio.h +++ b/src/H5FDmpio.h @@ -24,7 +24,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDmulti.h b/src/H5FDmulti.h index d21103fd42b..c08e0be33f5 100644 --- a/src/H5FDmulti.h +++ b/src/H5FDmulti.h @@ -23,7 +23,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDonion.h b/src/H5FDonion.h index 9302b09647d..a404dc225c9 100644 --- a/src/H5FDonion.h +++ b/src/H5FDonion.h @@ -22,7 +22,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDros3.h b/src/H5FDros3.h index 2807c5f651c..dd48ba27931 100644 --- a/src/H5FDros3.h +++ b/src/H5FDros3.h @@ -24,7 +24,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDsec2.h b/src/H5FDsec2.h index d51df368ac0..b2a8cd05eb2 100644 --- a/src/H5FDsec2.h +++ b/src/H5FDsec2.h @@ -23,7 +23,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDsplitter.h b/src/H5FDsplitter.h index b1fa029adf7..32cb50a8946 100644 --- a/src/H5FDsplitter.h +++ b/src/H5FDsplitter.h @@ -23,7 +23,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDstdio.h b/src/H5FDstdio.h index c0d11a8c7e3..2cf2c8d5e94 100644 --- a/src/H5FDstdio.h +++ b/src/H5FDstdio.h @@ -23,7 +23,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDsubfiling/H5FDioc.h b/src/H5FDsubfiling/H5FDioc.h index ea7e62dcf7f..589abb22cc4 100644 --- a/src/H5FDsubfiling/H5FDioc.h +++ b/src/H5FDsubfiling/H5FDioc.h @@ -28,7 +28,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDsubfiling/H5FDsubfiling.h b/src/H5FDsubfiling/H5FDsubfiling.h index 5838938e4af..a163f36c5e8 100644 --- a/src/H5FDsubfiling/H5FDsubfiling.h +++ b/src/H5FDsubfiling/H5FDsubfiling.h @@ -22,7 +22,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5FDwindows.h b/src/H5FDwindows.h index 07a11cd8f1a..e9975993589 100644 --- a/src/H5FDwindows.h +++ b/src/H5FDwindows.h @@ -26,7 +26,7 @@ /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5Opublic.h b/src/H5Opublic.h index 28954d4cb45..0851245afe3 100644 --- a/src/H5Opublic.h +++ b/src/H5Opublic.h @@ -1681,6 +1681,14 @@ H5_DLL herr_t H5Otoken_from_str(hid_t loc_id, const char *token_str, H5O_token_t #endif /// \endcond +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + /* The canonical 'undefined' token value */ #define H5O_TOKEN_UNDEF (H5OPEN H5O_TOKEN_UNDEF_g) H5_DLLVAR const H5O_token_t H5O_TOKEN_UNDEF_g; diff --git a/src/H5Ppublic.h b/src/H5Ppublic.h index 273250017a3..00360e0f206 100644 --- a/src/H5Ppublic.h +++ b/src/H5Ppublic.h @@ -37,7 +37,7 @@ /* When this header is included from a private HDF5 header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index 57a5b6047c3..a8344f2db6c 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -242,7 +242,7 @@ typedef H5T_conv_ret_t (*H5T_conv_except_func_t)(H5T_conv_except_t except_type, /* When this header is included from a private header, don't make calls to H5open() */ #undef H5OPEN #ifndef H5private_H -#define H5OPEN H5open(), +#define H5OPEN ((!H5_libinit_g && !H5_libterm_g) ? H5open() : 0), #else /* H5private_H */ #define H5OPEN #endif /* H5private_H */ diff --git a/src/H5private.h b/src/H5private.h index 7a579521ae3..2eb418e8654 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1207,10 +1207,6 @@ extern char H5_lib_vers_info_g[]; #endif /* H5_HAVE_THREADSAFE */ -/* Library init / term status (global) */ -extern bool H5_libinit_g; /* Has the library been initialized? */ -extern bool H5_libterm_g; /* Is the library being shutdown? */ - /* Macros for accessing the global variables */ #define H5_INIT_GLOBAL (H5_libinit_g) #define H5_TERM_GLOBAL (H5_libterm_g) diff --git a/src/H5public.h b/src/H5public.h index 460aca5f1e1..d436d4ffb38 100644 --- a/src/H5public.h +++ b/src/H5public.h @@ -434,6 +434,13 @@ typedef void (*H5_atclose_func_t)(void *ctx); extern "C" { #endif +/** @private + * + * \brief Library init / term status (global) + */ +H5_DLLVAR bool H5_libinit_g; /* Has the library been initialized? */ +H5_DLLVAR bool H5_libterm_g; /* Is the library being shutdown? */ + /* Functions in H5.c */ /** * \ingroup H5