Skip to content

Commit

Permalink
Switch VOL connector macros to use "H5OPEN, <id>" idiom
Browse files Browse the repository at this point in the history
Aligns them with the way the H5T, H5P, H5E packages return an ID back to
an application, and removes calling an internal routine from the public header.

Extra work for the internal passthru connector, to keep the main passthru
source file using only public API calls.

Signed-off-by: Quincey Koziol <[email protected]>
  • Loading branch information
qkoziol committed Sep 27, 2024
1 parent 10839a4 commit 7be1641
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 76 deletions.
2 changes: 1 addition & 1 deletion java/src/jni/h5Constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -3500,7 +3500,7 @@ Java_hdf_hdf5lib_HDF5Constants_H5VL_1CAP_1FLAG_1THREADSAFE(JNIEnv *env, jclass c
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5VL_1NATIVE(JNIEnv *env, jclass cls)
{
return H5VLget_connector_id_by_value(H5VL_NATIVE_VALUE);
return H5VL_NATIVE;
}
JNIEXPORT jobject JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5VL_1NATIVE_1NAME(JNIEnv *env, jclass cls)
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ set (H5VL_SOURCES
${HDF5_SRC_DIR}/H5VLnative_object.c
${HDF5_SRC_DIR}/H5VLnative_token.c
${HDF5_SRC_DIR}/H5VLpassthru.c
${HDF5_SRC_DIR}/H5VLpassthru_int.c
${HDF5_SRC_DIR}/H5VLquery.c
${HDF5_SRC_DIR}/H5VLtest.c
)
Expand Down
2 changes: 1 addition & 1 deletion src/H5VL.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ H5VLunregister_connector(hid_t vol_id)
HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, FAIL, "not a VOL connector ID");

/* For the time being, we disallow unregistering the native VOL connector */
native = H5VL_NATIVE;
native = H5VL_NATIVE_conn_g;
if (H5VL_cmp_connector_cls(&cmp_value, connector->cls, native->cls) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTCOMPARE, FAIL, "can't compare connector classes");
if (0 == cmp_value)
Expand Down
25 changes: 17 additions & 8 deletions src/H5VLint.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
#include "H5VLpkg.h" /* Virtual Object Layer */

/* VOL connectors */
#include "H5VLnative_private.h" /* Native VOL connector */
#include "H5VLpassthru.h" /* Pass-through VOL connector */
#include "H5VLnative_private.h" /* Native VOL connector */
#include "H5VLpassthru_private.h" /* Pass-through VOL connector */

/****************/
/* Local Macros */
Expand Down Expand Up @@ -217,6 +217,12 @@ H5VL_init_phase2(void)

/* clang-format on */

/* Register internal VOL connectors */
if (H5VL__native_register() < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "unable to register native VOL connector");
if (H5VL__passthru_register() < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "unable to register passthru VOL connector");

