2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
9 * $Id: exc.h,v 1.23 2001/06/07 20:04:53 ca Exp $
13 ** libsm exception handling
14 ** See libsm/exc.html for documentation.
20 #include <sm/setjmp.h>
23 #include <sm/assert.h>
25 typedef struct sm_exc SM_EXC_T
;
26 typedef struct sm_exc_type SM_EXC_TYPE_T
;
27 typedef union sm_val SM_VAL_T
;
33 extern const char SmExcTypeMagic
[];
38 const char *etype_category
;
39 const char *etype_argformat
;
40 void (*etype_print
) __P((SM_EXC_T
*, SM_FILE_T
*));
41 const char *etype_printcontext
;
44 extern const SM_EXC_TYPE_T SmEtypeOs
;
45 extern const SM_EXC_TYPE_T SmEtypeErr
;
56 extern const char SmExcMagic
[];
70 const SM_EXC_TYPE_T
*exc_type
;
74 # define SM_EXC_INITIALIZER(type, argv) \
84 const SM_EXC_TYPE_T
*_type
,
98 const char *_pattern
));
103 SM_FILE_T
*_stream
));
108 SM_FILE_T
*_stream
));
115 sm_exc_raisenew_x
__P((
116 const SM_EXC_TYPE_T
*_type
,
120 ** Exception handling
123 typedef void (*SM_EXC_DEFAULT_HANDLER_T
) __P((SM_EXC_T
*));
126 sm_exc_newthread
__P((
127 SM_EXC_DEFAULT_HANDLER_T _handle
));
129 typedef struct sm_exc_handler SM_EXC_HANDLER_T
;
130 struct sm_exc_handler
133 SM_JMPBUF_T eh_context
;
134 SM_EXC_HANDLER_T
*eh_parent
;
138 /* values for eh_state */
146 extern SM_EXC_HANDLER_T
*SmExcHandler
;
148 # define SM_TRY { SM_EXC_HANDLER_T _h; \
150 _h.eh_value = NULL; \
151 _h.eh_parent = SmExcHandler; \
152 _h.eh_state = SM_EH_PUSHED; \
153 SmExcHandler = &_h; \
154 if (sm_setjmp_nosig(_h.eh_context) == 0) {
156 # define SM_FINALLY SM_ASSERT(SmExcHandler == &_h); \
158 if (sm_setjmp_nosig(_h.eh_context) == 0) {
160 # define SM_EXCEPT(e,pat) } \
161 if (_h.eh_state == SM_EH_HANDLED) \
163 if (_h.eh_state == SM_EH_PUSHED) { \
164 SM_ASSERT(SmExcHandler == &_h); \
165 SmExcHandler = _h.eh_parent; \
167 _h.eh_state = sm_exc_match(_h.eh_value,pat) \
168 ? SM_EH_HANDLED : SM_EH_POPPED; \
169 if (_h.eh_state == SM_EH_HANDLED) { \
170 SM_UNUSED(SM_EXC_T *e) = _h.eh_value;
172 # define SM_END_TRY } \
174 if (_h.eh_state == SM_EH_PUSHED) { \
175 SM_ASSERT(SmExcHandler == &_h); \
176 SmExcHandler = _h.eh_parent; \
177 if (_h.eh_value != NULL) \
178 sm_exc_raise_x(_h.eh_value); \
179 } else if (_h.eh_state == SM_EH_POPPED) { \
180 if (_h.eh_value != NULL) \
181 sm_exc_raise_x(_h.eh_value); \
183 sm_exc_free(_h.eh_value); \
186 #endif /* SM_EXC_H */