From 4cd5a378c473faefd822beabbeccbb6e4f2f873e Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Tue, 27 Jan 2009 11:05:53 -0500 Subject: [svn-r16361] Purpose: Fix potential error with H5Tset_order Description: H5Tset_order will now properly reject H5T_ORDER_NONE for most datatypes. Previously this could cause major problems as the file could not be flushed. Tested: jam, smirom (h5committest) --- release_docs/RELEASE.txt | 2 + src/H5Torder.c | 2 + test/dtypes.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 6fbedda..40326bf 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -113,6 +113,8 @@ Bug Fixes since HDF5-1.8.2 Library ------- + - Changed H5Tset_order to properly reject H5T_ORDER_NONE for most datatypes. + NAF - 2009/01/27 - Fixed a bug where H5Tpack wouldn't remove trailing space from an otherwise packed compound type. NAF - 2009/01/14 - Fixed up some old v2 btree assertions that get run in debug mode that diff --git a/src/H5Torder.c b/src/H5Torder.c index 34dbd8e..6c0667b 100644 --- a/src/H5Torder.c +++ b/src/H5Torder.c @@ -158,6 +158,8 @@ H5Tset_order(hid_t type_id, H5T_order_t order) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined") while (dt->shared->parent) dt = dt->shared->parent; /*defer to parent*/ + if (order == H5T_ORDER_NONE && !(H5T_REFERENCE == dt->shared->type || H5T_IS_FIXED_STRING(dt->shared))) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal byte order") if (!H5T_IS_ATOMIC(dt->shared)) HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "operation not defined for specified datatype") diff --git a/test/dtypes.c b/test/dtypes.c index f4e0305..895d890 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -5645,6 +5645,172 @@ error: /*------------------------------------------------------------------------- + * Function: test_set_order + * + * Purpose: Tests H5Tset_order/H5Tget_order. Verifies that + * H5T_ORDER_NONE cannot be set. + * + * Return: Success: 0 + * + * Failure: number of errors + * + * Programmer: Neil Fortner + * January 23, 2009 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +test_set_order(void) +{ + hid_t dtype; /* Datatype ID */ + H5T_order_t order; /* Byte order */ + hsize_t dims[2] = {3, 4}; /* Array dimenstions */ + herr_t ret; /* Generic return value */ + + TESTING("H5Tset/get_order"); + + /* Integer */ + if ((dtype = H5Tcopy(H5T_STD_I32BE)) < 0) TEST_ERROR + if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR; + H5E_BEGIN_TRY + ret = H5Tset_order(dtype, H5T_ORDER_NONE); + H5E_END_TRY + if (ret >= 0) TEST_ERROR + if (H5Tset_order(dtype, H5T_ORDER_LE) < 0) TEST_ERROR + if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tclose(dtype) < 0) TEST_ERROR + + /* Float */ + if ((dtype = H5Tcopy(H5T_IEEE_F64LE)) < 0) TEST_ERROR + if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR; + H5E_BEGIN_TRY + ret = H5Tset_order(dtype, H5T_ORDER_NONE); + H5E_END_TRY + if (ret >= 0) TEST_ERROR + if (H5Tset_order(dtype, H5T_ORDER_BE) < 0) TEST_ERROR + if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tclose(dtype) < 0) TEST_ERROR + + /* Time */ + if ((dtype = H5Tcopy(H5T_UNIX_D64BE)) < 0) TEST_ERROR + if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR; + H5E_BEGIN_TRY + ret = H5Tset_order(dtype, H5T_ORDER_NONE); + H5E_END_TRY + if (ret >= 0) TEST_ERROR + if (H5Tset_order(dtype, H5T_ORDER_LE) < 0) TEST_ERROR + if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tclose(dtype) < 0) TEST_ERROR + + /* Fixed length string */ + if ((dtype = H5Tcopy(H5T_C_S1)) < 0) TEST_ERROR + if (H5Tset_size(dtype, 5) < 0) TEST_ERROR + if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tset_order(dtype, H5T_ORDER_NONE) < 0) TEST_ERROR; + if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR; + + /* Variable length string */ + if (H5Tset_size(dtype, H5T_VARIABLE) < 0) TEST_ERROR + H5E_BEGIN_TRY + ret = H5Tset_order(dtype, H5T_ORDER_NONE); + H5E_END_TRY + if (ret >= 0) TEST_ERROR + if (H5Tset_order(dtype, H5T_ORDER_BE) < 0) TEST_ERROR + if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tclose(dtype) < 0) TEST_ERROR + + /* Bitfield */ + if ((dtype = H5Tcopy(H5T_STD_B16LE)) < 0) TEST_ERROR + if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR; + H5E_BEGIN_TRY + ret = H5Tset_order(dtype, H5T_ORDER_NONE); + H5E_END_TRY + if (ret >= 0) TEST_ERROR + if (H5Tset_order(dtype, H5T_ORDER_BE) < 0) TEST_ERROR + if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tclose(dtype) < 0) TEST_ERROR + + /* Opaque - functions should fail */ + if ((dtype = H5Tcreate(H5T_OPAQUE, 96)) < 0) TEST_ERROR + H5E_BEGIN_TRY + ret = H5Tset_order(dtype, H5T_ORDER_LE); + order = H5Tget_order(dtype); + H5E_END_TRY + if (ret >= 0) TEST_ERROR + if (order >= 0) TEST_ERROR + if (H5Tclose(dtype) < 0) TEST_ERROR + + /* Compound - functions should fail */ + if ((dtype = H5Tcreate(H5T_COMPOUND, 48)) < 0) TEST_ERROR + H5E_BEGIN_TRY + ret = H5Tset_order(dtype, H5T_ORDER_LE); + order = H5Tget_order(dtype); + H5E_END_TRY + if (ret >= 0) TEST_ERROR + if (order >= 0) TEST_ERROR + if (H5Tclose(dtype) < 0) TEST_ERROR + + /* Object reference */ + if ((dtype = H5Tcopy(H5T_STD_REF_OBJ)) < 0) TEST_ERROR + if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tset_order(dtype, H5T_ORDER_NONE) < 0) TEST_ERROR; + if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tclose(dtype) < 0) TEST_ERROR + + /* Region reference */ + if ((dtype = H5Tcopy(H5T_STD_REF_DSETREG)) < 0) TEST_ERROR + if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tset_order(dtype, H5T_ORDER_NONE) < 0) TEST_ERROR; + if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tclose(dtype) < 0) TEST_ERROR + + /* Enum */ + if ((dtype = H5Tenum_create(H5T_STD_I16BE)) < 0) TEST_ERROR + if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR; + H5E_BEGIN_TRY + ret = H5Tset_order(dtype, H5T_ORDER_NONE); + H5E_END_TRY + if (ret >= 0) TEST_ERROR + if (H5Tset_order(dtype, H5T_ORDER_LE) < 0) TEST_ERROR + if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tclose(dtype) < 0) TEST_ERROR + + /* Vlen */ + if ((dtype = H5Tvlen_create(H5T_STD_U64LE)) < 0) TEST_ERROR + if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR; + H5E_BEGIN_TRY + ret = H5Tset_order(dtype, H5T_ORDER_NONE); + H5E_END_TRY + if (ret >= 0) TEST_ERROR + if (H5Tset_order(dtype, H5T_ORDER_BE) < 0) TEST_ERROR + if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tclose(dtype) < 0) TEST_ERROR + + /* Array */ + if ((dtype = H5Tarray_create2(H5T_IEEE_F64BE, 2, dims)) < 0) TEST_ERROR + if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR; + H5E_BEGIN_TRY + ret = H5Tset_order(dtype, H5T_ORDER_NONE); + H5E_END_TRY + if (ret >= 0) TEST_ERROR + if (H5Tset_order(dtype, H5T_ORDER_LE) < 0) TEST_ERROR + if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR; + if (H5Tclose(dtype) < 0) TEST_ERROR + + PASSED(); + return 0; + +error: + H5E_BEGIN_TRY + H5Tclose (dtype); + H5E_END_TRY; + return 1; +} /* end test_set_order() */ + + +/*------------------------------------------------------------------------- * Function: test_deprec * * Purpose: Tests deprecated API routines for datatypes. @@ -5847,6 +6013,7 @@ main(void) nerrors += test_conv_bitfield(); nerrors += test_bitfield_funcs(); nerrors += test_opaque(); + nerrors += test_set_order(); if(nerrors) { printf("***** %lu FAILURE%s! *****\n", -- cgit v0.12