OSDN Git Service

ed0899eb77edd50d81f3a88b301ab2131d37da74
[pf3gnuchains/gcc-fork.git] / gcc / objc / objects.c
1 /* GNU Objective C Runtime class related functions
2    Copyright (C) 1993, 1995 Free Software Foundation, Inc.
3    Contributed by Kresten Krab Thorup
4
5 This file is part of GNU CC.
6
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.
10
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.
15
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, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 /* As a special exception, if you link this library with files compiled with
21    GCC to produce an executable, this does not cause the resulting executable
22    to be covered by the GNU General Public License. This exception does not
23    however invalidate any other reasons why the executable file might be
24    covered by the GNU General Public License.  */
25
26 #include "../tconfig.h"         /* include defs of bzero for target */
27 #include "runtime.h"            /* the kitchen sink */
28
29 id __objc_object_alloc(Class);
30 id __objc_object_dispose(id);
31 id __objc_object_copy(id);
32
33 id (*_objc_object_alloc)(Class)   = __objc_object_alloc;
34 id (*_objc_object_dispose)(id)    = __objc_object_dispose;
35 id (*_objc_object_copy)(id)       = __objc_object_copy;
36
37 id
38 class_create_instance(Class class)
39 {
40   id new = nil;
41   if (CLS_ISCLASS(class))
42     new = (*_objc_object_alloc)(class);
43   if (new!=nil)
44     {
45       memset (new, 0, class->instance_size);
46       new->class_pointer = class;
47     }
48   return new;
49 }
50
51 id
52 object_copy(id object)
53 {
54   if ((object!=nil)&&CLS_ISCLASS(object->class_pointer))
55     return (*_objc_object_copy)(object);
56   else
57     return nil;
58 }
59
60 id
61 object_dispose(id object)
62 {
63   if ((object!=nil)&&CLS_ISCLASS(object->class_pointer))
64     {
65       if (_objc_object_dispose)
66         (*_objc_object_dispose)(object);
67       else
68         free(object);
69     }
70   return nil;
71 }
72
73 id __objc_object_alloc(Class class)
74 {
75   return (id)__objc_xmalloc(class->instance_size);
76 }
77
78 id __objc_object_dispose(id object) 
79 {
80   free(object);
81   return 0;
82 }
83
84 id __objc_object_copy(id object)
85 {
86   id copy = class_create_instance(object->class_pointer);
87   memcpy(copy, object, object->class_pointer->instance_size);
88   return copy;
89 }
90
91