📄 mwutil.h
字号:
* END_SETJMP
*
*
* case 2:
*
* BEGIN_SETJMP
*
* code that is always executed
*
* END_SETJMP
*
*/
#include <setjmp.h>
#include <string.h>
extern void utResetFPU(void);
#ifdef UNIX
/*
* Save signal masks as part of our context
*/
typedef sigjmp_buf ut_jmp_buf;
#define ut_setjmp(env) sigsetjmp(env,1)
#define ut_longjmp(env,val) (utResetFPU(), siglongjmp(env,val))
#else
/*
* Plain vanilla setjmp
*/
typedef jmp_buf ut_jmp_buf;
#define ut_setjmp(env) setjmp(env)
#define ut_longjmp(env,val) (utResetFPU(), longjmp(env,val))
#endif
#define BEGIN_SETJMP \
{ \
ut_jmp_buf local_copy; \
ExceptionFcn local_fcn; \
local_fcn = utSetExceptionFcn(utLongjmpFcn); \
\
ut_prevent_further_cleanup( utGetErrorContext() ) \
(void)memcpy(&local_copy, utGetSetjmpData(), sizeof(ut_jmp_buf)); \
\
if (!ut_setjmp(*utGetSetjmpData())) {
#define ELSE_SETJMP \
\
} else {
#define END_SETJMP \
\
} \
utSetExceptionFcn(local_fcn); \
ut_allow_further_cleanup( utGetErrorContext() ) \
(void)memcpy(utGetSetjmpData(), &local_copy, sizeof(ut_jmp_buf)); \
}
#define BEGIN_SETJUMP BEGIN_SETJMP
#define ELSE_SETJUMP ELSE_SETJMP
#define END_SETJUMP END_SETJMP
typedef void(*ExceptionFcn)(void *);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* exception_typedefs_h */
/* $Revision: 1.17 $ */
#ifndef err_typedefs_h
#define err_typedefs_h
#ifndef exception_typedefs_h
#include "exception_typedefs.h"
#endif
#define err_INDEX 1
#define err_message_mnemonics(X) X(ASSERTION_FAULT) X(INCORRECT_MAGIC) \
X(ERR_RETHROW) X(ERR_SIGNAL_INTERRUPT)
ut_define_module_mnemonics(err);
#define ERR_NO_ERROR 0
/* types */
typedef void (*fn_protectv)(void *);
typedef void (*fn_protectxv)( void *, void *);
#define ut_declare_protect_function(f, t) void (*f)(t)
#define ut_declare_protectx_function(f, t1, t2) void (*f)(t1, t2)
#define _protect_list_common_fields(t) \
struct _generic_protect_list *next; /* should come first for more efficient reference */ \
t *p;
#define _protect_list_common( t, t1) { \
_protect_list_common_fields(t) \
ut_declare_protect_function(f, t1); \
}
typedef struct _generic_protect_list _protect_list_common( void *, void *)
*generic_protect_list;
#define _protect_list(t, t1) struct _protect_list_common( t, t1)
/* The f field is deliberately put in a different position in the the following type,
to maximize catastrophe if the wrong type is used. */
#define _protectx_list(t, t1, t2) struct { \
_protect_list_common_fields(t) \
t1 x; /* the first argument to f */ \
ut_declare_protectx_function(f, t1, t2); \
}
typedef _protectx_list(void *, void *, void *) *generic_protectx_list;
typedef void (*fn_error_handler)(void *x, int status);
typedef struct _error_context {
generic_protect_list top; /* should come first for more efficient reference */
struct _try_catch_list *try_catch_top;
struct _try_catch_list *active_catch;
message_context msg;
fn_putsn putsn;
void *x; /* the first argument to putsn */
fn_error_handler error_handler;
void *xerr; /* The first argument to error_handler */
} _error_context, *error_context;
typedef void (*try_function)(error_context err, void *p);
typedef int (*catch_function)(error_context err, void *p, message_code code, va_list ap);
typedef struct _try_catch_list {
struct _try_catch_list *next;
generic_protect_list top;
void *p;
catch_function catch_fcn;
message_code code;
ut_jmp_buf label; /* Label must go away when longjump's are purged */
} _try_catch_list;
typedef _try_catch_list *try_catch_list;
/* macros */
#define ut_errassertalways(err, condition) (condition) ? (void)0 : ut_fault(err, #condition, __FILE__, __LINE__)
#ifndef NDEBUG
#define ut_assert_fault(err, condition) ut_fault(err, condition, __FILE__, __LINE__)
#define ut_errassert(err, condition) (condition) ? (void)0 : ut_assert_fault(err, #condition)
#define NNDEBUGC(X) X,
#define NNDEBUG(X) X
#define YNDEBUG(X)
#define YNNDEBUG(X)
#else
#define ut_assert_fault(err, condition) ((void) err)
#define ut_errassert( err, condition ) ((void) err)
#define NNDEBUGC(X)
#define NNDEBUG(X)
#define YNDEBUG(X) X
#define YNNDEBUG(X) X,
#endif
#if (defined(DEBUG) || (defined(DEBUG_ERROR_CONTEXT) && DEBUG_ERROR_CONTEXT != 0))
#undef DEBUG_ERROR_CONTEXT
#define DEBUG_ERROR_CONTEXT(X) X
#else
#undef DEBUG_ERROR_CONTEXT
#define DEBUG_ERROR_CONTEXT(X)
#endif
#define _protect_value_common(err, type, value, protectfn, _list, tag) \
typedef void (*ut_fn_protect_##tag)(type); \
DEBUG_ERROR_CONTEXT(generic_protect_list _local_top##tag;) \
_list _error_context_link##tag; \
_error_context_link##tag.next = (err)->top; \
_error_context_link##tag.p = value; \
ut_errassert(err, sizeof(type)==sizeof(void *)); \
_error_context_link##tag.f = protectfn;
#define _protect_common(err, type, name, value, protectfn, _list, tag) \
type name = value; \
_protect_value_common(err, type, &name, protectfn, _list, tag)
#define LOCAL_TOP(tag) DEBUG_ERROR_CONTEXT(_local_top##tag =)
#define ut_protect(err, type, name, value, protectfn) { \
_protect_common(err, type, name, value, protectfn, _protect_list(type, type), name ) \
(err)->top = LOCAL_TOP(name) (generic_protect_list)&_error_context_link##name;
#define ut_protectv(err, type, name, value, protectfn) { \
_protect_common(err, type, name, value, protectfn, _protect_list(type, void *), name ) \
(err)->top = LOCAL_TOP(name) (generic_protect_list)&_error_context_link##name;
#define ut_protectx(err, type, name, value, protectfn, typex, protectx) { \
_protect_common(err, type, name, value, \
protectfn, _protectx_list(type, typex, type),name) \
_error_context_link##name.x = protectx; \
(err)->top \
= LOCAL_TOP(name) (generic_protect_list)((unsigned long)&_error_context_link##name | 1);
#define ut_protectxv(err, type, name, value, protectfn, typex, protectx) { \
_protect_common(err, type, name, value, \
protectfn, _protectx_list(type, typex, void *), name) \
_error_context_link##name.x = protectx; \
(err)->top = LOCAL_TOP(name) \
(generic_protect_list)((unsigned long)&_error_context_link##name | 1);
#define ut_protect_value(err, type, value, protectfn) { \
_protect_value_common(err, type, &(value), protectfn, _protect_list(type, type), value ) \
(err)->top = LOCAL_TOP(value) (generic_protect_list)&_error_context_link##value;
#define ut_protectv_value(err, type, value, protectfn) { \
_protect_value_common(err, type, &(value), \
protectfn, _protect_list(type, void *), value ) \
(err)->top = LOCAL_TOP(value) (generic_protect_list)&_error_context_link##value;
#define ut_protectx_value(err, type, value, protectfn, typex, protectx) { \
_protect_value_common(err, type, &(value), protectfn, \
_protectx_list(type, typex, type), value) \
_error_context_link##value.x = protectx; \
(err)->top = LOCAL_TOP(value) \
(generic_protect_list)((unsigned long)&_error_context_link##value | 1);
#define ut_protectxv_value(err, type, value, protectfn, typex, protectx) { \
_protect_value_common(err, type, &(value), \
protectfn, _protectx_list(type, typex, void *), value) \
_error_context_link##value.x = protectx; \
(err)->top = LOCAL_TOP(value) \
(generic_protect_list)((unsigned long)&_error_context_link##value | 1);
#define ut_protect_value_tag(err, type, value, protectfn, tag) { \
_protect_value_common(err, type, &(value), protectfn, _protect_list(type, type), tag ) \
(err)->top = LOCAL_TOP(tag) (generic_protect_list)&_error_context_link##tag;
#define ut_protectv_value_tag(err, type, value, protectfn, tag) { \
_protect_value_common(err, type, &(value), protectfn, _protect_list(type, void *), tag ) \
(err)->top = LOCAL_TOP(tag) (generic_protect_list)&_error_context_link##tag;
#define ut_protectx_value_tag(err, type, value, protectfn, typex, protectx, tag) { \
_protect_value_common(err, type, &(value), \
protectfn, _protectx_list(type, typex, type), tag) \
_error_context_link##tag.x = protectx; \
(err)->top \
= LOCAL_TOP(tag) (generic_protect_list)((unsigned long)&_error_context_link##tag | 1);
#define ut_protectxv_value_tag(err, type, value, protectfn, typex, protectx, tag) { \
_protect_value_common(err, type, &(value), \
protectfn, _protectx_list(type, typex, void *), tag) \
_error_context_link##tag.x = protectx; \
(err)->top \
= LOCAL_TOP(tag) (generic_protect_list)((unsigned long)&_error_context_link##tag | 1);
#define ut_cast_to_generic_protectx_list(p) (generic_protectx_list)((unsigned long)(p) ^ 1)
#define ut_preserve(err,tag) (err)->top = (err)->top->next
#define ut_destroy(err,tag) { \
register error_context err_ = err; \
err_->top->f(*(err_->top->p)); \
ut_preserve(err_,tag); \
} (void)0
#define ut_preservex(err,tag) (err)->top = (ut_cast_to_generic_protectx_list((err)->top))->next
#define ut_destroyx(err,tag) { \
register generic_protectx_list px = ut_cast_to_generic_protectx_list((err)->top); \
(err)->top = px->next; \
px->f(px->x, *(px->p)); \
} (void)0
#define _fast_ut_preserve(err,tag)
#define _fast_ut_destroy(err,tag) _error_context_link##tag.f(*_error_context_link##tag.p);
#define _fast_ut_preservex(err,tag)
#define _fast_ut_destroyx(err,tag) \
_error_context_link##tag.f(_error_context_link##tag.x, *(_error_context_link##tag.p));
#define _incorrect_magic(err,tag) \
if (_local_top##tag != (err)->top) { \
(err)->top = _local_top##tag; \
ut_error(err, INCORRECT_MAGIC, __FILE__, __LINE__); \
}
#define ut_unprotect_unreachable }
#define ut_unprotect(err, tag, magic) \
DEBUG_ERROR_CONTEXT(_incorrect_magic(err,tag)) \
(err)->top = _error_context_link##tag.next; \
_fast_##magic(err,tag) \
}
#define ut_unprotect_and_return(err, tag, magic, expr) \
DEBUG_ERROR_CONTEXT(_incorrect_magic(err,tag)) \
(err)->top = _error_context_link##tag.next; \
_fast_##magic(err,tag) \
return expr; \
}
#define ut_protect_f _error_context_link.f
#define ut_prevent_further_cleanup(err) { \
_try_catch_list _link; \
ut_prevent_further_cleanup_fcn(err, &_link);
#define ut_allow_further_cleanup(err) \
ut_allow_further_cleanup_fcn(err, &_link); \
}
#endif /* err_typedefs_h */
#ifdef __cplusplus
extern "C" {
#endif
#include <limits.h>
typedef int FP_NumericFormat;
typedef int FP_ByteOrder;
#define FLITTLE_ENDIAN 0
#define FBIG_ENDIAN 1
#define ut_GET_LO(l,x) \
{ \
ieee_double_T d_u; \
d_u.value = (x); \
(l) = d_u.words.lw;\
}
#define ut_SET_LO(x,l) \
{ \
ieee_double_T d_u; \
d_u.value = (x); \
d_u.words.lw = (l);\
(x) = d_u.value; \
}
#define ut_SET_LOp(p,l)\
{ \
ieee_double_T d_u; \
d_u.value = *(p); \
d_u.words.lw = (l);\
*(p) = d_u.value; \
}
#define ut_GET_HI(h,x) \
{ \
ieee_double_T d_u; \
d_u.value = (x); \
(h) = d_u.words.hw;\
}
#define ut_SET_HI(x,h) \
{ \
ieee_double_T d_u; \
d_u.value = (x); \
d_u.words.hw = (h);\
(x) = d_u.value; \
}
#define ut_SET_HIp(p,h)\
{ \
ieee_double_T d_u; \
d_u.value = *(p); \
d_u.words.hw = (h);\
*(p) = d_u.value; \
}
#define ut_GET_BOTH(h,l,x)\
{ \
ieee_double_T d_u; \
d_u.value = (x); \
(h) = d_u.words.hw; \
(l) = d_u.words.lw; \
}
#define ut_SET_BOTH(x,h,l)\
{ \
ieee_double_T d_u; \
d_u.words.hw = (h); \
d_u.words.lw = (l); \
(x) = d_u.value; \
}
/* Macros to implement relational floating point comparisons
* with zeros when the comparee might be NaN.
* This is a work around for a PC compiler bug in both Microsoft VC++
* and WATCOM.
* -- CBM, 9/22/97.
*
* The comparsion values on the PC when the comparee is a NaN are:
*
* 1. NaN < 0 <== true
* 2. NaN <= 0 <== true
* 3. NaN > 0 <== false
* 4. NaN >= 0 <== false
* 5. NaN == 0 <== true
* 6. NaN != 0 <== false
*
* When comparing with NaNs, except the != operation all others should
* be false. However, this is not the case on the PC. So we have the
* following macros that work around this problem for cases 1,2,5 and 6.
* -- NBM 9/26/97
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -