diff options
author | Mohamad Chaarawi <chaarawi@hdfgroup.org> | 2015-04-03 21:41:28 (GMT) |
---|---|---|
committer | Mohamad Chaarawi <chaarawi@hdfgroup.org> | 2015-04-03 21:41:28 (GMT) |
commit | 5630846ea34f29b45aecdb431f846327c4fde9e1 (patch) | |
tree | 83e65a0feb757f39472e70d2168048d091cfed50 /src/H5PL.c | |
parent | 820b4dc39136072bccad1455fc0232ec9e710d58 (diff) | |
parent | b9e5e2af4e31b0a60c2d2f6421fb1b3cb9aa0564 (diff) | |
download | hdf5-5630846ea34f29b45aecdb431f846327c4fde9e1.zip hdf5-5630846ea34f29b45aecdb431f846327c4fde9e1.tar.gz hdf5-5630846ea34f29b45aecdb431f846327c4fde9e1.tar.bz2 |
[svn-r26724] - merge from trunk & fix conflicts.
- fix bug in opending an already open named datatype.
- fix dynamically loaded VOL plugin support with new changes coming in.
Diffstat (limited to 'src/H5PL.c')
-rw-r--r-- | src/H5PL.c | 210 |
1 files changed, 134 insertions, 76 deletions
@@ -23,12 +23,12 @@ /***********/ /* Headers */ /***********/ -#include "H5private.h" /* Generic Functions */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5PLprivate.h" /* Plugin */ -#include "H5VLprivate.h" /* VOL */ -#include "H5Zprivate.h" /* Filter pipeline */ +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5PLprivate.h" /* Plugin */ +#include "H5VLprivate.h" /* VOL */ +#include "H5Zprivate.h" /* Filter pipeline */ /****************/ @@ -41,7 +41,19 @@ /* Macros for supporting * both Windows and Unix */ /****************************/ -/* Windows support */ +/* Windows support + * + * SPECIAL WINDOWS NOTE + * + * Some of the Win32 API functions expand to fooA or fooW depending on + * whether UNICODE or _UNICODE are defined. You MUST explicitly use + * the A version of the functions to force char * behavior until we + * work out a scheme for proper Windows Unicode support. + * + * If you do not do this, people will be unable to incorporate our + * source code into their own CMake builds if they define UNICODE. + */ + #ifdef H5_HAVE_WIN32_API #define H5PL_PATH_SEPARATOR ";" @@ -50,7 +62,7 @@ #define H5PL_HANDLE HINSTANCE /* Get a handle to a plugin library. Windows: TEXT macro handles Unicode strings */ -#define H5PL_OPEN_DLIB(S) LoadLibraryEx(TEXT(S), NULL, LOAD_WITH_ALTERED_SEARCH_PATH) +#define H5PL_OPEN_DLIB(S) LoadLibraryExA(S, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) /* Get the address of a symbol in dynamic library */ #define H5PL_GET_LIB_FUNC(H,N) GetProcAddress(H,N) @@ -86,6 +98,7 @@ typedef const void *(__cdecl *H5PL_get_plugin_info_t)(void); typedef const void *(*H5PL_get_plugin_info_t)(void); #endif /* H5_HAVE_WIN32_API */ +/* Whether to preload pathnames for plugin libraries */ #define H5PL_DEFAULT_PATH H5_DEFAULT_PLUGINDIR /* Special symbol to indicate no plugin loading */ @@ -97,10 +110,10 @@ typedef const void *(*H5PL_get_plugin_info_t)(void); /* 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 */ - const char *pl_name; /* name of the plugin */ - H5PL_HANDLE handle; /* plugin handle */ + H5PL_type_t pl_type; /* plugin type */ + int pl_id; /* ID for the plugin */ + const char *pl_name; /* name of the plugin */ + H5PL_HANDLE handle; /* plugin handle */ } H5PL_table_t; @@ -144,8 +157,8 @@ static char *H5PL_path_table_g[H5PL_MAX_PATH_NUM]; static size_t H5PL_num_paths_g = 0; static hbool_t H5PL_path_found_g = FALSE; -/* Whether to preload pathnames for plugin libraries */ -static hbool_t H5PL_no_plugin_g = FALSE; +/* Enable all plugin libraries */ +static unsigned int H5PL_plugin_g = H5PL_ALL_PLUGIN; /*-------------------------------------------------------------------------- @@ -172,7 +185,7 @@ H5PL__init_interface(void) if(NULL != (preload_path = HDgetenv("HDF5_PLUGIN_PRELOAD"))) { /* Special symbal "::" means no plugin during data reading. */ if(!HDstrcmp(preload_path, H5PL_NO_PLUGIN)) - H5PL_no_plugin_g = TRUE; + H5PL_plugin_g = 0; } /* end if */ FUNC_LEAVE_NOAPI(SUCCEED) @@ -180,46 +193,83 @@ H5PL__init_interface(void) /*------------------------------------------------------------------------- - * Function: H5PL_no_plugin + * Function: H5PLset_loading_state * - * Purpose: Quick way for filter module to query whether to load plugin + * Purpose: Control the loading of dynamic plugin types. * - * Return: TRUE: No plugin loading during data reading + * This function will not allow plugin types if the pathname from the HDF5_PLUGIN_PRELOAD + * environment variable is set to the special "::" string. * - * FALSE: Load plugin during data reading + * plugin bit = 0, will prevent the use of that dynamic plugin type. + * plugin bit = 1, will allow the use of that dynamic plugin type. * - * Programmer: Raymond Lu - * 20 February 2013 + * H5PL_TYPE_FILTER changes just dynamic filters + * A H5PL_ALL_PLUGIN will enable all dynamic plugin types + * A zero value will disable all dynamic plugin types + * + * Return: Non-negative or success * *------------------------------------------------------------------------- */ -htri_t -H5PL_no_plugin(void) +herr_t +H5PLset_loading_state(unsigned int plugin_type) { - htri_t ret_value; + char *preload_path; + herr_t ret_value = SUCCEED; /* Return value */ + FUNC_ENTER_API(FAIL) + H5TRACE1("e", "Iu", plugin_type); + /* change the bit value of the requested plugin type(s) */ + H5PL_plugin_g = plugin_type; + /* check if special ENV variable is set and disable all plugin types */ + if(NULL != (preload_path = HDgetenv("HDF5_PLUGIN_PRELOAD"))) { + /* Special symbol "::" means no plugin during data reading. */ + if(!HDstrcmp(preload_path, H5PL_NO_PLUGIN)) + H5PL_plugin_g = 0; + } +done: + FUNC_LEAVE_API(ret_value) +} /* end H5PLset_loading_state() */ - FUNC_ENTER_NOAPI(FAIL) - ret_value = (htri_t)H5PL_no_plugin_g; +/*------------------------------------------------------------------------- + * Function: H5PLget_loading_state + * + * Purpose: Query state of the loading of dynamic plugin types. + * + * This function will return the state of the global flag. + * + * Return: Zero if all plugin types are disabled, negative if all + * plugin types are enabled, positive if one or more of the plugin types are enabled. + * + *------------------------------------------------------------------------- + */ +herr_t +H5PLget_loading_state(unsigned int* plugin_type) +{ + herr_t ret_value = SUCCEED; /* Return value */ + FUNC_ENTER_API(FAIL) + + if(plugin_type) + *plugin_type = H5PL_plugin_g; + done: + FUNC_LEAVE_API(ret_value) +} /* end H5PLget_loading_state() */ -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5PL_no_plugin() */ /*------------------------------------------------------------------------- - * Function: H5PL_term_interface + * Function: H5PL_term_interface * - * 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. + * 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. * - * Return: Success: Positive if any action was taken that might - * affect some other interface; zero otherwise. + * Return: Success: Positive if any action was taken that might + * affect some other interface; zero otherwise. * - * Failure: Negative. + * Failure: Negative. * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 20 February 2013 * *------------------------------------------------------------------------- @@ -234,7 +284,7 @@ H5PL_term_interface(void) if(H5_interface_initialize_g) { size_t u; /* Local index variable */ - /* Close opened dynamic libraries */ + /* Close opened dynamic libraries */ for(u = 0; u < H5PL_filter_table_used_g; u++) H5PL__close((H5PL_filter_table_g[u]).handle); @@ -259,7 +309,7 @@ H5PL_term_interface(void) H5PL_num_paths_g = 0; H5PL_path_found_g = FALSE; - H5_interface_initialize_g = 0; + H5_interface_initialize_g = 0; i = 1; } /* end if */ @@ -268,15 +318,15 @@ H5PL_term_interface(void) /*------------------------------------------------------------------------- - * Function: H5PL_load + * Function: H5PL_load * * Purpose: Given the plugin type and identifier and/or name, this function * searches and/or loads a dynamic plugin library first among the * already opened libraries then in the designated location paths. * - * Return: Non-NULL on success/NULL on failure + * Return: Non-NULL on success/NULL on failure * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 13 February 2013 * *------------------------------------------------------------------------- @@ -290,9 +340,18 @@ H5PL_load(H5PL_type_t type, int id, const char *name) FUNC_ENTER_NOAPI(NULL) - /* Check for "no plugins" indicated" */ - if(H5PL_no_plugin_g) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin filter '%d' is not available", id) + switch (type) { + case H5PL_TYPE_FILTER: + if((H5PL_plugin_g & H5PL_FILTER_PLUGIN) == 0) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin filter '%d' is not available", id) + break; + case H5PL_TYPE_VOL: + if((H5PL_plugin_g & H5PL_VOL_PLUGIN) == 0) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin filter '%d' is not available", id) + break; + default: + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin '%d' is not valid", id) + } /* Initialize the location paths for dynamic libraries, if they aren't * already set up. @@ -331,13 +390,13 @@ done: /*------------------------------------------------------------------------- - * Function: H5PL__init_path_table + * Function: H5PL__init_path_table * - * Purpose: Initialize the path table. + * Purpose: Initialize the path table. * - * Return: Non-negative on success/Negative on failure + * Return: Non-negative on success/Negative on failure * - * Programmer: Quincey Koziol + * Programmer: Quincey Koziol * 18 March 2013 * *------------------------------------------------------------------------- @@ -386,18 +445,18 @@ done: /*------------------------------------------------------------------------- - * Function: H5PL__find + * Function: H5PL__find * * Purpose: Given a path, this function opens the directory and envokes * another function to go through all files to find the right * plugin library. Two function definitions are for Unix and * Windows. * - * Return: TRUE on success, + * Return: TRUE on success, * FALSE on not found, * negative on failure * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 13 February 2013 * *------------------------------------------------------------------------- @@ -474,17 +533,17 @@ done: static htri_t H5PL__find(H5PL_type_t plugin_type, int type_id, const char *plugin_name, char *dir, const void **info) { - WIN32_FIND_DATA fdFile; - HANDLE hFind; - char *pathname = NULL; - char service[2048]; - htri_t ret_value = FALSE; + WIN32_FIND_DATAA fdFile; + HANDLE hFind; + char *pathname = NULL; + char service[2048]; + htri_t ret_value = FALSE; FUNC_ENTER_STATIC /* Specify a file mask. *.* = We want everything! */ sprintf(service, "%s\\*.dll", dir); - if((hFind = FindFirstFile(service, &fdFile)) == INVALID_HANDLE_VALUE) + if((hFind = FindFirstFileA(service, &fdFile)) == INVALID_HANDLE_VALUE) HGOTO_ERROR(H5E_PLUGIN, H5E_OPENERROR, FAIL, "can't open directory") do { @@ -497,7 +556,7 @@ H5PL__find(H5PL_type_t plugin_type, int type_id, const char *plugin_name, char * /* Allocate & initialize the path name */ pathname_len = HDstrlen(dir) + HDstrlen(fdFile.cFileName) + 2; - if(NULL == (pathname = (char *)H5MM_malloc(pathname_len))) + if(NULL == (pathname = (char *)H5MM_malloc(pathname_len))) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") HDsnprintf(pathname, pathname_len, "%s\\%s", dir, fdFile.cFileName); @@ -512,10 +571,10 @@ H5PL__find(H5PL_type_t plugin_type, int type_id, const char *plugin_name, char * HGOTO_DONE(TRUE) } /* end if */ else - HDassert(pathname); + HDassert(pathname); pathname = (char *)H5MM_xfree(pathname); } /* end if */ - } while(FindNextFile(hFind, &fdFile)); /* Find the next file. */ + } while(FindNextFileA(hFind, &fdFile)); /* Find the next file. */ done: if(hFind) @@ -529,17 +588,17 @@ done: /*------------------------------------------------------------------------- - * Function: H5PL__open + * Function: H5PL__open * * Purpose: Iterates through all files to find the right plugin library. * It loads the dynamic plugin library and keeps it on the list - * of loaded libraries. + * of loaded libraries. * - * Return: TRUE on success, + * Return: TRUE on success, * FALSE on not found, * negative on failure * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 13 February 2013 * *------------------------------------------------------------------------- @@ -680,16 +739,16 @@ done: /*------------------------------------------------------------------------- - * Function: H5PL__search_table + * Function: H5PL__search_table * * 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, + * Return: TRUE on success, * FALSE on not found, * Negative on failure * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 13 February 2013 * *------------------------------------------------------------------------- @@ -711,12 +770,12 @@ H5PL__search_table(H5PL_type_t plugin_type, int type_id, const char *plugin_name const H5Z_class2_t *plugin_info; if(NULL == (get_plugin_info = (H5PL_get_plugin_info_t)H5PL_GET_LIB_FUNC((H5PL_filter_table_g[i]).handle, "H5PLget_plugin_info"))) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get function for H5PLget_plugin_info") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get function for H5PLget_plugin_info") - if(NULL == (plugin_info = (const H5Z_class2_t *)(*get_plugin_info)())) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get plugin info") + if(NULL == (plugin_info = (const H5Z_class2_t *)(*get_plugin_info)())) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get plugin info") - *info = plugin_info; + *info = plugin_info; HGOTO_DONE(TRUE) } /* end if */ } /* end for */ @@ -748,13 +807,13 @@ done: /*------------------------------------------------------------------------- - * Function: H5PL__close + * Function: H5PL__close * * Purpose: Closes the handle for dynamic library * - * Return: Non-negative on success/Negative on failure + * Return: Non-negative on success/Negative on failure * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 13 February 2013 * *------------------------------------------------------------------------- @@ -768,4 +827,3 @@ H5PL__close(H5PL_HANDLE handle) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5PL__close() */ - |