1 | /* GNU Objective C Runtime Miscellaneous |
---|
2 | Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. |
---|
3 | |
---|
4 | Author: Kresten Krab Thorup |
---|
5 | |
---|
6 | This file is part of GNU CC. |
---|
7 | |
---|
8 | GNU CC is free software; you can redistribute it and/or modify it |
---|
9 | under the terms of the GNU General Public License as published by the |
---|
10 | Free Software Foundation; either version 2, or (at your option) any |
---|
11 | later version. |
---|
12 | |
---|
13 | GNU CC is distributed in the hope that it will be useful, but WITHOUT |
---|
14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
16 | for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with GNU CC; see the file COPYING. If not, write to the Free |
---|
20 | Software Foundation, 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. */ |
---|
22 | |
---|
23 | /* As a special exception, if you link this library with files compiled with |
---|
24 | GCC to produce an executable, this does not cause the resulting executable |
---|
25 | to be covered by the GNU General Public License. This exception does not |
---|
26 | however invalidate any other reasons why the executable file might be |
---|
27 | covered by the GNU General Public License. */ |
---|
28 | |
---|
29 | #ifdef __alpha__ |
---|
30 | #include <stdlib.h> |
---|
31 | extern int write (int, const char*, int); |
---|
32 | extern size_t strlen (const char*); |
---|
33 | #endif |
---|
34 | |
---|
35 | #include "runtime.h" |
---|
36 | |
---|
37 | void objc_error(id object, const char* fmt, va_list); |
---|
38 | |
---|
39 | void (*_objc_error)(id, const char*, va_list) = objc_error; |
---|
40 | |
---|
41 | void |
---|
42 | objc_error(id object, const char* fmt, va_list ap) |
---|
43 | { |
---|
44 | vfprintf (stderr, fmt, ap); |
---|
45 | abort (); |
---|
46 | } |
---|
47 | |
---|
48 | volatile void |
---|
49 | objc_fatal(const char* msg) |
---|
50 | { |
---|
51 | write(2, msg, (int)strlen((const char*)msg)); |
---|
52 | abort(); |
---|
53 | } |
---|
54 | |
---|
55 | void* |
---|
56 | __objc_xmalloc(size_t size) |
---|
57 | { |
---|
58 | void* res = (void*) malloc(size); |
---|
59 | if(!res) |
---|
60 | objc_fatal("Virtual memory exhausted\n"); |
---|
61 | return res; |
---|
62 | } |
---|
63 | |
---|
64 | void* |
---|
65 | __objc_xrealloc(void* mem, size_t size) |
---|
66 | { |
---|
67 | void* res = (void*) realloc(mem, size); |
---|
68 | if(!res) |
---|
69 | objc_fatal("Virtual memory exhausted\n"); |
---|
70 | return res; |
---|
71 | } |
---|
72 | |
---|
73 | void* |
---|
74 | __objc_xcalloc(size_t nelem, size_t size) |
---|
75 | { |
---|
76 | void* res = (void*)calloc(nelem, size); |
---|
77 | if(!res) |
---|
78 | objc_fatal("Virtual memory exhausted\n"); |
---|
79 | return res; |
---|
80 | } |
---|