* Added H5DO compatibility functions.

* Changed the offset copy to use an array on the stack.
* Yanked some unused #defines.
This commit is contained in:
Dana Robinson 2018-05-04 09:01:54 -07:00
parent ac035bf367
commit 1fa0c5a4b5
8 changed files with 2292 additions and 77 deletions

View File

@ -11,17 +11,63 @@
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
/* High-level library internal header file */
#include "H5HLprivate2.h"
/* public LT prototypes */
#include "H5DOpublic.h"
/*-------------------------------------------------------------------------
* Function: H5DOwrite_chunk
*
* Purpose: Writes an entire chunk to the file directly.
*
* The H5DOwrite_chunk() call was moved to H5Dwrite_chunk. This
* simple wrapper remains so that people can still link to the
* high-level library without changing their code.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5DOwrite_chunk(hid_t dset_id, hid_t dxpl_id, uint32_t filters, const hsize_t *offset,
size_t data_size, const void *buf)
{
/* Call underlying H5D function */
if (H5Dwrite_chunk(dset_id, dxpl_id, filters, offset, data_size, buf) < 0)
return FAIL;
else
return SUCCEED;
} /* end H5DOwrite_chunk() */
/*-------------------------------------------------------------------------
* Function: H5DOread_chunk
*
* Purpose: Reads an entire chunk from the file directly.
*
* The H5DOread_chunk() call was moved to H5Dread_chunk. This
* simple wrapper remains so that people can still link to the
* high-level library without changing their code.
*
* Return: Non-negative on success/Negative on failure
*
*---------------------------------------------------------------------------
*/
herr_t
H5DOread_chunk(hid_t dset_id, hid_t dxpl_id, const hsize_t *offset, uint32_t *filters,
void *buf)
{
/* Call underlying H5D function */
if (H5Dread_chunk(dset_id, dxpl_id, offset, filters, buf) < 0)
return FAIL;
else
return SUCCEED;
} /* end H5DOread_chunk() */
/*-------------------------------------------------------------------------
* Function: H5DOappend()
@ -113,7 +159,8 @@ H5DOappend(hid_t dset_id, hid_t dxpl_id, unsigned axis, size_t extension,
goto done;
/* Adjust the dimension size of the requested dimension,
but first record the old dimension size */
* but first record the old dimension size
*/
old_size = size[axis];
size[axis] += extension;
if(size[axis] < old_size)
@ -125,7 +172,7 @@ H5DOappend(hid_t dset_id, hid_t dxpl_id, unsigned axis, size_t extension,
/* Get the new dataspace of the dataset */
if(FAIL == (new_space_id = H5Dget_space(dset_id)))
goto done;
goto done;
/* Select a hyperslab corresponding to the append operation */
for(u = 0 ; u < ndims ; u++) {
@ -181,7 +228,7 @@ H5DOappend(hid_t dset_id, hid_t dxpl_id, unsigned axis, size_t extension,
goto done;
/* Do a dataset flush */
if(H5Dflush(dset_id) < 0)
if(H5Dflush(dset_id) < 0)
goto done;
} /* end if */
} /* end if */

View File

@ -28,6 +28,12 @@ extern "C" {
H5_HLDLL herr_t H5DOappend(hid_t dset_id, hid_t dxpl_id, unsigned axis,
size_t extension, hid_t memtype, const void *buf);
/* Compatibility wrappers for functionality moved to H5D */
H5_HLDLL herr_t H5DOwrite_chunk(hid_t dset_id, hid_t dxpl_id, uint32_t filters,
const hsize_t *offset, size_t data_size, const void *buf);
H5_HLDLL herr_t H5DOread_chunk(hid_t dset_id, hid_t dxpl_id, const hsize_t *offset,
uint32_t *filters /*out*/, void *buf /*out*/);
#ifdef __cplusplus
}
#endif

View File

@ -48,6 +48,7 @@ HL_ADD_EXE (test_table)
HL_ADD_EXE (test_ds)
HL_ADD_EXE (test_ld)
HL_ADD_EXE (test_dset_append)
HL_ADD_EXE (test_h5do_compat)
# test_packet has two source files
add_executable (hl_test_packet test_packet.c test_packet_vlen.c)

View File

@ -79,6 +79,7 @@ add_test (
file_img1.h5
file_img2.h5
test_append.h5
h5do_compat.h5
test_detach.h5
test_ds1.h5
test_ds2.h5
@ -116,4 +117,5 @@ HL_add_test (test_ds)
HL_add_test (test_packet)
HL_add_test (test_ld)
HL_add_test (test_dset_append)
HL_add_test (test_h5do_compat)

View File

@ -27,7 +27,7 @@ LDADD=$(LIBH5_HL) $(LIBH5TEST) $(LIBHDF5)
# Test programs. These are our main targets. They should be listed in the
# order to be executed, generally most specific tests to least specific tests.
TEST_PROG=test_lite test_image test_file_image test_table test_ds test_packet \
test_ld test_dset_append
test_ld test_dset_append test_h5do_compat
check_PROGRAMS=$(TEST_PROG)
# These programs generate test files for the tests. They don't need to be
@ -45,7 +45,8 @@ endif
CHECK_CLEANFILES+=combine_tables[1-2].h5 test_ds[1-9].h5 test_ds10.h5 \
test_image[1-3].h5 file_img[1-2].h5 test_lite[1-4].h5 test_table.h5 \
test_packet_table.h5 test_packet_compress.h5 test_detach.h5 \
test_packet_table_vlen.h5 testfl_packet_table_vlen.h5 test_append.h5
test_packet_table_vlen.h5 testfl_packet_table_vlen.h5 test_append.h5 \
h5do_compat.h5
# Sources for test_packet executable
test_packet_SOURCES=test_packet.c test_packet_vlen.c

2174
hl/test/test_h5do_compat.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -51,7 +51,7 @@
/********************/
static herr_t H5D__get_offset_copy(const H5D_t *dset, const hsize_t *offset,
hsize_t **offset_copy/*out*/);
hsize_t *offset_copy/*out*/);
static herr_t H5D__ioinfo_init(H5D_t *dset, const H5D_type_info_t *type_info,
H5D_storage_t *store, H5D_io_info_t *io_info);
static herr_t H5D__typeinfo_init(const H5D_t *dset, hid_t mem_type_id,
@ -86,14 +86,12 @@ H5FL_DEFINE(H5D_chunk_map_t);
* Purpose: Gets a copy of the user's offset array that is guaraneteed
* to be suitable for use by the library.
*
* The caller must free the constructed offset array.
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
H5D__get_offset_copy(const H5D_t *dset, const hsize_t *offset, hsize_t **offset_copy)
H5D__get_offset_copy(const H5D_t *dset, const hsize_t *offset, hsize_t *offset_copy)
{
unsigned u;
herr_t ret_value = SUCCEED; /* Return value */
@ -104,13 +102,14 @@ H5D__get_offset_copy(const H5D_t *dset, const hsize_t *offset, hsize_t **offset_
HDassert(offset);
HDassert(offset_copy);
if (NULL == (*offset_copy = (hsize_t *)H5MM_calloc(H5O_LAYOUT_NDIMS * sizeof(hsize_t))))
HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "unable to allocate offset_copy array")
/* The library's chunking code requires the offset to terminate with a zero.
* So transfer the offset array to an internal offset array that we
* can properly terminate (handled via the calloc call).
*/
HDmemset(offset_copy, 0, H5O_LAYOUT_NDIMS * sizeof(hsize_t));
for (u = 0; u < dset->shared->ndims; u++) {
/* Make sure the offset doesn't exceed the dataset's dimensions */
if (offset[u] > dset->shared->curr_dims[u])
@ -120,7 +119,7 @@ H5D__get_offset_copy(const H5D_t *dset, const hsize_t *offset, hsize_t **offset_
if (offset[u] % dset->shared->layout.u.chunk.dim[u])
HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "offset doesn't fall on chunks's boundary")
(*offset_copy)[u] = offset[u];
offset_copy[u] = offset[u];
}
done:
@ -133,30 +132,30 @@ done:
/*-------------------------------------------------------------------------
* Function: H5Dread
*
* Purpose: Reads (part of) a DSET from the file into application
* memory BUF. The part of the dataset to read is defined with
* MEM_SPACE_ID and FILE_SPACE_ID. The data points are
* converted from their file type to the MEM_TYPE_ID specified.
* Additional miscellaneous data transfer properties can be
* passed to this function with the PLIST_ID argument.
* Purpose: Reads (part of) a DSET from the file into application
* memory BUF. The part of the dataset to read is defined with
* MEM_SPACE_ID and FILE_SPACE_ID. The data points are
* converted from their file type to the MEM_TYPE_ID specified.
* Additional miscellaneous data transfer properties can be
* passed to this function with the PLIST_ID argument.
*
* The FILE_SPACE_ID can be the constant H5S_ALL which indicates
* that the entire file dataspace is to be referenced.
* The FILE_SPACE_ID can be the constant H5S_ALL which indicates
* that the entire file dataspace is to be referenced.
*
* The MEM_SPACE_ID can be the constant H5S_ALL in which case
* the memory dataspace is the same as the file dataspace
* defined when the dataset was created.
* The MEM_SPACE_ID can be the constant H5S_ALL in which case
* the memory dataspace is the same as the file dataspace
* defined when the dataset was created.
*
* The number of elements in the memory dataspace must match
* the number of elements in the file dataspace.
* The number of elements in the memory dataspace must match
* the number of elements in the file dataspace.
*
* The PLIST_ID can be the constant H5P_DEFAULT in which
* case the default data transfer properties are used.
* The PLIST_ID can be the constant H5P_DEFAULT in which
* case the default data transfer properties are used.
*
* Return: Non-negative on success/Negative on failure
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Thursday, December 4, 1997
* Programmer: Robb Matzke
* Thursday, December 4, 1997
*
*-------------------------------------------------------------------------
*/
@ -221,8 +220,8 @@ H5Dread_chunk(hid_t dset_id, hid_t dxpl_id, const hsize_t *offset, uint32_t *fil
void *buf)
{
H5D_t *dset = NULL;
hsize_t *offset_copy = NULL; /* Internal copy of chunk offset */
herr_t ret_value = SUCCEED; /* Return value */
hsize_t offset_copy[H5O_LAYOUT_NDIMS]; /* Internal copy of chunk offset */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE5("e", "ii*h*Iu*x", dset_id, dxpl_id, offset, filters, buf);
@ -254,7 +253,7 @@ H5Dread_chunk(hid_t dset_id, hid_t dxpl_id, const hsize_t *offset, uint32_t *fil
/* Copy the user's offset array so we can be sure it's terminated properly.
* (we don't want to mess with the user's buffer).
*/
if (H5D__get_offset_copy(dset, offset, &offset_copy) < 0)
if (H5D__get_offset_copy(dset, offset, offset_copy) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "failure to copy offset array")
/* Read the raw chunk */
@ -262,40 +261,38 @@ H5Dread_chunk(hid_t dset_id, hid_t dxpl_id, const hsize_t *offset, uint32_t *fil
HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read unprocessed chunk data")
done:
offset_copy = (hsize_t *)H5MM_xfree(offset_copy);
FUNC_LEAVE_API(ret_value)
} /* end H5Dread_chunk() */
/*-------------------------------------------------------------------------
* Function: H5Dwrite
* Function: H5Dwrite
*
* Purpose: Writes (part of) a DSET from application memory BUF to the
* file. The part of the dataset to write is defined with the
* MEM_SPACE_ID and FILE_SPACE_ID arguments. The data points
* are converted from their current type (MEM_TYPE_ID) to their
* file datatype. Additional miscellaneous data transfer
* properties can be passed to this function with the
* PLIST_ID argument.
* Purpose: Writes (part of) a DSET from application memory BUF to the
* file. The part of the dataset to write is defined with the
* MEM_SPACE_ID and FILE_SPACE_ID arguments. The data points
* are converted from their current type (MEM_TYPE_ID) to their
* file datatype. Additional miscellaneous data transfer
* properties can be passed to this function with the
* PLIST_ID argument.
*
* The FILE_SPACE_ID can be the constant H5S_ALL which indicates
* that the entire file dataspace is to be referenced.
* The FILE_SPACE_ID can be the constant H5S_ALL which indicates
* that the entire file dataspace is to be referenced.
*
* The MEM_SPACE_ID can be the constant H5S_ALL in which case
* the memory dataspace is the same as the file dataspace
* defined when the dataset was created.
* The MEM_SPACE_ID can be the constant H5S_ALL in which case
* the memory dataspace is the same as the file dataspace
* defined when the dataset was created.
*
* The number of elements in the memory dataspace must match
* the number of elements in the file dataspace.
* The number of elements in the memory dataspace must match
* the number of elements in the file dataspace.
*
* The PLIST_ID can be the constant H5P_DEFAULT in which
* case the default data transfer properties are used.
* The PLIST_ID can be the constant H5P_DEFAULT in which
* case the default data transfer properties are used.
*
* Return: Non-negative on success/Negative on failure
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Thursday, December 4, 1997
* Programmer: Robb Matzke
* Thursday, December 4, 1997
*
*-------------------------------------------------------------------------
*/
@ -360,9 +357,9 @@ H5Dwrite_chunk(hid_t dset_id, hid_t dxpl_id, uint32_t filters, const hsize_t *of
size_t data_size, const void *buf)
{
H5D_t *dset = NULL;
hsize_t *offset_copy = NULL; /* Internal copy of chunk offset */
uint32_t data_size_32; /* Chunk data size (limited to 32-bits currently) */
herr_t ret_value = SUCCEED; /* Return value */
hsize_t offset_copy[H5O_LAYOUT_NDIMS]; /* Internal copy of chunk offset */
uint32_t data_size_32; /* Chunk data size (limited to 32-bits currently) */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE6("e", "iiIu*hz*x", dset_id, dxpl_id, filters, offset, data_size, buf);
@ -399,7 +396,7 @@ H5Dwrite_chunk(hid_t dset_id, hid_t dxpl_id, uint32_t filters, const hsize_t *of
/* Copy the user's offset array so we can be sure it's terminated properly.
* (we don't want to mess with the user's buffer).
*/
if (H5D__get_offset_copy(dset, offset, &offset_copy) < 0)
if (H5D__get_offset_copy(dset, offset, offset_copy) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "failure to copy offset array")
/* Write chunk */
@ -407,8 +404,6 @@ H5Dwrite_chunk(hid_t dset_id, hid_t dxpl_id, uint32_t filters, const hsize_t *of
HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write unprocessed chunk data")
done:
offset_copy = (hsize_t *)H5MM_xfree(offset_copy);
FUNC_LEAVE_API(ret_value)
} /* end H5Dwrite_chunk() */

View File

@ -35,17 +35,6 @@
/* Bit flags for the H5Pset_chunk_opts() and H5Pget_chunk_opts() */
#define H5D_CHUNK_DONT_FILTER_PARTIAL_CHUNKS (0x0002u)
/* Property names for H5DOwrite_chunk */
#define H5D_XFER_DIRECT_CHUNK_WRITE_FLAG_NAME "direct_chunk_flag"
#define H5D_XFER_DIRECT_CHUNK_WRITE_FILTERS_NAME "direct_chunk_filters"
#define H5D_XFER_DIRECT_CHUNK_WRITE_OFFSET_NAME "direct_chunk_offset"
#define H5D_XFER_DIRECT_CHUNK_WRITE_DATASIZE_NAME "direct_chunk_datasize"
/* Property names for H5DOread_chunk */
#define H5D_XFER_DIRECT_CHUNK_READ_FLAG_NAME "direct_chunk_read_flag"
#define H5D_XFER_DIRECT_CHUNK_READ_OFFSET_NAME "direct_chunk_read_offset"
#define H5D_XFER_DIRECT_CHUNK_READ_FILTERS_NAME "direct_chunk_read_filters"
/*******************/
/* Public Typedefs */
/*******************/