diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2006-12-19 20:18:26 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2006-12-19 20:18:26 (GMT) |
commit | de9088b6bb7969aade23f5af0d1e4e1806fcc0c4 (patch) | |
tree | 5f77b2172513805db28c2907f119abe513550295 | |
parent | a75186cc511760578d8a9de722a16873371b6570 (diff) | |
download | hdf5-de9088b6bb7969aade23f5af0d1e4e1806fcc0c4.zip hdf5-de9088b6bb7969aade23f5af0d1e4e1806fcc0c4.tar.gz hdf5-de9088b6bb7969aade23f5af0d1e4e1806fcc0c4.tar.bz2 |
[svn-r13079] Description:
Add more tests for checking that writing to shared attributes works
correctly. (Looks like it still has a bug when dense storage is used, which
I'll correct shortly).
Add testing routine to shared message code, to retrieve reference count for
a shared message.
Add fractal heap 'op' callback for efficiently computing the hash value of
an existing encoded message in the shared message fractal heap.
Various minor cleanups and warning placations.
Tested on:
Linux/32 2.6 (chicago)
Linux/64 2.6 (chicago2)
-rw-r--r-- | MANIFEST | 2 | ||||
-rw-r--r-- | src/H5Adense.c | 22 | ||||
-rw-r--r-- | src/H5Apkg.h | 7 | ||||
-rw-r--r-- | src/H5Atest.c | 150 | ||||
-rw-r--r-- | src/H5Oattr.c | 3 | ||||
-rw-r--r-- | src/H5Oattribute.c | 55 | ||||
-rwxr-xr-x | src/H5SM.c | 120 | ||||
-rwxr-xr-x | src/H5SMbtree2.c | 26 | ||||
-rw-r--r-- | src/H5SMcache.c | 13 | ||||
-rwxr-xr-x | src/H5SMpkg.h | 52 | ||||
-rwxr-xr-x | src/H5SMprivate.h | 8 | ||||
-rw-r--r-- | src/H5SMtest.c | 196 | ||||
-rwxr-xr-x | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/Makefile.in | 10 | ||||
-rw-r--r-- | test/tattr.c | 201 |
15 files changed, 713 insertions, 156 deletions
@@ -414,6 +414,7 @@ ./src/H5Adense.c ./src/H5Adeprec.c ./src/H5Aint.c +./src/H5Atest.c ./src/H5Apkg.h ./src/H5Aprivate.h ./src/H5Apublic.h @@ -643,6 +644,7 @@ ./src/H5SMcache.c ./src/H5SMpkg.h ./src/H5SMprivate.h +./src/H5SMtest.c ./src/H5ST.c ./src/H5STprivate.h ./src/H5T.c diff --git a/src/H5Adense.c b/src/H5Adense.c index d6231cf..61726f8 100644 --- a/src/H5Adense.c +++ b/src/H5Adense.c @@ -464,7 +464,7 @@ H5A_dense_insert(H5F_t *f, hid_t dxpl_id, const H5O_t *oh, unsigned mesg_flags, attr_ptr = attr_buf; /* Create serialized form of attribute or shared message */ - if(H5O_msg_encode(f, H5O_ATTR_ID, attr_ptr, attr) < 0) + if(H5O_msg_encode(f, H5O_ATTR_ID, (unsigned char *)attr_ptr, attr) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "can't encode attribute") /* Insert the serialized attribute into the fractal heap */ @@ -499,14 +499,14 @@ done: if(fheap && H5HF_close(fheap, dxpl_id) < 0) HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close fractal heap") if(attr_ptr && attr_ptr != attr_buf) - H5FL_BLK_FREE(ser_attr, attr_ptr); + (void)H5FL_BLK_FREE(ser_attr, attr_ptr); FUNC_LEAVE_NOAPI(ret_value) } /* end H5A_dense_insert() */ /*------------------------------------------------------------------------- - * Function: H5A_dense_write_cb + * Function: H5A_dense_write_bt2_cb * * Purpose: v2 B-tree 'find' callback to update the data for an attribute * @@ -519,7 +519,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5A_dense_write_cb(const void *_record, void *_op_data) +H5A_dense_write_bt2_cb(const void *_record, void *_op_data) { const H5A_dense_bt2_name_rec_t *record = (const H5A_dense_bt2_name_rec_t *)_record; /* Record from B-tree */ H5A_bt2_od_wrt_t *op_data = (H5A_bt2_od_wrt_t *)_op_data; /* "op data" from v2 B-tree modify */ @@ -527,7 +527,7 @@ H5A_dense_write_cb(const void *_record, void *_op_data) hbool_t id_changed = FALSE; /* Whether the heap ID changed */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5A_dense_write_cb) + FUNC_ENTER_NOAPI_NOINIT(H5A_dense_write_bt2_cb) /* * Check arguments. @@ -559,7 +559,7 @@ H5A_dense_write_cb(const void *_record, void *_op_data) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5A_dense_write_cb() */ +} /* end H5A_dense_write_bt2_cb() */ /*------------------------------------------------------------------------- @@ -627,7 +627,7 @@ H5A_dense_write(H5F_t *f, hid_t dxpl_id, const H5O_t *oh, const H5A_t *attr) attr_ptr = attr_buf; /* Create serialized form of attribute */ - if(H5O_msg_encode(f, H5O_ATTR_ID, attr_ptr, attr) < 0) + if(H5O_msg_encode(f, H5O_ATTR_ID, (unsigned char *)attr_ptr, attr) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "can't encode attribute") /* Open the fractal heap */ @@ -654,7 +654,7 @@ H5A_dense_write(H5F_t *f, hid_t dxpl_id, const H5O_t *oh, const H5A_t *attr) op_data.attr_size = attr_size; /* Modify attribute through 'name' tracking v2 B-tree */ - if(H5B2_find(f, dxpl_id, H5A_BT2_NAME, oh->name_bt2_addr, &udata, H5A_dense_write_cb, &op_data) < 0) + if(H5B2_find(f, dxpl_id, H5A_BT2_NAME, oh->name_bt2_addr, &udata, H5A_dense_write_bt2_cb, &op_data) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTINSERT, FAIL, "unable to modify record in v2 B-tree") done: @@ -664,7 +664,7 @@ done: if(fheap && H5HF_close(fheap, dxpl_id) < 0) HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close fractal heap") if(attr_ptr && attr_ptr != attr_buf) - H5FL_BLK_FREE(ser_attr, attr_ptr); + (void)H5FL_BLK_FREE(ser_attr, attr_ptr); FUNC_LEAVE_NOAPI(ret_value) } /* end H5A_dense_write() */ @@ -699,7 +699,7 @@ H5A_dense_copy_fh_cb(const void *obj, size_t UNUSED obj_len, void *_udata) * HDF5 routine, it could attempt to re-protect that direct block for the * heap, causing the HDF5 routine called to fail) */ - if(NULL == (udata->attr = H5O_msg_decode(udata->f, udata->dxpl_id, H5O_ATTR_ID, obj))) + if(NULL == (udata->attr = (H5A_t *)H5O_msg_decode(udata->f, udata->dxpl_id, H5O_ATTR_ID, (const unsigned char *)obj))) HGOTO_ERROR(H5E_ATTR, H5E_CANTDECODE, FAIL, "can't decode attribute") done: @@ -926,7 +926,7 @@ H5A_dense_remove_fh_cb(const void *obj, size_t UNUSED obj_len, void *_udata) FUNC_ENTER_NOAPI_NOINIT(H5A_dense_remove_fh_cb) /* Decode attribute */ - if(NULL == (attr = H5O_msg_decode(udata->f, udata->dxpl_id, H5O_ATTR_ID, obj))) + if(NULL == (attr = (H5A_t *)H5O_msg_decode(udata->f, udata->dxpl_id, H5O_ATTR_ID, (const unsigned char *)obj))) HGOTO_ERROR(H5E_ATTR, H5E_CANTDECODE, FAIL, "can't decode attribute") /* Perform the deletion action on the attribute */ diff --git a/src/H5Apkg.h b/src/H5Apkg.h index ca7983f..6b618c8 100644 --- a/src/H5Apkg.h +++ b/src/H5Apkg.h @@ -190,7 +190,14 @@ H5_DLL herr_t H5A_attr_release_table(H5A_attr_table_t *atable); /* Attribute object header routines */ H5_DLL herr_t H5O_attr_reset(void *_mesg); H5_DLL herr_t H5O_attr_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link); +H5_DLL htri_t H5O_attr_is_shared(const void *_mesg); H5_DLL void *H5O_attr_get_share(const void *_mesg, H5O_shared_t *sh); +/* Testing functions */ +#ifdef H5A_TESTING +H5_DLL htri_t H5A_is_shared_test(hid_t aid); +H5_DLL herr_t H5A_get_shared_rc_test(hid_t attr_id, hsize_t *ref_count); +#endif /* H5A_TESTING */ + #endif /* _H5Apkg_H */ diff --git a/src/H5Atest.c b/src/H5Atest.c new file mode 100644 index 0000000..80348e8 --- /dev/null +++ b/src/H5Atest.c @@ -0,0 +1,150 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/*------------------------------------------------------------------------- + * + * Created: H5Aint.c + * Dec 18 2006 + * Quincey Koziol <koziol@hdfgroup.org> + * + * Purpose: Internal routines for managing attributes. + * + *------------------------------------------------------------------------- + */ + +/****************/ +/* Module Setup */ +/****************/ + +#define H5A_PACKAGE /*suppress error about including H5Apkg */ +#define H5A_TESTING /*suppress warning about H5A testing funcs*/ +#define H5SM_PACKAGE /*suppress error about including H5SMpkg */ +#define H5SM_TESTING /*suppress warning about H5SM testing funcs*/ + + +/***********/ +/* Headers */ +/***********/ +#include "H5private.h" /* Generic Functions */ +#include "H5Apkg.h" /* Attributes */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Iprivate.h" /* IDs */ +#include "H5SMpkg.h" /* Shared object header messages */ + + +/****************/ +/* Local Macros */ +/****************/ + + +/******************/ +/* Local Typedefs */ +/******************/ + + +/********************/ +/* Package Typedefs */ +/********************/ + + +/********************/ +/* Local Prototypes */ +/********************/ + + +/*********************/ +/* Package Variables */ +/*********************/ + + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + + +/*******************/ +/* Local Variables */ +/*******************/ + + +/*------------------------------------------------------------------------- + * Function: H5A_is_shared_test + * + * Purpose: Check if an attribute is shared + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Quincey Koziol + * Dec 19, 2006 + * + *------------------------------------------------------------------------- + */ +htri_t +H5A_is_shared_test(hid_t attr_id) +{ + H5A_t *attr; /* Attribute object for ID */ + htri_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5A_is_shared_test) + + /* Check arguments */ + if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") + + /* Check if attribute is shared */ + ret_value = H5O_attr_is_shared(attr); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5A_is_shared_test() */ + + +/*------------------------------------------------------------------------- + * Function: H5A_get_shared_rc_test + * + * Purpose: Retrieve the refcount for a shared attribute + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Quincey Koziol + * Dec 19, 2006 + * + *------------------------------------------------------------------------- + */ +herr_t +H5A_get_shared_rc_test(hid_t attr_id, hsize_t *ref_count) +{ + H5A_t *attr; /* Attribute object for ID */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5A_get_shared_rc_test) + + /* Check arguments */ + if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") + + /* Sanity check */ + HDassert(H5O_attr_is_shared(attr)); + + /* Retrieve ref count for shared attribute */ + if(H5SM_get_refcount_test(attr->oloc.file, H5AC_ind_dxpl_id, H5O_ATTR_ID, + &attr->sh_loc, ref_count) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't retrieve shared message ref count") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5A_get_shared_rc_test() */ + diff --git a/src/H5Oattr.c b/src/H5Oattr.c index 75b7d3a..619dcac 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -40,7 +40,6 @@ static void *H5O_attr_copy_file(H5F_t *file_src, const H5O_msg_class_t *mesg_typ void *native_src, H5F_t *file_dst, hid_t dxpl_id, H5O_copy_t *cpy_info, void *udata); static herr_t H5O_attr_set_share(void *_mesg, const H5O_shared_t *sh); -static htri_t H5O_attr_is_shared(const void *_mesg); static herr_t H5O_attr_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int indent, int fwidth); @@ -1145,7 +1144,7 @@ H5O_attr_set_share(void *_mesg/*in,out*/, const H5O_shared_t *sh) * *------------------------------------------------------------------------- */ -static htri_t +htri_t H5O_attr_is_shared(const void *_mesg) { const H5A_t *mesg = (const H5A_t *)_mesg; diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c index 2d43d9b..a7aeb79 100644 --- a/src/H5Oattribute.c +++ b/src/H5Oattribute.c @@ -162,7 +162,7 @@ H5O_attr_to_dense_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, { H5O_iter_cvt_t *udata = (H5O_iter_cvt_t *)_udata; /* Operator user data */ H5A_t shared_attr; /* Copy of shared attribute */ - H5A_t *attr; /* Pointer to attribute to insert */ + H5A_t *attr = NULL; /* Pointer to attribute to insert */ herr_t ret_value = H5_ITER_CONT; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_attr_to_dense_cb) @@ -174,14 +174,14 @@ H5O_attr_to_dense_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, /* Check for shared attribute */ if(mesg->flags & H5O_MSG_FLAG_SHARED) { /* Read the shared attribute in */ - if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, mesg->native, H5O_MSG_ATTR, &shared_attr)) + if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, (const H5O_shared_t *)mesg->native, H5O_MSG_ATTR, &shared_attr)) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, H5_ITER_ERROR, "unable to read shared attribute") /* Point attribute to insert at shared attribute read in */ attr = &shared_attr; } /* end if */ else - attr = mesg->native; + attr = (H5A_t *)mesg->native; /* Insert attribute into dense storage */ if(H5A_dense_insert(udata->f, udata->dxpl_id, oh, mesg->flags, attr) < 0) @@ -242,7 +242,7 @@ HDfprintf(stderr, "%s: adding attribute, attr->name = '%s'\n", FUNC, attr->name) HGOTO_ERROR(H5E_ATTR, H5E_WRITEERROR, FAIL, "error determining if message should be shared") /* Protect the object header to iterate over */ - if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_WRITE))) + if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_WRITE))) HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header") #ifdef QAK @@ -300,7 +300,7 @@ done: HDONE_ERROR(H5E_ATTR, H5E_PROTECT, FAIL, "unable to release object header") FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_attr_create */ +} /* end H5O_attr_create() */ /*------------------------------------------------------------------------- @@ -318,7 +318,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_attr_open_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, +H5O_attr_open_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/, unsigned UNUSED sequence, unsigned UNUSED *oh_flags_ptr, void *_udata/*in,out*/) { H5O_iter_opn_t *udata = (H5O_iter_opn_t *)_udata; /* Operator user data */ @@ -340,7 +340,7 @@ H5O_attr_open_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, * H5O_MSG_SHARED message. We use that information to look up the real * message in the global heap or some other object header. */ - if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, mesg->native, H5O_MSG_ATTR, &shared_attr)) + if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, (const H5O_shared_t *)mesg->native, H5O_MSG_ATTR, &shared_attr)) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, H5_ITER_ERROR, "unable to read shared attribute") /* Check for correct attribute message to modify */ @@ -399,7 +399,7 @@ H5O_attr_open_by_name(const H5O_loc_t *loc, const char *name, hid_t dxpl_id) HDassert(name); /* Protect the object header to iterate over */ - if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) + if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, NULL, "unable to load object header") #ifdef QAK @@ -533,7 +533,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_attr_write_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, +H5O_attr_write_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/, unsigned UNUSED sequence, unsigned *oh_flags_ptr, void *_udata/*in,out*/) { H5O_iter_wrt_t *udata = (H5O_iter_wrt_t *)_udata; /* Operator user data */ @@ -555,7 +555,7 @@ H5O_attr_write_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, * H5O_MSG_SHARED message. We use that information to look up the real * message in the global heap or some other object header. */ - if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, mesg->native, H5O_MSG_ATTR, &shared_attr)) + if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, (const H5O_shared_t *)mesg->native, H5O_MSG_ATTR, &shared_attr)) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, H5_ITER_ERROR, "unable to read shared attribute") /* Check for correct attribute message to modify */ @@ -569,12 +569,12 @@ H5O_attr_write_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, else if(shared_mesg < 0) HGOTO_ERROR(H5E_ATTR, H5E_BADMESG, H5_ITER_ERROR, "can't share attribute") - /* Remove the old attribut from the SOHM index */ - if(H5SM_try_delete(udata->f, udata->dxpl_id, H5O_ATTR_ID, mesg->native) < 0) + /* Remove the old attribute from the SOHM index */ + if(H5SM_try_delete(udata->f, udata->dxpl_id, H5O_ATTR_ID, (const H5O_shared_t *)mesg->native) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTFREE, H5_ITER_ERROR, "unable to delete shared attribute in shared storage") /* Extract shared message info from current attribute */ - if(NULL == H5O_attr_get_share(udata->attr, mesg->native)) + if(NULL == H5O_attr_get_share(udata->attr, (H5O_shared_t *)mesg->native)) HGOTO_ERROR(H5E_ATTR, H5E_BADMESG, H5_ITER_ERROR, "can't get shared info") /* Indicate that we found the correct attribute */ @@ -643,7 +643,7 @@ H5O_attr_write(const H5O_loc_t *loc, hid_t dxpl_id, H5A_t *attr) HDassert(attr); /* Protect the object header to iterate over */ - if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_WRITE))) + if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_WRITE))) HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header") /* Check for attributes stored densely */ @@ -699,7 +699,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_attr_rename_chk_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, +H5O_attr_rename_chk_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/, unsigned UNUSED sequence, unsigned UNUSED *oh_flags_ptr, void *_udata/*in,out*/) { H5O_iter_ren_t *udata = (H5O_iter_ren_t *)_udata; /* Operator user data */ @@ -721,7 +721,7 @@ H5O_attr_rename_chk_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, * H5O_MSG_SHARED message. We use that information to look up the real * message in the global heap or some other object header. */ - if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, mesg->native, H5O_MSG_ATTR, &shared_attr)) + if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, (const H5O_shared_t *)mesg->native, H5O_MSG_ATTR, &shared_attr)) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, H5_ITER_ERROR, "unable to read shared attribute") /* Check for existing attribute with new name */ @@ -767,7 +767,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_attr_rename_mod_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, +H5O_attr_rename_mod_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/, unsigned UNUSED sequence, unsigned *oh_flags_ptr, void *_udata/*in,out*/) { H5O_iter_ren_t *udata = (H5O_iter_ren_t *)_udata; /* Operator user data */ @@ -789,7 +789,7 @@ H5O_attr_rename_mod_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, * H5O_MSG_SHARED message. We use that information to look up the real * message in the global heap or some other object header. */ - if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, mesg->native, H5O_MSG_ATTR, &shared_attr)) + if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, (const H5O_shared_t *)mesg->native, H5O_MSG_ATTR, &shared_attr)) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, H5_ITER_ERROR, "unable to read shared attribute") /* Check for correct attribute message to modify */ @@ -855,7 +855,7 @@ H5O_attr_rename(const H5O_loc_t *loc, hid_t dxpl_id, const char *old_name, const HDassert(new_name); /* Protect the object header to iterate over */ - if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_WRITE))) + if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_WRITE))) HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header") /* Check for attributes stored densely */ @@ -931,7 +931,7 @@ H5O_attr_iterate(hid_t loc_id, const H5O_loc_t *loc, hid_t dxpl_id, HDassert(attr_op); /* Protect the object header to iterate over */ - if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) + if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header") /* Check for attributes stored densely */ @@ -1023,11 +1023,12 @@ H5O_attr_remove_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, * H5O_MSG_SHARED message. We use that information to look up the real * message in the global heap or some other object header. */ - if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, mesg->native, H5O_MSG_ATTR, &shared_attr)) + if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, (const H5O_shared_t *)mesg->native, H5O_MSG_ATTR, &shared_attr)) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, H5_ITER_ERROR, "unable to read shared attribute") HDfprintf(stderr, "%s: removing a shared attribute not supported yet!\n", FUNC); HGOTO_ERROR(H5E_ATTR, H5E_UNSUPPORTED, FAIL, "deleting a shared attribute not supported yet") +#ifdef NOT_YET /* Check for correct attribute message to modify */ if(HDstrcmp(shared_attr.name, udata->name) == 0) /* Indicate that this message is the attribute to be deleted */ @@ -1035,6 +1036,7 @@ HGOTO_ERROR(H5E_ATTR, H5E_UNSUPPORTED, FAIL, "deleting a shared attribute not su /* Release copy of shared attribute */ H5O_attr_reset(&shared_attr); +#endif /* NOT_YET */ } /* end if */ else { /* Check for correct attribute message to modify */ @@ -1094,7 +1096,7 @@ H5O_attr_remove(const H5O_loc_t *loc, const char *name, hid_t dxpl_id) HDassert(name); /* Protect the object header to iterate over */ - if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_WRITE))) + if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_WRITE))) HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header") /* Check for attributes stored densely */ @@ -1209,7 +1211,7 @@ H5O_attr_count(const H5O_loc_t *loc, hid_t dxpl_id) HDassert(loc); /* Protect the object header to iterate over */ - if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) + if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header") /* Check for attributes stored densely */ @@ -1247,7 +1249,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_attr_exists_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, +H5O_attr_exists_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/, unsigned UNUSED sequence, unsigned UNUSED *oh_flags_ptr, void *_udata/*in,out*/) { H5O_iter_rm_t *udata = (H5O_iter_rm_t *)_udata; /* Operator user data */ @@ -1256,7 +1258,6 @@ H5O_attr_exists_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, FUNC_ENTER_NOAPI_NOINIT(H5O_attr_exists_cb) /* check args */ - HDassert(oh); HDassert(mesg); HDassert(!udata->found); @@ -1269,7 +1270,7 @@ H5O_attr_exists_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, * H5O_MSG_SHARED message. We use that information to look up the real * message in the global heap or some other object header. */ - if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, mesg->native, H5O_MSG_ATTR, &shared_attr)) + if(NULL == H5O_shared_read(udata->f, udata->dxpl_id, (const H5O_shared_t *)mesg->native, H5O_MSG_ATTR, &shared_attr)) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, H5_ITER_ERROR, "unable to read shared attribute") /* Check for correct attribute message */ @@ -1324,7 +1325,7 @@ H5O_attr_exists(const H5O_loc_t *loc, const char *name, hid_t dxpl_id) HDassert(name); /* Protect the object header to iterate over */ - if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) + if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header") /* Check for attributes stored densely */ @@ -61,9 +61,7 @@ static herr_t H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *head static herr_t H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, unsigned type_id, const H5O_shared_t * mesg, unsigned *cache_flags); -static hsize_t H5SM_find_in_list(H5F_t *f, H5SM_list_t *list, const H5SM_mesg_key_t *key); static herr_t H5SM_type_to_flag(unsigned type_id, unsigned *type_flag); -static ssize_t H5SM_get_index(const H5SM_master_table_t *table, unsigned type_id); /*********************/ @@ -169,7 +167,7 @@ H5SM_init(H5F_t *f, H5P_genplist_t * fc_plist, hid_t dxpl_id) HDassert(table->num_indexes > 0 && table->num_indexes <= H5SM_MAX_NUM_INDEXES); /* Allocate the SOHM indexes as an array. */ - if(NULL == (table->indexes = H5FL_ARR_MALLOC(H5SM_index_header_t, table->num_indexes))) + if(NULL == (table->indexes = (H5SM_index_header_t *)H5FL_ARR_MALLOC(H5SM_index_header_t, (size_t)table->num_indexes))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for SOHM indexes") /* Initialize all of the indexes, but don't allocate space for them to @@ -278,7 +276,7 @@ done: * *------------------------------------------------------------------------- */ -static ssize_t +ssize_t H5SM_get_index(const H5SM_master_table_t *table, unsigned type_id) { ssize_t x; @@ -339,7 +337,7 @@ H5SM_type_shared(H5F_t *f, unsigned type_id, hid_t dxpl_id) /* Look up the master SOHM table */ if(H5F_addr_defined(f->shared->sohm_addr)) { - if(NULL == (table = H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_READ))) + if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_READ))) HGOTO_ERROR(H5E_OHDR, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") } /* end if */ else @@ -385,7 +383,7 @@ H5SM_get_fheap_addr(H5F_t *f, unsigned type_id, hid_t dxpl_id) FUNC_ENTER_NOAPI(H5SM_get_fheap_addr, FAIL) /* Look up the master SOHM table */ - if(NULL == (table = H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_READ))) + if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_READ))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, HADDR_UNDEF, "unable to load SOHM master table") /* JAMES! */ @@ -447,8 +445,8 @@ H5SM_create_index(H5F_t *f, H5SM_index_header_t *header, hid_t dxpl_id) { header->index_type = H5SM_BTREE; - if(H5B2_create(f, dxpl_id, H5SM_INDEX, H5SM_B2_NODE_SIZE, - H5SM_SOHM_ENTRY_SIZE(f), H5SM_B2_SPLIT_PERCENT, + if(H5B2_create(f, dxpl_id, H5SM_INDEX, (size_t)H5SM_B2_NODE_SIZE, + (size_t)H5SM_SOHM_ENTRY_SIZE(f), H5SM_B2_SPLIT_PERCENT, H5SM_B2_MERGE_PERCENT, &tree_addr) <0) HGOTO_ERROR(H5E_BTREE, H5E_CANTCREATE, FAIL, "B-tree creation failed for SOHM index") @@ -508,10 +506,10 @@ done: static haddr_t H5SM_create_list(H5F_t *f, H5SM_index_header_t * header, hid_t dxpl_id) { - H5SM_list_t *list = NULL; /* List of messages */ - hsize_t x; /* Counter variable */ - hsize_t size; /* Size of list on disk */ - size_t num_entries; /* Number of messages to create in list */ + H5SM_list_t *list = NULL; /* List of messages */ + hsize_t x; /* Counter variable */ + hsize_t size = 0; /* Size of list on disk */ + size_t num_entries; /* Number of messages to create in list */ haddr_t addr = HADDR_UNDEF; /* Address of the list on disk */ haddr_t ret_value; @@ -525,7 +523,7 @@ H5SM_create_list(H5F_t *f, H5SM_index_header_t * header, hid_t dxpl_id) /* Allocate list in memory */ if((list = H5FL_MALLOC(H5SM_list_t)) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "file allocation failed for SOHM list") - if((list->messages = H5FL_ARR_MALLOC(H5SM_sohm_t, num_entries)) == NULL) + if((list->messages = (H5SM_sohm_t *)H5FL_ARR_MALLOC(H5SM_sohm_t, num_entries)) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "file allocation failed for SOHM list") /* Initialize messages in list */ @@ -629,7 +627,7 @@ H5SM_try_share(H5F_t *f, hid_t dxpl_id, unsigned type_id, void *mesg) } /* Look up the master SOHM table */ - if (NULL == (table = H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_WRITE))) + if (NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_WRITE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") /* Find the right index for this message type. If there is no such index @@ -642,7 +640,7 @@ H5SM_try_share(H5F_t *f, hid_t dxpl_id, unsigned type_id, void *mesg) } /* end if */ /* If the message isn't big enough, don't bother sharing it */ - if(0 == (mesg_size = H5O_msg_mesg_size(f, type_id, mesg, 0))) + if(0 == (mesg_size = H5O_msg_mesg_size(f, type_id, mesg, (size_t)0))) HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "unable to get OH message size") if(mesg_size < table->indexes[index_num].min_mesg_size) HGOTO_DONE(FALSE); @@ -721,7 +719,7 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, if(NULL == (encoding_buf = H5MM_calloc(buf_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate buffer for encoding") - if(H5O_msg_encode(f, type_id, encoding_buf, mesg) < 0) + if(H5O_msg_encode(f, type_id, (unsigned char *)encoding_buf, mesg) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, FAIL, "can't encode message to be shared") /* Open the fractal heap for this index */ @@ -742,13 +740,13 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, if(header->index_type == H5SM_LIST) { /* The index is a list; get it from the cache */ - if (NULL == (list = H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_WRITE))) + if (NULL == (list = (H5SM_list_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_WRITE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM index") /* JAMES: not very effecient (gets hash value twice, searches list twice). Refactor. */ /* See if the message is already in the index and get its location */ /* JAMES: should return a pointer to the message */ - list_pos = H5SM_find_in_list(f, list, &key); + list_pos = H5SM_find_in_list(list, &key); if(list_pos != UFAIL) { /* The message was in the index. Increment its reference count. */ @@ -794,8 +792,8 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, hsize_t list_size; /* Size of list on disk */ haddr_t tree_addr; - if(H5B2_create(f, dxpl_id, H5SM_INDEX, H5SM_B2_NODE_SIZE, - H5SM_SOHM_ENTRY_SIZE(f), H5SM_B2_SPLIT_PERCENT, + if(H5B2_create(f, dxpl_id, H5SM_INDEX, (size_t)H5SM_B2_NODE_SIZE, + (size_t)H5SM_SOHM_ENTRY_SIZE(f), H5SM_B2_SPLIT_PERCENT, H5SM_B2_MERGE_PERCENT, &tree_addr) <0) HGOTO_ERROR(H5E_BTREE, H5E_CANTCREATE, FAIL, "B-tree creation failed for SOHM index") @@ -912,7 +910,7 @@ H5SM_try_delete(H5F_t *f, hid_t dxpl_id, unsigned type_id, HDassert(f->shared->sohm_addr != HADDR_UNDEF); /* Look up the master SOHM table */ - if(NULL == (table = H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_WRITE))) + if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_WRITE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") /* Find the correct index and try to delete from it */ @@ -945,15 +943,14 @@ done: * *------------------------------------------------------------------------- */ -static hsize_t -H5SM_find_in_list(H5F_t *f, H5SM_list_t *list, const H5SM_mesg_key_t *key) +size_t +H5SM_find_in_list(H5SM_list_t *list, const H5SM_mesg_key_t *key) { - hsize_t x; - hsize_t ret_value = UFAIL; + size_t x; + size_t ret_value = UFAIL; FUNC_ENTER_NOAPI_NOFUNC(H5SM_find_in_list) - HDassert(f); HDassert(list); HDassert(key); @@ -971,6 +968,34 @@ H5SM_find_in_list(H5F_t *f, H5SM_list_t *list, const H5SM_mesg_key_t *key) /*------------------------------------------------------------------------- + * Function: H5SM_get_hash_fh_cb + * + * Purpose: Callback for fractal heap operator, to make copy of link when + * when lookup up a link by index + * + * Return: SUCCEED/FAIL + * + * Programmer: Quincey Koziol + * koziol@hdfgroup.org + * Nov 7 2006 + * + *------------------------------------------------------------------------- + */ +herr_t +H5SM_get_hash_fh_cb(const void *obj, size_t obj_len, void *_udata) +{ + H5SM_fh_ud_gh_t *udata = (H5SM_fh_ud_gh_t *)_udata; /* User data for fractal heap 'op' callback */ + + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_get_hash_fh_cb) + + /* Compute hash value on raw message */ + udata->hash = H5_checksum_lookup3(obj, obj_len, udata->type_id); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5SM_get_hash_fh_cb() */ + + +/*------------------------------------------------------------------------- * Function: H5SM_delete_from_index * * Purpose: Given a SOHM message, delete it from this index. @@ -991,10 +1016,9 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, H5SM_list_t *list = NULL; H5SM_mesg_key_t key; H5SM_sohm_t message; - unsigned char *buf = NULL; - size_t buf_size; - hsize_t list_pos; /* Position of the message in the list */ - H5HF_t *fheap=NULL; /* Fractal heap that contains the message */ + size_t list_pos = UFAIL; /* Position of the message in the list */ + H5HF_t *fheap = NULL; /* Fractal heap that contains the message */ + H5SM_fh_ud_gh_t udata; /* User data for fractal heap 'op' callback */ herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(H5SM_delete_from_index, FAIL) @@ -1005,39 +1029,33 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, HDassert(mesg->flags & H5O_SHARED_IN_HEAP_FLAG); /* Open the heap that this message is in */ - if(NULL == (fheap=H5HF_open(f, dxpl_id, header->heap_addr))) + if(NULL == (fheap = H5HF_open(f, dxpl_id, header->heap_addr))) HGOTO_ERROR(H5E_HEAP, H5E_CANTOPENOBJ, FAIL, "unable to open fractal heap") - /* JAMES: use heap op command */ - /* Get the message size */ - if(H5HF_get_obj_len(fheap, dxpl_id, &(mesg->u.heap_id), &buf_size) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't get message size from fractal heap.") - - /* Allocate a buffer to hold the message */ - if(NULL == (buf = H5MM_malloc(buf_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "couldn't allocate memory") + /* Prepare user data for fractal heap 'op' callback */ + udata.type_id = type_id; - /* Read the message to get its hash value */ - if(H5HF_read(fheap, dxpl_id, &(mesg->u.heap_id), buf) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't read message from fractal heap.") + /* Compute the hash value for the B-tree lookup */ + if(H5HF_op(fheap, dxpl_id, &(mesg->u.heap_id), H5SM_get_hash_fh_cb, &udata) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't access message in fractal heap") /* Set up key for message to be deleted. */ - key.hash = H5_checksum_lookup3(buf, buf_size, type_id); + key.hash = udata.hash; key.encoding = NULL; key.encoding_size = 0; - key.fheap = fheap; /* JAMES: unused */ + key.fheap = fheap; key.mesg_heap_id = mesg->u.heap_id; /* Try to find the message in the index */ if(header->index_type == H5SM_LIST) { /* If the index is stored as a list, get it from the cache */ - if (NULL == (list = H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_WRITE))) + if (NULL == (list = (H5SM_list_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_WRITE))) HGOTO_ERROR(H5E_SOHM, H5E_CANTPROTECT, FAIL, "unable to load SOHM index") /* Find the message in the list */ - if((list_pos = H5SM_find_in_list(f, list, &key)) == UFAIL) + if((list_pos = H5SM_find_in_list(list, &key)) == UFAIL) HGOTO_ERROR(H5E_SOHM, H5E_NOTFOUND, FAIL, "message not in index") --(list->messages[list_pos].ref_count); @@ -1104,7 +1122,7 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, HGOTO_ERROR(H5E_SOHM, H5E_CANTINIT, FAIL, "unable to create shared message list") HDassert(NULL == list); - if(NULL == (list = H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_WRITE))) + if(NULL == (list = (H5SM_list_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_WRITE))) HGOTO_ERROR(H5E_SOHM, H5E_CANTPROTECT, FAIL, "unable to load SOHM index") /* Delete the B-tree and have messages copy themselves to the @@ -1116,10 +1134,6 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, } /* end if */ done: - /* Free the message buffer */ - if(buf) - H5MM_xfree(buf); - /* Release the SOHM list */ if(list && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, list, H5AC__DIRTIED_FLAG) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "unable to close SOHM index") @@ -1164,7 +1178,7 @@ H5SM_get_info(H5F_t *f, unsigned *index_flags, unsigned *minsizes, /* Read the rest of the SOHM table information from the cache */ - if (NULL == (table = H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, table_addr, NULL, NULL, H5AC_READ))) + if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, table_addr, NULL, NULL, H5AC_READ))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") /* Return info */ @@ -1210,7 +1224,7 @@ H5SM_reconstitute(H5O_shared_t *sh_mesg, const uint8_t *heap_id) /* Set flag for shared message */ sh_mesg->flags = H5O_SHARED_IN_HEAP_FLAG; - HDmemcpy(&sh_mesg->u.heap_id, heap_id, H5SM_FHEAP_ID_LEN); + HDmemcpy(&sh_mesg->u.heap_id, heap_id, (size_t)H5SM_FHEAP_ID_LEN); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5SM_reconstitute() */ diff --git a/src/H5SMbtree2.c b/src/H5SMbtree2.c index c495f56..adfcaba 100755 --- a/src/H5SMbtree2.c +++ b/src/H5SMbtree2.c @@ -17,28 +17,25 @@ /****************/ #define H5SM_PACKAGE /*suppress error about including H5SMpkg */ -#define H5F_PACKAGE /*suppress error about including H5Fpkg */ /***********/ /* Headers */ /***********/ #include "H5private.h" /* Generic Functions */ -#include "H5ACprivate.h" /* Metadata cache */ #include "H5Eprivate.h" /* Error handling */ -#include "H5FLprivate.h" /* Free Lists */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5Fpkg.h" /* File access */ #include "H5SMpkg.h" /* Shared object header messages */ -#include "H5B2private.h" /* v2 B-trees */ + /****************/ /* Local Macros */ /****************/ + /******************/ /* Local Typedefs */ /******************/ + /********************/ /* Local Prototypes */ /********************/ @@ -91,8 +88,9 @@ H5SM_message_compare(const void *rec1, const void *rec2) { const H5SM_mesg_key_t *key = (const H5SM_mesg_key_t *) rec1; const H5SM_sohm_t *mesg = (const H5SM_sohm_t *) rec2; - int64_t hash_diff; /* Has to be able to hold two 32-bit values */ - herr_t ret_value=0; + int64_t hash_diff; /* Has to be able to hold two 32-bit values */ + herr_t ret_value = 0; + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_message_compare) hash_diff = key->hash; @@ -116,7 +114,7 @@ H5SM_message_compare(const void *rec1, const void *rec2) /* We need to see if this message is in fact the message stored * in the heap. Read it from the heap and compare the two. */ - HDmemset(buf2, 0, H5O_MESG_MAX_SIZE); + HDmemset(buf2, 0, (size_t)H5O_MESG_MAX_SIZE); ret = H5HF_read(key->fheap, H5AC_dxpl_id, &(mesg->fheap_id), &buf2); HDassert(ret >= 0); @@ -136,7 +134,6 @@ H5SM_message_compare(const void *rec1, const void *rec2) FUNC_LEAVE_NOAPI(ret_value) } /* end H5SM_message_compare */ - /*------------------------------------------------------------------------- * Function: H5SM_message_store @@ -163,7 +160,6 @@ H5SM_message_store(void *native, const void *udata) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5SM_message_store */ - /*------------------------------------------------------------------------- * Function: H5SM_message_retrieve @@ -192,7 +188,6 @@ H5SM_message_retrieve(void *udata, const void *native) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5SM_message_retrieve */ - /*------------------------------------------------------------------------- * Function: H5SM_message_encode @@ -252,7 +247,6 @@ H5SM_message_decode(const H5F_t UNUSED *f, const uint8_t *raw, void *_nrecord) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5SM_message_decode */ - /*------------------------------------------------------------------------- * Function: H5SM_message_debug @@ -303,6 +297,7 @@ herr_t H5SM_incr_ref(void *record, void *op_data, hbool_t *changed) { H5SM_sohm_t *message = (H5SM_sohm_t *) record; + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_incr_ref) HDassert(record); @@ -318,7 +313,6 @@ H5SM_incr_ref(void *record, void *op_data, hbool_t *changed) FUNC_LEAVE_NOAPI(SUCCEED) } - /*------------------------------------------------------------------------- * Function: H5SM_decr_ref @@ -343,6 +337,7 @@ herr_t H5SM_decr_ref(void *record, void *op_data, hbool_t *changed) { H5SM_sohm_t *message = (H5SM_sohm_t *) record; + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_decr_ref) HDassert(record); @@ -359,7 +354,6 @@ H5SM_decr_ref(void *record, void *op_data, hbool_t *changed) } - /*------------------------------------------------------------------------- * Function: H5SM_convert_to_list_op * @@ -382,6 +376,7 @@ H5SM_convert_to_list_op(const void * record, void *op_data) const H5SM_sohm_t *message = (const H5SM_sohm_t *) record; const H5SM_list_t *list = (const H5SM_list_t *) op_data; hsize_t x; + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_convert_to_list_op) HDassert(record); @@ -402,3 +397,4 @@ H5SM_convert_to_list_op(const void * record, void *op_data) FUNC_LEAVE_NOAPI(SUCCEED) } + diff --git a/src/H5SMcache.c b/src/H5SMcache.c index 155a3ab..1786c74 100644 --- a/src/H5SMcache.c +++ b/src/H5SMcache.c @@ -246,7 +246,7 @@ H5SM_load_table(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1 HDassert((size_t)(p - buf) == H5SM_TABLE_SIZE(f) - H5SM_SIZEOF_CHECKSUM); /* Allocate space for the index headers in memory*/ - if(NULL == (table->indexes = H5FL_ARR_MALLOC(H5SM_index_header_t, table->num_indexes))) + if(NULL == (table->indexes = H5FL_ARR_MALLOC(H5SM_index_header_t, (size_t)table->num_indexes))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for SOHM indexes") /* Read in the index headers */ @@ -337,13 +337,12 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5SM_dest_table(H5F_t *f, H5SM_master_table_t* table) +H5SM_dest_table(H5F_t UNUSED *f, H5SM_master_table_t* table) { FUNC_ENTER_NOAPI_NOFUNC(H5SM_dest_table) - assert(table); - - assert(table->indexes); + HDassert(table); + HDassert(table->indexes); H5FL_ARR_FREE(H5SM_index_header_t, table->indexes); @@ -623,7 +622,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5SM_dest_list(H5F_t *f, H5SM_list_t* list) +H5SM_dest_list(H5F_t UNUSED *f, H5SM_list_t* list) { FUNC_ENTER_NOAPI_NOFUNC(H5SM_dest_list) @@ -653,7 +652,7 @@ H5SM_dest_list(H5F_t *f, H5SM_list_t* list) *------------------------------------------------------------------------- */ static herr_t -H5SM_list_size(const H5F_t *f, const H5SM_list_t *list, size_t *size_ptr) +H5SM_list_size(const H5F_t UNUSED *f, const H5SM_list_t *list, size_t *size_ptr) { FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_list_size) diff --git a/src/H5SMpkg.h b/src/H5SMpkg.h index 0aea386..342b2bc 100755 --- a/src/H5SMpkg.h +++ b/src/H5SMpkg.h @@ -63,6 +63,10 @@ #define H5SM_MAX_INDEXES 8 #define H5SM_MAX_LIST_ELEMS 1000 +#define H5SM_B2_NODE_SIZE 512 +#define H5SM_B2_SPLIT_PERCENT 100 +#define H5SM_B2_MERGE_PERCENT 40 + /****************************/ /* Package Typedefs */ /****************************/ @@ -95,10 +99,13 @@ * disk. */ -/* Declare free lists to manage H5SM structs */ -H5FL_ARR_EXTERN(H5SM_index_header_t); -H5FL_EXTERN(H5SM_list_t); -H5FL_ARR_EXTERN(H5SM_sohm_t); +/* Typedef for a SOHM index node */ +typedef struct { + /* JAMES: I think I need message type here, and stored in file. */ + uint32_t hash; /* Hash value for OHM */ + H5SM_fheap_id_t fheap_id; /* ID of the OHM in the fractal heap */ + hsize_t ref_count; /* JAMES TODO: should this be hsize_t? */ +} H5SM_sohm_t; typedef enum { H5SM_BADTYPE = -1, @@ -147,22 +154,39 @@ typedef struct { H5SM_index_header_t *indexes; /* Array of num_indexes indexes */ } H5SM_master_table_t; +/* + * Data exchange structure to pass through the fractal heap layer for the + * H5HF_op function when computing a hash value for a message. + */ +typedef struct { + /* downward (internal) */ + unsigned type_id; /* Message type */ + + /* upward */ + uint32_t hash; /* Hash value */ +} H5SM_fh_ud_gh_t; -#define H5SM_B2_NODE_SIZE 512 -#define H5SM_B2_SPLIT_PERCENT 100 -#define H5SM_B2_MERGE_PERCENT 40 /****************************/ /* Package Variables */ /****************************/ +/* Declare free lists to manage H5SM structs */ +H5FL_ARR_EXTERN(H5SM_index_header_t); +H5FL_EXTERN(H5SM_list_t); +H5FL_ARR_EXTERN(H5SM_sohm_t); + H5_DLLVAR const H5AC_class_t H5AC_SOHM_TABLE[1]; H5_DLLVAR const H5AC_class_t H5AC_SOHM_LIST[1]; - H5_DLLVAR const H5B2_class_t H5SM_INDEX[1]; /****************************/ /* Package Prototypes */ /****************************/ + +/* General routines */ +H5_DLL ssize_t H5SM_get_index(const H5SM_master_table_t *table, unsigned type_id); +H5_DLL size_t H5SM_find_in_list(H5SM_list_t *list, const H5SM_mesg_key_t *key); + /* Encode and decode routines, used for B-tree and cache encoding/decoding */ H5_DLL herr_t H5SM_message_encode(const H5F_t *f, uint8_t *raw, const void *native); @@ -183,4 +207,14 @@ H5_DLL herr_t H5SM_decr_ref(void *record, void *op_data, hbool_t *changed); /* H5B2_remove_t callback to add messages to a list index */ H5_DLL herr_t H5SM_convert_to_list_op(const void * record, void *op_data); -#endif /*_H5SMpkg_H*/ +/* Fractal heap 'op' callback to compute hash value for message "in place" */ +H5_DLL herr_t H5SM_get_hash_fh_cb(const void *obj, size_t obj_len, void *_udata); + +/* Testing functions */ +#ifdef H5SM_TESTING +H5_DLL herr_t H5SM_get_refcount_test(H5F_t *f, hid_t dxpl_id, unsigned type_id, + const H5O_shared_t *sh_mesg, hsize_t *ref_count); +#endif /* H5SM_TESTING */ + +#endif /* _H5SMpkg_H */ + diff --git a/src/H5SMprivate.h b/src/H5SMprivate.h index fd421e1..37d4689 100755 --- a/src/H5SMprivate.h +++ b/src/H5SMprivate.h @@ -31,14 +31,6 @@ #define H5SM_MAX_NUM_INDEXES 6 -/* Typedef for a SOHM index node */ -typedef struct { - /* JAMES: I think I need message type here, and stored in file. */ - uint32_t hash; /* Hash value for OHM */ - H5SM_fheap_id_t fheap_id; /* ID of the OHM in the fractal heap */ - hsize_t ref_count; /* JAMES TODO: should this be hsize_t? */ -} H5SM_sohm_t; - /******************************/ /* Library Private Prototypes */ /******************************/ diff --git a/src/H5SMtest.c b/src/H5SMtest.c new file mode 100644 index 0000000..03526bb --- /dev/null +++ b/src/H5SMtest.c @@ -0,0 +1,196 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/****************/ +/* Module Setup */ +/****************/ + +#define H5F_PACKAGE /*suppress error about including H5Fpkg */ +#define H5SM_PACKAGE /*suppress error about including H5SMpkg */ +#define H5SM_TESTING /*suppress warning about H5SM testing funcs*/ + + +/***********/ +/* Headers */ +/***********/ +#include "H5private.h" /* Generic Functions */ +#include "H5ACprivate.h" /* Metadata cache */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Fpkg.h" /* File access */ +#include "H5SMpkg.h" /* Shared object header messages */ + + +/****************/ +/* Local Macros */ +/****************/ + + +/******************/ +/* Local Typedefs */ +/******************/ + + +/********************/ +/* Local Prototypes */ +/********************/ + + +/*********************/ +/* Package Variables */ +/*********************/ + + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + + +/*******************/ +/* Local Variables */ +/*******************/ + + + +/*------------------------------------------------------------------------- + * Function: H5SM_get_refcount_bt2_cb + * + * Purpose: v2 B-tree 'find' callback to retrieve the record for a message + * + * Return: SUCCEED/FAIL + * + * Programmer: Quincey Koziol + * Tuesday, December 19, 2006 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5SM_get_refcount_bt2_cb(const void *_record, void *_op_data) +{ + const H5SM_sohm_t *record = (const H5SM_sohm_t *)_record; /* v2 B-tree record for message */ + H5SM_sohm_t *op_data = (H5SM_sohm_t *)_op_data; /* "op data" from v2 B-tree find */ + + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_get_refcount_bt2_cb) + + /* + * Check arguments. + */ + HDassert(record); + HDassert(op_data); + + /* Make a copy of the record */ + *op_data = *record; + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5SM_get_refcount_bt2_cb() */ + + +/*------------------------------------------------------------------------- + * Function: H5SM_get_refcount_test + * + * Purpose: Retrieve the reference count for a message + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Tuesday, December 19, 2006 + * + *------------------------------------------------------------------------- + */ +herr_t +H5SM_get_refcount_test(H5F_t *f, hid_t dxpl_id, unsigned type_id, + const H5O_shared_t *sh_mesg, hsize_t *ref_count) +{ + H5HF_t *fheap = NULL; /* Fractal heap that contains shared messages */ + H5SM_master_table_t *table = NULL; /* SOHM master table */ + H5SM_list_t *list = NULL; /* SOHM index list for message type (if in list form) */ + H5SM_index_header_t *header; /* Index header for message type */ + H5SM_mesg_key_t key; /* Key for looking up message */ + H5SM_fh_ud_gh_t udata; /* User data for fractal heap 'op' callback */ + H5SM_sohm_t message; /* Record for shared message */ + ssize_t index_num; /* Table index for message type */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5SM_get_refcount_test) + + /* Sanity check */ + HDassert(f); + HDassert(sh_mesg); + HDassert(ref_count); + + /* Look up the master SOHM table */ + if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_READ))) + HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") + + /* Find the correct index and try to delete from it */ + if((index_num = H5SM_get_index(table, type_id)) < 0) + HGOTO_ERROR(H5E_SOHM, H5E_NOTFOUND, FAIL, "unable to find correct SOHM index") + header = &(table->indexes[index_num]); + + /* Open the heap that this message is in */ + if(NULL == (fheap = H5HF_open(f, dxpl_id, header->heap_addr))) + HGOTO_ERROR(H5E_HEAP, H5E_CANTOPENOBJ, FAIL, "unable to open fractal heap") + + /* Prepare user data for callback */ + udata.type_id = type_id; + + /* Compute the hash value for the B-tree lookup */ + if(H5HF_op(fheap, dxpl_id, &(sh_mesg->u.heap_id), H5SM_get_hash_fh_cb, &udata) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't access message in fractal heap") + + /* Set up key for message to locate */ + key.hash = udata.hash; + key.encoding = NULL; + key.encoding_size = 0; + key.fheap = fheap; + key.mesg_heap_id = sh_mesg->u.heap_id; + + /* Try to find the message in the index */ + if(header->index_type == H5SM_LIST) { + size_t list_pos; /* Position of the message in the list */ + + /* If the index is stored as a list, get it from the cache */ + if(NULL == (list = (H5SM_list_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_READ))) + HGOTO_ERROR(H5E_SOHM, H5E_CANTPROTECT, FAIL, "unable to load SOHM index") + + /* Find the message in the list */ + if((list_pos = H5SM_find_in_list(list, &key)) == UFAIL) + HGOTO_ERROR(H5E_SOHM, H5E_NOTFOUND, FAIL, "message not in index") + + /* Copy the message */ + message = list->messages[list_pos]; + } /* end if */ + else /* Index is a B-tree */ + { + HDassert(header->index_type == H5SM_BTREE); + + /* Look up the message in the v2 B-tree */ + if(H5B2_find(f, dxpl_id, H5SM_INDEX, header->index_addr, &key, H5SM_get_refcount_bt2_cb, &message) < 0) + HGOTO_ERROR(H5E_SOHM, H5E_NOTFOUND, FAIL, "message not in index") + } /* end else */ + + /* Set the refcount for the message */ + *ref_count = message.ref_count; + +done: + /* Release resources */ + if(list && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, list, H5AC__NO_FLAGS_SET) < 0) + HDONE_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "unable to close SOHM index") + if(table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, table, H5AC__NO_FLAGS_SET) < 0) + HDONE_ERROR(H5E_CACHE, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") + if(fheap && H5HF_close(fheap, dxpl_id) < 0) + HDONE_ERROR(H5E_HEAP, H5E_CLOSEERROR, FAIL, "can't close fractal heap") + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5SM_get_refcount_test() */ + diff --git a/src/Makefile.am b/src/Makefile.am index 630e7fb..099f76a 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,7 +41,7 @@ DISTCLEANFILES=H5pubconf.h # library sources libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \ - H5A.c H5Abtree2.c H5Adense.c H5Adeprec.c H5Aint.c \ + H5A.c H5Abtree2.c H5Adense.c H5Adeprec.c H5Aint.c H5Atest.c \ H5AC.c H5B.c H5Bcache.c \ H5B2.c H5B2cache.c H5B2dbg.c H5B2int.c H5B2stat.c H5B2test.c \ H5C.c H5CS.c H5D.c H5Dcompact.c H5Dcontig.c \ @@ -71,7 +71,7 @@ libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \ H5R.c H5RC.c \ H5RS.c H5S.c H5Sall.c H5Shyper.c H5Smpio.c H5Snone.c H5Spoint.c \ H5Sselect.c H5Stest.c H5SL.c H5SM.c H5SMbtree2.c \ - H5SMcache.c H5ST.c H5T.c H5Tarray.c H5Tbit.c H5Tcommit.c \ + H5SMcache.c H5SMtest.c H5ST.c H5T.c H5Tarray.c H5Tbit.c H5Tcommit.c \ H5Tcompound.c H5Tconv.c H5Tcset.c H5Tenum.c H5Tfields.c H5Tfixed.c \ H5Tfloat.c H5Tinit.c H5Tnative.c H5Toffset.c H5Toh.c H5Topaque.c \ H5Torder.c \ diff --git a/src/Makefile.in b/src/Makefile.in index 90d13cd..f754ab5 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -82,7 +82,7 @@ LTLIBRARIES = $(lib_LTLIBRARIES) libhdf5_la_LIBADD = am_libhdf5_la_OBJECTS = H5.lo H5checksum.lo H5dbg.lo H5system.lo \ H5timer.lo H5trace.lo H5A.lo H5Abtree2.lo H5Adense.lo \ - H5Adeprec.lo H5Aint.lo H5AC.lo H5B.lo H5Bcache.lo H5B2.lo H5B2cache.lo \ + H5Adeprec.lo H5Aint.lo H5Atest.lo H5AC.lo H5B.lo H5Bcache.lo H5B2.lo H5B2cache.lo \ H5B2dbg.lo H5B2int.lo H5B2stat.lo H5B2test.lo H5C.lo H5CS.lo \ H5D.lo H5Dcompact.lo H5Dcontig.lo H5Defl.lo H5Dio.lo \ H5Distore.lo H5Dmpio.lo H5Doh.lo H5Dselect.lo H5Dtest.lo \ @@ -109,7 +109,7 @@ am_libhdf5_la_OBJECTS = H5.lo H5checksum.lo H5dbg.lo H5system.lo \ H5Pstrcpl.lo H5Ptest.lo H5R.lo H5RC.lo H5RS.lo H5S.lo \ H5Sall.lo H5Shyper.lo H5Smpio.lo H5Snone.lo H5Spoint.lo \ H5Sselect.lo H5Stest.lo H5SL.lo H5SM.lo H5SMbtree2.lo \ - H5SMcache.lo H5ST.lo H5T.lo H5Tarray.lo H5Tbit.lo H5Tcommit.lo \ + H5SMcache.lo H5SMtest.lo H5ST.lo H5T.lo H5Tarray.lo H5Tbit.lo H5Tcommit.lo \ H5Tcompound.lo H5Tconv.lo H5Tcset.lo H5Tenum.lo H5Tfields.lo \ H5Tfixed.lo H5Tfloat.lo H5Tinit.lo H5Tnative.lo H5Toffset.lo \ H5Toh.lo H5Topaque.lo H5Torder.lo H5Tpad.lo H5Tprecis.lo \ @@ -398,7 +398,7 @@ DISTCLEANFILES = H5pubconf.h # library sources libhdf5_la_SOURCES = H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \ - H5A.c H5Abtree2.c H5Adense.c H5Adeprec.c H5Aint.c H5AC.c H5B.c H5Bcache.c \ + H5A.c H5Abtree2.c H5Adense.c H5Adeprec.c H5Aint.c H5Atest.c H5AC.c H5B.c H5Bcache.c \ H5B2.c H5B2cache.c H5B2dbg.c H5B2int.c H5B2stat.c H5B2test.c \ H5C.c H5CS.c H5D.c H5Dcompact.c H5Dcontig.c \ H5Defl.c H5Dio.c H5Distore.c H5Dmpio.c H5Doh.c H5Dselect.c H5Dtest.c \ @@ -427,7 +427,7 @@ libhdf5_la_SOURCES = H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \ H5R.c H5RC.c \ H5RS.c H5S.c H5Sall.c H5Shyper.c H5Smpio.c H5Snone.c H5Spoint.c \ H5Sselect.c H5Stest.c H5SL.c H5SM.c H5SMbtree2.c \ - H5SMcache.c H5ST.c H5T.c H5Tarray.c H5Tbit.c H5Tcommit.c \ + H5SMcache.c H5SMtest.c H5ST.c H5T.c H5Tarray.c H5Tbit.c H5Tcommit.c \ H5Tcompound.c H5Tconv.c H5Tcset.c H5Tenum.c H5Tfields.c H5Tfixed.c \ H5Tfloat.c H5Tinit.c H5Tnative.c H5Toffset.c H5Toh.c H5Topaque.c \ H5Torder.c \ @@ -573,6 +573,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Adense.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Adeprec.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Aint.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Atest.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5B.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5B2.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5B2cache.Plo@am__quote@ @@ -708,6 +709,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5SM.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5SMbtree2.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5SMcache.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5SMtest.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5ST.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Sall.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Shyper.Plo@am__quote@ diff --git a/test/tattr.c b/test/tattr.c index 5860dae..4679b5b 100644 --- a/test/tattr.c +++ b/test/tattr.c @@ -28,13 +28,21 @@ #include "hdf5.h" /* - * This file needs to access private information from the H5G package. - * This file also needs to access the group testing code. + * This file needs to access private information from the H5O package. + * This file also needs to access the object header testing code. */ #define H5O_PACKAGE #define H5O_TESTING #include "H5Opkg.h" /* Object headers */ +/* + * This file needs to access private information from the H5A package. + * This file also needs to access the attribute testing code. + */ +#define H5A_PACKAGE +#define H5A_TESTING +#include "H5Apkg.h" /* Attributes */ + #define FILENAME "tattr.h5" #define NAME_BUF_SIZE 1024 #define ATTR_NAME_LEN 16 @@ -1740,6 +1748,7 @@ test_attr_dense_verify(hid_t loc_id, unsigned max_attr) } /* end for */ } /* test_attr_dense_verify() */ +#ifndef QAK /**************************************************************** ** ** test_attr_dense_create(): Test basic H5A (attribute) code. @@ -1791,7 +1800,7 @@ HDfprintf(stderr, "max_compact = %u, min_dense = %u\n", max_compact, min_dense); is_dense = H5O_is_attr_dense_test(dataset); VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test"); - /* Add attributes, until just before coverting to dense storage */ + /* Add attributes, until just before converting to dense storage */ for(u = 0; u < max_compact; u++) { /* Create attribute */ sprintf(attrname, "attr %02u", u); @@ -1897,7 +1906,7 @@ HDfprintf(stderr, "max_compact = %u, min_dense = %u\n", max_compact, min_dense); is_dense = H5O_is_attr_dense_test(dataset); VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test"); - /* Add attributes, until just before coverting to dense storage */ + /* Add attributes, until just before converting to dense storage */ for(u = 0; u < max_compact; u++) { /* Create attribute */ sprintf(attrname, "attr %02u", u); @@ -2087,6 +2096,159 @@ HDfprintf(stderr, "max_compact = %u, min_dense = %u\n", max_compact, min_dense); ret = H5Fclose(fid); CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_dense_delete() */ +#endif /* QAK */ + +/**************************************************************** +** +** test_attr_shared_write(): Test basic H5A (attribute) code. +** Tests writing to shared attributes in "compact" & "dense" storage +** +****************************************************************/ +static void +test_attr_shared_write(hid_t fcpl, hid_t fapl) +{ + hid_t fid; /* HDF5 File ID */ + hid_t dataset, dataset2; /* Dataset ID2 */ + hid_t sid; /* Dataspace ID */ + hid_t attr; /* Attribute ID */ + hid_t dcpl; /* Dataset creation property list ID */ + char attrname[NAME_BUF_SIZE]; /* Name of attribute */ + unsigned max_compact; /* Maximum # of attributes to store compactly */ + unsigned min_dense; /* Minimum # of attributes to store "densely" */ + htri_t is_dense; /* Are attributes stored densely? */ + htri_t is_shared; /* Is attributes shared? */ + hsize_t shared_refcount; /* Reference count of shared attribute */ + unsigned attr_value; /* Attribute value */ + unsigned u; /* Local index variable */ + herr_t ret; /* Generic return value */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Writing to Shared Attributes in Compact & Dense Storage\n")); + + /* Create file */ + fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl); + CHECK(fid, FAIL, "H5Fcreate"); + + /* Create dataspace for dataset */ + sid = H5Screate(H5S_SCALAR); + CHECK(sid, FAIL, "H5Screate"); + + /* Set up to query the object creation properties */ + dcpl = H5Pcreate(H5P_DATASET_CREATE); + CHECK(dcpl, FAIL, "H5Pcreate"); + + /* Create datasets */ + dataset = H5Dcreate(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, dcpl); + CHECK(dataset, FAIL, "H5Dcreate"); + dataset2 = H5Dcreate(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, dcpl); + CHECK(dataset2, FAIL, "H5Dcreate"); + + /* Retrieve limits for compact/dense attribute storage */ + ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense); + CHECK(ret, FAIL, "H5Pget_attr_phase_change"); +#ifdef QAK +HDfprintf(stderr, "max_compact = %u, min_dense = %u\n", max_compact, min_dense); +#endif /* QAK */ + + /* Check on datasets' attribute storage status */ + is_dense = H5O_is_attr_dense_test(dataset); + VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test"); + is_dense = H5O_is_attr_dense_test(dataset2); + VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test"); + + /* Add attributes to each dataset, until just before converting to dense storage */ + for(u = 0; u < max_compact; u++) { + /* Create attribute name */ + sprintf(attrname, "attr %02u", u); + + /* Create attribute on first dataset */ + attr = H5Acreate(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT); + CHECK(attr, FAIL, "H5Acreate"); + + /* Check that attribute is shared */ + is_shared = H5A_is_shared_test(attr); + VERIFY(is_shared, TRUE, "H5A_is_shared_test"); + + /* Check refcount for attribute */ + ret = H5A_get_shared_rc_test(attr, &shared_refcount); + CHECK(ret, FAIL, "H5A_get_shared_rc_test"); + VERIFY(shared_refcount, 1, "H5A_get_shared_rc_test"); + + /* Write data into the attribute */ + attr_value = u + 1; + ret = H5Awrite(attr, H5T_NATIVE_UINT, &attr_value); + CHECK(ret, FAIL, "H5Awrite"); + + /* Close attribute */ + ret = H5Aclose(attr); + CHECK(ret, FAIL, "H5Aclose"); + + /* Create attribute on second dataset */ + attr = H5Acreate(dataset2, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT); + CHECK(attr, FAIL, "H5Acreate"); + + /* Check that attribute is shared */ + is_shared = H5A_is_shared_test(attr); + VERIFY(is_shared, TRUE, "H5A_is_shared_test"); + + /* Check refcount for attribute */ + ret = H5A_get_shared_rc_test(attr, &shared_refcount); + CHECK(ret, FAIL, "H5A_get_shared_rc_test"); + VERIFY(shared_refcount, 1, "H5A_get_shared_rc_test"); + + /* Write data into the attribute */ + attr_value = u + 1; + ret = H5Awrite(attr, H5T_NATIVE_UINT, &attr_value); + CHECK(ret, FAIL, "H5Awrite"); + + /* Check refcount for attribute */ + ret = H5A_get_shared_rc_test(attr, &shared_refcount); + CHECK(ret, FAIL, "H5A_get_shared_rc_test"); + VERIFY(shared_refcount, 2, "H5A_get_shared_rc_test"); + + /* Close attribute */ + ret = H5Aclose(attr); + CHECK(ret, FAIL, "H5Aclose"); + } /* end for */ + + /* Check on dataset's attribute storage status */ + is_dense = H5O_is_attr_dense_test(dataset); + VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test"); + +#ifdef LATER + /* Add one more attribute, to push into "dense" storage */ + /* Create attribute */ + sprintf(attrname, "attr %02u", u); + attr = H5Acreate(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT); + CHECK(attr, FAIL, "H5Acreate"); + + /* Check on dataset's attribute storage status */ + is_dense = H5O_is_attr_dense_test(dataset); + VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test"); + + /* Write data into the attribute */ + ret = H5Awrite(attr, H5T_NATIVE_UINT, &u); + CHECK(ret, FAIL, "H5Awrite"); + + /* Close attribute */ + ret = H5Aclose(attr); + CHECK(ret, FAIL, "H5Aclose"); +#endif /* LATER */ + + /* Close dataspace */ + ret = H5Sclose(sid); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close Dataset2 */ + ret = H5Dclose(dataset); + CHECK(ret, FAIL, "H5Dclose"); + ret = H5Dclose(dataset2); + CHECK(ret, FAIL, "H5Dclose"); + + /* Close file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); +} /* test_attr_shared_write() */ /**************************************************************** ** @@ -2117,6 +2279,20 @@ test_attr(void) ret = H5Pset_latest_format(fapl2, TRUE); CHECK(ret, FAIL, "H5Pset_latest_format"); + /* Create a default file creation property list */ + fcpl = H5Pcreate(H5P_FILE_CREATE); + CHECK(fcpl, FAIL, "H5Pcreate"); + + /* Copy the file creation property list */ + fcpl2 = H5Pcopy(fcpl); + CHECK(fcpl2, FAIL, "H5Pcopy"); + + /* Make attributes > 1 byte shared (i.e. all of them :-) */ + ret = H5Pset_shared_mesg_nindexes(fcpl2, (unsigned)1); + CHECK_I(ret, "H5Pset_shared_mesg_nindexes"); + ret = H5Pset_shared_mesg_index(fcpl2, (unsigned)1, H5O_MESG_ATTR_FLAG, (unsigned)1); + CHECK_I(ret, "H5Pset_shared_mesg_index"); + #ifndef QAK /* Loop over using new group format */ for(new_format = FALSE; new_format <= TRUE; new_format++) { @@ -2158,20 +2334,6 @@ test_attr(void) test_attr_dtype_shared(my_fapl); /* Test using shared dataypes in attributes */ } /* end for */ - /* Create a default file creation property list */ - fcpl = H5Pcreate(H5P_FILE_CREATE); - CHECK(fcpl, FAIL, "H5Pcreate"); - - /* Copy the file creation property list */ - fcpl2 = H5Pcopy(fcpl); - CHECK(fcpl2, FAIL, "H5Pcopy"); - - /* Make attributes > 1 byte shared (i.e. all of them :-) */ - ret = H5Pset_shared_mesg_nindexes(fcpl2, (unsigned)1); - CHECK_I(ret, "H5Pset_shared_mesg_nindexes"); - ret = H5Pset_shared_mesg_index(fcpl2, (unsigned)1, H5O_MESG_ATTR_FLAG, (unsigned)1); - CHECK_I(ret, "H5Pset_shared_mesg_index"); - /* Tests on "new format" attribute storage */ /* Loop over using shared attributes */ for(use_shared = FALSE; use_shared <= TRUE; use_shared++) { @@ -2191,6 +2353,9 @@ test_attr(void) test_attr_dense_open(my_fcpl, fapl2); /* Test opening attributes in dense storage */ test_attr_dense_delete(my_fcpl, fapl2); /* Test deleting attributes in dense storage */ } /* end for */ + + /* Tests with both "new format" and shared attributes */ + test_attr_shared_write(fcpl2, fapl2); /* Test writing to shared attributes in compact & dense storage */ #else /* QAK */ HDfprintf(stderr, "Uncomment tests!\n"); #endif /* QAK */ |