From 10ef22fcd6b8692fc5f34f58ca2b2b6394021e0d Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Thu, 30 Mar 2017 12:15:25 -0500 Subject: HDFFV-10143 Fix initial issues from review --- MANIFEST | 1 + src/CMakeLists.txt | 1 + src/H5PL.c | 137 +++++++++++++---------------------------------- src/H5PLpkg.h | 50 ++++++++++++++++++ test/plugin.c | 152 ++++++++++++++++++++++++++++++++--------------------- 5 files changed, 181 insertions(+), 160 deletions(-) create mode 100644 src/H5PLpkg.h diff --git a/MANIFEST b/MANIFEST index 3d252eb..9400fe3 100644 --- a/MANIFEST +++ b/MANIFEST @@ -800,6 +800,7 @@ ./src/H5PBprivate.h ./src/H5PL.c ./src/H5PLmodule.h +./src/H5PLpkg.h ./src/H5PLprivate.h ./src/H5PLpublic.h ./src/H5PLextern.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9321bbd..e2acd30 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -520,6 +520,7 @@ set (H5PL_SOURCES set (H5PL_HDRS ${HDF5_SRC_DIR}/H5PLextern.h + ${HDF5_SRC_DIR}/H5PLpkg.h ${HDF5_SRC_DIR}/H5PLpublic.h ) IDE_GENERATED_PROPERTIES ("H5PL" "${H5PL_HDRS}" "${H5PL_SOURCES}" ) diff --git a/src/H5PL.c b/src/H5PL.c index 898e84b..f6af691 100644 --- a/src/H5PL.c +++ b/src/H5PL.c @@ -25,15 +25,34 @@ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5MMprivate.h" /* Memory management */ -#include "H5PLprivate.h" /* Plugin */ +#include "H5PLpkg.h" /* Plugin */ #include "H5Zprivate.h" /* Filter pipeline */ /****************/ /* Local Macros */ /****************/ - -#define H5PL_MAX_PATH_NUM 16 +#ifdef H5_HAVE_WIN32_API +#define H5PL_EXPAND_ENV_VAR { \ + long bufCharCount; \ + char *tempbuf; \ + if(NULL == (tempbuf = (char *)H5MM_malloc(H5PL_EXPAND_BUFFER_SIZE))) \ + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for expanded path") \ + if((bufCharCount = ExpandEnvironmentStrings(dl_path, tempbuf, H5PL_EXPAND_BUFFER_SIZE)) > H5PL_EXPAND_BUFFER_SIZE) { \ + tempbuf = (char *)H5MM_xfree(tempbuf); \ + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "expanded path is too long") \ + } \ + if(bufCharCount == 0) { \ + tempbuf = (char *)H5MM_xfree(tempbuf); \ + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "failed to expand path") \ + } \ + dl_path = (char *)H5MM_xfree(dl_path); \ + dl_path = H5MM_strdup(tempbuf); \ + tempbuf = (char *)H5MM_xfree(tempbuf); \ + } +#else +#define H5PL_EXPAND_ENV_VAR +#endif /* H5_HAVE_WIN32_API */ /****************************/ /* Macros for supporting @@ -412,25 +431,9 @@ H5PLappend(char* plugin_path) dl_path = H5MM_strdup(plugin_path); if(NULL == dl_path) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") -#ifdef H5_HAVE_WIN32_API - else { /* Expand windows env var*/ - long bufCharCount; - char *tempbuf; - if(NULL == (tempbuf = (char *)H5MM_malloc(H5PL_EXPAND_BUFFER_SIZE))) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for expanded path") - if((bufCharCount = ExpandEnvironmentStrings(dl_path, tempbuf, H5PL_EXPAND_BUFFER_SIZE)) > H5PL_EXPAND_BUFFER_SIZE) { - tempbuf = (char *)H5MM_xfree(tempbuf); - HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "expanded path is too long") - } - if(bufCharCount == 0) { - tempbuf = (char *)H5MM_xfree(tempbuf); - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "failed to expand path") - } - dl_path = (char *)H5MM_xfree(dl_path); - dl_path = H5MM_strdup(tempbuf); - tempbuf = (char *)H5MM_xfree(tempbuf); - } -#endif /* H5_HAVE_WIN32_API */ + + H5PL_EXPAND_ENV_VAR + if(NULL == (H5PL_path_table_g[H5PL_num_paths_g] = H5MM_strdup(dl_path))) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") H5PL_num_paths_g++; @@ -467,25 +470,9 @@ H5PLprepend(char* plugin_path) dl_path = H5MM_strdup(plugin_path); if(NULL == dl_path) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") -#ifdef H5_HAVE_WIN32_API - else { /* Expand windows env var*/ - long bufCharCount; - char *tempbuf; - if (NULL == (tempbuf = (char *)H5MM_malloc(H5PL_EXPAND_BUFFER_SIZE))) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for expanded path") - if ((bufCharCount = ExpandEnvironmentStrings(dl_path, tempbuf, H5PL_EXPAND_BUFFER_SIZE)) > H5PL_EXPAND_BUFFER_SIZE) { - tempbuf = (char *)H5MM_xfree(tempbuf); - HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "expanded path is too long") - } - if (bufCharCount == 0) { - tempbuf = (char *)H5MM_xfree(tempbuf); - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "failed to expand path") - } - dl_path = (char *)H5MM_xfree(dl_path); - dl_path = H5MM_strdup(tempbuf); - tempbuf = (char *)H5MM_xfree(tempbuf); - } -#endif /* H5_HAVE_WIN32_API */ + + H5PL_EXPAND_ENV_VAR + for (plindex = (unsigned int)H5PL_num_paths_g; plindex > 0; plindex--) H5PL_path_table_g[plindex] = H5PL_path_table_g[plindex - 1]; if (NULL == (H5PL_path_table_g[0] = H5MM_strdup(dl_path))) @@ -521,25 +508,9 @@ H5PLput(char* plugin_path, unsigned int index) dl_path = H5MM_strdup(plugin_path); if(NULL == dl_path) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") -#ifdef H5_HAVE_WIN32_API - else { /* Expand windows env var*/ - long bufCharCount; - char *tempbuf; - if(NULL == (tempbuf = (char *)H5MM_malloc(H5PL_EXPAND_BUFFER_SIZE))) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for expanded path") - if((bufCharCount = ExpandEnvironmentStrings(dl_path, tempbuf, H5PL_EXPAND_BUFFER_SIZE)) > H5PL_EXPAND_BUFFER_SIZE) { - tempbuf = (char *)H5MM_xfree(tempbuf); - HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "expanded path is too long") - } - if(bufCharCount == 0) { - tempbuf = (char *)H5MM_xfree(tempbuf); - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "failed to expand path") - } - dl_path = (char *)H5MM_xfree(dl_path); - dl_path = H5MM_strdup(tempbuf); - tempbuf = (char *)H5MM_xfree(tempbuf); - } -#endif /* H5_HAVE_WIN32_API */ + + H5PL_EXPAND_ENV_VAR + if(H5PL_path_table_g[index]) H5PL_path_table_g[index] = (char *)H5MM_xfree(H5PL_path_table_g[index]); if(NULL == (H5PL_path_table_g[index] = H5MM_strdup(dl_path))) @@ -577,25 +548,9 @@ H5PLinsert(char* plugin_path, unsigned int index) dl_path = H5MM_strdup(plugin_path); if(NULL == dl_path) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") -#ifdef H5_HAVE_WIN32_API - else { /* Expand windows env var*/ - long bufCharCount; - char *tempbuf; - if(NULL == (tempbuf = (char *)H5MM_malloc(H5PL_EXPAND_BUFFER_SIZE))) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for expanded path") - if((bufCharCount = ExpandEnvironmentStrings(dl_path, tempbuf, H5PL_EXPAND_BUFFER_SIZE)) > H5PL_EXPAND_BUFFER_SIZE) { - tempbuf = (char *)H5MM_xfree(tempbuf); - HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "expanded path is too long") - } - if(bufCharCount == 0) { - tempbuf = (char *)H5MM_xfree(tempbuf); - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "failed to expand path") - } - dl_path = (char *)H5MM_xfree(dl_path); - dl_path = H5MM_strdup(tempbuf); - tempbuf = (char *)H5MM_xfree(tempbuf); - } -#endif /* H5_HAVE_WIN32_API */ + + H5PL_EXPAND_ENV_VAR + for(plindex = (unsigned int)H5PL_num_paths_g; plindex > index; plindex--) H5PL_path_table_g[plindex] = H5PL_path_table_g[plindex - 1]; if(NULL == (H5PL_path_table_g[index] = H5MM_strdup(dl_path))) @@ -662,9 +617,9 @@ H5PLget(unsigned int index) FUNC_ENTER_API(NULL) if(H5PL_num_paths_g == 0) - HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "no directories in table") + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, NULL, "no directories in table") if(NULL == (ret_value = H5PL_path_table_g[index])) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no directory path at index") + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, NULL, "no directory path at index") done: FUNC_LEAVE_API(ret_value) @@ -720,25 +675,7 @@ H5PL__init_path_table(void) if(NULL == dl_path) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") -#ifdef H5_HAVE_WIN32_API - else { /* Expand windows env var*/ - long bufCharCount; - char *tempbuf; - if(NULL == (tempbuf = (char *)H5MM_malloc(H5PL_EXPAND_BUFFER_SIZE))) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for expanded path") - if((bufCharCount = ExpandEnvironmentStrings(dl_path, tempbuf, H5PL_EXPAND_BUFFER_SIZE)) > H5PL_EXPAND_BUFFER_SIZE) { - tempbuf = (char *)H5MM_xfree(tempbuf); - HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "expanded path is too long") - } - if(bufCharCount == 0) { - tempbuf = (char *)H5MM_xfree(tempbuf); - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "failed to expand path") - } - dl_path = (char *)H5MM_xfree(dl_path); - dl_path = H5MM_strdup(tempbuf); - tempbuf = (char *)H5MM_xfree(tempbuf); - } -#endif /* H5_HAVE_WIN32_API */ + H5PL_EXPAND_ENV_VAR /* Put paths in the path table. They are separated by ":" */ dir = HDstrtok(dl_path, H5PL_PATH_SEPARATOR); diff --git a/src/H5PLpkg.h b/src/H5PLpkg.h new file mode 100644 index 0000000..2761a33 --- /dev/null +++ b/src/H5PLpkg.h @@ -0,0 +1,50 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * 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://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#if !(defined H5PL_FRIEND || defined H5PL_MODULE) +#error "Do not include this file outside the H5PL package!" +#endif + +#ifndef _H5PLpkg_H +#define _H5PLpkg_H + +/* Include private header file */ +#include "H5PLprivate.h" /* Filter functions */ + +/* Other private headers needed by this file */ + +/**************************/ +/* Package Private Macros */ +/**************************/ + + +/****************************/ +/* Package Private Typedefs */ +/****************************/ + +#define H5PL_MAX_PATH_NUM 16 + + +/*****************************/ +/* Package Private Variables */ +/*****************************/ + + +/******************************/ +/* Package Private Prototypes */ +/******************************/ + +#endif /* _H5PLpkg_H */ + diff --git a/test/plugin.c b/test/plugin.c index 1d55a5d..c739b72 100644 --- a/test/plugin.c +++ b/test/plugin.c @@ -22,8 +22,10 @@ #include "H5srcdir.h" /* - * This file needs to access private datatypes from the H5Z package. + * This file needs to access private datatypes from the H5Z and H5PL package. */ +#define H5PL_FRIEND +#include "H5PLpkg.h" #define H5Z_FRIEND #include "H5Zpkg.h" @@ -114,7 +116,7 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl) /* Check if all the filters are available */ if(H5Pall_filters_avail(dcpl)!=TRUE) { H5_FAILED(); - printf(" Line %d: Incorrect filter availability\n",__LINE__); + HDprintf(" Line %d: Incorrect filter availability\n",__LINE__); TEST_ERROR } /* end if */ @@ -137,8 +139,8 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl) for(j=0; j<(size_t)size[1]; j++) { if(0!=check[i][j]) { H5_FAILED(); - printf(" Read a non-zero value.\n"); - printf(" At index %lu,%lu\n", + HDprintf(" Read a non-zero value.\n"); + HDprintf(" At index %lu,%lu\n", (unsigned long)i, (unsigned long)j); TEST_ERROR } @@ -180,10 +182,10 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl) for(j=0; j 0; i--) { if (H5PLremove(i-1) < 0) { - fprintf(stderr," at %d: %s\n", i, pathname); + HDfprintf(stderr," at %d: %s\n", i, pathname); TEST_ERROR } } @@ -772,9 +774,9 @@ test_filter_path_apis(void) TESTING(" append"); /* Create multiple paths to fill table */ for (i=0; i < 16; i++) { - sprintf(pathname, "a_path_%d", i); + HDsprintf(pathname, "a_path_%d", i); if (H5PLappend(pathname) < 0) { - fprintf(stderr," at %d: %s\n", i, pathname); + HDfprintf(stderr," at %d: %s\n", i, pathname); TEST_ERROR } } @@ -785,11 +787,41 @@ test_filter_path_apis(void) TESTING(" append (exceed)"); /* Exceed the max path append */ H5E_BEGIN_TRY { - sprintf(pathname, "a_path_%d", 16); + HDsprintf(pathname, "a_path_%d", 16); ret = H5PLappend(pathname); } H5E_END_TRY if (ret >= 0) TEST_ERROR + + /* Exceed the max path removal */ + H5E_BEGIN_TRY { + ret = H5PLremove(16); + } H5E_END_TRY + if (ret >= 0) + TEST_ERROR + PASSED(); + + TESTING(" get (bounds)"); + HDsprintf(pathname, "%s", H5PLget(0)); + if (strcmp(pathname, "a_path_0") != 0) { + HDfprintf(stderr," get 0: %s\n", pathname); + TEST_ERROR + } + HDsprintf(pathname, "%s", H5PLget(1)); + if (strcmp(pathname, "a_path_1") != 0) { + HDfprintf(stderr," get 1: %s\n", pathname); + TEST_ERROR + } + HDsprintf(pathname, "%s", H5PLget(15)); + if (strcmp(pathname, "a_path_15") != 0) { + HDfprintf(stderr," get 15: %s\n", pathname); + TEST_ERROR + } + PASSED(); + + TESTING(" get (bounds exceed)"); + if (H5PLget(16) != NULL) + TEST_ERROR PASSED(); TESTING(" remove (verify for prepend)"); @@ -797,9 +829,9 @@ test_filter_path_apis(void) if (H5PLremove(8) < 0) TEST_ERROR /* Verify that the entries were moved */ - sprintf(pathname, "%s", H5PLget(8)); + HDsprintf(pathname, "%s", H5PLget(8)); if (strcmp(pathname, "a_path_9") != 0) { - fprintf(stderr," get 8: %s\n", pathname); + HDfprintf(stderr," get 8: %s\n", pathname); TEST_ERROR } PASSED(); @@ -809,9 +841,9 @@ test_filter_path_apis(void) TESTING(" prepend"); /* Prepend one path*/ - sprintf(pathname, "a_path_%d", 17); + HDsprintf(pathname, "a_path_%d", 17); if (H5PLprepend(pathname) < 0) { - fprintf(stderr," prepend 17: %s\n", pathname); + HDfprintf(stderr," prepend 17: %s\n", pathname); TEST_ERROR } @@ -819,14 +851,14 @@ test_filter_path_apis(void) if (H5PLsize() != 16) TEST_ERROR /* Verify that the entries were moved */ - sprintf(pathname, "%s", H5PLget(8)); + HDsprintf(pathname, "%s", H5PLget(8)); if (strcmp(pathname, "a_path_7") != 0) { - fprintf(stderr," get 8: %s\n", pathname); + HDfprintf(stderr," get 8: %s\n", pathname); TEST_ERROR } - sprintf(pathname, "%s", H5PLget(0)); + HDsprintf(pathname, "%s", H5PLget(0)); if (strcmp(pathname, "a_path_17") != 0) { - fprintf(stderr," get 0: %s\n", pathname); + HDfprintf(stderr," get 0: %s\n", pathname); TEST_ERROR } PASSED(); @@ -834,7 +866,7 @@ test_filter_path_apis(void) TESTING(" prepend (exceed)"); /* Exceed the max path prepend */ H5E_BEGIN_TRY { - sprintf(pathname, "a_path_%d", 18); + HDsprintf(pathname, "a_path_%d", 18); ret = H5PLprepend(pathname); } H5E_END_TRY if (ret >= 0) @@ -843,9 +875,9 @@ test_filter_path_apis(void) TESTING(" replace"); /* Replace one path*/ - sprintf(pathname, "a_path_%d", 20); + HDsprintf(pathname, "a_path_%d", 20); if (H5PLput(pathname, 1) < 0) { - fprintf(stderr," replace 1: %s\n", pathname); + HDfprintf(stderr," replace 1: %s\n", pathname); TEST_ERROR } @@ -853,14 +885,14 @@ test_filter_path_apis(void) if (H5PLsize() != 16) TEST_ERROR /* Verify that the entries were not moved */ - sprintf(pathname, "%s", H5PLget(0)); + HDsprintf(pathname, "%s", H5PLget(0)); if (strcmp(pathname, "a_path_17") != 0) { - fprintf(stderr," get 0: %s\n", pathname); + HDfprintf(stderr," get 0: %s\n", pathname); TEST_ERROR } - sprintf(pathname, "%s", H5PLget(2)); + HDsprintf(pathname, "%s", H5PLget(2)); if (strcmp(pathname, "a_path_1") != 0) { - fprintf(stderr," get 2: %s\n", pathname); + HDfprintf(stderr," get 2: %s\n", pathname); TEST_ERROR } PASSED(); @@ -870,9 +902,9 @@ test_filter_path_apis(void) if (H5PLremove(4) < 0) TEST_ERROR /* Verify that the entries were moved */ - sprintf(pathname, "%s", H5PLget(4)); + HDsprintf(pathname, "%s", H5PLget(4)); if (strcmp(pathname, "a_path_4") != 0) { - fprintf(stderr," get 4: %s\n", pathname); + HDfprintf(stderr," get 4: %s\n", pathname); TEST_ERROR } PASSED(); @@ -882,16 +914,16 @@ test_filter_path_apis(void) TESTING(" insert"); /* Insert one path*/ - sprintf(pathname, "a_path_%d", 21); + HDsprintf(pathname, "a_path_%d", 21); if (H5PLinsert(pathname, 3) < 0){ - fprintf(stderr," insert 3: %s\n", pathname); + HDfprintf(stderr," insert 3: %s\n", pathname); TEST_ERROR } /* Verify that the entries were moved */ - sprintf(pathname, "%s", H5PLget(4)); + HDsprintf(pathname, "%s", H5PLget(4)); if (strcmp(pathname, "a_path_2") != 0){ - fprintf(stderr," get 4: %s\n", pathname); + HDfprintf(stderr," get 4: %s\n", pathname); TEST_ERROR } PASSED(); @@ -902,7 +934,7 @@ test_filter_path_apis(void) TESTING(" insert (exceed)"); /* Exceed the max path insert */ H5E_BEGIN_TRY { - sprintf(pathname, "a_path_%d", 22); + HDsprintf(pathname, "a_path_%d", 22); ret = H5PLinsert(pathname, 12); } H5E_END_TRY if (ret >= 0) @@ -968,11 +1000,11 @@ main(void) /* Set the FAPL for the type of format */ if(new_format) { - puts("\nTesting with new file format:"); + HDputs("\nTesting with new file format:"); my_fapl = fapl2; } /* end if */ else { - puts("Testing with old file format:"); + HDputs("Testing with old file format:"); my_fapl = fapl; } /* end else */ @@ -997,7 +1029,7 @@ main(void) /* Restore the default error handler (set in h5_reset()) */ h5_restore_err(); - puts("\nTesting reading data with with dynamic plugin filters:"); + HDputs("\nTesting reading data with with dynamic plugin filters:"); /* Close the library so that all loaded plugin libraries are unloaded */ h5_reset(); @@ -1035,14 +1067,14 @@ main(void) if(nerrors) TEST_ERROR - printf("All plugin tests passed.\n"); + HDprintf("All plugin tests passed.\n"); h5_cleanup(FILENAME, fapl); return 0; error: nerrors = MAX(1, nerrors); - printf("***** %d PLUGIN TEST%s FAILED! *****\n", + HDprintf("***** %d PLUGIN TEST%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "S"); return 1; } -- cgit v0.12