Skip to content

Commit

Permalink
Embrace more uses of H5_BEFORE_USER_CB*
Browse files Browse the repository at this point in the history
Signed-off-by: Quincey Koziol <quincey@koziol.cc>
  • Loading branch information
qkoziol committed Dec 17, 2024
1 parent 56d2f52 commit 18fe722
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 141 deletions.
25 changes: 15 additions & 10 deletions src/H5Eint.c
Original file line number Diff line number Diff line change
Expand Up @@ -1402,24 +1402,26 @@ H5E__walk(const H5E_stack_t *estack, H5E_direction_t direction, const H5E_walk_o
if (op->u.func2) {
ret_value = SUCCEED;
if (H5E_WALK_UPWARD == direction) {
for (i = 0; i < (int)estack->nused && ret_value == H5_ITER_CONT; i++)
for (i = 0; i < (int)estack->nused && ret_value == H5_ITER_CONT; i++) {
/* Prepare & restore library for user callback */
H5_BEFORE_USER_CB_NOERR(H5_ITER_ERROR)
{
ret_value = (op->u.func2)((unsigned)i, &estack->entries[i].err, client_data);
}
H5_AFTER_USER_CB_NOERR(H5_ITER_ERROR)
H5_AFTER_USER_CB_NOERR(H5_ITER_ERROR)
}
} /* end if */
else {
H5_CHECK_OVERFLOW(estack->nused - 1, size_t, int);
for (i = (int)(estack->nused - 1); i >= 0 && ret_value == H5_ITER_CONT; i--)
for (i = (int)(estack->nused - 1); i >= 0 && ret_value == H5_ITER_CONT; i--) {
/* Prepare & restore library for user callback */
H5_BEFORE_USER_CB_NOERR(H5_ITER_ERROR)
{
ret_value = (op->u.func2)((unsigned)(estack->nused - (size_t)(i + 1)),
&estack->entries[i].err, client_data);
}
H5_AFTER_USER_CB_NOERR(H5_ITER_ERROR)
H5_AFTER_USER_CB_NOERR(H5_ITER_ERROR)
}
} /* end else */

if (ret_value < 0)
Expand Down Expand Up @@ -1944,31 +1946,34 @@ H5E_dump_api_stack(void)
assert(estack);

#ifdef H5_NO_DEPRECATED_SYMBOLS
if (estack->auto_op.func2)
if (estack->auto_op.func2) {
/* Prepare & restore library for user callback */
H5_BEFORE_USER_CB_NOERR(H5_ITER_ERROR)
{
(void)((estack->auto_op.func2)(H5E_DEFAULT, estack->auto_data));
}
H5_AFTER_USER_CB_NOERR(H5_ITER_ERROR)
H5_AFTER_USER_CB_NOERR(H5_ITER_ERROR)
}
#else /* H5_NO_DEPRECATED_SYMBOLS */
if (estack->auto_op.vers == 1) {
if (estack->auto_op.func1)
if (estack->auto_op.func1) {
/* Prepare & restore library for user callback */
H5_BEFORE_USER_CB_NOERR(H5_ITER_ERROR)
{
(void)((estack->auto_op.func1)(estack->auto_data));
}
H5_AFTER_USER_CB_NOERR(H5_ITER_ERROR)
H5_AFTER_USER_CB_NOERR(H5_ITER_ERROR)
}
} /* end if */
else {
if (estack->auto_op.func2)
if (estack->auto_op.func2) {
/* Prepare & restore library for user callback */
H5_BEFORE_USER_CB_NOERR(H5_ITER_ERROR)
{
(void)((estack->auto_op.func2)(H5E_DEFAULT, estack->auto_data));
}
H5_AFTER_USER_CB_NOERR(H5_ITER_ERROR)
H5_AFTER_USER_CB_NOERR(H5_ITER_ERROR)
}
} /* end else */
#endif /* H5_NO_DEPRECATED_SYMBOLS */

Expand Down
69 changes: 33 additions & 36 deletions src/H5FD.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,6 @@ H5FD_open(bool try, H5FD_t **_file, const char *name, unsigned flags, hid_t fapl
if (HADDR_UNDEF == maxaddr)
maxaddr = driver->maxaddr;

/* clang-format off */
/* Try dispatching to file driver */
if (try) {
H5E_PAUSE_ERRORS
Expand Down Expand Up @@ -964,43 +963,41 @@ H5FD_open(bool try, H5FD_t **_file, const char *name, unsigned flags, hid_t fapl
if (NULL == file)
HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, FAIL, "can't open file");
}
/* clang-format on */

/* Set the file access flags */
file->access_flags = flags;
/* Set the file access flags */
file->access_flags = flags;

/* Fill in public fields. We must increment the reference count on the
* driver ID to prevent it from being freed while this file is open.
*/
file->driver_id = driver_prop.driver_id;
if (H5I_inc_ref(file->driver_id, false) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINC, FAIL, "unable to increment ref count on VFL driver");
file->cls = driver;
file->maxaddr = maxaddr;
if (H5P_get(plist, H5F_ACS_ALIGN_THRHD_NAME, &file->threshold) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get alignment threshold");
if (H5P_get(plist, H5F_ACS_ALIGN_NAME, &file->alignment) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get alignment");

/* Retrieve the VFL driver feature flags */
if (H5FD__query(file, &file->feature_flags) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to query file driver");

/* Increment the global serial number & assign it to this H5FD_t object */
if (++H5FD_file_serial_no_g == 0) {
/* (Just error out if we wrap around for now...) */
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to get file serial number");
} /* end if */
file->fileno = H5FD_file_serial_no_g;

/* Start with base address set to 0 */
/* (This will be changed later, when the superblock is located) */
file->base_addr = 0;

/* Set 'out' parameter */
*_file = file;

done :
/* Fill in public fields. We must increment the reference count on the
* driver ID to prevent it from being freed while this file is open.
*/
file->driver_id = driver_prop.driver_id;
if (H5I_inc_ref(file->driver_id, false) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINC, FAIL, "unable to increment ref count on VFL driver");
file->cls = driver;
file->maxaddr = maxaddr;
if (H5P_get(plist, H5F_ACS_ALIGN_THRHD_NAME, &file->threshold) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get alignment threshold");
if (H5P_get(plist, H5F_ACS_ALIGN_NAME, &file->alignment) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get alignment");

/* Retrieve the VFL driver feature flags */
if (H5FD__query(file, &file->feature_flags) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to query file driver");

/* Increment the global serial number & assign it to this H5FD_t object */
if (++H5FD_file_serial_no_g == 0)
/* (Just error out if we wrap around for now...) */
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to get file serial number");
file->fileno = H5FD_file_serial_no_g;

/* Start with base address set to 0 */
/* (This will be changed later, when the superblock is located) */
file->base_addr = 0;

/* Set 'out' parameter */
*_file = file;

done:
/* Can't cleanup 'file' information, since we don't know what type it is */
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_open() */
Expand Down
8 changes: 5 additions & 3 deletions src/H5FDint.c
Original file line number Diff line number Diff line change
Expand Up @@ -2539,14 +2539,16 @@ H5FD_driver_query(const H5FD_class_t *driver, unsigned long *flags /*out*/)
assert(flags);

/* Check for the driver to query and then query it */
if (driver->query)
if (driver->query) {
/* Prepare & restore library for user callback */
H5_BEFORE_USER_CB_NOERR(FAIL)
{
ret_value = (driver->query)(NULL, flags);
}
H5_AFTER_USER_CB_NOERR(FAIL)
else *flags = 0;
H5_AFTER_USER_CB_NOERR(FAIL)
}
else
*flags = 0;

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_driver_query() */
Expand Down
6 changes: 6 additions & 0 deletions src/H5Tconv_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ typedef struct H5T_conv_hw_t {
{ \
if (*(S) > (ST)(D_MAX)) { \
H5T_conv_ret_t except_ret; \
\
/* Prepare & restore library for user callback */ \
H5_BEFORE_USER_CB(FAIL) \
{ \
Expand Down Expand Up @@ -328,6 +329,7 @@ typedef struct H5T_conv_hw_t {
{ \
if (*(S) < 0) { \
H5T_conv_ret_t except_ret; \
\
/* Prepare & restore library for user callback */ \
H5_BEFORE_USER_CB(FAIL) \
{ \
Expand Down Expand Up @@ -396,6 +398,7 @@ typedef struct H5T_conv_hw_t {
#define H5T_CONV_uS_CORE_1(S, D, ST, DT, D_MIN, D_MAX) \
if (*(S) > (DT)(D_MAX)) { \
H5T_conv_ret_t except_ret; \
\
/* Prepare & restore library for user callback */ \
H5_BEFORE_USER_CB(FAIL) \
{ \
Expand Down Expand Up @@ -532,6 +535,7 @@ typedef struct H5T_conv_hw_t {
/* Assumes memory format of unsigned & signed integers is same */ \
if (*(S) < 0) { \
H5T_conv_ret_t except_ret; \
\
/* Prepare & restore library for user callback */ \
H5_BEFORE_USER_CB(FAIL) \
{ \
Expand Down Expand Up @@ -570,6 +574,7 @@ typedef struct H5T_conv_hw_t {
/* Assumes memory format of unsigned & signed integers is same */ \
if (*(S) > (ST)(D_MAX)) { \
H5T_conv_ret_t except_ret; \
\
/* Prepare & restore library for user callback */ \
H5_BEFORE_USER_CB(FAIL) \
{ \
Expand Down Expand Up @@ -737,6 +742,7 @@ typedef struct H5T_conv_hw_t {
/* Check for more bits of precision in src than available in dst */ \
if ((high_bit_pos - low_bit_pos) >= dprec) { \
H5T_conv_ret_t except_ret; \
\
/* Prepare & restore library for user callback */ \
H5_BEFORE_USER_CB(FAIL) \
{ \
Expand Down
8 changes: 5 additions & 3 deletions src/H5VLcallback.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,14 +780,16 @@ H5VLget_object(void *obj, hid_t connector_id)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a VOL connector ID");

/* Check for 'get_object' callback in connector */
if (connector->cls->wrap_cls.get_object)
if (connector->cls->wrap_cls.get_object) {
/* Prepare & restore library for user callback */
H5_BEFORE_USER_CB(NULL)
{
ret_value = (connector->cls->wrap_cls.get_object)(obj);
}
H5_AFTER_USER_CB(NULL)
else ret_value = obj;
H5_AFTER_USER_CB(NULL)
}
else
ret_value = obj;

done:
FUNC_LEAVE_API_NOINIT(ret_value)
Expand Down
17 changes: 10 additions & 7 deletions src/H5VLint.c
Original file line number Diff line number Diff line change
Expand Up @@ -1805,14 +1805,16 @@ H5VL_object_data(const H5VL_object_t *vol_obj)
FUNC_ENTER_NOAPI_NOINIT_NOERR

/* Check for 'get_object' callback in connector */
if (vol_obj->connector->cls->wrap_cls.get_object)
if (vol_obj->connector->cls->wrap_cls.get_object) {
/* Prepare & restore library for user callback */
H5_BEFORE_USER_CB_NOERR(NULL)
{
ret_value = (vol_obj->connector->cls->wrap_cls.get_object)(vol_obj->data);
}
H5_AFTER_USER_CB_NOERR(NULL)
else ret_value = vol_obj->data;
H5_AFTER_USER_CB_NOERR(NULL)
}
else
ret_value = vol_obj->data;

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_object_data() */
Expand Down Expand Up @@ -2243,16 +2245,17 @@ H5VL__free_vol_wrapper(H5VL_wrap_ctx_t *vol_wrap_ctx)
assert(vol_wrap_ctx->connector->cls);

/* If there is a VOL connector object wrapping context, release it */
if (vol_wrap_ctx->obj_wrap_ctx)
if (vol_wrap_ctx->obj_wrap_ctx) {
/* Prepare & restore library for user callback */
H5_BEFORE_USER_CB(FAIL)
{
/* Release the VOL connector's object wrapping context */
ret_value = (*vol_wrap_ctx->connector->cls->wrap_cls.free_wrap_ctx)(vol_wrap_ctx->obj_wrap_ctx);
}
H5_AFTER_USER_CB(FAIL)
if (ret_value < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release connector's object wrapping context");
H5_AFTER_USER_CB(FAIL)
if (ret_value < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release connector's object wrapping context");
}

/* Decrement refcount on connector */
if (H5VL_conn_dec_rc(vol_wrap_ctx->connector) < 0)
Expand Down
Loading

0 comments on commit 18fe722

Please sign in to comment.