Declare malloc, free, and atexit if inhibit_libc is defined.
[official-gcc.git] / libobjc / objects.c
blobdf74b85de872b0383ffeb9857ffbc2b8a2ec8a18
1 /* GNU Objective C Runtime class related functions
2 Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
3 Contributed by Kresten Krab Thorup
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 2, or (at your option) any later version.
11 GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 details.
16 You should have received a copy of the GNU General Public License along with
17 GNU CC; see the file COPYING. If not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* As a special exception, if you link this library with files compiled with
22 GCC to produce an executable, this does not cause the resulting executable
23 to be covered by the GNU General Public License. This exception does not
24 however invalidate any other reasons why the executable file might be
25 covered by the GNU General Public License. */
27 #include "tconfig.h" /* include defs of bzero for target */
28 #include "objc.h"
29 #include "runtime.h" /* the kitchen sink */
31 #if OBJC_WITH_GC
32 # include <gc.h>
33 #endif
35 id __objc_object_alloc(Class);
36 id __objc_object_dispose(id);
37 id __objc_object_copy(id);
39 id (*_objc_object_alloc)(Class) = __objc_object_alloc; /* !T:SINGLE */
40 id (*_objc_object_dispose)(id) = __objc_object_dispose; /* !T:SINGLE */
41 id (*_objc_object_copy)(id) = __objc_object_copy; /* !T:SINGLE */
44 class_create_instance(Class class)
46 id new = nil;
48 #if OBJC_WITH_GC
49 if (CLS_ISCLASS(class))
50 new = (id)GC_malloc_explicitly_typed (class->instance_size,
51 class->gc_object_type);
52 #else
53 if (CLS_ISCLASS(class))
54 new = (*_objc_object_alloc)(class);
55 #endif
57 if (new!=nil)
59 memset (new, 0, class->instance_size);
60 new->class_pointer = class;
62 return new;
66 object_copy(id object)
68 if ((object!=nil)&&CLS_ISCLASS(object->class_pointer))
69 return (*_objc_object_copy)(object);
70 else
71 return nil;
75 object_dispose(id object)
77 if ((object!=nil)&&CLS_ISCLASS(object->class_pointer))
79 if (_objc_object_dispose)
80 (*_objc_object_dispose)(object);
81 else
82 objc_free(object);
84 return nil;
87 id __objc_object_alloc(Class class)
89 return (id)objc_malloc(class->instance_size);
92 id __objc_object_dispose(id object)
94 objc_free(object);
95 return 0;
98 id __objc_object_copy(id object)
100 id copy = class_create_instance(object->class_pointer);
101 memcpy(copy, object, object->class_pointer->instance_size);
102 return copy;