]>
Commit | Line | Data |
---|---|---|
7b869986 NP |
1 | /* GNU Objective C Runtime Error Functions |
2 | Copyright (C) 1993, 1994, 1995, 1996, 1997, 2002, 2009, 2010 | |
3 | Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU General Public License as published by the | |
9 | Free Software Foundation; either version 3, or (at your option) any | |
10 | later version. | |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT | |
13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | Under Section 7 of GPL version 3, you are granted additional | |
18 | permissions described in the GCC Runtime Library Exception, version | |
19 | 3.1, as published by the Free Software Foundation. | |
20 | ||
21 | You should have received a copy of the GNU General Public License and | |
22 | a copy of the GCC Runtime Library Exception along with this program; | |
23 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
24 | <http://www.gnu.org/licenses/>. */ | |
25 | ||
26 | #include "objc-private/common.h" | |
27 | #include "objc-private/error.h" | |
28 | ||
29 | /* __USE_FIXED_PROTOTYPES__ used to be required to get prototypes for | |
30 | malloc, free, etc. on some platforms. It is unclear if we still | |
31 | need it, but it can't hurt. | |
32 | */ | |
33 | #define __USE_FIXED_PROTOTYPES__ | |
34 | #include <stdlib.h> | |
35 | #include <stdio.h> | |
36 | #include <stdarg.h> | |
37 | ||
38 | /* Prints an error message and aborts the program. */ | |
39 | void | |
40 | _objc_abort (const char *fmt, ...) | |
41 | { | |
42 | va_list ap; | |
43 | ||
44 | va_start (ap, fmt); | |
45 | vfprintf (stderr, fmt, ap); | |
46 | abort (); | |
47 | va_end (ap); | |
48 | } | |
49 | ||
50 | /* The rest of the file is deprecated. */ | |
718a8e53 | 51 | #include "objc/objc-api.h" /* For objc_error_handler. */ |
7b869986 NP |
52 | |
53 | /* | |
54 | ** Error handler function | |
55 | ** NULL so that default is to just print to stderr | |
56 | */ | |
57 | static objc_error_handler _objc_error_handler = NULL; | |
58 | ||
59 | /* Trigger an objc error */ | |
60 | void | |
61 | objc_error (id object, int code, const char *fmt, ...) | |
62 | { | |
63 | va_list ap; | |
64 | ||
65 | va_start (ap, fmt); | |
66 | objc_verror (object, code, fmt, ap); | |
67 | va_end (ap); | |
68 | } | |
69 | ||
70 | /* Trigger an objc error */ | |
71 | void | |
72 | objc_verror (id object, int code, const char *fmt, va_list ap) | |
73 | { | |
74 | BOOL result = NO; | |
75 | ||
76 | /* Call the error handler if its there | |
77 | Otherwise print to stderr */ | |
78 | if (_objc_error_handler) | |
79 | result = (*_objc_error_handler) (object, code, fmt, ap); | |
80 | else | |
81 | vfprintf (stderr, fmt, ap); | |
82 | ||
83 | /* Continue if the error handler says its ok | |
84 | Otherwise abort the program */ | |
85 | if (result) | |
86 | return; | |
87 | else | |
88 | abort (); | |
89 | } | |
90 | ||
91 | /* Set the error handler */ | |
92 | objc_error_handler | |
93 | objc_set_error_handler (objc_error_handler func) | |
94 | { | |
95 | objc_error_handler temp = _objc_error_handler; | |
96 | _objc_error_handler = func; | |
97 | return temp; | |
98 | } |