|
|
1.1 root 1: /* GNU Objective C Runtime class related functions
2: Copyright (C) 1993 Free Software Foundation, Inc.
3:
4: Author: Kresten Krab Thorup
5:
6: This file is part of GNU CC.
7:
8: GNU CC is free software; you can redistribute it and/or modify it under the
9: terms of the GNU General Public License as published by the Free Software
10: Foundation; either version 2, or (at your option) any later version.
11:
12: GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY
13: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14: FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15: details.
16:
17: You should have received a copy of the GNU General Public License along with
18: GNU CC; see the file COPYING. If not, write to the Free Software
19: Foundation, 675 Mass Ave, Cambridge, MA 02139, 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:
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: bzero (new, 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:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.