diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2003-11-13 15:19:50 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2003-11-13 15:19:50 (GMT) |
commit | e1792ebb22c1fee3eb349b83543e6e915bd1e6f7 (patch) | |
tree | 6e3f936d7809ff0191d17454ba0cb6047abda784 /tools | |
parent | 71f3513337e800f6500551448559cecc6853aca9 (diff) | |
download | hdf5-e1792ebb22c1fee3eb349b83543e6e915bd1e6f7.zip hdf5-e1792ebb22c1fee3eb349b83543e6e915bd1e6f7.tar.gz hdf5-e1792ebb22c1fee3eb349b83543e6e915bd1e6f7.tar.bz2 |
[svn-r7842] 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 | 102 | ||||
-rw-r--r-- | tools/testfiles/tvldtypes4.h5 | bin | 6208 -> 8192 bytes | |||
-rw-r--r-- | tools/testfiles/tvldtypes4.h5.xml | 55 | ||||
-rw-r--r-- | tools/testfiles/tvldtypes5.ddl | 14 | ||||
-rw-r--r-- | tools/testfiles/tvldtypes5.h5 | bin | 0 -> 8192 bytes | |||
-rw-r--r-- | tools/testfiles/tvldtypes5.h5.xml | 41 | ||||
-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 | 4 |
13 files changed, 243 insertions, 55 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 77ce159..d79f4ee 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -4846,7 +4846,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; @@ -4854,7 +4855,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 0356b2b..901f427 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 2e214d8..c0b5165 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 de1bf72..b3ee8e3 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; @@ -567,6 +567,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'; @@ -574,64 +575,71 @@ 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); - } + /* Check for NULL pointer for string */ + 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/tvldtypes4.h5.xml b/tools/testfiles/tvldtypes4.h5.xml new file mode 100644 index 0000000..6a31194 --- /dev/null +++ b/tools/testfiles/tvldtypes4.h5.xml @@ -0,0 +1,55 @@ +############################# +Expected output for 'h5dump --xml tvldtypes4.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" H5Path="/"> + <hdf5:Dataset Name="Dataset1" OBJ-XID="xid_976" H5Path= "/Dataset1" Parents="xid_928" H5ParentPaths="/"> + <hdf5:StorageLayout> + <hdf5:ContiguousLayout/> + </hdf5:StorageLayout> + <hdf5:FillValueInfo FillTime="FillOnAlloc" AllocationTime="Late"> + <hdf5:FillValue> + <hdf5:Data> + <!-- VL fill not yet implemented. --> + <hdf5:NoData /> + </hdf5:Data> + </hdf5:FillValue> + </hdf5:FillValueInfo> + <hdf5:Dataspace> + <hdf5:SimpleDataspace Ndims="1"> + <hdf5:Dimension DimSize="4" MaxDimSize="4"/> + </hdf5:SimpleDataspace> + </hdf5:Dataspace> + <hdf5:DataType> + <hdf5:VLType> + <hdf5:DataType> + <hdf5:CompoundType> + <hdf5:Field FieldName="i"> + <hdf5:DataType> + <hdf5:AtomicType> + <hdf5:IntegerType ByteOrder="LE" Sign="true" Size="4" /> + </hdf5:AtomicType> + </hdf5:DataType> + </hdf5:Field> + <hdf5:Field FieldName="f"> + <hdf5:DataType> + <hdf5:AtomicType> + <hdf5:FloatType ByteOrder="LE" Size="4" SignBitLocation="31" ExponentBits="8" ExponentLocation="23" MantissaBits="23" MantissaLocation="0" /> + </hdf5:AtomicType> + </hdf5:DataType> + </hdf5:Field> + </hdf5:CompoundType> + </hdf5:DataType> + </hdf5:VLType> + </hdf5:DataType> +<!-- Note: format of VL data not specified --> + <hdf5:Data> + <hdf5:DataFromFile> + 0 0 10 6.66667 11 7 20 13.3333 21 13.6667 22 14 + 30 20 31 20.3333 32 20.6667 33 21 + </hdf5:DataFromFile> + </hdf5:Data> + </hdf5:Dataset> +</hdf5:RootGroup> +</hdf5:HDF5-File> diff --git a/tools/testfiles/tvldtypes5.ddl b/tools/testfiles/tvldtypes5.ddl new file mode 100644 index 0000000..d199037 --- /dev/null +++ b/tools/testfiles/tvldtypes5.ddl @@ -0,0 +1,14 @@ +############################# +Expected output for 'h5dump tvldtypes5.h5' +############################# +HDF5 "tvldtypes5.h5" { +GROUP "/" { + DATASET "Dataset" { + DATATYPE H5T_VLEN { H5T_STD_U32LE} + DATASPACE SIMPLE { ( 4 ) / ( 4 ) } + DATA { + (0, 2, 4, 6, 8), (), (0, 2, 4, 6, 8, 10, 12), () + } + } +} +} diff --git a/tools/testfiles/tvldtypes5.h5 b/tools/testfiles/tvldtypes5.h5 Binary files differnew file mode 100644 index 0000000..702e45b --- /dev/null +++ b/tools/testfiles/tvldtypes5.h5 diff --git a/tools/testfiles/tvldtypes5.h5.xml b/tools/testfiles/tvldtypes5.h5.xml new file mode 100644 index 0000000..f2452a7 --- /dev/null +++ b/tools/testfiles/tvldtypes5.h5.xml @@ -0,0 +1,41 @@ +############################# +Expected output for 'h5dump --xml tvldtypes5.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" H5Path="/"> + <hdf5:Dataset Name="Dataset" OBJ-XID="xid_976" H5Path= "/Dataset" Parents="xid_928" H5ParentPaths="/"> + <hdf5:StorageLayout> + <hdf5:ContiguousLayout/> + </hdf5:StorageLayout> + <hdf5:FillValueInfo FillTime="FillOnAlloc" AllocationTime="Late"> + <hdf5:FillValue> + <hdf5:Data> + <!-- VL fill not yet implemented. --> + <hdf5:NoData /> + </hdf5:Data> + </hdf5:FillValue> + </hdf5:FillValueInfo> + <hdf5:Dataspace> + <hdf5:SimpleDataspace Ndims="1"> + <hdf5:Dimension DimSize="4" MaxDimSize="4"/> + </hdf5:SimpleDataspace> + </hdf5:Dataspace> + <hdf5:DataType> + <hdf5:VLType> + <hdf5:DataType> + <hdf5:AtomicType> + <hdf5:IntegerType ByteOrder="LE" Sign="false" Size="4" /> + </hdf5:AtomicType> + </hdf5:DataType> + </hdf5:VLType> + </hdf5:DataType> +<!-- Note: format of VL data not specified --> + <hdf5:Data> + <hdf5:DataFromFile> + 0 2 4 6 8 0 2 4 6 8 10 12 + </hdf5:DataFromFile> + </hdf5:Data> + </hdf5:Dataset> +</hdf5:RootGroup> +</hdf5:HDF5-File> 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 d6f31df..7d9fb5b 100644 --- a/tools/testfiles/tvlstr.h5.xml +++ b/tools/testfiles/tvlstr.h5.xml @@ -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> |