From 3b1728736840e25d5cd1b048f09025e7c0f22123 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 17 Nov 2017 15:21:49 -0800 Subject: Brings H5Z and H5PL packages in sync with VOL integration branch. --- src/H5PLint.c | 62 +++-- src/H5PLpath.c | 4 +- src/H5PLpkg.h | 8 +- src/H5PLplugin_cache.c | 14 +- src/H5PLprivate.h | 7 +- src/H5PLpublic.h | 6 +- src/H5Z.c | 173 ++++++------ test/error_test.c | 416 ++++++++++++++--------------- test/testfiles/error_test_1 | 2 +- tools/test/h5dump/errfiles/filter_fail.err | 2 +- 10 files changed, 352 insertions(+), 342 deletions(-) diff --git a/src/H5PLint.c b/src/H5PLint.c index c887f86..b190746 100644 --- a/src/H5PLint.c +++ b/src/H5PLint.c @@ -235,11 +235,11 @@ done: *------------------------------------------------------------------------- */ const void * -H5PL_load(H5PL_type_t type, int id) +H5PL_load(H5PL_type_t type, H5PL_key_t key) { - H5PL_search_params_t search_params; + H5PL_search_params_t search_params; /* Plugin search parameters */ hbool_t found = FALSE; /* Whether the plugin was found */ - const void *plugin_info = NULL; + const void *plugin_info = NULL; /* Information from the plugin */ const void *ret_value = NULL; FUNC_ENTER_NOAPI(NULL) @@ -248,18 +248,17 @@ H5PL_load(H5PL_type_t type, int id) switch (type) { case H5PL_TYPE_FILTER: if ((H5PL_plugin_control_mask_g & H5PL_FILTER_PLUGIN) == 0) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin filter '%d' is not available", id) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "filter plugins disabled") break; - case H5PL_TYPE_ERROR: case H5PL_TYPE_NONE: default: - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin '%d' is not valid", id) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "Invalid plugin type specified") } /* Set up the search parameters */ search_params.type = type; - search_params.id = id; + search_params.key.id = key.id; /* Search in the table of already loaded plugin libraries */ if(H5PL__find_plugin_in_cache(&search_params, &found, &plugin_info) < 0) @@ -304,11 +303,11 @@ done: #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" herr_t -H5PL__open(const char *path, H5PL_type_t type, int id, hbool_t *success, const void **plugin_info) +H5PL__open(const char *path, H5PL_type_t type, H5PL_key_t key, hbool_t *success, const void **plugin_info) { H5PL_HANDLE handle = NULL; H5PL_get_plugin_info_t get_plugin_info = NULL; - htri_t ret_value = SUCCEED; + herr_t ret_value = SUCCEED; FUNC_ENTER_PACKAGE @@ -326,35 +325,46 @@ H5PL__open(const char *path, H5PL_type_t type, int id, hbool_t *success, const v */ if (NULL == (handle = H5PL_OPEN_DLIB(path))) { H5PL_CLR_ERROR; /* clear error */ - HGOTO_DONE(SUCCEED); + HGOTO_DONE(SUCCEED) } /* Return a handle for the function H5PLget_plugin_info in the dynamic library. * The plugin library is suppose to define this function. */ - if (NULL != (get_plugin_info = (H5PL_get_plugin_info_t)H5PL_GET_LIB_FUNC(handle, "H5PLget_plugin_info"))) { - - const H5Z_class2_t *info; + if (NULL == (get_plugin_info = (H5PL_get_plugin_info_t)H5PL_GET_LIB_FUNC(handle, "H5PLget_plugin_info"))) + HGOTO_DONE(SUCCEED) - /* Get the plugin info */ - if (NULL == (info = (const H5Z_class2_t *)(*get_plugin_info)())) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "can't get plugin info") + /* Get the plugin information */ + switch (type) { + case H5PL_TYPE_FILTER: + { + const H5Z_class2_t *filter_info; - /* Check if the filter IDs match */ - if (info->id == id) { + /* Get the plugin info */ + if (NULL == (filter_info = (const H5Z_class2_t *)(*get_plugin_info)())) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "can't get filter info from plugin") - /* Store the plugin in the cache */ - if (H5PL__add_plugin(type, id, handle)) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTINSERT, FAIL, "unable to add new plugin to plugin cache") + /* If the filter IDs match, we're done. Set the output parameters. */ + if (filter_info->id == key.id) { + *plugin_info = (const void *)filter_info; + *success = TRUE; + } - /* Set output parameters */ - *success = TRUE; - *plugin_info = (const void *)info; + break; } - } + case H5PL_TYPE_ERROR: + case H5PL_TYPE_NONE: + default: + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "Invalid plugin type specified") + } /* end switch */ + + /* If we found the correct plugin, store it in the cache */ + if (*success) + if (H5PL__add_plugin(type, key, handle)) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTINSERT, FAIL, "unable to add new plugin to plugin cache") done: - if (!success && handle) + if (!(*success) && handle) if (H5PL__close(handle) < 0) HDONE_ERROR(H5E_PLUGIN, H5E_CLOSEERROR, FAIL, "can't close dynamic library") diff --git a/src/H5PLpath.c b/src/H5PLpath.c index 435802a..d8e82f8 100644 --- a/src/H5PLpath.c +++ b/src/H5PLpath.c @@ -689,7 +689,7 @@ H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *fo continue; /* attempt to open the dynamic library as a filter library */ - if (H5PL__open(path, search_params->type, search_params->id, found, plugin_info) < 0) + if (H5PL__open(path, search_params->type, search_params->key, found, plugin_info) < 0) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "search in directory failed") if (*found) HGOTO_DONE(SUCCEED) @@ -755,7 +755,7 @@ H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *fo continue; /* attempt to open the dynamic library as a filter library */ - if (H5PL__open(path, search_params->type, search_params->id, found, plugin_info) < 0) + if (H5PL__open(path, search_params->type, search_params->search_key.id, found, plugin_info) < 0) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "search in directory failed") if (*found) HGOTO_DONE(SUCCEED) diff --git a/src/H5PLpkg.h b/src/H5PLpkg.h index 0d1c271..dfaa4af 100644 --- a/src/H5PLpkg.h +++ b/src/H5PLpkg.h @@ -115,8 +115,8 @@ /* Data used to search for plugins */ typedef struct H5PL_search_params_t { - H5PL_type_t type; - int id; + H5PL_type_t type; + H5PL_key_t key; } H5PL_search_params_t; @@ -134,13 +134,13 @@ H5_DLL herr_t H5PL__get_plugin_control_mask(unsigned int *mask /*out*/); H5_DLL herr_t H5PL__set_plugin_control_mask(unsigned int mask); /* Plugin search and manipulation */ -H5_DLL herr_t H5PL__open(const char *libname, H5PL_type_t type, int id, hbool_t *success /*out*/, const void **plugin_info /*out*/); +H5_DLL herr_t H5PL__open(const char *libname, H5PL_type_t type, H5PL_key_t key, hbool_t *success /*out*/, const void **plugin_info /*out*/); H5_DLL herr_t H5PL__close(H5PL_HANDLE handle); /* Plugin cache calls */ H5_DLL herr_t H5PL__create_plugin_cache(void); H5_DLL herr_t H5PL__close_plugin_cache(hbool_t *already_closed /*out*/); -H5_DLL herr_t H5PL__add_plugin(H5PL_type_t type, int id, H5PL_HANDLE handle); +H5_DLL herr_t H5PL__add_plugin(H5PL_type_t type, H5PL_key_t key, H5PL_HANDLE handle); H5_DLL herr_t H5PL__find_plugin_in_cache(const H5PL_search_params_t *search_params, hbool_t *found /*out*/, const void **plugin_info /*out*/); /* Plugin search path calls */ diff --git a/src/H5PLplugin_cache.c b/src/H5PLplugin_cache.c index e483e01..e905ac2 100644 --- a/src/H5PLplugin_cache.c +++ b/src/H5PLplugin_cache.c @@ -56,9 +56,9 @@ /* Type for the list of info for opened plugin libraries */ typedef struct H5PL_plugin_t { - H5PL_type_t type; /* Plugin type */ - int id; /* ID for the plugin */ - H5PL_HANDLE handle; /* Plugin handle */ + H5PL_type_t type; /* Plugin type */ + H5PL_key_t key; /* Unique key to identify the plugin */ + H5PL_HANDLE handle; /* Plugin handle */ } H5PL_plugin_t; @@ -209,14 +209,14 @@ done: /*------------------------------------------------------------------------- * Function: H5PL__add_plugin * - * Purpose: Add a plugin to the plugin cached. + * Purpose: Add a plugin to the plugin cache. * * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ herr_t -H5PL__add_plugin(H5PL_type_t type, int id, H5PL_HANDLE handle) +H5PL__add_plugin(H5PL_type_t type, H5PL_key_t key, H5PL_HANDLE handle) { herr_t ret_value = SUCCEED; @@ -229,7 +229,7 @@ H5PL__add_plugin(H5PL_type_t type, int id, H5PL_HANDLE handle) /* Store the plugin info and bump the # of plugins */ H5PL_cache_g[H5PL_num_plugins_g].type = type; - H5PL_cache_g[H5PL_num_plugins_g].id = id; + H5PL_cache_g[H5PL_num_plugins_g].key = key; H5PL_cache_g[H5PL_num_plugins_g].handle = handle; H5PL_num_plugins_g++; @@ -276,7 +276,7 @@ H5PL__find_plugin_in_cache(const H5PL_search_params_t *search_params, hbool_t *f for (u = 0; u < H5PL_num_plugins_g; u++) { /* If the plugin type (filter, etc.) and ID match, query the plugin for its info */ - if ((search_params->type == (H5PL_cache_g[u]).type) && (search_params->id == (H5PL_cache_g[u]).id)) { + if ((search_params->type == (H5PL_cache_g[u]).type) && (search_params->key.id == (H5PL_cache_g[u]).key.id)) { H5PL_get_plugin_info_t get_plugin_info_function; const H5Z_class2_t *filter_info; diff --git a/src/H5PLprivate.h b/src/H5PLprivate.h index bc12e64..cc2e258 100644 --- a/src/H5PLprivate.h +++ b/src/H5PLprivate.h @@ -33,6 +33,11 @@ /* Library Private Typedefs */ /****************************/ +/* The key that will be used to find the plugin */ +typedef union H5PL_key_t { + int id; /* filters */ +} H5PL_key_t; + /*****************************/ /* Library-private Variables */ @@ -44,7 +49,7 @@ /***************************************/ /* Internal API routines */ -H5_DLL const void *H5PL_load(H5PL_type_t plugin_type, int type_id); +H5_DLL const void *H5PL_load(H5PL_type_t plugin_type, H5PL_key_t key); #endif /* _H5PLprivate_H */ diff --git a/src/H5PLpublic.h b/src/H5PLpublic.h index 3b36ccd..fe5bdfb 100644 --- a/src/H5PLpublic.h +++ b/src/H5PLpublic.h @@ -30,9 +30,9 @@ /* Plugin type used by the plugin library */ typedef enum H5PL_type_t { - H5PL_TYPE_ERROR = -1, /* Error */ - H5PL_TYPE_FILTER = 0, /* Filter */ - H5PL_TYPE_NONE = 1 /* This must be last! */ + H5PL_TYPE_ERROR = -1, /* Error */ + H5PL_TYPE_FILTER = 0, /* Filter */ + H5PL_TYPE_NONE = 1 /* This must be last! */ } H5PL_type_t; /* Common dynamic plugin type flags used by the set/get_loading_state functions */ diff --git a/src/H5Z.c b/src/H5Z.c index a9f7336..1e7cd79 100644 --- a/src/H5Z.c +++ b/src/H5Z.c @@ -86,24 +86,24 @@ H5Z__init_package(void) FUNC_ENTER_PACKAGE /* Internal filters */ - if (H5Z_register (H5Z_SHUFFLE) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register shuffle filter") - if (H5Z_register (H5Z_FLETCHER32) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register fletcher32 filter") - if (H5Z_register (H5Z_NBIT) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register nbit filter") - if (H5Z_register (H5Z_SCALEOFFSET) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register scaleoffset filter") + if (H5Z_register(H5Z_SHUFFLE) < 0) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register shuffle filter") + if (H5Z_register(H5Z_FLETCHER32) < 0) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register fletcher32 filter") + if (H5Z_register(H5Z_NBIT) < 0) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register nbit filter") + if (H5Z_register(H5Z_SCALEOFFSET) < 0) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register scaleoffset filter") /* External filters */ #ifdef H5_HAVE_FILTER_DEFLATE - if (H5Z_register (H5Z_DEFLATE) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register deflate filter") + if (H5Z_register(H5Z_DEFLATE) < 0) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register deflate filter") #endif /* H5_HAVE_FILTER_DEFLATE */ #ifdef H5_HAVE_FILTER_SZIP H5Z_SZIP->encoder_present = SZ_encoder_enabled(); - if (H5Z_register (H5Z_SZIP) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register szip filter") + if (H5Z_register(H5Z_SZIP) < 0) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register szip filter") #endif /* H5_HAVE_FILTER_SZIP */ done: @@ -180,7 +180,7 @@ H5Z_term_package(void) } /* end if */ #endif /* H5Z_DEBUG */ /* Free the table of filters */ - if(H5Z_table_g) { + if (H5Z_table_g) { H5Z_table_g = (H5Z_class2_t *)H5MM_xfree(H5Z_table_g); #ifdef H5Z_DEBUG H5Z_stat_table_g = (H5Z_stats_t *)H5MM_xfree(H5Z_stat_table_g); @@ -191,7 +191,7 @@ H5Z_term_package(void) } /* end if */ /* Mark interface as closed */ - if(0 == n) + if (0 == n) H5_PKG_INIT_VAR = FALSE; } /* end if */ @@ -219,7 +219,7 @@ H5Zregister(const void *cls) /* Check args */ if (cls_real==NULL) - HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid filter class") + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid filter class") /* Check H5Z_class_t version number; this is where a function to convert * from an outdated version should be called. @@ -251,20 +251,20 @@ H5Zregister(const void *cls) #else /* H5_NO_DEPRECATED_SYMBOLS */ /* Deprecated symbols not allowed, throw an error */ - HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid H5Z_class_t version number"); + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid H5Z_class_t version number"); #endif /* H5_NO_DEPRECATED_SYMBOLS */ } /* end if */ if (cls_real->id < 0 || cls_real->id > H5Z_FILTER_MAX) - HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid filter identification number") + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid filter identification number") if (cls_real->id < H5Z_FILTER_RESERVED) - HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "unable to modify predefined filters") + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to modify predefined filters") if (cls_real->filter == NULL) - HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "no filter function specified") + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no filter function specified") /* Do it */ - if (H5Z_register (cls_real) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register filter") + if (H5Z_register(cls_real) < 0) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register filter") done: FUNC_LEAVE_API(ret_value) @@ -289,8 +289,8 @@ H5Z_register (const H5Z_class2_t *cls) FUNC_ENTER_NOAPI(FAIL) - HDassert (cls); - HDassert (cls->id >= 0 && cls->id <= H5Z_FILTER_MAX); + HDassert(cls); + HDassert(cls->id >= 0 && cls->id <= H5Z_FILTER_MAX); /* Is the filter already registered? */ for (i = 0; i < H5Z_table_used_g; i++) @@ -306,11 +306,11 @@ H5Z_register (const H5Z_class2_t *cls) H5Z_stats_t *stat_table = (H5Z_stats_t *)H5MM_realloc(H5Z_stat_table_g, n * sizeof(H5Z_stats_t)); #endif /* H5Z_DEBUG */ if (!table) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to extend filter table") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to extend filter table") H5Z_table_g = table; #ifdef H5Z_DEBUG if (!stat_table) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to extend filter statistics table") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to extend filter statistics table") H5Z_stat_table_g = stat_table; #endif /* H5Z_DEBUG */ H5Z_table_alloc_g = n; @@ -318,15 +318,15 @@ H5Z_register (const H5Z_class2_t *cls) /* Initialize */ i = H5Z_table_used_g++; - HDmemcpy (H5Z_table_g+i, cls, sizeof(H5Z_class2_t)); + HDmemcpy(H5Z_table_g+i, cls, sizeof(H5Z_class2_t)); #ifdef H5Z_DEBUG - HDmemset (H5Z_stat_table_g+i, 0, sizeof(H5Z_stats_t)); + HDmemset(H5Z_stat_table_g+i, 0, sizeof(H5Z_stats_t)); #endif /* H5Z_DEBUG */ } /* end if */ /* Filter already registered */ else { /* Replace old contents */ - HDmemcpy (H5Z_table_g+i, cls, sizeof(H5Z_class2_t)); + HDmemcpy(H5Z_table_g+i, cls, sizeof(H5Z_class2_t)); } /* end else */ done: @@ -420,9 +420,9 @@ H5Z_unregister(H5Z_filter_t filter_id) /* Remove filter from table */ /* Don't worry about shrinking table size (for now) */ - HDmemmove (&H5Z_table_g[filter_index], &H5Z_table_g[filter_index+1], sizeof(H5Z_class2_t)*((H5Z_table_used_g-1)-filter_index)); + HDmemmove(&H5Z_table_g[filter_index], &H5Z_table_g[filter_index+1], sizeof(H5Z_class2_t)*((H5Z_table_used_g-1)-filter_index)); #ifdef H5Z_DEBUG - HDmemmove (&H5Z_stat_table_g[filter_index], &H5Z_stat_table_g[filter_index+1], sizeof(H5Z_stats_t)*((H5Z_table_used_g-1)-filter_index)); + HDmemmove(&H5Z_stat_table_g[filter_index], &H5Z_stat_table_g[filter_index+1], sizeof(H5Z_stats_t)*((H5Z_table_used_g-1)-filter_index)); #endif /* H5Z_DEBUG */ H5Z_table_used_g--; @@ -450,11 +450,11 @@ H5Z__check_unregister(hid_t ocpl_id, H5Z_filter_t filter_id) /* Get the plist structure of object creation */ if (NULL == (plist = H5P_object_verify(ocpl_id, H5P_OBJECT_CREATE))) - HGOTO_ERROR (H5E_PLINE, H5E_BADATOM, FAIL, "can't find object for ID") + HGOTO_ERROR(H5E_PLINE, H5E_BADATOM, FAIL, "can't find object for ID") /* Check if the object creation property list uses the filter */ if ((ret_value = H5P_filter_in_pline(plist, filter_id)) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTGET, FAIL, "can't check filter in pipeline") + HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't check filter in pipeline") done: FUNC_LEAVE_NOAPI(ret_value) @@ -487,11 +487,11 @@ H5Z__check_unregister_group_cb(void *obj_ptr, hid_t H5_ATTR_UNUSED obj_id, void /* Get the group creation property */ if ((ocpl_id = H5G_get_create_plist((H5G_t *)obj_ptr)) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTGET, FAIL, "can't get group creation property list") + HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't get group creation property list") /* Check if the filter is in the group creation property list */ if ((filter_in_pline = H5Z__check_unregister(ocpl_id, object->filter_id)) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTGET, FAIL, "can't check filter in pipeline") + HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't check filter in pipeline") /* H5I_iterate expects TRUE to stop the loop over objects. Stop the loop and * let H5Z_unregister return failure. @@ -504,7 +504,7 @@ H5Z__check_unregister_group_cb(void *obj_ptr, hid_t H5_ATTR_UNUSED obj_id, void done: if (ocpl_id > 0) if (H5I_dec_app_ref(ocpl_id) < 0) - HDONE_ERROR (H5E_PLINE, H5E_CANTDEC, FAIL, "can't release plist") + HDONE_ERROR(H5E_PLINE, H5E_CANTDEC, FAIL, "can't release plist") FUNC_LEAVE_NOAPI(ret_value) } /* end H5Z__check_unregister_group_cb() */ @@ -536,11 +536,11 @@ H5Z__check_unregister_dset_cb(void *obj_ptr, hid_t H5_ATTR_UNUSED obj_id, void * /* Get the dataset creation property */ if ((ocpl_id = H5D_get_create_plist((H5D_t *)obj_ptr)) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTGET, FAIL, "can't get dataset creation property list") + HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't get dataset creation property list") /* Check if the filter is in the dataset creation property list */ if ((filter_in_pline = H5Z__check_unregister(ocpl_id, object->filter_id)) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTGET, FAIL, "can't check filter in pipeline") + HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't check filter in pipeline") /* H5I_iterate expects TRUE to stop the loop over objects. Stop the loop and * let H5Z_unregister return failure. @@ -553,7 +553,7 @@ H5Z__check_unregister_dset_cb(void *obj_ptr, hid_t H5_ATTR_UNUSED obj_id, void * done: if (ocpl_id > 0) if (H5I_dec_app_ref(ocpl_id) < 0) - HDONE_ERROR (H5E_PLINE, H5E_CANTDEC, FAIL, "can't release plist") + HDONE_ERROR(H5E_PLINE, H5E_CANTDEC, FAIL, "can't release plist") FUNC_LEAVE_NOAPI(ret_value) } /* end H5Z__check_unregister_dset_cb() */ @@ -582,7 +582,7 @@ H5Z__flush_file_cb(void *obj_ptr, hid_t H5_ATTR_UNUSED obj_id, void H5_ATTR_UNUS * if the file is opened for write */ if (H5F_ACC_RDWR & H5F_INTENT((H5F_t *)obj_ptr)) { if (H5F_flush_mounts((H5F_t *)obj_ptr, H5AC_ind_read_dxpl_id, H5AC_rawdata_dxpl_id) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTFLUSH, FAIL, "unable to flush file hierarchy") + HGOTO_ERROR(H5E_PLINE, H5E_CANTFLUSH, FAIL, "unable to flush file hierarchy") } /* end if */ done: @@ -608,10 +608,10 @@ H5Zfilter_avail(H5Z_filter_t id) /* Check args */ if (id < 0 || id > H5Z_FILTER_MAX) - HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid filter identification number") + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid filter identification number") if ((ret_value = H5Z_filter_avail(id)) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_NOTFOUND, FAIL, "unable to check the availability of the filter") + HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "unable to check the availability of the filter") done: FUNC_LEAVE_API(ret_value) @@ -629,22 +629,25 @@ done: htri_t H5Z_filter_avail(H5Z_filter_t id) { - size_t i; /* Local index variable */ - H5Z_class2_t *filter_info; - htri_t ret_value = FALSE; /* Return value */ + H5PL_key_t key; /* Key for finding a plugin */ + const H5Z_class2_t *filter_info; /* Filter information */ + size_t i; /* Local index variable */ + htri_t ret_value = FALSE; /* Return value */ FUNC_ENTER_NOAPI(FAIL) /* Is the filter already registered? */ for (i = 0; i < H5Z_table_used_g; i++) if (H5Z_table_g[i].id == id) - HGOTO_DONE (TRUE) + HGOTO_DONE(TRUE) - if (NULL != (filter_info = (const H5Z_class2_t *)H5PL_load(H5PL_TYPE_FILTER, (int)id))) { - if (H5Z_register (filter_info) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register loaded filter") - HGOTO_DONE (TRUE) + key.id = (int)id; + if (NULL != (filter_info = (const H5Z_class2_t *)H5PL_load(H5PL_TYPE_FILTER, key))) { + if (H5Z_register(filter_info) < 0) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register loaded filter") + HGOTO_DONE(TRUE) } + done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5Z_filter_avail() */ @@ -683,7 +686,7 @@ H5Z_prelude_callback(const H5O_pline_t *pline, hid_t dcpl_id, hid_t type_id, if (pline->filter[u].flags & H5Z_FLAG_OPTIONAL) H5E_clear_stack (NULL); else - HGOTO_ERROR (H5E_PLINE, H5E_NOTFOUND, FAIL, "required filter was not located") + HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "required filter was not located") } /* end if */ else { /* Make correct callback */ @@ -691,7 +694,7 @@ H5Z_prelude_callback(const H5O_pline_t *pline, hid_t dcpl_id, hid_t type_id, case H5Z_PRELUDE_CAN_APPLY: /* Check if filter is configured to be able to encode */ if (!fclass->encoder_present) - HGOTO_ERROR (H5E_PLINE, H5E_NOENCODER, FAIL, "Filter present but encoding is disabled."); + HGOTO_ERROR(H5E_PLINE, H5E_NOENCODER, FAIL, "Filter present but encoding is disabled."); /* Check if there is a "can apply" callback */ @@ -716,7 +719,7 @@ H5Z_prelude_callback(const H5O_pline_t *pline, hid_t dcpl_id, hid_t type_id, /* Make callback to filter's "set local" function */ if ((fclass->set_local)(dcpl_id, type_id, space_id) < 0) /* Indicate error during filter callback */ - HGOTO_ERROR (H5E_PLINE, H5E_SETLOCAL, FAIL, "error during user callback") + HGOTO_ERROR(H5E_PLINE, H5E_SETLOCAL, FAIL, "error during user callback") } /* end if */ break; @@ -753,8 +756,8 @@ H5Z_prepare_prelude_callback_dcpl(hid_t dcpl_id, hid_t type_id, H5Z_prelude_type FUNC_ENTER_NOAPI_NOINIT - HDassert (H5I_GENPROP_LST == H5I_get_type(dcpl_id)); - HDassert (H5I_DATATYPE == H5I_get_type(type_id)); + HDassert(H5I_GENPROP_LST == H5I_get_type(dcpl_id)); + HDassert(H5I_DATATYPE == H5I_get_type(type_id)); /* Check if the property list is non-default */ if (dcpl_id != H5P_DATASET_CREATE_DEFAULT) { @@ -834,7 +837,7 @@ H5Z_can_apply(hid_t dcpl_id, hid_t type_id) /* Make "can apply" callbacks for filters in pipeline */ if (H5Z_prepare_prelude_callback_dcpl(dcpl_id, type_id, H5Z_PRELUDE_CAN_APPLY) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANAPPLY, FAIL, "unable to apply filter") + HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "unable to apply filter") done: FUNC_LEAVE_NOAPI(ret_value) @@ -865,7 +868,7 @@ H5Z_set_local(hid_t dcpl_id, hid_t type_id) /* Make "set local" callbacks for filters in pipeline */ if (H5Z_prepare_prelude_callback_dcpl(dcpl_id, type_id, H5Z_PRELUDE_SET_LOCAL) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_SETLOCAL, FAIL, "local filter parameters not set") + HGOTO_ERROR(H5E_PLINE, H5E_SETLOCAL, FAIL, "local filter parameters not set") done: FUNC_LEAVE_NOAPI(ret_value) @@ -894,7 +897,7 @@ H5Z_can_apply_direct(const H5O_pline_t *pline) /* Make "can apply" callbacks for filters in pipeline */ if (H5Z_prelude_callback(pline, (hid_t)-1, (hid_t)-1, (hid_t)-1, H5Z_PRELUDE_CAN_APPLY) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANAPPLY, FAIL, "unable to apply filter") + HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "unable to apply filter") done: FUNC_LEAVE_NOAPI(ret_value) @@ -927,7 +930,7 @@ H5Z_set_local_direct(const H5O_pline_t *pline) /* Make "set local" callbacks for filters in pipeline */ if (H5Z_prelude_callback(pline, (hid_t)-1, (hid_t)-1, (hid_t)-1, H5Z_PRELUDE_SET_LOCAL) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_SETLOCAL, FAIL, "local filter parameters not set") + HGOTO_ERROR(H5E_PLINE, H5E_SETLOCAL, FAIL, "local filter parameters not set") done: FUNC_LEAVE_NOAPI(ret_value) @@ -952,10 +955,10 @@ H5Z_modify(const H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags, FUNC_ENTER_NOAPI(FAIL) - HDassert (pline); - HDassert (filter >= 0 && filter <= H5Z_FILTER_MAX); - HDassert (0 == (flags & ~((unsigned)H5Z_FLAG_DEFMASK))); - HDassert (0 == cd_nelmts || cd_values); + HDassert(pline); + HDassert(filter >= 0 && filter <= H5Z_FILTER_MAX); + HDassert(0 == (flags & ~((unsigned)H5Z_FLAG_DEFMASK))); + HDassert(0 == cd_nelmts || cd_values); /* Locate the filter in the pipeline */ for (idx = 0; idx < pline->nused; idx++) @@ -964,7 +967,7 @@ H5Z_modify(const H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags, /* Check if the filter was not already in the pipeline */ if (idx > pline->nused) - HGOTO_ERROR (H5E_PLINE, H5E_NOTFOUND, FAIL, "filter not in pipeline") + HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "filter not in pipeline") /* Change parameters for filter */ pline->filter[idx].flags = flags; @@ -982,7 +985,7 @@ H5Z_modify(const H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags, if (cd_nelmts > H5Z_COMMON_CD_VALUES) { pline->filter[idx].cd_values = (unsigned *)H5MM_malloc(cd_nelmts * sizeof(unsigned)); if (NULL == pline->filter[idx].cd_values) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter parameters") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter parameters") } /* end if */ else pline->filter[idx].cd_values = pline->filter[idx]._cd_values; @@ -1017,10 +1020,10 @@ H5Z_append(H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags, FUNC_ENTER_NOAPI(FAIL) - HDassert (pline); - HDassert (filter >= 0 && filter <= H5Z_FILTER_MAX); - HDassert (0 == (flags & ~((unsigned)H5Z_FLAG_DEFMASK))); - HDassert (0 == cd_nelmts || cd_values); + HDassert(pline); + HDassert(filter >= 0 && filter <= H5Z_FILTER_MAX); + HDassert(0 == (flags & ~((unsigned)H5Z_FLAG_DEFMASK))); + HDassert(0 == cd_nelmts || cd_values); /* * Check filter limit. We do it here for early warnings although we may @@ -1052,13 +1055,13 @@ H5Z_append(H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags, x.nalloc = MAX(H5Z_MAX_NFILTERS, 2 * pline->nalloc); x.filter = (H5Z_filter_info_t *)H5MM_realloc(pline->filter, x.nalloc * sizeof(x.filter[0])); if (NULL == x.filter) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter pipeline") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter pipeline") /* Fix pointers in previous filters that need to point to their own * internal data. */ - for(n = 0; n < pline->nalloc; ++n) - if(x.filter[n].cd_values == (void *) ~((size_t) NULL)) + for (n = 0; n < pline->nalloc; ++n) + if (x.filter[n].cd_values == (void *) ~((size_t) NULL)) x.filter[n].cd_values = x.filter[n]._cd_values; /* Point to newly allocated buffer */ @@ -1079,7 +1082,7 @@ H5Z_append(H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags, if (cd_nelmts > H5Z_COMMON_CD_VALUES) { pline->filter[idx].cd_values = (unsigned *)H5MM_malloc(cd_nelmts * sizeof(unsigned)); if (NULL == pline->filter[idx].cd_values) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter") } /* end if */ else pline->filter[idx].cd_values = pline->filter[idx]._cd_values; @@ -1118,7 +1121,7 @@ H5Z_find_idx(H5Z_filter_t id) for (i = 0; i < H5Z_table_used_g; i++) if (H5Z_table_g[i].id == id) - HGOTO_DONE ((int)i) + HGOTO_DONE((int)i) done: FUNC_LEAVE_NOAPI(ret_value) @@ -1145,10 +1148,10 @@ H5Z_find(H5Z_filter_t id) /* Get the index in the global table */ if ((idx = H5Z_find_idx(id)) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_NOTFOUND, NULL, "required filter %d is not registered", id) + HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, NULL, "required filter %d is not registered", id) /* Set return value */ - ret_value = H5Z_table_g+idx; + ret_value = H5Z_table_g + idx; done: FUNC_LEAVE_NOAPI(ret_value) @@ -1219,13 +1222,15 @@ H5Z_pipeline(const H5O_pline_t *pline, unsigned flags, */ if ((fclass_idx = H5Z_find_idx(pline->filter[idx].id)) < 0) { hbool_t issue_error = FALSE; + H5PL_key_t key; const H5Z_class2_t *filter_info; /* Try loading the filter */ - if (NULL != (filter_info = (const H5Z_class2_t *)H5PL_load(H5PL_TYPE_FILTER, (int)(pline->filter[idx].id)))) { + key.id = (int)(pline->filter[idx].id); + if(NULL != (filter_info = (const H5Z_class2_t *)H5PL_load(H5PL_TYPE_FILTER, key))) { /* Register the filter we loaded */ - if (H5Z_register(filter_info) < 0) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register filter") + if(H5Z_register(filter_info) < 0) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register filter") /* Search in the table of registered filters again to find the dynamic filter just loaded and registered */ if ((fclass_idx = H5Z_find_idx(pline->filter[idx].id)) < 0) @@ -1263,7 +1268,7 @@ H5Z_pipeline(const H5O_pline_t *pline, unsigned flags, if (0 == new_nbytes) { if ((cb_struct.func && (H5Z_CB_FAIL == cb_struct.func (pline->filter[idx].id, *buf, *buf_size, cb_struct.op_data))) || !cb_struct.func) - HGOTO_ERROR (H5E_PLINE, H5E_READERROR, FAIL, "filter returned failure during read") + HGOTO_ERROR(H5E_PLINE, H5E_READERROR, FAIL, "filter returned failure during read") *nbytes = *buf_size; failed |= (unsigned)1 << idx; @@ -1303,7 +1308,7 @@ H5Z_pipeline(const H5O_pline_t *pline, unsigned flags, if (0 == new_nbytes) { if (0 == (pline->filter[idx].flags & H5Z_FLAG_OPTIONAL)) { if ((cb_struct.func && (H5Z_CB_FAIL == cb_struct.func (pline->filter[idx].id, *buf, *nbytes, cb_struct.op_data))) || !cb_struct.func) - HGOTO_ERROR (H5E_PLINE, H5E_WRITEERROR, FAIL, "filter returned failure") + HGOTO_ERROR(H5E_PLINE, H5E_WRITEERROR, FAIL, "filter returned failure") *nbytes = *buf_size; } @@ -1350,7 +1355,7 @@ H5Z_filter_info(const H5O_pline_t *pline, H5Z_filter_t filter) /* Check if the filter was not already in the pipeline */ if (idx >= pline->nused) - HGOTO_ERROR (H5E_PLINE, H5E_NOTFOUND, NULL, "filter not in pipeline") + HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, NULL, "filter not in pipeline") /* Set return value */ ret_value = &pline->filter[idx]; @@ -1427,7 +1432,7 @@ H5Z_all_filters_avail(const H5O_pline_t *pline) /* Check if we didn't find the filter */ if (j == H5Z_table_used_g) - HGOTO_DONE (FALSE) + HGOTO_DONE(FALSE) } /* end for */ done: @@ -1480,7 +1485,7 @@ H5Z_delete(H5O_pline_t *pline, H5Z_filter_t filter) /* filter was not found in the pipeline */ if (!found) - HGOTO_ERROR (H5E_PLINE, H5E_NOTFOUND, FAIL, "filter not in pipeline") + HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "filter not in pipeline") /* Free information for deleted filter */ if (pline->filter[idx].name && pline->filter[idx].name != pline->filter[idx]._name) @@ -1563,7 +1568,7 @@ H5Z_get_filter_info(H5Z_filter_t filter, unsigned int *filter_config_flags) /* Look up the filter class info */ if (NULL == (fclass = H5Z_find(filter))) - HGOTO_ERROR (H5E_PLINE, H5E_BADVALUE, FAIL, "Filter not defined") + HGOTO_ERROR(H5E_PLINE, H5E_BADVALUE, FAIL, "Filter not defined") /* Set the filter config flags for the application */ if (filter_config_flags != NULL) { diff --git a/test/error_test.c b/test/error_test.c index 9c39065..5356fa7 100644 --- a/test/error_test.c +++ b/test/error_test.c @@ -82,35 +82,33 @@ static herr_t custom_print_cb(unsigned n, const H5E_error2_t *err_desc, /*------------------------------------------------------------------------- - * Function: test_error + * Function: test_error * - * Purpose: Test error API functions + * Purpose: Test error API functions * - * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Raymond Lu - * July 10, 2003 + * Return: Success: 0 + * Failure: -1 * *------------------------------------------------------------------------- */ static herr_t test_error(hid_t file) { - hid_t dataset, space; - hid_t estack_id; + hid_t dataset = -1; + hid_t space = -1; + hid_t estack_id = -1; hsize_t dims[2]; const char *FUNC_test_error = "test_error"; H5E_auto2_t old_func; - void *old_data; + void *old_data = NULL; HDfprintf(stderr, "\nTesting error API based on data I/O\n"); /* Create the data space */ dims[0] = DIM0; dims[1] = DIM1; - if ((space = H5Screate_simple(2, dims, NULL))<0) TEST_ERROR; + if ((space = H5Screate_simple(2, dims, NULL)) < 0) + TEST_ERROR; /* Test H5E_BEGIN_TRY */ H5E_BEGIN_TRY { @@ -118,40 +116,40 @@ test_error(hid_t file) } H5E_END_TRY; /* Create the dataset */ - if((dataset = H5Dcreate2(file, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + if ((dataset = H5Dcreate2(file, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5Epush(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_CREATE, "H5Dcreate2 failed"); goto error; - } /* end if */ + } /* Test enabling and disabling default printing */ - if(H5Eget_auto2(H5E_DEFAULT, &old_func, &old_data) < 0) - TEST_ERROR; - if(old_data != NULL) - TEST_ERROR; + if (H5Eget_auto2(H5E_DEFAULT, &old_func, &old_data) < 0) + TEST_ERROR; + if (old_data != NULL) + TEST_ERROR; #ifdef H5_USE_16_API if (old_func != (H5E_auto_t)H5Eprint) - TEST_ERROR; + TEST_ERROR; #else /* H5_USE_16_API */ if (old_func != (H5E_auto2_t)H5Eprint2) - TEST_ERROR; + TEST_ERROR; #endif /* H5_USE_16_API */ - if(H5Eset_auto2(H5E_DEFAULT, NULL, NULL) < 0) + if (H5Eset_auto2(H5E_DEFAULT, NULL, NULL) < 0) TEST_ERROR; /* Make H5Dwrite fail, verify default print is disabled */ - if(H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) >= 0) { + if (H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) >= 0) { H5Epush(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_WRITE, "H5Dwrite shouldn't succeed"); goto error; - } /* end if */ + } - if(H5Eset_auto2(H5E_DEFAULT, old_func, old_data) < 0) + if (H5Eset_auto2(H5E_DEFAULT, old_func, old_data) < 0) TEST_ERROR; /* Test saving and restoring the current error stack */ - if(H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) < 0) { + if (H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) < 0) { H5Epush(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_WRITE, "H5Dwrite failed as supposed to"); estack_id = H5Eget_current_stack(); @@ -159,10 +157,11 @@ test_error(hid_t file) H5Sclose(space); H5Eset_current_stack(estack_id); goto error; - } /* end if */ + } /* In case program comes to this point, close dataset */ - if(H5Dclose(dataset) < 0) TEST_ERROR; + if(H5Dclose(dataset) < 0) + TEST_ERROR; TEST_ERROR; @@ -172,16 +171,12 @@ test_error(hid_t file) /*------------------------------------------------------------------------- - * Function: init_error + * Function: init_error * - * Purpose: Initialize error information. + * Purpose: Initialize error information. * - * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Raymond Lu - * July 10, 2003 + * Return: Success: 0 + * Failure: -1 * *------------------------------------------------------------------------- */ @@ -194,46 +189,46 @@ init_error(void) char *msg = NULL; H5E_type_t msg_type; - if(NULL == (cls_name = (char *)HDmalloc(HDstrlen(ERR_CLS_NAME) + 1))) + if (NULL == (cls_name = (char *)HDmalloc(HDstrlen(ERR_CLS_NAME) + 1))) TEST_ERROR - if(NULL == (msg = (char *)HDmalloc(HDstrlen(ERR_MIN_SUBROUTINE_MSG) + 1))) + if (NULL == (msg = (char *)HDmalloc(HDstrlen(ERR_MIN_SUBROUTINE_MSG) + 1))) TEST_ERROR - if((ERR_CLS = H5Eregister_class(ERR_CLS_NAME, PROG_NAME, PROG_VERS)) < 0) + if ((ERR_CLS = H5Eregister_class(ERR_CLS_NAME, PROG_NAME, PROG_VERS)) < 0) TEST_ERROR; - if(cls_size != H5Eget_class_name(ERR_CLS, cls_name, (size_t)cls_size) + 1) + if (cls_size != H5Eget_class_name(ERR_CLS, cls_name, (size_t)cls_size) + 1) TEST_ERROR; - if(HDstrcmp(ERR_CLS_NAME, cls_name)) + if (HDstrcmp(ERR_CLS_NAME, cls_name)) TEST_ERROR; - if((ERR_MAJ_TEST = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_TEST_MSG)) < 0) + if ((ERR_MAJ_TEST = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_TEST_MSG)) < 0) TEST_ERROR; - if((ERR_MAJ_IO = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_IO_MSG)) < 0) + if ((ERR_MAJ_IO = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_IO_MSG)) < 0) TEST_ERROR; - if((ERR_MAJ_API = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_API_MSG)) < 0) + if ((ERR_MAJ_API = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_API_MSG)) < 0) TEST_ERROR; - if((ERR_MIN_SUBROUTINE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_SUBROUTINE_MSG)) < 0) + if ((ERR_MIN_SUBROUTINE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_SUBROUTINE_MSG)) < 0) TEST_ERROR; - if((ERR_MIN_ERRSTACK = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_ERRSTACK_MSG)) < 0) + if ((ERR_MIN_ERRSTACK = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_ERRSTACK_MSG)) < 0) TEST_ERROR; - if((ERR_MIN_CREATE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_CREATE_MSG)) < 0) + if ((ERR_MIN_CREATE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_CREATE_MSG)) < 0) TEST_ERROR; - if((ERR_MIN_WRITE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_WRITE_MSG)) < 0) + if ((ERR_MIN_WRITE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_WRITE_MSG)) < 0) TEST_ERROR; - if((ERR_MIN_GETNUM = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_GETNUM_MSG)) < 0) + if ((ERR_MIN_GETNUM = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_GETNUM_MSG)) < 0) TEST_ERROR; - if(msg_size != H5Eget_msg(ERR_MIN_SUBROUTINE, &msg_type, msg, (size_t)msg_size) + 1) + if (msg_size != H5Eget_msg(ERR_MIN_SUBROUTINE, &msg_type, msg, (size_t)msg_size) + 1) TEST_ERROR; - if(msg_type != H5E_MINOR) + if (msg_type != H5E_MINOR) TEST_ERROR; - if(HDstrcmp(msg, ERR_MIN_SUBROUTINE_MSG)) + if (HDstrcmp(msg, ERR_MIN_SUBROUTINE_MSG)) TEST_ERROR; /* Register another class for later testing. */ - if((ERR_CLS2 = H5Eregister_class(ERR_CLS2_NAME, PROG2_NAME, PROG_VERS)) < 0) + if ((ERR_CLS2 = H5Eregister_class(ERR_CLS2_NAME, PROG2_NAME, PROG_VERS)) < 0) TEST_ERROR; HDfree(cls_name); @@ -242,9 +237,9 @@ init_error(void) return 0; error: - if(cls_name) + if (cls_name) HDfree(cls_name); - if(msg) + if (msg) HDfree(msg); return -1; @@ -252,16 +247,12 @@ error: /*------------------------------------------------------------------------- - * Function: error_stack - * - * Purpose: Manipulates current error stack. + * Function: error_stack * - * Return: Success: 0 + * Purpose: Manipulates current error stack. * - * Failure: -1 - * - * Programmer: Raymond Lu - * July 14, 2003 + * Return: Success: 0 + * Failure: -1 * *------------------------------------------------------------------------- */ @@ -271,23 +262,23 @@ error_stack(void) ssize_t err_num; const char *FUNC_error_stack = "error_stack"; - if((err_num = H5Eget_num(H5E_DEFAULT)) < 0) + if ((err_num = H5Eget_num(H5E_DEFAULT)) < 0) TEST_ERROR; - if(err_num) + if (err_num) TEST_ERROR; - if((ERR_STACK = H5Eget_current_stack()) < 0) + if ((ERR_STACK = H5Eget_current_stack()) < 0) TEST_ERROR; /* Make it push error, force this function to fail */ - if((err_num = H5Eget_num(ERR_STACK)) == 0) { + if ((err_num = H5Eget_num(ERR_STACK)) == 0) { H5Epush(ERR_STACK, __FILE__, FUNC_error_stack, __LINE__, ERR_CLS, ERR_MAJ_API, ERR_MIN_GETNUM, "Get number test failed, returned %d", (int)err_num); goto error; - } /* end if */ + } /* In case program falls through here, close the stack and let it fail. */ - if(H5Eclose_stack(ERR_STACK) < 0) + if (H5Eclose_stack(ERR_STACK) < 0) TEST_ERROR; return -1; @@ -300,14 +291,10 @@ error: /*------------------------------------------------------------------------- * Function: long_desc_cb * - * Purpose: Callback function to help test long description handling - * - * Return: Success: 0 + * Purpose: Callback function to help test long description handling * - * Failure: -1 - * - * Programmer: Quincey Koziol - * January 19, 2005 + * Return: Success: 0 + * Failure: -1 * *------------------------------------------------------------------------- */ @@ -316,24 +303,20 @@ long_desc_cb(unsigned H5_ATTR_UNUSED n, const H5E_error2_t *err_desc, void *clie { char *real_desc = (char *)client_data; - if(err_desc->desc != NULL && HDstrcmp(err_desc->desc, real_desc) == 0) - return(0); + if (err_desc->desc != NULL && HDstrcmp(err_desc->desc, real_desc) == 0) + return 0; else - return(-1); + return -1; } /* end long_desc_cb() */ /*------------------------------------------------------------------------- - * Function: test_long_desc + * Function: test_long_desc * - * Purpose: Test long error description handling + * Purpose: Test long error description handling * - * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Quincey Koziol - * January 19, 2005 + * Return: Success: 0 + * Failure: -1 * *------------------------------------------------------------------------- */ @@ -347,56 +330,59 @@ test_long_desc(void) const char *test_FUNC = "test_long_desc"; /* Allocate space for the error description info */ - if(NULL == (long_desc = (char*)HDmalloc(LONG_DESC_SIZE))) TEST_ERROR; - if(NULL == (full_desc = (char*)HDmalloc(LONG_DESC_SIZE + 128))) TEST_ERROR; + if (NULL == (long_desc = (char *)HDmalloc(LONG_DESC_SIZE))) + TEST_ERROR; + if (NULL == (full_desc = (char *)HDmalloc(LONG_DESC_SIZE + 128))) + TEST_ERROR; /* Create the long part of the error description */ - for(u = 0; u < LONG_DESC_SIZE; u++) + for (u = 0; u < LONG_DESC_SIZE; u++) long_desc[u] = (char)('A' + (u % 26)); long_desc[LONG_DESC_SIZE - 1] = '\0'; /* Clear the default error stack */ - if(H5Eclear2(H5E_DEFAULT) < 0) TEST_ERROR; + if (H5Eclear2(H5E_DEFAULT) < 0) + TEST_ERROR; /* Push an error with a long description */ - if(H5Epush(H5E_DEFAULT, __FILE__, test_FUNC, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, format, long_desc) < 0) TEST_ERROR; + if (H5Epush(H5E_DEFAULT, __FILE__, test_FUNC, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, format, long_desc) < 0) + TEST_ERROR; /* Create the string that should be in the description. Must use HDsnprintf here - * because snprintf is _snprintf on Windows */ + * because snprintf is _snprintf on Windows + */ HDsnprintf(full_desc, (size_t)(LONG_DESC_SIZE + 128), format, long_desc); /* Make certain that the description is correct */ - if(H5Ewalk2(H5E_DEFAULT, H5E_WALK_UPWARD, long_desc_cb, full_desc) < 0) TEST_ERROR; + if (H5Ewalk2(H5E_DEFAULT, H5E_WALK_UPWARD, long_desc_cb, full_desc) < 0) + TEST_ERROR; /* Clear the default error stack again */ - if(H5Eclear2(H5E_DEFAULT) < 0) TEST_ERROR; + if (H5Eclear2(H5E_DEFAULT) < 0) + TEST_ERROR; HDfree(long_desc); HDfree(full_desc); - return(0); + return 0; error: - if(long_desc) + if (long_desc) HDfree(long_desc); - if(full_desc) + if (full_desc) HDfree(full_desc); - return(-1); + return -1; } /* end test_long_desc() */ /*------------------------------------------------------------------------- * Function: dump_error * - * Purpose: Prints error stack in default and customized ways. + * Purpose: Prints error stack in default and customized ways. * - * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Raymond Lu - * July 17, 2003 + * Return: Success: 0 + * Failure: -1 * *------------------------------------------------------------------------- */ @@ -405,12 +391,12 @@ dump_error(hid_t estack) { /* Print errors in library default way */ HDfprintf(stderr, "********* Print error stack in HDF5 default way *********\n"); - if(H5Eprint2(estack, stderr) < 0) + if (H5Eprint2(estack, stderr) < 0) TEST_ERROR; /* Customized way to print errors */ HDfprintf(stderr, "\n********* Print error stack in customized way *********\n"); - if(H5Ewalk2(estack, H5E_WALK_UPWARD, custom_print_cb, stderr) < 0) + if (H5Ewalk2(estack, H5E_WALK_UPWARD, custom_print_cb, stderr) < 0) TEST_ERROR; return 0; @@ -423,34 +409,30 @@ error: /*------------------------------------------------------------------------- * Function: custom_print_cb * - * Purpose: Callback function to print error stack in customized way. - * - * Return: Success: 0 + * Purpose: Callback function to print error stack in customized way. * - * Failure: -1 - * - * Programmer: Raymond Lu - * July 17, 2003 + * Return: Success: 0 + * Failure: -1 * *------------------------------------------------------------------------- */ static herr_t custom_print_cb(unsigned n, const H5E_error2_t *err_desc, void* client_data) { - FILE *stream = (FILE *)client_data; + FILE *stream = (FILE *)client_data; char maj[MSG_SIZE]; char min[MSG_SIZE]; char cls[MSG_SIZE]; - const int indent = 4; + const int indent = 4; /* Get descriptions for the major and minor error numbers */ - if(H5Eget_class_name(err_desc->cls_id, cls, MSG_SIZE) < 0) + if (H5Eget_class_name(err_desc->cls_id, cls, MSG_SIZE) < 0) TEST_ERROR; - if(H5Eget_msg(err_desc->maj_num, NULL, maj, MSG_SIZE) < 0) + if (H5Eget_msg(err_desc->maj_num, NULL, maj, MSG_SIZE) < 0) TEST_ERROR; - if(H5Eget_msg(err_desc->min_num, NULL, min, MSG_SIZE) < 0) + if (H5Eget_msg(err_desc->min_num, NULL, min, MSG_SIZE) < 0) TEST_ERROR; HDfprintf(stream, "%*serror #%03d: %s in %s(): line %u\n", @@ -468,54 +450,58 @@ error: /*------------------------------------------------------------------------- - * Function: test_create - * - * Purpose: Test creating an empty error stack + * Function: test_create * - * Return: Success: 0 - * Failure: -1 + * Purpose: Test creating an empty error stack * - * Programmer: Quincey Koziol - * November 1, 2007 + * Return: Success: 0 + * Failure: -1 * *------------------------------------------------------------------------- */ static herr_t test_create(void) { - const char *err_func = "test_create"; /* Function name for pushing error */ - const char *err_msg = "Error message"; /* Error message for pushing error */ - ssize_t err_num; /* Number of errors on stack */ - hid_t estack_id; /* Error stack ID */ + const char *err_func = "test_create"; /* Function name for pushing error */ + const char *err_msg = "Error message"; /* Error message for pushing error */ + ssize_t err_num; /* Number of errors on stack */ + hid_t estack_id = -1; /* Error stack ID */ /* Create an empty error stack */ - if((estack_id = H5Ecreate_stack()) < 0) TEST_ERROR + if ((estack_id = H5Ecreate_stack()) < 0) + TEST_ERROR /* Check the number of errors on stack */ err_num = H5Eget_num(estack_id); - if(err_num != 0) TEST_ERROR + if (err_num != 0) + TEST_ERROR /* Push an error with a long description */ - if(H5Epush(estack_id, __FILE__, err_func, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, "%s", err_msg) < 0) TEST_ERROR; + if (H5Epush(estack_id, __FILE__, err_func, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, "%s", err_msg) < 0) + TEST_ERROR; /* Check the number of errors on stack */ err_num = H5Eget_num(estack_id); - if(err_num != 1) TEST_ERROR + if (err_num != 1) + TEST_ERROR /* Clear the error stack */ - if(H5Eclear2(estack_id) < 0) TEST_ERROR + if (H5Eclear2(estack_id) < 0) + TEST_ERROR /* Check the number of errors on stack */ err_num = H5Eget_num(estack_id); - if(err_num != 0) TEST_ERROR + if (err_num != 0) + TEST_ERROR /* Close error stack */ - if(H5Eclose_stack(estack_id) < 0) TEST_ERROR + if(H5Eclose_stack(estack_id) < 0) + TEST_ERROR - return(0); + return 0; error: - return(-1); + return -1; } /* end test_create() */ /*------------------------------------------------------------------------- @@ -526,70 +512,72 @@ error: * Return: Success: 0 * Failure: -1 * - * Programmer: Allen Byrne - * February 18, 2010 - * *------------------------------------------------------------------------- */ static herr_t test_copy(void) { - const char *err_func = "test_copy"; /* Function name for pushing error */ - const char *err_msg = "Error message"; /* Error message for pushing error */ - ssize_t err_num; /* Number of errors on stack */ - hid_t estack_id; /* Error stack ID */ - herr_t ret; /* Generic return value */ + const char *err_func = "test_copy"; /* Function name for pushing error */ + const char *err_msg = "Error message"; /* Error message for pushing error */ + ssize_t err_num; /* Number of errors on stack */ + hid_t estack_id = -1; /* Error stack ID */ + herr_t ret; /* Generic return value */ /* Push an error with a long description */ - if(H5Epush(H5E_DEFAULT, __FILE__, err_func, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, "%s", err_msg) < 0) TEST_ERROR; + if (H5Epush(H5E_DEFAULT, __FILE__, err_func, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, "%s", err_msg) < 0) + TEST_ERROR; /* Check the number of errors on stack */ err_num = H5Eget_num(H5E_DEFAULT); - if(err_num != 1) TEST_ERROR + if (err_num != 1) + TEST_ERROR /* Copy error stack, which clears the original */ - if((estack_id = H5Eget_current_stack()) < 0) TEST_ERROR + if ((estack_id = H5Eget_current_stack()) < 0) + TEST_ERROR /* Check the number of errors on stack copy */ err_num = H5Eget_num(estack_id); - if(err_num != 1) TEST_ERROR + if (err_num != 1) + TEST_ERROR /* Check the number of errors on original stack */ err_num = H5Eget_num(H5E_DEFAULT); - if(err_num != 0) TEST_ERROR + if (err_num != 0) + TEST_ERROR /* Put the stack copy as the default. It closes the stack copy, too. */ - if(H5Eset_current_stack(estack_id) < 0) TEST_ERROR + if (H5Eset_current_stack(estack_id) < 0) + TEST_ERROR /* Check the number of errors on default stack */ err_num = H5Eget_num(H5E_DEFAULT); - if(err_num != 1) TEST_ERROR + if (err_num != 1) + TEST_ERROR /* Try to close error stack copy. Should fail because - * the current H5Eset_current_stack closes the stack to be set.*/ + * the current H5Eset_current_stack closes the stack to be set. + */ H5E_BEGIN_TRY { ret = H5Eclose_stack(estack_id); } H5E_END_TRY - if(ret >= 0) TEST_ERROR + if (ret >= 0) + TEST_ERROR - return(0); + return 0; error: - return(-1); + return -1; } /* end test_copy() */ /*------------------------------------------------------------------------- - * Function: close_error + * Function: close_error * - * Purpose: Closes error information. + * Purpose: Closes error information. * - * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Raymond Lu - * July 10, 2003 + * Return: Success: 0 + * Failure: -1 * *------------------------------------------------------------------------- */ @@ -597,19 +585,19 @@ static herr_t close_error(void) { /* Close major errors, let H5Eunregister_class close minor errors */ - if(H5Eclose_msg(ERR_MAJ_TEST) < 0) + if (H5Eclose_msg(ERR_MAJ_TEST) < 0) TEST_ERROR; - if(H5Eclose_msg(ERR_MAJ_IO) < 0) + if (H5Eclose_msg(ERR_MAJ_IO) < 0) TEST_ERROR; - if(H5Eclose_msg(ERR_MAJ_API) < 0) + if (H5Eclose_msg(ERR_MAJ_API) < 0) TEST_ERROR; - if(H5Eunregister_class(ERR_CLS) < 0) + if (H5Eunregister_class(ERR_CLS) < 0) TEST_ERROR; - if(H5Eunregister_class(ERR_CLS2) < 0) + if (H5Eunregister_class(ERR_CLS2) < 0) TEST_ERROR; return 0; @@ -620,19 +608,15 @@ error: /*------------------------------------------------------------------------- - * Function: test_filter_error + * Function: test_filter_error * - * Purpose: Make sure the error message prints out the filter name + * Purpose: Make sure the error message prints out the filter name * when the existent file is opened but the filter isn't * registered. The existent file was created with * gen_filters.c. * - * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Raymond Lu - * 2 June 2011 + * Return: Success: 0 + * Failure: -1 * *------------------------------------------------------------------------- */ @@ -640,71 +624,72 @@ static herr_t test_filter_error(const char *fname) { const char *pathname = H5_get_srcdir_filename(fname); /* Corrected test file name */ - hid_t file, dataset; /* handles */ + hid_t file = -1; + hid_t dataset = -1; int buf[20]; HDfprintf(stderr, "\nTesting error message during data reading when filter isn't registered\n"); /* Open the file */ - if((file = H5Fopen(pathname, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) + if ((file = H5Fopen(pathname, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) TEST_ERROR; /* Open the regular dataset */ - if((dataset = H5Dopen2(file, DSET_FILTER_NAME, H5P_DEFAULT)) < 0) + if ((dataset = H5Dopen2(file, DSET_FILTER_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; - if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) >= 0) - TEST_ERROR; + if (H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) >= 0) + TEST_ERROR; /* Close/release resources */ - if(H5Dclose(dataset) < 0) + if (H5Dclose(dataset) < 0) TEST_ERROR - if(H5Fclose(file) < 0) + if (H5Fclose(file) < 0) TEST_ERROR return 0; error: return -1; -} +} /* end test_filter_error() */ /*------------------------------------------------------------------------- - * Function: main + * Function: main * - * Purpose: Test error API. - * - * Programmer: Raymond Lu - * July 10, 2003 + * Purpose: Test error API. * *------------------------------------------------------------------------- */ int main(void) { - hid_t file, fapl; - hid_t estack_id; - char filename[1024]; - const char *FUNC_main = "main"; + hid_t file = -1; + hid_t fapl = -1; + hid_t estack_id = -1; + char filename[1024]; + const char *FUNC_main = "main"; HDfprintf(stderr, " This program tests the Error API. There're supposed to be some error messages\n"); /* Initialize errors */ - if(init_error() < 0) + if (init_error() < 0) TEST_ERROR; - fapl = h5_fileaccess(); + if ((fapl = h5_fileaccess()) < 0) + TEST_ERROR; - h5_fixname(FILENAME[0], fapl, filename, sizeof filename); - if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) - TEST_ERROR; + h5_fixname(FILENAME[0], fapl, filename, sizeof(filename)); + if ((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) + TEST_ERROR; /* Test error stack */ - if(error_stack() < 0) { + if (error_stack() < 0) { /* Push an error onto error stack */ - if(H5Epush(ERR_STACK, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_ERRSTACK, - "Error stack test failed") < 0) TEST_ERROR; + if (H5Epush(ERR_STACK, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_ERRSTACK, + "Error stack test failed") < 0) + TEST_ERROR; /* Delete an error from the top of error stack */ H5Epop(ERR_STACK, 1); @@ -724,34 +709,39 @@ main(void) } /* end if */ /* Test error API */ - if(test_error(file) < 0) { + if (test_error(file) < 0) { H5Epush(H5E_DEFAULT, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, "Error test failed, %s", "it's wrong"); estack_id = H5Eget_current_stack(); H5Eprint2(estack_id, stderr); H5Eclose_stack(estack_id); - } /* end if */ + } /* Test pushing a very long error description */ - if(test_long_desc() < 0) TEST_ERROR; + if (test_long_desc() < 0) + TEST_ERROR; /* Test creating a new error stack */ - if(test_create() < 0) TEST_ERROR; + if (test_create() < 0) + TEST_ERROR; /* Test copying a new error stack */ - if(test_copy() < 0) TEST_ERROR; + if (test_copy() < 0) + TEST_ERROR; - if(H5Fclose(file) < 0) TEST_ERROR; + if (H5Fclose(file) < 0) + TEST_ERROR; /* Close error information */ - if(close_error() < 0) + if (close_error() < 0) TEST_ERROR; /* Test error message during data reading when filter isn't registered * Use default FAPL to avoid some VFD drivers by the check-vfd test because - * the test file was pre-generated. */ + * the test file was pre-generated. + */ h5_fixname(DATAFILE, H5P_DEFAULT, filename, sizeof filename); - if(test_filter_error(filename) < 0) + if (test_filter_error(filename) < 0) TEST_ERROR; h5_clean_files(FILENAME, fapl); diff --git a/test/testfiles/error_test_1 b/test/testfiles/error_test_1 index 0acd288..5b68002 100644 --- a/test/testfiles/error_test_1 +++ b/test/testfiles/error_test_1 @@ -53,7 +53,7 @@ HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs): #004: (file name) line (number) in H5Z_pipeline(): required filter 'bogus' is not registered major: Data filters minor: Read failed - #005: (file name) line (number) in H5PL_load(): required dynamically loaded plugin filter '305' is not available + #005: (file name) line (number) in H5PL_load(): filter plugins disabled major: Plugin for dynamically loaded library minor: Unable to load metadata into cache diff --git a/tools/test/h5dump/errfiles/filter_fail.err b/tools/test/h5dump/errfiles/filter_fail.err index db21044..5276ab0 100644 --- a/tools/test/h5dump/errfiles/filter_fail.err +++ b/tools/test/h5dump/errfiles/filter_fail.err @@ -14,7 +14,7 @@ HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs): #004: (file name) line (number) in H5Z_pipeline(): required filter 'filter_fail_test' is not registered major: Data filters minor: Read failed - #005: (file name) line (number) in H5PL_load(): required dynamically loaded plugin filter '312' is not available + #005: (file name) line (number) in H5PL_load(): filter plugins disabled major: Plugin for dynamically loaded library minor: Unable to load metadata into cache h5dump error: unable to print data -- cgit v0.12 From cd72e02a336369ee25a26d4ad63d4c498e613f70 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Tue, 21 Nov 2017 01:22:21 -0800 Subject: Fixed Windows code in H5PLpath.c --- src/H5PLpath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/H5PLpath.c b/src/H5PLpath.c index d8e82f8..972f1d0 100644 --- a/src/H5PLpath.c +++ b/src/H5PLpath.c @@ -755,7 +755,7 @@ H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *fo continue; /* attempt to open the dynamic library as a filter library */ - if (H5PL__open(path, search_params->type, search_params->search_key.id, found, plugin_info) < 0) + if (H5PL__open(path, search_params->type, search_params->key, found, plugin_info) < 0) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "search in directory failed") if (*found) HGOTO_DONE(SUCCEED) -- cgit v0.12 From 20bb11b52640befc4a0073520b23d9e49bf3e96c Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Tue, 21 Nov 2017 10:38:15 -0800 Subject: Fixed an uninitialized filter callback struct in H5Dchunk.c and unified the naming and initialization of said struct throughout the library. This was causing a crash on VS2015 in debug mode when the debug heap complained. Fixes HDFFV-10330. --- release_docs/RELEASE.txt | 15 +++++++++ src/H5Dchunk.c | 76 ++++++++++++++++++++++------------------- src/H5HFcache.c | 88 +++++++++++++++++++++++++++--------------------- src/H5HFhuge.c | 12 +++++-- src/H5Z.c | 62 +++++++++++++++++----------------- src/H5Zpublic.h | 20 +++++------ 6 files changed, 159 insertions(+), 114 deletions(-) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index a1b59b1..7498d01 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -179,6 +179,21 @@ Bug Fixes since HDF5-1.10.1 release (ADB - 2017/10/10, HDFFV-10297, HDFFV-10319) + - An uninitialized struct could cause a memory access error when using + variable-length or reference types in a compressed, chunked dataset. + + A struct containing a callback function pointer and a pointer to some + associated data was used before initialization. This could cause a + memory access error and system crash. This could only occur under + unusual conditions when using variable-lenth and reference types in + a compressed, chunked dataset. + + On recent versions of Visual Studio, when built in debug mode, the + debug heap will complain and cause a crash if the code in question + is executed (this will cause the objcopy test to fail). + + (DER - 2017/11/21, HDFFV-10330) + Configuration ------------- - cmake diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index 0d7fcc9..be3b678 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -5661,7 +5661,7 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) /* needed for commpressed variable length data */ hbool_t must_filter = FALSE; /* Whether chunk must be filtered during copy */ size_t nbytes; /* Size of chunk in file (in bytes) */ - H5Z_cb_t cb_struct; /* Filter failure callback struct */ + H5Z_cb_t filter_cb; /* Filter failure callback struct */ int ret_value = H5_ITER_CONT; /* Return value */ @@ -5670,6 +5670,10 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) /* Get 'size_t' local value for number of bytes in chunk */ H5_CHECKED_ASSIGN(nbytes, size_t, chunk_rec->nbytes, uint32_t); + /* Initialize the filter callback struct */ + filter_cb.op_data = NULL; + filter_cb.func = NULL; /* no callback function when failed */ + /* Check for filtered chunks */ /* Check for an edge chunk that is not filtered */ if(pline && pline->nused) { @@ -5716,7 +5720,8 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) HDassert(!H5F_addr_defined(chunk_rec->chunk_addr)); HDmemcpy(buf, udata->chunk, nbytes); udata->chunk = NULL; - } else { + } + else { H5D_rdcc_ent_t *ent = NULL; /* Cache entry */ unsigned idx; /* Index of chunk in cache, if present */ unsigned u; /* Counter */ @@ -5748,7 +5753,8 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) H5_CHECKED_ASSIGN(nbytes, size_t, shared_fo->layout.u.chunk.size, uint32_t); HDmemcpy(buf, ent->chunk, nbytes); - } else { + } + else { /* read chunk data from the source file */ if(H5F_block_read(udata->file_src, H5FD_MEM_DRAW, chunk_rec->chunk_addr, nbytes, H5AC_rawdata_dxpl_id, buf) < 0) HGOTO_ERROR(H5E_IO, H5E_READERROR, H5_ITER_ERROR, "unable to read raw data chunk") @@ -5759,8 +5765,7 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) if(must_filter && (is_vlen || fix_ref) && !udata->chunk_in_cache) { unsigned filter_mask = chunk_rec->filter_mask; - cb_struct.func = NULL; /* no callback function when failed */ - if(H5Z_pipeline(pline, H5Z_FLAG_REVERSE, &filter_mask, H5Z_NO_EDC, cb_struct, &nbytes, &buf_size, &buf) < 0) + if(H5Z_pipeline(pline, H5Z_FLAG_REVERSE, &filter_mask, H5Z_NO_EDC, filter_cb, &nbytes, &buf_size, &buf) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTFILTER, H5_ITER_ERROR, "data pipeline read failed") } /* end if */ @@ -5822,7 +5827,7 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) /* Need to compress variable-length or reference data elements or a chunk found in cache before writing to file */ if(must_filter && (is_vlen || fix_ref || udata->chunk_in_cache) ) { - if(H5Z_pipeline(pline, 0, &(udata_dst.filter_mask), H5Z_NO_EDC, cb_struct, &nbytes, &buf_size, &buf) < 0) + if(H5Z_pipeline(pline, 0, &(udata_dst.filter_mask), H5Z_NO_EDC, filter_cb, &nbytes, &buf_size, &buf) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTFILTER, H5_ITER_ERROR, "output pipeline failed") #if H5_SIZEOF_SIZE_T > 4 /* Check for the chunk expanding too much to encode in a 32-bit value */ @@ -6707,46 +6712,49 @@ H5D__chunk_format_convert_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) H5_CHECKED_ASSIGN(nbytes, size_t, chunk_rec->nbytes, uint32_t); chunk_addr = chunk_rec->chunk_addr; - if(new_idx_info->pline->nused && + if (new_idx_info->pline->nused && (new_idx_info->layout->flags & H5O_LAYOUT_CHUNK_DONT_FILTER_PARTIAL_BOUND_CHUNKS) && (H5D__chunk_is_partial_edge_chunk(udata->dset_ndims, new_idx_info->layout->dim, chunk_rec->scaled, udata->dset_dims))) { - /* This is a partial non-filtered edge chunk */ - /* Convert the chunk to a filtered edge chunk for v1 B-tree chunk index */ - unsigned filter_mask = chunk_rec->filter_mask; - H5Z_cb_t cb_struct; /* Filter failure callback struct */ - size_t read_size = nbytes; /* Bytes to read */ + /* This is a partial non-filtered edge chunk */ + /* Convert the chunk to a filtered edge chunk for v1 B-tree chunk index */ - HDassert(read_size == new_idx_info->layout->size); + unsigned filter_mask = chunk_rec->filter_mask; + H5Z_cb_t filter_cb; /* Filter failure callback struct */ + size_t read_size = nbytes; /* Bytes to read */ + + HDassert(read_size == new_idx_info->layout->size); - cb_struct.func = NULL; /* no callback function when failed */ + /* Initialize the filter callback struct */ + filter_cb.op_data = NULL; + filter_cb.func = NULL; /* no callback function when failed */ - /* Allocate buffer for chunk data */ - if(NULL == (buf = H5MM_malloc(read_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5_ITER_ERROR, "memory allocation failed for raw data chunk") + /* Allocate buffer for chunk data */ + if (NULL == (buf = H5MM_malloc(read_size))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5_ITER_ERROR, "memory allocation failed for raw data chunk") - /* Read the non-filtered edge chunk */ - if(H5F_block_read(new_idx_info->f, H5FD_MEM_DRAW, chunk_addr, read_size, H5AC_rawdata_dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_READERROR, H5_ITER_ERROR, "unable to read raw data chunk") + /* Read the non-filtered edge chunk */ + if (H5F_block_read(new_idx_info->f, H5FD_MEM_DRAW, chunk_addr, read_size, H5AC_rawdata_dxpl_id, buf) < 0) + HGOTO_ERROR(H5E_IO, H5E_READERROR, H5_ITER_ERROR, "unable to read raw data chunk") - /* Pass the chunk through the pipeline */ - if(H5Z_pipeline(new_idx_info->pline, 0, &filter_mask, H5Z_NO_EDC, cb_struct, &nbytes, &read_size, &buf) < 0) - HGOTO_ERROR(H5E_PLINE, H5E_CANTFILTER, H5_ITER_ERROR, "output pipeline failed") + /* Pass the chunk through the pipeline */ + if (H5Z_pipeline(new_idx_info->pline, 0, &filter_mask, H5Z_NO_EDC, filter_cb, &nbytes, &read_size, &buf) < 0) + HGOTO_ERROR(H5E_PLINE, H5E_CANTFILTER, H5_ITER_ERROR, "output pipeline failed") #if H5_SIZEOF_SIZE_T > 4 /* Check for the chunk expanding too much to encode in a 32-bit value */ - if(nbytes > ((size_t)0xffffffff)) - HGOTO_ERROR(H5E_DATASET, H5E_BADRANGE, H5_ITER_ERROR, "chunk too large for 32-bit length") + if (nbytes > ((size_t)0xffffffff)) + HGOTO_ERROR(H5E_DATASET, H5E_BADRANGE, H5_ITER_ERROR, "chunk too large for 32-bit length") #endif /* H5_SIZEOF_SIZE_T > 4 */ - /* Allocate space for the filtered chunk */ - if((chunk_addr = H5MF_alloc(new_idx_info->f, H5FD_MEM_DRAW, new_idx_info->dxpl_id, (hsize_t)nbytes)) == HADDR_UNDEF) - HGOTO_ERROR(H5E_DATASET, H5E_NOSPACE, H5_ITER_ERROR, "file allocation failed for filtered chunk") - HDassert(H5F_addr_defined(chunk_addr)); + /* Allocate space for the filtered chunk */ + if ((chunk_addr = H5MF_alloc(new_idx_info->f, H5FD_MEM_DRAW, new_idx_info->dxpl_id, (hsize_t)nbytes)) == HADDR_UNDEF) + HGOTO_ERROR(H5E_DATASET, H5E_NOSPACE, H5_ITER_ERROR, "file allocation failed for filtered chunk") + HDassert(H5F_addr_defined(chunk_addr)); - /* Write the filtered chunk to disk */ - if(H5F_block_write(new_idx_info->f, H5FD_MEM_DRAW, chunk_addr, nbytes, H5AC_rawdata_dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, H5_ITER_ERROR, "unable to write raw data to file") + /* Write the filtered chunk to disk */ + if (H5F_block_write(new_idx_info->f, H5FD_MEM_DRAW, chunk_addr, nbytes, H5AC_rawdata_dxpl_id, buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, H5_ITER_ERROR, "unable to write raw data to file") } /* end if */ /* Set up chunk information for insertion to chunk index */ @@ -6758,11 +6766,11 @@ H5D__chunk_format_convert_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) insert_udata.common.storage = new_idx_info->storage; /* Insert chunk into the v1 B-tree chunk index */ - if((new_idx_info->storage->ops->insert)(new_idx_info, &insert_udata, NULL) < 0) + if ((new_idx_info->storage->ops->insert)(new_idx_info, &insert_udata, NULL) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, H5_ITER_ERROR, "unable to insert chunk addr into index") done: - if(buf) + if (buf) H5MM_xfree(buf); FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5HFcache.c b/src/H5HFcache.c index f957e2e..069bf17 100644 --- a/src/H5HFcache.c +++ b/src/H5HFcache.c @@ -1671,9 +1671,13 @@ H5HF__cache_dblock_verify_chksum(const void *_image, size_t len, void *_udata) HGOTO_DONE(TRUE); if(hdr->filter_len > 0) { - size_t nbytes; /* Number of bytes used in buffer, after applying reverse filters */ - unsigned filter_mask; /* Excluded filters for direct block */ - H5Z_cb_t filter_cb = {NULL, NULL}; /* Filter callback structure */ + size_t nbytes; /* Number of bytes used in buffer, after applying reverse filters */ + unsigned filter_mask; /* Excluded filters for direct block */ + H5Z_cb_t filter_cb; /* Filter callback structure */ + + /* Initialize the filter callback struct */ + filter_cb.op_data = NULL; + filter_cb.func = NULL; /* no callback function when failed */ /* Allocate buffer to perform I/O filtering on and copy image into * it. Must do this as H5Z_pipeline() may re-size the buffer @@ -1682,17 +1686,17 @@ H5HF__cache_dblock_verify_chksum(const void *_image, size_t len, void *_udata) if(NULL == (read_buf = H5MM_malloc(len))) HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "memory allocation failed for pipeline buffer") - /* Set up parameters for filter pipeline */ - nbytes = len; - filter_mask = udata->filter_mask; + /* Set up parameters for filter pipeline */ + nbytes = len; + filter_mask = udata->filter_mask; HDmemcpy(read_buf, image, len); - /* Push direct block data through I/O filter pipeline */ - if(H5Z_pipeline(&(hdr->pline), H5Z_FLAG_REVERSE, &filter_mask, H5Z_ENABLE_EDC, filter_cb, &nbytes, &len, &read_buf) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_CANTFILTER, FAIL, "output pipeline failed") + /* Push direct block data through I/O filter pipeline */ + if(H5Z_pipeline(&(hdr->pline), H5Z_FLAG_REVERSE, &filter_mask, H5Z_ENABLE_EDC, filter_cb, &nbytes, &len, &read_buf) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_CANTFILTER, FAIL, "output pipeline failed") /* Update info about direct block */ - udata->decompressed = TRUE; + udata->decompressed = TRUE; len = nbytes; } /* end if */ else @@ -1818,45 +1822,49 @@ H5HF__cache_dblock_deserialize(const void *_image, size_t len, void *_udata, udata->dblk = NULL; } /* end if */ else { - H5Z_cb_t filter_cb = {NULL, NULL}; /* Filter callback structure */ + H5Z_cb_t filter_cb; /* Filter callback structure */ size_t nbytes; /* Number of bytes used in buffer, after applying reverse filters */ unsigned filter_mask; /* Excluded filters for direct block */ /* Sanity check */ - HDassert(udata->dblk == NULL); + HDassert(udata->dblk == NULL); - /* Allocate buffer to perform I/O filtering on and copy image into - * it. Must do this as H5Z_pipeline() may resize the buffer - * provided to it. - */ - if(NULL == (read_buf = H5MM_malloc(len))) - HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "memory allocation failed for pipeline buffer") + /* Initialize the filter callback struct */ + filter_cb.op_data = NULL; + filter_cb.func = NULL; /* no callback function when failed */ + + /* Allocate buffer to perform I/O filtering on and copy image into + * it. Must do this as H5Z_pipeline() may resize the buffer + * provided to it. + */ + if (NULL == (read_buf = H5MM_malloc(len))) + HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "memory allocation failed for pipeline buffer") /* Copy compressed image into buffer */ - HDmemcpy(read_buf, image, len); + HDmemcpy(read_buf, image, len); - /* Push direct block data through I/O filter pipeline */ - nbytes = len; - filter_mask = udata->filter_mask; - if(H5Z_pipeline(&(hdr->pline), H5Z_FLAG_REVERSE, &filter_mask, H5Z_ENABLE_EDC, filter_cb, &nbytes, &len, &read_buf) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_CANTFILTER, NULL, "output pipeline failed") + /* Push direct block data through I/O filter pipeline */ + nbytes = len; + filter_mask = udata->filter_mask; + if (H5Z_pipeline(&(hdr->pline), H5Z_FLAG_REVERSE, &filter_mask, H5Z_ENABLE_EDC, filter_cb, &nbytes, &len, &read_buf) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_CANTFILTER, NULL, "output pipeline failed") - /* Sanity check */ - HDassert(nbytes == dblock->size); + /* Sanity check */ + HDassert(nbytes == dblock->size); - /* Copy un-filtered data into block's buffer */ - HDmemcpy(dblock->blk, read_buf, dblock->size); - } /* end if */ + /* Copy un-filtered data into block's buffer */ + HDmemcpy(dblock->blk, read_buf, dblock->size); + } /* end if */ } /* end if */ else { /* Sanity checks */ - HDassert(udata->dblk == NULL); - HDassert(!udata->decompressed); + HDassert(udata->dblk == NULL); + HDassert(!udata->decompressed); - /* Allocate block buffer */ -/* XXX: Change to using free-list factories */ - if(NULL == (dblock->blk = H5FL_BLK_MALLOC(direct_block, (size_t)dblock->size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + /* Allocate block buffer */ + /* XXX: Change to using free-list factories */ + if (NULL == (dblock->blk = H5FL_BLK_MALLOC(direct_block, (size_t)dblock->size))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Copy image to dblock->blk */ HDassert(dblock->size == len); @@ -1895,9 +1903,9 @@ H5HF__cache_dblock_deserialize(const void *_image, size_t len, void *_udata, /* Decode checksum on direct block, if requested */ if(hdr->checksum_dblocks) { - uint32_t stored_chksum; /* Metadata checksum value */ + uint32_t stored_chksum; /* Metadata checksum value */ - /* checksum verification already done in verify_chksum cb */ + /* checksum verification already done in verify_chksum cb */ /* Metadata checksum */ UINT32DECODE(image, stored_chksum); @@ -2188,10 +2196,14 @@ H5HF__cache_dblock_pre_serialize(H5F_t *f, hid_t dxpl_id, void *_thing, /* Check for I/O filters on this heap */ if(hdr->filter_len > 0) { - H5Z_cb_t filter_cb = {NULL, NULL}; /* Filter callback structure */ + H5Z_cb_t filter_cb; /* Filter callback structure */ size_t nbytes; /* Number of bytes used */ unsigned filter_mask = 0; /* Filter mask for block */ + /* Initialize the filter callback struct */ + filter_cb.op_data = NULL; + filter_cb.func = NULL; /* no callback function when failed */ + /* Allocate buffer to perform I/O filtering on */ write_size = dblock->size; if(NULL == (write_buf = H5MM_malloc(write_size))) diff --git a/src/H5HFhuge.c b/src/H5HFhuge.c index b2a1e68..350100e 100644 --- a/src/H5HFhuge.c +++ b/src/H5HFhuge.c @@ -345,9 +345,13 @@ HDfprintf(stderr, "%s: obj_size = %Zu\n", FUNC, obj_size); /* Check for I/O pipeline filter on heap */ if(hdr->filter_len > 0) { - H5Z_cb_t filter_cb = {NULL, NULL}; /* Filter callback structure */ + H5Z_cb_t filter_cb; /* Filter callback structure */ size_t nbytes; /* Number of bytes used */ + /* Initialize the filter callback struct */ + filter_cb.op_data = NULL; + filter_cb.func = NULL; /* no callback function when failed */ + /* Allocate buffer to perform I/O filtering on */ write_size = obj_size; if(NULL == (write_buf = H5MM_malloc(write_size))) @@ -773,10 +777,14 @@ H5HF_huge_op_real(H5HF_hdr_t *hdr, hid_t dxpl_id, const uint8_t *id, /* Check for I/O pipeline filter on heap */ if(hdr->filter_len > 0) { - H5Z_cb_t filter_cb = {NULL, NULL}; /* Filter callback structure */ + H5Z_cb_t filter_cb; /* Filter callback structure */ size_t read_size; /* Object's size in the file */ size_t nbytes; /* Number of bytes used */ + /* Initialize the filter callback struct */ + filter_cb.op_data = NULL; + filter_cb.func = NULL; /* no callback function when failed */ + /* De-filter the object */ read_size = nbytes = obj_size; if(H5Z_pipeline(&(hdr->pline), H5Z_FLAG_REVERSE, &filter_mask, H5Z_NO_EDC, filter_cb, &nbytes, &read_size, &read_buf) < 0) diff --git a/src/H5Z.c b/src/H5Z.c index 1e7cd79..89c97d4 100644 --- a/src/H5Z.c +++ b/src/H5Z.c @@ -275,7 +275,7 @@ done: * Function: H5Z_register * * Purpose: Same as the public version except this one allows filters - * to be set for predefined method numbers nused > 0); + HDassert(pline->nused > 0); /* Make "can apply" callbacks for filters in pipeline */ if (H5Z_prelude_callback(pline, (hid_t)-1, (hid_t)-1, (hid_t)-1, H5Z_PRELUDE_CAN_APPLY) < 0) @@ -926,7 +926,7 @@ H5Z_set_local_direct(const H5O_pline_t *pline) FUNC_ENTER_NOAPI(FAIL) - HDassert (pline->nused > 0); + HDassert(pline->nused > 0); /* Make "set local" callbacks for filters in pipeline */ if (H5Z_prelude_callback(pline, (hid_t)-1, (hid_t)-1, (hid_t)-1, H5Z_PRELUDE_SET_LOCAL) < 0) @@ -1200,12 +1200,12 @@ H5Z_pipeline(const H5O_pline_t *pline, unsigned flags, FUNC_ENTER_NOAPI(FAIL) - HDassert (0 == (flags & ~((unsigned)H5Z_FLAG_INVMASK))); - HDassert (filter_mask); - HDassert (nbytes && *nbytes>0); - HDassert (buf_size && *buf_size>0); - HDassert (buf && *buf); - HDassert (!pline || pline->nused0); + HDassert(buf_size && *buf_size>0); + HDassert(buf && *buf); + HDassert(!pline || pline->nused < H5Z_MAX_NFILTERS); if (pline && (flags & H5Z_FLAG_REVERSE)) { /* Read */ for (i = pline->nused; i > 0; --i) { @@ -1235,7 +1235,7 @@ H5Z_pipeline(const H5O_pline_t *pline, unsigned flags, /* Search in the table of registered filters again to find the dynamic filter just loaded and registered */ if ((fclass_idx = H5Z_find_idx(pline->filter[idx].id)) < 0) issue_error = TRUE; - } /* end if */ + } else issue_error = TRUE; @@ -1247,7 +1247,7 @@ H5Z_pipeline(const H5O_pline_t *pline, unsigned flags, HGOTO_ERROR(H5E_PLINE, H5E_READERROR, FAIL, "required filter '%s' is not registered", pline->filter[idx].name) else HGOTO_ERROR(H5E_PLINE, H5E_READERROR, FAIL, "required filter (name unavailable) is not registered") - } /* end if */ + } } /* end if */ fclass = &H5Z_table_g[fclass_idx]; @@ -1263,11 +1263,12 @@ H5Z_pipeline(const H5O_pline_t *pline, unsigned flags, #ifdef H5Z_DEBUG H5_timer_end (&(fstats->stats[1].timer), &timer); fstats->stats[1].total += MAX(*nbytes, new_nbytes); - if (0 == new_nbytes) fstats->stats[1].errors += *nbytes; + if (0 == new_nbytes) + fstats->stats[1].errors += *nbytes; #endif if (0 == new_nbytes) { - if ((cb_struct.func && (H5Z_CB_FAIL == cb_struct.func (pline->filter[idx].id, *buf, *buf_size, cb_struct.op_data))) || !cb_struct.func) + if ((cb_struct.func && (H5Z_CB_FAIL == cb_struct.func(pline->filter[idx].id, *buf, *buf_size, cb_struct.op_data))) || !cb_struct.func) HGOTO_ERROR(H5E_PLINE, H5E_READERROR, FAIL, "filter returned failure during read") *nbytes = *buf_size; @@ -1303,7 +1304,8 @@ H5Z_pipeline(const H5O_pline_t *pline, unsigned flags, #ifdef H5Z_DEBUG H5_timer_end (&(fstats->stats[0].timer), &timer); fstats->stats[0].total += MAX(*nbytes, new_nbytes); - if (0 == new_nbytes) fstats->stats[0].errors += *nbytes; + if (0 == new_nbytes) + fstats->stats[0].errors += *nbytes; #endif if (0 == new_nbytes) { if (0 == (pline->filter[idx].flags & H5Z_FLAG_OPTIONAL)) { @@ -1345,8 +1347,8 @@ H5Z_filter_info(const H5O_pline_t *pline, H5Z_filter_t filter) FUNC_ENTER_NOAPI(NULL) - HDassert (pline); - HDassert (filter >= 0 && filter <= H5Z_FILTER_MAX); + HDassert(pline); + HDassert(filter >= 0 && filter <= H5Z_FILTER_MAX); /* Locate the filter in the pipeline */ for (idx = 0; idx < pline->nused; idx++) @@ -1384,8 +1386,8 @@ H5Z_filter_in_pline(const H5O_pline_t *pline, H5Z_filter_t filter) FUNC_ENTER_NOAPI(FAIL) - HDassert (pline); - HDassert (filter >= 0 && filter <= H5Z_FILTER_MAX); + HDassert(pline); + HDassert(filter >= 0 && filter <= H5Z_FILTER_MAX); /* Locate the filter in the pipeline */ for (idx = 0; idx < pline->nused; idx++) @@ -1421,7 +1423,7 @@ H5Z_all_filters_avail(const H5O_pline_t *pline) FUNC_ENTER_NOAPI(FAIL) /* Check args */ - HDassert (pline); + HDassert(pline); /* Iterate through all the filters in pipeline */ for (i = 0; i < pline->nused; i++) { @@ -1459,8 +1461,8 @@ H5Z_delete(H5O_pline_t *pline, H5Z_filter_t filter) FUNC_ENTER_NOAPI(FAIL) /* Check args */ - HDassert (pline); - HDassert (filter >= 0 && filter <= H5Z_FILTER_MAX); + HDassert(pline); + HDassert(filter >= 0 && filter <= H5Z_FILTER_MAX); /* if the pipeline has no filters, just return */ if (pline->nused == 0) @@ -1470,7 +1472,7 @@ H5Z_delete(H5O_pline_t *pline, H5Z_filter_t filter) if (H5Z_FILTER_ALL == filter) { if (H5O_msg_reset(H5O_PLINE_ID, pline) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTFREE, FAIL, "can't release pipeline info") - } /* end if */ + } /* Delete filter */ else { size_t idx; /* Index of filter in pipeline */ @@ -1481,7 +1483,7 @@ H5Z_delete(H5O_pline_t *pline, H5Z_filter_t filter) if (pline->filter[idx].id == filter) { found = TRUE; break; - } /* end if */ + } /* filter was not found in the pipeline */ if (!found) @@ -1489,11 +1491,11 @@ H5Z_delete(H5O_pline_t *pline, H5Z_filter_t filter) /* Free information for deleted filter */ if (pline->filter[idx].name && pline->filter[idx].name != pline->filter[idx]._name) - HDassert ((HDstrlen(pline->filter[idx].name) + 1) > H5Z_COMMON_NAME_LEN); + HDassert((HDstrlen(pline->filter[idx].name) + 1) > H5Z_COMMON_NAME_LEN); if (pline->filter[idx].name != pline->filter[idx]._name) pline->filter[idx].name = (char *)H5MM_xfree(pline->filter[idx].name); if (pline->filter[idx].cd_values && pline->filter[idx].cd_values != pline->filter[idx]._cd_values) - HDassert (pline->filter[idx].cd_nelmts > H5Z_COMMON_CD_VALUES); + HDassert(pline->filter[idx].cd_nelmts > H5Z_COMMON_CD_VALUES); if (pline->filter[idx].cd_values != pline->filter[idx]._cd_values) pline->filter[idx].cd_values = (unsigned *)H5MM_xfree(pline->filter[idx].cd_values); @@ -1506,8 +1508,8 @@ H5Z_delete(H5O_pline_t *pline, H5Z_filter_t filter) pline->filter[idx].name = pline->filter[idx]._name; if (pline->filter[idx].cd_nelmts <= H5Z_COMMON_CD_VALUES) pline->filter[idx].cd_values = pline->filter[idx]._cd_values; - } /* end for */ - } /* end if */ + } + } /* Decrement number of used filters */ pline->nused--; diff --git a/src/H5Zpublic.h b/src/H5Zpublic.h index f6b313e..fcb2d37 100644 --- a/src/H5Zpublic.h +++ b/src/H5Zpublic.h @@ -129,8 +129,8 @@ typedef H5Z_cb_return_t (*H5Z_filter_func_t)(H5Z_filter_t filter, void* buf, /* Structure for filter callback property */ typedef struct H5Z_cb_t { - H5Z_filter_func_t func; - void* op_data; + H5Z_filter_func_t func; + void *op_data; } H5Z_cb_t; #ifdef __cplusplus @@ -206,14 +206,14 @@ typedef size_t (*H5Z_func_t)(unsigned int flags, size_t cd_nelmts, * contain a pointers to the filter function and timing statistics. */ typedef struct H5Z_class2_t { - int version; /* Version number of the H5Z_class_t struct */ - H5Z_filter_t id; /* Filter ID number */ - unsigned encoder_present; /* Does this filter have an encoder? */ - unsigned decoder_present; /* Does this filter have a decoder? */ - const char *name; /* Comment for debugging */ - H5Z_can_apply_func_t can_apply; /* The "can apply" callback for a filter */ - H5Z_set_local_func_t set_local; /* The "set local" callback for a filter */ - H5Z_func_t filter; /* The actual filter function */ + int version; /* Version number of the H5Z_class_t struct */ + H5Z_filter_t id; /* Filter ID number */ + unsigned encoder_present; /* Does this filter have an encoder? */ + unsigned decoder_present; /* Does this filter have a decoder? */ + const char *name; /* Comment for debugging */ + H5Z_can_apply_func_t can_apply; /* The "can apply" callback for a filter */ + H5Z_set_local_func_t set_local; /* The "set local" callback for a filter */ + H5Z_func_t filter; /* The actual filter function */ } H5Z_class2_t; H5_DLL herr_t H5Zregister(const void *cls); -- cgit v0.12 From 22e58124ec26da5ffe2833f53c8d73ee9edf0570 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Tue, 21 Nov 2017 13:20:33 -0800 Subject: Made a dcpl layout struct in H5Z.c dynamic to quiet a stack size warning. --- src/H5Z.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/H5Z.c b/src/H5Z.c index 89c97d4..6f173b2 100644 --- a/src/H5Z.c +++ b/src/H5Z.c @@ -752,6 +752,7 @@ static herr_t H5Z_prepare_prelude_callback_dcpl(hid_t dcpl_id, hid_t type_id, H5Z_prelude_type_t prelude_type) { hid_t space_id = -1; /* ID for dataspace describing chunk */ + H5O_layout_t *dcpl_layout = NULL; /* Dataset's layout information */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -761,19 +762,22 @@ H5Z_prepare_prelude_callback_dcpl(hid_t dcpl_id, hid_t type_id, H5Z_prelude_type /* Check if the property list is non-default */ if (dcpl_id != H5P_DATASET_CREATE_DEFAULT) { - H5P_genplist_t *dc_plist; /* Dataset creation property list object */ - H5O_layout_t dcpl_layout; /* Dataset's layout information */ + H5P_genplist_t *dc_plist; /* Dataset creation property list object */ + + /* Get memory for the layout */ + if (NULL == (dcpl_layout = (H5O_layout_t *)H5MM_calloc(sizeof(H5O_layout_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate dcpl layout buffer") /* Get dataset creation property list object */ if (NULL == (dc_plist = (H5P_genplist_t *)H5I_object(dcpl_id))) HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "can't get dataset creation property list") /* Peek at the layout information */ - if (H5P_peek(dc_plist, H5D_CRT_LAYOUT_NAME, &dcpl_layout) < 0) + if (H5P_peek(dc_plist, H5D_CRT_LAYOUT_NAME, dcpl_layout) < 0) HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "can't retrieve layout") /* Check if the dataset is chunked */ - if (H5D_CHUNKED == dcpl_layout.type) { + if (H5D_CHUNKED == dcpl_layout->type) { H5O_pline_t dcpl_pline; /* Object's I/O pipeline information */ /* Get I/O pipeline information */ @@ -787,28 +791,31 @@ H5Z_prepare_prelude_callback_dcpl(hid_t dcpl_id, hid_t type_id, H5Z_prelude_type size_t u; /* Local index variable */ /* Create a dataspace for a chunk & set the extent */ - for (u = 0; u < dcpl_layout.u.chunk.ndims; u++) - chunk_dims[u] = dcpl_layout.u.chunk.dim[u]; - if (NULL == (space = H5S_create_simple(dcpl_layout.u.chunk.ndims, chunk_dims, NULL))) + for (u = 0; u < dcpl_layout->u.chunk.ndims; u++) + chunk_dims[u] = dcpl_layout->u.chunk.dim[u]; + if (NULL == (space = H5S_create_simple(dcpl_layout->u.chunk.ndims, chunk_dims, NULL))) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create simple dataspace") /* Get ID for dataspace to pass to filter routines */ if ((space_id = H5I_register(H5I_DATASPACE, space, FALSE)) < 0) { - (void)H5S_close (space); + (void)H5S_close(space); HGOTO_ERROR (H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace ID") - } /* end if */ + } /* Make the callbacks */ if (H5Z_prelude_callback(&dcpl_pline, dcpl_id, type_id, space_id, prelude_type) < 0) HGOTO_ERROR (H5E_PLINE, H5E_CANAPPLY, FAIL, "unable to apply filter") - } /* end if */ - } /* end if */ - } /* end if */ + } + } + } done: if (space_id > 0 && H5I_dec_ref(space_id) < 0) HDONE_ERROR(H5E_PLINE, H5E_CANTRELEASE, FAIL, "unable to close dataspace") + if (dcpl_layout) + dcpl_layout = (H5O_layout_t *)H5MM_xfree(dcpl_layout); + FUNC_LEAVE_NOAPI(ret_value) } /* end H5Z_prepare_prelude_callback_dcpl() */ -- cgit v0.12