diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2005-08-25 17:16:02 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2005-08-25 17:16:02 (GMT) |
commit | ab6656c52c8186fc9bca911f7dfb4df967b26817 (patch) | |
tree | cfe481ed9b6cd408414c0f5e05d2c9bd0fc6c6f9 | |
parent | 4a6e1b6ba9287ba1ea84e9c09950aac5be09a59e (diff) | |
download | hdf5-ab6656c52c8186fc9bca911f7dfb4df967b26817.zip hdf5-ab6656c52c8186fc9bca911f7dfb4df967b26817.tar.gz hdf5-ab6656c52c8186fc9bca911f7dfb4df967b26817.tar.bz2 |
[svn-r11295] Purpose:
Bug fix
Description:
Fix "strong" file closing to handle a dangling dataset which uses a
dangling named datatype.
Platforms tested:
FreeBSD 4.11 (sleipnir)
Too minor too require h5committest
-rw-r--r-- | src/H5F.c | 17 | ||||
-rw-r--r-- | test/dangle.c | 100 |
2 files changed, 110 insertions, 7 deletions
@@ -2677,8 +2677,21 @@ H5F_try_close(H5F_t *f) hid_t objs[128]; /* Array of objects to close */ unsigned u; /* Local index variable */ - /* Get the list of IDs of open dataset, group, named datatype & attribute objects */ - while((obj_count = H5F_get_obj_ids(f, H5F_OBJ_LOCAL|H5F_OBJ_DATASET|H5F_OBJ_GROUP|H5F_OBJ_DATATYPE|H5F_OBJ_ATTR, (int)(sizeof(objs)/sizeof(objs[0])), objs)) != 0) { + /* Get the list of IDs of open dataset, group, & attribute objects */ + while((obj_count = H5F_get_obj_ids(f, H5F_OBJ_LOCAL|H5F_OBJ_DATASET|H5F_OBJ_GROUP|H5F_OBJ_ATTR, (int)(sizeof(objs)/sizeof(objs[0])), objs)) != 0) { + + /* Try to close all the open objects in this file */ + for(u = 0; u < obj_count; u++) + if(H5I_dec_ref(objs[u]) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CLOSEERROR, FAIL, "can't close object") + } /* end while */ + + /* Get the list of IDs of open named datatype objects */ + /* (Do this separately from the dataset & attribute IDs, because + * they could be using one of the named datatypes and then the + * open named datatype ID will get closed twice. + */ + while((obj_count = H5F_get_obj_ids(f, H5F_OBJ_LOCAL|H5F_OBJ_DATATYPE, (int)(sizeof(objs)/sizeof(objs[0])), objs)) != 0) { /* Try to close all the open objects in this file */ for(u = 0; u < obj_count; u++) diff --git a/test/dangle.c b/test/dangle.c index c80d1a9..5086937 100644 --- a/test/dangle.c +++ b/test/dangle.c @@ -225,7 +225,7 @@ error: /*------------------------------------------------------------------------- - * Function: test_dangle_datatype + * Function: test_dangle_datatype1 * * Purpose: Check for dangling datatype IDs causing problems on library * shutdown @@ -241,7 +241,7 @@ error: *------------------------------------------------------------------------- */ static int -test_dangle_datatype(H5F_close_degree_t degree) +test_dangle_datatype1(H5F_close_degree_t degree) { char filename[1024]; hid_t fid; /* File ID */ @@ -322,6 +322,93 @@ error: /*------------------------------------------------------------------------- + * Function: test_dangle_datatype2 + * + * Purpose: Check for dangling datatype IDs causing problems on library + * shutdown + * + * Return: Success: zero + * Failure: non-zero + * + * Programmer: Quincey Koziol + * Thursday, August 25, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +test_dangle_datatype2(H5F_close_degree_t degree) +{ + char filename[1024]; + hid_t fid; /* File ID */ + hid_t fapl; /* File access property list */ + hid_t did; /* Dataset ID */ + hid_t sid; /* Dataspace ID */ + hid_t tid; /* Datatype ID */ + + TESTING(" dangling named datatype ID used by dataset"); + + if(H5open()<0) + TEST_ERROR; + + /* Create file access property list */ + if((fapl=H5Pcreate(H5P_FILE_ACCESS))<0) + TEST_ERROR; + + /* Set file close degree */ + if(H5Pset_fclose_degree(fapl,degree)<0) + TEST_ERROR; + + h5_fixname(FILENAME[0], H5P_DEFAULT, filename, sizeof filename); + if((fid = H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) + TEST_ERROR; + + if((tid = H5Tcopy (H5T_NATIVE_INT))<0) + TEST_ERROR; + + if(H5Tcommit(fid,TYPENAME,tid)<0) + TEST_ERROR; + + /* Create a dataset that uses the named datatype & leave it open */ + if((sid = H5Screate(H5S_SCALAR)) < 0) + TEST_ERROR; + if((did = H5Dcreate(fid, DSETNAME, tid, sid, H5P_DEFAULT)) < 0) + TEST_ERROR; + if(H5Sclose(sid)<0) + TEST_ERROR; + + if(degree==H5F_CLOSE_SEMI) { + H5E_BEGIN_TRY { + if(H5Fclose(fid)>=0) + TEST_ERROR; + } H5E_END_TRY; + } /* end if */ + else + if(H5Fclose(fid)<0) + TEST_ERROR; + + if(H5Pclose(fapl)<0) + TEST_ERROR; + + if(H5close()<0) + TEST_ERROR; + + if(h5_get_file_size(filename)==0) + TEST_ERROR; + + /* Clean up temporary file */ + HDremove(filename); + + PASSED(); + return 0; + +error: + return 1; +} + + +/*------------------------------------------------------------------------- * Function: test_dangle_attribute * * Purpose: Check for dangling attribute IDs causing problems on library @@ -453,21 +540,24 @@ main(void) puts("Testing dangling objects with weak file close:"); nerrors += test_dangle_dataset(H5F_CLOSE_WEAK); nerrors += test_dangle_group(H5F_CLOSE_WEAK); - nerrors += test_dangle_datatype(H5F_CLOSE_WEAK); + nerrors += test_dangle_datatype1(H5F_CLOSE_WEAK); + nerrors += test_dangle_datatype2(H5F_CLOSE_WEAK); nerrors += test_dangle_attribute(H5F_CLOSE_WEAK); /* Run tests w/semi file close */ puts("Testing dangling objects with semi file close:"); nerrors += test_dangle_dataset(H5F_CLOSE_SEMI); nerrors += test_dangle_group(H5F_CLOSE_SEMI); - nerrors += test_dangle_datatype(H5F_CLOSE_SEMI); + nerrors += test_dangle_datatype1(H5F_CLOSE_SEMI); + nerrors += test_dangle_datatype2(H5F_CLOSE_SEMI); nerrors += test_dangle_attribute(H5F_CLOSE_SEMI); /* Run tests w/strong file close */ puts("Testing dangling objects with strong file close:"); nerrors += test_dangle_dataset(H5F_CLOSE_STRONG); nerrors += test_dangle_group(H5F_CLOSE_STRONG); - nerrors += test_dangle_datatype(H5F_CLOSE_STRONG); + nerrors += test_dangle_datatype1(H5F_CLOSE_STRONG); + nerrors += test_dangle_datatype2(H5F_CLOSE_STRONG); nerrors += test_dangle_attribute(H5F_CLOSE_STRONG); /* Check for errors */ |