summaryrefslogtreecommitdiffstats
path: root/src/H5Aint.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Aint.c')
-rw-r--r--src/H5Aint.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/H5Aint.c b/src/H5Aint.c
index 160c7fb..bfc69ec 100644
--- a/src/H5Aint.c
+++ b/src/H5Aint.c
@@ -112,6 +112,13 @@ static herr_t H5A__attr_sort_table(H5A_attr_table_t *atable, H5_index_t idx_type
/* Local Variables */
/*******************/
+/* Format version bounds for attribute */
+static const unsigned H5O_attr_ver_bounds[] = {
+ H5O_ATTR_VERSION_1, /* H5F_LIBVER_EARLIEST */
+ H5O_ATTR_VERSION_3, /* H5F_LIBVER_V18 */
+ H5O_ATTR_VERSION_LATEST /* H5F_LIBVER_LATEST */
+};
+
typedef H5A_t* H5A_t_ptr;
H5FL_SEQ_DEFINE(H5A_t_ptr);
@@ -210,17 +217,15 @@ H5A_create(const H5G_loc_t *loc, const char *name, const H5T_t *type,
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "invalid datatype location")
/* Set the latest format for datatype, if requested */
- if(H5F_USE_LATEST_FLAGS(loc->oloc->file, H5F_LATEST_DATATYPE))
- if(H5T_set_latest_version(attr->shared->dt) < 0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, NULL, "can't set latest version of datatype")
+ if(H5T_set_version(loc->oloc->file, attr->shared->dt) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, NULL, "can't set version of datatype")
/* Copy the dataspace for the attribute */
attr->shared->ds = H5S_copy(space, FALSE, TRUE);
- /* Set the latest format for dataspace, if requested */
- if(H5F_USE_LATEST_FLAGS(loc->oloc->file, H5F_LATEST_DATASPACE))
- if(H5S_set_latest_version(attr->shared->ds) < 0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, NULL, "can't set latest version of dataspace")
+ /* Set the version for dataspace */
+ if(H5S_set_version(loc->oloc->file, attr->shared->ds) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, NULL, "can't set version of dataspace")
/* Copy the object header information */
if(H5O_loc_copy(&(attr->oloc), loc->oloc, H5_COPY_DEEP) < 0)
@@ -1840,11 +1845,11 @@ done:
* Function: H5A_set_version
*
* Purpose: Sets the correct version to encode attribute with.
- * Chooses the oldest version possible, unless the "use the
- * latest format" flag is set.
+ * Chooses the oldest version possible, unless the
+ * file's low bound indicates otherwise.
*
- * Return: Success: Non-negative
- * Failure: Negative
+ * Return: Success: Non-negative
+ * Failure: Negative
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
@@ -1857,7 +1862,7 @@ H5A_set_version(const H5F_t *f, H5A_t *attr)
{
hbool_t type_shared, space_shared; /* Flags to indicate that shared messages are used for this attribute */
hbool_t use_latest_format; /* Flag indicating the latest attribute version support is enabled */
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
@@ -1865,9 +1870,6 @@ H5A_set_version(const H5F_t *f, H5A_t *attr)
HDassert(f);
HDassert(attr);
- /* Get the file's 'use the latest attribute version support' flag */
- use_latest_format = H5F_USE_LATEST_FLAGS(f, H5F_LATEST_ATTRIBUTE);
-
/* Check whether datatype and dataspace are shared */
if(H5O_msg_is_shared(H5O_DTYPE_ID, attr->shared->dt) > 0)
type_shared = TRUE;
@@ -1880,15 +1882,19 @@ H5A_set_version(const H5F_t *f, H5A_t *attr)
space_shared = FALSE;
/* Check which version to encode attribute with */
- if(use_latest_format)
- attr->shared->version = H5O_ATTR_VERSION_LATEST; /* Write out latest attribute version */
- else if(attr->shared->encoding != H5T_CSET_ASCII)
+ if(attr->shared->encoding != H5T_CSET_ASCII)
attr->shared->version = H5O_ATTR_VERSION_3; /* Write version which includes the character encoding */
else if(type_shared || space_shared)
attr->shared->version = H5O_ATTR_VERSION_2; /* Write out version with flag for indicating shared datatype or dataspace */
else
attr->shared->version = H5O_ATTR_VERSION_1; /* Write out basic version */
+ /* Upgrade to the version indicated by the file's low bound if higher */
+ attr->shared->version = MAX(attr->shared->version, (uint8_t)H5O_attr_ver_bounds[H5F_LOW_BOUND(f)]);
+
+ /* File bound check */
+ if(attr->shared->version > H5O_attr_ver_bounds[H5F_HIGH_BOUND(f)])
+ HGOTO_ERROR(H5E_ATTR, H5E_BADRANGE, FAIL, "attribute version out of bounds")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5A_set_version() */