Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fit libex into SimGrid (with an axe, I admit)
[simgrid.git] / src / xbt / ex.c
1 /*
2 **  OSSP ex - Exception Handling (modified to fit into SimGrid)
3 **  Copyright (c) 2005 Martin Quinson
4 **  Copyright (c) 2002-2004 Ralf S. Engelschall <rse@engelschall.com>
5 **  Copyright (c) 2002-2004 The OSSP Project <http://www.ossp.org/>
6 **  Copyright (c) 2002-2004 Cable & Wireless <http://www.cw.com/>
7 **
8 **  This file is part of OSSP ex, an exception handling library
9 **  which can be found at http://www.ossp.org/pkg/lib/ex/.
10 **
11 **  Permission to use, copy, modify, and distribute this software for
12 **  any purpose with or without fee is hereby granted, provided that
13 **  the above copyright notice and this permission notice appear in all
14 **  copies.
15 **
16 **  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
17 **  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 **  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 **  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
20 **  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 **  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 **  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 **  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 **  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 **  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 **  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 **  SUCH DAMAGE.
28 **
29 **  ex.c: exception handling (compiler part)
30 */
31
32 #include <stdio.h>
33 #include <stdlib.h>
34
35 #include "xbt/ex.h"
36
37 /* default __ex_ctx callback function */
38 ex_ctx_t *__xbt_ex_ctx_default(void) {
39     static ex_ctx_t ctx = SG_CTX_INITIALIZER;
40
41     return &ctx;
42 }
43
44 /* default __ex_terminate callback function */
45 void __xbt_ex_terminate_default(ex_t *e) {
46
47     fprintf(stderr,
48             "** SimGrid: UNCAUGHT EXCEPTION:\n"
49             "** (%d/%d) %s\n"
50             "** Thrown by %s%s%s at %s:%d:%s\n",
51             e->code, e->value, e->msg,
52             e->procname, (e->host?"@":""),(e->host?e->host:""),
53             e->file,e->line,e->func);
54     abort();
55 }
56
57 /* the externally visible API */
58 ex_ctx_cb_t  __xbt_ex_ctx       = &__xbt_ex_ctx_default;
59 ex_term_cb_t __xbt_ex_terminate = &__xbt_ex_terminate_default;
60