diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2003-11-13 15:20:23 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2003-11-13 15:20:23 (GMT) |
commit | 898ba82d42aa46cbca59fca31f47d5bce3e8dd72 (patch) | |
tree | 33a1c536ed8ed4a1654bf898ccca4622f9547aaf /tools | |
parent | dd241064c18efe59768cc5b495fe78b2a779b058 (diff) | |
download | hdf5-898ba82d42aa46cbca59fca31f47d5bce3e8dd72.zip hdf5-898ba82d42aa46cbca59fca31f47d5bce3e8dd72.tar.gz hdf5-898ba82d42aa46cbca59fca31f47d5bce3e8dd72.tar.bz2 |
[svn-r7844] Purpose:
Bug fix
Description:
Variable length strings and sequences with NULL pointers were not handled
by library, causing problems access the data. This also affected fill values
for variable-length datatypes.
Solution:
Address the issues in the library by detecting NULL sequences/strings
and avoid trying to convert them.
Patched up dumper to display NULL sequences/strings.
Platforms tested:
FreeBSD 4.9 (sleipnir)
h5committest
Diffstat (limited to 'tools')
-rw-r--r-- | tools/h5dump/h5dump.c | 5 | ||||
-rw-r--r-- | tools/h5dump/h5dumpgentest.c | 71 | ||||
-rwxr-xr-x | tools/h5dump/testh5dump.sh | 1 | ||||
-rwxr-xr-x | tools/h5dump/testh5dumpxml.sh | 2 | ||||
-rw-r--r-- | tools/lib/h5tools_str.c | 101 | ||||
-rw-r--r-- | tools/testfiles/tvldtypes4.h5 | bin | 6208 -> 8192 bytes | |||
-rw-r--r-- | tools/testfiles/tvlstr.ddl | 3 | ||||
-rw-r--r-- | tools/testfiles/tvlstr.h5 | bin | 8192 -> 8192 bytes | |||
-rw-r--r-- | tools/testfiles/tvlstr.h5.xml | 12 |
9 files changed, 136 insertions, 59 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 5431e21..21913cd 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -4930,7 +4930,8 @@ xml_print_strs(hid_t did, int source) for (i = 0; i < ssiz; i++) { if(is_vlstr) { onestring = *(char **)bp; - str_size = (size_t)strlen(onestring); + if(onestring) + str_size = (size_t)strlen(onestring); } else { strncpy(onestring, bp, tsiz); str_size = tsiz; @@ -4938,7 +4939,7 @@ xml_print_strs(hid_t did, int source) indentation(indent + COL); if (!onestring) { - printf("\"%s\"\n", "NULL"); + printf("NULL\n"); } else { char *t_onestring = xml_escape_the_string(onestring, (int)str_size); diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c index 690d1c7..002cf89 100644 --- a/tools/h5dump/h5dumpgentest.c +++ b/tools/h5dump/h5dumpgentest.c @@ -68,6 +68,7 @@ #define FILE40 "tattr2.h5" #define FILE41 "tcompound_complex.h5" #define FILE42 "tnamed_dtype_attr.h5" +#define FILE43 "tvldtypes5.h5" /* prototypes */ @@ -145,6 +146,10 @@ typedef struct s1_t { #define F42_TYPENAME "Datatype" #define F42_ATTRNAME "Attribute" +/* "File 43" macros */ +/* Name of dataset to create in datafile */ +#define F43_DSETNAME "Dataset" + static void gent_group(void) { hid_t fid, group; @@ -2196,6 +2201,67 @@ static void gent_vldatatypes4(void) assert(ret>=0); } +/* Generate a variable-length dataset with NULL values in it */ +static void gent_vldatatypes5(void) +{ + hvl_t wdata [SPACE1_DIM1]; + hid_t fid1; + hid_t dataset; + hid_t sid1; + hid_t tid1; + hsize_t dims1[] = {SPACE1_DIM1}; + int i,j; /* counting variable */ + herr_t ret; /* Generic return value */ + + /* initialize data for dataset */ + for(i=0; i<SPACE1_DIM1; i++) { + if(i%2) { + wdata[i].len=0; + wdata[i].p=NULL; + } /* end if */ + else { + wdata[i].len=i+5; + wdata[i].p=malloc(sizeof(unsigned)*(i+5)); + for(j=0; j<i+5; j++) + ((unsigned *)wdata[i].p)[j]=j*2; + } /* end else */ + } /* end for */ + + /* Create file */ + fid1 = H5Fcreate (FILE43, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + assert(fid1>0); + + /* Create dataspace for datasets */ + sid1 = H5Screate_simple (SPACE1_RANK, dims1, NULL); + assert(sid1>0); + + /* Create a datatype to refer to */ + tid1 = H5Tvlen_create (H5T_NATIVE_UINT); + assert(tid1>0); + + /* Create a dataset */ + dataset = H5Dcreate (fid1, F43_DSETNAME, tid1, sid1, H5P_DEFAULT); + assert(dataset>0); + + ret = H5Dwrite (dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata); + assert(ret>=0); + + ret = H5Dclose (dataset); + assert(ret>=0); + + ret = H5Dvlen_reclaim (tid1, sid1, H5P_DEFAULT, wdata); + assert(ret>=0); + + ret = H5Tclose (tid1); + assert(ret>=0); + + ret = H5Sclose (sid1); + assert(ret>=0); + + ret = H5Fclose (fid1); + assert(ret>=0); +} + static void gent_array1(void) { int wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */ @@ -2884,8 +2950,8 @@ static void gent_vlstr(void) const char *wdata[SPACE1_DIM1]= { "Four score and seven years ago our forefathers brought forth on this continent a new nation,", "conceived in liberty and dedicated to the proposition that all men are created equal.", - "Now we are engaged in a great civil war,", - "testing whether that nation or any nation so conceived and so dedicated can long endure." + "", + NULL }; /* Information to write */ const char *string_att= "This is the string for the attribute"; hid_t fid1; /* HDF5 File IDs */ @@ -4288,6 +4354,7 @@ int main(void) gent_vldatatypes2(); gent_vldatatypes3(); gent_vldatatypes4(); + gent_vldatatypes5(); gent_array1(); gent_array2(); diff --git a/tools/h5dump/testh5dump.sh b/tools/h5dump/testh5dump.sh index 5a4e902..78e2f03 100755 --- a/tools/h5dump/testh5dump.sh +++ b/tools/h5dump/testh5dump.sh @@ -147,6 +147,7 @@ TOOLTEST tvldtypes1.ddl tvldtypes1.h5 TOOLTEST tvldtypes2.ddl tvldtypes2.h5 TOOLTEST tvldtypes3.ddl tvldtypes3.h5 TOOLTEST tvldtypes4.ddl tvldtypes4.h5 +TOOLTEST tvldtypes5.ddl tvldtypes5.h5 #test for file with variable length string data TOOLTEST tvlstr.ddl tvlstr.h5 diff --git a/tools/h5dump/testh5dumpxml.sh b/tools/h5dump/testh5dumpxml.sh index b7c6f54..d5e3ad5 100755 --- a/tools/h5dump/testh5dumpxml.sh +++ b/tools/h5dump/testh5dumpxml.sh @@ -126,6 +126,8 @@ TOOLTEST tarray7.h5.xml --xml tarray7.h5 TOOLTEST tvldtypes1.h5.xml --xml tvldtypes1.h5 TOOLTEST tvldtypes2.h5.xml --xml tvldtypes2.h5 TOOLTEST tvldtypes3.h5.xml --xml tvldtypes3.h5 +TOOLTEST tvldtypes4.h5.xml --xml tvldtypes4.h5 +TOOLTEST tvldtypes5.h5.xml --xml tvldtypes5.h5 TOOLTEST tvlstr.h5.xml --xml tvlstr.h5 TOOLTEST tsaf.h5.xml --xml tsaf.h5 TOOLTEST tempty.h5.xml --xml tempty.h5 diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index 45e2027..e38e8fd 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -510,8 +510,8 @@ char * h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container, hid_t type, void *vp, h5tools_context_t *ctx) { - size_t n, offset, size, nelmts, start; - char *name, quote = '\0'; + size_t n, offset, size=0, nelmts, start; + char *name; unsigned char *ucp_vp = (unsigned char *)vp; char *cp_vp = (char *)vp; hid_t memb, obj, region; @@ -566,6 +566,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container, h5tools_print_char(str, info, (unsigned char)(*ucp_vp)); } else if (H5T_STRING == H5Tget_class(type)) { unsigned int i; + char quote = '\0'; char *s; quote = '\0'; @@ -573,64 +574,70 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container, /* cp_vp is the pointer into the struct where a `char*' is stored. So we have * to dereference the pointer to get the `char*' to pass to HDstrlen(). */ s = *(char**)cp_vp; - size = HDstrlen(s); + if(s!=NULL) + size = HDstrlen(s); } else { s = cp_vp; size = H5Tget_size(type); } pad = H5Tget_strpad(type); - for (i=0; i<size && (s[i] || pad!=H5T_STR_NULLTERM); i++) { - int j = 1; - - /* - * Count how many times the next character repeats. If the - * threshold is zero then that means it can repeat any number - * of times. - */ - if (info->str_repeat > 0) - while (i + j < size && s[i] == s[i + j]) - j++; - - /* - * Print the opening quote. If the repeat count is high enough to - * warrant printing the number of repeats instead of enumerating - * the characters, then make sure the character to be repeated is - * in it's own quote. - */ - if (info->str_repeat > 0 && j > info->str_repeat) { - if (quote) - h5tools_str_append(str, "%c", quote); - - quote = '\''; - h5tools_str_append(str, "%s%c", i ? " " : "", quote); - } else if (!quote) { - quote = '"'; - h5tools_str_append(str, "%s%c", i ? " " : "", quote); - } + if(s==NULL) { + h5tools_str_append(str, "NULL"); + } + else { + for (i=0; i<size && (s[i] || pad!=H5T_STR_NULLTERM); i++) { + int j = 1; + + /* + * Count how many times the next character repeats. If the + * threshold is zero then that means it can repeat any number + * of times. + */ + if (info->str_repeat > 0) + while (i + j < size && s[i] == s[i + j]) + j++; - /* Print the character */ - h5tools_print_char(str, info, (unsigned char)(s[i])); - - /* Print the repeat count */ - if (info->str_repeat && j > info->str_repeat) { + /* + * Print the opening quote. If the repeat count is high enough to + * warrant printing the number of repeats instead of enumerating + * the characters, then make sure the character to be repeated is + * in it's own quote. + */ + if (info->str_repeat > 0 && j > info->str_repeat) { + if (quote) + h5tools_str_append(str, "%c", quote); + + quote = '\''; + h5tools_str_append(str, "%s%c", i ? " " : "", quote); + } else if (!quote) { + quote = '"'; + h5tools_str_append(str, "%s%c", i ? " " : "", quote); + } + + /* Print the character */ + h5tools_print_char(str, info, (unsigned char)(s[i])); + + /* Print the repeat count */ + if (info->str_repeat && j > info->str_repeat) { #ifdef REPEAT_VERBOSE - h5tools_str_append(str, "%c repeats %d times", quote, j - 1); + h5tools_str_append(str, "%c repeats %d times", quote, j - 1); #else - h5tools_str_append(str, "%c*%d", quote, j - 1); + h5tools_str_append(str, "%c*%d", quote, j - 1); #endif /* REPEAT_VERBOSE */ - quote = '\0'; - i += j - 1; - } + 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*/ - h5tools_str_append(str, "\"\""); + if (i == 0) + /*empty string*/ + h5tools_str_append(str, "\"\""); + } /* end else */ } else if (H5Tequal(type, H5T_NATIVE_INT)) { memcpy(&tempint, vp, sizeof(int)); h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint); diff --git a/tools/testfiles/tvldtypes4.h5 b/tools/testfiles/tvldtypes4.h5 Binary files differindex 87aa5f9..ae5f967 100644 --- a/tools/testfiles/tvldtypes4.h5 +++ b/tools/testfiles/tvldtypes4.h5 diff --git a/tools/testfiles/tvlstr.ddl b/tools/testfiles/tvlstr.ddl index 2487984..aa19d89 100644 --- a/tools/testfiles/tvlstr.ddl +++ b/tools/testfiles/tvlstr.ddl @@ -21,8 +21,7 @@ GROUP "/" { DATA { "Four score and seven years ago our forefathers brought forth on this continent a new nation,", "conceived in liberty and dedicated to the proposition that all men are created equal.", - "Now we are engaged in a great civil war,", - "testing whether that nation or any nation so conceived and so dedicated can long endure." + "", NULL } } DATATYPE "vl_string_type" H5T_STRING { diff --git a/tools/testfiles/tvlstr.h5 b/tools/testfiles/tvlstr.h5 Binary files differindex f2bf9e4..c00defc 100644 --- a/tools/testfiles/tvlstr.h5 +++ b/tools/testfiles/tvlstr.h5 diff --git a/tools/testfiles/tvlstr.h5.xml b/tools/testfiles/tvlstr.h5.xml index d74cd1f..7d9fb5b 100644 --- a/tools/testfiles/tvlstr.h5.xml +++ b/tools/testfiles/tvlstr.h5.xml @@ -3,26 +3,26 @@ Expected output for 'h5dump --xml tvlstr.h5' ############################# <?xml version="1.0" encoding="UTF-8"?> <hdf5:HDF5-File xmlns:hdf5="http://hdf.ncsa.uiuc.edu/DTDs/HDF5-File" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://hdf.ncsa.uiuc.edu/DTDs/HDF5File http://hdf.ncsa.uiuc.edu/DTDs/HDF5-File.xsd"> -<hdf5:RootGroup OBJ-XID="xid_928-0" H5Path="/"> +<hdf5:RootGroup OBJ-XID="xid_928" H5Path="/"> <hdf5:Attribute Name="test_scalar"> <hdf5:Dataspace> <hdf5:ScalarDataspace /> </hdf5:Dataspace> - <hdf5:NamedDataTypePtr OBJ-XID="xid_1576-0" H5Path="/vl_string_type" /> + <hdf5:NamedDataTypePtr OBJ-XID="xid_1576" H5Path="/vl_string_type" /> <hdf5:Data> <hdf5:DataFromFile> "This is the string for the attribute" </hdf5:DataFromFile> </hdf5:Data> </hdf5:Attribute> - <hdf5:NamedDataType Name="vl_string_type" OBJ-XID="xid_1576-0" H5Path="/vl_string_type" Parents="xid_928-0" H5ParentPaths="/"> + <hdf5:NamedDataType Name="vl_string_type" OBJ-XID="xid_1576" H5Path="/vl_string_type" Parents="xid_928" H5ParentPaths="/"> <hdf5:DataType> <hdf5:AtomicType> <hdf5:StringType Cset="H5T_CSET_ASCII" StrSize="H5T_VARIABLE" StrPad="H5T_STR_NULLPAD"/> </hdf5:AtomicType> </hdf5:DataType> </hdf5:NamedDataType> - <hdf5:Dataset Name="Dataset1" OBJ-XID="xid_976-0" H5Path= "/Dataset1" Parents="xid_928-0" H5ParentPaths="/"> + <hdf5:Dataset Name="Dataset1" OBJ-XID="xid_976" H5Path= "/Dataset1" Parents="xid_928" H5ParentPaths="/"> <hdf5:StorageLayout> <hdf5:ContiguousLayout/> </hdf5:StorageLayout> @@ -48,8 +48,8 @@ Expected output for 'h5dump --xml tvlstr.h5' <hdf5:DataFromFile> "Four score and seven years ago our forefathers brought forth on this continent a new nation," "conceived in liberty and dedicated to the proposition that all men are created equal." - "Now we are engaged in a great civil war," - "testing whether that nation or any nation so conceived and so dedicated can long endure." + "" + NULL </hdf5:DataFromFile> </hdf5:Data> </hdf5:Dataset> |