diff options
Diffstat (limited to 'src/H5Tcommit.c')
-rw-r--r-- | src/H5Tcommit.c | 122 |
1 files changed, 90 insertions, 32 deletions
diff --git a/src/H5Tcommit.c b/src/H5Tcommit.c index bcb9962..46a1ac8 100644 --- a/src/H5Tcommit.c +++ b/src/H5Tcommit.c @@ -18,12 +18,19 @@ * to a file for the H5T interface. */ +/****************/ +/* Module Setup */ +/****************/ + #define H5T_PACKAGE /*suppress error about including H5Tpkg */ /* Interface initialization */ #define H5_INTERFACE_INIT_FUNC H5T_init_commit_interface +/***********/ +/* Headers */ +/***********/ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5FOprivate.h" /* File objects */ @@ -32,9 +39,48 @@ #include "H5Pprivate.h" /* Property lists */ #include "H5Tpkg.h" /* Datatypes */ -/* Static local functions */ + +/****************/ +/* Local Macros */ +/****************/ + + +/******************/ +/* Local Typedefs */ +/******************/ + + +/********************/ +/* Package Typedefs */ +/********************/ + + +/********************/ +/* Local Prototypes */ +/********************/ static H5T_t *H5T_open_oid(const H5G_loc_t *loc, hid_t dxpl_id); + +/*********************/ +/* Public Variables */ +/*********************/ + + +/*********************/ +/* Package Variables */ +/*********************/ + + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + + +/*******************/ +/* Local Variables */ +/*******************/ + + /*-------------------------------------------------------------------------- NAME @@ -87,7 +133,7 @@ H5Tcommit2(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") if(!name || !*name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name") - if(NULL == (type = H5I_object_verify(type_id, H5I_DATATYPE))) + if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") /* Get correct property list */ @@ -224,17 +270,17 @@ done: herr_t H5Tcommit_anon(hid_t loc_id, hid_t type_id, hid_t tcpl_id, hid_t tapl_id) { - H5G_loc_t loc; - H5T_t *type = NULL; - herr_t ret_value=SUCCEED; /* Return value */ + H5G_loc_t loc; /* Group location for location */ + H5T_t *type = NULL; /* Datatype created */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(H5Tcommit_anon, FAIL) H5TRACE4("e", "iiii", loc_id, type_id, tcpl_id, tapl_id); /* Check arguments */ - if(H5G_loc (loc_id, &loc) < 0) + if(H5G_loc(loc_id, &loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - if(NULL == (type = H5I_object_verify(type_id, H5I_DATATYPE))) + if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") /* Get correct property list */ @@ -288,6 +334,10 @@ H5T_commit(H5F_t *file, H5T_t *type, hid_t tcpl_id, hid_t dxpl_id) HDassert(type); HDassert(tcpl_id != H5P_DEFAULT); + /* Check if we are allowed to write to this file */ + if(0 == (H5F_INTENT(file) & H5F_ACC_RDWR)) + HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "no write intent on file") + /* * Check arguments. We cannot commit an immutable type because H5Tclose() * normally fails on such types (try H5Tclose(H5T_NATIVE_INT)) but closing @@ -302,8 +352,9 @@ H5T_commit(H5F_t *file, H5T_t *type, hid_t tcpl_id, hid_t dxpl_id) if(H5T_is_sensible(type) <= 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "datatype is not sensible") - /* Mark datatype as being on disk now. This step changes the size of datatype as - * stored on disk. */ + /* Mark datatype as being on disk now. This step changes the size of + * datatype as stored on disk. + */ if(H5T_set_loc(type, file, H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype on disk") @@ -350,8 +401,9 @@ H5T_commit(H5F_t *file, H5T_t *type, hid_t tcpl_id, hid_t dxpl_id) if(H5FO_insert(type->sh_loc.file, type->sh_loc.u.loc.oh_addr, type->shared, TRUE) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "can't insert datatype into list of open objects") - /* Mark datatype as being on memory now. Since this datatype may still be used in memory - * after committed to disk, change its size back as in memory. */ + /* Mark datatype as being on memory again. Since this datatype may still be + * used in memory after committed to disk, change its size back as in memory. + */ if(H5T_set_loc(type, NULL, H5T_LOC_MEMORY) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype in memory") @@ -391,14 +443,14 @@ done: htri_t H5Tcommitted(hid_t type_id) { - H5T_t *type = NULL; - htri_t ret_value; /* Return value */ + H5T_t *type; /* Datatype to query */ + htri_t ret_value; /* Return value */ FUNC_ENTER_API(H5Tcommitted, FAIL) H5TRACE1("t", "i", type_id); /* Check arguments */ - if(NULL == (type = H5I_object_verify(type_id,H5I_DATATYPE))) + if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") /* Set return value */ @@ -440,7 +492,6 @@ H5T_committed(const H5T_t *type) * ADJUST to the link count. * * Return: Success: New link count - * * Failure: Negative * * Programmer: Quincey Koziol @@ -484,15 +535,15 @@ done: hid_t H5Topen2(hid_t loc_id, const char *name, hid_t tapl_id) { - H5T_t *type = NULL; - H5G_loc_t loc; + H5T_t *type = NULL; /* Datatype opened in file */ + H5G_loc_t loc; /* Group location of object to open */ H5G_name_t path; /* Datatype group hier. path */ H5O_loc_t oloc; /* Datatype object location */ H5O_type_t obj_type; /* Type of object at location */ H5G_loc_t type_loc; /* Group object for datatype */ hbool_t obj_found = FALSE; /* Object at 'name' found */ hid_t dxpl_id = H5AC_dxpl_id; /* dxpl to use to open datatype */ - hid_t ret_value = FAIL; + hid_t ret_value = FAIL; /* Return value */ FUNC_ENTER_API(H5Topen2, FAIL) H5TRACE3("i", "i*si", loc_id, name, tapl_id); @@ -530,11 +581,11 @@ H5Topen2(hid_t loc_id, const char *name, hid_t tapl_id) HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a named datatype") /* Open it */ - if((type = H5T_open(&type_loc, dxpl_id)) == NULL) + if(NULL == (type = H5T_open(&type_loc, dxpl_id))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to open named datatype") /* Register the type and return the ID */ - if((ret_value = H5I_register(H5I_DATATYPE, type)) < 0) + if((ret_value = H5I_register(H5I_DATATYPE, type, TRUE)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register named datatype") done: @@ -580,13 +631,13 @@ H5Tget_create_plist(hid_t dtype_id) H5TRACE1("i", "i", dtype_id); /* Check arguments */ - if(NULL == (type = H5I_object_verify(dtype_id, H5I_DATATYPE))) + if(NULL == (type = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") /* Copy the default datatype creation property list */ - if(NULL == (tcpl_plist = H5I_object(H5P_LST_DATATYPE_CREATE_g))) + if(NULL == (tcpl_plist = (H5P_genplist_t *)H5I_object(H5P_LST_DATATYPE_CREATE_g))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get default creation property list") - if((new_tcpl_id = H5P_copy_plist(tcpl_plist)) < 0) + if((new_tcpl_id = H5P_copy_plist(tcpl_plist, TRUE)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to copy the creation property list") /* Check if the datatype is committed */ @@ -598,7 +649,7 @@ H5Tget_create_plist(hid_t dtype_id) H5P_genplist_t *new_plist; /* New datatype creation property list */ /* Get property list object for new TCPL */ - if(NULL == (new_plist = H5I_object(new_tcpl_id))) + if(NULL == (new_plist = (H5P_genplist_t *)H5I_object(new_tcpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get property list") /* Retrieve any object creation properties */ @@ -612,7 +663,7 @@ H5Tget_create_plist(hid_t dtype_id) done: if(ret_value < 0) if(new_tcpl_id > 0) - (void)H5I_dec_ref(new_tcpl_id); + (void)H5I_dec_ref(new_tcpl_id, TRUE); FUNC_LEAVE_API(ret_value) } /* end H5Tget_create_plist() */ @@ -644,12 +695,12 @@ H5T_open(const H5G_loc_t *loc, hid_t dxpl_id) HDassert(loc); /* Check if datatype was already open */ - if((shared_fo = H5FO_opened(loc->oloc->file, loc->oloc->addr)) == NULL) { + if(NULL == (shared_fo = (H5T_shared_t *)H5FO_opened(loc->oloc->file, loc->oloc->addr))) { /* Clear any errors from H5FO_opened() */ H5E_clear_stack(NULL); /* Open the datatype object */ - if((dt = H5T_open_oid(loc, dxpl_id)) == NULL) + if(NULL == (dt = H5T_open_oid(loc, dxpl_id))) HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, "not found") /* Add the datatype to the list of opened objects in the file */ @@ -694,6 +745,10 @@ H5T_open(const H5G_loc_t *loc, hid_t dxpl_id) /* Point to shared datatype info */ dt->shared = shared_fo; + /* 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") + /* Increment ref. count on shared info */ shared_fo->fo_count++; @@ -715,12 +770,12 @@ done: if(ret_value == NULL) { if(dt) { if(shared_fo == NULL) /* Need to free shared fo */ - H5FL_FREE(H5T_shared_t, dt->shared); + dt->shared = H5FL_FREE(H5T_shared_t, dt->shared); H5O_loc_free(&(dt->oloc)); H5G_name_free(&(dt->path)); - H5FL_FREE(H5T_t, dt); + dt = H5FL_FREE(H5T_t, dt); } /* end if */ if(shared_fo) @@ -748,16 +803,19 @@ done: static H5T_t * H5T_open_oid(const H5G_loc_t *loc, hid_t dxpl_id) { - H5T_t *dt = NULL; - H5T_t *ret_value; + H5T_t *dt = NULL; /* Datatype from the file */ + H5T_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5T_open_oid) HDassert(loc); + /* Open named datatype object in file */ if(H5O_open(loc->oloc) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to open named datatype") - if(NULL == (dt = H5O_msg_read(loc->oloc, H5O_DTYPE_ID, NULL, dxpl_id))) + + /* Deserialize the datatype message into a datatype in memory */ + if(NULL == (dt = (H5T_t *)H5O_msg_read(loc->oloc, H5O_DTYPE_ID, NULL, dxpl_id))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to load type message from object header") /* Mark the type as named and open */ |