diff options
-rw-r--r-- | examples/h5_elink_unix2win.c | 20 | ||||
-rw-r--r-- | examples/h5_extlink.c | 52 | ||||
-rw-r--r-- | hl/examples/ex_table_04.c | 7 | ||||
-rw-r--r-- | hl/examples/ptExampleFL.c | 2 | ||||
-rw-r--r-- | src/H5L.c | 64 | ||||
-rw-r--r-- | src/H5Lexternal.c | 173 | ||||
-rw-r--r-- | src/H5Lpublic.h | 24 | ||||
-rw-r--r-- | test/be_extlink1.h5 | bin | 896 -> 896 bytes | |||
-rw-r--r-- | test/dt_arith.c | 4 | ||||
-rw-r--r-- | test/error_test.c | 4 | ||||
-rw-r--r-- | test/fheap.c | 2 | ||||
-rw-r--r-- | test/le_extlink1.h5 | bin | 896 -> 896 bytes | |||
-rw-r--r-- | test/links.c | 260 | ||||
-rw-r--r-- | tools/h5dump/h5dump.c | 60 | ||||
-rw-r--r-- | tools/h5ls/h5ls.c | 10 | ||||
-rw-r--r-- | tools/lib/h5trav.c | 58 | ||||
-rw-r--r-- | tools/testfiles/tall.h5 | bin | 9968 -> 9968 bytes | |||
-rw-r--r-- | tools/testfiles/tboot1.ddl | 2 | ||||
-rw-r--r-- | tools/testfiles/textlink.h5 | bin | 936 -> 936 bytes | |||
-rw-r--r-- | tools/testfiles/tfcontents1.h5 | bin | 7426 -> 7426 bytes | |||
-rw-r--r-- | tools/testfiles/tmany.h5 | bin | 18536 -> 18536 bytes | |||
-rw-r--r-- | tools/testfiles/tudlink.h5 | bin | 904 -> 904 bytes | |||
-rw-r--r-- | tools/testfiles/twithub.h5 | bin | 10592 -> 10592 bytes | |||
-rw-r--r-- | tools/testfiles/twithub513.h5 | bin | 11056 -> 11056 bytes |
24 files changed, 389 insertions, 353 deletions
diff --git a/examples/h5_elink_unix2win.c b/examples/h5_elink_unix2win.c index ef38626..abf7512 100644 --- a/examples/h5_elink_unix2win.c +++ b/examples/h5_elink_unix2win.c @@ -39,12 +39,12 @@ * Note that this may not be necessary on your system; many Windows systems can * understand Unix paths. */ -static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group, void * udata, size_t udata_size, hid_t lapl_id) +static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group, + const void *udata, size_t udata_size, hid_t lapl_id) { hid_t fid; - char *file_name = NULL; - char *obj_name; - char *elink_prefix; /* External link prefix */ + const char *file_name; + const char *obj_name; char *new_fname = NULL; /* Buffer allocated to hold Unix file path */ ssize_t prefix_len; /* External link prefix length */ size_t fname_len; @@ -54,7 +54,7 @@ static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group, void * printf("Converting Unix path to Windows path.\n"); - if(H5Lunpack_elink_val(udata, udata_size, &file_name, &obj_name) < 0) + if(H5Lunpack_elink_val(udata, udata_size, NULL, &file_name, &obj_name) < 0) goto error; fname_len = strlen(file_name); @@ -71,7 +71,7 @@ static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group, void * new_fname = malloc(prefix_len + fname_len + 1); /* Copy the prefix into the buffer */ - if(H5Pget_elink_prefix(lapl_id, new_fname, prefix_len + 1) < 0) + if(H5Pget_elink_prefix(lapl_id, new_fname, (size_t)(prefix_len + 1)) < 0) goto error; start_pos = prefix_len; @@ -102,16 +102,14 @@ static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group, void * if(H5Fclose(fid) < 0) goto error; - /* Free file names if they've been allocated */ + /* Free file name if it's been allocated */ if(new_fname) free(new_fname); - if(file_name) - free(file_name); return ret_value; error: - /* Free file_name if it's been allocated */ + /* Free file name if it's been allocated */ if(new_fname) free(new_fname); return -1; @@ -138,7 +136,7 @@ const H5L_class_t elink_unix2win_class[1] = {{ * follows the external link to open the target file. */ static int -unix2win_example() +unix2win_example(void) { hid_t fid = (-1); /* File ID */ hid_t gid = (-1); /* Group ID */ diff --git a/examples/h5_extlink.c b/examples/h5_extlink.c index 121e0a8..dd5a834 100644 --- a/examples/h5_extlink.c +++ b/examples/h5_extlink.c @@ -51,7 +51,7 @@ * Creates two files and uses an external link to access an object in the * second file from the first file. */ -void extlink_example(void) +static void extlink_example(void) { hid_t source_file_id, targ_file_id; hid_t group_id, group2_id; @@ -111,7 +111,7 @@ void extlink_example(void) * where it is run (so to run this example on Unix, first mkdir red and mkdir * blue). */ -void extlink_prefix_example(void) +static void extlink_prefix_example(void) { hid_t source_file_id, red_file_id, blue_file_id; hid_t group_id, group2_id; @@ -209,9 +209,10 @@ void extlink_prefix_example(void) * We might also have wanted to supply a creation callback that checks * that a path was supplied in the udata. */ -static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group, void *udata, size_t udata_size, hid_t lapl_id); +static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group, + const void *udata, size_t udata_size, hid_t lapl_id); -void soft_link_example(void) +static void soft_link_example(void) { hid_t file_id; hid_t group_id; @@ -276,9 +277,11 @@ void soft_link_example(void) * The actual traversal function simply needs to open the correct object by * name and return its ID. */ -static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group, void *udata, size_t udata_size, hid_t lapl_id) + +static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group, + const void *udata, size_t udata_size, hid_t lapl_id) { - const char *target = (char *) udata; + const char *target = (const char *) udata; hid_t ret_value; /* Pass the udata straight through to HDF5. If it's invalid, let HDF5 @@ -288,7 +291,6 @@ static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group, void *udat return ret_value; } - /* Hard Link example * @@ -305,11 +307,14 @@ static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group, void *udat * To keep the example simple, these links don't have a query callback. * Generally, real link classes should always be query-able. */ -static herr_t UD_hard_create(const char *link_name, hid_t loc_group, void *udata, size_t udata_size, hid_t lcpl_id); -static herr_t UD_hard_delete(const char *link_name, hid_t loc_group, void *udata, size_t udata_size); -static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group, void *udata, size_t udata_size, hid_t lapl_id); - -void hard_link_example(void) +static herr_t UD_hard_create(const char *link_name, hid_t loc_group, + const void *udata, size_t udata_size, hid_t lcpl_id); +static herr_t UD_hard_delete(const char *link_name, hid_t loc_group, + const void *udata, size_t udata_size); +static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group, + const void *udata, size_t udata_size, hid_t lapl_id); + +static void hard_link_example(void) { hid_t file_id; hid_t group_id; @@ -398,7 +403,8 @@ void hard_link_example(void) * If this function returns a negative value, the call to H5Lcreate_ud() * will also return failure and the link will not be created. */ -static herr_t UD_hard_create(const char *link_name, hid_t loc_group, void *udata, size_t udata_size, hid_t lcpl_id) +static herr_t UD_hard_create(const char *link_name, hid_t loc_group, + const void *udata, size_t udata_size, hid_t lcpl_id) { haddr_t addr; hid_t target_obj = -1; @@ -411,7 +417,7 @@ static herr_t UD_hard_create(const char *link_name, hid_t loc_group, void *udata goto done; } - addr = *((haddr_t *) udata); + addr = *((const haddr_t *) udata); /* Open the object this link points to so that we can increment * its reference count. This also ensures that the address passed @@ -441,7 +447,8 @@ done: * Since the creation function increments the object's reference count, it's * important to decrement it again when the link is deleted. */ -static herr_t UD_hard_delete(const char *link_name, hid_t loc_group, void *udata, size_t udata_size) +static herr_t UD_hard_delete(const char *link_name, hid_t loc_group, + const void *udata, size_t udata_size) { haddr_t addr; hid_t target_obj = -1; @@ -456,7 +463,7 @@ static herr_t UD_hard_delete(const char *link_name, hid_t loc_group, void *udata goto done; } - addr = *((haddr_t *) udata); + addr = *((const haddr_t *) udata); /* Open the object this link points to */ target_obj= H5Oopen_by_addr(loc_group, addr); @@ -484,7 +491,8 @@ done: * The actual traversal function simply needs to open the correct object and * return its ID. */ -static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group, void * udata, size_t udata_size, hid_t lapl_id) +static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group, + const void *udata, size_t udata_size, hid_t lapl_id) { haddr_t addr; hid_t ret_value = -1; @@ -495,7 +503,7 @@ static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group, void * uda if(udata_size != sizeof(haddr_t)) return -1; - addr = *((haddr_t *) udata); + addr = *((const haddr_t *) udata); /* Open the object by address. If H5Oopen_by_addr fails, ret_value will * be negative to indicate that the traversal function failed. @@ -520,9 +528,10 @@ static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group, void * uda * These are defined after the example below. * These links have no udata, so they don't need a query function. */ -static hid_t UD_plist_traverse(const char *link_name, hid_t cur_group, void *udata, size_t udata_size, hid_t lapl_id); +static hid_t UD_plist_traverse(const char *link_name, hid_t cur_group, + const void *udata, size_t udata_size, hid_t lapl_id); -void plist_link_example(void) +static void plist_link_example(void) { hid_t file_id; hid_t group_id, group2_id; @@ -610,7 +619,8 @@ void plist_link_example(void) /* UD_plist_traverse * Open a path passed in through the property list. */ -static hid_t UD_plist_traverse(const char *link_name, hid_t cur_group, void * udata, size_t udata_size, hid_t lapl_id) +static hid_t UD_plist_traverse(const char *link_name, hid_t cur_group, + const void *udata, size_t udata_size, hid_t lapl_id) { char * path; hid_t ret_value = -1; diff --git a/hl/examples/ex_table_04.c b/hl/examples/ex_table_04.c index 5912c43..f10f526 100644 --- a/hl/examples/ex_table_04.c +++ b/hl/examples/ex_table_04.c @@ -70,8 +70,6 @@ int main( void ) sizeof( dst_buf[0].temperature)}; size_t field_offset_pos[2] = { HOFFSET( Position, lati ), HOFFSET( Position, longi )}; - size_t field_offset_namepre[2] = { HOFFSET( NamePressure, name ), - HOFFSET( NamePressure, pressure )}; const char *field_names[NFIELDS] = /* Define field information */ { "Name","Latitude", "Longitude", "Pressure", "Temperature" }; hid_t field_type[NFIELDS]; @@ -102,11 +100,6 @@ int main( void ) sizeof(position_in[0].longi), sizeof(position_in[0].lati) }; - size_t field_sizes_namepre[2]= - { - sizeof(namepre_in[0].name), - sizeof(namepre_in[0].pressure) - }; size_t field_sizes_pre[1]= { sizeof(namepre_in[0].pressure) diff --git a/hl/examples/ptExampleFL.c b/hl/examples/ptExampleFL.c index 956f1d6..bbd0bf6 100644 --- a/hl/examples/ptExampleFL.c +++ b/hl/examples/ptExampleFL.c @@ -72,7 +72,7 @@ int main(void) if(err < 0) goto out; - printf("Number of packets in packet table after five appends: %d\n", count); + printf("Number of packets in packet table after five appends: %d\n", (int)count); /* Initialize packet table's "current record" */ err = H5PTcreate_index(ptable); @@ -613,8 +613,7 @@ H5Lcreate_ud(hid_t link_loc_id, const char *link_name, H5L_type_t link_type, HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no link name specified") /* Create external link */ - if(H5L_create_ud(&link_loc, link_name, udata, udata_size, link_type, - lcpl_id, lapl_id, H5AC_dxpl_id) < 0) + if(H5L_create_ud(&link_loc, link_name, udata, udata_size, link_type, lcpl_id, lapl_id, H5AC_dxpl_id) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link") done: @@ -1512,17 +1511,15 @@ H5L_link_cb(H5G_loc_t *grp_loc/*in*/, const char *name, const H5O_link_t UNUSED if(H5G_name_set(grp_loc->path, udata->path, name) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "cannot set name") - /* If link is a user-defined link, trigger its creation callback if it has one*/ - if(udata->lnk->type >= H5L_TYPE_UD_MIN) - { + /* If link is a user-defined link, trigger its creation callback if it has one */ + if(udata->lnk->type >= H5L_TYPE_UD_MIN) { const H5L_class_t *link_class; /* User-defined link class */ /* Get the link class for this type of link. */ if(NULL == (link_class = H5L_find_class(udata->lnk->type))) HGOTO_ERROR(H5E_LINK, H5E_NOTREGISTERED, FAIL, "unable to get class of UD link") - if(link_class->create_func != NULL) - { + if(link_class->create_func != NULL) { H5O_loc_t temp_oloc; H5G_name_t temp_path; @@ -1551,16 +1548,14 @@ H5L_link_cb(H5G_loc_t *grp_loc/*in*/, const char *name, const H5O_link_t UNUSED done: /* Close the location given to the user callback if it was created */ - if(grp_id >= 0) - { + if(grp_id >= 0) { if(H5I_dec_ref(grp_id) < 0) HDONE_ERROR(H5E_ATOM, H5E_CANTRELEASE, FAIL, "unable to close atom from UD callback") - } - else if(grp != NULL) - { + } /* end if */ + else if(grp != NULL) { if(H5G_close(grp) < 0) HDONE_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "unable to close group given to UD callback") - } + } /* end if */ else if(temp_loc_init) H5G_loc_free(&temp_loc); @@ -1615,8 +1610,7 @@ H5L_create_real(H5G_loc_t *link_loc, const char *link_name, H5G_name_t *obj_path HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "can't normalize name") /* Check for flags present in creation property list */ - if(lcpl_id != H5P_DEFAULT) - { + if(lcpl_id != H5P_DEFAULT) { unsigned crt_intmd_group; if(NULL == (lc_plist = H5I_object(lcpl_id))) @@ -1807,7 +1801,7 @@ done: *------------------------------------------------------------------------- */ herr_t -H5L_create_ud(H5G_loc_t *link_loc, const char *link_name, const void * ud_data, +H5L_create_ud(H5G_loc_t *link_loc, const char *link_name, const void *ud_data, size_t ud_data_size, H5L_type_t type, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id) { @@ -1830,11 +1824,10 @@ H5L_create_ud(H5G_loc_t *link_loc, const char *link_name, const void * ud_data, HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "link class has not been registered with library") /* Fill in UD link-specific information in the link struct*/ - if(ud_data_size > 0) - { - lnk.u.ud.udata = H5MM_malloc((size_t) ud_data_size); + if(ud_data_size > 0) { + lnk.u.ud.udata = H5MM_malloc((size_t)ud_data_size); HDmemcpy(lnk.u.ud.udata, ud_data, (size_t) ud_data_size); - } + } /* end if */ else lnk.u.ud.udata = NULL; @@ -2223,16 +2216,14 @@ H5L_move_dest_cb(H5G_loc_t *grp_loc/*in*/, const char *name, HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create new link to object") /* If the link was a user-defined link, call its move callback if it has one */ - if(udata->lnk->type >= H5L_TYPE_UD_MIN) - { + if(udata->lnk->type >= H5L_TYPE_UD_MIN) { const H5L_class_t *link_class; /* User-defined link class */ /* Get the link class for this type of link. */ if(NULL == (link_class = H5L_find_class(udata->lnk->type))) HGOTO_ERROR(H5E_LINK, H5E_NOTREGISTERED, FAIL, "link class is not registered") - if((!udata->copy && link_class->move_func != NULL) || (udata->copy && link_class->move_func)) - { + if((!udata->copy && link_class->move_func) || (udata->copy && link_class->copy_func)) { H5O_loc_t temp_oloc; H5G_name_t temp_path; @@ -2253,13 +2244,11 @@ H5L_move_dest_cb(H5G_loc_t *grp_loc/*in*/, const char *name, if((grp_id = H5I_register(H5I_GROUP, grp)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register group ID") - if(udata->copy) - { + if(udata->copy) { if((link_class->copy_func)(udata->lnk->name, grp_id, udata->lnk->u.ud.udata, udata->lnk->u.ud.size) < 0) HGOTO_ERROR(H5E_LINK, H5E_CALLBACK, FAIL, "UD copy callback returned error") } /* end if */ - else - { + else { if((link_class->move_func)(udata->lnk->name, grp_id, udata->lnk->u.ud.udata, udata->lnk->u.ud.size) < 0) HGOTO_ERROR(H5E_LINK, H5E_CALLBACK, FAIL, "UD move callback returned error") } /* end else */ @@ -2268,16 +2257,14 @@ H5L_move_dest_cb(H5G_loc_t *grp_loc/*in*/, const char *name, done: /* Close the location given to the user callback if it was created */ - if(grp_id >= 0) - { + if(grp_id >= 0) { if(H5I_dec_ref(grp_id) < 0) HDONE_ERROR(H5E_ATOM, H5E_CANTRELEASE, FAIL, "unable to close atom from UD callback") - } - else if(grp != NULL) - { + } /* end if */ + else if(grp != NULL) { if(H5G_close(grp) < 0) HDONE_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "unable to close group given to UD callback") - } + } /* end if */ else if(temp_loc_init) H5G_loc_free(&temp_loc); @@ -2370,8 +2357,7 @@ H5L_move_cb(H5G_loc_t *grp_loc/*in*/, const char *name, const H5O_link_t *lnk, HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "unable to follow symbolic link") /* If this is a move and not a copy operation, change the object's name and remove the old link */ - if(!udata->copy) - { + if(!udata->copy) { H5RS_str_t *dst_name_r; /* Ref-counted version of dest name */ /* Fix names up */ @@ -2402,8 +2388,7 @@ done: * In this special case, the H5L_move_dest_cb callback frees the name * if it succeeds */ - if(link_copied) - { + if(link_copied) { if(udata_out.lnk->type == H5L_TYPE_SOFT) udata_out.lnk->u.soft.name = H5MM_xfree(udata_out.lnk->u.soft.name); else if(udata_out.lnk->type >= H5L_TYPE_UD_MIN && udata_out.lnk->u.ud.size > 0) @@ -2461,8 +2446,7 @@ H5L_move(H5G_loc_t *src_loc, const char *src_name, H5G_loc_t *dst_loc, HDassert(dst_name && *dst_name); /* Check for flags present in creation property list */ - if(lcpl_id != H5P_DEFAULT) - { + if(lcpl_id != H5P_DEFAULT) { unsigned crt_intmd_group; if(NULL == (lc_plist = H5I_object(lcpl_id))) diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c index 254544d..fea2ab5 100644 --- a/src/H5Lexternal.c +++ b/src/H5Lexternal.c @@ -29,15 +29,15 @@ #include "H5Pprivate.h" /* Property lists */ static hid_t H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, - void * udata, size_t UNUSED udata_size, hid_t lapl_id); -static ssize_t H5L_extern_query(const char UNUSED * link_name, void * udata, + const void *udata, size_t UNUSED udata_size, hid_t lapl_id); +static ssize_t H5L_extern_query(const char UNUSED * link_name, const void *udata, size_t udata_size, void * buf /*out*/, size_t buf_size); /* Default External Link link class */ const H5L_class_t H5L_EXTERN_LINK_CLASS[1] = {{ H5L_LINK_CLASS_T_VERS, /* H5L_class_t version */ H5L_TYPE_EXTERNAL, /* Link type id number */ - "external_link", /* Link name for debugging */ + "external", /* Link name for debugging */ NULL, /* Creation callback */ NULL, /* Move callback */ NULL, /* Copy callback */ @@ -46,6 +46,12 @@ const H5L_class_t H5L_EXTERN_LINK_CLASS[1] = {{ H5L_extern_query /* Query callback */ }}; +/* Version of external link format */ +#define H5L_EXT_VERSION 0 + +/* Valid flags for external links */ +#define H5L_EXT_FLAGS_ALL 0 + /*-------------------------------------------------------------------------- NAME @@ -91,29 +97,39 @@ H5L_init_extern_interface(void) */ static hid_t H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, - void * udata, size_t UNUSED udata_size, hid_t lapl_id) + const void *_udata, size_t UNUSED udata_size, hid_t lapl_id) { H5P_genplist_t *plist; /* Property list pointer */ char *my_prefix; /* Library's copy of the prefix */ H5G_loc_t root_loc; /* Location of root group in external file */ H5G_loc_t loc; /* Location of object */ H5F_t *ext_file = NULL; /* File struct for external file */ - char *file_name = (char *)udata; - char *obj_name; - size_t fname_len; - hbool_t fname_alloc = FALSE; - unsigned intent; - hid_t fapl_id = -1; - hid_t ret_value = -1; + const uint8_t *p = (const uint8_t *)_udata; /* Pointer into external link buffer */ + const char *file_name; /* Name of file containing external link's object */ + char *full_name = NULL; /* File name with prefix */ + const char *obj_name; /* Name external link's object */ + size_t fname_len; /* Length of external link file name */ + unsigned intent; /* File access permissions */ + hid_t fapl_id = -1; /* File access property list for external link's file */ + hid_t ext_obj = -1; /* ID for external link's object */ + hid_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5L_extern_traverse, FAIL) /* Sanity checks */ - HDassert(file_name); + HDassert(p); + + /* Check external link version & flags */ + if(((*p >> 4) & 0x0F) > H5L_EXT_VERSION) + HGOTO_ERROR(H5E_LINK, H5E_CANTDECODE, FAIL, "bad version number for external link") + if((*p & 0x0F) & ~H5L_EXT_FLAGS_ALL) + HGOTO_ERROR(H5E_LINK, H5E_CANTDECODE, FAIL, "bad flags for external link") + p++; /* Gather some information from the external link's user data */ + file_name = (const char *)p; fname_len = HDstrlen(file_name); - obj_name = ((char *)udata) + fname_len + 1; + obj_name = (const char *)p + fname_len + 1; /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(lapl_id, H5P_LINK_ACCESS))) @@ -128,15 +144,17 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, size_t prefix_len = HDstrlen(my_prefix); /* Allocate a buffer to hold the filename plus prefix */ - if(NULL == (file_name = H5MM_malloc(prefix_len + fname_len + 1))) + if(NULL == (full_name = H5MM_malloc(prefix_len + fname_len + 1))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate filename buffer") - fname_alloc = TRUE; /* Copy the prefix into the buffer */ - HDstrcpy(file_name, my_prefix); + HDstrcpy(full_name, my_prefix); /* Add the external link's filename to the prefix supplied */ - HDstrcat(file_name, udata); + HDstrcat(full_name, (const char *)p); + + /* Point to name w/prefix */ + file_name = full_name; } /* end if */ /* Get the location for the group holding the external link */ @@ -178,7 +196,7 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "unable to create location for file") /* Open the object referenced in the external file */ - if((ret_value = H5O_open_name(&root_loc, obj_name, lapl_id)) < 0) { + if((ext_obj = H5O_open_name(&root_loc, obj_name, lapl_id)) < 0) { H5F_decr_nopen_objs(ext_file); HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open object") } /* end if */ @@ -191,6 +209,9 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, HGOTO_ERROR(H5E_LINK, H5E_CANTCLOSEFILE, FAIL, "problem closing external file") ext_file = NULL; + /* Set return value */ + ret_value = ext_obj; + done: /* Release resources */ if(fapl_id > 0 && H5I_dec_ref(fapl_id) < 0) @@ -198,9 +219,13 @@ done: if(ext_file && H5F_try_close(ext_file) < 0) HDONE_ERROR(H5E_LINK, H5E_CANTCLOSEFILE, FAIL, "problem closing external file") - /* Free file_name if it's been allocated */ - if(fname_alloc) - H5MM_xfree(file_name); + /* Free full_name if it's been allocated */ + if(full_name) + H5MM_xfree(full_name); + + /* Close object if it's open and something failed */ + if(ret_value < 0 && ext_obj >= 0 && H5I_dec_ref(ext_obj) < 0) + HDONE_ERROR(H5E_ATOM, H5E_CANTRELEASE, FAIL, "unable to close atom for external object") FUNC_LEAVE_NOAPI(ret_value) } /* end H5L_extern_traverse() */ @@ -224,10 +249,19 @@ done: *------------------------------------------------------------------------- */ static ssize_t -H5L_extern_query(const char UNUSED * link_name, void * udata, - size_t udata_size, void * buf /*out*/, size_t buf_size) +H5L_extern_query(const char UNUSED * link_name, const void *_udata, size_t udata_size, + void *buf /*out*/, size_t buf_size) { - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5L_extern_query) + const uint8_t *udata = (const uint8_t *)_udata; /* Pointer to external link buffer */ + ssize_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5L_extern_query) + + /* Check external link version & flags */ + if(((*udata >> 4) & 0x0F) != H5L_EXT_VERSION) + HGOTO_ERROR(H5E_LINK, H5E_CANTDECODE, FAIL, "bad version number for external link") + if((*udata & 0x0F) & ~H5L_EXT_FLAGS_ALL) + HGOTO_ERROR(H5E_LINK, H5E_CANTDECODE, FAIL, "bad flags for external link") /* If the buffer is NULL, skip writing anything in it and just return * the size needed */ @@ -239,7 +273,11 @@ H5L_extern_query(const char UNUSED * link_name, void * udata, HDmemcpy(buf, udata, buf_size); } /* end if */ - FUNC_LEAVE_NOAPI(udata_size) + /* Set return value */ + ret_value = udata_size; + +done: + FUNC_LEAVE_NOAPI(ret_value) } /* end H5L_extern_query() */ @@ -265,12 +303,13 @@ H5L_extern_query(const char UNUSED * link_name, void * udata, */ herr_t H5Lcreate_external(const char *file_name, const char *obj_name, - hid_t link_loc_id, const char *link_name, hid_t lcpl_id, hid_t lapl_id) + hid_t link_loc_id, const char *link_name, hid_t lcpl_id, hid_t lapl_id) { - H5G_loc_t link_loc; - char *temp_name = NULL; - size_t buf_size; - herr_t ret_value = SUCCEED; /* Return value */ + H5G_loc_t link_loc; /* Group location to create link */ + void *ext_link_buf = NULL; /* Buffer to contain external link */ + size_t buf_size; /* Size of buffer to hold external link */ + uint8_t *p; /* Pointer into external link buffer */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(H5Lcreate_external, FAIL) H5TRACE6("e", "*s*si*sii", file_name, obj_name, link_loc_id, link_name, @@ -287,19 +326,25 @@ H5Lcreate_external(const char *file_name, const char *obj_name, HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no link name specified") /* Combine the filename and link name into a single buffer to give to the UD link */ - buf_size = HDstrlen(file_name) + HDstrlen(obj_name) + 2; - if(NULL == (temp_name = H5MM_malloc(buf_size))) + buf_size = 1 + (HDstrlen(file_name) + 1) + (HDstrlen(obj_name) + 1); + if(NULL == (ext_link_buf = H5MM_malloc(buf_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate udata buffer") - HDstrcpy(temp_name, file_name); - HDstrcpy(temp_name + (HDstrlen(file_name) + 1), obj_name); + + /* Encode the external link information */ + p = ext_link_buf; + *p++ = (H5L_EXT_VERSION << 4) | H5L_EXT_FLAGS_ALL; /* External link version & flags */ + HDstrcpy((char *)p, file_name); /* Name of file containing external link's object */ + p += HDstrlen(file_name) + 1; + HDstrcpy((char *)p, obj_name); /* External link's object */ /* Create an external link */ - if(H5L_create_ud(&link_loc, link_name, temp_name, buf_size, H5L_TYPE_EXTERNAL, lcpl_id, lapl_id, H5AC_dxpl_id) < 0) + if(H5L_create_ud(&link_loc, link_name, ext_link_buf, buf_size, H5L_TYPE_EXTERNAL, lcpl_id, lapl_id, H5AC_dxpl_id) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link") done: - if(temp_name != NULL) - H5MM_free(temp_name); + if(ext_link_buf != NULL) + H5MM_free(ext_link_buf); + FUNC_LEAVE_API(ret_value) } /* end H5Lcreate_external() */ @@ -330,21 +375,21 @@ H5L_register_external(void) done: FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5L_register_external() */ /*------------------------------------------------------------------------- * Function: H5Lunpack_elink_val * * Purpose: Given a buffer holding the "link value" from an external link, - * gets pointers to the filename and object path within the - * link value buffer. + * gets pointers to the information within the link value buffer. * - * External link linkvalues are two NULL-terminated strings - * one after the other. + * External link link values contain some flags and + * two NULL-terminated strings, one after the other. * - * FILENAME and OBJ_PATH will be set to pointers within - * ext_linkval unless they are NULL. + * The FLAGS value will be filled in and FILENAME and + * OBJ_PATH will be set to pointers within ext_linkval (unless + * any of these values is NULL). * * Using this function on strings that aren't external link * udata buffers can result in segmentation faults. @@ -357,48 +402,60 @@ done: *------------------------------------------------------------------------- */ herr_t -H5Lunpack_elink_val(char *ext_linkval, size_t link_size, char **filename, - char **obj_path) +H5Lunpack_elink_val(const void *_ext_linkval, size_t link_size, + unsigned *flags, const char **filename, const char **obj_path) { - size_t len; /* Length of the filename in the linkval*/ - herr_t ret_value=SUCCEED; /* Return value */ + const uint8_t *ext_linkval = (const uint8_t *)_ext_linkval; /* Pointer to the link value */ + unsigned lnk_version; /* External link format version */ + unsigned lnk_flags; /* External link flags */ + size_t len; /* Length of the filename in the linkval*/ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(H5Lunpack_elink_val, FAIL) - H5TRACE4("e", "*sz**s**s", ext_linkval, link_size, filename, obj_path); + /* Sanity check external link buffer */ if(ext_linkval == NULL ) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not an external link linkval buffer") - if(link_size <= 1) + lnk_version = (*ext_linkval >> 4) & 0x0F; + lnk_flags = *ext_linkval & 0x0F; + if(lnk_version > H5L_EXT_VERSION) + HGOTO_ERROR(H5E_LINK, H5E_CANTDECODE, FAIL, "bad version number for external link") + if(lnk_flags & ~H5L_EXT_FLAGS_ALL) + HGOTO_ERROR(H5E_LINK, H5E_CANTDECODE, FAIL, "bad flags for external link") + if(link_size <= 2) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid external link buffer") /* Try to do some error checking. If the last character in the linkval * (the last character of obj_path) isn't NULL, then something's wrong. */ - if(ext_linkval[link_size-1] != '\0') + if(ext_linkval[link_size - 1] != '\0') HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "linkval buffer is not NULL-terminated") /* We're now guaranteed that HDstrlen won't segfault, since the buffer has * at least one NULL in it. */ - len = HDstrlen(ext_linkval); + len = HDstrlen(ext_linkval + 1); /* If the first NULL we found was at the very end of the buffer, then * this external link value has no object name and is invalid. */ - if(len + 1>= link_size) + if((len + 1) >= (link_size - 1)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "linkval buffer doesn't contain an object path") /* If we got here then the buffer contains (at least) two strings packed * in the correct way. Assume it's correct and return pointers to the * filename and object path. */ - if(filename != NULL) - *filename = ext_linkval; + if(filename) + *filename = ext_linkval + 1; + if(obj_path) + *obj_path = (ext_linkval + 1) + len + 1; /* Add one for NULL terminator */ - if(obj_path != NULL) - *obj_path = ext_linkval + len + 1; /* Add one for NULL terminator */ + /* Set the flags to return */ + if(flags) + *flags = lnk_flags; done: FUNC_LEAVE_API(ret_value) -} +} /* end H5Lunpack_elink_val() */ diff --git a/src/H5Lpublic.h b/src/H5Lpublic.h index 2c9331f..679f176 100644 --- a/src/H5Lpublic.h +++ b/src/H5Lpublic.h @@ -90,23 +90,29 @@ typedef struct { */ /* Callback prototypes for user-defined links */ /* Link creation callback */ -typedef herr_t (*H5L_create_func_t)(const char * link_name, hid_t loc_group, void * udata, size_t udata_size, hid_t lcpl_id); +typedef herr_t (*H5L_create_func_t)(const char *link_name, hid_t loc_group, + const void *lnkdata, size_t lnkdata_size, hid_t lcpl_id); /* Callback for when the link is moved */ -typedef herr_t (*H5L_move_func_t)(const char * new_name, hid_t new_loc, void * udata, size_t udata_size); +typedef herr_t (*H5L_move_func_t)(const char *new_name, hid_t new_loc, + const void *lnkdata, size_t lnkdata_size); /* Callback for when the link is copied */ -typedef herr_t (*H5L_copy_func_t)(const char * new_name, hid_t new_loc, void * udata, size_t udata_size); +typedef herr_t (*H5L_copy_func_t)(const char *new_name, hid_t new_loc, + const void *lnkdata, size_t lnkdata_size); /* Callback during link traversal */ -typedef herr_t (*H5L_traverse_func_t)(const char * link_name, hid_t cur_group, void * udata, size_t udata_size, hid_t lapl_id); +typedef herr_t (*H5L_traverse_func_t)(const char *link_name, hid_t cur_group, + const void *lnkdata, size_t lnkdata_size, hid_t lapl_id); /* Callback for when the link is deleted */ -typedef herr_t (*H5L_delete_func_t)(const char * link_name, hid_t file, void * udata, size_t udata_size); +typedef herr_t (*H5L_delete_func_t)(const char *link_name, hid_t file, + const void *lnkdata, size_t lnkdata_size); /* Callback for querying the link */ /* Returns the size of the buffer needed */ -typedef ssize_t (*H5L_query_func_t)(const char * link_name, void * udata, size_t udata_size, void * buf /*out*/, size_t buf_size); +typedef ssize_t (*H5L_query_func_t)(const char *link_name, const void *lnkdata, + size_t lnkdata_size, void *buf /*out*/, size_t buf_size); /* User-defined link types */ typedef struct { @@ -167,15 +173,15 @@ H5_DLL herr_t H5Literate(hid_t loc_id, const char *group_name, /* UD link functions */ H5_DLL herr_t H5Lcreate_ud(hid_t link_loc_id, const char *link_name, - H5L_type_t link_type, const void * udata, size_t udata_size, hid_t lcpl_id, + H5L_type_t link_type, const void *udata, size_t udata_size, hid_t lcpl_id, hid_t lapl_id); H5_DLL herr_t H5Lregister(const H5L_class_t *cls); H5_DLL herr_t H5Lunregister(H5L_type_t id); H5_DLL htri_t H5Lis_registered(H5L_type_t id); /* External link functions */ -H5_DLL herr_t H5Lunpack_elink_val(char * ext_linkval/*in*/, size_t link_size, - char ** filename/*out*/, char** obj_path /*out*/); +H5_DLL herr_t H5Lunpack_elink_val(const void *ext_linkval/*in*/, size_t link_size, + unsigned *flags, const char **filename/*out*/, const char **obj_path /*out*/); H5_DLL herr_t H5Lcreate_external(const char *file_name, const char *obj_name, hid_t link_loc_id, const char *link_name, hid_t lcpl_id, hid_t lapl_id); diff --git a/test/be_extlink1.h5 b/test/be_extlink1.h5 Binary files differindex d8a8347..f800185 100644 --- a/test/be_extlink1.h5 +++ b/test/be_extlink1.h5 diff --git a/test/dt_arith.c b/test/dt_arith.c index 2d761ad..b06147c 100644 --- a/test/dt_arith.c +++ b/test/dt_arith.c @@ -725,8 +725,8 @@ static int test_particular_fp_integer(void) hbool_t flag; double src_d = (double)SCHAR_MAX; signed char dst_c; - unsigned char *buf1, *buf2; - unsigned char *saved_buf1, *saved_buf2; + unsigned char *buf1 = NULL, *buf2 = NULL; + unsigned char *saved_buf1 = NULL, *saved_buf2 = NULL; size_t src_size1, src_size2; size_t dst_size1, dst_size2; float src_f = (float)INT_MAX; diff --git a/test/error_test.c b/test/error_test.c index 0df5aa5..e8ccacf 100644 --- a/test/error_test.c +++ b/test/error_test.c @@ -337,8 +337,8 @@ static herr_t test_long_desc(void) { const char *format="Testing very long description string, %s"; - char *long_desc; - char *full_desc; + char *long_desc = NULL; + char *full_desc = NULL; size_t u; const char *test_FUNC="test_long_desc"; diff --git a/test/fheap.c b/test/fheap.c index f3dd7b3..b3f6986 100644 --- a/test/fheap.c +++ b/test/fheap.c @@ -15168,7 +15168,7 @@ test_write(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam) unsigned char tiny_heap_id[HEAP_ID_LEN]; /* Heap ID for 'tiny' object */ unsigned char huge_heap_id[HEAP_ID_LEN]; /* Heap ID for 'huge' object */ hbool_t id_changed = FALSE; /* Whether the heap ID changed */ - unsigned char *rewrite_obj; /* Pointer to re-write buffer for objects */ + unsigned char *rewrite_obj = NULL; /* Pointer to re-write buffer for objects */ fheap_heap_ids_t keep_ids; /* Structure to retain heap IDs */ h5_stat_size_t empty_size; /* Size of a file with an empty heap */ size_t obj_size; /* Size of object */ diff --git a/test/le_extlink1.h5 b/test/le_extlink1.h5 Binary files differindex 7132ad7..10ed0bc 100644 --- a/test/le_extlink1.h5 +++ b/test/le_extlink1.h5 diff --git a/test/links.c b/test/links.c index ff6a8b8..8b44494 100644 --- a/test/links.c +++ b/test/links.c @@ -1592,8 +1592,8 @@ external_link_root(hid_t fapl, hbool_t new_format) ssize_t name_len; /* Length of object name */ char filename1[NAME_BUF_SIZE]; char filename2[NAME_BUF_SIZE]; - char *file; /* File from external link */ - char *path; /* Path from external link */ + const char *file; /* File from external link */ + const char *path; /* Path from external link */ if(new_format) TESTING("external link to root (w/new group format)") @@ -1627,15 +1627,13 @@ external_link_root(hid_t fapl, hbool_t new_format) goto error; } if(H5Lget_val(fid, "ext_link", objname, sizeof(objname), H5P_DEFAULT) < 0) TEST_ERROR - if(H5Lunpack_elink_val(objname, sb.linklen, &file, &path) < 0) TEST_ERROR - if(HDstrcmp(file, filename1)) - { + if(H5Lunpack_elink_val(objname, sb.linklen, NULL, &file, &path) < 0) TEST_ERROR + if(HDstrcmp(file, filename1)) { H5_FAILED(); puts(" External link file name incorrect"); goto error; } - if(HDstrcmp(path, "/")) - { + if(HDstrcmp(path, "/")) { H5_FAILED(); puts(" External link path incorrect"); goto error; @@ -2591,8 +2589,8 @@ external_link_query(hid_t fapl, hbool_t new_format) { hid_t fid = (-1); /* File ID */ hid_t gid = (-1); /* Group IDs */ - char *file_name; /* Name of the file the external link points to */ - char *object_name; /* Name of the object the external link points to */ + const char *file_name; /* Name of the file the external link points to */ + const char *object_name; /* Name of the object the external link points to */ H5G_stat_t sb; /* Object information */ H5L_info_t li; /* Link information */ char filename1[NAME_BUF_SIZE], @@ -2616,7 +2614,7 @@ external_link_query(hid_t fapl, hbool_t new_format) /* Get size of buffer for external link */ if(H5Lget_info(fid, "src", &li, H5P_DEFAULT) < 0) TEST_ERROR - if(li.u.val_size != (HDstrlen(filename2) + HDstrlen("/dst") + 2)) TEST_ERROR + if(li.u.val_size != (1 + (HDstrlen(filename2) + 1) + (HDstrlen("/dst") + 1))) TEST_ERROR if (H5L_TYPE_EXTERNAL != li.type) { H5_FAILED(); puts(" Unexpected link class - should have been an external link"); @@ -2642,7 +2640,7 @@ external_link_query(hid_t fapl, hbool_t new_format) /* Get size of buffer for external link */ if(H5Lget_info(fid, "src", &li, H5P_DEFAULT) < 0) TEST_ERROR - if(li.u.val_size != (HDstrlen(filename2) + HDstrlen("/dst") + 2)) TEST_ERROR + if(li.u.val_size != (1 + (HDstrlen(filename2) + 1) + (HDstrlen("/dst") + 1))) TEST_ERROR if (H5L_TYPE_EXTERNAL != li.type) { H5_FAILED(); puts(" Unexpected link class - should have been an external link"); @@ -2653,7 +2651,7 @@ external_link_query(hid_t fapl, hbool_t new_format) if(H5Lget_val(fid, "src", query_buf, (size_t)NAME_BUF_SIZE, H5P_DEFAULT) < 0) TEST_ERROR /* Extract the file and object names from the buffer */ - if(H5Lunpack_elink_val(query_buf, li.u.val_size, &file_name, &object_name) < 0) TEST_ERROR + if(H5Lunpack_elink_val(query_buf, li.u.val_size, NULL, &file_name, &object_name) < 0) TEST_ERROR /* Compare the file and object names */ if(strcmp(file_name, filename2)) TEST_ERROR @@ -2671,20 +2669,20 @@ external_link_query(hid_t fapl, hbool_t new_format) if(H5Fclose(fid) < 0) TEST_ERROR /* Make sure that passing in NULLs to H5Lunpack_elink_val works */ - if(H5Lunpack_elink_val(query_buf, li.u.val_size, NULL, NULL) < 0) TEST_ERROR + if(H5Lunpack_elink_val(query_buf, li.u.val_size, NULL, NULL, NULL) < 0) TEST_ERROR /* Make sure that bogus cases trigger errors in H5Lunpack_elink_val */ H5E_BEGIN_TRY { - if(H5Lunpack_elink_val(query_buf, li.u.val_size - 1, NULL, NULL) >= 0) TEST_ERROR + if(H5Lunpack_elink_val(query_buf, li.u.val_size - 1, NULL, NULL, NULL) >= 0) TEST_ERROR } H5E_END_TRY H5E_BEGIN_TRY { - if(H5Lunpack_elink_val(query_buf, (size_t)0, NULL, NULL) >= 0) TEST_ERROR + if(H5Lunpack_elink_val(query_buf, (size_t)0, NULL, NULL, NULL) >= 0) TEST_ERROR } H5E_END_TRY H5E_BEGIN_TRY { - if(H5Lunpack_elink_val(NULL, (size_t)0, NULL, NULL) >= 0) TEST_ERROR + if(H5Lunpack_elink_val(NULL, (size_t)0, NULL, NULL, NULL) >= 0) TEST_ERROR } H5E_END_TRY H5E_BEGIN_TRY { - if(H5Lunpack_elink_val(NULL, (size_t)1000, NULL, NULL) >= 0) TEST_ERROR + if(H5Lunpack_elink_val(NULL, (size_t)1000, NULL, NULL, NULL) >= 0) TEST_ERROR } H5E_END_TRY PASSED(); @@ -3730,133 +3728,127 @@ error: /* Callback functions for UD hard links. */ /* UD_hard_create increments the object's reference count */ static herr_t -UD_hard_create(const char UNUSED * link_name, hid_t loc_group, void * udata, size_t udata_size, hid_t UNUSED lcpl_id) +UD_hard_create(const char UNUSED * link_name, hid_t loc_group, const void *udata, + size_t udata_size, hid_t UNUSED lcpl_id) { haddr_t addr; hid_t target_obj = -1; herr_t ret_value = 0; - if(udata_size != sizeof(haddr_t)) - { - ret_value = -1; - goto done; - } + if(udata_size != sizeof(haddr_t)) { + ret_value = -1; + goto done; + } /* end if */ - addr = *((haddr_t *) udata); + addr = *((const haddr_t *)udata); /* Open the object this link points to */ target_obj= H5Oopen_by_addr(loc_group, addr); - if(target_obj < 0) - { - ret_value = -1; - goto done; - } + if(target_obj < 0) { + ret_value = -1; + goto done; + } /* end if */ /* Increment the reference count of the target object */ - if(H5Oincr_refcount(target_obj) < 0) - { - ret_value = -1; - goto done; - } + if(H5Oincr_refcount(target_obj) < 0) { + ret_value = -1; + goto done; + } /* end if */ done: /* Close the target object if we opened it */ - if(target_obj >= 0) - { - switch(H5Iget_type(target_obj)) - { + if(target_obj >= 0) { + switch(H5Iget_type(target_obj)) { case H5I_GROUP: if(H5Gclose(target_obj) < 0) - ret_value = -1; + ret_value = -1; break; case H5I_DATASET: if(H5Dclose(target_obj) < 0) - ret_value = -1; + ret_value = -1; break; case H5I_DATATYPE: if(H5Tclose(target_obj) < 0) - ret_value = -1; + ret_value = -1; break; default: return -1; - } - } + } /* end switch */ + } /* end if */ return ret_value; -} +} /* end UD_hard_create() */ + +/* Traverse a hard link by opening the object */ +static hid_t +UD_hard_traverse(const char UNUSED *link_name, hid_t cur_group, + const void *udata, size_t udata_size, hid_t UNUSED lapl_id) +{ + haddr_t addr; + hid_t ret_value = -1; + + if(udata_size != sizeof(haddr_t)) + return -1; + + addr = *((const haddr_t *) udata); + + ret_value = H5Oopen_by_addr(cur_group, addr); /* If this fails, our return value will be negative. */ + + return ret_value; +} /* end UD_hard_traverse() */ /* UD_hard_delete decrements the object's reference count */ static herr_t -UD_hard_delete(const char UNUSED * link_name, hid_t file, void * udata, size_t udata_size) +UD_hard_delete(const char UNUSED * link_name, hid_t file, const void *udata, + size_t udata_size) { haddr_t addr; hid_t target_obj = -1; herr_t ret_value = 0; - if(udata_size != sizeof(haddr_t)) - { - ret_value = -1; - goto done; - } + if(udata_size != sizeof(haddr_t)) { + ret_value = -1; + goto done; + } /* end if */ - addr = *((haddr_t *) udata); + addr = *((const haddr_t *) udata); /* Open the object this link points to */ target_obj= H5Oopen_by_addr(file, addr); - if(target_obj < 0) - { - ret_value = -1; - goto done; - } + if(target_obj < 0) { + ret_value = -1; + goto done; + } /* end if */ /* Decrement the reference count of the target object */ - if(H5Odecr_refcount(target_obj) < 0) - { - ret_value = -1; - goto done; - } + if(H5Odecr_refcount(target_obj) < 0) { + ret_value = -1; + goto done; + } /* end if */ done: /* Close the target object if we opened it */ - if(target_obj >= 0) - { - switch(H5Iget_type(target_obj)) - { + if(target_obj >= 0) { + switch(H5Iget_type(target_obj)) { case H5I_GROUP: if(H5Gclose(target_obj) < 0) - ret_value = -1; + ret_value = -1; break; case H5I_DATASET: if(H5Dclose(target_obj) < 0) - ret_value = -1; + ret_value = -1; break; case H5I_DATATYPE: if(H5Tclose(target_obj) < 0) - ret_value = -1; + ret_value = -1; break; default: - return -1; - } - } - - return ret_value; -} - -static hid_t -UD_hard_traverse(const char UNUSED *link_name, hid_t cur_group, void * udata, size_t udata_size, hid_t UNUSED lapl_id) -{ - haddr_t addr; - hid_t ret_value = -1; - - if(udata_size != sizeof(haddr_t)) - return -1; - - addr = *((haddr_t *) udata); - - ret_value = H5Oopen_by_addr(cur_group, addr); /* If this fails, our return value will be negative. */ + return -1; + } /* end switch */ + } /* end if */ return ret_value; -} +} /* end UD_hard_delete() */ const H5L_class_t UD_hard_class[1] = {{ H5L_LINK_CLASS_T_VERS, /* H5L_class_t version */ @@ -4010,7 +4002,8 @@ ud_hard_links(hid_t fapl) * in the current group named REREG_TARGET_NAME */ static hid_t -UD_rereg_traverse(const char UNUSED * link_name, hid_t cur_group, void UNUSED * udata, size_t UNUSED udata_size, hid_t lapl_id) +UD_rereg_traverse(const char UNUSED * link_name, hid_t cur_group, + const void UNUSED *udata, size_t UNUSED udata_size, hid_t lapl_id) { hid_t ret_value; @@ -4020,7 +4013,7 @@ UD_rereg_traverse(const char UNUSED * link_name, hid_t cur_group, void UNUSED * error: return -1; -} +} /* end UD_rereg_traverse() */ /* This link class has the same ID number as the UD hard links but * has a very different traversal function */ @@ -4194,7 +4187,8 @@ ud_link_reregister(hid_t fapl) /* Callback functions for UD "callback" links. */ /* Creation callback. Called during move as well. */ static herr_t -UD_cb_create(const char * link_name, hid_t loc_group, void * udata, size_t udata_size, hid_t lcpl_id) +UD_cb_create(const char * link_name, hid_t loc_group, const void *udata, + size_t udata_size, hid_t lcpl_id) { if(!link_name) TEST_ERROR if(loc_group < 0) TEST_ERROR @@ -4209,12 +4203,13 @@ UD_cb_create(const char * link_name, hid_t loc_group, void * udata, size_t udata error: return -1; -} +} /* end UD_cb_create() */ static hid_t -UD_cb_traverse(const char * link_name, hid_t cur_group, void * udata, size_t udata_size, hid_t lapl_id) +UD_cb_traverse(const char * link_name, hid_t cur_group, const void *udata, + size_t udata_size, hid_t lapl_id) { - const char *target = (char *) udata; + const char *target = (const char *)udata; hid_t ret_value; if(!link_name) TEST_ERROR @@ -4232,11 +4227,12 @@ UD_cb_traverse(const char * link_name, hid_t cur_group, void * udata, size_t uda error: return -1; -} +} /* end UD_cb_traverse() */ /* Callback for when the link is moved or renamed */ static herr_t -UD_cb_move(const char * new_name, hid_t new_loc, void * udata, size_t udata_size) +UD_cb_move(const char *new_name, hid_t new_loc, const void *udata, + size_t udata_size) { if(!new_name) TEST_ERROR if(new_loc < 0) TEST_ERROR @@ -4250,11 +4246,12 @@ UD_cb_move(const char * new_name, hid_t new_loc, void * udata, size_t udata_size error: return -1; -} +} /* end UD_cb_move() */ /* Callback for when the link is deleted. Also called during move */ static herr_t -UD_cb_delete(const char * link_name, hid_t file, void * udata, size_t udata_size) +UD_cb_delete(const char *link_name, hid_t file, const void *udata, + size_t udata_size) { if(!link_name) TEST_ERROR if(file < 0) TEST_ERROR @@ -4268,11 +4265,12 @@ UD_cb_delete(const char * link_name, hid_t file, void * udata, size_t udata_size error: return -1; -} +} /* end UD_cb_delete() */ /* Callback for when the link is queried */ static ssize_t -UD_cb_query(const char * link_name, void * udata, size_t udata_size, void* buf, size_t buf_size) +UD_cb_query(const char * link_name, const void *udata, size_t udata_size, + void *buf, size_t buf_size) { if(!link_name) TEST_ERROR if(udata_size > 0 && !udata) TEST_ERROR @@ -4281,18 +4279,17 @@ UD_cb_query(const char * link_name, void * udata, size_t udata_size, void* buf, if(strcmp(udata, UD_CB_TARGET)) TEST_ERROR if(udata_size != UD_CB_TARGET_LEN) TEST_ERROR - if(buf) - { + if(buf) { if(buf_size < 16) TEST_ERROR strcpy(buf, "query succeeded"); - } + } /* end if */ /* There are 15 characters and a NULL in "query succeeded" */ return 16; error: return -1; -} +} /* end UD_cb_query() */ const H5L_class_t UD_cb_class[1] = {{ H5L_LINK_CLASS_T_VERS, /* H5L_class_t version */ @@ -4448,7 +4445,8 @@ ud_callbacks(hid_t fapl, hbool_t new_format) *------------------------------------------------------------------------- */ static hid_t -UD_plist_traverse(const char UNUSED * link_name, hid_t cur_group, void UNUSED * udata, size_t udata_size, hid_t lapl_id) +UD_plist_traverse(const char UNUSED * link_name, hid_t cur_group, + const void UNUSED *udata, size_t udata_size, hid_t lapl_id) { char target[NAME_BUF_SIZE]; hid_t ret_value; @@ -4465,7 +4463,8 @@ UD_plist_traverse(const char UNUSED * link_name, hid_t cur_group, void UNUSED * error: return -1; -} +} /* end UD_plist_traverse() */ + const H5L_class_t UD_plist_class[1] = {{ H5L_LINK_CLASS_T_VERS, /* H5L_class_t version */ UD_PLIST_TYPE, /* Link type id number */ @@ -4590,20 +4589,20 @@ lapl_udata(hid_t fapl, hbool_t new_format) */ static herr_t UD_cbsucc_create(const char UNUSED * link_name, hid_t UNUSED loc_group, - void * udata, size_t udata_size, hid_t UNUSED lcpl_id) + const void *udata, size_t udata_size, hid_t UNUSED lcpl_id) { /* Check to make sure that this "soft link" has a target */ if(udata_size < 1 || !udata) return -1; return 0; -} +} /* end UD_cbsucc_create() */ static hid_t -UD_cbsucc_traverse(const char UNUSED * link_name, hid_t cur_group, - void * udata, size_t UNUSED udata_size, hid_t lapl_id) +UD_cbsucc_traverse(const char UNUSED *link_name, hid_t cur_group, + const void *udata, size_t UNUSED udata_size, hid_t lapl_id) { - const char *target = (char *) udata; + const char *target = (const char *)udata; hid_t ret_value; if(!target) goto error; @@ -4614,57 +4613,57 @@ UD_cbsucc_traverse(const char UNUSED * link_name, hid_t cur_group, error: return -1; -} +} /* end UD_cbsucc_traverse() */ /* Failure callback for when the link is moved or renamed */ static herr_t -UD_cbfail_move(const char UNUSED * new_name, hid_t UNUSED new_loc, - void UNUSED * udata, size_t UNUSED udata_size) +UD_cbfail_move(const char UNUSED *new_name, hid_t UNUSED new_loc, + const void UNUSED *udata, size_t UNUSED udata_size) { /* This traversal function will always fail. */ return -1; -} +} /* end UD_cbfail_move() */ /* SuccessCallback for when the link is moved or renamed */ static herr_t -UD_cbsucc_move(const char UNUSED * new_name, hid_t UNUSED new_loc, - void UNUSED * udata, size_t UNUSED udata_size) +UD_cbsucc_move(const char UNUSED *new_name, hid_t UNUSED new_loc, + const void UNUSED *udata, size_t UNUSED udata_size) { /* This traversal function will always succeed. */ return 0; -} +} /* end UD_cbsucc_move() */ /* Callback for when the link is deleted. Also called during move */ static herr_t -UD_cbsucc_delete(const char UNUSED * link_name, hid_t UNUSED file, - void UNUSED * udata, size_t UNUSED udata_size) +UD_cbsucc_delete(const char UNUSED *link_name, hid_t UNUSED file, + const void UNUSED *udata, size_t UNUSED udata_size) { /* This callback will always succeed */ return 0; -} +} /* end UD_cbsucc_delete() */ /* Callback for when the link is deleted. Also called during move */ static herr_t -UD_cbfail_delete(const char UNUSED * link_name, hid_t UNUSED file, - void UNUSED * udata, size_t UNUSED udata_size) +UD_cbfail_delete(const char UNUSED *link_name, hid_t UNUSED file, + const void UNUSED *udata, size_t UNUSED udata_size) { /* This traversal function will always fail. */ /* Note: un-deletable links are in general a very bad idea! */ return -1; -} +} /* end UD_cbfail_delete() */ /* Callback for when the link is queried */ static ssize_t -UD_cbfail_query(const char UNUSED * link_name, void UNUSED * udata, +UD_cbfail_query(const char UNUSED *link_name, const void UNUSED *udata, size_t UNUSED udata_size, void UNUSED *buf, size_t UNUSED buf_size) { /* This traversal function will always fail. */ return -1; -} +} /* end UD_cbfail_query() */ /* Callback for when the link is queried */ static ssize_t -UD_cbfail_on_write_query(const char UNUSED * link_name, void UNUSED * udata, +UD_cbfail_on_write_query(const char UNUSED *link_name, const void UNUSED *udata, size_t UNUSED udata_size, void *buf, size_t UNUSED buf_size) { /* This traversal function will return a buffer size, @@ -4676,11 +4675,12 @@ UD_cbfail_on_write_query(const char UNUSED * link_name, void UNUSED * udata, return -1; return 0; -} +} /* end UD_cbfail_on_write_query() */ /* Callback for when the link is queried */ static ssize_t -UD_cbsucc_query(const char UNUSED * link_name, void UNUSED * udata, size_t UNUSED udata_size, void *buf, size_t buf_size) +UD_cbsucc_query(const char UNUSED *link_name, const void UNUSED *udata, + size_t UNUSED udata_size, void *buf, size_t buf_size) { /* This traversal function will return a buffer size, * but will fail when a buffer is passed in ("writing to the buffer" @@ -4691,7 +4691,7 @@ UD_cbsucc_query(const char UNUSED * link_name, void UNUSED * udata, size_t UNUSE strcpy(buf, "succeed"); return 8; -} +} /* end UD_cbsucc_query() */ /* This class is full of failing callbacks */ const H5L_class_t UD_cbfail_class1[1] = {{ diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 0af6d5d..555334a 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -1544,25 +1544,26 @@ dump_all(hid_t group, const char *name, void * op_data) case H5G_UDLINK: { indentation(indent); - switch(linfo.type) - { + switch(linfo.type) { case H5L_TYPE_EXTERNAL: { char *targbuf; - char *filename; - char *targname; + targbuf = HDmalloc(statbuf.linklen); HDassert(targbuf); - if (!doxml) { - begin_obj(dump_header_format->extlinkbegin, name, - dump_header_format->extlinkblockbegin); - } - if (H5Lget_val(group, name, targbuf, statbuf.linklen, H5P_DEFAULT) < 0) { + if(!doxml) { + begin_obj(dump_header_format->extlinkbegin, name, dump_header_format->extlinkblockbegin); + } /* end if */ + + if(H5Lget_val(group, name, targbuf, statbuf.linklen, H5P_DEFAULT) < 0) { error_msg(progname, "unable to get external link value\n"); d_status = EXIT_FAILURE; ret = FAIL; } else { - if(H5Lunpack_elink_val(targbuf, statbuf.linklen, &filename, &targname) < 0) { + const char *filename; + const char *targname; + + if(H5Lunpack_elink_val(targbuf, statbuf.linklen, NULL, &filename, &targname) < 0) { error_msg(progname, "unable to unpack external link value\n"); d_status = EXIT_FAILURE; ret = FAIL; @@ -2963,7 +2964,7 @@ parse_hsize_list(const char *h_list) p_list = calloc(size_count, sizeof(hsize_t)); for (ptr = h_list; i < size_count && ptr && *ptr && *ptr != ';' && *ptr != ']'; ptr++) - if (isdigit(*ptr)) { + if(isdigit(*ptr)) { /* we should have an integer now */ p_list[i++] = (hsize_t)atof(ptr); @@ -3214,8 +3215,6 @@ handle_links(hid_t fid, char *links, void UNUSED * data) { H5G_stat_t statbuf; H5L_info_t linfo; - char * elink_file; - char * elink_path; if(H5Gget_objinfo(fid, links, FALSE, &statbuf) < 0) { error_msg(progname, "unable to get obj info from \"%s\"\n", links); @@ -3247,25 +3246,26 @@ handle_links(hid_t fid, char *links, void UNUSED * data) dump_header_format->udlinkblockbegin); indentation(COL); switch(linfo.type) { - case H5L_TYPE_EXTERNAL: - begin_obj(dump_header_format->extlinkbegin, links, + case H5L_TYPE_EXTERNAL: + begin_obj(dump_header_format->extlinkbegin, links, dump_header_format->extlinkblockbegin); - if(H5Lget_val(fid, links, buf, statbuf.linklen, H5P_DEFAULT) >= 0) { - if(H5Lunpack_elink_val(buf, statbuf.linklen, &elink_file, &elink_path)>=0) { - indentation(COL); - printf("LINKCLASS %d\n", linfo.type); - indentation(COL); - printf("TARGETFILE \"%s\"\n", elink_file); - indentation(COL); - printf("TARGETPATH \"%s\"\n", elink_path); - } else { - error_msg(progname, "h5dump error: unable to unpack external link value for \"%s\"\n", - links); - d_status = EXIT_FAILURE; - } + if(H5Lget_val(fid, links, buf, statbuf.linklen, H5P_DEFAULT) >= 0) { + const char *elink_file; + const char *elink_path; + + if(H5Lunpack_elink_val(buf, statbuf.linklen, NULL, &elink_file, &elink_path)>=0) { + indentation(COL); + printf("LINKCLASS %d\n", linfo.type); + indentation(COL); + printf("TARGETFILE \"%s\"\n", elink_file); + indentation(COL); + printf("TARGETPATH \"%s\"\n", elink_path); + } else { + error_msg(progname, "h5dump error: unable to unpack external link value for \"%s\"\n", links); + d_status = EXIT_FAILURE; + } } else { - error_msg(progname, "h5dump error: unable to get external link value for \"%s\"\n", - links); + error_msg(progname, "h5dump error: unable to get external link value for \"%s\"\n", links); d_status = EXIT_FAILURE; } end_obj(dump_header_format->extlinkend, diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c index 63b5115..6d0da89 100644 --- a/tools/h5ls/h5ls.c +++ b/tools/h5ls/h5ls.c @@ -1775,14 +1775,13 @@ udlink_open(hid_t location, const char *name) { H5L_info_t linfo; char * buf = NULL; - char * filename = NULL; - char * path = NULL; + const char * filename; + const char * path; if(H5Lget_info(location, name, &linfo, H5P_DEFAULT) < 0) return -1; - switch(linfo.type) - { + switch(linfo.type) { /* For external links, try to display info for the object it points to */ case H5L_TYPE_EXTERNAL: if((buf = HDmalloc(linfo.u.val_size)) == NULL) @@ -1790,7 +1789,7 @@ udlink_open(hid_t location, const char *name) if(H5Lget_val(location, name, buf, linfo.u.val_size, H5P_DEFAULT) < 0) goto error; - if(H5Lunpack_elink_val(buf, linfo.u.val_size, &filename, &path) < 0) goto error; + if(H5Lunpack_elink_val(buf, linfo.u.val_size, NULL, &filename, &path) < 0) goto error; HDfputs("file: ", stdout); HDfputs(filename, stdout); HDfputs(" path: ", stdout); @@ -1800,6 +1799,7 @@ udlink_open(hid_t location, const char *name) default: HDfputs("cannot follow UD links", stdout); } + return 0; error: diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c index 8abdf55..3646827 100644 --- a/tools/lib/h5trav.c +++ b/tools/lib/h5trav.c @@ -665,32 +665,29 @@ static int traverse( hid_t loc_id, H5Lget_info( loc_id, path, &linkbuf, H5P_DEFAULT); } H5E_END_TRY; - if(linkbuf.type == H5L_TYPE_EXTERNAL) - { - if (statbuf.linklen>0) - { - char *targbuf; - char *objname; - - targbuf = HDmalloc(statbuf.linklen); - assert(targbuf); - H5Gget_linkval(loc_id,path,statbuf.linklen,targbuf); - H5Lunpack_elink_val(targbuf, statbuf.linklen, NULL, &objname); - if (print) - printf(" %-10s %s -> %s %s\n", "ext link", path, targbuf, objname); - free(targbuf); - } - else - { - if (print) - printf(" %-10s %s ->\n", "udlink", path); - } - } - else /* Unknown user-defined type */ - { - if (print) - printf(" %-10s %s ->\n", "UD link type", path); - } + if(linkbuf.type == H5L_TYPE_EXTERNAL) { + if(statbuf.linklen > 0) { + char *targbuf; + const char *filename; + const char *objname; + + targbuf = HDmalloc(statbuf.linklen); + assert(targbuf); + H5Gget_linkval(loc_id, path, statbuf.linklen, targbuf); + H5Lunpack_elink_val(targbuf, statbuf.linklen, NULL, &filename, &objname); + if(print) + printf(" %-10s %s -> %s %s\n", "ext link", path, filename, objname); + free(targbuf); + } /* end if */ + else { + if(print) + printf(" %-10s %s ->\n", "udlink", path); + } /* end else */ + } /* end if */ + else { /* Unknown user-defined type */ + if(print) + printf(" %-10s %s ->\n", "UD link type", path); + } /* end else */ } break; @@ -718,12 +715,3 @@ static int traverse( hid_t loc_id, return inserted_objs; } - - - - - - - - - diff --git a/tools/testfiles/tall.h5 b/tools/testfiles/tall.h5 Binary files differindex 8e377ff..918aeee 100644 --- a/tools/testfiles/tall.h5 +++ b/tools/testfiles/tall.h5 diff --git a/tools/testfiles/tboot1.ddl b/tools/testfiles/tboot1.ddl index df1a85e..9a7cafc 100644 --- a/tools/testfiles/tboot1.ddl +++ b/tools/testfiles/tboot1.ddl @@ -17,7 +17,7 @@ USER_BLOCK { USERBLOCK_SIZE 0 } DATASET "dset" { - DATATYPE H5T_STD_I32LE + DATATYPE H5T_STD_I32BE DATASPACE SIMPLE { ( 4 ) / ( 4 ) } } } diff --git a/tools/testfiles/textlink.h5 b/tools/testfiles/textlink.h5 Binary files differindex 44857dc..a5ec3e6 100644 --- a/tools/testfiles/textlink.h5 +++ b/tools/testfiles/textlink.h5 diff --git a/tools/testfiles/tfcontents1.h5 b/tools/testfiles/tfcontents1.h5 Binary files differindex 5fd6f79..c16ee4d 100644 --- a/tools/testfiles/tfcontents1.h5 +++ b/tools/testfiles/tfcontents1.h5 diff --git a/tools/testfiles/tmany.h5 b/tools/testfiles/tmany.h5 Binary files differindex 82ce3e0..10e29d6 100644 --- a/tools/testfiles/tmany.h5 +++ b/tools/testfiles/tmany.h5 diff --git a/tools/testfiles/tudlink.h5 b/tools/testfiles/tudlink.h5 Binary files differindex 4c4e494..5dc0c707 100644 --- a/tools/testfiles/tudlink.h5 +++ b/tools/testfiles/tudlink.h5 diff --git a/tools/testfiles/twithub.h5 b/tools/testfiles/twithub.h5 Binary files differindex 4402107..4bc1833 100644 --- a/tools/testfiles/twithub.h5 +++ b/tools/testfiles/twithub.h5 diff --git a/tools/testfiles/twithub513.h5 b/tools/testfiles/twithub513.h5 Binary files differindex be1b87b..0eac208 100644 --- a/tools/testfiles/twithub513.h5 +++ b/tools/testfiles/twithub513.h5 |