diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2016-09-28 18:06:02 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2016-09-28 18:06:02 (GMT) |
commit | 208cfdc941bd911253051dc496c087dae6012241 (patch) | |
tree | a91d11ade122596d7e7eb44f8468efd2a50d7d38 /tools/lib | |
parent | 50d3fc7a61f4b1dbe2ead376b778f5743060cc6e (diff) | |
download | hdf5-208cfdc941bd911253051dc496c087dae6012241.zip hdf5-208cfdc941bd911253051dc496c087dae6012241.tar.gz hdf5-208cfdc941bd911253051dc496c087dae6012241.tar.bz2 |
Merge/align from trunk(develop)
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/h5diff_util.c | 131 | ||||
-rw-r--r-- | tools/lib/h5tools.c | 85 | ||||
-rw-r--r-- | tools/lib/h5tools.h | 39 | ||||
-rw-r--r-- | tools/lib/h5tools_dump.c | 149 | ||||
-rw-r--r-- | tools/lib/h5tools_error.h | 2 | ||||
-rw-r--r-- | tools/lib/h5tools_filters.c | 76 | ||||
-rw-r--r-- | tools/lib/h5tools_ref.c | 8 | ||||
-rw-r--r-- | tools/lib/h5tools_str.c | 333 | ||||
-rw-r--r-- | tools/lib/h5tools_str.h | 5 | ||||
-rw-r--r-- | tools/lib/h5tools_type.c | 193 | ||||
-rw-r--r-- | tools/lib/h5tools_utils.c | 22 | ||||
-rw-r--r-- | tools/lib/h5tools_utils.h | 6 |
12 files changed, 580 insertions, 469 deletions
diff --git a/tools/lib/h5diff_util.c b/tools/lib/h5diff_util.c index aefd641..ab3e1ce 100644 --- a/tools/lib/h5diff_util.c +++ b/tools/lib/h5diff_util.c @@ -78,8 +78,6 @@ void print_type(hid_t type) { switch (H5Tget_class(type)) { - default: - return; case H5T_INTEGER: if (H5Tequal(type, H5T_STD_I8BE)) { parallel_print("H5T_STD_I8BE"); @@ -160,7 +158,21 @@ void print_type(hid_t type) } break; - }/*switch*/ + case H5T_TIME: + case H5T_STRING: + case H5T_BITFIELD: + case H5T_OPAQUE: + case H5T_COMPOUND: + case H5T_REFERENCE: + case H5T_ENUM: + case H5T_VLEN: + case H5T_ARRAY: + case H5T_NO_CLASS: + case H5T_NCLASSES: + default: + return; + + } /* end switch */ } /*------------------------------------------------------------------------- @@ -179,16 +191,16 @@ diff_basename(const char *name) { size_t i; - if (name==NULL) + if (name == NULL) return NULL; /* Find the end of the base name */ i = HDstrlen(name); - while (i>0 && '/'==name[i-1]) + while (i > 0 && '/' == name[i - 1]) --i; /* Skip backward over base name */ - while (i>0 && '/'!=name[i-1]) + while (i > 0 && '/' != name[i - 1]) --i; return(name+i); @@ -211,14 +223,20 @@ get_type(h5trav_type_t type) switch(type) { case H5TRAV_TYPE_DATASET: return("H5G_DATASET"); + case H5TRAV_TYPE_GROUP: return("H5G_GROUP"); + case H5TRAV_TYPE_NAMED_DATATYPE: return("H5G_TYPE"); + case H5TRAV_TYPE_LINK: return("H5G_LINK"); + case H5TRAV_TYPE_UDLINK: return("H5G_UDLINK"); + + case H5TRAV_TYPE_UNKNOWN: default: return("unknown type"); } @@ -242,13 +260,22 @@ get_sign(H5T_sign_t sign) { switch (sign) { - default: - return("H5T_SGN_ERROR"); - case H5T_SGN_NONE: - return("H5T_SGN_NONE"); - case H5T_SGN_2: - return("H5T_SGN_2"); - } + case H5T_SGN_NONE: + return "H5T_SGN_NONE"; + + case H5T_SGN_2: + return "H5T_SGN_2"; + + case H5T_SGN_ERROR: + return "H5T_SGN_ERROR"; + + case H5T_NSGN: + return "H5T_NSGN"; + + default: + HDassert(0); + return "unknown sign value"; + } /* end switch */ } @@ -266,34 +293,47 @@ get_sign(H5T_sign_t sign) const char* get_class(H5T_class_t tclass) { - switch (tclass) - { - default: - return("Invalid class"); - case H5T_TIME: - return("H5T_TIME"); - case H5T_INTEGER: - return("H5T_INTEGER"); - case H5T_FLOAT: - return("H5T_FLOAT"); - case H5T_STRING: - return("H5T_STRING"); - case H5T_BITFIELD: - return("H5T_BITFIELD"); - case H5T_OPAQUE: - return("H5T_OPAQUE"); - case H5T_COMPOUND: - return("H5T_COMPOUND"); - case H5T_REFERENCE: - return("H5T_REFERENCE"); - case H5T_ENUM: - return("H5T_ENUM"); - case H5T_VLEN: - return("H5T_VLEN"); - case H5T_ARRAY: - return("H5T_ARRAY"); - } -} + switch (tclass) { + case H5T_TIME: + return("H5T_TIME"); + + case H5T_INTEGER: + return("H5T_INTEGER"); + + case H5T_FLOAT: + return("H5T_FLOAT"); + + case H5T_STRING: + return("H5T_STRING"); + + case H5T_BITFIELD: + return("H5T_BITFIELD"); + + case H5T_OPAQUE: + return("H5T_OPAQUE"); + + case H5T_COMPOUND: + return("H5T_COMPOUND"); + + case H5T_REFERENCE: + return("H5T_REFERENCE"); + + case H5T_ENUM: + return("H5T_ENUM"); + + case H5T_VLEN: + return("H5T_VLEN"); + + case H5T_ARRAY: + return("H5T_ARRAY"); + + case H5T_NO_CLASS: + case H5T_NCLASSES: + default: + HDassert(0); + return("Invalid class"); + } /* end switch */ +} /* end get_class() */ /*------------------------------------------------------------------------- * Function: print_found @@ -304,10 +344,10 @@ get_class(H5T_class_t tclass) */ void print_found(hsize_t nfound) { - if(g_Parallel) - parallel_print("%"H5_PRINTF_LL_WIDTH"u differences found\n", (unsigned long long)nfound); - else - HDfprintf(stdout,"%Hu differences found\n",nfound); + if(g_Parallel) + parallel_print("%"H5_PRINTF_LL_WIDTH"u differences found\n", (unsigned long long)nfound); + else + HDfprintf(stdout,"%Hu differences found\n",nfound); } @@ -354,3 +394,4 @@ herr_t match_up_memsize (hid_t f_tid1_id, hid_t f_tid2_id, out: return ret; } + diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index a21dea7..f2123fb 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -47,10 +47,11 @@ int region_output; /* region output */ int oid_output; /* oid output */ int data_output; /* data output */ int attr_data_output; /* attribute data output */ -int packed_bits_num; /* number of packed bits to display */ -int packed_data_offset; /* offset of packed bits to display */ -int packed_data_length; /* lengtht of packed bits to display */ +unsigned packed_bits_num; /* number of packed bits to display */ +unsigned packed_data_offset; /* offset of packed bits to display */ +unsigned packed_data_length; /* length of packed bits to display */ unsigned long long packed_data_mask; /* mask in which packed bits to display */ +int enable_error_stack= FALSE; /* re-enable error stack */ /* module-scoped variables */ static int h5tools_init_g; /* if h5tools lib has been initialized */ @@ -805,7 +806,7 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_str_t prefix; h5tools_str_t str; /*temporary for indentation */ size_t templength = 0; - int i, indentlevel = 0; + unsigned u, indentlevel = 0; if (stream == NULL) return; @@ -827,10 +828,9 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_str_prefix(&prefix, info, elmtno, ctx->ndims, ctx); /* Write new prefix to output */ - if (ctx->indent_level >= 0) { + if (ctx->indent_level > 0) indentlevel = ctx->indent_level; - } - else { + else /* * This is because sometimes we don't print out all the header * info for the data (like the tattr-2.ddl example). If that happens @@ -838,29 +838,23 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, * just print out the default indent levels. */ indentlevel = ctx->default_indent_level; - } /* when printing array indices, print the indentation before the prefix the prefix is printed one indentation level before */ - if (info->pindex) { - for (i = 0; i < indentlevel - 1; i++) { + if (info->pindex) + for (u = 0; u < indentlevel - 1; u++) PUTSTREAM(h5tools_str_fmt(&str, (size_t)0, info->line_indent), stream); - } - } - if (elmtno == 0 && secnum == 0 && info->line_1st) { + if (elmtno == 0 && secnum == 0 && info->line_1st) PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_1st), stream); - } - else if (secnum && info->line_cont) { + else if (secnum && info->line_cont) PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_cont), stream); - } - else { + else PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_pre), stream); - } templength = h5tools_str_len(&prefix); - for (i = 0; i < indentlevel; i++) { + for (u = 0; u < indentlevel; u++) /*we already made the indent for the array indices case */ if (!info->pindex) { PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_indent), stream); @@ -870,7 +864,6 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, /*we cannot count the prefix for the array indices case */ templength += h5tools_str_len(&str); } - } ctx->cur_column = ctx->prev_prefix_len = templength; ctx->cur_elmt = 0; @@ -900,7 +893,7 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_str_t prefix; h5tools_str_t str; /*temporary for indentation */ size_t templength = 0; - int i, indentlevel = 0; + unsigned u, indentlevel = 0; if (stream == NULL) return; @@ -922,7 +915,7 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_str_region_prefix(&prefix, info, elmtno, ptdata, ctx->ndims, ctx->p_max_idx, ctx); /* Write new prefix to output */ - if (ctx->indent_level >= 0) + if (ctx->indent_level > 0) indentlevel = ctx->indent_level; else /* @@ -936,20 +929,19 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, /* when printing array indices, print the indentation before the prefix the prefix is printed one indentation level before */ if (info->pindex) - for (i = 0; i < indentlevel - 1; i++) { + for (u = 0; u < indentlevel - 1; u++) PUTSTREAM(h5tools_str_fmt(&str, (size_t)0, info->line_indent), stream); - } - if (elmtno == 0 && secnum == 0 && info->line_1st) { + if (elmtno == 0 && secnum == 0 && info->line_1st) PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_1st), stream); - } else if (secnum && info->line_cont) { + else if (secnum && info->line_cont) PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_cont), stream); - } else + else PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_pre), stream); templength = h5tools_str_len(&prefix); - for (i = 0; i < indentlevel; i++) { + for (u = 0; u < indentlevel; u++) /*we already made the indent for the array indices case */ if (!info->pindex) { PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_indent), stream); @@ -959,7 +951,6 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, /*we cannot count the prefix for the array indices case */ templength += h5tools_str_len(&str); } - } ctx->cur_column = ctx->prev_prefix_len = templength; ctx->cur_elmt = 0; @@ -1299,9 +1290,8 @@ init_acc_pos(h5tools_context_t *ctx, hsize_t *dims) HDassert(ctx->ndims); ctx->acc[ctx->ndims - 1] = 1; - for (i = (ctx->ndims - 2); i >= 0; i--) { + for (i = ((int)ctx->ndims - 2); i >= 0; i--) ctx->acc[i] = ctx->acc[i + 1] * dims[i + 1]; - } for (j = 0; j < ctx->ndims; j++) ctx->pos[j] = 0; } @@ -1536,18 +1526,18 @@ CATCH */ int render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, - hid_t container, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) + hid_t container, unsigned ndims, hid_t type_id, hsize_t nblocks, hsize_t *ptdata) { hsize_t *dims1 = NULL; hsize_t *start = NULL; hsize_t *count = NULL; hsize_t numelem; hsize_t total_size[H5S_MAX_RANK]; - int jndx; + unsigned jndx; size_t type_size; hid_t mem_space = -1; void *region_buf = NULL; - int blkndx; + hsize_t blkndx; hid_t sid1 = -1; int ret_value = SUCCEED; @@ -1567,7 +1557,7 @@ render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, } /* Create dataspace for reading buffer */ - if((mem_space = H5Screate_simple(ndims, dims1, NULL)) < 0) + if((mem_space = H5Screate_simple((int)ndims, dims1, NULL)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed"); if((type_size = H5Tget_size(type_id)) == 0) @@ -1640,7 +1630,8 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id, hsize_t nblocks; hsize_t alloc_size; hsize_t *ptdata; - int ndims; + int sndims; + unsigned ndims; hid_t dtype = -1; hid_t type_id = -1; @@ -1649,16 +1640,16 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id, nblocks = (hsize_t)snblocks; /* Print block information */ - if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) + if((sndims = H5Sget_simple_extent_ndims(region_space)) < 0) H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + ndims = (unsigned)sndims; alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]); HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ if((ptdata = (hsize_t*) HDmalloc((size_t) alloc_size)) == NULL) HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); - H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t); - if(H5Sget_select_hyper_blocklist(region_space, (hsize_t) 0, (hsize_t) nblocks, ptdata) < 0) + if(H5Sget_select_hyper_blocklist(region_space, (hsize_t) 0, nblocks, ptdata) < 0) HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Rget_select_hyper_blocklist failed"); if((dtype = H5Dget_type(region_id)) < 0) @@ -1705,10 +1696,10 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id, int render_bin_output_region_data_points(hid_t region_space, hid_t region_id, FILE *stream, hid_t container, - int ndims, hid_t type_id, hssize_t npoints) + unsigned ndims, hid_t type_id, hsize_t npoints) { hsize_t *dims1 = NULL; - int type_size; + size_t type_size; hid_t mem_space = -1; void *region_buf = NULL; int ret_value = SUCCEED; @@ -1763,17 +1754,21 @@ render_bin_output_region_points(hid_t region_space, hid_t region_id, FILE *stream, hid_t container) { HERR_INIT(hbool_t, TRUE) - hssize_t npoints; - int ndims; + hssize_t snpoints; + hsize_t npoints; + int sndims; + unsigned ndims; hid_t dtype = -1; hid_t type_id = -1; - if((npoints = H5Sget_select_elem_npoints(region_space)) <= 0) + if((snpoints = H5Sget_select_elem_npoints(region_space)) <= 0) H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed"); + npoints = (hsize_t)snpoints; /* Allocate space for the dimension array */ - if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) + if((sndims = H5Sget_simple_extent_ndims(region_space)) < 0) H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + ndims = (unsigned)sndims; if((dtype = H5Dget_type(region_id)) < 0) HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Dget_type failed"); diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index 5c08f33..b548100 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -37,10 +37,10 @@ #define H5TOOLS_DUMP_MAX_RANK H5S_MAX_RANK /* Stream macros */ -#define FLUSHSTREAM(S) {if(S != NULL) HDfflush(S);} -#define PRINTSTREAM(S, F, ...) {if(S != NULL) HDfprintf(S, F, __VA_ARGS__);} -#define PRINTVALSTREAM(S, V) {if(S != NULL) HDfprintf(S, V);} -#define PUTSTREAM(X,S) {if(S != NULL) HDfputs(X, S);} +#define FLUSHSTREAM(S) if(S != NULL) HDfflush(S) +#define PRINTSTREAM(S, F, ...) if(S != NULL) HDfprintf(S, F, __VA_ARGS__) +#define PRINTVALSTREAM(S, V) if(S != NULL) HDfprintf(S, V) +#define PUTSTREAM(X,S) do { if(S != NULL) HDfputs(X, S); } while(0) /* * Strings for output - these were duplicated from the h5dump.h @@ -81,7 +81,7 @@ #define FLETCHER32 "CHECKSUM FLETCHER32" #define SZIP "COMPRESSION SZIP" #define NBIT "COMPRESSION NBIT" -#define SCALEOFFSET "COMPRESSION SCALEOFFSET" +#define SCALEOFFSET "COMPRESSION SCALEOFFSET" #define SCALEOFFSET_MINBIT "MIN BITS" #define STORAGE_LAYOUT "STORAGE_LAYOUT" #define CONTIGUOUS "CONTIGUOUS" @@ -275,7 +275,7 @@ typedef struct h5tool_format_t { const char *fmt_float; int ascii; int str_locale; - int str_repeat; + unsigned str_repeat; /* * Fields associated with compound array members. @@ -491,9 +491,9 @@ typedef struct h5tools_context_t { hsize_t size_last_dim; /*the size of the last dimension, *needed so we can break after each *row */ - int indent_level; /*the number of times we need some + unsigned indent_level; /*the number of times we need some *extra indentation */ - int default_indent_level; /*this is used when the indent level gets changed */ + unsigned default_indent_level; /*this is used when the indent level gets changed */ hsize_t acc[H5S_MAX_RANK]; /* accumulator position */ hsize_t pos[H5S_MAX_RANK]; /* matrix position */ hsize_t sm_pos; /* current stripmine element position */ @@ -526,9 +526,9 @@ H5TOOLS_DLLVAR const h5tools_dump_header_t* h5tools_dump_header_format; extern "C" { #endif -H5TOOLS_DLLVAR int packed_bits_num; /* number of packed bits to display */ -H5TOOLS_DLLVAR int packed_data_offset; /* offset of packed bits to display */ -H5TOOLS_DLLVAR int packed_data_length; /* lengtht of packed bits to display */ +H5TOOLS_DLLVAR unsigned packed_bits_num; /* number of packed bits to display */ +H5TOOLS_DLLVAR unsigned packed_data_offset; /* offset of packed bits to display */ +H5TOOLS_DLLVAR unsigned packed_data_length; /* length of packed bits to display */ H5TOOLS_DLLVAR unsigned long long packed_data_mask; /* mask in which packed bits to display */ H5TOOLS_DLLVAR FILE *rawattrstream; /* output stream for raw attribute data */ H5TOOLS_DLLVAR FILE *rawdatastream; /* output stream for raw data */ @@ -542,6 +542,9 @@ H5TOOLS_DLLVAR int oid_output; /* oid output */ H5TOOLS_DLLVAR int data_output; /* data output */ H5TOOLS_DLLVAR int attr_data_output; /* attribute data output */ +/* things to display or which are set via command line parameters */ +H5TOOLS_DLLVAR int enable_error_stack; /* re-enable error stack */ + /* Strings for output */ #define H5_TOOLS_GROUP "GROUP" #define H5_TOOLS_DATASET "DATASET" @@ -550,11 +553,11 @@ H5TOOLS_DLLVAR int attr_data_output; /* attribute data output */ /* Definitions of useful routines */ H5TOOLS_DLL void h5tools_init(void); H5TOOLS_DLL void h5tools_close(void); -H5TOOLS_DLL int h5tools_set_data_output_file(const char *fname, int is_bin); -H5TOOLS_DLL int h5tools_set_attr_output_file(const char *fname, int is_bin); -H5TOOLS_DLL int h5tools_set_input_file(const char *fname, int is_bin); -H5TOOLS_DLL int h5tools_set_output_file(const char *fname, int is_bin); -H5TOOLS_DLL int h5tools_set_error_file(const char *fname, int is_bin); +H5TOOLS_DLL int h5tools_set_data_output_file(const char *fname, int is_bin); +H5TOOLS_DLL int h5tools_set_attr_output_file(const char *fname, int is_bin); +H5TOOLS_DLL int h5tools_set_input_file(const char *fname, int is_bin); +H5TOOLS_DLL int h5tools_set_output_file(const char *fname, int is_bin); +H5TOOLS_DLL int h5tools_set_error_file(const char *fname, int is_bin); H5TOOLS_DLL hid_t h5tools_fopen(const char *fname, unsigned flags, hid_t fapl, const char *driver, char *drivername, size_t drivername_len); H5TOOLS_DLL hid_t h5tools_get_native_type(hid_t type); @@ -574,8 +577,12 @@ H5TOOLS_DLL void h5tools_region_simple_prefix(FILE *stream, const h5tool_form h5tools_context_t *ctx, hsize_t elmtno, hsize_t *ptdata, int secnum); H5TOOLS_DLL int render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t nelmts); +H5TOOLS_DLL int render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, + hid_t container, unsigned ndims, hid_t type_id, hsize_t nblocks, hsize_t *ptdata); H5TOOLS_DLL hbool_t render_bin_output_region_blocks(hid_t region_space, hid_t region_id, FILE *stream, hid_t container); +H5TOOLS_DLL int render_bin_output_region_data_points(hid_t region_space, hid_t region_id, + FILE* stream, hid_t container, unsigned ndims, hid_t type_id, hsize_t npoints); H5TOOLS_DLL hbool_t render_bin_output_region_points(hid_t region_space, hid_t region_id, FILE *stream, hid_t container); diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c index 2c2a06f..3928837 100644 --- a/tools/lib/h5tools_dump.c +++ b/tools/lib/h5tools_dump.c @@ -198,10 +198,10 @@ hbool_t h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, size_t ncols, hsize_t region_elmt_counter/*element counter*/, hsize_t elmt_counter); -int h5tools_print_region_data_points(hid_t region_space, hid_t region_id, +static int h5tools_print_region_data_points(hid_t region_space, hid_t region_id, FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, h5tools_str_t *buffer, size_t ncols, - int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata); + unsigned ndims, hid_t type_id, hsize_t npoints, hsize_t *ptdata); hbool_t h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, FILE *stream, const h5tool_format_t *info, @@ -634,10 +634,10 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]); HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ if((ptdata = (hsize_t*) HDmalloc((size_t) alloc_size)) == NULL) -{ + { HERROR(H5E_tools_g, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); HGOTO_DONE(dimension_break); -} + } if(H5Sget_select_hyper_blocklist(region_space, (hsize_t)0, nblocks, ptdata) < 0) HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Rget_select_hyper_blocklist failed"); @@ -779,20 +779,20 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, * hssize_t npoints is the number of points in the region *------------------------------------------------------------------------- */ -int +static int h5tools_print_region_data_points(hid_t region_space, hid_t region_id, FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, h5tools_str_t *buffer, size_t ncols, - int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata) + unsigned ndims, hid_t type_id, hsize_t npoints, hsize_t *ptdata) { hbool_t dimension_break = TRUE; hsize_t *dims1 = NULL; hsize_t elmtno; /* elemnt index */ hsize_t curr_pos = 0; hsize_t total_size[H5S_MAX_RANK]; - size_t jndx; + hsize_t jndx; unsigned indx; - int type_size; + size_t type_size; int ret_value = SUCCEED; unsigned int region_flags; /* buffer extent flags */ hid_t mem_space = -1; @@ -807,7 +807,7 @@ h5tools_print_region_data_points(hid_t region_space, hid_t region_id, HDmemset(&ctx, 0, sizeof(ctx)); /* Allocate space for the dimension array */ - if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims)) == NULL) + if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for dims"); dims1[0] = npoints; @@ -841,7 +841,7 @@ h5tools_print_region_data_points(hid_t region_space, hid_t region_id, HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); /* assume entire data space to be printed */ - for (indx = 0; indx < (size_t) ctx.ndims; indx++) + for (indx = 0; indx < ctx.ndims; indx++) ctx.p_min_idx[indx] = 0; init_acc_pos(&ctx, total_size); @@ -850,13 +850,12 @@ h5tools_print_region_data_points(hid_t region_space, hid_t region_id, if (jndx == npoints - 1) region_flags |= END_OF_DATA; - for (indx = 0; indx < (size_t)ctx.ndims; indx++) + for (indx = 0; indx < ctx.ndims; indx++) ctx.p_max_idx[indx] = cur_ctx->p_max_idx[indx]; ctx.sm_pos = jndx * ndims; - if (ctx.ndims > 0) { - ctx.size_last_dim = (int) (ctx.p_max_idx[ctx.ndims - 1]); - } + if (ctx.ndims > 0) + ctx.size_last_dim = ctx.p_max_idx[ctx.ndims - 1]; else ctx.size_last_dim = 0; @@ -922,11 +921,13 @@ h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, hsize_t elmt_counter) { HERR_INIT(hbool_t, TRUE) hbool_t dimension_break = TRUE; - hssize_t npoints; + hssize_t snpoints; + hsize_t npoints; hsize_t alloc_size; hsize_t *ptdata; - int ndims; - hssize_t indx; + int sndims; + unsigned ndims; + hsize_t indx; hid_t dtype = -1; hid_t type_id = -1; @@ -934,12 +935,14 @@ h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, HDassert(ctx); HDassert(buffer); - if((npoints = H5Sget_select_elem_npoints(region_space)) <= 0) + if((snpoints = H5Sget_select_elem_npoints(region_space)) <= 0) H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed"); + npoints = (hsize_t)snpoints; /* Allocate space for the dimension array */ - if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) + if((sndims = H5Sget_simple_extent_ndims(region_space)) < 0) H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + ndims = (unsigned)sndims; /* Render the region { element begin */ h5tools_str_reset(buffer); @@ -960,12 +963,11 @@ h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, if(NULL == (ptdata = (hsize_t *)HDmalloc((size_t) alloc_size))) HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); - H5_CHECK_OVERFLOW(npoints, hssize_t, hsize_t); - if(H5Sget_select_elem_pointlist(region_space, (hsize_t) 0, (hsize_t) npoints, ptdata) < 0) + if(H5Sget_select_elem_pointlist(region_space, (hsize_t) 0, npoints, ptdata) < 0) HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Sget_select_elem_pointlist failed"); for (indx = 0; indx < npoints; indx++) { - int loop_indx; + unsigned loop_indx; h5tools_str_append(buffer, info->dset_ptformat_pre, indx ? "," OPTIONAL_LINE_BREAK " " : "", (unsigned long) indx); @@ -1249,7 +1251,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c H5Dvlen_reclaim(p_type, sm_space, H5P_DEFAULT, sm_buf); if(H5Sclose(sm_space) < 0) - H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if(sm_buf) HDfree(sm_buf); sm_buf = NULL; @@ -1333,7 +1335,7 @@ h5tools_display_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools } /* initialize temporary start, count and maximum start */ - for (i = 0; i < (size_t) ctx->ndims; i++) { + for (i = 0; i < ctx->ndims; i++) { temp_start[i] = sset->start.data[i]; temp_count[i] = sset->count.data[i]; temp_block[i] = sset->block.data[i]; @@ -1375,12 +1377,11 @@ h5tools_display_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools if (ctx->ndims > 2) { /* dimension for start */ - current_outer_dim = (ctx->ndims - 2) - 1; + current_outer_dim = (int)(ctx->ndims - 2) - 1; /* set start to original from current_outer_dim up */ - for (i = current_outer_dim + 1; i < ctx->ndims; i++) { + for (i = (size_t)(current_outer_dim + 1); i < ctx->ndims; i++) temp_start[i] = sset->start.data[i]; - } /* increment start dimension */ do { @@ -1472,7 +1473,7 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_co CATCH if(f_space >= 0 && H5Sclose(f_space) < 0) - H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); return ret_value; } @@ -1500,6 +1501,7 @@ h5tools_dump_simple_dset(FILE *stream, const h5tool_format_t *info, h5tools_cont hid_t f_space = -1; /* file data space */ hsize_t elmtno; /* counter */ size_t i; /* counter */ + int sndims; /* rank of dataspace */ int carry; /* counter carry value */ hsize_t zero[8]; /* vector of zeros */ unsigned int flags; /* buffer extent flags */ @@ -1529,11 +1531,13 @@ h5tools_dump_simple_dset(FILE *stream, const h5tool_format_t *info, h5tools_cont if (f_space == FAIL) H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); - ctx->ndims = H5Sget_simple_extent_ndims(f_space); + sndims = H5Sget_simple_extent_ndims(f_space); + if(sndims < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_simple_extent_ndims failed"); + ctx->ndims = (unsigned)sndims; - if ((size_t)ctx->ndims > NELMTS(sm_size)) { + if ((size_t)ctx->ndims > NELMTS(sm_size)) H5E_THROW(FAIL, H5E_tools_min_id_g, "ctx->ndims > NELMTS(sm_size) failed"); - } /* Assume entire data space to be printed */ if (ctx->ndims > 0) @@ -1652,9 +1656,9 @@ CATCH done: if(sm_space >= 0 && H5Sclose(sm_space) < 0) - H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if(f_space >= 0 && H5Sclose(f_space) < 0) - H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); return ret_value; } @@ -1675,10 +1679,14 @@ h5tools_dump_simple_mem(FILE *stream, const h5tool_format_t *info, h5tools_conte hid_t type, hid_t space, void *mem) { HERR_INIT(herr_t, SUCCEED) + int sndims; /* rank of dataspace */ unsigned i; /*counters */ hsize_t nelmts; /*total selected elmts */ - ctx->ndims = H5Sget_simple_extent_ndims(space); + sndims = H5Sget_simple_extent_ndims(space); + if(sndims < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_simple_extent_ndims failed"); + ctx->ndims = (unsigned)sndims; if ((size_t) ctx->ndims > NELMTS(ctx->p_min_idx)) H5E_THROW(FAIL, H5E_tools_min_id_g, "ctx->ndims > NELMTS(ctx->p_min_idx) failed"); @@ -1696,7 +1704,7 @@ h5tools_dump_simple_mem(FILE *stream, const h5tool_format_t *info, h5tools_conte H5_LEAVE(SUCCEED); /* nothing to print */ if (ctx->ndims > 0) { HDassert(ctx->p_max_idx[ctx->ndims - 1] == (hsize_t) ((int) ctx->p_max_idx[ctx->ndims - 1])); - ctx->size_last_dim = (int) (ctx->p_max_idx[ctx->ndims - 1]); + ctx->size_last_dim = ctx->p_max_idx[ctx->ndims - 1]; } /* end if */ else ctx->size_last_dim = 0; @@ -2583,7 +2591,6 @@ h5tools_print_enum(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *i unsigned i; unsigned nmembs = 0; /*number of members */ int snmembs; - int nchars; /*number of output characters */ hid_t super = -1; /*enum base integer type */ hid_t native = -1; /*native integer datatype */ H5T_sign_t sign_type; /*sign of value type */ @@ -2650,12 +2657,14 @@ h5tools_print_enum(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *i /* Print members */ for (i = 0; i < nmembs; i++) { + int nchars; /*number of output characters */ + ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, (hsize_t)0, 0); h5tools_str_reset(buffer); h5tools_str_append(buffer, "\"%s\"", name[i]); - nchars = HDstrlen(name[i]); + nchars = (int)HDstrlen(name[i]); h5tools_str_append(buffer, "%*s ", MAX(0, 16 - nchars), ""); if (native < 0) { @@ -2900,7 +2909,7 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, 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 file 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; @@ -2942,7 +2951,7 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, for(i = 1; i < rank; i++) h5tools_str_append(&buffer, ", " HSIZE_T_FORMAT, chsize[i]); h5tools_str_append(&buffer, " %s", h5tools_dump_header_format->dataspacedimend); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); @@ -2995,8 +3004,7 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, else { h5tools_str_append(&buffer, "SIZE " HSIZE_T_FORMAT, storage_size); } - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); - + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->indent_level--; break; case H5D_COMPACT: @@ -3006,15 +3014,14 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "%s", COMPACT); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "SIZE " HSIZE_T_FORMAT, storage_size); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); - + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->indent_level--; break; case H5D_CONTIGUOUS: @@ -3034,14 +3041,14 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "%s", CONTIGUOUS); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "%s %s", EXTERNAL, BEGIN); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->indent_level++; for (j = 0; j < (unsigned) next; j++) { @@ -3053,7 +3060,7 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "FILENAME %s SIZE " HSIZE_T_FORMAT, name, size); h5tools_str_append(&buffer, " OFFSET %ld", offset); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); } ctx->indent_level--; @@ -3072,14 +3079,14 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "%s", CONTIGUOUS); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); h5tools_str_reset(&buffer); h5tools_str_append(&buffer,"SIZE " HSIZE_T_FORMAT, storage_size); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); @@ -3437,7 +3444,7 @@ h5tools_dump_comment(FILE *stream, const h5tool_format_t *info, if (cmt_bufsize > 0) { comment = (char *)HDmalloc((size_t)(cmt_bufsize+1)); /* new_size including null terminator */ if(comment) { - cmt_bufsize = H5Oget_comment(obj_id, comment, cmt_bufsize); + cmt_bufsize = H5Oget_comment(obj_id, comment, (size_t)cmt_bufsize); if(cmt_bufsize > 0) { comment[cmt_bufsize] = '\0'; /* necessary because null char is not returned */ @@ -3576,49 +3583,39 @@ h5tools_print_dims(h5tools_str_t *buffer, hsize_t *s, int dims) void h5tools_print_packed_bits(h5tools_str_t *buffer, hid_t type) { - int packed_bits_size = 0; - + unsigned packed_bits_size = 0; hid_t n_type = h5tools_get_native_type(type); - if(H5Tget_class(n_type)==H5T_INTEGER) { - if(H5Tequal(n_type, H5T_NATIVE_SCHAR) == TRUE) { + + if(H5Tget_class(n_type) == H5T_INTEGER) { + if(H5Tequal(n_type, H5T_NATIVE_SCHAR) == TRUE) packed_bits_size = 8 * sizeof(char); - } - else if(H5Tequal(n_type, H5T_NATIVE_UCHAR) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_UCHAR) == TRUE) packed_bits_size = 8 * sizeof(unsigned char); - } - else if(H5Tequal(n_type, H5T_NATIVE_SHORT) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_SHORT) == TRUE) packed_bits_size = 8 * sizeof(short); - } - else if(H5Tequal(n_type, H5T_NATIVE_USHORT) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_USHORT) == TRUE) packed_bits_size = 8 * sizeof(unsigned short); - } - else if(H5Tequal(n_type, H5T_NATIVE_INT) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_INT) == TRUE) packed_bits_size = 8 * sizeof(int); - } - else if(H5Tequal(n_type, H5T_NATIVE_UINT) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_UINT) == TRUE) packed_bits_size = 8 * sizeof(unsigned int); - } - else if(H5Tequal(n_type, H5T_NATIVE_LONG) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_LONG) == TRUE) packed_bits_size = 8 * sizeof(long); - } - else if(H5Tequal(n_type, H5T_NATIVE_ULONG) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_ULONG) == TRUE) packed_bits_size = 8 * sizeof(unsigned long); - } - else if(H5Tequal(n_type, H5T_NATIVE_LLONG) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_LLONG) == TRUE) packed_bits_size = 8 * sizeof(long long); - } - else if(H5Tequal(n_type, H5T_NATIVE_ULLONG) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_ULLONG) == TRUE) packed_bits_size = 8 * sizeof(unsigned long long); - } else error_msg("Packed Bit not valid for this datatype"); } - if ((packed_bits_size>0) && (packed_data_offset + packed_data_length) > packed_bits_size) { - error_msg("Packed Bit offset+length value(%d) too large. Max is %d\n", packed_data_offset+packed_data_length, packed_bits_size); + if((packed_bits_size > 0) && (packed_data_offset + packed_data_length) > packed_bits_size) { + error_msg("Packed Bit offset+length value(%u) too large. Max is %d\n", packed_data_offset + packed_data_length, packed_bits_size); packed_data_mask = 0; }; - h5tools_str_append(buffer, "%s %s=%d %s=%d", PACKED_BITS, PACKED_OFFSET, packed_data_offset, PACKED_LENGTH, packed_data_length); + h5tools_str_append(buffer, "%s %s=%u %s=%u", PACKED_BITS, PACKED_OFFSET, packed_data_offset, PACKED_LENGTH, packed_data_length); } /*------------------------------------------------------------------------- diff --git a/tools/lib/h5tools_error.h b/tools/lib/h5tools_error.h index ae549fd..749157e 100644 --- a/tools/lib/h5tools_error.h +++ b/tools/lib/h5tools_error.h @@ -98,7 +98,7 @@ H5TOOLS_DLLVAR hid_t H5E_tools_min_id_g; * to the `catch_except' label, if we're not already past it. */ #define H5E_THROW(fail_value, min_id, str) { \ - HERROR(H5E_tools_g, min_id, str); \ + H5Epush2(H5tools_ERR_STACK_g, __FILE__, FUNC, __LINE__, H5tools_ERR_CLS_g, H5E_tools_g, min_id, str); \ H5_LEAVE(fail_value) \ } diff --git a/tools/lib/h5tools_filters.c b/tools/lib/h5tools_filters.c index ccdba26..0b42124 100644 --- a/tools/lib/h5tools_filters.c +++ b/tools/lib/h5tools_filters.c @@ -13,7 +13,7 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "hdf5.h" +#include "H5private.h" #include "h5tools.h" /*------------------------------------------------------------------------- @@ -151,54 +151,60 @@ int h5tools_can_encode(H5Z_filter_t filtn) { switch (filtn) { /* user defined filter */ default: - return 0; + return 0; case H5Z_FILTER_DEFLATE: #ifndef H5_HAVE_FILTER_DEFLATE - return 0; + return 0; #endif - break; + break; + case H5Z_FILTER_SZIP: #ifndef H5_HAVE_FILTER_SZIP - return 0; + return 0; #else { - unsigned int filter_config_flags; + unsigned int filter_config_flags; - if (H5Zget_filter_info(filtn, &filter_config_flags) < 0) - return -1; - if ((filter_config_flags - & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) == 0) { - /* filter present but neither encode nor decode is supported (???) */ - return -1; - } - else if ((filter_config_flags - & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) == H5Z_FILTER_CONFIG_DECODE_ENABLED) { - /* decoder only: read but not write */ - return 0; - } - else if ((filter_config_flags - & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) == H5Z_FILTER_CONFIG_ENCODE_ENABLED) { - /* encoder only: write but not read (???) */ - return -1; - } - else if ((filter_config_flags - & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) - == (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) { - return 1; - } + if (H5Zget_filter_info(filtn, &filter_config_flags) < 0) + return -1; + if ((filter_config_flags + & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) == 0) { + /* filter present but neither encode nor decode is supported (???) */ + return -1; + } + else if ((filter_config_flags + & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) == H5Z_FILTER_CONFIG_DECODE_ENABLED) { + /* decoder only: read but not write */ + return 0; + } + else if ((filter_config_flags + & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) == H5Z_FILTER_CONFIG_ENCODE_ENABLED) { + /* encoder only: write but not read (???) */ + return -1; + } + else if ((filter_config_flags + & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) + == (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) { + return 1; + } } #endif - break; + break; + case H5Z_FILTER_SHUFFLE: - break; + break; + case H5Z_FILTER_FLETCHER32: - break; + break; + case H5Z_FILTER_NBIT: - break; + break; + case H5Z_FILTER_SCALEOFFSET: - break; - }/*switch*/ + break; + }/*switch*/ - return 1; + return 1; } + diff --git a/tools/lib/h5tools_ref.c b/tools/lib/h5tools_ref.c index 3a4183b..8c869c8 100644 --- a/tools/lib/h5tools_ref.c +++ b/tools/lib/h5tools_ref.c @@ -39,7 +39,7 @@ typedef struct { haddr_t objno; /* Object ID (i.e. address) */ - const char *path; /* Object path */ + char *path; /* Object path */ } ref_path_node_t; static H5SL_t *ref_path_table = NULL; /* the "table" (implemented with a skip list) */ @@ -65,7 +65,7 @@ free_ref_path_info(void *item, void H5_ATTR_UNUSED *key, void H5_ATTR_UNUSED *op { ref_path_node_t *node = (ref_path_node_t *)item; - HDfree((void *)node->path); + HDfree(node->path); HDfree(node); return(0); @@ -218,7 +218,7 @@ ref_path_table_put(const char *path, haddr_t objno) HDassert(ref_path_table); HDassert(path); - if((new_node = HDmalloc(sizeof(ref_path_node_t))) == NULL) + if((new_node = (ref_path_node_t *)HDmalloc(sizeof(ref_path_node_t))) == NULL) return(-1); new_node->objno = objno; @@ -300,7 +300,7 @@ lookup_ref_path(haddr_t ref) if(ref_path_table == NULL) init_ref_path_table(); - node = H5SL_search(ref_path_table, &ref); + node = (ref_path_node_t *)H5SL_search(ref_path_table, &ref); return(node ? node->path : NULL); } diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index a92568a..60b85d9 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -126,14 +126,12 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) va_list ap; /* Make sure we have some memory into which to print */ - if (!str->s || str->nalloc <= 0) { + if (!str->s || str->nalloc <= 0) h5tools_str_reset(str); - } - if (HDstrlen(fmt) == 0) { + if (HDstrlen(fmt) == 0) /* nothing to print */ return str->s; - } /* Format the arguments and append to the value already in `str' */ while (1) { @@ -156,19 +154,18 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) * to lack of buffer size, so try one more time after realloc more * buffer size before return NULL. */ - if (nchars < 0) { + if (nchars < 0) /* failure, such as bad format */ return NULL; - } - if (nchars < 0 || (size_t) nchars >= avail || (0 == nchars && (HDstrcmp(fmt, "%s")))) { + if ((size_t) nchars >= avail || (0 == nchars && (HDstrcmp(fmt, "%s")))) { /* Truncation return value as documented by C99, or zero return value with either of the * following conditions, each of which indicates that the proper C99 return value probably * should have been positive when the format string is * something other than "%s" * Alocate at least twice as much space and try again. */ - size_t newsize = MAX(str->len + nchars + 1, 2 * str->nalloc); + size_t newsize = MAX(str->len + (size_t)nchars + 1, 2 * str->nalloc); HDassert(newsize > str->nalloc); /*overflow*/ str->s = (char*)HDrealloc(str->s, newsize); HDassert(str->s); @@ -176,7 +173,7 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) } else { /* Success */ - str->len += nchars; + str->len += (size_t)nchars; break; } } @@ -267,6 +264,9 @@ h5tools_str_fmt(h5tools_str_t *str/*in,out*/, size_t start, const char *fmt) { char _temp[1024], *temp = _temp; + HDassert(str); + HDassert(fmt); + /* If the format string is simply "%s" then don't bother doing anything */ if (!HDstrcmp(fmt, "%s")) return str->s; @@ -413,9 +413,9 @@ h5tools_str_region_prefix(h5tools_str_t *str, const h5tool_format_t *info, } /*------------------------------------------------------------------------- - * Function: h5tools_str_dump_region_blocks + * Function: h5tools_str_dump_space_slabs * - * Purpose: Prints information about a dataspace region by appending + * Purpose: Prints information about a dataspace selection by appending * the information to the specified string. * * Return: none @@ -426,45 +426,111 @@ h5tools_str_region_prefix(h5tools_str_t *str, const h5tool_format_t *info, *------------------------------------------------------------------------- */ void -h5tools_str_dump_region_blocks(h5tools_str_t *str, hid_t region, +h5tools_str_dump_space_slabs(h5tools_str_t *str, hid_t rspace, + const h5tool_format_t *info, h5tools_context_t *ctx) +{ + hsize_t start[H5S_MAX_RANK]; + hsize_t stride[H5S_MAX_RANK]; + hsize_t count[H5S_MAX_RANK]; + hsize_t block[H5S_MAX_RANK]; + int j; + int ndims = H5Sget_simple_extent_ndims(rspace); + + H5Sget_regular_hyperslab(rspace, start, stride, count, block); + + /* Print hyperslab information */ + + /* Start coordinates */ + h5tools_str_append(str, "%s%s ", info->line_indent, START); + for (j = 0; j < ndims; j++) + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : "(", start[j]); + h5tools_str_append(str, ")"); + h5tools_str_append(str, "%s", "\n"); + h5tools_str_indent(str, info, ctx); + + /* Stride coordinates */ + h5tools_str_append(str, "%s ", STRIDE); + for (j = 0; j < ndims; j++) + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : "(", stride[j]); + h5tools_str_append(str, ")"); + h5tools_str_append(str, "%s", "\n"); + h5tools_str_indent(str, info, ctx); + + /* Count coordinates */ + h5tools_str_append(str, "%s ", COUNT); + for (j = 0; j < ndims; j++) { + if(count[j] == H5S_UNLIMITED) + h5tools_str_append(str, "%s%s", j ? "," : "(","H5S_UNLIMITED"); + else + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : "(", count[j]); + } + h5tools_str_append(str, ")"); + h5tools_str_append(str, "%s", "\n"); + h5tools_str_indent(str, info, ctx); + + /* Block coordinates */ + h5tools_str_append(str, "%s ", BLOCK); + for (j = 0; j < ndims; j++) { + if(block[j] == H5S_UNLIMITED) + h5tools_str_append(str, "%s%s", j ? "," : "(","H5S_UNLIMITED"); + else + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : "(", block[j]); + } + h5tools_str_append(str, ")"); +} + +/*------------------------------------------------------------------------- + * Function: h5tools_str_dump_space_blocks + * + * Purpose: Prints information about a dataspace selection by appending + * the information to the specified string. + * + * Return: none + * + * In/Out: + * h5tools_str_t *str + *------------------------------------------------------------------------- + */ +void +h5tools_str_dump_space_blocks(h5tools_str_t *str, hid_t rspace, const h5tool_format_t *info) { - hssize_t nblocks; - hsize_t alloc_size; - hsize_t *ptdata; - int ndims = H5Sget_simple_extent_ndims(region); + hssize_t snblocks; /* - * This function fails if the region does not have blocks. + * This function fails if the rspace does not have blocks. */ H5E_BEGIN_TRY { - nblocks = H5Sget_select_hyper_nblocks(region); + snblocks = H5Sget_select_hyper_nblocks(rspace); } H5E_END_TRY; /* Print block information */ - if (nblocks > 0) { - int i; - + if (snblocks > 0) { + hsize_t nblocks; + hsize_t *ptdata; + hsize_t alloc_size; + unsigned ndims = (unsigned)H5Sget_simple_extent_ndims(rspace); + hsize_t u; + + nblocks = (hsize_t)snblocks; alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]); HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ ptdata = (hsize_t *)HDmalloc((size_t) alloc_size); - H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t); - H5Sget_select_hyper_blocklist(region, (hsize_t)0, (hsize_t)nblocks, ptdata); + H5Sget_select_hyper_blocklist(rspace, (hsize_t)0, nblocks, ptdata); - for (i = 0; i < nblocks; i++) { - int j; + for (u = 0; u < nblocks; u++) { + unsigned v; - h5tools_str_append(str, info->dset_blockformat_pre, i ? "," OPTIONAL_LINE_BREAK " " : "", - (unsigned long)i); + h5tools_str_append(str, info->dset_blockformat_pre, u ? "," OPTIONAL_LINE_BREAK " " : "", (unsigned long)u); /* Start coordinates and opposite corner */ - for (j = 0; j < ndims; j++) - h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : "(", - ptdata[i * 2 * ndims + j]); + for (v = 0; v < ndims; v++) + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, v ? "," : "(", + ptdata[u * 2 * ndims + v]); - for (j = 0; j < ndims; j++) - h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : ")-(", - ptdata[i * 2 * ndims + j + ndims]); + for (v = 0; v < ndims; v++) + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, v ? "," : ")-(", + ptdata[u * 2 * ndims + v + ndims]); h5tools_str_append(str, ")"); } @@ -474,53 +540,53 @@ h5tools_str_dump_region_blocks(h5tools_str_t *str, hid_t region, } /*------------------------------------------------------------------------- - * Function: h5tools_str_dump_region_points + * Function: h5tools_str_dump_space_points * - * Purpose: Prints information about a dataspace region by appending + * Purpose: Prints information about a dataspace selection by appending * the information to the specified string. * * Return: none * * In/Out: - * h5tools_context_t *ctx * h5tools_str_t *str *------------------------------------------------------------------------- */ void -h5tools_str_dump_region_points(h5tools_str_t *str, hid_t region, +h5tools_str_dump_space_points(h5tools_str_t *str, hid_t rspace, const h5tool_format_t *info) { - hssize_t npoints; - hsize_t alloc_size; - hsize_t *ptdata; - int ndims = H5Sget_simple_extent_ndims(region); + hssize_t snpoints; /* - * This function fails if the region does not have points. + * This function fails if the rspace does not have points. */ H5E_BEGIN_TRY { - npoints = H5Sget_select_elem_npoints(region); + snpoints = H5Sget_select_elem_npoints(rspace); } H5E_END_TRY; /* Print point information */ - if (npoints > 0) { - int i; - + if (snpoints > 0) { + hsize_t npoints; + hsize_t alloc_size; + hsize_t *ptdata; + unsigned ndims = (unsigned)H5Sget_simple_extent_ndims(rspace); + hsize_t u; + + npoints = (hsize_t)snpoints; alloc_size = npoints * ndims * sizeof(ptdata[0]); HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ ptdata = (hsize_t *)HDmalloc((size_t) alloc_size); - H5_CHECK_OVERFLOW(npoints, hssize_t, hsize_t); - H5Sget_select_elem_pointlist(region, (hsize_t)0, (hsize_t)npoints, ptdata); + H5Sget_select_elem_pointlist(rspace, (hsize_t)0, npoints, ptdata); - for (i = 0; i < npoints; i++) { - int j; + for (u = 0; u < npoints; u++) { + unsigned v; - h5tools_str_append(str, info->dset_ptformat_pre, i ? "," OPTIONAL_LINE_BREAK " " : "", - (unsigned long)i); + h5tools_str_append(str, info->dset_ptformat_pre, u ? "," OPTIONAL_LINE_BREAK " " : "", + (unsigned long)u); - for (j = 0; j < ndims; j++) - h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : "(", - (ptdata[i * ndims + j])); + for (v = 0; v < ndims; v++) + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, v ? "," : "(", + (ptdata[u * ndims + v])); h5tools_str_append(str, ")"); } @@ -609,13 +675,12 @@ void h5tools_str_indent(h5tools_str_t *str, const h5tool_format_t *info, h5tools_context_t *ctx) { - int i, indentlevel = 0; + unsigned u, indentlevel = 0; /* Write new prefix */ - if (ctx->indent_level >= 0) { + if (ctx->indent_level > 0) indentlevel = ctx->indent_level; - } - else { + else /* * This is because sometimes we don't print out all the header * info for the data (like the tattr-2.ddl example). If that happens @@ -623,11 +688,9 @@ h5tools_str_indent(h5tools_str_t *str, const h5tool_format_t *info, * just print out the default indent levels. */ indentlevel = ctx->default_indent_level; - } - for (i = 0; i < indentlevel; i++) { + for (u = 0; u < indentlevel; u++) h5tools_str_append(str, "%s", OPT(info->line_indent, "")); - } } /*------------------------------------------------------------------------- @@ -686,22 +749,10 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai unsigned char *ucp_vp = (unsigned char *)vp; char *cp_vp = (char *)vp; hid_t memb, obj; - unsigned nmembs; static char fmt_llong[8], fmt_ullong[8]; H5T_str_t pad; H5T_class_t type_class; - /* - * some tempvars to store the value before we append it to the string to - * get rid of the memory alignment problem - */ - unsigned long long tempullong; - long long templlong; - unsigned long tempulong; - long templong; - unsigned int tempuint; - int tempint; - /* Build default formats for long long types */ if (!fmt_llong[0]) { HDsnprintf(fmt_llong, sizeof(fmt_llong), "%%%sd", H5_PRINTF_LL_WIDTH); @@ -737,7 +788,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai float tempfloat; HDmemcpy(&tempfloat, vp, sizeof(float)); - h5tools_str_append(str, OPT(info->fmt_float, "%g"), tempfloat); + h5tools_str_append(str, OPT(info->fmt_float, "%g"), (double)tempfloat); } else if (sizeof(double) == nsize) { /* if (H5Tequal(type, H5T_NATIVE_DOUBLE)) */ @@ -756,6 +807,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai #endif } break; + case H5T_STRING: { unsigned int i; @@ -776,12 +828,11 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai pad = H5Tget_strpad(type); /* Check for NULL pointer for string */ - if (s == NULL) { + if (s == NULL) h5tools_str_append(str, "NULL"); - } else { for (i = 0; i < size && (s[i] || pad != H5T_STR_NULLTERM); i++) { - int j = 1; + unsigned j = 1; /* * Count how many times the next character repeats. If the @@ -798,7 +849,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai * in it's own quote. */ if (info->str_repeat > 0 && j > info->str_repeat) { - if (quote) h5tools_str_append(str, "%c", quote); + if (quote) + h5tools_str_append(str, "%c", quote); quote = '\''; h5tools_str_append(str, "%s%c", i ? " " : "", quote); @@ -821,10 +873,10 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai quote = '\0'; i += j - 1; } - } - if (quote) h5tools_str_append(str, "%c", quote); + if (quote) + h5tools_str_append(str, "%c", quote); if (i == 0) /*empty string*/ @@ -832,64 +884,64 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai } /* end else */ } break; + case H5T_INTEGER: if (sizeof(char) == nsize) { - /* if ((H5Tequal(type, H5T_NATIVE_SCHAR) || H5Tequal(type, H5T_NATIVE_UCHAR))) */ - if (info->ascii) { + if (info->ascii) h5tools_print_char(str, info, (char) (*ucp_vp)); - } else if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(type, H5T_NATIVE_UCHAR)) */ unsigned char tempuchar; + HDmemcpy(&tempuchar, ucp_vp, sizeof(unsigned char)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(unsigned char)) tempuchar = 0; else - tempuchar = (tempuchar >> packed_data_offset) & packed_data_mask; + tempuchar = (unsigned char)((unsigned long long)(tempuchar >> packed_data_offset) & packed_data_mask); } - h5tools_str_append(str, OPT(info->fmt_uchar, "%u"), tempuchar); + h5tools_str_append(str, OPT(info->fmt_uchar, "%hhu"), tempuchar); } else { - /* if (H5Tequal(type, H5T_NATIVE_SCHAR)) */ signed char tempchar; + HDmemcpy(&tempchar, cp_vp, sizeof(char)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(char)) tempchar = 0; else - tempchar = (tempchar >> packed_data_offset) & packed_data_mask; + tempchar = (signed char)((unsigned long long)(tempchar >> packed_data_offset) & packed_data_mask); } h5tools_str_append(str, OPT(info->fmt_schar, "%hhd"), tempchar); } } /* end if (sizeof(char) == nsize) */ else if (sizeof(int) == nsize) { if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(type, H5T_NATIVE_UINT)) */ + unsigned int tempuint; + HDmemcpy(&tempuint, vp, sizeof(unsigned int)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(unsigned int)) tempuint = 0; else - tempuint = (tempuint >> packed_data_offset) & packed_data_mask; + tempuint = (unsigned)((tempuint >> packed_data_offset) & packed_data_mask); } h5tools_str_append(str, OPT(info->fmt_uint, "%u"), tempuint); } else { - /* if (H5Tequal(type, H5T_NATIVE_INT)) */ + int tempint; + HDmemcpy(&tempint, vp, sizeof(int)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(int)) tempint = 0; else - tempint = (tempint >> packed_data_offset) & packed_data_mask; + tempint = (int)((unsigned long long)(tempint >> packed_data_offset) & packed_data_mask); } h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint); } } /* end if (sizeof(int) == nsize) */ else if (sizeof(short) == nsize) { if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(type, H5T_NATIVE_USHORT)) */ unsigned short tempushort; HDmemcpy(&tempushort, vp, sizeof(unsigned short)); @@ -897,12 +949,11 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai if (packed_data_offset >= 8 * sizeof(unsigned short)) tempushort = 0; else - tempushort = (tempushort >> packed_data_offset) & packed_data_mask; + tempushort = (unsigned short)((unsigned long long)(tempushort >> packed_data_offset) & packed_data_mask); } - h5tools_str_append(str, OPT(info->fmt_ushort, "%u"), tempushort); + h5tools_str_append(str, OPT(info->fmt_ushort, "%hu"), tempushort); } else { - /* if (H5Tequal(type, H5T_NATIVE_SHORT)) */ short tempshort; HDmemcpy(&tempshort, vp, sizeof(short)); @@ -910,14 +961,15 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai if (packed_data_offset >= 8 * sizeof(short)) tempshort = 0; else - tempshort = (tempshort >> packed_data_offset) & packed_data_mask; + tempshort = (short)((unsigned long long)(tempshort >> packed_data_offset) & packed_data_mask); } - h5tools_str_append(str, OPT(info->fmt_short, "%d"), tempshort); + h5tools_str_append(str, OPT(info->fmt_short, "%hd"), tempshort); } } /* end if (sizeof(short) == nsize) */ else if (sizeof(long) == nsize) { if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(type, H5T_NATIVE_ULONG)) */ + unsigned long tempulong; + HDmemcpy(&tempulong, vp, sizeof(unsigned long)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(unsigned long)) @@ -928,20 +980,23 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai h5tools_str_append(str, OPT(info->fmt_ulong, "%lu"), tempulong); } else { - /* if (H5Tequal(type, H5T_NATIVE_LONG)) */ + long templong; + HDmemcpy(&templong, vp, sizeof(long)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(long)) templong = 0; else - templong = (templong >> packed_data_offset) & packed_data_mask; + templong = (long)((unsigned long long)(templong >> packed_data_offset) & packed_data_mask); } h5tools_str_append(str, OPT(info->fmt_long, "%ld"), templong); } } /* end if (sizeof(long) == nsize) */ +#if H5_SIZEOF_LONG != H5_SIZEOF_LONG_LONG else if (sizeof(long long) == nsize) { if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(type, H5T_NATIVE_ULLONG)) */ + unsigned long long tempullong; + HDmemcpy(&tempullong, vp, sizeof(unsigned long long)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(unsigned long long)) @@ -952,7 +1007,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai h5tools_str_append(str, OPT(info->fmt_ullong, fmt_ullong), tempullong); } else { - /* if (H5Tequal(type, H5T_NATIVE_LLONG)) */ + long long templlong; + HDmemcpy(&templlong, vp, sizeof(long long)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(long long)) @@ -963,12 +1019,15 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai h5tools_str_append(str, OPT(info->fmt_llong, fmt_llong), templlong); } } /* end if (sizeof(long long) == nsize) */ +#endif /* H5_SIZEOF_LONG != H5_SIZEOF_LONG_LONG */ break; + case H5T_COMPOUND: { + unsigned nmembs; unsigned j; - nmembs = H5Tget_nmembers(type); + nmembs = (unsigned)H5Tget_nmembers(type); h5tools_str_append(str, "%s", OPT(info->cmpd_pre, "{")); ctx->indent_level++; @@ -979,7 +1038,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai else h5tools_str_append(str, "%s", OPT(info->cmpd_end, "")); - if (info->arr_linebreak) h5tools_str_indent(str, info, ctx); + if (info->arr_linebreak) + h5tools_str_indent(str, info, ctx); /* The name */ name = H5Tget_member_name(type, j); @@ -1001,9 +1061,9 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai h5tools_str_indent(str, info, ctx); } h5tools_str_append(str, "%s", OPT(info->cmpd_suf, "}")); - } break; + case H5T_ENUM: { char enum_name[1024]; @@ -1023,10 +1083,10 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai } } break; + case H5T_REFERENCE: - if (h5tools_str_is_zero(vp, nsize)) { + if (h5tools_str_is_zero(vp, nsize)) h5tools_str_append(str, "NULL"); - } else { if (nsize == H5R_DSET_REG_REF_BUF_SIZE) { /* if (H5Tequal(type, H5T_STD_REF_DSETREG)) */ @@ -1082,6 +1142,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai } /* end else if (H5Tequal(type, H5T_STD_REF_OBJ)) */ } break; + case H5T_ARRAY: { int k, ndims; @@ -1108,7 +1169,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai ctx->indent_level++; for (i = 0; i < nelmts; i++) { - if (i) h5tools_str_append(str, "%s", OPT(info->arr_sep, "," OPTIONAL_LINE_BREAK)); + if (i) + h5tools_str_append(str, "%s", OPT(info->arr_sep, "," OPTIONAL_LINE_BREAK)); if (info->arr_linebreak && i && i % dims[ndims - 1] == 0) { h5tools_str_append(str, "%s", "\n"); @@ -1143,6 +1205,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai H5Tclose(memb); } break; + case H5T_VLEN: { unsigned int i; @@ -1244,9 +1307,9 @@ h5tools_str_sprint_region(h5tools_str_t *str, const h5tool_format_t *info, region_type = H5Sget_select_type(region); if(region_type==H5S_SEL_POINTS) - h5tools_str_dump_region_points(str, region, info); + h5tools_str_dump_space_points(str, region, info); else - h5tools_str_dump_region_blocks(str, region, info); + h5tools_str_dump_space_blocks(str, region, info); h5tools_str_append(str, "}"); @@ -1392,31 +1455,33 @@ h5tools_str_is_zero(const void *_mem, size_t size) char * h5tools_str_replace ( const char *string, const char *substr, const char *replacement ) { - char *tok = NULL; - char *newstr = NULL; - char *oldstr = NULL; - char *head = NULL; - - if ( substr == NULL || replacement == NULL ) - return HDstrdup (string); - newstr = HDstrdup (string); - head = newstr; - while ( (tok = HDstrstr ( head, substr ))){ - oldstr = newstr; - newstr = (char *)HDmalloc( HDstrlen( oldstr ) - HDstrlen( substr ) + HDstrlen( replacement ) + 1 ); - - if ( newstr == NULL ){ - HDfree (oldstr); - return NULL; + char *tok = NULL; + char *newstr = NULL; + char *head = NULL; + + if(substr == NULL || replacement == NULL) + return HDstrdup(string); + newstr = HDstrdup(string); + head = newstr; + while((tok = HDstrstr(head, substr))) { + char *oldstr; + + oldstr = newstr; + newstr = (char *)HDmalloc(HDstrlen(oldstr) - HDstrlen(substr) + HDstrlen(replacement) + 1); + + if(newstr == NULL) { + HDfree(oldstr); + return NULL; } - HDmemcpy ( newstr, oldstr, tok - oldstr ); - HDmemcpy ( newstr + (tok - oldstr), replacement, HDstrlen ( replacement ) ); - HDmemcpy ( newstr + (tok - oldstr) + HDstrlen( replacement ), tok + HDstrlen ( substr ), HDstrlen ( oldstr ) - HDstrlen ( substr ) - ( tok - oldstr ) ); - HDmemset ( newstr + HDstrlen ( oldstr ) - HDstrlen ( substr ) + HDstrlen ( replacement ) , 0, 1 ); + HDmemcpy(newstr, oldstr, (size_t)(tok - oldstr)); + HDmemcpy(newstr + (tok - oldstr), replacement, HDstrlen(replacement)); + HDmemcpy(newstr + (tok - oldstr) + HDstrlen(replacement), tok + HDstrlen(substr), HDstrlen(oldstr) - HDstrlen(substr) - (size_t)(tok - oldstr)); + HDmemset(newstr + HDstrlen (oldstr) - HDstrlen(substr) + HDstrlen(replacement) , 0, 1); /* move back head right after the last replacement */ - head = newstr + (tok - oldstr) + HDstrlen( replacement ); - HDfree (oldstr); + head = newstr + (tok - oldstr) + HDstrlen(replacement); + HDfree(oldstr); } return newstr; } + diff --git a/tools/lib/h5tools_str.h b/tools/lib/h5tools_str.h index 38697c6..6173b89 100644 --- a/tools/lib/h5tools_str.h +++ b/tools/lib/h5tools_str.h @@ -40,8 +40,9 @@ H5TOOLS_DLL char *h5tools_str_prefix(h5tools_str_t *str, const h5tool_format_ H5TOOLS_DLL char *h5tools_str_region_prefix(h5tools_str_t *str, const h5tool_format_t *info, hsize_t elmtno, hsize_t *ptdata, unsigned ndims, hsize_t max_idx[], h5tools_context_t *ctx); -H5TOOLS_DLL void h5tools_str_dump_region_blocks(h5tools_str_t *, hid_t, const h5tool_format_t *); -H5TOOLS_DLL void h5tools_str_dump_region_points(h5tools_str_t *, hid_t, const h5tool_format_t *); +H5TOOLS_DLL void h5tools_str_dump_space_slabs(h5tools_str_t *, hid_t, const h5tool_format_t *, h5tools_context_t *ctx); +H5TOOLS_DLL void h5tools_str_dump_space_blocks(h5tools_str_t *, hid_t, const h5tool_format_t *); +H5TOOLS_DLL void h5tools_str_dump_space_points(h5tools_str_t *, hid_t, const h5tool_format_t *); H5TOOLS_DLL void h5tools_str_sprint_region(h5tools_str_t *str, const h5tool_format_t *info, hid_t container, void *vp); H5TOOLS_DLL char *h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, diff --git a/tools/lib/h5tools_type.c b/tools/lib/h5tools_type.c index d68d3c5..8a56d29 100644 --- a/tools/lib/h5tools_type.c +++ b/tools/lib/h5tools_type.c @@ -13,6 +13,7 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +#include "H5private.h" #include "h5tools.h" /*------------------------------------------------------------------------- @@ -75,54 +76,54 @@ h5tools_get_little_endian_type(hid_t tid) size = H5Tget_size(tid); sign = H5Tget_sign(tid); - switch( type_class ) - { - case H5T_INTEGER: - { - if ( size == 1 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I8LE); - else if ( size == 2 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I16LE); - else if ( size == 4 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I32LE); - else if ( size == 8 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I64LE); - else if ( size == 1 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U8LE); - else if ( size == 2 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U16LE); - else if ( size == 4 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U32LE); - else if ( size == 8 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U64LE); - } - break; - - case H5T_FLOAT: - if ( size == 4) - p_type=H5Tcopy(H5T_IEEE_F32LE); - else if ( size == 8) - p_type=H5Tcopy(H5T_IEEE_F64LE); - break; - - case H5T_TIME: - case H5T_BITFIELD: - case H5T_OPAQUE: - case H5T_STRING: - case H5T_COMPOUND: - case H5T_REFERENCE: - case H5T_ENUM: - case H5T_VLEN: - case H5T_ARRAY: - break; - - default: - break; - - } - - return(p_type); -} + switch(type_class) { + case H5T_INTEGER: + if ( size == 1 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I8LE); + else if ( size == 2 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I16LE); + else if ( size == 4 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I32LE); + else if ( size == 8 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I64LE); + else if ( size == 1 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U8LE); + else if ( size == 2 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U16LE); + else if ( size == 4 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U32LE); + else if ( size == 8 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U64LE); + break; + + case H5T_FLOAT: + if ( size == 4) + p_type=H5Tcopy(H5T_IEEE_F32LE); + else if ( size == 8) + p_type=H5Tcopy(H5T_IEEE_F64LE); + break; + + case H5T_TIME: + case H5T_BITFIELD: + case H5T_OPAQUE: + case H5T_STRING: + case H5T_COMPOUND: + case H5T_REFERENCE: + case H5T_ENUM: + case H5T_VLEN: + case H5T_ARRAY: + break; + + case H5T_NO_CLASS: + case H5T_NCLASSES: + default: + HDassert(0); + break; + + } /* end switch */ + + return p_type; +} /* end h5tools_get_little_endian_type() */ /*------------------------------------------------------------------------- @@ -152,53 +153,51 @@ h5tools_get_big_endian_type(hid_t tid) size = H5Tget_size(tid); sign = H5Tget_sign(tid); - switch( type_class ) - { - case H5T_INTEGER: - { - if ( size == 1 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I8BE); - else if ( size == 2 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I16BE); - else if ( size == 4 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I32BE); - else if ( size == 8 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I64BE); - else if ( size == 1 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U8BE); - else if ( size == 2 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U16BE); - else if ( size == 4 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U32BE); - else if ( size == 8 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U64BE); - } - break; - - case H5T_FLOAT: - if ( size == 4) - p_type=H5Tcopy(H5T_IEEE_F32BE); - else if ( size == 8) - p_type=H5Tcopy(H5T_IEEE_F64BE); - break; - - case H5T_TIME: - case H5T_BITFIELD: - case H5T_OPAQUE: - case H5T_STRING: - case H5T_COMPOUND: - case H5T_REFERENCE: - case H5T_ENUM: - case H5T_VLEN: - case H5T_ARRAY: - break; - - default: - break; - - } - - - return(p_type); -} + switch(type_class) { + case H5T_INTEGER: + if ( size == 1 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I8BE); + else if ( size == 2 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I16BE); + else if ( size == 4 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I32BE); + else if ( size == 8 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I64BE); + else if ( size == 1 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U8BE); + else if ( size == 2 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U16BE); + else if ( size == 4 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U32BE); + else if ( size == 8 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U64BE); + break; + + case H5T_FLOAT: + if ( size == 4) + p_type=H5Tcopy(H5T_IEEE_F32BE); + else if ( size == 8) + p_type=H5Tcopy(H5T_IEEE_F64BE); + break; + + case H5T_TIME: + case H5T_BITFIELD: + case H5T_OPAQUE: + case H5T_STRING: + case H5T_COMPOUND: + case H5T_REFERENCE: + case H5T_ENUM: + case H5T_VLEN: + case H5T_ARRAY: + break; + + case H5T_NO_CLASS: + case H5T_NCLASSES: + default: + HDassert(0); + break; + } /* end switch */ + + return p_type; +} /* end h5tools_get_big_endian_type() */ diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index b87abf6..e19926b 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -34,7 +34,7 @@ #include "h5trav.h" /* global variables */ -int h5tools_nCols = 80; +unsigned h5tools_nCols = 80; /* ``get_option'' variables */ int opt_err = 1; /*get_option prints errors if this is on */ int opt_ind = 1; /*token pointer */ @@ -57,7 +57,7 @@ hsize_t H5TOOLS_BUFSIZE = ( 32 * 1024 * 1024); /* 32 MB */ /* ``parallel_print'' variables */ unsigned char g_Parallel = 0; /*0 for serial, 1 for parallel */ char outBuff[OUTBUFF_SIZE]; -int outBuffOffset; +unsigned outBuffOffset; FILE* overflow_file = NULL; /* local functions */ @@ -89,11 +89,11 @@ void parallel_print(const char* format, ...) HDvprintf(format, ap); else { if(overflow_file == NULL) /*no overflow has occurred yet */ { - bytes_written = HDvsnprintf(outBuff+outBuffOffset, OUTBUFF_SIZE-outBuffOffset, format, ap); + bytes_written = HDvsnprintf(outBuff + outBuffOffset, OUTBUFF_SIZE - outBuffOffset, format, ap); HDva_end(ap); HDva_start(ap, format); - if((bytes_written < 0) || (bytes_written >= (OUTBUFF_SIZE - outBuffOffset))) { + if((bytes_written < 0) || ((unsigned)bytes_written >= (OUTBUFF_SIZE - outBuffOffset))) { /* Terminate the outbuff at the end of the previous output */ outBuff[outBuffOffset] = '\0'; @@ -104,7 +104,7 @@ void parallel_print(const char* format, ...) bytes_written = HDvfprintf(overflow_file, format, ap); } else - outBuffOffset += bytes_written; + outBuffOffset += (unsigned)bytes_written; } else bytes_written = HDvfprintf(overflow_file, format, ap); @@ -376,7 +376,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti *------------------------------------------------------------------------- */ void -indentation(int x) +indentation(unsigned x) { if (x < h5tools_nCols) { while (x-- > 0) @@ -408,7 +408,7 @@ print_version(const char *progname) { PRINTSTREAM(rawoutstream, "%s: Version %u.%u.%u%s%s\n", progname, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE, - ((char *)H5_VERS_SUBRELEASE)[0] ? "-" : "", H5_VERS_SUBRELEASE); + ((const char *)H5_VERS_SUBRELEASE)[0] ? "-" : "", H5_VERS_SUBRELEASE); } @@ -680,7 +680,7 @@ init_objs(hid_t fid, find_objs_t *info, table_t **group_table, static void add_obj(table_t *table, haddr_t objno, const char *objname, hbool_t record) { - unsigned u; + size_t u; /* See if we need to make table larger */ if(table->nobjs == table->size) { @@ -912,7 +912,6 @@ int h5tools_getenv_update_hyperslab_bufsize(void) hyperslab_bufsize_mb = HDstrtol(env_str, (char**)NULL, 10); if (errno != 0 || hyperslab_bufsize_mb <= 0) { - /* TODO: later when pubilshed HDfprintf(rawerrorstream,"Error: Invalid environment variable \"H5TOOLS_BUFSIZE\" : %s\n", env_str); */ @@ -922,13 +921,14 @@ int h5tools_getenv_update_hyperslab_bufsize(void) /* convert MB to byte */ - H5TOOLS_BUFSIZE = hyperslab_bufsize_mb * 1024 * 1024; + H5TOOLS_BUFSIZE = (hsize_t)hyperslab_bufsize_mb * 1024 * 1024; H5TOOLS_MALLOCSIZE = MAX(H5TOOLS_BUFSIZE, H5TOOLS_MALLOCSIZE); } - return (1); + error: return (-1); } + diff --git a/tools/lib/h5tools_utils.h b/tools/lib/h5tools_utils.h index 3285278..f7ab65b 100644 --- a/tools/lib/h5tools_utils.h +++ b/tools/lib/h5tools_utils.h @@ -35,7 +35,7 @@ extern "C" { H5TOOLS_DLLVAR int g_nTasks; H5TOOLS_DLLVAR unsigned char g_Parallel; H5TOOLS_DLLVAR char outBuff[]; -H5TOOLS_DLLVAR int outBuffOffset; +H5TOOLS_DLLVAR unsigned outBuffOffset; H5TOOLS_DLLVAR FILE * overflow_file; /* Maximum size used in a call to malloc for a dataset */ @@ -119,10 +119,10 @@ typedef struct find_objs_t { table_t *dset_table; } find_objs_t; -H5TOOLS_DLLVAR int h5tools_nCols; /*max number of columns for outputting */ +H5TOOLS_DLLVAR unsigned h5tools_nCols; /*max number of columns for outputting */ /* Definitions of useful routines */ -H5TOOLS_DLL void indentation(int); +H5TOOLS_DLL void indentation(unsigned); H5TOOLS_DLL void print_version(const char *progname); H5TOOLS_DLL void parallel_print(const char* format, ... ); H5TOOLS_DLL void error_msg(const char *fmt, ...); |