From e37ee97a58733d3739d5e2588bdea9a1453fa023 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Thu, 14 Mar 2013 15:00:48 -0500 Subject: [svn-r23350] I cleaned up some code and added comments for my previous checkin of the DESY project. Tested on koala. --- src/H5PL.c | 66 +++++++++++++++++++++++++++------------------ src/H5PLpkg.h | 3 +++ src/H5PLpublic.h | 1 + src/H5Zpublic.h | 4 ++- test/plugin.c | 56 +++++++++++++++++--------------------- test/plugin_lib/Makefile.in | 19 +++++++++++++ test/plugin_lib/dynlib1.c | 21 +++++++++++++++ test/plugin_lib/dynlib1.h | 26 ++++++++++++++++++ test/test_plugin.sh.in | 5 +++- 9 files changed, 142 insertions(+), 59 deletions(-) diff --git a/src/H5PL.c b/src/H5PL.c index 4bf059c..afa1785 100644 --- a/src/H5PL.c +++ b/src/H5PL.c @@ -57,7 +57,7 @@ H5PL_init_interface(void) /*------------------------------------------------------------------------- * Function: H5PL_term_interface * - * Purpose: Terminate the H5I interface: release all memory, reset all + * Purpose: Terminate the H5PL interface: release all memory, reset all * global variables to initial values. This only happens if all * types have been destroyed from other interfaces. * @@ -69,6 +69,8 @@ H5PL_init_interface(void) * Programmer: Raymond Lu * 20 February 2013 * + * Modifications: + * *------------------------------------------------------------------------- */ int @@ -80,16 +82,17 @@ H5PL_term_interface(void) FUNC_ENTER_NOAPI_NOINIT_NOERR if(H5_interface_initialize_g) { - /* Free the table of dynamic libraries */ + /* Close opened dynamic libraries */ for(i=0; id_name, "lib", 3) && HDstrstr(dp->d_name, ".so")) { pathname = (char *)H5MM_malloc(strlen(dir) + strlen(dp->d_name) + 2); HDstrncpy(pathname, dir, strlen(dir)+1); @@ -248,21 +257,25 @@ H5PL_find(H5PL_type_t plugin_type, int type_id, char *dir, void **info) if(HDstat(pathname, &my_stat) == -1) HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't stat file: %s", strerror(errno)) - if(!S_ISDIR(my_stat.st_mode)) { /* if directory, skip it */ + if(!S_ISDIR(my_stat.st_mode)) { /* if it is a directory, skip it */ if(NULL == (handle = dlopen(pathname, RTLD_NOW|RTLD_LAZY))) { /*fprintf(stderr, "not open dl library: %s", dlerror());*/ - if(!HDstrcmp(dp->d_name, "libbogus2.so")) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "can't open dl library: %s", dlerror()) - else - continue; + /* There are different reasons why a library can't be open, e.g. wrong architecture. + * simply continue if we can't open it */ + continue; } - dlerror(); /*clear error*/ + dlerror(); /*clear error*/ + + /* Return a handle for the function H5PL_get_plugin_info in the dynamic library. + * The plugin library is suppose to define this function. */ if(NULL == (H5PL_get_plugin_info = dlsym(handle, "H5PL_get_plugin_info"))) { if(H5PL_close(handle) < 0) HGOTO_ERROR(H5E_PLUGIN, H5E_CLOSEERROR, FAIL, "can't close dynamic library") } + /* Envoke H5PL_get_plugin_info to verify this is the right library we are looking for. + * Move on if it isn't. */ if(H5PL_get_plugin_info) { if(NULL == (plugin_info = (*H5PL_get_plugin_info)())) { if(H5PL_close(handle) < 0) @@ -289,13 +302,13 @@ H5PL_find(H5PL_type_t plugin_type, int type_id, char *dir, void **info) if(pathname) pathname = (char *)H5MM_xfree(pathname); } - } - - if(HDclosedir(dirp) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CLOSEERROR, FAIL, "can't close directory: %s", strerror(errno)) - dirp = NULL; } + if(HDclosedir(dirp) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CLOSEERROR, FAIL, "can't close directory: %s", strerror(errno)) + dirp = NULL; + } + done: if(pathname) @@ -310,7 +323,8 @@ done: /*------------------------------------------------------------------------- * Function: H5PL_search_table * - * Purpose: + * Purpose: Search in the list of already opened dynamic libraries + * to see if the one we are looking for is already opened. * * Return: TRUE on success, * FALSE on not found, @@ -355,7 +369,7 @@ fprintf(stderr, "%s: H5PL_table_used_g=%d, id=%d\n", FUNC, H5PL_table_used_g, (H } } - /* Expand the table if it is small */ + /* Expand the table if it is too small */ if(H5PL_table_used_g >= H5PL_table_alloc_g) { size_t n = MAX(H5Z_MAX_NFILTERS, 2*H5PL_table_alloc_g); H5PL_table_t *table = (H5PL_table_t *)H5MM_realloc(H5PL_table_g, n * sizeof(H5PL_table_t)); @@ -375,7 +389,7 @@ done: /*------------------------------------------------------------------------- * Function: H5PL_close * - * Purpose: + * Purpose: Closes the handle for dynamic library * * Return: Non-negative on success/Negative on failure * diff --git a/src/H5PLpkg.h b/src/H5PLpkg.h index adbe38a..dae4c59 100644 --- a/src/H5PLpkg.h +++ b/src/H5PLpkg.h @@ -29,6 +29,7 @@ /* Local typedefs */ /****************************/ +/* Type for the list of info for opened plugin libraries */ typedef struct H5PL_table_t { H5PL_type_t pl_type; /* plugin type */ int pl_id; /* ID for the plugin */ @@ -39,10 +40,12 @@ typedef struct H5PL_table_t { /* Local variables */ /****************************/ +/* Table for opened plugin libraries */ static size_t H5PL_table_alloc_g = 0; static size_t H5PL_table_used_g = 0; static H5PL_table_t *H5PL_table_g = NULL; +/* Table of location paths for plugin libraries */ static char *path_table[MAX_PATH_NUM]; static size_t num_paths = 0; static htri_t path_found = FALSE; diff --git a/src/H5PLpublic.h b/src/H5PLpublic.h index 1f21f88..4c4a669 100644 --- a/src/H5PLpublic.h +++ b/src/H5PLpublic.h @@ -27,6 +27,7 @@ /* Library Public Typedefs */ /****************************/ +/* Plugin type */ typedef enum H5PL_type_t { H5PL_TYPE_ERROR = -1, /*error */ H5PL_TYPE_FILTER = 0, /*filter */ diff --git a/src/H5Zpublic.h b/src/H5Zpublic.h index b5ac475..24496e4 100644 --- a/src/H5Zpublic.h +++ b/src/H5Zpublic.h @@ -43,10 +43,12 @@ typedef int H5Z_filter_t; #define H5Z_FILTER_SCALEOFFSET 6 /*scale+offset compression */ #define H5Z_FILTER_RESERVED 256 /*filter ids below this value are reserved for library use */ +/* Filters for HDF5 internal test */ #define H5Z_FILTER_DYNLIB1 257 #define H5Z_FILTER_DYNLIB2 258 -#define H5Z_FILTER_BZIP2 300 +/* Registered third-party filters */ +#define H5Z_FILTER_BZIP2 307 #define H5Z_FILTER_MAX 65535 /*maximum filter id */ diff --git a/test/plugin.c b/test/plugin.c index 4385916..debc38b 100644 --- a/test/plugin.c +++ b/test/plugin.c @@ -188,7 +188,7 @@ int points_deflate[DSET_DIM1][DSET_DIM2], /*------------------------------------------------------------------------- * Function: test_filter_internal * - * Purpose: Tests + * Purpose: Tests writing entire data and partial data with filters * * Return: Success: 0 * Failure: -1 @@ -417,6 +417,8 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl, hsize_t *dset_size PASSED(); + /* Save the data written to the file for later comparison when the file + * is reopened for read test */ for(i=0; i #include #include #define FILTER_DYNLIB1_VERS 1 +const H5PL_type_t H5PL_get_plugin_type(void); +const int H5PL_get_plugin_version(void); +const char* H5PL_get_plugin_name(void); +const H5Z_class2_t* H5PL_get_plugin_info(void); + /* Local prototypes for filter functions */ static size_t H5Z_filter_dynlib1(unsigned int flags, size_t cd_nelmts, const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf); diff --git a/test/test_plugin.sh.in b/test/test_plugin.sh.in index a1287a5..a881198 100644 --- a/test/test_plugin.sh.in +++ b/test/test_plugin.sh.in @@ -13,7 +13,10 @@ # http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have # access to either file, you may request a copy from help@hdfgroup.org. # -# Tests for test_error and err_compat +# This script file first envokes the Makefile in plugin_lib to build dynamic +# plugin libraries. Then it moves the libraries to some locations and points +# HDF5_PLUGIN_PATH to these locations. In the end, it runs plugin.c test. +# srcdir=@srcdir@ TOP_BUILDDIR=@top_builddir@ -- cgit v0.12