/**************************************************************** ** ** test_refstr_own(): Test basic H5RS (ref-counted strings) code. ** Tests transferring ownership of dynamically allocated strings ** to ref-counted strings. ** ****************************************************************/ static void test_refstr_own(void) { H5RS_str_t *rs; /* Ref-counted string created */ char *s; /* Pointer to string to transfer */ const char *t; /* Temporary pointers to string */ int cmp; /* Comparison value */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Transferring Ref-Counted Strings\n")); /* Initialize buffer */ s = (char *)H5FL_BLK_MALLOC(str_buf,HDstrlen("foo") + 1); CHECK(s, NULL, "H5FL_BLK_MALLOC"); HDstrcpy(s, "foo"); /* Transfer ownership of dynamically allocated string to ref-counted string */ rs=H5RS_own(s); CHECK(rs, NULL, "H5RS_own"); /* Get pointer to raw string in ref-counted string */ t=H5RS_get_str(rs); CHECK(t, NULL, "H5RS_get_str"); VERIFY(t, s, "transferring"); cmp=HDstrcmp(s,t); VERIFY(cmp, 0, "HDstrcmp"); /* Increment reference count (should NOT duplicate string) */ ret=H5RS_incr(rs); CHECK(ret, FAIL, "H5RS_incr"); /* Change the buffer initially wrapped */ *s='F'; /* Get pointer to raw string in ref-counted string */ t=H5RS_get_str(rs); CHECK(t, NULL, "H5RS_get_str"); VERIFY(t, s, "transferring"); cmp=HDstrcmp(t,s); VERIFY(cmp, 0, "HDstrcmp"); /* Decrement reference count for string */ ret=H5RS_decr(rs); CHECK(ret, FAIL, "H5RS_decr"); ret=H5RS_decr(rs); CHECK(ret, FAIL, "H5RS_decr"); } /* end test_refstr_own() */
/**************************************************************** ** ** test_refstr_wrap(): Test basic H5RS (ref-counted strings) code. ** Tests wrapping ref-counted strings around existing strings. ** ****************************************************************/ static void test_refstr_wrap(void) { H5RS_str_t *rs; /* Ref-counted string created */ const char *s; /* Pointer to raw string in ref-counted string */ char buf[16]; /* Buffer to wrap */ int cmp; /* Comparison value */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Wrapping Ref-Counted Strings\n")); /* Initialize buffer */ HDstrcpy(buf,"foo"); /* Wrap ref-counted string around existing buffer */ rs=H5RS_wrap(buf); CHECK(rs, NULL, "H5RS_wrap"); /* Get pointer to raw string in ref-counted string */ s=H5RS_get_str(rs); CHECK(s, NULL, "H5RS_get_str"); VERIFY(s, buf, "wrapping"); cmp=HDstrcmp(s,buf); VERIFY(cmp, 0, "HDstrcmp"); /* Increment reference count (should duplicate string) */ ret=H5RS_incr(rs); CHECK(ret, FAIL, "H5RS_incr"); /* Change the buffer initially wrapped */ buf[0]='F'; /* Get pointer to raw string in ref-counted string */ s=H5RS_get_str(rs); CHECK(s, NULL, "H5RS_get_str"); CHECK(s, buf, "wrapping"); cmp=HDstrcmp(s,buf); if(cmp<=0) TestErrPrintf("%d: string comparison incorrect!\n",__LINE__); /* Decrement reference count for string */ ret=H5RS_decr(rs); CHECK(ret, FAIL, "H5RS_decr"); ret=H5RS_decr(rs); CHECK(ret, FAIL, "H5RS_decr"); } /* end test_refstr_wrap() */
/*------------------------------------------------------------------------- * Function: H5G__link_name_replace * * Purpose: Determine the type of object referred to (for hard links) or * the link type (for soft links and user-defined links). * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * [email protected] * Nov 13 2006 * *------------------------------------------------------------------------- */ herr_t H5G__link_name_replace(H5F_t *file, hid_t dxpl_id, H5RS_str_t *grp_full_path_r, const H5O_link_t *lnk) { H5RS_str_t *obj_path_r = NULL; /* Full path for link being removed */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE /* check arguments */ HDassert(file); /* Search the open IDs and replace names for unlinked object */ if(grp_full_path_r) { obj_path_r = H5G_build_fullpath_refstr_str(grp_full_path_r, lnk->name); if(H5G_name_replace(lnk, H5G_NAME_DELETE, file, obj_path_r, NULL, NULL, dxpl_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTDELETE, FAIL, "unable to replace name") } /* end if */ done: if(obj_path_r) H5RS_decr(obj_path_r); FUNC_LEAVE_NOAPI(ret_value) } /* end H5G__link_name_replace() */
/**************************************************************** ** ** test_refstr_cmp(): Test basic H5RS (ref-counted strings) code. ** Tests comparing ref-counted strings. ** ****************************************************************/ static void test_refstr_cmp(void) { H5RS_str_t *rs1; /* Ref-counted string created */ H5RS_str_t *rs2; /* Ref-counted string created */ int cmp; /* Comparison value */ ssize_t len; /* Length of string */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Comparing Ref-Counted Strings\n")); /* Create first reference counted string */ rs1=H5RS_create("foo"); CHECK(rs1, NULL, "H5RS_create"); /* Create second reference counted string */ rs2=H5RS_create("foo2"); CHECK(rs2, NULL, "H5RS_create"); /* Compare the strings in various ways */ cmp=H5RS_cmp(rs1,rs1); VERIFY(cmp, 0, "H5RS_cmp"); cmp=H5RS_cmp(rs2,rs2); VERIFY(cmp, 0, "H5RS_cmp"); cmp=H5RS_cmp(rs1,rs2); if(cmp>=0) TestErrPrintf("%d: string comparison incorrect!\n",__LINE__); /* Check the lengths of the strings also */ len=H5RS_len(rs1); VERIFY(len, 3, "H5RS_len"); len=H5RS_len(rs2); VERIFY(len, 4, "H5RS_len"); /* Decrement reference count for strings */ ret=H5RS_decr(rs2); CHECK(ret, FAIL, "H5RS_decr"); ret=H5RS_decr(rs1); CHECK(ret, FAIL, "H5RS_decr"); } /* end test_refstr_cmp() */
/**************************************************************** ** ** test_refstr_dup(): Test basic H5RS (ref-counted strings) code. ** Tests duplicating ref-counted strings. ** ****************************************************************/ static void test_refstr_dup(void) { H5RS_str_t *rs1; /* Ref-counted string created */ H5RS_str_t *rs2; /* Ref-counted string created */ unsigned count; /* Reference count on string */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Duplicating Ref-Counted Strings\n")); /* Try creating a ref-counted string */ rs1=H5RS_create("foo"); CHECK(rs1, NULL, "H5RS_create"); /* Get the reference count on the string */ count=H5RS_get_count(rs1); VERIFY(count, 1, "H5RS_get_count"); /* Duplicate r-string */ rs2=H5RS_dup(rs1); CHECK(rs2, NULL, "H5RS_dup"); /* Get the reference count on the strings */ count=H5RS_get_count(rs1); VERIFY(count, 2, "H5RS_get_count"); count=H5RS_get_count(rs2); VERIFY(count, 2, "H5RS_get_count"); /* Decrement reference count for string */ ret=H5RS_decr(rs2); CHECK(ret, FAIL, "H5RS_decr"); /* Get the reference count on the string */ count=H5RS_get_count(rs1); VERIFY(count, 1, "H5RS_get_count"); /* Decrement reference count for string */ ret=H5RS_decr(rs1); CHECK(ret, FAIL, "H5RS_decr"); } /* end test_refstr_dup() */
/**************************************************************** ** ** test_refstr_create(): Test basic H5RS (ref-counted strings) code. ** Tests creating and closing ref-counted strings. ** ****************************************************************/ static void test_refstr_create(void) { H5RS_str_t *rs; /* Ref-counted string created */ unsigned count; /* Reference count on string */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Creating & Closing Ref-Counted Strings\n")); /* Try creating a ref-counted string */ rs=H5RS_create("foo"); CHECK(rs, NULL, "H5RS_create"); /* Get the reference count on the string */ count=H5RS_get_count(rs); VERIFY(count, 1, "H5RS_get_count"); /* Try closing a real ref-counted string */ ret=H5RS_decr(rs); CHECK(ret, FAIL, "H5RS_decr"); } /* end test_refstr_create() */
/*------------------------------------------------------------------------- * Function: H5G_traverse_slink * * Purpose: Traverses symbolic link. The link head appears in the group * whose entry is GRP_ENT and the link head entry is OBJ_ENT. * * Return: Success: Non-negative, OBJ_ENT will contain information * about the object to which the link points and * GRP_ENT will contain the information about * the group in which the link tail appears. * * Failure: Negative * * Programmer: Robb Matzke * Friday, April 10, 1998 * * Modifications: * * Pedro Vicente, <*****@*****.**> 22 Aug 2002 * Added `id to name' support. * *------------------------------------------------------------------------- */ static herr_t H5G_traverse_slink (H5G_entry_t *grp_ent/*in,out*/, H5G_entry_t *obj_ent/*in,out*/, int *nlinks/*in,out*/, hid_t dxpl_id) { H5O_stab_t stab_mesg; /*info about local heap */ const char *clv = NULL; /*cached link value */ char *linkval = NULL; /*the copied link value */ H5G_entry_t tmp_grp_ent; /* Temporary copy of group entry */ H5RS_str_t *tmp_full_path_r = NULL, *tmp_user_path_r = NULL; /* Temporary pointer to object's user path & canonical path */ const H5HL_t *heap; herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5G_traverse_slink); /* Portably initialize the temporary group entry */ H5G_ent_reset(&tmp_grp_ent); /* Get the link value */ if (NULL==H5O_read (grp_ent, H5O_STAB_ID, 0, &stab_mesg, dxpl_id)) HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "unable to determine local heap address"); if (NULL == (heap = H5HL_protect(grp_ent->file, dxpl_id, stab_mesg.heap_addr))) HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "unable to read protect link value") clv = H5HL_offset_into(grp_ent->file, heap, obj_ent->cache.slink.lval_offset); linkval = H5MM_xstrdup (clv); assert(linkval); if (H5HL_unprotect(grp_ent->file, dxpl_id, heap, stab_mesg.heap_addr) < 0) HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "unable to read unprotect link value") /* Hold the entry's name (& old_name) to restore later */ tmp_full_path_r = obj_ent->full_path_r; obj_ent->full_path_r = NULL; tmp_user_path_r = obj_ent->user_path_r; obj_ent->user_path_r = NULL; /* Free the names for the group entry */ H5G_name_free(grp_ent); /* Clone the group entry, so we can track the names properly */ H5G_ent_copy(&tmp_grp_ent,grp_ent,H5_COPY_DEEP); /* Traverse the link */ if (H5G_namei (&tmp_grp_ent, linkval, NULL, grp_ent, obj_ent, H5G_TARGET_NORMAL, nlinks, H5G_NAMEI_TRAVERSE, NULL, dxpl_id)) HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "unable to follow symbolic link"); /* Free the entry's names, we will use the original name for the object */ H5G_name_free(obj_ent); /* Restore previous name for object */ obj_ent->full_path_r = tmp_full_path_r; tmp_full_path_r = NULL; obj_ent->user_path_r = tmp_user_path_r; tmp_user_path_r = NULL; done: /* Error cleanup */ if(tmp_full_path_r) H5RS_decr(tmp_full_path_r); if(tmp_user_path_r) H5RS_decr(tmp_user_path_r); /* Release cloned copy of group entry */ H5G_name_free(&tmp_grp_ent); H5MM_xfree (linkval); FUNC_LEAVE_NOAPI(ret_value); }