summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2011-05-20 16:34:12 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2011-05-20 16:34:12 (GMT)
commitb290a2d784254feb5586d7e3171396bcc7ddc352 (patch)
tree2b9afd6fae153497a9edd7e5004d86fc53bd99dd
parent54728019ca2a5be26efcc56fd361cbcc11f5b36a (diff)
downloadhdf5-b290a2d784254feb5586d7e3171396bcc7ddc352.zip
hdf5-b290a2d784254feb5586d7e3171396bcc7ddc352.tar.gz
hdf5-b290a2d784254feb5586d7e3171396bcc7ddc352.tar.bz2
[svn-r20873] Issue 7564 - Allow H5Tcreat to create string type (fixed-length and variable-length). I also added a test case in dtypes.c. The commit is only for test/dtypes.c, src/H5T.c, and release_docs/RELEASE.txt. All others are property changes due to the merge from the trunk.
Tested on jam but I tested the same change for the trunk on jam and linew - relatively simple.
-rw-r--r--release_docs/RELEASE.txt3
-rw-r--r--src/H5T.c32
-rw-r--r--test/dtypes.c63
3 files changed, 89 insertions, 9 deletions
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt
index ba2d3d7..6ead9dc 100644
--- a/release_docs/RELEASE.txt
+++ b/release_docs/RELEASE.txt
@@ -64,7 +64,8 @@ New Features
Parallel Library
----------------
- - None
+ - H5Tcreate now supports string type (fixed-length and variable-length).
+ (SLU - 2011/05/20)
Tools
-----
diff --git a/src/H5T.c b/src/H5T.c
index a34783a..3f0f46b 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -1588,9 +1588,9 @@ H5Tcreate(H5T_class_t type, size_t size)
FUNC_ENTER_API(H5Tcreate, FAIL)
H5TRACE2("i", "Ttz", type, size);
- /* check args */
- if(size == 0)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid size")
+ /* check args. We support string (fixed-size or variable-length) now. */
+ if(size <= 0 && size != H5T_VARIABLE)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "size must be positive")
/* create the type */
if(NULL == (dt = H5T_create(type, size)))
@@ -2155,8 +2155,6 @@ H5Tset_size(hid_t type_id, size_t size)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined")
if(H5T_REFERENCE == dt->shared->type)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for this datatype")
- if(size == 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't adjust size to 0")
/* Modify the datatype */
if(H5T_set_size(dt, size) < 0)
@@ -2970,7 +2968,9 @@ done:
* Friday, December 5, 1997
*
* Modifications:
- *
+ * Raymond Lu
+ * 19 May 2011
+ * We support fixed size or variable-length string now.
*-------------------------------------------------------------------------
*/
H5T_t *
@@ -2986,6 +2986,22 @@ H5T_create(H5T_class_t type, size_t size)
case H5T_FLOAT:
case H5T_TIME:
case H5T_STRING:
+ {
+ H5T_t *origin_dt = NULL;
+
+ if(NULL == (origin_dt = (H5T_t *)H5I_object(H5T_C_S1)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, NULL, "can't get structure for string type")
+
+ /* Copy the default string datatype */
+ if(NULL == (dt = H5T_copy(origin_dt, H5T_COPY_TRANSIENT)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy");
+
+ /* Modify the datatype */
+ if(H5T_set_size(dt, size) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to set size for string type")
+ }
+ break;
+
case H5T_BITFIELD:
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, NULL, "type class is not appropriate - use H5Tcopy()")
@@ -3045,7 +3061,9 @@ H5T_create(H5T_class_t type, size_t size)
HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, NULL, "unknown data type class")
} /* end switch */
- dt->shared->size = size;
+ /* Set the size except VL string */
+ if(H5T_STRING != type || H5T_VARIABLE != size)
+ dt->shared->size = size;
/* Set return value */
ret_value = dt;
diff --git a/test/dtypes.c b/test/dtypes.c
index 3511d04..2605a1e 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -3901,6 +3901,67 @@ mkstr(size_t len, H5T_str_t strpad)
/*-------------------------------------------------------------------------
+ * Function: test_str_create
+ *
+ * Purpose: Test string type creation using H5Tcreate
+ *
+ * Return: Success: 0
+ * Failure: number of errors
+ *
+ * Programmer: Raymond Lu
+ * 19 May 2011
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_str_create(void)
+{
+ hid_t fixed_str1, fixed_str2;
+ hid_t vlen_str1, vlen_str2;
+ htri_t is_vl_str = FALSE;
+ size_t query_size, str_size = 10;
+
+ TESTING("string type creation using H5Tcreate");
+
+ /* Create fixed-length string in two ways and make sure they are the same */
+ if((fixed_str1 = mkstr(str_size, H5T_STR_NULLTERM)) < 0) goto error;
+
+ if((fixed_str2 = H5Tcreate(H5T_STRING, str_size)) < 0) goto error;
+ if(H5Tset_strpad(fixed_str2, H5T_STR_NULLTERM) < 0) goto error;
+
+ if(!H5Tequal(fixed_str1, fixed_str2)) goto error;
+
+ if((query_size = H5Tget_size(fixed_str1)) == 0) goto error;
+ if(query_size != str_size) goto error;
+
+ if((query_size = H5Tget_size(fixed_str2)) == 0) goto error;
+ if(query_size != str_size) goto error;
+
+ /* Create variable-length string in two ways and make sure they are the same */
+ if((vlen_str1 = mkstr((size_t)H5T_VARIABLE, H5T_STR_NULLTERM)) < 0) goto error;
+
+ if((vlen_str2 = H5Tcreate(H5T_STRING, (size_t)H5T_VARIABLE)) < 0) goto error;
+ if(H5Tset_strpad(vlen_str2, H5T_STR_NULLTERM) < 0) goto error;
+
+ if(!H5Tequal(vlen_str1, vlen_str2)) goto error;
+
+ if((is_vl_str = H5Tis_variable_str(vlen_str1)) < 0) goto error;
+ if(!is_vl_str) goto error;
+
+ if((is_vl_str = H5Tis_variable_str(vlen_str2)) < 0) goto error;
+ if(!is_vl_str) goto error;
+
+
+ PASSED();
+ return 0;
+
+error:
+ H5_FAILED();
+ return 1;
+}
+
+
+/*-------------------------------------------------------------------------
* Function: test_conv_str_1
*
* Purpose: Test string conversions
@@ -6641,6 +6702,7 @@ main(void)
nerrors += test_int_float_except();
nerrors += test_named_indirect_reopen(fapl);
nerrors += test_set_order_compound(fapl);
+ nerrors += test_str_create();
#ifndef H5_NO_DEPRECATED_SYMBOLS
nerrors += test_deprec(fapl);
#endif /* H5_NO_DEPRECATED_SYMBOLS */
@@ -6684,4 +6746,3 @@ main(void)
return 0;
}
-