From 05f1e4f778a3535135339293953d89cee8874854 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 27 Jan 2009 17:43:58 -0500 Subject: [svn-r16366] Description: Add context pointer for extensible array client callbacks. Tested on: Mac OS X/32 (amazon) FreeBSD/32 (duty) (too minor to require full h5committest) --- src/H5EA.c | 2 +- src/H5EAcache.c | 12 +++---- src/H5EAhdr.c | 11 ++++++- src/H5EApkg.h | 5 ++- src/H5EAprivate.h | 6 ++-- src/H5EAtest.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 6 files changed, 116 insertions(+), 15 deletions(-) diff --git a/src/H5EA.c b/src/H5EA.c index eadb9c0..aa65da7 100644 --- a/src/H5EA.c +++ b/src/H5EA.c @@ -906,7 +906,7 @@ HDfprintf(stderr, "%s: Called\n", FUNC); } /* end if */ /* Release the extensible array wrapper */ - (void)H5FL_FREE(H5EA_t, ea); + ea = H5FL_FREE(H5EA_t, ea); CATCH diff --git a/src/H5EAcache.c b/src/H5EAcache.c index a3c9f87..bf2bf43 100644 --- a/src/H5EAcache.c +++ b/src/H5EAcache.c @@ -596,7 +596,7 @@ H5EA__cache_iblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, /* Decode elements in index block */ if(hdr->cparam.idx_blk_elmts > 0) { /* Convert from raw elements on disk into native elements in memory */ - if((hdr->cparam.cls->decode)(p, iblock->elmts, (size_t)hdr->cparam.idx_blk_elmts) < 0) + if((hdr->cparam.cls->decode)(p, iblock->elmts, (size_t)hdr->cparam.idx_blk_elmts, hdr->cb_ctx) < 0) H5E_THROW(H5E_CANTDECODE, "can't decode extensible array index elements") p += (hdr->cparam.idx_blk_elmts * hdr->cparam.raw_elmt_size); } /* end if */ @@ -720,7 +720,7 @@ H5EA__cache_iblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, /* Encode elements in index block */ if(iblock->hdr->cparam.idx_blk_elmts > 0) { /* Convert from native elements in memory into raw elements on disk */ - if((iblock->hdr->cparam.cls->encode)(p, iblock->elmts, (size_t)iblock->hdr->cparam.idx_blk_elmts) < 0) + if((iblock->hdr->cparam.cls->encode)(p, iblock->elmts, (size_t)iblock->hdr->cparam.idx_blk_elmts, iblock->hdr->cb_ctx) < 0) H5E_THROW(H5E_CANTENCODE, "can't encode extensible array index elements") p += (iblock->hdr->cparam.idx_blk_elmts * iblock->hdr->cparam.raw_elmt_size); } /* end if */ @@ -1326,7 +1326,7 @@ H5EA__cache_dblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, if(!dblock->npages) { /* Decode elements in data block */ /* Convert from raw elements on disk into native elements in memory */ - if((hdr->cparam.cls->decode)(p, dblock->elmts, *nelmts) < 0) + if((hdr->cparam.cls->decode)(p, dblock->elmts, *nelmts, hdr->cb_ctx) < 0) H5E_THROW(H5E_CANTDECODE, "can't decode extensible array data elements") p += (*nelmts * hdr->cparam.raw_elmt_size); } /* end if */ @@ -1440,7 +1440,7 @@ H5EA__cache_dblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, /* Encode elements in data block */ /* Convert from native elements in memory into raw elements on disk */ - if((dblock->hdr->cparam.cls->encode)(p, dblock->elmts, dblock->nelmts) < 0) + if((dblock->hdr->cparam.cls->encode)(p, dblock->elmts, dblock->nelmts, dblock->hdr->cb_ctx) < 0) H5E_THROW(H5E_CANTENCODE, "can't encode extensible array data elements") p += (dblock->nelmts * dblock->hdr->cparam.raw_elmt_size); } /* end if */ @@ -1655,7 +1655,7 @@ HDfprintf(stderr, "%s: addr = %a\n", FUNC, addr); /* Decode elements in data block page */ /* Convert from raw elements on disk into native elements in memory */ - if((hdr->cparam.cls->decode)(p, dblk_page->elmts, hdr->dblk_page_nelmts) < 0) + if((hdr->cparam.cls->decode)(p, dblk_page->elmts, hdr->dblk_page_nelmts, hdr->cb_ctx) < 0) H5E_THROW(H5E_CANTDECODE, "can't decode extensible array data elements") p += (hdr->dblk_page_nelmts * hdr->cparam.raw_elmt_size); @@ -1750,7 +1750,7 @@ H5EA__cache_dblk_page_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t ad /* Encode elements in data block page */ /* Convert from native elements in memory into raw elements on disk */ - if((dblk_page->hdr->cparam.cls->encode)(p, dblk_page->elmts, dblk_page->hdr->dblk_page_nelmts) < 0) + if((dblk_page->hdr->cparam.cls->encode)(p, dblk_page->elmts, dblk_page->hdr->dblk_page_nelmts, dblk_page->hdr->cb_ctx) < 0) H5E_THROW(H5E_CANTENCODE, "can't encode extensible array data elements") p += (dblk_page->hdr->dblk_page_nelmts * dblk_page->hdr->cparam.raw_elmt_size); diff --git a/src/H5EAhdr.c b/src/H5EAhdr.c index afbd6bd..349dceb 100644 --- a/src/H5EAhdr.c +++ b/src/H5EAhdr.c @@ -140,6 +140,10 @@ H5EA__hdr_alloc(H5F_t *f, const H5EA_class_t *cls)) /* Set the class of the array */ hdr->cparam.cls = cls; + /* Create the callback context */ + if(NULL == (hdr->cb_ctx = (*cls->crt_context)(f))) + H5E_THROW(H5E_CANTCREATE, "unable to create extensible array client callback context") + /* Set the return value */ ret_value = hdr; @@ -686,6 +690,11 @@ H5EA__hdr_dest(H5EA_hdr_t *hdr)) HDassert(hdr); HDassert(hdr->rc == 0); + /* Destroy the callback context */ + if((*hdr->cparam.cls->dst_context)(hdr->cb_ctx) < 0) + H5E_THROW(H5E_CANTRELEASE, "unable to destroy extensible array client callback context") + hdr->cb_ctx = NULL; + /* Check for data block element buffer factory info to free */ if(hdr->elmt_fac.fac) { unsigned u; /* Local index variable */ @@ -712,7 +721,7 @@ H5EA__hdr_dest(H5EA_hdr_t *hdr)) hdr->sblk_info = (H5EA_sblk_info_t *)H5FL_SEQ_FREE(H5EA_sblk_info_t, hdr->sblk_info); /* Free the shared info itself */ - (void)H5FL_FREE(H5EA_hdr_t, hdr); + hdr = H5FL_FREE(H5EA_hdr_t, hdr); CATCH diff --git a/src/H5EApkg.h b/src/H5EApkg.h index 51305c4..7ac5be6 100644 --- a/src/H5EApkg.h +++ b/src/H5EApkg.h @@ -464,7 +464,7 @@ typedef struct H5EA_hdr_t { /* Information for H5AC cache functions, _must_ be first field in structure */ H5AC_info_t cache_info; - /* Extensible array configuration/creation parameters (stored) */ + /* Extensible array configuration/creation parameters (stored in header) */ H5EA_create_t cparam; /* Creation parameters for extensible array */ /* Index block information (stored in header) */ @@ -496,6 +496,9 @@ typedef struct H5EA_hdr_t { /* Data block information (not stored) */ size_t dblk_page_nelmts; /* # of elements per data block page */ + + /* Client information (not stored) */ + void *cb_ctx; /* Callback context */ } H5EA_hdr_t; /* The extensible array index block information */ diff --git a/src/H5EAprivate.h b/src/H5EAprivate.h index a1f3221..3b9ba4d 100644 --- a/src/H5EAprivate.h +++ b/src/H5EAprivate.h @@ -62,9 +62,11 @@ typedef struct H5EA_class_t { size_t nat_elmt_size; /* Size of native (memory) element */ /* Extensible array client callback methods */ + void *(*crt_context)(const H5F_t *f); /* Create context for other callbacks */ + herr_t (*dst_context)(void *ctx); /* Destroy context */ herr_t (*fill)(void *nat_blk, size_t nelmts); /* Fill array of elements with encoded form of "missing element" value */ - herr_t (*encode)(void *raw, const void *elmt, size_t nelmts); /* Encode elements from native form to disk storage form */ - herr_t (*decode)(const void *raw, void *elmt, size_t nelmts); /* Decode elements from disk storage form to native form */ + herr_t (*encode)(void *raw, const void *elmt, size_t nelmts, void *ctx); /* Encode elements from native form to disk storage form */ + herr_t (*decode)(const void *raw, void *elmt, size_t nelmts, void *ctx); /* Decode elements from disk storage form to native form */ herr_t (*debug)(FILE *stream, int indent, int fwidth, hsize_t idx, const void *elmt); /* Print an element for debugging */ } H5EA_class_t; diff --git a/src/H5EAtest.c b/src/H5EAtest.c index eea69ea..31dfb5f 100644 --- a/src/H5EAtest.c +++ b/src/H5EAtest.c @@ -39,6 +39,7 @@ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5EApkg.h" /* Extensible Arrays */ +#include "H5FLprivate.h" /* Free Lists */ #include "H5Vprivate.h" /* Vector functions */ @@ -46,11 +47,17 @@ /* Local Macros */ /****************/ +/* Sanity checking value for callback contexts */ +#define H5EA__TEST_BOGUS_VAL 42 /******************/ /* Local Typedefs */ /******************/ +/* Callback context */ +typedef struct H5EA__test_ctx_t { + uint32_t bogus; /* Placeholder field to verify that context is working */ +} H5EA__test_ctx_t; /********************/ /* Package Typedefs */ @@ -62,9 +69,13 @@ /********************/ /* Extensible array class callbacks */ +static void *H5EA__test_crt_context(const H5F_t *f); +static herr_t H5EA__test_dst_context(void *ctx); static herr_t H5EA__test_fill(void *nat_blk, size_t nelmts); -static herr_t H5EA__test_encode(void *raw, const void *elmt, size_t nelmts); -static herr_t H5EA__test_decode(const void *raw, void *elmt, size_t nelmts); +static herr_t H5EA__test_encode(void *raw, const void *elmt, size_t nelmts, + void *ctx); +static herr_t H5EA__test_decode(const void *raw, void *elmt, size_t nelmts, + void *ctx); static herr_t H5EA__test_debug(FILE *stream, int indent, int fwidth, hsize_t idx, const void *elmt); @@ -77,6 +88,8 @@ static herr_t H5EA__test_debug(FILE *stream, int indent, int fwidth, const H5EA_class_t H5EA_CLS_TEST[1]={{ H5EA_CLS_TEST_ID, /* Type of Extensible array */ sizeof(uint64_t), /* Size of native element */ + H5EA__test_crt_context, /* Create context */ + H5EA__test_dst_context, /* Destroy context */ H5EA__test_fill, /* Fill block of missing elements callback */ H5EA__test_encode, /* Element encoding callback */ H5EA__test_decode, /* Element decoding callback */ @@ -93,6 +106,76 @@ const H5EA_class_t H5EA_CLS_TEST[1]={{ /* Local Variables */ /*******************/ +/* Declare a free list to manage the H5EA__test_ctx_t struct */ +H5FL_DEFINE_STATIC(H5EA__test_ctx_t); + + + +/*------------------------------------------------------------------------- + * Function: H5EA__test_crt_context + * + * Purpose: Create context for callbacks + * + * Return: Success: non-NULL + * Failure: NULL + * + * Programmer: Quincey Koziol + * Tuesday, January 27, 2009 + * + *------------------------------------------------------------------------- + */ +BEGIN_FUNC(STATIC, ERR, +void *, NULL, NULL, +H5EA__test_crt_context(const H5F_t UNUSED *f)) + + /* Local variables */ + H5EA__test_ctx_t *ctx; /* Context for callbacks */ + + /* Sanity checks */ + HDassert(f); + + /* Allocate new context structure */ + if(NULL == (ctx = H5FL_MALLOC(H5EA__test_ctx_t))) + H5E_THROW(H5E_CANTALLOC, "can't allocate extensible array client callback context") + + /* Initialize the context */ + ctx->bogus = H5EA__TEST_BOGUS_VAL; + + /* Set return value */ + ret_value = ctx; + +CATCH + +END_FUNC(STATIC) /* end H5EA__test_crt_context() */ + + +/*------------------------------------------------------------------------- + * Function: H5EA__test_dst_context + * + * Purpose: Destroy context for callbacks + * + * Return: Success: non-negative + * Failure: negative + * + * Programmer: Quincey Koziol + * Tuesday, January 27, 2009 + * + *------------------------------------------------------------------------- + */ +BEGIN_FUNC(STATIC, NOERR, +herr_t, SUCCEED, -, +H5EA__test_dst_context(void *_ctx)) + + /* Local variables */ + H5EA__test_ctx_t *ctx = (H5EA__test_ctx_t *)_ctx; /* Callback context to destroy */ + + /* Sanity checks */ + HDassert(H5EA__TEST_BOGUS_VAL == ctx->bogus); + + /* Release context structure */ + ctx = H5FL_FREE(H5EA__test_ctx_t, ctx); + +END_FUNC(STATIC) /* end H5EA__test_dst_context() */ /*------------------------------------------------------------------------- @@ -139,15 +222,17 @@ END_FUNC(STATIC) /* end H5EA__test_fill() */ */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, -H5EA__test_encode(void *raw, const void *_elmt, size_t nelmts)) +H5EA__test_encode(void *raw, const void *_elmt, size_t nelmts, void *_ctx)) /* Local variables */ + H5EA__test_ctx_t *ctx = (H5EA__test_ctx_t *)_ctx; /* Callback context to destroy */ const uint64_t *elmt = (const uint64_t *)_elmt; /* Convenience pointer to native elements */ /* Sanity checks */ HDassert(raw); HDassert(elmt); HDassert(nelmts); + HDassert(H5EA__TEST_BOGUS_VAL == ctx->bogus); /* Encode native elements into raw elements */ while(nelmts) { @@ -180,9 +265,10 @@ END_FUNC(STATIC) /* end H5EA__test_encode() */ */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, -H5EA__test_decode(const void *_raw, void *_elmt, size_t nelmts)) +H5EA__test_decode(const void *_raw, void *_elmt, size_t nelmts, void *_ctx)) /* Local variables */ + H5EA__test_ctx_t *ctx = (H5EA__test_ctx_t *)_ctx; /* Callback context to destroy */ uint64_t *elmt = (uint64_t *)_elmt; /* Convenience pointer to native elements */ const uint8_t *raw = (const uint8_t *)_raw; /* Convenience pointer to raw elements */ @@ -190,6 +276,7 @@ H5EA__test_decode(const void *_raw, void *_elmt, size_t nelmts)) HDassert(raw); HDassert(elmt); HDassert(nelmts); + HDassert(H5EA__TEST_BOGUS_VAL == ctx->bogus); /* Decode raw elements into native elements */ while(nelmts) { -- cgit v0.12