Skip to content

Commit

Permalink
Fix H5Otoken_to_str call in h5dump and other minor cleanup (HDFGroup#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendersonHDF authored and lrknox committed Aug 4, 2023
1 parent 54d6708 commit f61a7ea
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 36 deletions.
16 changes: 10 additions & 6 deletions src/H5Dint.c
Original file line number Diff line number Diff line change
Expand Up @@ -3540,11 +3540,11 @@ H5D_flush_all(H5F_t *f)
hid_t
H5D_get_create_plist(const H5D_t *dset)
{
H5P_genplist_t *dcpl_plist; /* Dataset's DCPL */
H5P_genplist_t *new_plist; /* Copy of dataset's DCPL */
H5O_layout_t copied_layout; /* Layout to tweak */
H5O_fill_t copied_fill; /* Fill value to tweak */
H5O_efl_t copied_efl; /* External file list to tweak */
H5P_genplist_t *dcpl_plist; /* Dataset's DCPL */
H5P_genplist_t *new_plist; /* Copy of dataset's DCPL */
H5O_layout_t copied_layout; /* Layout to tweak */
H5O_fill_t copied_fill = {0}; /* Fill value to tweak */
H5O_efl_t copied_efl; /* External file list to tweak */
hid_t new_dcpl_id = FAIL;
hid_t ret_value = H5I_INVALID_HID; /* Return value */

Expand Down Expand Up @@ -3697,11 +3697,15 @@ H5D_get_create_plist(const H5D_t *dset)
ret_value = new_dcpl_id;

done:
if (ret_value < 0)
if (ret_value < 0) {
if (new_dcpl_id > 0)
if (H5I_dec_app_ref(new_dcpl_id) < 0)
HDONE_ERROR(H5E_DATASET, H5E_CANTDEC, FAIL, "unable to close temporary object");

if (copied_fill.type && (H5T_close_real(copied_fill.type) < 0))
HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't free temporary datatype");
}

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

Expand Down
73 changes: 50 additions & 23 deletions tools/lib/h5tools_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -3067,11 +3067,15 @@ h5tools_print_fill_value(h5tools_str_t *buffer /*in,out*/, const h5tool_format_t
h5tools_context_t *ctx /*in,out*/, hid_t dcpl, hid_t type_id, hid_t obj_id)
{
size_t size;
hid_t n_type = H5I_INVALID_HID;
void *buf = NULL;
hid_t n_type = H5I_INVALID_HID;
void *buf = NULL;
bool vl_data = false;

n_type = H5Tget_native_type(type_id, H5T_DIR_DEFAULT);

if (h5tools_detect_vlen(type_id) == TRUE)
vl_data = true;

size = H5Tget_size(n_type);
buf = malloc(size);

Expand All @@ -3081,6 +3085,17 @@ h5tools_print_fill_value(h5tools_str_t *buffer /*in,out*/, const h5tool_format_t

H5Tclose(n_type);

if (vl_data) {
hsize_t dims[1] = {1};
hid_t space_id = H5I_INVALID_HID;

space_id = H5Screate_simple(1, dims, NULL);

H5Treclaim(type_id, space_id, H5P_DEFAULT, buf);

H5Sclose(space_id);
}

if (buf)
free(buf);
}
Expand All @@ -3097,26 +3112,26 @@ void
h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t dcpl_id,
hid_t type_id, hid_t dset_id)
{
int nfilters; /* number of filters */
int rank; /* rank */
int nfilters = -1; /* number of filters */
int rank; /* rank */
int i;
unsigned j;
unsigned filt_flags; /* filter flags */
unsigned cd_values[20]; /* filter client data values */
unsigned szip_options_mask;
unsigned szip_pixels_per_block;
H5Z_filter_t filtn; /* filter identification number */
H5D_fill_value_t fvstatus;
H5D_alloc_time_t at;
H5D_fill_time_t ft;
H5D_layout_t stl;
size_t ncols = 80; /* available output width */
size_t cd_nelmts; /* filter client number of values */
off_t offset; /* offset of external file */
char f_name[256]; /* filter name */
char name[256]; /* external or virtual file name */
hsize_t chsize[64]; /* chunk size in elements */
hsize_t size; /* size of external file */
H5D_fill_value_t fvstatus = H5D_FILL_VALUE_ERROR;
H5D_alloc_time_t at = H5D_ALLOC_TIME_ERROR;
H5D_fill_time_t ft = H5D_FILL_TIME_ERROR;
H5D_layout_t stl = H5D_LAYOUT_ERROR;
size_t ncols = 80; /* available output width */
size_t cd_nelmts; /* filter client number of values */
off_t offset; /* offset of external file */
char f_name[256]; /* filter name */
char name[256]; /* external or virtual file name */
hsize_t chsize[64]; /* chunk size in elements */
hsize_t size; /* size of external file */
hsize_t storage_size;
hsize_t curr_pos = 0; /* total data element position */
h5tools_str_t buffer; /* string into which to render */
Expand All @@ -3127,7 +3142,9 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_context_t *
ncols = info->line_ncols;

storage_size = H5Dget_storage_size(dset_id);
nfilters = H5Pget_nfilters(dcpl_id);
if (dcpl_id >= 0)
nfilters = H5Pget_nfilters(dcpl_id);

HDstrcpy(f_name, "\0");

/*-------------------------------------------------------------------------
Expand All @@ -3140,7 +3157,9 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_context_t *
h5tools_str_append(&buffer, "%s %s", STORAGE_LAYOUT, BEGIN);
h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

stl = H5Pget_layout(dcpl_id);
if (dcpl_id >= 0)
stl = H5Pget_layout(dcpl_id);

switch (stl) {
case H5D_CHUNKED:
ctx->indent_level++;
Expand Down Expand Up @@ -3639,7 +3658,9 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_context_t *
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "FILL_TIME ");

H5Pget_fill_time(dcpl_id, &ft);
if (dcpl_id >= 0)
H5Pget_fill_time(dcpl_id, &ft);

switch (ft) {
case H5D_FILL_TIME_ALLOC:
h5tools_str_append(&buffer, "%s", "H5D_FILL_TIME_ALLOC");
Expand All @@ -3652,7 +3673,7 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_context_t *
break;
case H5D_FILL_TIME_ERROR:
default:
assert(0);
h5tools_str_append(&buffer, "%s", "INVALID");
break;
}
h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
Expand All @@ -3661,7 +3682,10 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_context_t *

h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "%s ", "VALUE ");
H5Pfill_value_defined(dcpl_id, &fvstatus);

if (dcpl_id >= 0)
H5Pfill_value_defined(dcpl_id, &fvstatus);

switch (fvstatus) {
case H5D_FILL_VALUE_UNDEFINED:
h5tools_str_append(&buffer, "%s", "H5D_FILL_VALUE_UNDEFINED");
Expand All @@ -3676,7 +3700,7 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_context_t *
break;
case H5D_FILL_VALUE_ERROR:
default:
assert(0);
h5tools_str_append(&buffer, "%s", "INVALID");
break;
}
h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
Expand Down Expand Up @@ -3704,7 +3728,10 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_context_t *
ctx->need_prefix = TRUE;

h5tools_str_reset(&buffer);
H5Pget_alloc_time(dcpl_id, &at);

if (dcpl_id >= 0)
H5Pget_alloc_time(dcpl_id, &at);

switch (at) {
case H5D_ALLOC_TIME_EARLY:
h5tools_str_append(&buffer, "%s", "H5D_ALLOC_TIME_EARLY");
Expand All @@ -3718,7 +3745,7 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_context_t *
case H5D_ALLOC_TIME_ERROR:
case H5D_ALLOC_TIME_DEFAULT:
default:
assert(0);
h5tools_str_append(&buffer, "%s", "INVALID");
break;
}
h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
Expand Down
3 changes: 2 additions & 1 deletion tools/lib/h5tools_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -1228,11 +1228,12 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai
h5tools_str_append(str, "%u-", (unsigned)oi.type);
break;
}
H5Oclose(obj);

/* Print OID */
H5Otoken_to_str(obj, &oi.token, &obj_tok_str);

H5Oclose(obj);

if (info->obj_hidefileno)
h5tools_str_append(str, info->obj_format, obj_tok_str);
else
Expand Down
16 changes: 10 additions & 6 deletions tools/src/h5dump/h5dump_ddl.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset)
h5tool_format_t *outputformat = &h5tools_dataformat;
h5tool_format_t string_dataformat;
hid_t type, space;
unsigned attr_crt_order_flags;
unsigned attr_crt_order_flags = 0;
hid_t dcpl_id; /* dataset creation property list ID */
h5tools_str_t buffer; /* string into which to render */
hsize_t curr_pos = 0; /* total data element position */
Expand All @@ -947,14 +947,16 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset)
outputformat = &string_dataformat;

if ((dcpl_id = H5Dget_create_plist(did)) < 0) {
error_msg("error in getting creation property list ID\n");
error_msg("error in getting creation property list ID for dataset '%s'\n", name);
h5tools_setstatus(EXIT_FAILURE);
}

/* query the creation properties for attributes */
if (H5Pget_attr_creation_order(dcpl_id, &attr_crt_order_flags) < 0) {
error_msg("error in getting creation properties\n");
h5tools_setstatus(EXIT_FAILURE);
if (dcpl_id >= 0) {
if (H5Pget_attr_creation_order(dcpl_id, &attr_crt_order_flags) < 0) {
error_msg("error in getting creation properties for dataset '%s'\n", name);
h5tools_setstatus(EXIT_FAILURE);
}
}

/* setup */
Expand Down Expand Up @@ -993,7 +995,9 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset)
h5tools_dump_dcpl(rawoutstream, outputformat, &ctx, dcpl_id, type, did);
h5dump_type_table = NULL;
}
H5Pclose(dcpl_id);

if (dcpl_id >= 0)
H5Pclose(dcpl_id);

ctx.sset = sset;
ctx.display_index = dump_opts.display_ai;
Expand Down

0 comments on commit f61a7ea

Please sign in to comment.