From a2dff313f7b0ccd5c0904d6e2c1cec824c5d93fa Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Wed, 13 Mar 2024 08:25:59 -0700 Subject: [PATCH 1/4] Fix for H5Literate() callback versioning The netCDF library supports many versions of HDF5, which handles API compatibility via a set of API-call-specific macros. netCDF uses H5Literate(), which was versioned in the 1.12.x maintenance line in order to better support the virtual object layer (VOL). h5_test/tst_h_files4.c failed to compile with certain compilers when the HDF5 library was built using pre-VOL versions of the library- e.g., 1.10, which can be configured with --with-default-api-version=110. This was due to the API compatibility macros being used to select the 1.10 version of H5Literate(), but not its callback function, which was set using a `H5_VERSION_GE()` macro that does not take the compatibility macros into consideration. Fixing the problem involved removing the `H5_VERSION_GE()` macro and letting the compatibility macros handle the versioning, and using the `H5_USE_XXX_API_DEFAULT` symbols to protect the H5Oopen_by_addr() call used in the callback (a new call that wasn't versioned, hence the different protection mechanism). Tested w/ HDF5's develop branch w/ both 1.14 and 1.10 API bindings Fixes #2886 (4118 in HDF5's issue tracker) --- h5_test/tst_h_files4.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/h5_test/tst_h_files4.c b/h5_test/tst_h_files4.c index 3e82f352e1..a8f89c6ed7 100644 --- a/h5_test/tst_h_files4.c +++ b/h5_test/tst_h_files4.c @@ -45,21 +45,18 @@ with the H5Lvisit function call */ herr_t op_func (hid_t g_id, const char *name, -#if H5_VERSION_GE(1,12,0) - const H5L_info2_t *info, -#else - const H5L_info_t *info, -#endif + const H5L_info_t *info, void *op_data) { hid_t id; H5I_type_t obj_type; strcpy((char *)op_data, name); -#if H5_VERSION_GE(1,12,0) - if ((id = H5Oopen_by_token(g_id, info->u.token)) < 0) ERR; -#else +#if defined(H5_USE_110_API_DEFAULT) || defined(H5_USE_18_API_DEFAULT) || defined(H5_USE_16_API_DEFAULT) if ((id = H5Oopen_by_addr(g_id, info->u.address)) < 0) ERR; +#else + /* HDF5 1.12 switched from addresses to tokens to better support the VOL */ + if ((id = H5Oopen_by_token(g_id, info->u.token)) < 0) ERR; #endif /* Using H5Ovisit is really slow. Use H5Iget_type for a fast From 32f12d1c1b85e98ae529cefe328646c0153ab5b3 Mon Sep 17 00:00:00 2001 From: Dana Robinson <43805+derobins@users.noreply.github.com> Date: Wed, 13 Mar 2024 08:49:00 -0700 Subject: [PATCH 2/4] Update tst_h_files4.c --- h5_test/tst_h_files4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5_test/tst_h_files4.c b/h5_test/tst_h_files4.c index a8f89c6ed7..607b7579c8 100644 --- a/h5_test/tst_h_files4.c +++ b/h5_test/tst_h_files4.c @@ -45,7 +45,7 @@ with the H5Lvisit function call */ herr_t op_func (hid_t g_id, const char *name, - const H5L_info_t *info, + const H5L_info_t *info, void *op_data) { hid_t id; From ae85c3466122442e13211fedf1324e8292f5c8ec Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Wed, 13 Mar 2024 13:40:02 -0700 Subject: [PATCH 3/4] Update tst_h_files4.c to work with HDF5 1.8 HDF5 1.8 never defined H5_USE_18_API_DEFAULT --- h5_test/tst_h_files4.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/h5_test/tst_h_files4.c b/h5_test/tst_h_files4.c index a8f89c6ed7..cabd0b231a 100644 --- a/h5_test/tst_h_files4.c +++ b/h5_test/tst_h_files4.c @@ -52,7 +52,11 @@ op_func (hid_t g_id, const char *name, H5I_type_t obj_type; strcpy((char *)op_data, name); -#if defined(H5_USE_110_API_DEFAULT) || defined(H5_USE_18_API_DEFAULT) || defined(H5_USE_16_API_DEFAULT) +#if H5_VERSION_LE(1, 10, 11) || defined(H5_USE_110_API_DEFAULT) || defined(H5_USE_18_API_DEFAULT) || defined(H5_USE_16_API_DEFAULT) + /* This library is either 1.10.11 (the last 1.10 release) or earlier + * OR this a later version of the library built with a 1.10 or + * earlier API. + */ if ((id = H5Oopen_by_addr(g_id, info->u.address)) < 0) ERR; #else /* HDF5 1.12 switched from addresses to tokens to better support the VOL */ From c9bbf8f62629e39b9451741c06eeffe21c3066c8 Mon Sep 17 00:00:00 2001 From: Dana Robinson <43805+derobins@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:43:17 -0700 Subject: [PATCH 4/4] Fix typo and clarify comment --- h5_test/tst_h_files4.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/h5_test/tst_h_files4.c b/h5_test/tst_h_files4.c index 25491ade26..0d61fdea8f 100644 --- a/h5_test/tst_h_files4.c +++ b/h5_test/tst_h_files4.c @@ -54,8 +54,9 @@ op_func (hid_t g_id, const char *name, strcpy((char *)op_data, name); #if H5_VERSION_LE(1, 10, 11) || defined(H5_USE_110_API_DEFAULT) || defined(H5_USE_18_API_DEFAULT) || defined(H5_USE_16_API_DEFAULT) /* This library is either 1.10.11 (the last 1.10 release) or earlier - * OR this a later version of the library built with a 1.10 or - * earlier API. + * OR this is a later version of the library built with a 1.10 or + * earlier API (earlier versions did not define their own USE + * API symbol). */ if ((id = H5Oopen_by_addr(g_id, info->u.address)) < 0) ERR; #else