summaryrefslogtreecommitdiffstats
path: root/hl/src
diff options
context:
space:
mode:
Diffstat (limited to 'hl/src')
-rw-r--r--hl/src/H5DS.c900
-rw-r--r--hl/src/H5DSprivate.h8
-rw-r--r--hl/src/H5DSpublic.h2
-rw-r--r--hl/src/H5LT.c62
4 files changed, 633 insertions, 339 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index 2bd4046..7d93de4 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -18,7 +18,36 @@
/* Local routines */
static herr_t H5DS_is_reserved(hid_t did);
-static hid_t H5DS_get_REFLIST_type(void);
+
+/*-------------------------------------------------------------------------
+ * Function: H5DSwith_new_ref
+ *
+ * Purpose: Detremines if new references are used with dimension scales.
+ * The function H5DSwith_new_ref takes any object identifier and checks
+ * if new references are used for dimenison scales. Currently,
+ * new references are used when non-native VOL connector is used or when
+ * H5_DIMENSION_SCALES_WITH_NEW_REF is set up via configure option.
+ *
+ * Return: Success: TRUE/FALSE, Failure: FAIL
+ *
+ *-------------------------------------------------------------------------
+ */
+hbool_t
+H5DSwith_new_ref(hid_t obj_id)
+{
+ hbool_t ret_value = FALSE;
+ hbool_t config_flag = FALSE;
+ hbool_t native = FALSE;
+
+ native = H5VLobject_is_native(obj_id);
+ if (native < 0)
+ return FAIL;
+#ifdef H5_DIMENSION_SCALES_WITH_NEW_REF
+ config_flag = TRUE;
+#endif
+ ret_value = (config_flag || !native);
+ return ret_value;
+}
/*-------------------------------------------------------------------------
* Function: H5DSset_scale
@@ -106,22 +135,34 @@ H5DSset_scale(hid_t dsid, const char *dimname)
herr_t
H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
{
- int has_dimlist;
- int has_reflist;
- int is_ds;
- hssize_t nelmts;
- hid_t sid; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t ntid = -1; /* attribute native type ID */
- hid_t aid = -1; /* attribute ID */
- int rank; /* rank of dataset */
- hsize_t dims[1]; /* dimension of the "REFERENCE_LIST" array */
- ds_list_t dsl; /* attribute data in the DS pointing to the dataset */
- ds_list_t * dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
- hobj_ref_t ref_to_ds; /* reference to the DS */
- hobj_ref_t ref_j; /* iterator reference */
- hvl_t * buf = NULL; /* VL buffer to store in the attribute */
- hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
+ int has_dimlist;
+ int has_reflist;
+ int is_ds;
+ hssize_t nelmts;
+ hid_t sid, sid_w; /* space ID */
+ hid_t tid = H5I_INVALID_HID; /* attribute type ID */
+ hid_t ntid = H5I_INVALID_HID; /* attribute native type ID */
+ hid_t aid = H5I_INVALID_HID; /* attribute ID */
+ int rank; /* rank of dataset */
+ hsize_t dims[1]; /* dimension of the "REFERENCE_LIST" array */
+
+ ds_list_t dsl; /* attribute data in the DS pointing to the dataset */
+ ds_list_t *dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
+ ds_list_t *dsbuf_w =
+ NULL; /* array of "REFERENCE_LIST" attribute data to write when adding new reference to a dataset */
+ hobj_ref_t ref_to_ds; /* reference to the DS */
+ hobj_ref_t ref_j; /* iterator reference */
+
+ /* Variables to be used when new references are used */
+ nds_list_t ndsl;
+ nds_list_t *ndsbuf = NULL;
+ nds_list_t *ndsbuf_w = NULL;
+ H5R_ref_t nref_to_ds;
+ H5R_ref_t nref_j;
+ hbool_t is_new_ref;
+
+ hvl_t * buf = NULL; /* VL buffer to store in the attribute */
+ hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
H5O_info2_t oi1, oi2;
H5I_type_t it1, it2;
int i;
@@ -159,6 +200,15 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
return FAIL;
} /* end if */
+ /*-------------------------------------------------------------------------
+ * determine if old or new references should be used
+ *-------------------------------------------------------------------------
+ */
+
+ is_new_ref = H5DSwith_new_ref(did);
+ if (is_new_ref < 0)
+ return FAIL;
+
/* get ID type */
if ((it1 = H5Iget_type(did)) < 0)
return FAIL;
@@ -209,14 +259,23 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
* and one to the dataset, saved in "REFERENCE_LIST"
*-------------------------------------------------------------------------
*/
- /* create a reference for the >>DS<< dataset */
- if (H5Rcreate(&ref_to_ds, dsid, ".", H5R_OBJECT, (hid_t)-1) < 0)
- return FAIL;
-
- /* create a reference for the >>data<< dataset */
- if (H5Rcreate(&dsl.ref, did, ".", H5R_OBJECT, (hid_t)-1) < 0)
- return FAIL;
+ if (is_new_ref) {
+ /* create a reference for the >>DS<< dataset */
+ if (H5Rcreate_object(dsid, ".", H5P_DEFAULT, &nref_to_ds) < 0)
+ return FAIL;
+ /* create a reference for the >>data<< dataset */
+ if (H5Rcreate_object(did, ".", H5P_DEFAULT, &ndsl.ref) < 0)
+ return FAIL;
+ }
+ else {
+ /* create a reference for the >>DS<< dataset */
+ if (H5Rcreate(&ref_to_ds, dsid, ".", H5R_OBJECT, (hid_t)-1) < 0)
+ return FAIL;
+ /* create a reference for the >>data<< dataset */
+ if (H5Rcreate(&dsl.ref, did, ".", H5R_OBJECT, (hid_t)-1) < 0)
+ return FAIL;
+ }
/* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
if ((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
return FAIL;
@@ -234,9 +293,14 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
return FAIL;
/* create the type for the attribute "DIMENSION_LIST" */
- if ((tid = H5Tvlen_create(H5T_STD_REF_OBJ)) < 0)
- goto out;
-
+ if (is_new_ref) {
+ if ((tid = H5Tvlen_create(H5T_STD_REF)) < 0)
+ goto out;
+ }
+ else {
+ if ((tid = H5Tvlen_create(H5T_STD_REF_OBJ)) < 0)
+ goto out;
+ }
/* create the attribute */
if ((aid = H5Acreate2(did, DIMENSION_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
@@ -252,24 +316,32 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
}
/* store the REF information in the index of the dataset that has the DS */
- buf[idx].len = 1;
- buf[idx].p = HDmalloc(1 * sizeof(hobj_ref_t));
- ((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds;
-
+ buf[idx].len = 1;
+ if (is_new_ref) {
+ buf[idx].p = HDmalloc(1 * sizeof(H5R_ref_t));
+ ((H5R_ref_t *)buf[idx].p)[0] = nref_to_ds;
+ }
+ else {
+ buf[idx].p = HDmalloc(1 * sizeof(hobj_ref_t));
+ ((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds;
+ }
/* write the attribute with the reference */
if (H5Awrite(aid, tid, buf) < 0)
goto out;
/* close */
- if (H5Treclaim(tid, sid, H5P_DEFAULT, buf) < 0)
- goto out;
+ if (is_new_ref) {
+ if (H5Rdestroy(&nref_to_ds) < 0)
+ goto out;
+ }
if (H5Sclose(sid) < 0)
goto out;
if (H5Tclose(tid) < 0)
goto out;
if (H5Aclose(aid) < 0)
goto out;
-
+ HDfree(buf[idx].p);
+ buf[idx].p = NULL;
HDfree(buf);
buf = NULL;
}
@@ -302,12 +374,20 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
/* iterate all the REFs in this dimension IDX */
for (i = 0; i < (int)buf[idx].len; i++) {
/* get the reference */
- ref_j = ((hobj_ref_t *)buf[idx].p)[i];
+ if (is_new_ref) {
+ nref_j = ((H5R_ref_t *)buf[idx].p)[i];
- /* get the scale id for this REF */
- if ((dsid_j = H5Rdereference2(did, H5P_DEFAULT, H5R_OBJECT, &ref_j)) < 0)
- goto out;
+ /* get the scale id for this REF */
+ if ((dsid_j = H5Ropen_object(&nref_j, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+ }
+ else {
+ ref_j = ((hobj_ref_t *)buf[idx].p)[i];
+ /* get the scale id for this REF */
+ if ((dsid_j = H5Rdereference2(did, H5P_DEFAULT, H5R_OBJECT, &ref_j)) < 0)
+ goto out;
+ }
/* get info for DS in the parameter list */
if (H5Oget_info3(dsid, &oi1, H5O_INFO_BASIC) < 0)
goto out;
@@ -335,17 +415,33 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
/* we are adding one more DS to this dimension */
if (buf[idx].len > 0) {
buf[idx].len++;
- len = buf[idx].len;
- buf[idx].p = HDrealloc(buf[idx].p, len * sizeof(hobj_ref_t));
- ((hobj_ref_t *)buf[idx].p)[len - 1] = ref_to_ds;
+ len = buf[idx].len;
+ if (is_new_ref) {
+ buf[idx].p = HDrealloc(buf[idx].p, len * sizeof(H5R_ref_t));
+ ((H5R_ref_t *)buf[idx].p)[len - 1] = nref_to_ds;
+ }
+ else {
+ buf[idx].p = HDrealloc(buf[idx].p, len * sizeof(hobj_ref_t));
+ ((hobj_ref_t *)buf[idx].p)[len - 1] = ref_to_ds;
+ }
} /* end if */
else {
/* store the REF information in the index of the dataset that has the DS */
- buf[idx].len = 1;
- buf[idx].p = HDmalloc(sizeof(hobj_ref_t));
- ((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds;
+ buf[idx].len = 1;
+ if (is_new_ref) {
+ buf[idx].p = HDmalloc(sizeof(H5R_ref_t));
+ ((H5R_ref_t *)buf[idx].p)[0] = nref_to_ds;
+ }
+ else {
+ buf[idx].p = HDmalloc(sizeof(hobj_ref_t));
+ ((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds;
+ }
} /* end else */
} /* end if */
+ else {
+ if (is_new_ref && H5Rdestroy(&nref_to_ds) < 0)
+ goto out;
+ }
/* write the attribute with the new references */
if (H5Awrite(aid, tid, buf) < 0)
@@ -385,29 +481,40 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
goto out;
/* create the compound datatype for the attribute "REFERENCE_LIST" */
- if ((tid = H5Tcreate(H5T_COMPOUND, sizeof(ds_list_t))) < 0)
- goto out;
-
- /* insert reference field */
- if (H5Tinsert(tid, "dataset", HOFFSET(ds_list_t, ref), H5T_STD_REF_OBJ) < 0)
- goto out;
-
- /* insert dimension idx of the dataset field */
- if (H5Tinsert(tid, "dimension", HOFFSET(ds_list_t, dim_idx), H5T_NATIVE_INT) < 0)
- goto out;
+ if (is_new_ref) {
+ if ((tid = H5Tcreate(H5T_COMPOUND, sizeof(nds_list_t))) < 0)
+ goto out;
+ if (H5Tinsert(tid, "dataset", HOFFSET(nds_list_t, ref), H5T_STD_REF) < 0)
+ goto out;
+ if (H5Tinsert(tid, "dimension", HOFFSET(nds_list_t, dim_idx), H5T_NATIVE_UINT) < 0)
+ goto out;
+ }
+ else {
+ if ((tid = H5Tcreate(H5T_COMPOUND, sizeof(ds_list_t))) < 0)
+ goto out;
+ if (H5Tinsert(tid, "dataset", HOFFSET(ds_list_t, ref), H5T_STD_REF_OBJ) < 0)
+ goto out;
+ if (H5Tinsert(tid, "dimension", HOFFSET(ds_list_t, dim_idx), H5T_NATIVE_UINT) < 0)
+ goto out;
+ }
/* create the attribute */
if ((aid = H5Acreate2(dsid, REFERENCE_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
/* store the IDX information */
- dsl.dim_idx = idx;
-
- /* write the attribute with the reference */
- if (H5Awrite(aid, tid, &dsl) < 0)
- goto out;
-
- /* close */
+ if (is_new_ref) {
+ ndsl.dim_idx = idx;
+ if (H5Awrite(aid, tid, &ndsl) < 0)
+ goto out;
+ if (H5Rdestroy(&ndsl.ref) < 0)
+ goto out;
+ }
+ else {
+ dsl.dim_idx = idx;
+ if (H5Awrite(aid, tid, &dsl) < 0)
+ goto out;
+ }
if (H5Sclose(sid) < 0)
goto out;
if (H5Tclose(tid) < 0)
@@ -421,6 +528,9 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
*-------------------------------------------------------------------------
*/
else if (has_reflist == 1) {
+ hid_t tmp_id; /* Temporary DS dataset ID to recreate reference */
+ int j;
+
if ((aid = H5Aopen(dsid, REFERENCE_LIST, H5P_DEFAULT)) < 0)
goto out;
@@ -428,7 +538,7 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
goto out;
/* get native type to read attribute REFERENCE_LIST */
- if ((ntid = H5DS_get_REFLIST_type()) < 0)
+ if ((ntid = H5Tget_native_type(tid, H5T_DIR_ASCEND)) < 0)
goto out;
/* get and save the old reference(s) */
@@ -439,17 +549,22 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
goto out;
nelmts++;
-
- dsbuf = (ds_list_t *)HDmalloc((size_t)nelmts * sizeof(ds_list_t));
- if (dsbuf == NULL)
- goto out;
-
- if (H5Aread(aid, ntid, dsbuf) < 0)
- goto out;
+ if (is_new_ref) {
+ ndsbuf = (nds_list_t *)HDmalloc((size_t)nelmts * sizeof(nds_list_t));
+ if (ndsbuf == NULL)
+ goto out;
+ if (H5Aread(aid, ntid, ndsbuf) < 0)
+ goto out;
+ }
+ else {
+ dsbuf = (ds_list_t *)HDmalloc((size_t)nelmts * sizeof(ds_list_t));
+ if (dsbuf == NULL)
+ goto out;
+ if (H5Aread(aid, ntid, dsbuf) < 0)
+ goto out;
+ }
/* close */
- if (H5Sclose(sid) < 0)
- goto out;
if (H5Aclose(aid) < 0)
goto out;
@@ -458,40 +573,93 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
*-------------------------------------------------------------------------
*/
+ /* Allocate new buffer to copy old references and add new one */
+
+ if (is_new_ref) {
+ ndsbuf_w = (nds_list_t *)HDmalloc((size_t)nelmts * sizeof(nds_list_t));
+ if (ndsbuf_w == NULL)
+ goto out;
+ }
+ else {
+ dsbuf_w = (ds_list_t *)HDmalloc((size_t)nelmts * sizeof(ds_list_t));
+ if (dsbuf_w == NULL)
+ goto out;
+ }
+ /* Recreate the references we read from the existing "REFERENCE_LIST" attribute */
+ for (j = 0; j < nelmts - 1; j++) {
+ if (is_new_ref) {
+ ndsbuf_w[j].dim_idx = ndsbuf[j].dim_idx;
+ tmp_id = H5Ropen_object(&ndsbuf[j].ref, H5P_DEFAULT, H5P_DEFAULT);
+ if (tmp_id < 0)
+ goto out;
+ if (H5Rcreate_object(tmp_id, ".", H5P_DEFAULT, &ndsbuf_w[j].ref) < 0) {
+ H5Dclose(tmp_id);
+ goto out;
+ }
+ }
+ else {
+ dsbuf_w[j] = dsbuf[j];
+ }
+ }
+ /* store the IDX information (index of the dataset that has the DS) */
+ if (is_new_ref) {
+ ndsl.dim_idx = idx;
+ ndsbuf_w[nelmts - 1] = ndsl;
+ }
+ else {
+ dsl.dim_idx = idx;
+ dsbuf_w[nelmts - 1] = dsl;
+ }
+
/* the attribute must be deleted, in order to the new one can reflect the changes*/
if (H5Adelete(dsid, REFERENCE_LIST) < 0)
goto out;
- /* store the IDX information (index of the dataset that has the DS) */
- dsl.dim_idx = idx;
- dsbuf[nelmts - 1] = dsl;
-
/* create a new data space for the new references array */
dims[0] = (hsize_t)nelmts;
- if ((sid = H5Screate_simple(1, dims, NULL)) < 0)
+ if ((sid_w = H5Screate_simple(1, dims, NULL)) < 0)
goto out;
/* create the attribute again with the changes of space */
- if ((aid = H5Acreate2(dsid, REFERENCE_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ if ((aid = H5Acreate2(dsid, REFERENCE_LIST, tid, sid_w, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
/* write the attribute with the new references */
- if (H5Awrite(aid, ntid, dsbuf) < 0)
- goto out;
-
- /* close */
+ if (is_new_ref) {
+ if (H5Awrite(aid, ntid, ndsbuf_w) < 0)
+ goto out;
+ if (H5Treclaim(tid, sid, H5P_DEFAULT, ndsbuf_w) < 0)
+ goto out;
+ }
+ else {
+ if (H5Awrite(aid, ntid, dsbuf_w) < 0)
+ goto out;
+ if (H5Treclaim(tid, sid, H5P_DEFAULT, dsbuf_w) < 0)
+ goto out;
+ }
if (H5Sclose(sid) < 0)
goto out;
+ if (H5Sclose(sid_w) < 0)
+ goto out;
if (H5Tclose(tid) < 0)
goto out;
if (H5Aclose(aid) < 0)
goto out;
if (H5Tclose(ntid) < 0)
goto out;
-
- HDfree(dsbuf);
- dsbuf = NULL;
+ if (is_new_ref) {
+ HDfree(ndsbuf);
+ dsbuf = NULL;
+ HDfree(ndsbuf_w);
+ dsbuf = NULL;
+ }
+ else {
+ HDfree(dsbuf);
+ dsbuf = NULL;
+ HDfree(dsbuf_w);
+ dsbuf = NULL;
+ }
} /* has_reflist */
/*-------------------------------------------------------------------------
@@ -515,6 +683,8 @@ out:
HDfree(buf);
if (dsbuf)
HDfree(dsbuf);
+ if (dsbuf_w)
+ HDfree(dsbuf_w);
H5E_BEGIN_TRY
{
@@ -554,27 +724,35 @@ out:
herr_t
H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
{
- int has_dimlist;
- int has_reflist;
- hssize_t nelmts;
- hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
- hid_t did_i; /* dataset ID in REFERENCE_LIST */
- hid_t sid; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t ntid = -1; /* attribute native type ID */
- hid_t aid = -1; /* attribute ID */
- int rank; /* rank of dataset */
- ds_list_t * dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
- hsize_t dims[1]; /* dimension of the "REFERENCE_LIST" array */
- hobj_ref_t ref; /* reference to the DS */
- hvl_t * buf = NULL; /* VL buffer to store in the attribute */
- int i;
- size_t j;
- hssize_t ii;
- H5O_info2_t did_oi, dsid_oi, tmp_oi;
- int found_dset = 0, found_ds = 0;
- int have_ds = 0;
- htri_t is_scale;
+ int has_dimlist;
+ int has_reflist;
+ hssize_t nelmts;
+ hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
+ hid_t did_i; /* dataset ID in REFERENCE_LIST */
+ hid_t sid = H5I_INVALID_HID; /* space ID */
+ hid_t sid_w = H5I_INVALID_HID; /* space ID */
+ hid_t tid = H5I_INVALID_HID; /* attribute type ID */
+ hid_t ntid = H5I_INVALID_HID; /* attribute native type ID */
+ hid_t aid = H5I_INVALID_HID; /* attribute ID */
+ int rank; /* rank of dataset */
+ nds_list_t * ndsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
+ nds_list_t * ndsbuf_w = NULL; /* array of attribute data in the DS pointing to the dataset to write*/
+ ds_list_t * dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
+ ds_list_t * dsbuf_w = NULL; /* array of attribute data in the DS pointing to the dataset to write*/
+ hsize_t dims[1]; /* dimension of the "REFERENCE_LIST" array */
+ H5R_ref_t nref;
+ hobj_ref_t ref; /* reference to the DS */
+ hvl_t * buf = NULL; /* VL buffer to store in the attribute */
+ int i;
+ size_t j;
+ hssize_t ii;
+ H5O_info2_t did_oi, dsid_oi, tmp_oi;
+ int found_dset = 0, found_ds = 0;
+ int have_ds = 0;
+ htri_t is_scale;
+ hbool_t is_new_ref;
+ unsigned int tmp_idx;
+ hid_t tmp_id;
/*-------------------------------------------------------------------------
* parameter checking
@@ -612,9 +790,18 @@ H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
} /* end if */
/*-------------------------------------------------------------------------
- * Find "DIMENSION_LIST"
+ * determine if old or new references should be used
*-------------------------------------------------------------------------
*/
+ is_new_ref = H5DSwith_new_ref(did);
+ if (is_new_ref < 0)
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * find "DIMENSION_LIST"
+ *-------------------------------------------------------------------------
+ */
+
/* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
if ((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
return FAIL;
@@ -676,13 +863,22 @@ H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
/* reset */
if (buf[idx].len > 0) {
for (j = 0; j < buf[idx].len; j++) {
- /* get the reference */
- ref = ((hobj_ref_t *)buf[idx].p)[j];
+ if (is_new_ref) {
+ /* get the reference */
+ nref = ((H5R_ref_t *)buf[idx].p)[j];
- /* get the DS id */
- if ((dsid_j = H5Rdereference2(did, H5P_DEFAULT, H5R_OBJECT, &ref)) < 0)
- goto out;
+ /* get the scale id for this REF */
+ if ((dsid_j = H5Ropen_object(&nref, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+ }
+ else {
+ /* get the reference */
+ ref = ((hobj_ref_t *)buf[idx].p)[j];
+ /* get the DS id */
+ if ((dsid_j = H5Rdereference2(did, H5P_DEFAULT, H5R_OBJECT, &ref)) < 0)
+ goto out;
+ }
/* get info for this DS */
if (H5Oget_info3(dsid_j, &tmp_oi, H5O_INFO_BASIC) < 0)
goto out;
@@ -708,8 +904,14 @@ H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
size_t len = buf[idx].len;
- if (j < len - 1)
- ((hobj_ref_t *)buf[idx].p)[j] = ((hobj_ref_t *)buf[idx].p)[len - 1];
+ if (j < len - 1) {
+ if (is_new_ref) {
+ ((H5R_ref_t *)buf[idx].p)[j] = ((H5R_ref_t *)buf[idx].p)[len - 1];
+ }
+ else {
+ ((hobj_ref_t *)buf[idx].p)[j] = ((hobj_ref_t *)buf[idx].p)[len - 1];
+ }
+ }
len = --buf[idx].len;
if (len == 0) {
HDfree(buf[idx].p);
@@ -770,7 +972,7 @@ H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
goto out;
/* get native type to read attribute REFERENCE_LIST */
- if ((ntid = H5DS_get_REFLIST_type()) < 0)
+ if ((ntid = H5Tget_native_type(tid, H5T_DIR_ASCEND)) < 0)
goto out;
/* get and save the old reference(s) */
@@ -780,22 +982,65 @@ H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
if ((nelmts = H5Sget_simple_extent_npoints(sid)) < 0)
goto out;
- dsbuf = (ds_list_t *)HDmalloc((size_t)nelmts * sizeof(ds_list_t));
- if (dsbuf == NULL)
- goto out;
-
- if (H5Aread(aid, ntid, dsbuf) < 0)
- goto out;
-
+ if (is_new_ref) {
+ ndsbuf = (nds_list_t *)HDmalloc((size_t)nelmts * sizeof(nds_list_t));
+ if (ndsbuf == NULL)
+ goto out;
+ if (H5Aread(aid, ntid, ndsbuf) < 0)
+ goto out;
+ ndsbuf_w = (nds_list_t *)HDmalloc((size_t)nelmts * sizeof(nds_list_t));
+ if (ndsbuf_w == NULL)
+ goto out;
+ }
+ else {
+ dsbuf = (ds_list_t *)HDmalloc((size_t)nelmts * sizeof(ds_list_t));
+ if (dsbuf == NULL)
+ goto out;
+ if (H5Aread(aid, ntid, dsbuf) < 0)
+ goto out;
+ dsbuf_w = (ds_list_t *)HDmalloc((size_t)nelmts * sizeof(ds_list_t));
+ if (dsbuf_w == NULL)
+ goto out;
+ }
+ /* Recreate the references we read from the existing "REFERENCE_LIST" attribute */
+ for (i = 0; i < nelmts; i++) {
+ if (is_new_ref) {
+ ndsbuf_w[i].dim_idx = ndsbuf[i].dim_idx;
+ tmp_id = H5Ropen_object(&ndsbuf[i].ref, H5P_DEFAULT, H5P_DEFAULT);
+ if (tmp_id < 0)
+ goto out;
+ if (H5Rcreate_object(tmp_id, ".", H5P_DEFAULT, &ndsbuf_w[i].ref) < 0) {
+ H5Dclose(tmp_id);
+ goto out;
+ }
+ H5Dclose(tmp_id);
+ }
+ else {
+ dsbuf_w[i] = dsbuf[i];
+ }
+ }
for (ii = 0; ii < nelmts; ii++) {
/* First check if we have the same dimension index */
- if (idx == dsbuf[ii].dim_idx) {
+ if (is_new_ref) {
+ tmp_idx = ndsbuf_w[ii].dim_idx;
+ }
+ else {
+ tmp_idx = dsbuf_w[ii].dim_idx;
+ }
+ if (idx == tmp_idx) {
/* get the reference to the dataset */
- ref = dsbuf[ii].ref;
-
- /* get the dataset id */
- if ((did_i = H5Rdereference2(did, H5P_DEFAULT, H5R_OBJECT, &ref)) < 0)
- goto out;
+ if (is_new_ref) {
+ /* get the dataset id */
+ nref = ndsbuf_w[ii].ref;
+ if ((did_i = H5Ropen_object(&nref, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+ }
+ else {
+ /* get the dataset id */
+ ref = dsbuf_w[ii].ref;
+ if ((did_i = H5Rdereference2(did, H5P_DEFAULT, H5R_OBJECT, &ref)) < 0)
+ goto out;
+ }
/* get info for this dataset */
if (H5Oget_info3(did_i, &tmp_oi, H5O_INFO_BASIC) < 0)
@@ -813,7 +1058,12 @@ H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
goto out;
if (!token_cmp) {
/* copy the last one to replace the one which is found */
- dsbuf[ii] = dsbuf[nelmts - 1];
+ if (is_new_ref) {
+ ndsbuf_w[ii] = ndsbuf_w[nelmts - 1];
+ }
+ else {
+ dsbuf_w[ii] = dsbuf_w[nelmts - 1];
+ }
nelmts--;
found_dset = 1;
break;
@@ -822,9 +1072,7 @@ H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
} /* if we have the same dimension index */
} /* ii */
- /* close space and attribute */
- if (H5Sclose(sid) < 0)
- goto out;
+ /* close attribute */
if (H5Aclose(aid) < 0)
goto out;
@@ -851,32 +1099,69 @@ H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
/* create a new data space for the new references array */
dims[0] = (hsize_t)nelmts;
- if ((sid = H5Screate_simple(1, dims, NULL)) < 0)
+ if ((sid_w = H5Screate_simple(1, dims, NULL)) < 0)
goto out;
/* create the attribute again with the changes of space */
- if ((aid = H5Acreate2(dsid, REFERENCE_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ if ((aid = H5Acreate2(dsid, REFERENCE_LIST, tid, sid_w, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
/* write the new attribute with the new references */
- if (H5Awrite(aid, ntid, dsbuf) < 0)
- goto out;
+ if (is_new_ref) {
+ if (H5Awrite(aid, ntid, ndsbuf_w) < 0)
+ goto out;
+ }
+ else {
+ if (H5Awrite(aid, ntid, dsbuf_w) < 0)
+ goto out;
+ }
- /* close space and attribute */
- if (H5Sclose(sid) < 0)
- goto out;
if (H5Aclose(aid) < 0)
goto out;
} /* nelmts */
+ /* Free refrences */
+ if (is_new_ref) {
+ if (H5Treclaim(tid, sid, H5P_DEFAULT, ndsbuf) < 0)
+ goto out;
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (sid_w > 0) {
+ if (H5Treclaim(tid, sid_w, H5P_DEFAULT, ndsbuf_w) < 0)
+ goto out;
+ if (H5Sclose(sid_w) < 0)
+ goto out;
+ }
+ }
+ else {
+ if (H5Treclaim(tid, sid, H5P_DEFAULT, dsbuf) < 0)
+ goto out;
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (sid_w > 0) {
+ if (H5Treclaim(tid, sid_w, H5P_DEFAULT, dsbuf_w) < 0)
+ goto out;
+ if (H5Sclose(sid_w) < 0)
+ goto out;
+ }
+ }
/* close type */
if (H5Tclose(tid) < 0)
goto out;
if (H5Tclose(ntid) < 0)
goto out;
-
- HDfree(dsbuf);
- dsbuf = NULL;
+ if (is_new_ref) {
+ HDfree(ndsbuf);
+ HDfree(ndsbuf_w);
+ ndsbuf = NULL;
+ ndsbuf_w = NULL;
+ }
+ else {
+ HDfree(dsbuf);
+ HDfree(dsbuf_w);
+ dsbuf = NULL;
+ dsbuf_w = NULL;
+ }
return SUCCEED;
@@ -889,6 +1174,14 @@ out:
H5Tclose(ntid);
H5Tclose(tid);
+ if (ndsbuf) {
+ HDfree(ndsbuf);
+ ndsbuf = NULL;
+ }
+ if (ndsbuf_w) {
+ HDfree(ndsbuf_w);
+ ndsbuf_w = NULL;
+ }
if (dsbuf) {
HDfree(dsbuf);
dsbuf = NULL;
@@ -936,21 +1229,24 @@ H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
int has_dimlist;
int has_reflist;
hssize_t nelmts;
- hid_t sid; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t ntid = -1; /* attribute native type ID */
- hid_t aid = -1; /* attribute ID */
- int rank; /* rank of dataset */
- ds_list_t * dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
- hobj_ref_t ref; /* reference to the DS */
- hvl_t * buf = NULL; /* VL buffer to store in the attribute */
- hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
- hid_t did_i; /* dataset ID in REFERENCE_LIST */
+ hid_t sid; /* space ID */
+ hid_t tid = H5I_INVALID_HID; /* attribute type ID */
+ hid_t ntid = H5I_INVALID_HID; /* attribute native type ID */
+ hid_t aid = H5I_INVALID_HID; /* attribute ID */
+ int rank; /* rank of dataset */
+ nds_list_t *ndsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
+ ds_list_t * dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
+ H5R_ref_t nref; /* reference to the DS */
+ hobj_ref_t ref; /* reference to the DS */
+ hvl_t * buf = NULL; /* VL buffer to store in the attribute */
+ hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
+ hid_t did_i; /* dataset ID in REFERENCE_LIST */
H5O_info2_t oi1, oi2, oi3, oi4;
H5I_type_t it1, it2;
int i;
int found_dset = 0, found_ds = 0;
htri_t is_scale;
+ hbool_t is_new_ref;
/*-------------------------------------------------------------------------
* parameter checking
@@ -982,6 +1278,15 @@ H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
return FAIL;
} /* end if */
+ /*-------------------------------------------------------------------------
+ * determine if old or new references should be used
+ *-------------------------------------------------------------------------
+ */
+
+ is_new_ref = H5DSwith_new_ref(did);
+ if (is_new_ref < 0)
+ return FAIL;
+
/* get ID type */
if ((it1 = H5Iget_type(did)) < 0)
return FAIL;
@@ -1042,12 +1347,22 @@ H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
/* iterate all the REFs in this dimension IDX */
for (i = 0; i < (int)buf[idx].len; i++) {
- /* get the reference */
- ref = ((hobj_ref_t *)buf[idx].p)[i];
+ if (is_new_ref) {
+ /* get the reference */
+ nref = ((H5R_ref_t *)buf[idx].p)[i];
- /* get the scale id for this REF */
- if ((dsid_j = H5Rdereference2(did, H5P_DEFAULT, H5R_OBJECT, &ref)) < 0)
- goto out;
+ /* get the scale id for this REF */
+ if ((dsid_j = H5Ropen_object(&nref, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+ }
+ else {
+ /* get the reference */
+ ref = ((hobj_ref_t *)buf[idx].p)[i];
+
+ /* get the scale id for this REF */
+ if ((dsid_j = H5Rdereference2(did, H5P_DEFAULT, H5R_OBJECT, &ref)) < 0)
+ goto out;
+ }
/* get info for DS in the parameter list */
if (H5Oget_info3(dsid, &oi1, H5O_INFO_BASIC) < 0)
@@ -1107,7 +1422,7 @@ H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
goto out;
/* get native type to read REFERENCE_LIST attribute */
- if ((ntid = H5DS_get_REFLIST_type()) < 0)
+ if ((ntid = H5Tget_native_type(tid, H5T_DIR_ASCEND)) < 0)
goto out;
/* get and save the old reference(s) */
@@ -1117,13 +1432,20 @@ H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
if ((nelmts = H5Sget_simple_extent_npoints(sid)) < 0)
goto out;
- dsbuf = (ds_list_t *)HDmalloc((size_t)nelmts * sizeof(ds_list_t));
-
- if (dsbuf == NULL)
- goto out;
-
- if (H5Aread(aid, ntid, dsbuf) < 0)
- goto out;
+ if (is_new_ref) {
+ ndsbuf = (nds_list_t *)HDmalloc((size_t)nelmts * sizeof(nds_list_t));
+ if (ndsbuf == NULL)
+ goto out;
+ if (H5Aread(aid, ntid, ndsbuf) < 0)
+ goto out;
+ }
+ else {
+ dsbuf = (ds_list_t *)HDmalloc((size_t)nelmts * sizeof(ds_list_t));
+ if (dsbuf == NULL)
+ goto out;
+ if (H5Aread(aid, ntid, dsbuf) < 0)
+ goto out;
+ }
/*-------------------------------------------------------------------------
* iterate
@@ -1131,40 +1453,58 @@ H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
*/
for (i = 0; i < nelmts; i++) {
- /* get the reference */
- ref = dsbuf[i].ref;
- /* the reference was not deleted */
- if (ref) {
+ if (is_new_ref) {
+ nref = ndsbuf[i].ref;
+ /* get the dataset id */
+ if ((did_i = H5Ropen_object(&nref, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+ }
+ else {
+ ref = dsbuf[i].ref;
/* get the dataset id */
if ((did_i = H5Rdereference2(did, H5P_DEFAULT, H5R_OBJECT, &ref)) < 0)
goto out;
+ }
- /* get info for dataset in the parameter list */
- if (H5Oget_info3(did, &oi3, H5O_INFO_BASIC) < 0)
- goto out;
+ /* get info for dataset in the parameter list */
+ if (H5Oget_info3(did, &oi3, H5O_INFO_BASIC) < 0)
+ goto out;
- /* get info for this dataset */
- if (H5Oget_info3(did_i, &oi4, H5O_INFO_BASIC) < 0)
- goto out;
+ /* get info for this dataset */
+ if (H5Oget_info3(did_i, &oi4, H5O_INFO_BASIC) < 0)
+ goto out;
- /* same object */
- if (oi3.fileno == oi4.fileno) {
- int token_cmp;
+ /* same object */
+ if (oi3.fileno == oi4.fileno) {
+ int token_cmp;
- if (H5Otoken_cmp(did, &oi3.token, &oi4.token, &token_cmp) < 0)
- goto out;
+ if (H5Otoken_cmp(did, &oi3.token, &oi4.token, &token_cmp) < 0)
+ goto out;
+ if (is_new_ref) {
+ if (!token_cmp && (idx == ndsbuf[i].dim_idx))
+ found_dset = 1;
+ }
+ else {
if (!token_cmp && (idx == dsbuf[i].dim_idx))
found_dset = 1;
- } /* end if */
+ }
+ } /* end if */
- /* close the dereferenced dataset */
- if (H5Dclose(did_i) < 0)
- goto out;
- } /* if */
- } /* i */
+ /* close the dereferenced dataset */
+ if (H5Dclose(did_i) < 0)
+ goto out;
+ } /* for */
/* close */
+ if (is_new_ref) {
+ if (H5Treclaim(ntid, sid, H5P_DEFAULT, ndsbuf) < 0)
+ goto out;
+ }
+ else {
+ if (H5Treclaim(ntid, sid, H5P_DEFAULT, dsbuf) < 0)
+ goto out;
+ }
if (H5Sclose(sid) < 0)
goto out;
if (H5Tclose(ntid) < 0)
@@ -1174,8 +1514,14 @@ H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
if (H5Aclose(aid) < 0)
goto out;
- HDfree(dsbuf);
- dsbuf = NULL;
+ if (ndsbuf) {
+ HDfree(ndsbuf);
+ ndsbuf = NULL;
+ }
+ if (dsbuf) {
+ HDfree(dsbuf);
+ dsbuf = NULL;
+ }
} /* has_reflist */
if (found_ds && found_dset)
@@ -1198,6 +1544,10 @@ out:
HDfree(buf);
buf = NULL;
}
+ if (ndsbuf) {
+ HDfree(ndsbuf);
+ ndsbuf = NULL;
+ }
if (dsbuf) {
HDfree(dsbuf);
dsbuf = NULL;
@@ -1249,17 +1599,19 @@ H5DSiterate_scales(hid_t did, unsigned int dim, int *ds_idx, H5DS_iterate_t visi
{
hid_t scale_id;
int rank;
- hobj_ref_t ref; /* reference to the DS */
- hid_t sid; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- hvl_t * buf = NULL; /* VL buffer to store in the attribute */
- H5I_type_t it; /* ID type */
+ H5R_ref_t nref; /* reference to the DS */
+ hobj_ref_t ref; /* reference to the DS */
+ hid_t sid; /* space ID */
+ hid_t tid = H5I_INVALID_HID; /* attribute type ID */
+ hid_t aid = H5I_INVALID_HID; /* attribute ID */
+ hvl_t * buf = NULL; /* VL buffer to store in the attribute */
+ H5I_type_t it; /* ID type */
herr_t ret_value = 0;
int j_idx;
int nscales;
int has_dimlist;
int i;
+ hbool_t is_new_ref;
/*-------------------------------------------------------------------------
* parameter checking
@@ -1272,6 +1624,15 @@ H5DSiterate_scales(hid_t did, unsigned int dim, int *ds_idx, H5DS_iterate_t visi
if (H5I_DATASET != it)
return FAIL;
+ /*-------------------------------------------------------------------------
+ * determine if old or new references should be used
+ *-------------------------------------------------------------------------
+ */
+
+ is_new_ref = H5DSwith_new_ref(did);
+ if (is_new_ref < 0)
+ return FAIL;
+
/* get the number of scales assotiated with this DIM */
if ((nscales = H5DSget_num_scales(did, dim)) < 0)
return FAIL;
@@ -1330,17 +1691,32 @@ H5DSiterate_scales(hid_t did, unsigned int dim, int *ds_idx, H5DS_iterate_t visi
/* iterate */
for (i = j_idx; i < nscales; i++) {
- /* get the reference */
- ref = ((hobj_ref_t *)buf[dim].p)[i];
-
- /* disable error reporting, the ID might refer to a deleted dataset */
- H5E_BEGIN_TRY
- {
- /* get the DS id */
- if ((scale_id = H5Rdereference2(did, H5P_DEFAULT, H5R_OBJECT, &ref)) < 0)
- goto out;
+ if (is_new_ref) {
+ /* get the reference */
+ nref = ((H5R_ref_t *)buf[dim].p)[i];
+
+ /* disable error reporting, the ID might refer to a deleted dataset */
+ H5E_BEGIN_TRY
+ {
+ /* get the DS id */
+ if ((scale_id = H5Ropen_object(&nref, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+ }
+ H5E_END_TRY;
+ }
+ else {
+ /* get the reference */
+ ref = ((hobj_ref_t *)buf[dim].p)[i];
+
+ /* disable error reporting, the ID might refer to a deleted dataset */
+ H5E_BEGIN_TRY
+ {
+ /* get the DS id */
+ if ((scale_id = H5Rdereference2(did, H5P_DEFAULT, H5R_OBJECT, &ref)) < 0)
+ goto out;
+ }
+ H5E_END_TRY;
}
- H5E_END_TRY;
/* set the return IDX OUT value at current scale index */
if (ds_idx != NULL) {
@@ -1413,12 +1789,12 @@ herr_t
H5DSset_label(hid_t did, unsigned int idx, const char *label)
{
int has_labels;
- hid_t sid = -1; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- int rank; /* rank of dataset */
- hsize_t dims[1]; /* dimensions of dataset */
- H5I_type_t it; /* ID type */
+ hid_t sid = H5I_INVALID_HID; /* space ID */
+ hid_t tid = H5I_INVALID_HID; /* attribute type ID */
+ hid_t aid = H5I_INVALID_HID; /* attribute ID */
+ int rank; /* rank of dataset */
+ hsize_t dims[1]; /* dimensions of dataset */
+ H5I_type_t it; /* ID type */
unsigned int i;
union { /* union is needed to eliminate compiler warnings about */
char ** buf; /* discarding the 'const' qualifier in the free */
@@ -1616,12 +1992,12 @@ ssize_t
H5DSget_label(hid_t did, unsigned int idx, char *label, size_t size)
{
int has_labels;
- hid_t sid = -1; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- int rank; /* rank of dataset */
- char ** buf = NULL; /* buffer to store in the attribute */
- H5I_type_t it; /* ID type */
+ hid_t sid = H5I_INVALID_HID; /* space ID */
+ hid_t tid = H5I_INVALID_HID; /* attribute type ID */
+ hid_t aid = H5I_INVALID_HID; /* attribute ID */
+ int rank; /* rank of dataset */
+ char ** buf = NULL; /* buffer to store in the attribute */
+ H5I_type_t it; /* ID type */
size_t nbytes = 0;
size_t copy_len;
int i;
@@ -1764,10 +2140,10 @@ out:
ssize_t
H5DSget_scale_name(hid_t did, char *name, size_t size)
{
- hid_t aid; /* attribute ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t sid; /* space ID */
- H5I_type_t it; /* ID type */
+ hid_t aid = H5I_INVALID_HID; /* attribute ID */
+ hid_t tid = H5I_INVALID_HID; /* attribute type ID */
+ hid_t sid = H5I_INVALID_HID; /* space ID */
+ H5I_type_t it; /* ID type */
size_t nbytes;
size_t copy_len;
int has_name;
@@ -1881,13 +2257,13 @@ out:
htri_t
H5DSis_scale(hid_t did)
{
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- herr_t attr_class; /* has the "CLASS" attribute */
- htri_t is_ds = -1; /* set to "not a dimension scale" */
- H5I_type_t it; /* type of identifier */
- char * buf = NULL; /* buffer to read name of attribute */
- size_t string_size; /* size of storage for the attribute */
+ hid_t tid = H5I_INVALID_HID; /* attribute type ID */
+ hid_t aid = H5I_INVALID_HID; /* attribute ID */
+ herr_t attr_class; /* has the "CLASS" attribute */
+ htri_t is_ds = -1; /* set to "not a dimension scale" */
+ H5I_type_t it; /* type of identifier */
+ char * buf = NULL; /* buffer to read name of attribute */
+ size_t string_size; /* size of storage for the attribute */
H5T_class_t type_class;
H5T_str_t strpad;
@@ -1995,12 +2371,12 @@ int
H5DSget_num_scales(hid_t did, unsigned int idx)
{
int has_dimlist;
- hid_t sid; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- int rank; /* rank of dataset */
- hvl_t * buf = NULL; /* VL buffer to store in the attribute */
- H5I_type_t it; /* ID type */
+ hid_t sid; /* space ID */
+ hid_t tid = H5I_INVALID_HID; /* attribute type ID */
+ hid_t aid = H5I_INVALID_HID; /* attribute ID */
+ int rank; /* rank of dataset */
+ hvl_t * buf = NULL; /* VL buffer to store in the attribute */
+ H5I_type_t it; /* ID type */
int nscales;
/*-------------------------------------------------------------------------
@@ -2112,12 +2488,12 @@ out:
static herr_t
H5DS_is_reserved(hid_t did)
{
- int has_class;
- hid_t tid = -1;
- hid_t aid = -1;
- char * buf; /* Name of attribute */
- hsize_t storage_size; /* Size of storage for attribute */
- herr_t ret;
+ int has_class;
+ hid_t tid = H5I_INVALID_HID;
+ hid_t aid = H5I_INVALID_HID;
+ char * buf = NULL; /* Name of attribute */
+ size_t string_size; /* Size of storage for attribute */
+ herr_t ret;
/* try to find the attribute "CLASS" on the dataset */
if ((has_class = H5LT_find_attribute(did, "CLASS")) < 0)
@@ -2142,10 +2518,10 @@ H5DS_is_reserved(hid_t did)
goto out;
/* allocate buffer large enough to hold string */
- if ((storage_size = H5Aget_storage_size(aid)) == 0)
+ if ((string_size = H5Tget_size(tid)) == 0)
goto out;
- buf = (char *)HDmalloc((size_t)storage_size * sizeof(char) + 1);
+ buf = (char *)HDmalloc((size_t)string_size * sizeof(char));
if (buf == NULL)
goto out;
@@ -2174,51 +2550,11 @@ H5DS_is_reserved(hid_t did)
out:
H5E_BEGIN_TRY
{
+ if (buf)
+ HDfree(buf);
H5Tclose(tid);
H5Aclose(aid);
}
H5E_END_TRY;
return FAIL;
}
-
-/*-------------------------------------------------------------------------
- * Function: H5DS_get_REFLIST_type
- *
- * Purpose: This is a helper function to return a native type for
- * the REFERENCE_LIST attribute.
- *
- * Return: Type identifier on success and negative on failure
- *
- * Programmer: Elena Pourmal
- *
- * Date: May 22, 2010
- *
- *-------------------------------------------------------------------------
- */
-static hid_t
-H5DS_get_REFLIST_type(void)
-{
- hid_t ntid_t = -1;
-
- /* Build native type that corresponds to compound datatype
- used to store ds_list_t structure in the REFERENCE_LIST
- attribute */
-
- if ((ntid_t = H5Tcreate(H5T_COMPOUND, sizeof(ds_list_t))) < 0)
- goto out;
-
- if (H5Tinsert(ntid_t, "dataset", HOFFSET(ds_list_t, ref), H5T_STD_REF_OBJ) < 0)
- goto out;
-
- if (H5Tinsert(ntid_t, "dimension", HOFFSET(ds_list_t, dim_idx), H5T_NATIVE_INT) < 0)
- goto out;
-
- return ntid_t;
-out:
- H5E_BEGIN_TRY
- {
- H5Tclose(ntid_t);
- }
- H5E_END_TRY;
- return FAIL;
-}
diff --git a/hl/src/H5DSprivate.h b/hl/src/H5DSprivate.h
index 0403a4c..ede0209 100644
--- a/hl/src/H5DSprivate.h
+++ b/hl/src/H5DSprivate.h
@@ -20,12 +20,18 @@
/* public LT prototypes */
#include "H5DSpublic.h"
-/* attribute type of a DS dataset */
+/* attribute type of a DS dataset when old references are used*/
typedef struct ds_list_t {
hobj_ref_t ref; /* object reference */
unsigned int dim_idx; /* dimension index of the dataset */
} ds_list_t;
+/* attribute type of a DS dataset when new references are used*/
+typedef struct nds_list_t {
+ H5R_ref_t ref;
+ unsigned int dim_idx; /* dimension index of the dataset */
+} nds_list_t;
+
/*-------------------------------------------------------------------------
* private functions
*-------------------------------------------------------------------------
diff --git a/hl/src/H5DSpublic.h b/hl/src/H5DSpublic.h
index 7306cbc..9aabb98 100644
--- a/hl/src/H5DSpublic.h
+++ b/hl/src/H5DSpublic.h
@@ -25,6 +25,8 @@ typedef herr_t (*H5DS_iterate_t)(hid_t dset, unsigned dim, hid_t scale, void *vi
extern "C" {
#endif
+H5_HLDLL hbool_t H5DSwith_new_ref(hid_t obj_id);
+
H5_HLDLL herr_t H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx);
H5_HLDLL herr_t H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx);
diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c
index 8f2b33f..58a1b16 100644
--- a/hl/src/H5LT.c
+++ b/hl/src/H5LT.c
@@ -1856,46 +1856,6 @@ H5LTset_attribute_double(hid_t loc_id, const char *obj_name, const char *attr_na
}
/*-------------------------------------------------------------------------
- * Function: find_attr
- *
- * Purpose: operator function used by H5LT_find_attribute
- *
- * Programmer: Pedro Vicente
- *
- * Date: June 21, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-find_attr(H5_ATTR_UNUSED hid_t loc_id, const char *name, H5_ATTR_UNUSED const H5A_info_t *ainfo,
- void *op_data)
-{
- int ret = H5_ITER_CONT;
-
- /* check the arguments */
- if (name == NULL)
- return H5_ITER_CONT;
-
- /* Shut compiler up */
- (void)loc_id;
- (void)ainfo;
-
- /* Define a positive value for return value if the attribute was found. This will
- * cause the iterator to immediately return that positive value,
- * indicating short-circuit success
- */
-
- if (HDstrncmp(name, (char *)op_data, MAX(HDstrlen((char *)op_data), HDstrlen(name))) == 0)
- ret = H5_ITER_STOP;
-
- return ret;
-}
-
-/*-------------------------------------------------------------------------
* Function: H5LTfind_attribute
*
* Purpose: Inquires if an attribute named attr_name exists attached to
@@ -1926,32 +1886,22 @@ H5LTfind_attribute(hid_t loc_id, const char *attr_name)
*
* Date: June 21, 2001
*
- * Comments:
- * The function uses H5Aiterate2 with the operator function find_attr
- *
* Return:
- * Success: The return value of the first operator that
- * returns non-zero, or zero if all members were
- * processed with no operator returning non-zero.
+ * Success: Positive if the attribute exists attached to the
+ * object loc_id. Zero if the attribute does not
+ * exist attached to the object loc_id.
*
* Failure: Negative if something goes wrong within the
- * library, or the negative value returned by one
- * of the operators.
+ * library.
*
*-------------------------------------------------------------------------
*/
-/* H5Aiterate wants a non-const pointer but we have a const pointer in the API
- * call. It's safe to ignore this because we control the callback, don't
- * modify the op_data buffer (i.e.: attr_name) during the traversal, and the
- * library never modifies that buffer.
- */
-H5_GCC_CLANG_DIAG_OFF("cast-qual")
herr_t
H5LT_find_attribute(hid_t loc_id, const char *attr_name)
{
- return H5Aiterate2(loc_id, H5_INDEX_NAME, H5_ITER_INC, NULL, find_attr, (void *)attr_name);
+ htri_t attr_exists = H5Aexists(loc_id, attr_name);
+ return (attr_exists < 0) ? (herr_t)-1 : (attr_exists) ? (herr_t)1 : (herr_t)0;
}
-H5_GCC_CLANG_DIAG_ON("cast-qual")
/*-------------------------------------------------------------------------
* Function: H5LTget_attribute_ndims