]> git.ipfire.org Git - thirdparty/gcc.git/blame - libobjc/objects.c
patch to fix extraneous nop at function start, bug from David Mosberger
[thirdparty/gcc.git] / libobjc / objects.c
CommitLineData
88e17b57
BE
1/* GNU Objective C Runtime class related functions
2 Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
3 Contributed by Kresten Krab Thorup
4
38709cad 5This file is part of GCC.
88e17b57 6
38709cad 7GCC is free software; you can redistribute it and/or modify it under the
88e17b57
BE
8terms of the GNU General Public License as published by the Free Software
9Foundation; either version 2, or (at your option) any later version.
10
38709cad 11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
88e17b57
BE
12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14details.
15
16You should have received a copy of the GNU General Public License along with
38709cad 17GCC; see the file COPYING. If not, write to the Free Software
88e17b57
BE
18Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
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
bce1b489 27#include "tconfig.h" /* include defs of bzero for target */
88e17b57
BE
28#include "objc.h"
29#include "runtime.h" /* the kitchen sink */
30
31#if OBJC_WITH_GC
32# include <gc.h>
33#endif
34
40165636
RB
35id __objc_object_alloc (Class);
36id __objc_object_dispose (id);
37id __objc_object_copy (id);
88e17b57 38
40165636
RB
39id (*_objc_object_alloc) (Class) = __objc_object_alloc; /* !T:SINGLE */
40id (*_objc_object_dispose) (id) = __objc_object_dispose; /* !T:SINGLE */
41id (*_objc_object_copy) (id) = __objc_object_copy; /* !T:SINGLE */
88e17b57
BE
42
43id
40165636 44class_create_instance (Class class)
88e17b57
BE
45{
46 id new = nil;
47
48#if OBJC_WITH_GC
40165636
RB
49 if (CLS_ISCLASS (class))
50 new = (id) GC_malloc_explicitly_typed (class->instance_size,
51 class->gc_object_type);
88e17b57 52#else
40165636
RB
53 if (CLS_ISCLASS (class))
54 new = (*_objc_object_alloc) (class);
88e17b57
BE
55#endif
56
40165636 57 if (new != nil)
88e17b57
BE
58 {
59 memset (new, 0, class->instance_size);
60 new->class_pointer = class;
61 }
62 return new;
63}
64
65id
40165636 66object_copy (id object)
88e17b57 67{
40165636
RB
68 if ((object != nil) && CLS_ISCLASS (object->class_pointer))
69 return (*_objc_object_copy) (object);
88e17b57
BE
70 else
71 return nil;
72}
73
74id
40165636 75object_dispose (id object)
88e17b57 76{
40165636 77 if ((object != nil) && CLS_ISCLASS (object->class_pointer))
88e17b57
BE
78 {
79 if (_objc_object_dispose)
40165636 80 (*_objc_object_dispose) (object);
88e17b57 81 else
40165636 82 objc_free (object);
88e17b57
BE
83 }
84 return nil;
85}
86
40165636 87id __objc_object_alloc (Class class)
88e17b57 88{
40165636 89 return (id) objc_malloc (class->instance_size);
88e17b57
BE
90}
91
40165636 92id __objc_object_dispose (id object)
88e17b57 93{
40165636 94 objc_free (object);
88e17b57
BE
95 return 0;
96}
97
40165636 98id __objc_object_copy (id object)
88e17b57 99{
40165636
RB
100 id copy = class_create_instance (object->class_pointer);
101 memcpy (copy, object, object->class_pointer->instance_size);
88e17b57
BE
102 return copy;
103}