summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5Odtype.c4
-rw-r--r--src/H5T.c10
-rw-r--r--src/H5Tcommit.c15
-rw-r--r--test/dtypes.c203
4 files changed, 227 insertions, 5 deletions
diff --git a/src/H5Odtype.c b/src/H5Odtype.c
index 4d44075..1d7ce7c 100644
--- a/src/H5Odtype.c
+++ b/src/H5Odtype.c
@@ -1122,7 +1122,9 @@ H5O_dtype_get_share(H5F_t UNUSED *f, const void *_mesg,
assert (sh);
if (H5F_addr_defined (dt->ent.header)) {
- assert (H5T_STATE_NAMED==dt->state || H5T_STATE_OPEN==dt->state);
+ if(H5T_STATE_NAMED!=dt->state && H5T_STATE_OPEN!=dt->state && H5T_STATE_TRANSIENT!=dt->state)
+ HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "datatype state is not valid");
+
sh->in_gh = FALSE;
sh->u.ent = dt->ent;
} else
diff --git a/src/H5T.c b/src/H5T.c
index e3379ec..304536b 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -2727,6 +2727,14 @@ H5T_open (H5G_entry_t *loc, const char *name, hid_t dxpl_id)
/* Open the datatype object */
if ((dt=H5T_open_oid(&ent, dxpl_id)) ==NULL)
HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, "not found");
+
+ /* Mark any datatypes as being in memory now */
+ if (H5T_set_loc(dt, NULL, H5T_LOC_MEMORY)<0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "invalid datatype location")
+
+ /* Unlock data type */
+ if (H5T_lock (dt, FALSE)<0)
+ HGOTO_ERROR (H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to lock transient data type")
/* Set return value */
ret_value=dt;
@@ -4347,7 +4355,7 @@ done:
USAGE
htri_t H5T_set_loc(dt,f,loc)
H5T_t *dt; IN/OUT: Pointer to the datatype to mark
- H5F_t *dt; IN: Pointer to the file the datatype is in
+ H5F_t *f; IN: Pointer to the file the datatype is in
H5T_vlen_type_t loc IN: location of type
RETURNS
diff --git a/src/H5Tcommit.c b/src/H5Tcommit.c
index fccb313..3a3b7a1 100644
--- a/src/H5Tcommit.c
+++ b/src/H5Tcommit.c
@@ -140,13 +140,17 @@ H5T_commit (H5G_entry_t *loc, const char *name, H5T_t *type, hid_t dxpl_id)
if (H5T_STATE_IMMUTABLE==type->state)
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "data type is immutable");
+ /* Find the insertion file */
+ if (NULL==(file=H5G_insertion_file(loc, name, dxpl_id)))
+ HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to find insertion point");
+
/* Check for a "sensible" datatype to store on disk */
if(H5T_is_sensible(type)!=TRUE)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "datatype is not sensible");
- /* Find the insertion file */
- if (NULL==(file=H5G_insertion_file(loc, name, dxpl_id)))
- HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to find insertion point");
+ /* Mark datatype as being on disk now */
+ if(H5T_set_loc(type, file, H5T_LOC_DISK)<0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype on disk")
/*
* Create the object header and open it for write access. Insert the data
@@ -160,6 +164,10 @@ H5T_commit (H5G_entry_t *loc, const char *name, H5T_t *type, hid_t dxpl_id)
HGOTO_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to name data type");
type->state = H5T_STATE_OPEN;
+ /* Mark datatype as being on memory now */
+ if(H5T_set_loc(type, NULL, H5T_LOC_MEMORY)<0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype in memory")
+
done:
if (ret_value<0) {
if ((type->state==H5T_STATE_TRANSIENT || type->state==H5T_STATE_RDONLY) && H5F_addr_defined(type->ent.header)) {
@@ -170,6 +178,7 @@ done:
type->ent.header = HADDR_UNDEF;
}
}
+
FUNC_LEAVE_NOAPI(ret_value);
}
diff --git a/test/dtypes.c b/test/dtypes.c
index e1bc0a5..a01e765 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -60,6 +60,7 @@ const char *FILENAME[] = {
"dtypes1",
"dtypes2",
"dtypes3",
+ "dtypes4",
NULL
};
@@ -1464,6 +1465,207 @@ test_compound_8(void)
/*-------------------------------------------------------------------------
+ * Function: test_compound_9
+ *
+ * Purpose: Tests compound data type with VL string as field.
+ *
+ * Return: Success: 0
+ *
+ * Failure: number of errors
+ *
+ * Programmer: Raymond Lu
+ * Wednesday, June 9, 2004
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_compound_9(void)
+{
+ typedef struct cmpd_struct {
+ int i1;
+ const char* str;
+ int i2;
+ } cmpd_struct;
+
+ cmpd_struct wdata = {11, "variable-length string", 22};
+ cmpd_struct rdata;
+ hid_t file;
+ hid_t cmpd_tid, str_id, dup_tid;
+ hid_t space_id;
+ hid_t dset_id;
+ hsize_t dim1[1];
+ char filename[1024];
+
+ TESTING("compound data type with VL string");
+
+ /* Create File */
+ h5_fixname(FILENAME[3], H5P_DEFAULT, filename, sizeof filename);
+ if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) {
+ H5_FAILED(); AT();
+ printf("Can't create file!\n");
+ goto error;
+ } /* end if */
+
+ /* Create first compound datatype */
+ if((cmpd_tid = H5Tcreate( H5T_COMPOUND, sizeof(struct cmpd_struct)))<0) {
+ H5_FAILED(); AT();
+ printf("Can't create datatype!\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tinsert(cmpd_tid,"i1",HOFFSET(struct cmpd_struct,i1),H5T_NATIVE_INT)<0) {
+ H5_FAILED(); AT();
+ printf("Can't insert field 'i1'\n");
+ goto error;
+ } /* end if */
+
+ str_id = H5Tcopy(H5T_C_S1);
+ if(H5Tset_size(str_id,H5T_VARIABLE)<0) {
+ H5_FAILED(); AT();
+ printf("Can't set size for VL string\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tinsert(cmpd_tid,"vl_string",HOFFSET(cmpd_struct,str),str_id)<0) {
+ H5_FAILED(); AT();
+ printf("Can't insert field 'i1'\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tinsert(cmpd_tid,"i2",HOFFSET(struct cmpd_struct,i2),H5T_NATIVE_INT)<0) {
+ H5_FAILED(); AT();
+ printf("Can't insert field 'i2'\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tcommit(file,"compound",cmpd_tid)<0) {
+ H5_FAILED(); AT();
+ printf("Can't commit datatype\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tclose(cmpd_tid)<0) {
+ H5_FAILED(); AT();
+ printf("Can't close datatype\n");
+ goto error;
+ } /* end if */
+
+ if((cmpd_tid = H5Topen(file, "compound"))<0) {
+ H5_FAILED(); AT();
+ printf("Can't open datatype\n");
+ goto error;
+ } /* end if */
+
+ if((dup_tid = H5Tcopy(cmpd_tid))<0) {
+ H5_FAILED(); AT();
+ printf("Can't copy datatype\n");
+ goto error;
+ } /* end if */
+
+ dim1[0] = 1;
+ if((space_id=H5Screate_simple(1,dim1,NULL))<0) {
+ H5_FAILED(); AT();
+ printf("Can't create space\n");
+ goto error;
+ } /* end if */
+
+ if((dset_id = H5Dcreate(file,"Dataset",dup_tid,space_id,H5P_DEFAULT))<0) {
+ H5_FAILED(); AT();
+ printf("Can't create dataset\n");
+ goto error;
+ } /* end if */
+
+ if(H5Dwrite(dset_id,dup_tid,H5S_ALL,H5S_ALL,H5P_DEFAULT,&wdata)<0) {
+ H5_FAILED(); AT();
+ printf("Can't write data\n");
+ goto error;
+ } /* end if */
+
+ if(H5Dread(dset_id,dup_tid,H5S_ALL,H5S_ALL,H5P_DEFAULT,&rdata)<0) {
+ H5_FAILED(); AT();
+ printf("Can't read data\n");
+ goto error;
+ } /* end if */
+
+ if(rdata.i1!=wdata.i1 || rdata.i2!=wdata.i2 || strcmp(rdata.str, wdata.str)) {
+ H5_FAILED(); AT();
+ printf("incorrect read data\n");
+ goto error;
+ } /* end if */
+
+ if(H5Dclose(dset_id)<0)
+ goto error;
+ if(H5Tclose(cmpd_tid)<0)
+ goto error;
+ /*if(H5Tclose(dup_tid)<0)
+ goto error;*/
+ if(H5Tclose(str_id)<0)
+ goto error;
+ if(H5Sclose(space_id)<0)
+ goto error;
+ if(H5Fclose(file)<0)
+ goto error;
+
+
+ if((file=H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT))<0) {
+ H5_FAILED(); AT();
+ printf("cannot open file\n");
+ goto error;
+ } /* end if */
+
+ if((dset_id = H5Dopen(file, "Dataset"))<0) {
+ H5_FAILED(); AT();
+ printf("cannot open dataset\n");
+ goto error;
+ } /* end if */
+
+ if((cmpd_tid = H5Dget_type(dset_id))<0) {
+ H5_FAILED(); AT();
+ printf("cannot open dataset\n");
+ goto error;
+ } /* end if */
+
+ if((dup_tid = H5Tcopy(cmpd_tid))<0) {
+ H5_FAILED(); AT();
+ printf("Can't copy datatype\n");
+ goto error;
+ } /* end if */
+
+ rdata.i1 = rdata.i2 = 0;
+ free(rdata.str);
+
+ if(H5Dread(dset_id,dup_tid,H5S_ALL,H5S_ALL,H5P_DEFAULT,&rdata)<0) {
+ H5_FAILED(); AT();
+ printf("Can't read data\n");
+ goto error;
+ } /* end if */
+
+ if(rdata.i1!=wdata.i1 || rdata.i2!=wdata.i2 || strcmp(rdata.str, wdata.str)) {
+ H5_FAILED(); AT();
+ printf("incorrect read data\n");
+ goto error;
+ } /* end if */
+
+ if(H5Dclose(dset_id)<0)
+ goto error;
+ if(H5Tclose(cmpd_tid)<0)
+ goto error;
+ if(H5Tclose(dup_tid)<0)
+ goto error;
+ if(H5Fclose(file)<0)
+ goto error;
+
+ PASSED();
+ return 0;
+
+ error:
+ return 1;
+}
+
+
+/*-------------------------------------------------------------------------
* Function: test_query
*
* Purpose: Tests query functions of compound and enumeration types.
@@ -5801,6 +6003,7 @@ main(void)
nerrors += test_compound_6();
nerrors += test_compound_7();
nerrors += test_compound_8();
+ nerrors += test_compound_9();
nerrors += test_conv_int ();
nerrors += test_conv_enum_1();
nerrors += test_conv_enum_2();