From 2f6e3cb5bee1abac0be573123439938cb5d3096e Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 19 Aug 2010 14:55:48 -0500 Subject: [svn-r19252] Description: Bring Coverity changes from branch to trunk: r19161: Fixed the part for matching the subset info with dataset r19189: BZ1646: h5dump does not check number of dimensions for subsetting parameters against the dataset Changed subset_t structure from holding hsize_t pointers to holding new subset_d pointers, which hold the original hsize_t pointer + len. this len is then checked against dataset ndims in the handle_dataset function of h5dump. Changed all references to use new data structure. Added tests for each subset parameter. r19190: Added new h5dump ddl files Tested on: Mac OS X/32 10.6.4 (amazon) w/debug & production (h5committested on branch) --- tools/h5dump/h5dump.c | 244 +++++++++++++++++------------------ tools/h5dump/testh5dump.sh.in | 11 ++ tools/h5jam/tellub.c | 2 +- tools/lib/h5diff.h | 1 - tools/lib/h5diff_util.c | 70 ---------- tools/lib/h5tools.c | 35 +++-- tools/lib/h5tools.h | 13 +- tools/lib/h5tools_utils.c | 80 +++++++++++- tools/lib/h5tools_utils.h | 5 + tools/lib/ph5diff.h | 2 - tools/testfiles/tbinregR.txt | 15 +++ tools/testfiles/texceedsubblock.ddl | 3 + tools/testfiles/texceedsubcount.ddl | 3 + tools/testfiles/texceedsubstart.ddl | 3 + tools/testfiles/texceedsubstride.ddl | 3 + 15 files changed, 267 insertions(+), 223 deletions(-) create mode 100644 tools/testfiles/tbinregR.txt create mode 100644 tools/testfiles/texceedsubblock.ddl create mode 100644 tools/testfiles/texceedsubcount.ddl create mode 100644 tools/testfiles/texceedsubstart.ddl create mode 100644 tools/testfiles/texceedsubstride.ddl diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 4abc0b0..261fe15 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -1607,8 +1607,7 @@ dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void UNUSED begin_obj(dump_header_format->datasetbegin, name, dump_header_format->datasetblockbegin); indentation(indent + COL); - error_msg(h5tools_getprogname(), - "internal error (file %s:line %d)\n", + error_msg("internal error (file %s:line %d)\n", __FILE__, __LINE__); indentation(indent); end_obj(dump_header_format->datasetend, @@ -2116,8 +2115,7 @@ dump_group(hid_t gid, const char *name) if (found_obj == NULL) { indentation(indent); - error_msg("internal error (file %s:line %d)\n", - __FILE__, __LINE__); + error_msg("internal error (file %s:line %d)\n", __FILE__, __LINE__); h5tools_setstatus(EXIT_FAILURE); } else if (found_obj->displayed) { @@ -2354,14 +2352,14 @@ dump_subsetting_header(struct subset_t *sset, int dims) indentation(indent); printf("%s %s ", dump_header_format->startbegin, dump_header_format->startblockbegin); - dump_dims((hsize_t *)sset->start, dims); + dump_dims(sset->start.data, dims); printf("%s %s\n", dump_header_format->startend, dump_header_format->startblockend); indentation(indent); printf("%s %s ", dump_header_format->stridebegin, dump_header_format->strideblockbegin); - dump_dims(sset->stride, dims); + dump_dims(sset->stride.data, dims); printf("%s %s\n", dump_header_format->strideend, dump_header_format->strideblockend); @@ -2369,8 +2367,8 @@ dump_subsetting_header(struct subset_t *sset, int dims) printf("%s %s ", dump_header_format->countbegin, dump_header_format->countblockbegin); - if (sset->count) - dump_dims(sset->count, dims); + if(sset->count.data) + dump_dims(sset->count.data, dims); else printf("DEFAULT"); @@ -2381,8 +2379,8 @@ dump_subsetting_header(struct subset_t *sset, int dims) printf("%s %s ", dump_header_format->blockbegin, dump_header_format->blockblockbegin); - if (sset->block) - dump_dims(sset->block, dims); + if(sset->block.data) + dump_dims(sset->block.data, dims); else printf("DEFAULT"); @@ -3418,25 +3416,22 @@ handle_attributes(hid_t fid, const char *attr, void UNUSED * data, int UNUSED pe * semicolons (;). The lists themselves can be separated by * either commas (,) or white spaces. * - * Return: Success: hsize_t array. NULL is a valid return type if - * there aren't any elements in the array. + * Return: * * Programmer: Bill Wendling * Tuesday, 6. February 2001 * - * Modifications: - * *------------------------------------------------------------------------- */ -static hsize_t * -parse_hsize_list(const char *h_list) +static void +parse_hsize_list(const char *h_list, subset_d *d) { hsize_t *p_list; const char *ptr; unsigned int size_count = 0, i = 0, last_digit = 0; if (!h_list || !*h_list || *h_list == ';') - return NULL; + return; /* count how many integers do we have */ for (ptr = h_list; ptr && *ptr && *ptr != ';' && *ptr != ']'; ptr++) @@ -3452,10 +3447,10 @@ parse_hsize_list(const char *h_list) if (size_count == 0) /* there aren't any integers to read */ - return NULL; + return; /* allocate an array for the integers in the list */ - p_list = calloc(size_count, sizeof(hsize_t)); + p_list = (hsize_t *)calloc(size_count, sizeof(hsize_t)); for (ptr = h_list; i < size_count && ptr && *ptr && *ptr != ';' && *ptr != ']'; ptr++) if(isdigit(*ptr)) { @@ -3466,8 +3461,10 @@ parse_hsize_list(const char *h_list) /* scroll to end of integer */ ptr++; } - - return p_list; + d->data = p_list; + d->len = size_count; + + return; } /*------------------------------------------------------------------------- @@ -3499,8 +3496,8 @@ parse_subset_params(char *dset) if (brace > slash) { *brace++ = '\0'; - s = calloc(1, sizeof(struct subset_t)); - s->start = parse_hsize_list(brace); + s = (struct subset_t *)calloc(1, sizeof(struct subset_t)); + parse_hsize_list(brace, &s->start); while (*brace && *brace != ';') brace++; @@ -3508,7 +3505,7 @@ parse_subset_params(char *dset) if (*brace) brace++; - s->stride = parse_hsize_list(brace); + parse_hsize_list(brace, &s->stride); while (*brace && *brace != ';') brace++; @@ -3516,7 +3513,7 @@ parse_subset_params(char *dset) if (*brace) brace++; - s->count = parse_hsize_list(brace); + parse_hsize_list(brace, &s->count); while (*brace && *brace != ';') brace++; @@ -3524,7 +3521,7 @@ parse_subset_params(char *dset) if (*brace) brace++; - s->block = parse_hsize_list(brace); + parse_hsize_list(brace, &s->block); } } @@ -3576,79 +3573,83 @@ handle_datasets(hid_t fid, const char *dset, void *data, int pe, const char *dis } /* end if */ if(sset) { - if(!sset->start || !sset->stride || !sset->count || !sset->block) { + unsigned int i; + hid_t sid = H5Dget_space(dsetid); + unsigned int ndims = H5Sget_simple_extent_ndims(sid); + + H5Sclose(sid); + + if(!sset->start.data || !sset->stride.data || !sset->count.data || !sset->block.data) { /* they didn't specify a ``stride'' or ``block''. default to 1 in all * dimensions */ - hid_t sid = H5Dget_space(dsetid); - unsigned int ndims = H5Sget_simple_extent_ndims(sid); - - if(!sset->start) + if(!sset->start.data) { /* default to (0, 0, ...) for the start coord */ - sset->start = calloc(ndims, sizeof(hsize_t)); - - if(!sset->stride) { - unsigned int i; - - sset->stride = calloc(ndims, sizeof(hsize_t)); + sset->start.data = (hsize_t *)calloc(ndims, sizeof(hsize_t)); + sset->start.len = ndims; + } + if(!sset->stride.data) { + sset->stride.data = (hsize_t *)calloc(ndims, sizeof(hsize_t)); + sset->stride.len = ndims; for (i = 0; i < ndims; i++) - sset->stride[i] = 1; + sset->stride.data[i] = 1; } - if (!sset->count) { - unsigned int i; - - - sset->count = calloc(ndims, sizeof(hsize_t)); - + if(!sset->count.data) { + sset->count.data = (hsize_t *)calloc(ndims, sizeof(hsize_t)); + sset->count.len = ndims; for (i = 0; i < ndims; i++) - sset->count[i] = 1; + sset->count.data[i] = 1; } - if (!sset->block) { - unsigned int i; - - sset->block = calloc(ndims, sizeof(hsize_t)); - + if(!sset->block.data) { + sset->block.data = (hsize_t *)calloc(ndims, sizeof(hsize_t)); + sset->block.len = ndims; for (i = 0; i < ndims; i++) - sset->block[i] = 1; + sset->block.data[i] = 1; } - - H5Sclose(sid); } - } - - - /*------------------------------------------------------------------------- - * check for block overlap - *------------------------------------------------------------------------- - */ - - if(sset) - { - hid_t sid = H5Dget_space(dsetid); - unsigned int ndims = H5Sget_simple_extent_ndims(sid); - unsigned int i; - for ( i = 0; i < ndims; i++) - { - if ( sset->count[i] > 1 ) - { - - if ( sset->stride[i] < sset->block[i] ) - { + /*------------------------------------------------------------------------- + * check for dimension overflow + *------------------------------------------------------------------------- + */ + if(sset->start.len > ndims) { + error_msg("number of start dims (%u) exceed dataset dims (%u)\n", sset->start.len, ndims); + h5tools_setstatus(EXIT_FAILURE); + return; + } + if(sset->stride.len > ndims) { + error_msg("number of stride dims (%u) exceed dataset dims (%u)\n", sset->stride.len, ndims); + h5tools_setstatus(EXIT_FAILURE); + return; + } + if(sset->count.len > ndims) { + error_msg("number of count dims (%u) exceed dataset dims (%u)\n", sset->count.len, ndims); + h5tools_setstatus(EXIT_FAILURE); + return; + } + if(sset->block.len > ndims) { + error_msg("number of block dims (%u) exceed dataset dims (%u)\n", sset->block.len, ndims); + h5tools_setstatus(EXIT_FAILURE); + return; + } + + /*------------------------------------------------------------------------- + * check for block overlap + *------------------------------------------------------------------------- + */ + for(i = 0; i < ndims; i++) { + if(sset->count.data[i] > 1) { + if(sset->stride.data[i] < sset->block.data[i]) { error_msg("wrong subset selection; blocks overlap\n"); h5tools_setstatus(EXIT_FAILURE); return; + } /* end if */ + } /* end if */ + } /* end for */ + } /* end if */ - } - - } - - } - H5Sclose(sid); - - } H5Oget_info(dsetid, &oinfo); if(oinfo.rc > 1 || hit_elink) { @@ -3726,7 +3727,7 @@ handle_groups(hid_t fid, const char *group, void UNUSED * data, int pe, const ch if(prefix_len <= new_len) { prefix_len = new_len; - prefix = HDrealloc(prefix, prefix_len); + prefix = (char *)HDrealloc(prefix, prefix_len); } /* end if */ HDstrcpy(prefix, group); @@ -3764,7 +3765,7 @@ handle_links(hid_t fid, const char *links, void UNUSED * data, int UNUSED pe, co error_msg("\"%s\" is a hard link\n", links); h5tools_setstatus(EXIT_FAILURE); } else { - char *buf = HDmalloc(linfo.u.val_size); + char *buf = (char *)HDmalloc(linfo.u.val_size); switch(linfo.type) { case H5L_TYPE_SOFT: /* Soft link */ @@ -3938,7 +3939,7 @@ parse_command_line(int argc, const char *argv[]) } /* this will be plenty big enough to hold the info */ - hand = calloc((size_t)argc, sizeof(struct handler_t)); + hand = (struct handler_t *)calloc((size_t)argc, sizeof(struct handler_t)); /* parse command line options */ while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) { @@ -4010,7 +4011,7 @@ parse_start: hand[i].func = handle_datasets; hand[i].obj = HDstrdup(opt_arg); hand[i].subset_info = parse_subset_params(hand[i].obj); - last_dset = hand; + last_dset = &hand[i]; break; } @@ -4163,8 +4164,7 @@ parse_start: struct subset_t *s; if (!last_was_dset) { - error_msg(h5tools_getprogname(), - "option `-%c' can only be used after --dataset option\n", + error_msg("option `-%c' can only be used after --dataset option\n", opt); leave(EXIT_FAILURE); } @@ -4176,7 +4176,7 @@ parse_start: */ s = last_dset->subset_info; } else { - last_dset->subset_info = s = calloc(1, sizeof(struct subset_t)); + last_dset->subset_info = s = (struct subset_t *)calloc(1, sizeof(struct subset_t)); } /* @@ -4192,10 +4192,10 @@ parse_start: */ do { switch ((char)opt) { - case 's': free(s->start); s->start = parse_hsize_list(opt_arg); break; - case 'S': free(s->stride); s->stride = parse_hsize_list(opt_arg); break; - case 'c': free(s->count); s->count = parse_hsize_list(opt_arg); break; - case 'k': free(s->block); s->block = parse_hsize_list(opt_arg); break; + case 's': free(s->start.data); parse_hsize_list(opt_arg, &s->start); break; + case 'S': free(s->stride.data); parse_hsize_list(opt_arg, &s->stride); break; + case 'c': free(s->count.data); parse_hsize_list(opt_arg, &s->count); break; + case 'k': free(s->block.data); parse_hsize_list(opt_arg, &s->block); break; default: goto end_collect; } } while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF); @@ -4256,10 +4256,10 @@ free_handler(struct handler_t *hand, int len) free(hand[i].obj); if (hand[i].subset_info) { - free(hand[i].subset_info->start); - free(hand[i].subset_info->stride); - free(hand[i].subset_info->count); - free(hand[i].subset_info->block); + free(hand[i].subset_info->start.data); + free(hand[i].subset_info->stride.data); + free(hand[i].subset_info->count.data); + free(hand[i].subset_info->block.data); free(hand[i].subset_info); } } @@ -4588,8 +4588,8 @@ print_enum(hid_t type) dst_size = H5Tget_size(type); /* Get the names and raw values of all members */ - name = calloc(nmembs, sizeof(char *)); - value = calloc(nmembs, MAX(H5Tget_size(type), dst_size)); + name = (char **)calloc(nmembs, sizeof(char *)); + value = (unsigned char *)calloc(nmembs, MAX(H5Tget_size(type), dst_size)); for (i = 0; i < nmembs; i++) { name[i] = H5Tget_member_name(type, i); @@ -4749,7 +4749,7 @@ xml_escape_the_name(const char *str) return HDstrdup(str); cp = str; - rcp = ncp = HDmalloc(len + extra + 1); + rcp = ncp = (char *)HDmalloc(len + extra + 1); if (!ncp) return NULL; /* ?? */ @@ -4838,7 +4838,7 @@ xml_escape_the_string(const char *str, int slen) } cp = str; - rcp = ncp = calloc((len + extra + 1), sizeof(char)); + rcp = ncp = (char *)calloc((len + extra + 1), sizeof(char)); if (ncp == NULL) return NULL; /* ?? */ @@ -4930,7 +4930,7 @@ xml_print_datatype(hid_t type, unsigned in_group) /* This should be defined somewhere else */ /* These 2 cases are handled the same right now, but probably will have something different eventually */ - char * dtxid = malloc(100); + char * dtxid = (char *)malloc(100); xml_name_to_XID(found_obj->objname, dtxid, 100, 1); if (!found_obj->recorded) { @@ -5290,7 +5290,7 @@ xml_dump_datatype(hid_t type) if(found_obj) { /* Shared datatype, must be entered as an object */ /* These 2 cases are the same now, but may change */ - char * dtxid = malloc(100); + char * dtxid = (char *)malloc(100); xml_name_to_XID(found_obj->objname, dtxid, 100, 1); if (!found_obj->recorded) { @@ -5669,14 +5669,14 @@ xml_dump_named_datatype(hid_t type, const char *name) char *t_prefix; char *t_name; - tmp = HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2); + tmp = (char *)HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2); HDstrcpy(tmp, prefix); HDstrcat(tmp, "/"); HDstrcat(tmp, name); indentation(indent); - dtxid = HDmalloc(100); - parentxid = HDmalloc(100); + dtxid = (char *)HDmalloc(100); + parentxid = (char *)HDmalloc(100); t_tmp = xml_escape_the_name(tmp); t_prefix = xml_escape_the_name(prefix); t_name = xml_escape_the_name(name); @@ -5824,7 +5824,7 @@ xml_dump_group(hid_t gid, const char *name) isRoot = 1; tmp = HDstrdup("/"); } else { - tmp = HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2); + tmp = (char *)HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2); HDstrcpy(tmp, prefix); par = HDstrdup(tmp); cp = HDstrrchr(par, '/'); @@ -5854,11 +5854,11 @@ xml_dump_group(hid_t gid, const char *name) h5tools_setstatus(EXIT_FAILURE); } else { char *t_name = xml_escape_the_name(name); - char *grpxid = malloc(100); - char *parentxid = malloc(100); + char *grpxid = (char *)malloc(100); + char *parentxid = (char *)malloc(100); if(found_obj->displayed) { - char *ptrstr = malloc(100); + char *ptrstr = (char *)malloc(100); /* already seen: enter a groupptr */ if(isRoot) { @@ -5960,8 +5960,8 @@ xml_dump_group(hid_t gid, const char *name) /* only link -- must be first time! */ char *t_name = xml_escape_the_name(name); - char *grpxid = malloc(100); - char *parentxid = malloc(100); + char *grpxid = (char *)malloc(100); + char *parentxid = (char *)malloc(100); if(isRoot) { xml_name_to_XID("/", grpxid, 100, 1); @@ -6078,7 +6078,7 @@ xml_print_refs(hid_t did, int source) ssiz = H5Sget_simple_extent_npoints(space); ssiz *= H5Tget_size(type); - buf = calloc((size_t)ssiz, sizeof(char)); + buf = (char *)calloc((size_t)ssiz, sizeof(char)); if(buf == NULL) return FAIL; e = H5Dread(did, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); @@ -6092,7 +6092,7 @@ xml_print_refs(hid_t did, int source) ssiz = H5Sget_simple_extent_npoints(space); ssiz *= H5Tget_size(type); - buf = calloc((size_t)ssiz, sizeof(char)); + buf = (char *)calloc((size_t)ssiz, sizeof(char)); if (buf == NULL) { free(buf); return FAIL; @@ -6213,7 +6213,7 @@ xml_print_strs(hid_t did, int source) tsiz = H5Tget_size(type); bp = (char*)buf; if(!is_vlstr) - onestring = (char *) calloc(tsiz, sizeof(char)); + onestring = (char *)calloc(tsiz, sizeof(char)); for (i = 0; i < ssiz; i++) { if(is_vlstr) { @@ -6486,10 +6486,10 @@ xml_dump_dataset(hid_t did, const char *name, struct subset_t UNUSED * sset) char *tmp; char *t_name, *t_tmp, *t_prefix; unsigned attr_crt_order_flags; - char *rstr = HDmalloc(100); - char *pstr = HDmalloc(100); + char *rstr = (char *)HDmalloc(100); + char *pstr = (char *)HDmalloc(100); - tmp = HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2); + tmp = (char *)HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2); HDstrcpy(tmp, prefix); HDstrcat(tmp, "/"); HDstrcat(tmp, name); @@ -6521,7 +6521,7 @@ xml_dump_dataset(hid_t did, const char *name, struct subset_t UNUSED * sset) /* Print information about storage layout */ if(H5D_CHUNKED == H5Pget_layout(dcpl)) { maxdims = H5Sget_simple_extent_ndims(space); - chsize = (hsize_t *) malloc(maxdims * sizeof(hsize_t)); + chsize = (hsize_t *)malloc(maxdims * sizeof(hsize_t)); indent += COL; indentation(indent); printf("<%sStorageLayout>\n",xmlnsprefix); @@ -6804,8 +6804,8 @@ xml_print_enum(hid_t type) } /* Get the names and raw values of all members */ - name = calloc(nmembs, sizeof(char *)); - value = calloc(nmembs, MAX(H5Tget_size(type), dst_size)); + name = (char **)calloc(nmembs, sizeof(char *)); + value = (unsigned char *)calloc(nmembs, MAX(H5Tget_size(type), dst_size)); for (i = 0; i < nmembs; i++) { name[i] = H5Tget_member_name(type, i); @@ -6989,7 +6989,7 @@ static void init_prefix(char **prfx, size_t prfx_len) { HDassert(prfx_len > 0); - *prfx = HDcalloc(prfx_len, 1); + *prfx = (char *)HDcalloc(prfx_len, 1); } @@ -7010,7 +7010,7 @@ add_prefix(char **prfx, size_t *prfx_len, const char *name) /* Check if we need more space */ if(*prfx_len <= new_len) { *prfx_len = new_len + 1; - *prfx = HDrealloc(*prfx, *prfx_len); + *prfx = (char *)HDrealloc(*prfx, *prfx_len); } /* Append object name to prefix */ diff --git a/tools/h5dump/testh5dump.sh.in b/tools/h5dump/testh5dump.sh.in index 78b7757..9c28ed9 100644 --- a/tools/h5dump/testh5dump.sh.in +++ b/tools/h5dump/testh5dump.sh.in @@ -421,6 +421,12 @@ TOOLTEST tindicessub3.ddl -d 3d -s 0,1,2 -S 1,3,3 -c 2,2,2 -k 1,2,2 taindices. # 4D case TOOLTEST tindicessub4.ddl -d 4d -s 0,0,1,2 -c 2,2,3,2 -S 1,1,3,3 -k 1,1,2,2 taindices.h5 +#Exceed the dimensions for subsetting +TOOLTEST1 texceedsubstart.ddl -d 1d -s 1,3 taindices.h5 +TOOLTEST1 texceedsubcount.ddl -d 1d -c 1,3 taindices.h5 +TOOLTEST1 texceedsubstride.ddl -d 1d -S 1,3 taindices.h5 +TOOLTEST1 texceedsubblock.ddl -d 1d -k 1,3 taindices.h5 + # tests for filters # SZIP @@ -528,6 +534,11 @@ TOOLTEST tattrregR.ddl -R tattrreg.h5 TOOLTEST2 tbinregR.exp -d /Dataset1 -s 0 -y -o $TESTDIR/tbinregR.txt tdatareg.h5 +# Clean up text output files +if test -z "$HDF5_NOCLEANUP"; then + rm -f $TESTDIR/tbinregR.txt +fi + # tests for group creation order # "1" tracked, "2" name, root tracked TOOLTEST tordergr1.ddl --group=1 --sort_by=creation_order --sort_order=ascending tordergr.h5 diff --git a/tools/h5jam/tellub.c b/tools/h5jam/tellub.c index 2cf30e2..f1b6756 100644 --- a/tools/h5jam/tellub.c +++ b/tools/h5jam/tellub.c @@ -104,7 +104,7 @@ parse_command_line (int argc, const char *argv[]) /* check for file name to be processed */ if (argc <= opt_ind) { - error_msg(h5tools_getprogname(), "missing file name\n"); + error_msg("missing file name\n"); usage (h5tools_getprogname()); exit (EXIT_FAILURE); } diff --git a/tools/lib/h5diff.h b/tools/lib/h5diff.h index ede6ea0..71993b8 100644 --- a/tools/lib/h5diff.h +++ b/tools/lib/h5diff.h @@ -154,7 +154,6 @@ hsize_t diff_attr(hid_t loc1_id, */ void print_found(hsize_t nfound); -void parallel_print(const char* format, ... ); void print_type(hid_t type); const char* diff_basename(const char *name); const char* get_type(h5trav_type_t type); diff --git a/tools/lib/h5diff_util.c b/tools/lib/h5diff_util.c index 721c3d7..5df94fa 100644 --- a/tools/lib/h5diff_util.c +++ b/tools/lib/h5diff_util.c @@ -21,76 +21,6 @@ /* global variables */ int g_nTasks = 1; -unsigned char g_Parallel = 0; /*0 for serial, 1 for parallel */ -char outBuff[OUTBUFF_SIZE]; -int outBuffOffset; -FILE* overflow_file = NULL; - -/*------------------------------------------------------------------------- - * Function: parallel_print - * - * Purpose: wrapper for printf for use in parallel mode. - * - * Programmer: Leon Arber - * - * Date: December 1, 2004 - * - *------------------------------------------------------------------------- - */ -void parallel_print(const char* format, ...) -{ - int bytes_written; - va_list ap; - - va_start(ap, format); - - if(!g_Parallel) - vprintf(format, ap); - else - { - - if(overflow_file == NULL) /*no overflow has occurred yet */ - { -#if 0 - printf("calling HDvsnprintf: OUTBUFF_SIZE=%ld, outBuffOffset=%ld, ", (long)OUTBUFF_SIZE, (long)outBuffOffset); -#endif - bytes_written = HDvsnprintf(outBuff+outBuffOffset, OUTBUFF_SIZE-outBuffOffset, format, ap); -#if 0 - printf("bytes_written=%ld\n", (long)bytes_written); -#endif - va_end(ap); - va_start(ap, format); - -#if 0 - printf("Result: bytes_written=%ld, OUTBUFF_SIZE-outBuffOffset=%ld\n", (long)bytes_written, (long)OUTBUFF_SIZE-outBuffOffset); -#endif - - if ((bytes_written < 0) || -#ifdef H5_VSNPRINTF_WORKS - (bytes_written >= (OUTBUFF_SIZE-outBuffOffset)) -#else - ((bytes_written+1) == (OUTBUFF_SIZE-outBuffOffset)) -#endif - ) - { - /* Terminate the outbuff at the end of the previous output */ - outBuff[outBuffOffset] = '\0'; - - overflow_file = HDtmpfile(); - if(overflow_file == NULL) - fprintf(stderr, "warning: could not create overflow file. Output may be truncated.\n"); - else - bytes_written = HDvfprintf(overflow_file, format, ap); - } - else - outBuffOffset += bytes_written; - } - else - bytes_written = HDvfprintf(overflow_file, format, ap); - - } - va_end(ap); -} /*------------------------------------------------------------------------- * Function: print_dimensions diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 60f5d01..3cfe56b 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -1985,7 +1985,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c if (ctx->ndims > 0) init_acc_pos(ctx, total_size); - size_row_block = sset->block[row_dim]; + size_row_block = sset->block.data[row_dim]; /* display loop */ for (; hyperslab_count > 0; temp_start[row_dim] += temp_stride[row_dim], hyperslab_count--) { @@ -1993,9 +1993,9 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c cases where block > 1 only and stride > block */ if (size_row_block > 1 && row_counter == size_row_block - && sset->stride[row_dim] > sset->block[row_dim]) { + && sset->stride.data[row_dim] > sset->block.data[row_dim]) { - hsize_t increase_rows = sset->stride[row_dim] - sset->block[row_dim]; + hsize_t increase_rows = sset->stride.data[row_dim] - sset->block.data[row_dim]; temp_start[row_dim] += increase_rows; row_counter = 0; } @@ -2153,22 +2153,22 @@ h5tools_display_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools if (ctx->ndims > 2) for (i = 0; i < (size_t) ctx->ndims - 2; i++) { /* consider block size */ - outer_count = outer_count * sset->count[i] * sset->block[i]; + outer_count = outer_count * sset->count.data[i] * sset->block.data[i]; } /* initialize temporary start, count and maximum start */ for (i = 0; i < (size_t) ctx->ndims; i++) { - temp_start[i] = sset->start[i]; - temp_count[i] = sset->count[i]; - temp_block[i] = sset->block[i]; - temp_stride[i] = sset->stride[i]; + temp_start[i] = sset->start.data[i]; + temp_count[i] = sset->count.data[i]; + temp_block[i] = sset->block.data[i]; + temp_stride[i] = sset->stride.data[i]; max_start[i] = 0; } if (ctx->ndims > 2) { for (i = 0; i < (size_t) ctx->ndims - 2; i++) { - max_start[i] = temp_start[i] + sset->count[i]; + max_start[i] = temp_start[i] + sset->count.data[i]; temp_count[i] = 1; } @@ -2181,14 +2181,14 @@ h5tools_display_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools /* count is the number of iterations to display all the rows, the block size count times */ - count = sset->count[row_dim] * sset->block[row_dim]; + count = sset->count.data[row_dim] * sset->block.data[row_dim]; /* always 1 row_counter at a time, that is a block of size 1, 1 time */ temp_count[row_dim] = 1; temp_block[row_dim] = 1; /* advance 1 row_counter at a time */ - if (sset->block[row_dim] > 1) + if (sset->block.data[row_dim] > 1) temp_stride[row_dim] = 1; } @@ -2207,7 +2207,7 @@ h5tools_display_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools /* set start to original from current_outer_dim up */ for (i = current_outer_dim + 1; i < ctx->ndims; i++) { - temp_start[i] = sset->start[i]; + temp_start[i] = sset->start.data[i]; } /* increment start dimension */ @@ -2215,10 +2215,10 @@ h5tools_display_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools reset_dim = 0; temp_start[current_outer_dim]++; if (temp_start[current_outer_dim] >= max_start[current_outer_dim]) { - temp_start[current_outer_dim] = sset->start[current_outer_dim]; + temp_start[current_outer_dim] = sset->start.data[current_outer_dim]; /* consider block */ - if (sset->block[current_outer_dim] > 1) + if (sset->block.data[current_outer_dim] > 1) temp_start[current_outer_dim]++; current_outer_dim--; @@ -2626,7 +2626,6 @@ h5tools_dump_dset(FILE *stream, const h5tool_format_t *info, hid_t dset, H5S_class_t space_type; int status = FAIL; h5tool_format_t info_dflt; - /* Use default values */ if (!stream) stream = stdout; @@ -2661,12 +2660,10 @@ h5tools_dump_dset(FILE *stream, const h5tool_format_t *info, hid_t dset, /* Print the data */ if (space_type == H5S_SIMPLE || space_type == H5S_SCALAR) { - if (!sset) { + if(!sset) status = h5tools_dump_simple_dset(stream, info, dset, p_type, indentlevel); - } - else { + else status = h5tools_dump_simple_subset(stream, info, dset, p_type, sset, indentlevel); - } } else /* space is H5S_NULL */ diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index ab72025..b3e3dd2 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -507,12 +507,17 @@ typedef struct h5tools_context_t { hsize_t sm_pos; /* current stripmine element position */ } h5tools_context_t; +typedef struct subset_d { + hsize_t *data; + unsigned int len; +} subset_d; + /* a structure to hold the subsetting particulars for a dataset */ struct subset_t { - hsize_t *start; - hsize_t *stride; - hsize_t *count; - hsize_t *block; + subset_d start; + subset_d stride; + subset_d count; + subset_d block; }; /* The following include, h5tools_str.h, must be after the diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index b226bd7..2e3c756 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -42,6 +42,12 @@ const char *opt_arg; /*flag argument (or value) */ static int h5tools_d_status = 0; static const char *h5tools_progname = "h5tools"; +/* ``parallel_print'' variables */ +unsigned char g_Parallel = 0; /*0 for serial, 1 for parallel */ +char outBuff[OUTBUFF_SIZE]; +int outBuffOffset; +FILE* overflow_file = NULL; + /* local functions */ static void init_table(table_t **tbl); #ifdef H5DUMP_DEBUG @@ -49,6 +55,72 @@ static void dump_table(char* tablename, table_t *table); #endif /* H5DUMP_DEBUG */ static void add_obj(table_t *table, haddr_t objno, const char *objname, hbool_t recorded); +/*------------------------------------------------------------------------- + * Function: parallel_print + * + * Purpose: wrapper for printf for use in parallel mode. + * + * Programmer: Leon Arber + * + * Date: December 1, 2004 + * + *------------------------------------------------------------------------- + */ +void parallel_print(const char* format, ...) +{ + int bytes_written; + va_list ap; + + va_start(ap, format); + + if(!g_Parallel) + vprintf(format, ap); + else + { + + if(overflow_file == NULL) /*no overflow has occurred yet */ + { +#if 0 + printf("calling HDvsnprintf: OUTBUFF_SIZE=%ld, outBuffOffset=%ld, ", (long)OUTBUFF_SIZE, (long)outBuffOffset); +#endif + bytes_written = HDvsnprintf(outBuff+outBuffOffset, OUTBUFF_SIZE-outBuffOffset, format, ap); +#if 0 + printf("bytes_written=%ld\n", (long)bytes_written); +#endif + va_end(ap); + va_start(ap, format); + +#if 0 + printf("Result: bytes_written=%ld, OUTBUFF_SIZE-outBuffOffset=%ld\n", (long)bytes_written, (long)OUTBUFF_SIZE-outBuffOffset); +#endif + + if ((bytes_written < 0) || +#ifdef H5_VSNPRINTF_WORKS + (bytes_written >= (OUTBUFF_SIZE-outBuffOffset)) +#else + ((bytes_written+1) == (OUTBUFF_SIZE-outBuffOffset)) +#endif + ) + { + /* Terminate the outbuff at the end of the previous output */ + outBuff[outBuffOffset] = '\0'; + + overflow_file = HDtmpfile(); + if(overflow_file == NULL) + fprintf(stderr, "warning: could not create overflow file. Output may be truncated.\n"); + else + bytes_written = HDvfprintf(overflow_file, format, ap); + } + else + outBuffOffset += bytes_written; + } + else + bytes_written = HDvfprintf(overflow_file, format, ap); + + } + va_end(ap); +} + /*------------------------------------------------------------------------- * Function: error_msg @@ -591,7 +663,7 @@ add_obj(table_t *table, haddr_t objno, const char *objname, hbool_t record) /* See if we need to make table larger */ if(table->nobjs == table->size) { table->size *= 2; - table->objs = HDrealloc(table->objs, table->size * sizeof(table->objs[0])); + table->objs = (struct obj_t *)HDrealloc(table->objs, table->size * sizeof(table->objs[0])); } /* end if */ /* Increment number of objects in table */ @@ -690,7 +762,7 @@ H5tools_get_link_info(hid_t file_id, const char * linkpath, h5tool_link_info_t * HDassert(link_info->trg_path); /* get link value */ - if(H5Lget_val(file_id, linkpath, link_info->trg_path, link_info->linfo.u.val_size, H5P_DEFAULT) < 0) { + if(H5Lget_val(file_id, linkpath, (void *)link_info->trg_path, link_info->linfo.u.val_size, H5P_DEFAULT) < 0) { if(link_info->opt.msg_mode == 1) parallel_print("Warning: unable to get link value from <%s>\n",linkpath); goto out; @@ -769,12 +841,12 @@ void h5tools_setstatus(int D_status) h5tools_d_status = D_status; } -const char*h5tools_getprogname() +const char*h5tools_getprogname(void) { return h5tools_progname; } -int h5tools_getstatus() +int h5tools_getstatus(void) { return h5tools_d_status; } diff --git a/tools/lib/h5tools_utils.h b/tools/lib/h5tools_utils.h index 14a7daa..82a5a02 100644 --- a/tools/lib/h5tools_utils.h +++ b/tools/lib/h5tools_utils.h @@ -28,6 +28,10 @@ extern "C" { #endif +/* ``parallel_print'' information */ +#define PRINT_DATA_MAX_SIZE 512 +#define OUTBUFF_SIZE (PRINT_DATA_MAX_SIZE*4) + /* * begin get_option section */ @@ -110,6 +114,7 @@ H5TOOLS_DLLVAR int nCols; /*max number of columns for outputti /* Definitions of useful routines */ H5TOOLS_DLL void indentation(int); H5TOOLS_DLL void print_version(const char *progname); +H5TOOLS_DLL void parallel_print(const char* format, ... ); H5TOOLS_DLL void error_msg(const char *fmt, ...); H5TOOLS_DLL void warn_msg(const char *fmt, ...); H5TOOLS_DLL void free_table(table_t *table); diff --git a/tools/lib/ph5diff.h b/tools/lib/ph5diff.h index 3ad158f..e48a643 100644 --- a/tools/lib/ph5diff.h +++ b/tools/lib/ph5diff.h @@ -16,8 +16,6 @@ #ifndef _PH5DIFF_H__ #define _PH5DIFF_H__ -#define PRINT_DATA_MAX_SIZE 512 -#define OUTBUFF_SIZE (PRINT_DATA_MAX_SIZE*4) /* Send from manager to workers */ #define MPI_TAG_ARGS 1 #define MPI_TAG_PRINT_TOK 2 diff --git a/tools/testfiles/tbinregR.txt b/tools/testfiles/tbinregR.txt new file mode 100644 index 0000000..f4c38a1 --- /dev/null +++ b/tools/testfiles/tbinregR.txt @@ -0,0 +1,15 @@ +HDF5 "tdatareg.h5" { +DATASET "/Dataset1" { + DATATYPE H5T_REFERENCE + DATASPACE SIMPLE { ( 4 ) / ( 4 ) } + SUBSET { + START ( 0 ); + STRIDE ( 1 ); + COUNT ( 1 ); + BLOCK ( 1 ); + DATA { + + } + } +} +} diff --git a/tools/testfiles/texceedsubblock.ddl b/tools/testfiles/texceedsubblock.ddl new file mode 100644 index 0000000..499e0d2 --- /dev/null +++ b/tools/testfiles/texceedsubblock.ddl @@ -0,0 +1,3 @@ +HDF5 "taindices.h5" { +} +h5dump error: number of block dims (2) exceed dataset dims (1) diff --git a/tools/testfiles/texceedsubcount.ddl b/tools/testfiles/texceedsubcount.ddl new file mode 100644 index 0000000..81e8c4a --- /dev/null +++ b/tools/testfiles/texceedsubcount.ddl @@ -0,0 +1,3 @@ +HDF5 "taindices.h5" { +} +h5dump error: number of count dims (2) exceed dataset dims (1) diff --git a/tools/testfiles/texceedsubstart.ddl b/tools/testfiles/texceedsubstart.ddl new file mode 100644 index 0000000..cb535a0 --- /dev/null +++ b/tools/testfiles/texceedsubstart.ddl @@ -0,0 +1,3 @@ +HDF5 "taindices.h5" { +} +h5dump error: number of start dims (2) exceed dataset dims (1) diff --git a/tools/testfiles/texceedsubstride.ddl b/tools/testfiles/texceedsubstride.ddl new file mode 100644 index 0000000..bf85997 --- /dev/null +++ b/tools/testfiles/texceedsubstride.ddl @@ -0,0 +1,3 @@ +HDF5 "taindices.h5" { +} +h5dump error: number of stride dims (2) exceed dataset dims (1) -- cgit v0.12