Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to reduce code duplication #4531

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/H5D.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,8 @@ H5D__read_api_common(size_t count, hid_t dset_id[], hid_t mem_type_id[], hid_t m
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms");

/* Read the data */
if (H5VL_dataset_read_direct(count, obj, connector, mem_type_id, mem_space_id, file_space_id, dxpl_id,
buf, token_ptr) < 0)
if (H5VL_dataset_read(count, obj, connector, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf,
token_ptr) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read data");

done:
Expand Down Expand Up @@ -1289,8 +1289,8 @@ H5D__write_api_common(size_t count, hid_t dset_id[], hid_t mem_type_id[], hid_t
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms");

/* Write the data */
if (H5VL_dataset_write_direct(count, obj, connector, mem_type_id, mem_space_id, file_space_id, dxpl_id,
buf, token_ptr) < 0)
if (H5VL_dataset_write(count, obj, connector, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf,
token_ptr) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data");

done:
Expand Down
10 changes: 5 additions & 5 deletions src/H5Dint.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ typedef struct {
/* Internal data structure for computing variable-length dataset's total size */
/* (Used for generic 'get vlen buf size' operation) */
typedef struct {
const H5VL_object_t *dset_vol_obj; /* VOL object for the dataset */
H5VL_object_t *dset_vol_obj; /* VOL object for the dataset */
hid_t fspace_id; /* Dataset dataspace ID of the dataset we are working on */
H5S_t *fspace; /* Dataset's dataspace for operation */
hid_t mspace_id; /* Memory dataspace ID of the dataset we are working on */
Expand Down Expand Up @@ -2816,9 +2816,9 @@ H5D__vlen_get_buf_size_gen_cb(void H5_ATTR_UNUSED *elem, hid_t type_id, unsigned
HGOTO_ERROR(H5E_DATASET, H5E_CANTCREATE, FAIL, "can't select point");

/* Read in the point (with the custom VL memory allocator) */
if (H5VL_dataset_read(1, &vlen_bufsize->dset_vol_obj, &type_id, &vlen_bufsize->mspace_id,
&vlen_bufsize->fspace_id, vlen_bufsize->dxpl_id, &vlen_bufsize->common.fl_tbuf,
H5_REQUEST_NULL) < 0)
if (H5VL_dataset_read(1, &vlen_bufsize->dset_vol_obj->data, vlen_bufsize->dset_vol_obj->connector,
&type_id, &vlen_bufsize->mspace_id, &vlen_bufsize->fspace_id, vlen_bufsize->dxpl_id,
&vlen_bufsize->common.fl_tbuf, H5_REQUEST_NULL) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read point");

done:
Expand Down Expand Up @@ -2860,7 +2860,7 @@ H5D__vlen_get_buf_size_gen(H5VL_object_t *vol_obj, hid_t type_id, hid_t space_id
HGOTO_ERROR(H5E_DATASET, H5E_BADVALUE, FAIL, "dataspace does not have extent set");

/* Save the dataset */
vlen_bufsize.dset_vol_obj = (const H5VL_object_t *)vol_obj;
vlen_bufsize.dset_vol_obj = vol_obj;

/* Set up VOL callback arguments */
vol_cb_args.op_type = H5VL_DATASET_GET_SPACE;
Expand Down
141 changes: 6 additions & 135 deletions src/H5VLcallback.c
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,7 @@ H5VL__dataset_read(size_t count, void *obj[], const H5VL_class_t *cls, hid_t mem
} /* end H5VL__dataset_read() */

/*-------------------------------------------------------------------------
* Function: H5VL_dataset_read_direct
* Function: H5VL_dataset_read
*
* Purpose: Reads data from dataset through the VOL. This is like
* H5VL_dataset_read, but takes an array of void * for the
Expand All @@ -2039,8 +2039,8 @@ H5VL__dataset_read(size_t count, void *obj[], const H5VL_class_t *cls, hid_t mem
*-------------------------------------------------------------------------
*/
herr_t
H5VL_dataset_read_direct(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[],
hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id, void *buf[], void **req)
H5VL_dataset_read(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[], hid_t mem_space_id[],
hid_t file_space_id[], hid_t dxpl_id, void *buf[], void **req)
{
bool vol_wrapper_set = false; /* Whether the VOL object wrapping context was set up */
H5VL_object_t tmp_vol_obj; /* Temporary VOL object for setting VOL wrapper */
Expand Down Expand Up @@ -2069,70 +2069,6 @@ H5VL_dataset_read_direct(size_t count, void *obj[], H5VL_t *connector, hid_t mem
if (vol_wrapper_set && H5VL_reset_vol_wrapper() < 0)
HDONE_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset VOL wrapper info");

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_dataset_read_direct() */

/*-------------------------------------------------------------------------
* Function: H5VL_dataset_read
*
* Purpose: Reads data from dataset through the VOL
*
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL_dataset_read(size_t count, const H5VL_object_t *vol_obj[], hid_t mem_type_id[], hid_t mem_space_id[],
hid_t file_space_id[], hid_t dxpl_id, void *buf[], void **req)
{
bool vol_wrapper_set = false; /* Whether the VOL object wrapping context was set up */
void *obj_local; /* Local buffer for obj */
void **obj = &obj_local; /* Array of object pointers */
size_t i; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_NOAPI(FAIL)

assert(vol_obj);
assert(vol_obj[0]);

/* Set wrapper info in API context */
if (H5VL_set_vol_wrapper(vol_obj[0]) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set VOL wrapper info");
vol_wrapper_set = true;

/* Allocate obj array if necessary */
if (count > 1)
if (NULL == (obj = (void **)H5MM_malloc(count * sizeof(void *))))
HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, FAIL, "can't allocate space for object array");

/* Build obj array */
for (i = 0; i < count; i++) {
/* Get the object */
obj[i] = vol_obj[i]->data;

/* Make sure the class matches */
if (vol_obj[i]->connector->cls->value != vol_obj[0]->connector->cls->value)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL,
"datasets are accessed through different VOL connectors and can't be used in the "
"same I/O call");
}

/* Call the corresponding internal VOL routine */
if (H5VL__dataset_read(count, obj, vol_obj[0]->connector->cls, mem_type_id, mem_space_id, file_space_id,
dxpl_id, buf, req) < 0)
HGOTO_ERROR(H5E_VOL, H5E_READERROR, FAIL, "dataset read failed");

done:
/* Reset object wrapping info in API context */
if (vol_wrapper_set && H5VL_reset_vol_wrapper() < 0)
HDONE_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset VOL wrapper info");

/* Free memory */
if (obj != &obj_local)
H5MM_free(obj);

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_dataset_read() */

Expand Down Expand Up @@ -2212,7 +2148,7 @@ H5VL__dataset_write(size_t count, void *obj[], const H5VL_class_t *cls, hid_t me
} /* end H5VL__dataset_write() */

/*-------------------------------------------------------------------------
* Function: H5VL_dataset_write_direct
* Function: H5VL_dataset_write
*
* Purpose: Writes data from dataset through the VOL. This is like
* H5VL_dataset_write, but takes an array of void * for the
Expand All @@ -2226,9 +2162,8 @@ H5VL__dataset_write(size_t count, void *obj[], const H5VL_class_t *cls, hid_t me
*-------------------------------------------------------------------------
*/
herr_t
H5VL_dataset_write_direct(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[],
hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id, const void *buf[],
void **req)
H5VL_dataset_write(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[], hid_t mem_space_id[],
hid_t file_space_id[], hid_t dxpl_id, const void *buf[], void **req)
{
bool vol_wrapper_set = false; /* Whether the VOL object wrapping context was set up */
H5VL_object_t tmp_vol_obj; /* Temporary VOL object for setting VOL wrapper */
Expand Down Expand Up @@ -2257,70 +2192,6 @@ H5VL_dataset_write_direct(size_t count, void *obj[], H5VL_t *connector, hid_t me
if (vol_wrapper_set && H5VL_reset_vol_wrapper() < 0)
HDONE_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset VOL wrapper info");

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_dataset_write_direct() */

/*-------------------------------------------------------------------------
* Function: H5VL_dataset_write
*
* Purpose: Writes data from dataset through the VOL
*
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL_dataset_write(size_t count, const H5VL_object_t *vol_obj[], hid_t mem_type_id[], hid_t mem_space_id[],
hid_t file_space_id[], hid_t dxpl_id, const void *buf[], void **req)
{
bool vol_wrapper_set = false; /* Whether the VOL object wrapping context was set up */
void *obj_local; /* Local buffer for obj */
void **obj = &obj_local; /* Array of object pointers */
size_t i; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_NOAPI(FAIL)

assert(vol_obj);
assert(vol_obj[0]);

/* Set wrapper info in API context */
if (H5VL_set_vol_wrapper(vol_obj[0]) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set VOL wrapper info");
vol_wrapper_set = true;

/* Allocate obj array if necessary */
if (count > 1)
if (NULL == (obj = (void **)H5MM_malloc(count * sizeof(void *))))
HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, FAIL, "can't allocate space for object array");

/* Build obj array */
for (i = 0; i < count; i++) {
/* Get the object */
obj[i] = vol_obj[i]->data;

/* Make sure the class matches */
if (vol_obj[i]->connector->cls->value != vol_obj[0]->connector->cls->value)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL,
"datasets are accessed through different VOL connectors and can't be used in the "
"same I/O call");
}

/* Call the corresponding internal VOL routine */
if (H5VL__dataset_write(count, obj, vol_obj[0]->connector->cls, mem_type_id, mem_space_id, file_space_id,
dxpl_id, buf, req) < 0)
HGOTO_ERROR(H5E_VOL, H5E_WRITEERROR, FAIL, "dataset write failed");

done:
/* Reset object wrapping info in API context */
if (vol_wrapper_set && H5VL_reset_vol_wrapper() < 0)
HDONE_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset VOL wrapper info");

/* Free memory */
if (obj != &obj_local)
H5MM_free(obj);

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_dataset_write() */

Expand Down
10 changes: 2 additions & 8 deletions src/H5VLprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,12 @@ H5_DLL void *H5VL_dataset_create(const H5VL_object_t *vol_obj, const H5VL_loc_p
hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req);
H5_DLL void *H5VL_dataset_open(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params,
const char *name, hid_t dapl_id, hid_t dxpl_id, void **req);
H5_DLL herr_t H5VL_dataset_read(size_t count, const H5VL_object_t *vol_obj[], hid_t mem_type_id[],
H5_DLL herr_t H5VL_dataset_read(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[],
hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id, void *buf[],
void **req);
H5_DLL herr_t H5VL_dataset_read_direct(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[],
hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id,
void *buf[], void **req);
H5_DLL herr_t H5VL_dataset_write(size_t count, const H5VL_object_t *vol_obj[], hid_t mem_type_id[],
H5_DLL herr_t H5VL_dataset_write(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[],
hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id,
const void *buf[], void **req);
H5_DLL herr_t H5VL_dataset_write_direct(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[],
hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id,
const void *buf[], void **req);
H5_DLL herr_t H5VL_dataset_get(const H5VL_object_t *vol_obj, H5VL_dataset_get_args_t *args, hid_t dxpl_id,
void **req);
H5_DLL herr_t H5VL_dataset_specific(const H5VL_object_t *cls, H5VL_dataset_specific_args_t *args,
Expand Down
2 changes: 1 addition & 1 deletion test/testfiles/error_test_1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ HDF5-DIAG: Error detected in HDF5 (version (number)):
#001: (file name) line (number) in H5D__read_api_common(): can't read data
major: Dataset
minor: Read failed
#002: (file name) line (number) in H5VL_dataset_read_direct(): dataset read failed
#002: (file name) line (number) in H5VL_dataset_read(): dataset read failed
major: Virtual Object Layer
minor: Read failed
#003: (file name) line (number) in H5VL__dataset_read(): dataset read failed
Expand Down
Loading