head 1.28; access; symbols EX_1_0_6:1.28 LMTP2NNTP_1_4_1:1.26 LMTP2NNTP_1_4_0:1.26 EX_1_0_5:1.26 LMTP2NNTP_1_3_0:1.25 LMTP2NNTP_1_3b2:1.25 LMTP2NNTP_1_3b1:1.25 LMTP2NNTP_1_3a3:1.25 LMTP2NNTP_1_3a2:1.25 LMTP2NNTP_1_3a1:1.25 EX_1_0_4:1.25 EX_1_0_3:1.25 OSSP_RC_0_7_3:1.21 OSSP_RC_0_7_2:1.21 OSSP_RC_0_7_1:1.21 OSSP_RC_ALPHA_06:1.21 OSSP_RC_EXBROKEN:1.21 LMTP2NNTP_1_2_0:1.21 LMTP2NNTP_1_2b4:1.21 LMTP2NNTP_1_2b3:1.21 LMTP2NNTP_1_2b2:1.21 LMTP2NNTP_1_2b1:1.21 LMTP2NNTP_1_2a8:1.21 LMTP2NNTP_1_2a7:1.21 EX_1_0_2:1.21 EX_1_0_1:1.19 LMTP2NNTP_1_2a6:1.18 LMTP2NNTP_1_2a5:1.18 EX_1_0_0:1.18 LMTP2NNTP_1_2a4:1.17 EX_0_9_1:1.17 LMTP2NNTP_1_2a3:1.16 EX_0_9_0:1.14; locks; strict; comment @ * @; 1.28 date 2007.10.12.19.59.57; author rse; state Exp; branches; next 1.27; commitid 9SN7ivPOxnsC7lBs; 1.27 date 2006.08.10.19.49.33; author rse; state Exp; branches; next 1.26; commitid o4A6XFppdzD0PkIr; 1.26 date 2005.01.30.13.39.07; author rse; state Exp; branches; next 1.25; 1.25 date 2004.03.25.19.01.42; author rse; state Exp; branches; next 1.24; 1.24 date 2004.03.18.15.50.34; author rse; state Exp; branches; next 1.23; 1.23 date 2004.02.17.09.14.55; author thl; state Exp; branches; next 1.22; 1.22 date 2004.02.17.09.14.54; author thl; state Exp; branches; next 1.21; 1.21 date 2003.01.30.11.04.42; author rse; state Exp; branches; next 1.20; 1.20 date 2003.01.30.10.59.34; author rse; state Exp; branches; next 1.19; 1.19 date 2003.01.06.15.31.24; author rse; state Exp; branches; next 1.18; 1.18 date 2002.03.30.18.56.02; author rse; state Exp; branches; next 1.17; 1.17 date 2002.03.07.21.30.09; author rse; state Exp; branches; next 1.16; 1.16 date 2002.02.25.10.33.02; author rse; state Exp; branches; next 1.15; 1.15 date 2002.02.25.10.30.15; author rse; state Exp; branches; next 1.14; 1.14 date 2002.01.31.19.54.05; author rse; state Exp; branches; next 1.13; 1.13 date 2002.01.30.10.37.55; author rse; state Exp; branches; next 1.12; 1.12 date 2002.01.30.10.33.36; author rse; state Exp; branches; next 1.11; 1.11 date 2002.01.29.20.10.53; author rse; state Exp; branches; next 1.10; 1.10 date 2002.01.29.11.05.21; author rse; state Exp; branches; next 1.9; 1.9 date 2002.01.27.19.38.49; author rse; state Exp; branches; next 1.8; 1.8 date 2002.01.26.22.50.12; author rse; state Exp; branches; next 1.7; 1.7 date 2002.01.26.22.42.46; author rse; state Exp; branches; next 1.6; 1.6 date 2002.01.26.22.35.02; author rse; state Exp; branches; next 1.5; 1.5 date 2002.01.26.20.12.19; author rse; state Exp; branches; next 1.4; 1.4 date 2002.01.25.22.23.17; author rse; state Exp; branches; next 1.3; 1.3 date 2002.01.25.18.36.17; author rse; state Exp; branches; next 1.2; 1.2 date 2002.01.25.18.31.07; author rse; state Exp; branches; next 1.1; 1.1 date 2002.01.25.15.25.51; author rse; state Exp; branches; next ; desc @@ 1.28 log @prepare for release @ text @/* ** OSSP ex - Exception Handling ** Copyright (c) 2002-2007 Ralf S. Engelschall ** Copyright (c) 2002-2007 The OSSP Project ** ** This file is part of OSSP ex, an exception handling library ** which can be found at http://www.ossp.org/pkg/lib/ex/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** ex.h: exception handling (pre-processor part) */ #ifndef __EX_H__ #define __EX_H__ /* required ISO-C standard facilities */ #include /* convenience define */ #ifndef NULL #define NULL (void *)0 #endif /* determine how the current function name can be fetched */ #if ( defined(__STDC__) \ && defined(__STDC_VERSION__) \ && __STDC_VERSION__ >= 199901L) #define __EX_FUNC__ __func__ /* ISO-C99 compliant */ #elif ( defined(__GNUC__) \ && defined(__GNUC_MINOR__) \ && ( __GNUC__ > 2 \ || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))) #define __EX_FUNC__ __FUNCTION__ /* gcc >= 2.8 */ #else #define __EX_FUNC__ "#NA#" /* not available */ #endif /* the machine context */ #if defined(__EX_MCTX_MCSC__) #include /* POSIX.1 ucontext(3) */ #define __ex_mctx_struct ucontext_t uc; #define __ex_mctx_save(mctx) (getcontext(&(mctx)->uc) == 0) #define __ex_mctx_restored(mctx) /* noop */ #define __ex_mctx_restore(mctx) (void)setcontext(&(mctx)->uc) #elif defined(__EX_MCTX_SSJLJ__) #include /* POSIX.1 sigjmp_buf(3) */ #define __ex_mctx_struct sigjmp_buf jb; #define __ex_mctx_save(mctx) (sigsetjmp((mctx)->jb, 1) == 0) #define __ex_mctx_restored(mctx) /* noop */ #define __ex_mctx_restore(mctx) (void)siglongjmp((mctx)->jb, 1) #elif defined(__EX_MCTX_SJLJ__) || !defined(__EX_MCTX_CUSTOM__) #include /* ISO-C jmp_buf(3) */ #define __ex_mctx_struct jmp_buf jb; #define __ex_mctx_save(mctx) (setjmp((mctx)->jb) == 0) #define __ex_mctx_restored(mctx) /* noop */ #define __ex_mctx_restore(mctx) (void)longjmp((mctx)->jb, 1) #endif /* declare the machine context type */ typedef struct { __ex_mctx_struct } __ex_mctx_t; /* declare the exception type (public) */ typedef struct { /* throw value */ void *ex_class; void *ex_object; void *ex_value; /* throw point */ const char *ex_file; int ex_line; const char *ex_func; } ex_t; /* declare the context type (private) */ typedef struct { __ex_mctx_t *ctx_mctx; /* permanent machine context of enclosing try/catch */ int ctx_deferred; /* permanent flag whether exception is deferred */ int ctx_deferring;/* permanent counter of exception deferring level */ int ctx_defer; /* temporary flag for exception deferring macro */ int ctx_shielding;/* permanent counter of exception shielding level */ int ctx_shield; /* temporary flag for exception shielding macro */ int ctx_caught; /* temporary flag whether exception was caught */ volatile ex_t ctx_ex; /* temporary exception storage */ } ex_ctx_t; /* the static and dynamic initializers for a context structure */ #define EX_CTX_INITIALIZER \ { NULL, 0, 0, 0, 0, 0, 0, { NULL, NULL, NULL, NULL, 0, NULL } } #define EX_CTX_INITIALIZE(ctx) \ do { \ (ctx)->ctx_mctx = NULL; \ (ctx)->ctx_deferred = 0; \ (ctx)->ctx_deferring = 0; \ (ctx)->ctx_defer = 0; \ (ctx)->ctx_shielding = 0; \ (ctx)->ctx_shield = 0; \ (ctx)->ctx_caught = 0; \ (ctx)->ctx_ex.ex_class = NULL; \ (ctx)->ctx_ex.ex_object = NULL; \ (ctx)->ctx_ex.ex_value = NULL; \ (ctx)->ctx_ex.ex_file = NULL; \ (ctx)->ctx_ex.ex_line = 0; \ (ctx)->ctx_ex.ex_func = NULL; \ } while (0) /* the exception context */ typedef ex_ctx_t *(*ex_ctx_cb_t)(void); extern ex_ctx_cb_t __ex_ctx; extern ex_ctx_t *__ex_ctx_default(void); /* the termination handler */ typedef void (*ex_term_cb_t)(ex_t *); extern ex_term_cb_t __ex_terminate; extern void __ex_terminate_default(ex_t *e); /* the block for trying execution */ #define ex_try \ { \ ex_ctx_t *__ex_ctx_ptr = __ex_ctx(); \ int __ex_cleanup = 0; \ __ex_mctx_t *__ex_mctx_en; \ __ex_mctx_t __ex_mctx_me; \ __ex_mctx_en = __ex_ctx_ptr->ctx_mctx; \ __ex_ctx_ptr->ctx_mctx = &__ex_mctx_me; \ if (__ex_mctx_save(&__ex_mctx_me)) { \ if (1) /* the optional(!) block for cleanup */ #define ex_cleanup \ else { \ } \ __ex_ctx_ptr->ctx_caught = 0; \ } \ else { \ __ex_mctx_restored(&__ex_mctx_me); \ __ex_ctx_ptr->ctx_caught = 1; \ } \ __ex_ctx_ptr->ctx_mctx = __ex_mctx_en; \ __ex_cleanup = 1; \ if (1) { \ if (1) /* the block for catching an exception */ #define ex_catch(e) \ else { \ } \ if (!(__ex_cleanup)) \ __ex_ctx_ptr->ctx_caught = 0; \ } \ else { \ if (!(__ex_cleanup)) { \ __ex_mctx_restored(&__ex_mctx_me); \ __ex_ctx_ptr->ctx_caught = 1; \ } \ } \ __ex_ctx_ptr->ctx_mctx = __ex_mctx_en; \ } \ if ( !(__ex_ctx()->ctx_caught) \ || ((e) = __ex_ctx()->ctx_ex, 0)) { \ } \ else /* the throwing of a new exception */ #define ex_throw(c,o,v) \ (( __ex_ctx()->ctx_shielding > 0 \ || (__ex_ctx()->ctx_deferring > 0 && __ex_ctx()->ctx_deferred == 1)) ? 0 : \ (__ex_ctx()->ctx_ex.ex_class = (void *)(c), \ __ex_ctx()->ctx_ex.ex_object = (void *)(o), \ __ex_ctx()->ctx_ex.ex_value = (void *)(v), \ __ex_ctx()->ctx_ex.ex_file = __FILE__, \ __ex_ctx()->ctx_ex.ex_line = __LINE__, \ __ex_ctx()->ctx_ex.ex_func = __EX_FUNC__, \ __ex_ctx()->ctx_deferred = 1, \ (__ex_ctx()->ctx_deferring > 0 ? 0 : \ (__ex_ctx()->ctx_mctx == NULL \ ? (__ex_terminate((ex_t *)&(__ex_ctx()->ctx_ex)), -1) \ : (__ex_mctx_restore(__ex_ctx()->ctx_mctx), 1) )))) /* the re-throwing of an already caught exception */ #define ex_rethrow \ (( __ex_ctx()->ctx_shielding > 0 \ || __ex_ctx()->ctx_deferring > 0) ? 0 : \ ( __ex_ctx()->ctx_mctx == NULL \ ? (__ex_terminate((ex_t *)&(__ex_ctx()->ctx_ex)), -1) \ : (__ex_mctx_restore(__ex_ctx()->ctx_mctx), 1) )) /* shield an operation from exception handling */ #define ex_shield \ for (__ex_ctx()->ctx_shielding++, \ __ex_ctx()->ctx_shield = 1; \ __ex_ctx()->ctx_shield == 1; \ __ex_ctx()->ctx_shield = 0, \ __ex_ctx()->ctx_shielding--) /* defer immediate exception handling */ #define ex_defer \ for (((__ex_ctx()->ctx_deferring)++ == 0 ? __ex_ctx()->ctx_deferred = 0 : 0), \ __ex_ctx()->ctx_defer = 1; \ __ex_ctx()->ctx_defer == 1; \ __ex_ctx()->ctx_defer = 0, \ ((--(__ex_ctx()->ctx_deferring) == 0 && __ex_ctx()->ctx_deferred == 1) ? ex_rethrow : 0)) /* exception handling tests */ #define ex_catching \ (__ex_ctx()->ctx_mctx != NULL) #define ex_shielding \ (__ex_ctx()->ctx_shielding > 0) #define ex_deferring \ (__ex_ctx()->ctx_deferring > 0) /* optional namespace mapping */ #if defined(__EX_NS_UCCXX__) #define Try ex_try #define Cleanup ex_cleanup #define Catch ex_catch #define Throw ex_throw #define Rethrow ex_rethrow #define Shield ex_shield #define Defer ex_defer #elif defined(__EX_NS_CXX__) || (!defined(__cplusplus) && !defined(__EX_NS_CUSTOM__)) #define try ex_try #define cleanup ex_cleanup #define catch ex_catch #define throw ex_throw #define rethrow ex_rethrow #define shield ex_shield #define defer ex_defer #endif #endif /* __EX_H__ */ @ 1.27 log @cleanup source tree @ text @d3 2 a4 2 ** Copyright (c) 2002-2006 Ralf S. Engelschall ** Copyright (c) 2002-2006 The OSSP Project @ 1.26 log @Adjusted copyright messages to include new year 2005. @ text @d3 2 a4 3 ** Copyright (c) 2002-2005 Ralf S. Engelschall ** Copyright (c) 2002-2005 The OSSP Project ** Copyright (c) 2002-2005 Cable & Wireless @ 1.25 log @bump and adjust copyright @ text @d3 3 a5 3 ** Copyright (c) 2002-2004 Ralf S. Engelschall ** Copyright (c) 2002-2004 The OSSP Project ** Copyright (c) 2002-2004 Cable & Wireless @ 1.24 log @Constifiy the ex_file and ex_func fields of the exception context structure because __FUNCTION__ and __FILE__ are usually (especially under strict C99 environments) constant values. Submitted by: @ text @d3 3 a5 3 ** Copyright (c) 2002-2003 Ralf S. Engelschall ** Copyright (c) 2002-2003 The OSSP Project ** Copyright (c) 2002-2003 Cable & Wireless Germany @ 1.23 log @correct spelling: privileges, convenient; @ text @d85 3 a87 3 void *ex_class; void *ex_object; void *ex_value; d89 3 a91 3 char *ex_file; int ex_line; char *ex_func; @ 1.22 log @correct spelling: privileges, convenient; @ text @@ 1.21 log @final polishing @ text @d37 1 a37 1 /* convinience define */ @ 1.20 log @Fixed the implementation of the ex_cleanup clause. Submitted by: A Makarov @ text @d5 1 a5 1 ** Copyright (c) 2002-2003 Cable & Wireless Deutschland @ 1.19 log @- consistently use "Exception Handling" - strip trailing whitespaces - adjust copyright for new year 2003 - consistently use OSSP ASCII-art @ text @a102 1 int ctx_cleanup; /* temporary flag whether cleanup block was present */ d108 1 a108 1 { NULL, 0, 0, 0, 0, 0, 0, 0, { NULL, NULL, NULL, NULL, 0, NULL } } a117 1 (ctx)->ctx_cleanup = 0; \ d140 1 a144 1 __ex_ctx_ptr->ctx_cleanup = 0; \ d159 1 a159 1 __ex_ctx()->ctx_cleanup = 1; \ d167 1 a167 1 if (!(__ex_ctx()->ctx_cleanup)) \ d171 1 a171 1 if (!(__ex_ctx()->ctx_cleanup)) { \ @ 1.18 log @bump version and fix URLs @ text @d2 4 a5 4 ** OSSP ex - Exception Handling Library ** Copyright (c) 2002 Ralf S. Engelschall ** Copyright (c) 2002 The OSSP Project ** Copyright (c) 2002 Cable & Wireless Deutschland d59 1 a59 1 #define __ex_mctx_struct ucontext_t uc; d89 2 a90 2 char *ex_file; int ex_line; d135 1 a135 1 extern ex_term_cb_t __ex_terminate; @ 1.17 log @Implement one of the coolest things since sliced bread: deferred exceptions. This allows one to more conviniently program the allocation (and the freeing in case of an error) of multiple (independent) resources. @ text @d8 1 a8 1 ** which can be found at http://www.ossp.org/pkg/ex/. @ 1.16 log @be pedantic in style @ text @d97 3 d109 1 a109 1 { NULL, 0, 0, 0, 0, { NULL, NULL, NULL, NULL, 0, NULL } } d113 3 d187 2 a188 1 (__ex_ctx()->ctx_shielding > 0 ? 0 : \ d195 5 a199 3 ( __ex_ctx()->ctx_mctx == NULL \ ? (__ex_terminate((ex_t *)&(__ex_ctx()->ctx_ex)), -1) \ : (__ex_mctx_restore(__ex_ctx()->ctx_mctx), 1) ))) d203 2 a204 1 (__ex_ctx()->ctx_shielding > 0 ? 0 : \ d217 8 d230 2 d241 1 d249 1 @ 1.15 log @Allow ex_shield clauses to be dynamically nested. Without this the whole functionality would be useless in practice. @ text @d46 1 a46 1 #define __EX_FUNC__ __func__ /* ISO C99 compliant */ d72 1 a72 1 #include /* ISO C jmp_buf(3) */ @ 1.14 log @remove USE in macro names. It is already clear without this. @ text @d97 2 a98 1 int ctx_disabled; /* permanent flag whether exception handling is disabled */ d106 1 a106 1 { NULL, 0, 0, 0, { NULL, NULL, NULL, NULL, 0, NULL } } d110 2 a111 1 (ctx)->ctx_disabled = 0; \ d181 1 a181 1 (__ex_ctx()->ctx_disabled ? 0 : \ d194 1 a194 1 (__ex_ctx()->ctx_disabled ? 0 : \ d201 5 a205 3 for (__ex_ctx()->ctx_disabled = 1; \ __ex_ctx()->ctx_disabled == 1; \ __ex_ctx()->ctx_disabled = 0) d211 1 a211 1 (__ex_ctx()->ctx_disabled) @ 1.13 log @added namespace mapping for cleanup @ text @d57 1 a57 1 #if defined(__EX_MCTX_USE_MCSC__) d64 1 a64 1 #elif defined(__EX_MCTX_USE_SSJLJ__) d71 1 a71 1 #elif defined(__EX_MCTX_USE_SJLJ__) || !defined(__EX_MCTX_USE_CUSTOM__) d210 1 a210 1 #if defined(__EX_NS_USE_UCCXX__) d217 1 a217 1 #elif defined(__EX_NS_USE_CXX__) || (!defined(__cplusplus) && !defined(__EX_NS_USE_CUSTOM__)) @ 1.12 log @add ex_cleanup clause to ex_try/ex_catch, modelled after Java's "finally" @ text @d212 1 d219 1 @ 1.11 log @make defaults useable from outside to reset library @ text @d99 1 d105 1 a105 1 { NULL, 0, 0, { NULL, NULL, NULL, NULL, 0, NULL } } d111 1 d138 1 d142 2 a143 2 /* the block for catching an exception */ #define ex_catch(e) \ d151 18 @ 1.10 log @overhaul __ex_ctx and __ex_terminate stuff @ text @d121 1 d126 1 @ 1.9 log @reduce referencing amount (important in MT environments) @ text @d96 4 a99 4 __ex_mctx_t *ctx_mctx; /* permanent machine context of enclosing try/catch */ int ctx_disabled; /* permanent flag whether exception handling is disabled */ int ctx_caught; /* temporary flag whether exception was caught */ volatile ex_t ctx_ex; /* temporary exception storage */ d119 2 a120 8 #if defined(__EX_CTX_USE_STATIC__) static ex_ctx_t __ex_ctx_global; #define __ex_ctx (&__ex_ctx_global) #elif defined(__EX_CTX_USE_GLOBAL__) || !defined(__EX_CTX_USE_CUSTOM__) #define EX_CTX_GLOBAL ex_ctx_t __ex_ctx_global; extern ex_ctx_t __ex_ctx_global; #define __ex_ctx (&__ex_ctx_global) #endif d123 2 a124 12 #if defined(__EX_TERMINATE_USE_NOOP__) #define __ex_terminate(e) \ /* noop */ #elif defined(__EX_TERMINATE_USE_ABORT__) || !defined(__EX_CTX_USE_CUSTOM__) #define __ex_terminate(e) \ ( fprintf(stderr, \ "**EX: UNCAUGHT EXCEPTION: " \ "class=0x%lx object=0x%lx value=0x%lx [%s:%d@@%s]\n", \ (long)((e)->ex_class), (long)((e)->ex_object), (long)((e)->ex_value), \ (e)->ex_file, (e)->ex_line, (e)->ex_func), \ abort() ) #endif d129 1 a129 1 ex_ctx_t *__ex_ctx_ptr = __ex_ctx; \ d149 2 a150 2 if ( !(__ex_ctx->ctx_caught) \ || ((e) = __ex_ctx->ctx_ex, 0)) { \ d156 10 a165 10 (__ex_ctx->ctx_disabled ? 0 : \ (__ex_ctx->ctx_ex.ex_class = (void *)(c), \ __ex_ctx->ctx_ex.ex_object = (void *)(o), \ __ex_ctx->ctx_ex.ex_value = (void *)(v), \ __ex_ctx->ctx_ex.ex_file = __FILE__, \ __ex_ctx->ctx_ex.ex_line = __LINE__, \ __ex_ctx->ctx_ex.ex_func = __EX_FUNC__, \ ( __ex_ctx->ctx_mctx == NULL \ ? (__ex_terminate(&(__ex_ctx->ctx_ex)), -1) \ : (__ex_mctx_restore(__ex_ctx->ctx_mctx), 1) ))) d169 4 a172 3 (__ex_ctx->ctx_disabled ? 0 : \ (__ex_ctx->ctx_mctx == NULL ? (__ex_terminate(&(__ex_ctx->ctx_ex)), -1) : \ (__ex_mctx_restore(__ex_ctx->ctx_mctx), 1) )) d176 3 a178 3 for (__ex_ctx->ctx_disabled = 1; \ __ex_ctx->ctx_disabled == 1; \ __ex_ctx->ctx_disabled = 0) d182 1 a182 1 (__ex_ctx->ctx_mctx != NULL) d184 1 a184 1 (__ex_ctx->ctx_disabled) @ 1.8 log @fix typo @ text @d145 1 d148 2 a149 2 __ex_mctx_en = __ex_ctx->ctx_mctx; \ __ex_ctx->ctx_mctx = &__ex_mctx_me; \ d157 1 a157 1 __ex_ctx->ctx_caught = 0; \ d161 1 a161 1 __ex_ctx->ctx_caught = 1; \ d163 1 a163 1 __ex_ctx->ctx_mctx = __ex_mctx_en; \ @ 1.7 log @- rename ex_shielded to ex_shielding - do not provide namespace mapping for ex_shielding - add ex_catching for testing whether someone is trying to catch exceptions @ text @d122 1 a122 1 #elif defined(__EX_CTX_USE_GLOBAL__) || !(__EX_CTX_USE_CUSTOM__) d132 1 a132 1 #elif defined(__EX_TERMINATE_USE_ABORT__) || !(__EX_CTX_USE_CUSTOM__) @ 1.6 log @fix license messages @ text @d193 6 a198 2 #define ex_shielded \ (__ex_ctx->ctx_disabled) a206 1 #define Shielded ex_shielded a212 1 #define shielded ex_shielded @ 1.5 log @switch to our standard build environment @ text @d10 4 a13 4 ** This program is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License ** as published by the Free Software Foundation; either version ** 2.0 of the License, or (at your option) any later version. d15 12 a26 9 ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this file; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ** USA, or contact the OSSP project . @ 1.4 log @many many polishing and extending @ text @d2 4 a5 2 ** Copyright (c) 2001-2002 The OSSP Project ** Copyright (c) 2001-2002 Cable & Wireless Deutschland d7 1 a7 1 ** This file is part of OSSP ex, an exception library @ 1.3 log @cleanups @ text @d29 7 a35 3 /* the required ISO-C standard facilities */ #include /* for NULL */ #include /* for jmp_buf, setjmp(3), longjmp(3) */ d52 17 a68 4 #ifndef __ex_mctx_st #define __ex_mctx_st struct { jmp_buf jb; } #endif #ifndef __ex_mctx_save d70 1 a70 2 #endif #ifndef __ex_mctx_restore d73 3 a75 4 #ifndef __ex_mctx_restored #define __ex_mctx_restored(mctx) /* NOOP */ #endif typedef __ex_mctx_st __ex_mctx_t; d89 1 a89 1 /* declare the exception context type (private) */ d91 4 a94 3 __ex_mctx_t *ctx_mctx_prev; /* previous jump buffer */ int ctx_caught; /* flag whether exception was caught */ volatile ex_t ctx_ex; /* the exception temporary storage */ d97 23 a119 2 /* exception context */ #ifndef __ex_ctx a120 4 #ifdef __EX_STATIC_CTX__ static ex_ctx_t __ex_ctx_global; /* for very small environments */ #else extern ex_ctx_t __ex_ctx_global; /* for non-MT environments (require libex.a) */ d122 13 d137 1 a137 1 /* block for trying execution */ d140 1 a140 1 __ex_mctx_t *__ex_mctx_prev; \ d142 2 a143 2 __ex_mctx_prev = __ex_ctx->ctx_mctx_prev; \ __ex_ctx->ctx_mctx_prev = &__ex_mctx_me; \ d147 1 a147 1 /* block for catching an exception */ d157 1 a157 1 __ex_ctx->ctx_mctx_prev = __ex_mctx_prev; \ d159 2 a160 1 if (!__ex_ctx->ctx_caught || ((e) = __ex_ctx->ctx_ex, 0)) { \ d164 1 a164 1 /* throw a new exception */ d166 10 a175 12 (__ex_ctx->ctx_mctx_prev == NULL ? \ (abort(), 0) : \ ( __ex_ctx->ctx_ex.ex_class = (void *)(c), \ __ex_ctx->ctx_ex.ex_object = (void *)(o), \ __ex_ctx->ctx_ex.ex_value = (void *)(v), \ __ex_ctx->ctx_ex.ex_file = __FILE__, \ __ex_ctx->ctx_ex.ex_line = __LINE__, \ __ex_ctx->ctx_ex.ex_func = __EX_FUNC__, \ __ex_mctx_restore(__ex_ctx->ctx_mctx_prev), \ 0 \ ) \ ) d177 1 a177 1 /* re-throw a caught exception */ d179 11 a189 4 (__ex_ctx->ctx_mctx_prev == NULL ? \ (abort(), 0) : \ (__ex_mctx_restore(__ex_ctx->ctx_mctx_prev), 0) \ ) d192 8 a199 1 #if !defined(__cplusplus) && !defined(__EX_NO_CXX_NS__) d204 2 a205 6 #endif #if !defined(__EX_NO_SIMPLE_NS__) #define Try ex_try #define Catch ex_catch #define Throw ex_throw #define Rethrow ex_rethrow @ 1.2 log @Allow overriding of machine context switching approach. @ text @d52 1 a52 1 #define __ex_mctx_save(mctx) setjmp((mctx)->jb) d77 2 a78 2 int ctx_caught; /* flag whether exception was caught */ volatile ex_t ctx_ex; /* the exception temporary storage */ d81 1 a81 1 /* ex context (default requires linking against libex) */ d84 5 a88 1 extern ex_ctx_t __ex_ctx_global; d98 1 a98 1 if (__ex_mctx_save(&__ex_mctx_me) == 0) { \ @ 1.1 log @Welcome OSSP ex, another new-born OSSP library. This is the first cut for a C exception handling library. Read ex.pod for details... @ text @d26 2 a27 2 #ifndef __TEXAS_H__ #define __TEXAS_H__ d37 1 a37 1 #define __TEXAS_FUNC__ __func__ /* ISO C99 compliant */ d42 1 a42 1 #define __TEXAS_FUNC__ __FUNCTION__ /* gcc >= 2.8 */ d44 1 a44 1 #define __TEXAS_FUNC__ "#NA#" /* not available */ d47 15 d76 1 a76 1 jmp_buf *ctx_jbprev; /* previous jump buffer */ d90 5 a94 5 jmp_buf *__ex_jbprev; \ jmp_buf __ex_jbme; \ __ex_jbprev = __ex_ctx->ctx_jbprev; \ __ex_ctx->ctx_jbprev = &__ex_jbme; \ if (setjmp(__ex_jbme) == 0) { \ d104 1 d107 1 a107 1 __ex_ctx->ctx_jbprev = __ex_jbprev; \ d115 1 a115 1 (__ex_ctx->ctx_jbprev == NULL ? \ d122 2 a123 2 __ex_ctx->ctx_ex.ex_func = __TEXAS_FUNC__, \ longjmp(*(__ex_ctx->ctx_jbprev), 1), \ d130 1 a130 1 (__ex_ctx->ctx_jbprev == NULL ? \ d132 1 a132 1 (longjmp(*(__ex_ctx->ctx_jbprev), 1), 0) \ d136 1 a136 1 #if !defined(__cplusplus) && !defined(__TEXAS_NO_CXX_NS__) d142 1 a142 1 #if !defined(__TEXAS_NO_SIMPLE_NS__) d149 1 a149 1 #endif /* __TEXAS_H__ */ @