Files
hdf5/tools/lib/h5tools_error.h
Larry Knox e2c47ffb01 Merge1 issue 839 PRs to hdf5 1 12 (#904)
* Fixes for a couple of trivial warnings (#676)

* Committing clang-format changes

* Trivial warning fixes:

* Removes an unused done target in H5Tbit.c
* Add (void) to quiet "ignored return value" warnings in the generators
  (which generally ignore errors)

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Removes alternative function enter/leave macro scheme (#678)

* Committing clang-format changes

* Converted BEGIN_FUNC, etc. macros to FUNC_ENTER

* Rips out the BEGIN_FUNC, etc. macros

* Removes 'end if', etc. comments from H5HL package

* Committing clang-format changes

* Fixes an H5EA iterate issue

* Fixes an issue in the H5FA iterator code

* Further cleanup in bin/trace after macro removal

* Iterator changes in H5EA and H5FA

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Various CMake changes (#679)

* Committing clang-format changes

* Several CMake updates:

* Removes unused HDF5_ENABLE_HSIZET
* Switches TEST_SHELL_SCRIPTS to ON
* Sets SH_PROGRAM to bash instead of sh

* Set default build type back to RelWithDebInfo

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* err_compat test cleanup (#681)

* Committing clang-format changes

* Cleans up err_compat test and output

* Formatted source

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* CMake fix for sporadic flush2 failures (#692)

* Committing clang-format changes

* Runs the flush1/flush2 tests in their own directory

Avoids file deletions by other tests.

* Revert "Runs the flush1/flush2 tests in their own directory"

This reverts commit 746c048824.

Also pulls the flush files from the clean list, which is a simpler fix.

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Ubsan fixes (#498)

* Fixed use of null pointer identified by UBSan

UBSan warned:
runtime error: member access within null pointer of type 'named_dt_t' (aka 'struct named_dt_t')

with these two tests:
H5REPACK-committed_dt_DFF
H5REPACK-committed_dt

Reformulated per @gnuoyd suggestion.

* Fixed undefined float -> unsigned char conversion in HL_test_image

* Removed dead skip_overflow_tests_g global

The global `skip_overflow_tests_g` was being set but never read.

* Don't treat 2d array as 1d array, fixing UBSan complaint in `CPP_testhdf5`

* Committing clang-format changes

* Remove extra ']' in line 730.

* Committing clang-format changes

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Larry Knox <lrknox@hdfgroup.org>

* BUG: DataSet assignment operator is missing (#503)

* BUG: DataSet assignment operator is missing

* Some compilers complain if the copy constructor is given explicitly
  but the assignment operator is implicitly set to default.

* Explicitly defining the assignment operator allows us to properly
  handle reference counters for shared resources.

* BUG: DataSet assignment operator is missing.

* Mimicking code of H5DataType::operator() as suggested by @bmribler.

* Added test

Description:
    Added test for DataSet::operator= that Leengit added
Platform tested:
    Linux/64 (jelly)

* Removed Author field.

* Commit clang format changes.

* Entry for Leengit's github PR #503

* Removed lines left by mistake

Co-authored-by: Binh-Minh Ribler <bmribler@hdfgroup.org>
Co-authored-by: Larry Knox <lrknox@hdfgroup.org>

* Hdf5 merge pr7 (#516)

* Modify temporary rpath for testing in java example scripts.

* Update URL in source file Copyright headers for web copy of COPYING (license) file.

* Add release_docs/code-conventions.md file.

* Add script to test h5py.

* Fix script error.

* Add file h5pytest.yml.

* Test declaration of counter variables in for loops.

* Committing clang-format changes

* Committing clang-format changes

* Added [] to line 126 of H5LTanalyze.l.
Ran bin/genparser with flex v2.6.4 and Bison v3.0.4 on jelly.

* Revert "Added [] to line 126 of H5LTanalyze.l."

This reverts commit e4a9cee441.

* Revert extra commits to match canonical develop.

* Add cmake variable HDF5_LIB_INFIX (#7)

* Add cmake variable HDF5_LIB_INFIX

This infix is added to all library names after 'hdf5'.
e.g. the infix '_openmpi' results in the library name 'libhdf5_openmpi.so'
This name is used in packages on debian based systems.
(see https://packages.debian.org/jessie/amd64/libhdf5-openmpi-8/filelist)

This option is useful when testing projects on debian based systems with
custom builds of hdf5 while trying to minimize differences between the
custom setup and the environment created by installing system packages.

* Added RELEASE.txt entry for HDF5_LIB_INFIX.

Co-authored-by: Larry Knox <lrknox@hdfgroup.org>

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Raphael Grimm <barcode@users.noreply.github.com>

* Fixes a segfault when H5Pset_mdc_log_options is called multiple times on a fapl (#601)

* Committing clang-format changes

* Fixes a segfault when H5Pset_mdc_log_options() is called multiple times

An internal string is incorrectly freed when the API call is invoked
multiple times on a property list, which will usually cause a segfault
to occur. On the first call the log location is NULL so the problem
doesn't occur.

Fixes HDFFV-11239

* Fixes typos

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Fix for a segfault when H5Pset_fapl_log is passed an invalid fapl ID (#607)

* Committing clang-format changes

* Fixes an issue where H5Pset_fapl_log sefaults when passed an invalid
fapl ID

This was due to a pointer-containing struct being memset after the first
internal API call. If the first call failed, the error condition would
check if the pointer was not NULL and then attempt to free it if not.
This would lead to the freeing of a wild pointer if an invalid fapl ID
were passed in.

This was fixed by reordering the memset and adding a test to ensure the
problem stays fixed.

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Fixes crashes when size_hint > UINT32_MAX is passed to H5Gcreate1 (#611)

* Committing clang-format changes

* Fixes incorrect size_hint handling in H5Gcreate1

* Updates the size hint type for group creation

* Updates the RELEASE.txt note

* Revert "Updates the RELEASE.txt note"

This reverts commit 3df386acca.

* Reverts previous behavior to use a uint32_t struct field

* Updates RELEASE.txt

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

Co-authored-by: Dana Robinson <43805+derobins@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Sean McBride <sean@rogue-research.com>
Co-authored-by: Lee Newberg <35611400+Leengit@users.noreply.github.com>
Co-authored-by: Binh-Minh Ribler <bmribler@hdfgroup.org>
Co-authored-by: Raphael Grimm <barcode@users.noreply.github.com>
2021-08-12 13:26:15 -05:00

254 lines
17 KiB
C

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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 COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Header file for error values, etc.
*/
#ifndef H5TOOLS_ERROR_H
#define H5TOOLS_ERROR_H
#include "H5Epublic.h"
#include "H5Eprivate.h" /* Error handling */
/* tools-HDF5 Error variables */
H5TOOLS_DLLVAR int H5tools_INDENT_g;
H5TOOLS_DLLVAR hid_t H5tools_ERR_STACK_g;
H5TOOLS_DLLVAR hid_t H5tools_ERR_CLS_g;
H5TOOLS_DLLVAR hid_t H5E_tools_g;
H5TOOLS_DLLVAR hid_t H5E_tools_min_id_g;
H5TOOLS_DLLVAR hid_t H5E_tools_min_info_id_g;
H5TOOLS_DLLVAR hid_t H5E_tools_min_dbg_id_g;
/* Use FUNC to safely handle variations of C99 __func__ keyword handling */
#ifdef H5_HAVE_C99_FUNC
#define FUNC __func__
#elif defined(H5_HAVE_FUNCTION)
#define FUNC __FUNCTION__
#else
#error "We need __func__ or __FUNCTION__ to test function names!"
#endif
/*
* H5TOOLS_INIT_ERROR macro, used to initialize error reporting.
*/
#define H5TOOLS_INIT_ERROR() \
do { \
char lib_str[256]; \
\
/* Initialize library version string for error class */ \
HDsnprintf(lib_str, sizeof(lib_str), "%d.%d.%d", H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE); \
\
/* Create new HDF5 error stack for the tools to use */ \
if ((H5tools_ERR_STACK_g = H5Ecreate_stack()) < 0) \
HDfprintf(stderr, "Failed to create HDF5 tools error stack\n"); \
\
/* Register errors from the HDF5 tools as a new error class */ \
if ((H5tools_ERR_CLS_g = H5Eregister_class("H5tools", "HDF5:tools", lib_str)) < 0) \
HDfprintf(stderr, "Failed to register HDF5 tools error class\n"); \
\
/* Create a new HDF5 major error message for errors from the tools library */ \
if ((H5E_tools_g = H5Ecreate_msg(H5tools_ERR_CLS_g, H5E_MAJOR, "Failure in tools library")) < 0) \
HDfprintf(stderr, "Failed to register major error message for tools library errors\n"); \
\
/* Create a new HDF5 minor error message for errors from the tools library */ \
if ((H5E_tools_min_id_g = H5Ecreate_msg(H5tools_ERR_CLS_g, H5E_MINOR, "error in function")) < 0) \
HDfprintf(stderr, "Failed to register minor error message for tools library errors\n"); \
\
/* Create a new HDF5 minor error message for info messages from the tools library */ \
if ((H5E_tools_min_info_id_g = H5Ecreate_msg(H5tools_ERR_CLS_g, H5E_MINOR, "function info")) < 0) \
HDfprintf(stderr, "Failed to register minor error message for tools library info messages\n"); \
\
/* Create a new HDF5 minor error message for debug messages from the tools library */ \
if ((H5E_tools_min_dbg_id_g = H5Ecreate_msg(H5tools_ERR_CLS_g, H5E_MINOR, "function debug")) < 0) \
HDfprintf(stderr, "Failed to register minor error message for tools library debug messages\n"); \
} while (0)
/*
* H5TOOLS_CLOSE_ERROR macro, used to terminate error reporting.
*/
#define H5TOOLS_CLOSE_ERROR() \
do { \
/* Close all error messages created by H5TOOLS_INIT_ERROR() */ \
if (H5Eclose_msg(H5E_tools_min_dbg_id_g) < 0) \
HDfprintf(stderr, "Failed to close minor error message for tools library debug messages\n"); \
if (H5Eclose_msg(H5E_tools_min_info_id_g) < 0) \
HDfprintf(stderr, "Failed to close minor error message for tools library info messages\n"); \
if (H5Eclose_msg(H5E_tools_min_id_g) < 0) \
HDfprintf(stderr, "Failed to close minor error message for tools library errors\n"); \
if (H5Eclose_msg(H5E_tools_g) < 0) \
HDfprintf(stderr, "Failed to close major error message for tools library errors\n"); \
\
/* Unregister the HDF5 tools error class */ \
if (H5Eunregister_class(H5tools_ERR_CLS_g) < 0) \
HDfprintf(stderr, "Failed to unregister the HDF5 tools error class\n"); \
\
/* Close the tools error stack */ \
if (H5Eclose_stack(H5tools_ERR_STACK_g) < 0) \
HDfprintf(stderr, "Failed to close HDF5 tools error stack\n"); \
} while (0)
/*
* H5TOOLS_PUSH_ERROR macro, used to push an error to an error stack. Not meant to
* be called directly.
*/
#define H5TOOLS_PUSH_ERROR(estack_id, err_cls, maj_err_id, min_err_id, ...) \
do { \
if (enable_error_stack > 0) { \
if (estack_id >= 0 && err_cls >= 0) \
H5Epush2(estack_id, __FILE__, FUNC, __LINE__, err_cls, maj_err_id, min_err_id, __VA_ARGS__); \
else { \
HDfprintf(stderr, __VA_ARGS__); \
HDfprintf(stderr, "\n"); \
} \
} \
} while (0)
/*
* H5TOOLS_ERROR macro, used to facilitate error reporting within a function body.
* The arguments are the return value and an error string. The return value is assigned
* to a variable `ret_value'. This macro is meant to be used for reporting an error without
* having control branch to the `done' label. This is often used when an error occurs
* after the `done' label, in which case an infinite loop would ensue if control branched
* backwards.
*/
#define H5TOOLS_ERROR(ret_val, ...) \
do { \
H5TOOLS_PUSH_ERROR(H5tools_ERR_STACK_g, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_id_g, \
__VA_ARGS__); \
ret_value = ret_val; \
} while (0)
/*
* H5TOOLS_GOTO_ERROR macro, used to facilitate error reporting within a function body.
* The arguments are the return value and an error string. The return value is assigned
* to a variable `ret_value' and control branches to the `done' label.
*/
#define H5TOOLS_GOTO_ERROR(ret_val, ...) \
do { \
H5TOOLS_PUSH_ERROR(H5tools_ERR_STACK_g, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_id_g, \
__VA_ARGS__); \
H5TOOLS_GOTO_DONE(ret_val); \
} while (0)
/*
* H5TOOLS_GOTO_DONE macro, used to facilitate normal return within a function body.
* The argument is the return value which is assigned to the `ret_value'
* variable. Control branches to the `done' label.
*/
#define H5TOOLS_GOTO_DONE(ret_val) \
do { \
ret_value = ret_val; \
goto done; \
} while (0)
/*
* H5TOOLS_GOTO_DONE_NO_RET macro, used to facilitate normal return within a function body.
* Control simply branches to the `done' label without setting any return value.
*/
#define H5TOOLS_GOTO_DONE_NO_RET() \
do { \
goto done; \
} while (0)
/*
* H5TOOLS_INFO macro, used to facilitate error reporting. The arguments are
* a description of the error.
*/
#define H5TOOLS_INFO(...) \
do { \
H5TOOLS_PUSH_ERROR(H5tools_ERR_STACK_g, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_info_id_g, \
__VA_ARGS__); \
} while (0)
#ifdef H5_TOOLS_DEBUG
#define H5TOOLS_START_DEBUG(...) \
do { \
H5tools_INDENT_g += 2; \
HDfprintf(stderr, "%*sENTER %s:%d in %s()...", H5tools_INDENT_g, "", __FILE__, __LINE__, FUNC); \
HDfprintf(stderr, __VA_ARGS__); \
HDfprintf(stderr, "\n"); \
HDfflush(stderr); \
} while (0)
#define H5TOOLS_DEBUG(...) \
do { \
HDfprintf(stderr, "%*s %s:%d in %s()...", H5tools_INDENT_g, "", __FILE__, __LINE__, FUNC); \
HDfprintf(stderr, __VA_ARGS__); \
HDfprintf(stderr, "\n"); \
HDfflush(stderr); \
} while (0)
#define H5TOOLS_ENDDEBUG(...) \
do { \
HDfprintf(stderr, "%*sEXIT %s:%d in %s()...", H5tools_INDENT_g, "", __FILE__, __LINE__, FUNC); \
HDfprintf(stderr, __VA_ARGS__); \
HDfprintf(stderr, "\n"); \
H5tools_INDENT_g -= 2; \
HDfflush(stderr); \
} while (0)
#else
#define H5TOOLS_START_DEBUG(...) \
do { \
; \
} while (0)
#define H5TOOLS_DEBUG(...) \
do { \
; \
} while (0)
#define H5TOOLS_ENDDEBUG(...) \
do { \
; \
} while (0)
#endif
/* Macro for "catching" flow of control when an error occurs. Note that the
* H5_LEAVE macro won't jump back here once it's past this point.
*/
#define CATCH \
catch_except:; \
past_catch = TRUE;
/*
* H5_LEAVE macro, used to facilitate control flow in a function. The argument
* is the return value. The return value is assigned to a variable `ret_value'
* and control branches to the `catch_except' label, if we're not already past
* it.
*/
#define H5_LEAVE(v) \
{ \
ret_value = v; \
if (!past_catch) \
goto catch_except; \
}
/*
* H5TOOLS_THROW macro, used to facilitate error reporting within a function body.
* The arguments are the minor error number, and an error string.
* The return value is assigned to a variable `ret_value' and control branches
* to the `catch_except' label, if we're not already past it.
*/
#define H5TOOLS_THROW(ret_val, ...) \
do { \
H5TOOLS_PUSH_ERROR(H5tools_ERR_STACK_g, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_id_g, \
__VA_ARGS__); \
H5_LEAVE(ret_val) \
} while (0)
#endif /* H5TOOLS_ERROR_H */