mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-04-12 17:31:09 +08:00
[svn-r10637] Purpose:
Bug fix/code cleanup Description: Add tests to determine that very long (64K+) object names are working. Fixed a couple of bugs in h5dump where they weren't... Platforms tested: FreeBSD 4.11 (sleipnir) Solaris 2.9 (shanti)
This commit is contained in:
parent
31fb2d13de
commit
0cf3f85cce
2
MANIFEST
2
MANIFEST
@ -1309,6 +1309,8 @@
|
||||
./tools/testfiles/thlink.h5
|
||||
./tools/testfiles/tlarge_objname.ddl
|
||||
./tools/testfiles/tlarge_objname.h5
|
||||
./tools/testfiles/tlonglinks.ddl
|
||||
./tools/testfiles/tlonglinks.h5
|
||||
./tools/testfiles/tloop-1.ddl
|
||||
./tools/testfiles/tloop.h5
|
||||
./tools/testfiles/tloop2.h5
|
||||
|
11
src/H5G.c
11
src/H5G.c
@ -2469,7 +2469,6 @@ H5G_link (H5G_entry_t *cur_loc, const char *cur_name, H5G_entry_t *new_loc,
|
||||
const char *rest = NULL; /*last component of new name */
|
||||
char *norm_cur_name = NULL; /* Pointer to normalized current name */
|
||||
char *norm_new_name = NULL; /* Pointer to normalized current name */
|
||||
char _comp[1024]; /*name component */
|
||||
size_t nchars; /*characters in component */
|
||||
size_t offset; /*offset to sym-link value */
|
||||
herr_t ret_value=SUCCEED; /* Return value */
|
||||
@ -2504,15 +2503,7 @@ H5G_link (H5G_entry_t *cur_loc, const char *cur_name, H5G_entry_t *new_loc,
|
||||
* There should be one component left. Make sure it's null
|
||||
* terminated and that `rest' points to it.
|
||||
*/
|
||||
if (rest[nchars]) {
|
||||
if (nchars+1 > sizeof _comp) {
|
||||
HGOTO_ERROR (H5E_SYM, H5E_COMPLEN, FAIL, "name component is too long");
|
||||
} else {
|
||||
HDmemcpy (_comp, rest, nchars);
|
||||
_comp[nchars] = '\0';
|
||||
rest = _comp;
|
||||
}
|
||||
}
|
||||
assert(!rest[nchars]);
|
||||
|
||||
/*
|
||||
* Add the link-value to the local heap for the symbol table which
|
||||
|
92
test/links.c
92
test/links.c
@ -27,6 +27,8 @@ const char *FILENAME[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
#define MAX_NAME_LEN ((64*1024)+1024)
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: mklinks
|
||||
@ -48,7 +50,7 @@ static int
|
||||
mklinks(hid_t fapl)
|
||||
{
|
||||
hid_t file, scalar, grp, d1;
|
||||
static hsize_t size[1] = {1};
|
||||
hsize_t size[1] = {1};
|
||||
char filename[1024];
|
||||
|
||||
TESTING("link creation");
|
||||
@ -61,7 +63,7 @@ mklinks(hid_t fapl)
|
||||
if ((scalar=H5Screate_simple (1, size, size))<0) goto error;
|
||||
|
||||
/* Create a group */
|
||||
if ((grp=H5Gcreate (file, "grp1", 0))<0) goto error;
|
||||
if ((grp=H5Gcreate (file, "grp1", (size_t)0))<0) goto error;
|
||||
if (H5Gclose (grp)<0) goto error;
|
||||
|
||||
/* Create a dataset */
|
||||
@ -121,7 +123,7 @@ new_links(hid_t fapl)
|
||||
hid_t scalar=(-1);
|
||||
hid_t dset1=(-1), dset2=(-1);
|
||||
char filename[1024];
|
||||
static hsize_t size[1] = {1};
|
||||
hsize_t size[1] = {1};
|
||||
|
||||
TESTING("H5Glink2 function");
|
||||
|
||||
@ -137,10 +139,10 @@ new_links(hid_t fapl)
|
||||
if ((scalar=H5Screate_simple (1, size, size))<0) goto error;
|
||||
|
||||
/* Create two groups in each file */
|
||||
if ((grp1_a=H5Gcreate (file_a, "grp1", 0))<0) goto error;
|
||||
if ((grp2_a=H5Gcreate (file_a, "grp2", 0))<0) goto error;
|
||||
if ((grp1_b=H5Gcreate (file_b, "grp1", 0))<0) goto error;
|
||||
if ((grp2_b=H5Gcreate (file_b, "grp2", 0))<0) goto error;
|
||||
if ((grp1_a=H5Gcreate (file_a, "grp1", (size_t)0))<0) goto error;
|
||||
if ((grp2_a=H5Gcreate (file_a, "grp2", (size_t)0))<0) goto error;
|
||||
if ((grp1_b=H5Gcreate (file_b, "grp1", (size_t)0))<0) goto error;
|
||||
if ((grp2_b=H5Gcreate (file_b, "grp2", (size_t)0))<0) goto error;
|
||||
|
||||
/* Create datasets */
|
||||
if((dset1=H5Dcreate(file_a, "dataset1", H5T_NATIVE_INT, scalar,
|
||||
@ -441,6 +443,79 @@ ck_new_links(hid_t fapl)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: long_links
|
||||
*
|
||||
* Purpose: Build a file with long names
|
||||
*
|
||||
* Return: Success: 0
|
||||
*
|
||||
* Failure: -1
|
||||
*
|
||||
* Programmer: Quincey Koziol
|
||||
* Saturday, April 16, 2005
|
||||
*
|
||||
* Modifications:
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
long_links(hid_t fapl)
|
||||
{
|
||||
hid_t fid = (-1); /* File ID */
|
||||
hid_t gid = (-1); /* Group ID */
|
||||
hid_t gid2 = (-1); /* Datatype ID */
|
||||
char *objname = NULL; /* Name of object [Long] */
|
||||
size_t u; /* Local index variable */
|
||||
char filename[1024];
|
||||
|
||||
TESTING("long names for objects & links");
|
||||
|
||||
/* Create files */
|
||||
h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
|
||||
if((fid=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR;
|
||||
|
||||
/* Create group with short name in file (used as target for hard links) */
|
||||
if((gid=H5Gcreate (fid, "grp1", (size_t)0))<0) TEST_ERROR;
|
||||
|
||||
/* Construct very long file name */
|
||||
if((objname = HDmalloc((size_t)(MAX_NAME_LEN + 1))) == NULL) TEST_ERROR;
|
||||
for(u = 0; u < MAX_NAME_LEN; u++)
|
||||
objname[u] = 'a';
|
||||
objname[MAX_NAME_LEN] = '\0';
|
||||
|
||||
/* Create hard link to existing object */
|
||||
if(H5Glink2(fid, "grp1", H5G_LINK_HARD, fid, objname) < 0) TEST_ERROR;
|
||||
|
||||
/* Create soft link to existing object */
|
||||
objname[0] = 'b';
|
||||
if(H5Glink2(fid, "grp1", H5G_LINK_SOFT, fid, objname) < 0) TEST_ERROR;
|
||||
|
||||
/* Create group with long name in existing group */
|
||||
if((gid2=H5Gcreate(gid, objname, (size_t)0))<0) TEST_ERROR;
|
||||
|
||||
/* Close objects */
|
||||
if(H5Gclose(gid2)<0) TEST_ERROR;
|
||||
if(H5Gclose(gid)<0) TEST_ERROR;
|
||||
if(H5Fclose(fid)<0) TEST_ERROR;
|
||||
|
||||
/* Release memory */
|
||||
HDfree(objname);
|
||||
|
||||
PASSED();
|
||||
return 0;
|
||||
|
||||
error:
|
||||
H5E_BEGIN_TRY {
|
||||
H5Gclose (gid2);
|
||||
H5Gclose (gid);
|
||||
H5Fclose (fid);
|
||||
} H5E_END_TRY;
|
||||
HDfree(objname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: main
|
||||
@ -469,9 +544,10 @@ main(void)
|
||||
|
||||
/* The tests... */
|
||||
nerrors += mklinks(fapl) < 0 ? 1 : 0;
|
||||
nerrors += new_links(fapl) < 0 ? 1 : 0;
|
||||
nerrors += cklinks(fapl) < 0 ? 1 : 0;
|
||||
nerrors += new_links(fapl) < 0 ? 1 : 0;
|
||||
nerrors += ck_new_links(fapl) < 0 ? 1 : 0;
|
||||
nerrors += long_links(fapl) < 0 ? 1 : 0;
|
||||
|
||||
/* Results */
|
||||
if (nerrors) {
|
||||
|
@ -35,9 +35,9 @@ const char *progname = "h5dump";
|
||||
|
||||
int d_status = EXIT_SUCCESS;
|
||||
static int unamedtype = 0; /* shared data type with no name */
|
||||
static size_t prefix_len = 1024;
|
||||
extern size_t prefix_len;
|
||||
static table_t *group_table = NULL, *dset_table = NULL, *type_table = NULL;
|
||||
char *prefix;
|
||||
extern char *prefix;
|
||||
static const char *driver = NULL; /* The driver to open the file with. */
|
||||
|
||||
static const dump_header *dump_header_format;
|
||||
@ -825,7 +825,7 @@ print_datatype(hid_t type,unsigned in_group)
|
||||
if (H5Tequal(tmp_type, str_type)) {
|
||||
printf("H5T_C_S1;\n");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* If not equal to C variable-length string, check Fortran type. */
|
||||
H5Tclose(str_type);
|
||||
@ -3734,15 +3734,15 @@ print_enum(hid_t type)
|
||||
for (j = 0; j < dst_size; j++)
|
||||
printf("%02x", value[i * dst_size + j]);
|
||||
} else if (H5T_SGN_NONE == H5Tget_sign(native)) {
|
||||
/*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
|
||||
*strangely, unless use another pointer "copy".*/
|
||||
copy = value+i*dst_size;
|
||||
/*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
|
||||
*strangely, unless use another pointer "copy".*/
|
||||
copy = value+i*dst_size;
|
||||
HDfprintf(stdout,"%" H5_PRINTF_LL_WIDTH "u", *((unsigned long_long *)
|
||||
((void *)copy)));
|
||||
} else {
|
||||
/*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
|
||||
*strangely, unless use another pointer "copy".*/
|
||||
copy = value+i*dst_size;
|
||||
/*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
|
||||
*strangely, unless use another pointer "copy".*/
|
||||
copy = value+i*dst_size;
|
||||
HDfprintf(stdout,"%" H5_PRINTF_LL_WIDTH "d",
|
||||
*((long_long *) ((void *)copy)));
|
||||
}
|
||||
|
@ -77,6 +77,7 @@
|
||||
#define FILE48 "tfvalues.h5"
|
||||
#define FILE49 "tstr3.h5"
|
||||
#define FILE50 "taindices.h5"
|
||||
#define FILE51 "tlonglinks.h5"
|
||||
|
||||
|
||||
|
||||
@ -195,6 +196,9 @@ typedef struct s1_t {
|
||||
/* Name of dataset to create in datafile */
|
||||
#define F43_DSETNAME "Dataset"
|
||||
|
||||
/* "File 51" macros */
|
||||
#define F51_MAX_NAME_LEN ((64*1024)+1024)
|
||||
|
||||
static void gent_group(void)
|
||||
{
|
||||
hid_t fid, group;
|
||||
@ -5310,6 +5314,56 @@ static void gent_aindices(void)
|
||||
assert(ret>=0);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: gent_longlinks
|
||||
*
|
||||
* Purpose: make file with very long names for objects
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
static void gent_longlinks(void)
|
||||
{
|
||||
hid_t fid = (-1); /* File ID */
|
||||
hid_t gid = (-1); /* Group ID */
|
||||
hid_t gid2 = (-1); /* Datatype ID */
|
||||
char *objname = NULL; /* Name of object [Long] */
|
||||
size_t u; /* Local index variable */
|
||||
|
||||
/* Create files */
|
||||
fid = H5Fcreate(FILE51, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
assert(fid >= 0);
|
||||
|
||||
/* Create group with short name in file (used as target for hard links) */
|
||||
gid=H5Gcreate(fid, "grp1", (size_t)0);
|
||||
assert(gid >= 0);
|
||||
|
||||
/* Construct very long file name */
|
||||
objname = HDmalloc((size_t)(F51_MAX_NAME_LEN + 1));
|
||||
assert(objname);
|
||||
for(u = 0; u < F51_MAX_NAME_LEN; u++)
|
||||
objname[u] = 'a';
|
||||
objname[F51_MAX_NAME_LEN] = '\0';
|
||||
|
||||
/* Create hard link to existing object */
|
||||
assert(H5Glink2(fid, "grp1", H5G_LINK_HARD, fid, objname) >= 0);
|
||||
|
||||
/* Create soft link to existing object */
|
||||
objname[0] = 'b';
|
||||
assert(H5Glink2(fid, "grp1", H5G_LINK_SOFT, fid, objname) >= 0);
|
||||
|
||||
/* Create group with long name in existing group */
|
||||
gid2=H5Gcreate(gid, objname, (size_t)0);
|
||||
assert(gid2 >= 0);
|
||||
|
||||
/* Close objects */
|
||||
assert(H5Gclose(gid2) >= 0);
|
||||
assert(H5Gclose(gid) >= 0);
|
||||
assert(H5Fclose(fid) >= 0);
|
||||
|
||||
/* Release memory */
|
||||
HDfree(objname);
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: main
|
||||
@ -5369,6 +5423,7 @@ int main(void)
|
||||
gent_fcontents();
|
||||
gent_string();
|
||||
gent_aindices();
|
||||
gent_longlinks();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -311,6 +311,9 @@ TOOLTEST tuserfilter.ddl -H -p -d myfilter tfilters.h5
|
||||
# test for displaying dataset and attribute of null space
|
||||
TOOLTEST tnullspace.ddl tnullspace.h5
|
||||
|
||||
# test for displaying objects with very long names
|
||||
TOOLTEST tlonglinks.ddl tlonglinks.h5
|
||||
|
||||
|
||||
if test $nerrors -eq 0 ; then
|
||||
echo "All $DUMPER tests passed."
|
||||
@ -318,5 +321,3 @@ fi
|
||||
|
||||
exit $nerrors
|
||||
|
||||
|
||||
|
||||
|
@ -36,7 +36,8 @@
|
||||
|
||||
|
||||
extern hid_t thefile;
|
||||
extern char *prefix;
|
||||
size_t prefix_len = 1024;
|
||||
char *prefix;
|
||||
extern char *progname;
|
||||
extern int d_status;
|
||||
|
||||
@ -227,17 +228,19 @@ fill_ref_path_table(hid_t group, const char *name, void UNUSED * op_data)
|
||||
{
|
||||
hid_t obj;
|
||||
char *tmp;
|
||||
size_t tmp_len;
|
||||
H5G_stat_t statbuf;
|
||||
ref_path_table_entry_t *pte;
|
||||
char *thepath;
|
||||
|
||||
H5Gget_objinfo(group, name, FALSE, &statbuf);
|
||||
tmp = (char *) malloc(strlen(prefix) + strlen(name) + 2);
|
||||
tmp_len = strlen(prefix) + strlen(name) + 2;
|
||||
tmp = (char *) malloc(tmp_len);
|
||||
|
||||
if (tmp == NULL)
|
||||
return FAIL;
|
||||
|
||||
thepath = (char *) malloc(strlen(prefix) + strlen(name) + 2);
|
||||
thepath = (char *) malloc(tmp_len);
|
||||
|
||||
if (thepath == NULL) {
|
||||
free(tmp);
|
||||
@ -264,6 +267,11 @@ fill_ref_path_table(hid_t group, const char *name, void UNUSED * op_data)
|
||||
break;
|
||||
case H5G_GROUP:
|
||||
if ((obj = H5Gopen(group, name)) >= 0) {
|
||||
if (prefix_len <= tmp_len) {
|
||||
prefix_len = tmp_len + 1;
|
||||
prefix = realloc(prefix, prefix_len);
|
||||
}
|
||||
|
||||
strcat(strcat(prefix, "/"), name);
|
||||
pte = ref_path_table_lookup(thepath);
|
||||
if (pte == NULL) {
|
||||
|
@ -435,7 +435,7 @@ find_objs(hid_t group, const char *name, void *op_data)
|
||||
switch (statbuf.type) {
|
||||
case H5G_GROUP:
|
||||
if ((obj = H5Gopen(group, name)) >= 0) {
|
||||
if (info->prefix_len < (HDstrlen(info->prefix) + HDstrlen(name) + 2)) {
|
||||
while (info->prefix_len < (HDstrlen(info->prefix) + HDstrlen(name) + 2)) {
|
||||
info->prefix_len *= 2;
|
||||
info->prefix = HDrealloc(info->prefix,
|
||||
info->prefix_len * sizeof(char));
|
||||
|
17
tools/testfiles/tlonglinks.ddl
Normal file
17
tools/testfiles/tlonglinks.ddl
Normal file
File diff suppressed because one or more lines are too long
BIN
tools/testfiles/tlonglinks.h5
Normal file
BIN
tools/testfiles/tlonglinks.h5
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user