/* Sanity check default VOL connector */
assert(H5VL_def_conn_s.connector == NULL);
assert(H5VL_def_conn_s.connector_info == NULL);
Expand Down Expand Up @@ -258,6 +264,11 @@ H5VL_term_package(void)
if (H5I_nmembers(H5I_VOL) > 0) {
/* Unregister all VOL connectors */
(void)H5I_clear_type(H5I_VOL, true, false);

/* Reset internal VOL connectors' global vars */
(void)H5VL__native_unregister();
(void)H5VL__passthru_unregister();

n++;
} /* end if */
else {
Expand Down Expand Up @@ -377,15 +388,13 @@ H5VL__set_def_conn(void)
else {
/* Check for VOL connectors that ship with the library */
if (!strcmp(tok, "native")) {
connector = H5VL_NATIVE;
connector = H5VL_NATIVE_conn_g;

/* Inc. refcount on connector object, so it can be uniformly released */
H5VL_conn_inc_rc(connector);
} /* end if */
else if (!strcmp(tok, "pass_through")) {
if (NULL == (connector = H5I_object(H5VL_PASSTHRU)))
HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL,
"can't get connector for internal pass-through VOL connector");
connector = H5VL_PASSTHRU_conn_g;

/* Inc. refcount on connector object, so it can be uniformly released */
H5VL_conn_inc_rc(connector);
Expand Down Expand Up @@ -1186,7 +1195,7 @@ H5VL_object_is_native(const H5VL_object_t *obj, bool *is_native)
HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get VOL connector class");

/* Retrieve the native connector class */
native = H5VL_NATIVE;
native = H5VL_NATIVE_conn_g;

/* Compare connector classes */
if (H5VL_cmp_connector_cls(&cmp_value, cls, native->cls) < 0)
Expand Down Expand Up @@ -2403,7 +2412,7 @@ H5VL_wrap_register(H5I_type_t type, void *obj, bool app_ref)
* field will get clobbered later, so disallow this.
*/
if (type == H5I_DATATYPE)
if (vol_wrap_ctx->connector == H5VL_NATIVE)
if (vol_wrap_ctx->connector == H5VL_NATIVE_conn_g)
if (true == H5T_already_vol_managed((const H5T_t *)obj))
HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, H5I_INVALID_HID, "can't wrap an uncommitted datatype");

Expand Down
51 changes: 27 additions & 24 deletions src/H5VLnative.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@
#include "H5VLnative_private.h" /* Native VOL connector */

/* The native VOL connector */
static H5VL_connector_t *H5VL_NATIVE_conn_g = NULL;

/* Prototypes */
static herr_t H5VL__native_term(void);
hid_t H5VL_NATIVE_g = H5I_INVALID_HID;
H5VL_connector_t *H5VL_NATIVE_conn_g = NULL;

#define H5VL_NATIVE_CAP_FLAGS \
(H5VL_CAP_FLAG_NATIVE_FILES | H5VL_CAP_FLAG_ATTR_BASIC | H5VL_CAP_FLAG_ATTR_MORE | \
Expand All @@ -66,7 +64,7 @@ static const H5VL_class_t H5VL_native_cls_g = {
H5VL_NATIVE_VERSION, /* connector version */
H5VL_NATIVE_CAP_FLAGS, /* capability flags */
NULL, /* initialize */
H5VL__native_term, /* terminate */
NULL, /* terminate */
{
/* info_cls */
(size_t)0, /* info size */
Expand Down Expand Up @@ -182,54 +180,59 @@ static const H5VL_class_t H5VL_native_cls_g = {
};

/*-------------------------------------------------------------------------
* Function: H5VL_native_register
* Function: H5VL__native_register
*
* Purpose: Register the native VOL connector and retrieve an ID for it.
* Purpose: Register the native VOL connector and set up an ID for it.
*
* Return: Success: A pointer to the native connector
* Failure: NULL
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
H5VL_connector_t *
H5VL_native_register(void)
herr_t
H5VL__native_register(void)
{
H5VL_connector_t *ret_value = NULL;
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_NOAPI(NULL)
FUNC_ENTER_PACKAGE

/* Register the native VOL connector, if it isn't already */
if (NULL == H5VL_NATIVE_conn_g)
if (NULL ==
(H5VL_NATIVE_conn_g = H5VL__register_connector(&H5VL_native_cls_g, H5P_VOL_INITIALIZE_DEFAULT)))
HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, NULL, "can't create ID for native VOL connector");
if (NULL == (H5VL_NATIVE_conn_g = H5VL__register_connector(&H5VL_native_cls_g, H5P_VOL_INITIALIZE_DEFAULT)))
HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, FAIL, "can't register native VOL connector");

/* Set return value */
ret_value = H5VL_NATIVE_conn_g;
/* Get ID for connector */
if (H5I_VOL != H5I_get_type(H5VL_NATIVE_g)) {
if ((H5VL_NATIVE_g = H5I_register(H5I_VOL, H5VL_NATIVE_conn_g, false)) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, FAIL, "can't create ID for native VOL connector");

/* ID is holding a reference to the connector */
H5VL_conn_inc_rc(H5VL_NATIVE_conn_g);
}

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_native_register() */
} /* end H5VL__native_register() */

/*---------------------------------------------------------------------------
* Function: H5VL__native_term
* Function: H5VL__native_unregister
*
* Purpose: Shut down the native VOL
*
* Returns: SUCCEED (Can't fail)
*
*---------------------------------------------------------------------------
*/
static herr_t
H5VL__native_term(void)
herr_t
H5VL__native_unregister(void)
{
FUNC_ENTER_PACKAGE_NOERR

/* Reset VOL */
/* Reset VOL conector info */

Check failure on line 230 in src/H5VLnative.c

View workflow job for this annotation

GitHub Actions / Check for spelling errors

conector ==> connector
H5VL_NATIVE_g = H5I_INVALID_HID;
H5VL_NATIVE_conn_g = NULL;

FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5VL__native_term() */
} /* end H5VL__native_unregister() */

/*---------------------------------------------------------------------------
* Function: H5VL__native_introspect_get_conn_cls
Expand Down
14 changes: 14 additions & 0 deletions src/H5VLnative.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
/* Public Macros */
/*****************/

/* When this header is included from a private header, don't make calls to H5open() */
#undef H5OPEN
#ifndef H5private_H
#define H5OPEN H5open(),
#else /* H5private_H */
#define H5OPEN
#endif /* H5private_H */

/* Identifier for the native VOL connector */
#define H5VL_NATIVE (H5OPEN H5VL_NATIVE_g)

/* Characteristics of the native VOL connector */
#define H5VL_NATIVE_NAME "native"
#define H5VL_NATIVE_VALUE H5_VOL_NATIVE /* enum value */
Expand Down Expand Up @@ -511,6 +522,9 @@ typedef union H5VL_native_object_optional_args_t {
extern "C" {
#endif

/* Global variable to hold the VOL connector ID */
H5_DLLVAR hid_t H5VL_NATIVE_g;

/* Token <--> address converters */

/**
Expand Down
11 changes: 3 additions & 8 deletions src/H5VLnative_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
/* Library Private Macros */
/**************************/

/* Identifier for the native VOL connector */
#define H5VL_NATIVE (H5VL_native_register())

/****************************/
/* Library Private Typedefs */
/****************************/
Expand All @@ -39,6 +36,9 @@
/* Library Private Variables */
/*****************************/

/* The native VOL connector */
H5_DLLVAR H5VL_connector_t *H5VL_NATIVE_conn_g;

/******************************/
/* Library Private Prototypes */
/******************************/
Expand Down Expand Up @@ -157,11 +157,6 @@ H5_DLL herr_t H5VL__native_token_to_str(void *obj, H5I_type_t obj_type, const H5
H5_DLL herr_t H5VL__native_str_to_token(void *obj, H5I_type_t obj_type, const char *token_str,
H5O_token_t *token);

/*
* Register the native VOL connector and retrieve a pointer to it
*/
H5_DLL H5VL_connector_t *H5VL_native_register(void);

/* Helper functions */
H5_DLL herr_t H5VL_native_get_file_addr_len(hid_t loc_id, size_t *addr_len);
H5_DLL herr_t H5VL__native_get_file_addr_len(void *obj, H5I_type_t obj_type, size_t *addr_len);
Expand Down
29 changes: 1 addition & 28 deletions src/H5VLpassthru.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static herr_t H5VL_pass_through_optional(void *obj, H5VL_optional_args_t *args,
/*******************/

/* Pass through VOL connector class struct */
static const H5VL_class_t H5VL_pass_through_g = {
const H5VL_class_t H5VL_pass_through_g = {
H5VL_VERSION, /* VOL class struct version */
(H5VL_class_value_t)H5VL_PASSTHRU_VALUE, /* value */
H5VL_PASSTHRU_NAME, /* name */
Expand Down Expand Up @@ -364,9 +364,6 @@ static const H5VL_class_t H5VL_pass_through_g = {
H5VL_pass_through_optional /* optional */
};

/* The connector identification number, initialized at runtime */
static hid_t H5VL_PASSTHRU_g = H5I_INVALID_HID;

/*-------------------------------------------------------------------------
* Function: H5VL__pass_through_new_obj
*
Expand Down Expand Up @@ -420,27 +417,6 @@ H5VL_pass_through_free_obj(H5VL_pass_through_t *obj)
return 0;
} /* end H5VL__pass_through_free_obj() */

/*-------------------------------------------------------------------------
* Function: H5VL_pass_through_register
*
* Purpose: Register the pass-through VOL connector and retrieve an ID
* for it.
*
* Return: Success: The ID for the pass-through VOL connector
* Failure: -1
*
*-------------------------------------------------------------------------
*/
hid_t
H5VL_pass_through_register(void)
{
/* Singleton register the pass-through VOL connector ID */
if (H5VL_PASSTHRU_g < 0)
H5VL_PASSTHRU_g = H5VLregister_connector(&H5VL_pass_through_g, H5P_DEFAULT);

return H5VL_PASSTHRU_g;
} /* end H5VL_pass_through_register() */

/*-------------------------------------------------------------------------
* Function: H5VL_pass_through_init
*
Expand Down Expand Up @@ -486,9 +462,6 @@ H5VL_pass_through_term(void)
printf("------- PASS THROUGH VOL TERM\n");
#endif

/* Reset VOL ID */
H5VL_PASSTHRU_g = H5I_INVALID_HID;

return 0;
} /* end H5VL_pass_through_term() */

Expand Down
13 changes: 11 additions & 2 deletions src/H5VLpassthru.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@
/* Public headers needed by this file */
#include "H5VLpublic.h" /* Virtual Object Layer */

/* When this header is included from a private header, don't make calls to H5open() */
#undef H5OPEN
#ifndef H5private_H
#define H5OPEN H5open(),
#else /* H5private_H */
#define H5OPEN
#endif /* H5private_H */

/* Identifier for the pass-through VOL connector */
#define H5VL_PASSTHRU (H5VL_pass_through_register())
#define H5VL_PASSTHRU (H5OPEN H5VL_PASSTHRU_g)

/* Characteristics of the pass-through VOL connector */
#define H5VL_PASSTHRU_NAME "pass_through"
Expand All @@ -38,7 +46,8 @@ typedef struct H5VL_pass_through_info_t {
extern "C" {
#endif

H5_DLL hid_t H5VL_pass_through_register(void);
/* Global variable to hold the VOL connector ID */
H5_DLLVAR hid_t H5VL_PASSTHRU_g;

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 7be1641

Please sign in to comment.