2009-09-15 03:52:42 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
|
|
|
* the files COPYING and Copyright.html. COPYING can be found at the root *
|
|
|
|
* of the source code distribution tree; Copyright.html can be found at the *
|
|
|
|
* root level of an installed copy of the electronic HDF5 document set and *
|
|
|
|
* is linked from the top-level documents page. It can also be found at *
|
|
|
|
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
|
|
|
|
* access to either file, you may request a copy from help@hdfgroup.org. *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Header file for error values, etc.
|
|
|
|
*/
|
|
|
|
#ifndef H5TOOLS_ERROR_H_
|
|
|
|
#define H5TOOLS_ERROR_H_
|
|
|
|
|
|
|
|
#include "H5Epublic.h"
|
|
|
|
|
|
|
|
/* tools-HDF5 Error variables */
|
2012-03-13 00:33:15 +08:00
|
|
|
H5TOOLS_DLLVAR hid_t H5tools_ERR_STACK_g;
|
2010-05-12 04:10:25 +08:00
|
|
|
H5TOOLS_DLLVAR hid_t H5tools_ERR_CLS_g;
|
|
|
|
H5TOOLS_DLLVAR hid_t H5E_tools_g;
|
|
|
|
H5TOOLS_DLLVAR hid_t H5E_tools_min_id_g;
|
2009-09-15 03:52:42 +08:00
|
|
|
|
|
|
|
/* 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() { \
|
|
|
|
H5tools_ERR_CLS_g = H5Eregister_class("H5tools", "HDF5:tools", lib_str); \
|
|
|
|
H5E_tools_g= H5Ecreate_msg(H5tools_ERR_CLS_g, H5E_MAJOR, "Failure in tools library"); \
|
|
|
|
H5E_tools_min_id_g = H5Ecreate_msg(H5tools_ERR_CLS_g, H5E_MINOR, "error in function"); \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* H5TOOLS_CLOSE_ERROR macro, used to initialize error reporting.
|
|
|
|
*/
|
|
|
|
#define H5TOOLS_CLOSE_ERROR() { \
|
|
|
|
H5Eclose_msg(H5E_tools_min_id_g); \
|
|
|
|
H5Eclose_msg(H5E_tools_g); \
|
|
|
|
H5Eunregister_class(H5tools_ERR_CLS_g); \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HERR_INIT macro, used to facilitate error reporting. Declaration and assignments of error variables.
|
|
|
|
* Use at the beginning of a function using error handling macros.
|
|
|
|
*/
|
|
|
|
#define HERR_INIT(ret_typ, ret_init) \
|
|
|
|
hbool_t past_catch = FALSE; \
|
|
|
|
ret_typ ret_value = ret_init;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HERROR macro, used to facilitate error reporting . The arguments are the major
|
|
|
|
* error number, the minor error number, and a description of the error.
|
|
|
|
*/
|
2012-03-13 00:33:15 +08:00
|
|
|
#define HERROR(maj_id, min_id, str) { \
|
|
|
|
H5Epush2(H5tools_ERR_STACK_g, __FILE__, FUNC, __LINE__, H5tools_ERR_CLS_g, maj_id, min_id, str); \
|
|
|
|
ret_value = FAIL; \
|
|
|
|
}
|
|
|
|
|
2009-09-15 03:52:42 +08:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
[svn-r18109] Description:
Bring r18076-18096 from hdf5_1_8_coverity branch to trunk:
r18076:
Correct Coverity issue #1 by removing dead code
r18077:
Fix coverity item 142. When an error occurred while copying a linked list in
H5S_point_copy, the library would not free the partially allocated list. Added
code to free the list in this case.
r18078:
Correct Coverity issue #2 by removing impossible to reach code.
r18079:
Correct #3 by removing impossible to reach code.
r18080:
Correct Coverity issue #4 by removing impossible to reach code.
r18081:
fix coverity 26 , check (dblik->parent) before calls H5HF_man_iblock_detach().
r18082:
Fixed coverity issues 321 and 316.
321: freed sm_buf in error handling to remove resource leak.
Also set sm_buf to NULL after other instances in which
it is freed to prevent double free.
316: initialized nmembs to 0.
r18083:
Correct Coverity issue #6 by removing debugging knob from error reporting code.
r18084:
Fix coverity item 269 + others. When a error occurred in a function using the
h5tools error framework, the "past_catch" variable would not be set to true
because that statement was before the label that goto jumped to. This could
cause a failure in the cleanup section to go back to the start of the section,
freeing variables twice, etc.
Moved the label infront of past_catch=TRUE.
r18085:
fixed coverity #27, check if (heap) before use heap->obj....
r18086:
fixed coverity #28, check curr_span not null before use it at if(curr_span &&
(io_bytes_left==0 || curr_seq>=maxseq))
r18087:
Correct Coverity issue #7 by cleaning up correctly on error
r18088:
Correct Coverity #8 by removing unchanged variable checking code.
r18089:
Correct Coverity issue #9 - remove impossible to reach code.
r18090:
Correct Coverity issue #11 by removing impossible to reach code. Also clean
up some minor style issues.
r18091:
Fix coverity items 314 and 318. Changed the improper assertion of the return
value of a library function to a check, and a return(void) on failure.
r18092:
Fix coverity item 70. Changed the improper assertion of the return value of a
library function to a check, and a return(void) on failure.
r18093:
Correct Coverity issue #12 by removing dead code.
r18094:
Correct Coverity issue #16 by removing debugging code.
r18095:
Fixed coverity issue # 271.
Removed redundant checking and freeing of sm_buf1 and sm_buf2.
r18096:
Correct Coverity issue #17 by refactoring test to remove dead code.
Also, removed previous "coverity" statements in comments, we'll review
those issues again and see if we can figure them out, now that we have more
experience with Coverity.
Tested on:
Mac OS X/32 10.6.2 (amazon)
2010-01-15 11:05:59 +08:00
|
|
|
#define CATCH catch_except:; past_catch = TRUE;
|
2009-09-15 03:52:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* H5_LEAVE macro, used to facilitate control flow between a
|
|
|
|
* BEGIN_FUNC() and an END_FUNC() within a function body. 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; \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-01-30 12:29:13 +08:00
|
|
|
* H5E_THROW macro, used to facilitate error reporting within a function body.
|
2009-09-15 03:52:42 +08:00
|
|
|
* 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 H5E_THROW(fail_value, min_id, str) { \
|
|
|
|
HERROR(H5E_tools_g, min_id, str); \
|
|
|
|
H5_LEAVE(fail_value) \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HGOTO_ERROR macro, used to facilitate error reporting within a function body. The arguments are
|
|
|
|
* the major error number, the minor error number, 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 HGOTO_ERROR(fail_value, min_id, str) { \
|
|
|
|
HERROR(H5E_tools_g, min_id, str); \
|
|
|
|
HGOTO_DONE(fail_value) \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-01-30 12:29:13 +08:00
|
|
|
* HGOTO_DONE macro, used to facilitate normal return within a function body.
|
|
|
|
* The argument is the return value which is assigned to the `ret_value'
|
2009-09-15 03:52:42 +08:00
|
|
|
* variable. Control branches to the `done' label.
|
|
|
|
*/
|
|
|
|
#define HGOTO_DONE(ret_val) {ret_value = ret_val; goto done;}
|
|
|
|
|
|
|
|
#endif /* H5TOOLS_ERROR_H_ */
|
2009-12-13 13:28:30 +08:00
|
|
|
|