]> gcc.gnu.org Git - gcc.git/blame - gcc/objc/objects.c
More system.h cutover patches:
[gcc.git] / gcc / objc / objects.c
CommitLineData
c72fc2d9 1/* GNU Objective C Runtime class related functions
691466c0 2 Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
0994488a 3 Contributed by Kresten Krab Thorup
c72fc2d9
TW
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify it under the
0994488a
RK
8terms of the GNU General Public License as published by the Free Software
9Foundation; either version 2, or (at your option) any later version.
c72fc2d9
TW
10
11GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY
0994488a
RK
12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14details.
c72fc2d9
TW
15
16You should have received a copy of the GNU General Public License along with
0994488a 17GNU CC; see the file COPYING. If not, write to the Free Software
84c09f78
RK
18Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
c72fc2d9
TW
20
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. */
26
83a4b97f 27#include "../tconfig.h" /* include defs of bzero for target */
c3c12186 28#include "runtime.h" /* the kitchen sink */
c72fc2d9 29
0994488a 30id __objc_object_alloc(Class);
c72fc2d9
TW
31id __objc_object_dispose(id);
32id __objc_object_copy(id);
33
691466c0
RK
34id (*_objc_object_alloc)(Class) = __objc_object_alloc; /* !T:SINGLE */
35id (*_objc_object_dispose)(id) = __objc_object_dispose; /* !T:SINGLE */
36id (*_objc_object_copy)(id) = __objc_object_copy; /* !T:SINGLE */
c72fc2d9
TW
37
38id
0994488a 39class_create_instance(Class class)
c72fc2d9 40{
991d3e71
KKT
41 id new = nil;
42 if (CLS_ISCLASS(class))
43 new = (*_objc_object_alloc)(class);
44 if (new!=nil)
d9d27c6e 45 {
d5e4fa5e 46 memset (new, 0, class->instance_size);
d9d27c6e
KKT
47 new->class_pointer = class;
48 }
991d3e71 49 return new;
c72fc2d9
TW
50}
51
991d3e71 52id
c72fc2d9
TW
53object_copy(id object)
54{
991d3e71
KKT
55 if ((object!=nil)&&CLS_ISCLASS(object->class_pointer))
56 return (*_objc_object_copy)(object);
57 else
58 return nil;
c72fc2d9
TW
59}
60
991d3e71 61id
c72fc2d9
TW
62object_dispose(id object)
63{
991d3e71
KKT
64 if ((object!=nil)&&CLS_ISCLASS(object->class_pointer))
65 {
66 if (_objc_object_dispose)
67 (*_objc_object_dispose)(object);
68 else
a1feef75 69 objc_free(object);
991d3e71
KKT
70 }
71 return nil;
c72fc2d9
TW
72}
73
0994488a 74id __objc_object_alloc(Class class)
c72fc2d9 75{
a1feef75 76 return (id)objc_malloc(class->instance_size);
c72fc2d9
TW
77}
78
79id __objc_object_dispose(id object)
80{
a1feef75 81 objc_free(object);
c72fc2d9
TW
82 return 0;
83}
84
85id __objc_object_copy(id object)
86{
87 id copy = class_create_instance(object->class_pointer);
a7ab3794 88 memcpy(copy, object, object->class_pointer->instance_size);
c72fc2d9
TW
89 return copy;
90}
91
92
This page took 0.446591 seconds and 5 git commands to generate.