summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2011-05-20 16:14:33 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2011-05-20 16:14:33 (GMT)
commit2de5fa986fc4e8588af5df33ed5c6500a7fa5a96 (patch)
tree2bbf235f713a682c7890cff3078d6ad043930550 /src
parent0982e11bb483c73b827237ce59886dce93a8fba9 (diff)
downloadhdf5-2de5fa986fc4e8588af5df33ed5c6500a7fa5a96.zip
hdf5-2de5fa986fc4e8588af5df33ed5c6500a7fa5a96.tar.gz
hdf5-2de5fa986fc4e8588af5df33ed5c6500a7fa5a96.tar.bz2
[svn-r20872] Issue 7564 - Allow H5Tcreat to create string type (fixed-length and variable-length). I also added a test case in dtypes.c.
Tested on jam and linew - relatively simple.
Diffstat (limited to 'src')
-rw-r--r--src/H5T.c32
1 files changed, 25 insertions, 7 deletions
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;