* src/powerpc/ffi_darwin.c (ffi_closure_helper_DARWIN): Increment
[official-gcc.git] / libobjc / objects.c
blob36ff8675a2f10e90b70303c75bea7ab369415e9c
1 /* GNU Objective C Runtime class related functions
2 Copyright (C) 1993, 1995, 1996, 2009 Free Software Foundation, Inc.
3 Contributed by Kresten Krab Thorup
5 This file is part of GCC.
7 GCC 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 3, or (at your option) any later version.
11 GCC 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 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
26 #include "tconfig.h" /* include defs of bzero for target */
27 #include "objc/objc.h"
28 #include "objc/runtime.h" /* the kitchen sink */
30 #if OBJC_WITH_GC
31 # include <gc.h>
32 #endif
34 id __objc_object_alloc (Class);
35 id __objc_object_dispose (id);
36 id __objc_object_copy (id);
38 id (*_objc_object_alloc) (Class) = __objc_object_alloc; /* !T:SINGLE */
39 id (*_objc_object_dispose) (id) = __objc_object_dispose; /* !T:SINGLE */
40 id (*_objc_object_copy) (id) = __objc_object_copy; /* !T:SINGLE */
43 class_create_instance (Class class)
45 id new = nil;
47 #if OBJC_WITH_GC
48 if (CLS_ISCLASS (class))
49 new = (id) GC_malloc_explicitly_typed (class->instance_size,
50 class->gc_object_type);
51 #else
52 if (CLS_ISCLASS (class))
53 new = (*_objc_object_alloc) (class);
54 #endif
56 if (new != nil)
58 memset (new, 0, class->instance_size);
59 new->class_pointer = class;
61 return new;
65 object_copy (id object)
67 if ((object != nil) && CLS_ISCLASS (object->class_pointer))
68 return (*_objc_object_copy) (object);
69 else
70 return nil;
74 object_dispose (id object)
76 if ((object != nil) && CLS_ISCLASS (object->class_pointer))
78 if (_objc_object_dispose)
79 (*_objc_object_dispose) (object);
80 else
81 objc_free (object);
83 return nil;
86 id __objc_object_alloc (Class class)
88 return (id) objc_malloc (class->instance_size);
91 id __objc_object_dispose (id object)
93 objc_free (object);
94 return 0;
97 id __objc_object_copy (id object)
99 id copy = class_create_instance (object->class_pointer);
100 memcpy (copy, object, object->class_pointer->instance_size);
101 return copy;