summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2017-03-08 22:05:43 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2017-03-08 22:05:43 (GMT)
commit86bc81b4fda4a4b7f06e522b1d4c87a71102174e (patch)
tree10816f013e26032c9bf699319c236200891b7cc3
parent190dd5cf46fa13e86bb8669dbe1af14ca890217c (diff)
downloadhdf5-86bc81b4fda4a4b7f06e522b1d4c87a71102174e.zip
hdf5-86bc81b4fda4a4b7f06e522b1d4c87a71102174e.tar.gz
hdf5-86bc81b4fda4a4b7f06e522b1d4c87a71102174e.tar.bz2
Fix attribute datatype conversion implementation to always supply
background buffer for compound conversion, as the library requires (despite the reference manual saying it's optional). Added h5dsm_ttconv.c to test this. Other minor fixes/cleanup.
-rw-r--r--examples/h5dsm_dset_w1m.c4
-rw-r--r--examples/h5dsm_ttconv.c922
-rw-r--r--src/H5VLdaosm.c170
3 files changed, 996 insertions, 100 deletions
diff --git a/examples/h5dsm_dset_w1m.c b/examples/h5dsm_dset_w1m.c
index 566bef8..42b1281 100644
--- a/examples/h5dsm_dset_w1m.c
+++ b/examples/h5dsm_dset_w1m.c
@@ -81,10 +81,11 @@ int main(int argc, char *argv[]) {
if(H5Dclose(ndset) < 0)
ERROR;
if(H5Fclose(file) < 0)
- if(H5Fclose(file) < 0)
ERROR;
if(H5Fclose(nfile) < 0)
ERROR;
+ if(H5Sclose(space) < 0)
+ ERROR;
if(H5Pclose(fapl) < 0)
ERROR;
free(buf);
@@ -102,6 +103,7 @@ error:
H5Dclose(ndset);
H5Fclose(file);
H5Fclose(nfile);
+ H5Sclose(space);
H5Pclose(fapl);
} H5E_END_TRY;
diff --git a/examples/h5dsm_ttconv.c b/examples/h5dsm_ttconv.c
new file mode 100644
index 0000000..1fb2af4
--- /dev/null
+++ b/examples/h5dsm_ttconv.c
@@ -0,0 +1,922 @@
+#include "h5dsm_example.h"
+#include <time.h>
+
+#define FILE_NAME "ttconv.h5"
+
+typedef struct {
+ int a;
+ char b;
+ double c;
+} type_all;
+
+typedef struct {
+ long long a;
+ char b;
+ float c;
+} type_convall;
+
+hbool_t verbose_g = 1;
+
+int main(int argc, char *argv[]) {
+ uuid_t pool_uuid;
+ char *pool_grp = NULL;
+ hid_t file = -1, dset = -1, dset_a = -1, dset_b = -1, dset_c = -1, attr = -1, attr_a = -1, attr_b = -1 , attr_c = -1, space = -1, fapl = -1;
+ hid_t file_type = -1, file_type_a = -1, file_type_b = -1, file_type_c = -1;
+ hid_t mem_type = -1, mem_type_conv = -1, mem_type_a = -1, mem_type_b = -1, mem_type_c = -1;
+ hsize_t dims[1] = {4};
+ type_all buf[4];
+ type_all file_buf[4];
+ type_convall buf_conv[4];
+ const type_all buf_init[4] = {{-1, 'a', (double)-1.}, {-2, 'b', (double)-2.}, {-3, 'c', (double)-3.}, {-4, 'd', (double)-4.}};
+ const type_convall buf_conv_init[4] = {{(long long)-5, 'e', (float)-5.}, {(long long)-6, 'f', (float)-6.}, {(long long)-7, 'g', (float)-7.}, {(long long)-8, 'h', (float)-8.}};
+ int i;
+
+ (void)MPI_Init(&argc, &argv);
+ (void)daos_init();
+
+ /* Seed random number generator */
+ srand(time(NULL));
+
+ if(argc != 2)
+ PRINTF_ERROR("argc must be 2\n");
+
+ /* Parse UUID */
+ if(0 != uuid_parse(argv[1], pool_uuid))
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_daosm(fapl, MPI_COMM_WORLD, MPI_INFO_NULL, pool_uuid, pool_grp) < 0)
+ ERROR;
+
+ /* Create file */
+ if((file = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
+ ERROR;
+
+ /* Set up dataspace */
+ if((space = H5Screate_simple(1, dims, NULL)) < 0)
+ ERROR;
+
+ /*
+ * Set up types
+ */
+ /* Set up file "all" type */
+ if((file_type = H5Tcreate(H5T_COMPOUND, sizeof(int) + 1 + sizeof(double))) < 0)
+ ERROR;
+ if(H5Tinsert(file_type, "a", 0, H5T_NATIVE_INT) < 0)
+ ERROR;
+ if(H5Tinsert(file_type, "b", sizeof(int), H5T_NATIVE_CHAR) < 0)
+ ERROR;
+ if(H5Tinsert(file_type, "c", sizeof(int) + 1, H5T_NATIVE_DOUBLE) < 0)
+ ERROR;
+
+ /* Set up file "a" type" */
+ if((file_type_a = H5Tcreate(H5T_COMPOUND, sizeof(int))) < 0)
+ ERROR;
+ if(H5Tinsert(file_type_a, "a", 0, H5T_NATIVE_INT) < 0)
+ ERROR;
+
+ /* Set up file "b" type" */
+ if((file_type_b = H5Tcreate(H5T_COMPOUND, 1)) < 0)
+ ERROR;
+ if(H5Tinsert(file_type_b, "b", 0, H5T_NATIVE_CHAR) < 0)
+ ERROR;
+
+ /* Set up file "c" type" */
+ if((file_type_c = H5Tcreate(H5T_COMPOUND, sizeof(double))) < 0)
+ ERROR;
+ if(H5Tinsert(file_type_c, "c", 0, H5T_NATIVE_DOUBLE) < 0)
+ ERROR;
+
+ /* Set up memory "all" type */
+ if((mem_type = H5Tcreate(H5T_COMPOUND, sizeof(type_all))) < 0)
+ ERROR;
+ if(H5Tinsert(mem_type, "a", HOFFSET(type_all, a), H5T_NATIVE_INT) < 0)
+ ERROR;
+ if(H5Tinsert(mem_type, "b", HOFFSET(type_all, b), H5T_NATIVE_CHAR) < 0)
+ ERROR;
+ if(H5Tinsert(mem_type, "c", HOFFSET(type_all, c), H5T_NATIVE_DOUBLE) < 0)
+ ERROR;
+
+ /* Set up memory "convall" type */
+ if((mem_type_conv = H5Tcreate(H5T_COMPOUND, sizeof(type_convall))) < 0)
+ ERROR;
+ if(H5Tinsert(mem_type_conv, "a", HOFFSET(type_convall, a), H5T_NATIVE_LLONG) < 0)
+ ERROR;
+ if(H5Tinsert(mem_type_conv, "b", HOFFSET(type_convall, b), H5T_NATIVE_CHAR) < 0)
+ ERROR;
+ if(H5Tinsert(mem_type_conv, "c", HOFFSET(type_convall, c), H5T_NATIVE_FLOAT) < 0)
+ ERROR;
+
+ /* Set up memory "a" type" */
+ if((mem_type_a = H5Tcreate(H5T_COMPOUND, sizeof(type_convall))) < 0)
+ ERROR;
+ if(H5Tinsert(mem_type_a, "a", HOFFSET(type_convall, a), H5T_NATIVE_LLONG) < 0)
+ ERROR;
+
+ /* Set up memory "b" type" */
+ if((mem_type_b = H5Tcreate(H5T_COMPOUND, sizeof(type_convall))) < 0)
+ ERROR;
+ if(H5Tinsert(mem_type_b, "b", HOFFSET(type_convall, b), H5T_NATIVE_CHAR) < 0)
+ ERROR;
+
+ /* Set up memory "c" type" */
+ if((mem_type_c = H5Tcreate(H5T_COMPOUND, sizeof(type_convall))) < 0)
+ ERROR;
+ if(H5Tinsert(mem_type_c, "c", HOFFSET(type_convall, c), H5T_NATIVE_FLOAT) < 0)
+ ERROR;
+
+ /* Create dataset */
+ if((dset = H5Dcreate2(file, "dset", file_type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /* Create dataset a */
+ if((dset_a = H5Dcreate2(file, "dset_a", file_type_a, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /* Create dataset b */
+ if((dset_b = H5Dcreate2(file, "dset_b", file_type_b, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /* Create dataset c */
+ if((dset_c = H5Dcreate2(file, "dset_c", file_type_c, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /* Create attribute */
+ if((attr = H5Acreate2(dset, "attr", file_type, space, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /* Create attribute a */
+ if((attr_a = H5Acreate2(dset_a, "attr_a", file_type_a, space, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /* Create attribute b */
+ if((attr_b = H5Acreate2(dset_b, "attr_b", file_type_b, space, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /* Create attribute c */
+ if((attr_c = H5Acreate2(dset_c, "attr_c", file_type_c, space, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /*
+ * Test attribute
+ */
+ /*
+ * Full write/read, no member conversion
+ */
+ /* Fill buffer */
+ for(i = 0; i < dims[0]; i++) {
+ buf[i].a = rand() % 10;
+ buf[i].b = 'A' + (char)(rand() % 26);
+ buf[i].c = (double)(rand() % 100) / (double)10;
+ } /* end for */
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Writing attribute with no member conversion\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", buf[i].a, buf[i].b, buf[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Write data */
+ if(H5Awrite(attr, mem_type, buf) < 0)
+ ERROR;
+
+ /* Update file_buf */
+ for(i = 0; i < dims[0]; i++) {
+ file_buf[i].a = buf[i].a;
+ file_buf[i].b = buf[i].b;
+ file_buf[i].c = buf[i].c;
+ } /* end for */
+
+ /* Read data */
+ memcpy(buf, buf_init, sizeof(buf));
+ if(H5Aread(attr, mem_type, buf) < 0)
+ ERROR;
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Read attribute with no member conversion\n");
+ printf("exp = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", file_buf[i].a, file_buf[i].b, file_buf[i].c);
+ } /* end for */
+ printf("}\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", buf[i].a, buf[i].b, buf[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Check buffer */
+ for(i = 0; i< dims[0]; i++) {
+ if(file_buf[i].a != buf[i].a)
+ PRINTF_ERROR("Member a at location %d does not match", i);
+ if(file_buf[i].b != buf[i].b)
+ PRINTF_ERROR("Member b at location %d does not match", i);
+ if(((file_buf[i].c - buf[i].c) > (double)0.01)
+ || ((file_buf[i].c - buf[i].c) < (double)-0.01))
+ PRINTF_ERROR("Member c at location %d does not match", i);
+ } /* end for */
+
+ printf("\n");
+
+ /*
+ * Full write/read, with member conversion
+ */
+ /* Fill buffer */
+ for(i = 0; i < dims[0]; i++) {
+ buf_conv[i].a = (long long)(rand() % 10);
+ buf_conv[i].b = 'A' + (char)(rand() % 26);
+ buf_conv[i].c = (float)(rand() % 100) / (float)10;
+ } /* end for */
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Writing attribute with member conversion\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Write data */
+ if(H5Awrite(attr, mem_type_conv, buf_conv) < 0)
+ ERROR;
+
+ /* Update file_buf */
+ for(i = 0; i < dims[0]; i++) {
+ file_buf[i].a = (int)buf_conv[i].a;
+ file_buf[i].b = buf_conv[i].b;
+ file_buf[i].c = (double)buf_conv[i].c;
+ } /* end for */
+
+ /* Read data */
+ memcpy(buf, buf_init, sizeof(buf));
+ if(H5Aread(attr, mem_type, buf) < 0)
+ ERROR;
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Read attribute with no member conversion\n");
+ printf("exp = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", file_buf[i].a, file_buf[i].b, file_buf[i].c);
+ } /* end for */
+ printf("}\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", buf[i].a, buf[i].b, buf[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Check buffer */
+ for(i = 0; i< dims[0]; i++) {
+ if(file_buf[i].a != buf[i].a)
+ PRINTF_ERROR("Member a at location %d does not match", i);
+ if(file_buf[i].b != buf[i].b)
+ PRINTF_ERROR("Member b at location %d does not match", i);
+ if(((file_buf[i].c - buf[i].c) > (double)0.01)
+ || ((file_buf[i].c - buf[i].c) < (double)-0.01))
+ PRINTF_ERROR("Member c at location %d does not match", i);
+ } /* end for */
+
+ /* Read data */
+ memcpy(buf_conv, buf_conv_init, sizeof(buf_conv));
+ if(H5Aread(attr, mem_type_conv, buf_conv) < 0)
+ ERROR;
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Read attribute with member conversion\n");
+ printf("exp = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", file_buf[i].a, file_buf[i].b, file_buf[i].c);
+ } /* end for */
+ printf("}\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Check buffer */
+ for(i = 0; i< dims[0]; i++) {
+ if(file_buf[i].a != (int)buf_conv[i].a)
+ PRINTF_ERROR("Member a at location %d does not match", i);
+ if(file_buf[i].b != buf_conv[i].b)
+ PRINTF_ERROR("Member b at location %d does not match", i);
+ if(((file_buf[i].c - (double)buf_conv[i].c) > (double)0.01)
+ || ((file_buf[i].c - (double)buf_conv[i].c) < (double)-0.01))
+ PRINTF_ERROR("Member c at location %d does not match", i);
+ } /* end for */
+
+ printf("\n");
+
+ /*
+ * Write by parts
+ */
+ /* Fill buffer */
+ for(i = 0; i < dims[0]; i++) {
+ buf_conv[i].a = (long long)(rand() % 10);
+ buf_conv[i].b = 'A' + (char)(rand() % 26);
+ buf_conv[i].c = (float)(rand() % 100) / (float)10;
+ } /* end for */
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Writing attribute compound member \'a\'\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Write data */
+ if(H5Awrite(attr, mem_type_a, buf_conv) < 0)
+ ERROR;
+
+ /* Update file_buf */
+ for(i = 0; i < dims[0]; i++)
+ file_buf[i].a = (int)buf_conv[i].a;
+
+ /* Read data */
+ memcpy(buf, buf_init, sizeof(buf));
+ if(H5Aread(attr, mem_type, buf) < 0)
+ ERROR;
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Read attribute with no member conversion\n");
+ printf("exp = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", file_buf[i].a, file_buf[i].b, file_buf[i].c);
+ } /* end for */
+ printf("}\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", buf[i].a, buf[i].b, buf[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Check buffer */
+ for(i = 0; i< dims[0]; i++) {
+ if(file_buf[i].a != buf[i].a)
+ PRINTF_ERROR("Member a at location %d does not match", i);
+ if(file_buf[i].b != buf[i].b)
+ PRINTF_ERROR("Member b at location %d does not match", i);
+ if(((file_buf[i].c - buf[i].c) > (double)0.01)
+ || ((file_buf[i].c - buf[i].c) < (double)-0.01))
+ PRINTF_ERROR("Member c at location %d does not match", i);
+ } /* end for */
+
+ printf("\n");
+
+ /* Fill buffer */
+ for(i = 0; i < dims[0]; i++) {
+ buf_conv[i].a = (long long)(rand() % 10);
+ buf_conv[i].b = 'A' + (char)(rand() % 26);
+ buf_conv[i].c = (float)(rand() % 100) / (float)10;
+ } /* end for */
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Writing attribute compound member \'b\'\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Write data */
+ if(H5Awrite(attr, mem_type_b, buf_conv) < 0)
+ ERROR;
+
+ /* Update file_buf */
+ for(i = 0; i < dims[0]; i++)
+ file_buf[i].b = buf_conv[i].b;
+
+ /* Read data */
+ memcpy(buf, buf_init, sizeof(buf));
+ if(H5Aread(attr, mem_type, buf) < 0)
+ ERROR;
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Read attribute with no member conversion\n");
+ printf("exp = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", file_buf[i].a, file_buf[i].b, file_buf[i].c);
+ } /* end for */
+ printf("}\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", buf[i].a, buf[i].b, buf[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Check buffer */
+ for(i = 0; i< dims[0]; i++) {
+ if(file_buf[i].a != buf[i].a)
+ PRINTF_ERROR("Member a at location %d does not match", i);
+ if(file_buf[i].b != buf[i].b)
+ PRINTF_ERROR("Member b at location %d does not match", i);
+ if(((file_buf[i].c - buf[i].c) > (double)0.01)
+ || ((file_buf[i].c - buf[i].c) < (double)-0.01))
+ PRINTF_ERROR("Member c at location %d does not match", i);
+ } /* end for */
+
+ printf("\n");
+
+ /* Fill buffer */
+ for(i = 0; i < dims[0]; i++) {
+ buf_conv[i].a = (long long)(rand() % 10);
+ buf_conv[i].b = 'A' + (char)(rand() % 26);
+ buf_conv[i].c = (float)(rand() % 100) / (float)10;
+ } /* end for */
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Writing attribute compound member \'c\'\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Write data */
+ if(H5Awrite(attr, mem_type_c, buf_conv) < 0)
+ ERROR;
+
+ /* Update file_buf */
+ for(i = 0; i < dims[0]; i++)
+ file_buf[i].c = (double)buf_conv[i].c;
+
+ /* Read data */
+ memcpy(buf, buf_init, sizeof(buf));
+ if(H5Aread(attr, mem_type, buf) < 0)
+ ERROR;
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Read attribute with no member conversion\n");
+ printf("exp = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", file_buf[i].a, file_buf[i].b, file_buf[i].c);
+ } /* end for */
+ printf("}\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", buf[i].a, buf[i].b, buf[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Check buffer */
+ for(i = 0; i< dims[0]; i++) {
+ if(file_buf[i].a != buf[i].a)
+ PRINTF_ERROR("Member a at location %d does not match", i);
+ if(file_buf[i].b != buf[i].b)
+ PRINTF_ERROR("Member b at location %d does not match", i);
+ if(((file_buf[i].c - buf[i].c) > (double)0.01)
+ || ((file_buf[i].c - buf[i].c) < (double)-0.01))
+ PRINTF_ERROR("Member c at location %d does not match", i);
+ } /* end for */
+
+ printf("\n");
+
+ /*
+ * Read by parts
+ */
+ /* Read member a */
+ memcpy(buf_conv, buf_conv_init, sizeof(buf_conv));
+ if(H5Aread(attr, mem_type_a, buf_conv) < 0)
+ ERROR;
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Read full attribute compound member \'a\'\n");
+ printf("exp = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", file_buf[i].a, buf_conv_init[i].b, (double)buf_conv_init[i].c);
+ } /* end for */
+ printf("}\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Check buffer */
+ for(i = 0; i< dims[0]; i++) {
+ if(file_buf[i].a != (int)buf_conv[i].a)
+ PRINTF_ERROR("Member a at location %d does not match", i);
+ if(buf_conv_init[i].b != buf_conv[i].b)
+ PRINTF_ERROR("Member b at location %d does not match", i);
+ if(((buf_conv_init[i].c - buf_conv[i].c) > 0.01f)
+ || ((buf_conv_init[i].c - buf_conv[i].c) < -0.01f))
+ PRINTF_ERROR("Member c at location %d does not match", i);
+ } /* end for */
+
+ printf("\n");
+
+ /* Read member b */
+ memcpy(buf_conv, buf_conv_init, sizeof(buf_conv));
+ if(H5Aread(attr, mem_type_b, buf_conv) < 0)
+ ERROR;
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Read full attribute compound member \'b\'\n");
+ printf("exp = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv_init[i].a, file_buf[i].b, (double)buf_conv_init[i].c);
+ } /* end for */
+ printf("}\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Check buffer */
+ for(i = 0; i< dims[0]; i++) {
+ if(buf_conv_init[i].a != buf_conv[i].a)
+ PRINTF_ERROR("Member a at location %d does not match", i);
+ if(file_buf[i].b != buf_conv[i].b)
+ PRINTF_ERROR("Member b at location %d does not match", i);
+ if(((buf_conv_init[i].c - buf_conv[i].c) > 0.01f)
+ || ((buf_conv_init[i].c - buf_conv[i].c) < -0.01f))
+ PRINTF_ERROR("Member c at location %d does not match", i);
+ } /* end for */
+
+ printf("\n");
+
+ /* Read member c */
+ memcpy(buf_conv, buf_conv_init, sizeof(buf_conv));
+ if(H5Aread(attr, mem_type_c, buf_conv) < 0)
+ ERROR;
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Read full attribute compound member \'c\'\n");
+ printf("exp = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv_init[i].a, buf_conv_init[i].b, file_buf[i].c);
+ } /* end for */
+ printf("}\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Check buffer */
+ for(i = 0; i< dims[0]; i++) {
+ if(buf_conv_init[i].a != buf_conv[i].a)
+ PRINTF_ERROR("Member a at location %d does not match", i);
+ if(buf_conv_init[i].b != buf_conv[i].b)
+ PRINTF_ERROR("Member b at location %d does not match", i);
+ if(((file_buf[i].c - (double)buf_conv[i].c) > (double)0.01)
+ || ((file_buf[i].c - (double)buf_conv[i].c) < (double)-0.01))
+ PRINTF_ERROR("Member c at location %d does not match", i);
+ } /* end for */
+
+ printf("\n");
+
+ /*
+ * Write/read partial attributes
+ */
+ /* Fill buffer */
+ for(i = 0; i < dims[0]; i++) {
+ buf_conv[i].a = (long long)(rand() % 10);
+ buf_conv[i].b = 'A' + (char)(rand() % 26);
+ buf_conv[i].c = (float)(rand() % 100) / (float)10;
+ } /* end for */
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Writing full memory type to attribute containing only member \'a\'\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Write data */
+ if(H5Awrite(attr_a, mem_type_conv, buf_conv) < 0)
+ ERROR;
+
+ /* Update file_buf */
+ for(i = 0; i < dims[0]; i++)
+ file_buf[i].a = (int)buf_conv[i].a;
+
+ /* Read data */
+ memcpy(buf_conv, buf_conv_init, sizeof(buf_conv));
+ if(H5Aread(attr_a, mem_type_conv, buf_conv) < 0)
+ ERROR;
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Read attribute containing only member \'a\'\n");
+ printf("exp = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%d, %c, %.1f}", file_buf[i].a, buf_conv_init[i].b, (double)buf_conv_init[i].c);
+ } /* end for */
+ printf("}\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Check buffer */
+ for(i = 0; i< dims[0]; i++) {
+ if(file_buf[i].a != (int)buf_conv[i].a)
+ PRINTF_ERROR("Member a at location %d does not match", i);
+ if(buf_conv_init[i].b != buf_conv[i].b)
+ PRINTF_ERROR("Member b at location %d does not match", i);
+ if(((buf_conv_init[i].c - buf_conv[i].c) > 0.01f)
+ || ((buf_conv_init[i].c - buf_conv[i].c) < -0.01f))
+ PRINTF_ERROR("Member c at location %d does not match", i);
+ } /* end for */
+
+ printf("\n");
+
+ /* Fill buffer */
+ for(i = 0; i < dims[0]; i++) {
+ buf_conv[i].a = (long long)(rand() % 10);
+ buf_conv[i].b = 'A' + (char)(rand() % 26);
+ buf_conv[i].c = (float)(rand() % 100) / (float)10;
+ } /* end for */
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Writing full memory type to attribute containing only member \'b\'\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Write data */
+ if(H5Awrite(attr_b, mem_type_conv, buf_conv) < 0)
+ ERROR;
+
+ /* Update file_buf */
+ for(i = 0; i < dims[0]; i++)
+ file_buf[i].b = buf_conv[i].b;
+
+ /* Read data */
+ memcpy(buf_conv, buf_conv_init, sizeof(buf_conv));
+ if(H5Aread(attr_b, mem_type_conv, buf_conv) < 0)
+ ERROR;
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Read attribute containing only member \'b\'\n");
+ printf("exp = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv_init[i].a, file_buf[i].b, (double)buf_conv_init[i].c);
+ } /* end for */
+ printf("}\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Check buffer */
+ for(i = 0; i< dims[0]; i++) {
+ if(buf_conv_init[i].a != buf_conv[i].a)
+ PRINTF_ERROR("Member a at location %d does not match", i);
+ if(file_buf[i].b != buf_conv[i].b)
+ PRINTF_ERROR("Member b at location %d does not match", i);
+ if(((buf_conv_init[i].c - buf_conv[i].c) > 0.01f)
+ || ((buf_conv_init[i].c - buf_conv[i].c) < -0.01f))
+ PRINTF_ERROR("Member c at location %d does not match", i);
+ } /* end for */
+
+ printf("\n");
+
+ /* Fill buffer */
+ for(i = 0; i < dims[0]; i++) {
+ buf_conv[i].a = (long long)(rand() % 10);
+ buf_conv[i].b = 'A' + (char)(rand() % 26);
+ buf_conv[i].c = (float)(rand() % 100) / (float)10;
+ } /* end for */
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Writing full memory type to attribute containing only member \'c\'\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Write data */
+ if(H5Awrite(attr_c, mem_type_conv, buf_conv) < 0)
+ ERROR;
+
+ /* Update file_buf */
+ for(i = 0; i < dims[0]; i++)
+ file_buf[i].c = (double)buf_conv[i].c;
+
+ /* Read data */
+ memcpy(buf_conv, buf_conv_init, sizeof(buf_conv));
+ if(H5Aread(attr_c, mem_type_conv, buf_conv) < 0)
+ ERROR;
+
+ /* Print message */
+ if(verbose_g) {
+ printf("Read attribute containing only member \'c\'\n");
+ printf("exp = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv_init[i].a, buf_conv_init[i].b, file_buf[i].c);
+ } /* end for */
+ printf("}\n");
+ printf("buf = {");
+ for(i = 0; i < dims[0]; i++) {
+ if(i > 0)
+ printf(", ");
+ printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c);
+ } /* end for */
+ printf("}\n");
+ } /* end if */
+
+ /* Check buffer */
+ for(i = 0; i< dims[0]; i++) {
+ if(buf_conv_init[i].a != buf_conv[i].a)
+ PRINTF_ERROR("Member a at location %d does not match", i);
+ if(buf_conv_init[i].b != buf_conv[i].b)
+ PRINTF_ERROR("Member b at location %d does not match", i);
+ if(((file_buf[i].c - (double)buf_conv[i].c) > (double)0.01)
+ || ((file_buf[i].c - (double)buf_conv[i].c) < (double)-0.01))
+ PRINTF_ERROR("Member c at location %d does not match", i);
+ } /* end for */
+
+ printf("\n");
+
+ /*
+ * Close
+ */
+ if(H5Aclose(attr) < 0)
+ ERROR;
+ if(H5Aclose(attr_a) < 0)
+ ERROR;
+ if(H5Aclose(attr_b) < 0)
+ ERROR;
+ if(H5Aclose(attr_c) < 0)
+ ERROR;
+ if(H5Dclose(dset) < 0)
+ ERROR;
+ if(H5Dclose(dset_a) < 0)
+ ERROR;
+ if(H5Dclose(dset_b) < 0)
+ ERROR;
+ if(H5Dclose(dset_c) < 0)
+ ERROR;
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Tclose(file_type) < 0)
+ ERROR;
+ if(H5Tclose(file_type_a) < 0)
+ ERROR;
+ if(H5Tclose(file_type_b) < 0)
+ ERROR;
+ if(H5Tclose(file_type_c) < 0)
+ ERROR;
+ if(H5Tclose(mem_type) < 0)
+ ERROR;
+ if(H5Tclose(mem_type_conv) < 0)
+ ERROR;
+ if(H5Tclose(mem_type_a) < 0)
+ ERROR;
+ if(H5Tclose(mem_type_b) < 0)
+ ERROR;
+ if(H5Tclose(mem_type_c) < 0)
+ ERROR;
+ if(H5Sclose(space) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+
+ printf("Success\n");
+
+ (void)daos_fini();
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Aclose(attr);
+ H5Aclose(attr_a);
+ H5Aclose(attr_b);
+ H5Aclose(attr_c);
+ H5Dclose(dset);
+ H5Dclose(dset_a);
+ H5Dclose(dset_b);
+ H5Dclose(dset_c);
+ H5Fclose(file);
+ H5Tclose(file_type);
+ H5Tclose(file_type_a);
+ H5Tclose(file_type_b);
+ H5Tclose(file_type_c);
+ H5Tclose(mem_type);
+ H5Tclose(mem_type_conv);
+ H5Tclose(mem_type_a);
+ H5Tclose(mem_type_b);
+ H5Tclose(mem_type_c);
+ H5Sclose(space);
+ H5Pclose(fapl);
+ } H5E_END_TRY;
+
+ (void)daos_fini();
+ (void)MPI_Finalize();
+ return 1;
+}
+
diff --git a/src/H5VLdaosm.c b/src/H5VLdaosm.c
index 1e81a66..41223bc 100644
--- a/src/H5VLdaosm.c
+++ b/src/H5VLdaosm.c
@@ -152,10 +152,10 @@ static void *H5VL_daosm_group_create_helper(H5VL_daosm_file_t *file,
static void *H5VL_daosm_group_open_helper(H5VL_daosm_file_t *file,
daos_obj_id_t oid, hid_t gapl_id, hid_t dxpl_id, void **req);
static htri_t H5VL_daosm_need_bkg(hid_t src_type_id, hid_t dst_type_id,
- hbool_t types_equal, hbool_t have_contig_dst_buf, size_t *dst_type_size);
+ hbool_t *fill_bkg);
static herr_t H5VL_daosm_tconv_init(hid_t src_type_id, size_t *src_type_size,
hid_t dst_type_id, size_t *dst_type_size, size_t num_elem, void **tconv_buf,
- void **bkg_buf, H5VL_daosm_tconv_reuse_t *reuse);
+ void **bkg_buf, H5VL_daosm_tconv_reuse_t *reuse, hbool_t *fill_bkg);
static herr_t H5VL_daosm_sel_to_recx_iov(H5S_t *space, size_t type_size,
void *buf, daos_recx_t **recxs, daos_iov_t **sg_iovs, size_t *list_nused);
static herr_t H5VL_daosm_object_close(void *_obj, hid_t dxpl_id, void **req);
@@ -2509,22 +2509,16 @@ H5VL_daosm_group_close(void *_grp, hid_t H5_ATTR_UNUSED dxpl_id,
*-------------------------------------------------------------------------
*/
static htri_t
-H5VL_daosm_need_bkg(hid_t src_type_id, hid_t dst_type_id, hbool_t types_equal,
- hbool_t have_contig_dst_buf, size_t *dst_type_size)
+H5VL_daosm_need_bkg(hid_t src_type_id, hid_t dst_type_id, hbool_t *fill_bkg)
{
hid_t memb_type_id = -1;
hid_t src_memb_type_id = -1;
char *memb_name = NULL;
- size_t memb_size;
H5T_class_t tclass;
htri_t ret_value;
FUNC_ENTER_NOAPI_NOINIT
- /* Get destination type size */
- if((*dst_type_size = H5Tget_size(dst_type_id)) == 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get source type size")
-
/* Get datatype class */
if(H5T_NO_CLASS == (tclass = H5Tget_class(dst_type_id)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get type class")
@@ -2545,96 +2539,74 @@ H5VL_daosm_need_bkg(hid_t src_type_id, hid_t dst_type_id, hbool_t types_equal,
case H5T_COMPOUND:
{
int nmemb;
- size_t size_used = 0;
int src_i;
int i;
- /* If we have a contiguous destination buffer and the types are not
- * equal, no reason not to use it for the background buffer (the
- * library will allocate one even if we don't care about its
- * contents so we may as well provide it), so no need to check
- * further */
- if(!types_equal && have_contig_dst_buf)
- HGOTO_DONE(TRUE)
+ /* We must always provide a background buffer for compound
+ * conversions. Only need to check further to see if it must be
+ * filled. */
+ ret_value = TRUE;
/* Get number of compound members */
if((nmemb = H5Tget_nmembers(dst_type_id)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get number of compound members")
- /* Iterate over compound members */
+ /* Iterate over compound members, checking for a member in
+ * dst_type_id with no match in src_type_id */
for(i = 0; i < nmemb; i++) {
/* Get member type */
if((memb_type_id = H5Tget_member_type(dst_type_id, (unsigned)i)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get compound member type")
- /* If the types are equal, only check for missing space,
- * otherwise must also check for a member in dst_type_id
- * having no match in src_type_id */
- if(types_equal) {
- /* Recursively check member type, this will fill in the
- * member size */
- if((ret_value = H5VL_daosm_need_bkg(-1, memb_type_id, types_equal, have_contig_dst_buf, &memb_size)) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't check if background buffer needed")
- } /* end if */
- else {
- /* Get member name */
- if(NULL == (memb_name = H5Tget_member_name(dst_type_id, (unsigned)i)))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get compound member name")
-
- /* Check for matching name in source type */
- H5E_BEGIN_TRY {
- src_i = H5Tget_member_index(src_type_id, memb_name);
- } H5E_END_TRY
-
- /* Free memb_name */
- if(H5free_memory(memb_name) < 0)
- HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, FAIL, "can't free member name")
- memb_name = NULL;
-
- /* If no match was found, this type is not being filled
- * in, so we must use a background buffer */
- if(src_i < 0) {
- if(H5Tclose(memb_type_id) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "can't close member type")
- memb_type_id = -1;
- HGOTO_DONE(TRUE)
- } /* end if */
-
- /* Open matching source type */
- if((src_memb_type_id = H5Tget_member_type(src_type_id, (unsigned)src_i)) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get compound member type")
-
- /* Recursively check member type, this will fill in the
- * member size */
- if((ret_value = H5VL_daosm_need_bkg(src_memb_type_id, memb_type_id, types_equal, have_contig_dst_buf, &memb_size)) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't check if background buffer needed")
-
- /* Close source member type */
- if(H5Tclose(src_memb_type_id) < 0)
+ /* Get member name */
+ if(NULL == (memb_name = H5Tget_member_name(dst_type_id, (unsigned)i)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get compound member name")
+
+ /* Check for matching name in source type */
+ H5E_BEGIN_TRY {
+ src_i = H5Tget_member_index(src_type_id, memb_name);
+ } H5E_END_TRY
+
+ /* Free memb_name */
+ if(H5free_memory(memb_name) < 0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, FAIL, "can't free member name")
+ memb_name = NULL;
+
+ /* If no match was found, this type is not being filled in,
+ * so we must fill the background buffer */
+ if(src_i < 0) {
+ if(H5Tclose(memb_type_id) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "can't close member type")
- src_memb_type_id = -1;
+ memb_type_id = -1;
+ *fill_bkg = TRUE;
+ HGOTO_DONE(TRUE)
} /* end if */
+ /* Open matching source type */
+ if((src_memb_type_id = H5Tget_member_type(src_type_id, (unsigned)src_i)) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get compound member type")
+
+ /* Recursively check member type, this will fill in the
+ * member size */
+ if(H5VL_daosm_need_bkg(src_memb_type_id, memb_type_id, fill_bkg) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't check if background buffer needed")
+
+ /* Close source member type */
+ if(H5Tclose(src_memb_type_id) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "can't close member type")
+ src_memb_type_id = -1;
+
/* Close member type */
if(H5Tclose(memb_type_id) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "can't close member type")
memb_type_id = -1;
- /* If a background buffer is needed for the member, it is
- * needed for the parent */
- if(ret_value)
+ /* If the source member type needs the background filled, so
+ * does the parent */
+ if(*fill_bkg)
HGOTO_DONE(TRUE)
-
- /* Keep track of the size used in compound */
- size_used += memb_size;
} /* end for */
- /* Check if all the space in the type is used. If not, we must
- * use a background buffer */
- HDassert(size_used <= *dst_type_size);
- if(size_used != *dst_type_size)
- HGOTO_DONE(TRUE)
-
break;
} /* end block */
@@ -2643,16 +2615,12 @@ H5VL_daosm_need_bkg(hid_t src_type_id, hid_t dst_type_id, hbool_t types_equal,
if((memb_type_id = H5Tget_super(dst_type_id)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get array parent type")
- /* Get source parent type, if appropriate */
- if(src_type_id >= 0) {
- if((src_memb_type_id = H5Tget_super(src_type_id)) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get array parent type")
- } /* end if */
- else
- HDassert(types_equal);
+ /* Get source parent type */
+ if((src_memb_type_id = H5Tget_super(src_type_id)) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get array parent type")
/* Recursively check parent type */
- if((ret_value = H5VL_daosm_need_bkg(src_memb_type_id, memb_type_id, types_equal, have_contig_dst_buf, &memb_size)) < 0)
+ if((ret_value = H5VL_daosm_need_bkg(src_memb_type_id, memb_type_id, fill_bkg)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't check if background buffer needed")
/* Close source parent type */
@@ -2712,7 +2680,7 @@ done:
static herr_t
H5VL_daosm_tconv_init(hid_t src_type_id, size_t *src_type_size,
hid_t dst_type_id, size_t *dst_type_size, size_t num_elem, void **tconv_buf,
- void **bkg_buf, H5VL_daosm_tconv_reuse_t *reuse)
+ void **bkg_buf, H5VL_daosm_tconv_reuse_t *reuse, hbool_t *fill_bkg)
{
htri_t need_bkg;
htri_t types_equal;
@@ -2726,6 +2694,8 @@ H5VL_daosm_tconv_init(hid_t src_type_id, size_t *src_type_size,
HDassert(!*tconv_buf);
HDassert(bkg_buf);
HDassert(!*bkg_buf);
+ HDassert(fill_bkg);
+ HDassert(!*fill_bkg);
/* Get source type size */
if((*src_type_size = H5Tget_size(src_type_id)) == 0)
@@ -2734,23 +2704,21 @@ H5VL_daosm_tconv_init(hid_t src_type_id, size_t *src_type_size,
/* Check if the types are equal */
if((types_equal = H5Tequal(src_type_id, dst_type_id)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOMPARE, FAIL, "can't check if types are equal")
-
- /* Get destination type size */
if(types_equal)
+ /* Types are equal, no need for conversion, just set dst_type_size */
*dst_type_size = *src_type_size;
- else
+ else {
+ /* Get destination type size */
if((*dst_type_size = H5Tget_size(dst_type_id)) == 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get source type size")
- /* Check if we need a background buffer */
- if((need_bkg = H5VL_daosm_need_bkg(src_type_id, dst_type_id, types_equal, reuse != NULL, dst_type_size)) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't check if background buffer needed")
+ /* Check if we need a background buffer */
+ if((need_bkg = H5VL_daosm_need_bkg(src_type_id, dst_type_id, fill_bkg)) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't check if background buffer needed")
- /* Check if we need to perform type conversion */
- if(!types_equal || need_bkg) {
/* Check for reusable destination buffer */
if(reuse) {
- HDassert(*reuse = H5VL_DAOSM_TCONV_REUSE_NONE);
+ HDassert(*reuse == H5VL_DAOSM_TCONV_REUSE_NONE);
/* Use dest buffer for type conversion if it large enough, otherwise
* use it for the background buffer if one is needed. */
@@ -2771,7 +2739,7 @@ H5VL_daosm_tconv_init(hid_t src_type_id, size_t *src_type_size,
if(need_bkg && (!reuse || (*reuse != H5VL_DAOSM_TCONV_REUSE_BKG)))
if(NULL == (*bkg_buf = H5MM_malloc(num_elem * *dst_type_size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't allocate background buffer")
- } /* end if */
+ } /* end else */
done:
/* Cleanup on failure */
@@ -4037,6 +4005,7 @@ H5VL_daosm_attribute_read(void *_attr, hid_t mem_type_id, void *buf,
void *tconv_buf = NULL;
void *bkg_buf = NULL;
H5VL_daosm_tconv_reuse_t reuse = H5VL_DAOSM_TCONV_REUSE_NONE;
+ hbool_t fill_bkg = FALSE;
int ret;
int i;
herr_t ret_value = SUCCEED;
@@ -4055,7 +4024,7 @@ H5VL_daosm_attribute_read(void *_attr, hid_t mem_type_id, void *buf,
attr_size *= (uint64_t)dim[i];
/* Check for type conversion */
- if(H5VL_daosm_tconv_init(attr->type_id, &file_type_size, mem_type_id, &mem_type_size, (size_t)attr_size, &tconv_buf, &bkg_buf, &reuse) < 0)
+ if(H5VL_daosm_tconv_init(attr->type_id, &file_type_size, mem_type_id, &mem_type_size, (size_t)attr_size, &tconv_buf, &bkg_buf, &reuse, &fill_bkg) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "can't initialize type conversion")
/* Reuse buffer as appropriate */
@@ -4065,7 +4034,7 @@ H5VL_daosm_attribute_read(void *_attr, hid_t mem_type_id, void *buf,
bkg_buf = buf;
/* Fill background buffer if necessary */
- if(bkg_buf && (bkg_buf != buf))
+ if(fill_bkg && (bkg_buf != buf))
(void)HDmemcpy(bkg_buf, buf, (size_t)attr_size * mem_type_size);
/* Set up operation to read data */
@@ -4157,6 +4126,7 @@ H5VL_daosm_attribute_write(void *_attr, hid_t H5_ATTR_UNUSED mem_type_id,
uint64_t attr_size;
void *tconv_buf = NULL;
void *bkg_buf = NULL;
+ hbool_t fill_bkg = FALSE;
int ret;
int i;
herr_t ret_value = SUCCEED;
@@ -4179,7 +4149,7 @@ H5VL_daosm_attribute_write(void *_attr, hid_t H5_ATTR_UNUSED mem_type_id,
attr_size *= (uint64_t)dim[i];
/* Check for type conversion */
- if(H5VL_daosm_tconv_init(mem_type_id, &mem_type_size, attr->type_id, &file_type_size, (size_t)attr_size, &tconv_buf, &bkg_buf, NULL) < 0)
+ if(H5VL_daosm_tconv_init(mem_type_id, &mem_type_size, attr->type_id, &file_type_size, (size_t)attr_size, &tconv_buf, &bkg_buf, NULL, &fill_bkg) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "can't initialize type conversion")
/* Set up operation to write data */
@@ -4212,8 +4182,10 @@ H5VL_daosm_attribute_write(void *_attr, hid_t H5_ATTR_UNUSED mem_type_id,
/* Check for type conversion */
if(tconv_buf) {
- /* Check for background buffer */
- if(bkg_buf) {
+ /* Check if we need to fill background buffer */
+ if(fill_bkg) {
+ HDassert(bkg_buf);
+
/* Read data from attribute to background buffer */
daos_iov_set(&sg_iov, bkg_buf, (daos_size_t)(attr_size * (uint64_t)file_type_size));