-
Notifications
You must be signed in to change notification settings - Fork 4
/
GNUstep.h
184 lines (159 loc) · 5.12 KB
/
GNUstep.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* GNUstep.h - macros to make easier to port gnustep apps to macos-x
Copyright (C) 2001 Free Software Foundation, Inc.
Written by: Nicola Pero
Date: March, October 2001
This file is part of GNUstep.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef Performance_GNUstep_h
#define Performance_GNUstep_h
#ifndef RETAIN
/**
* Basic retain operation ... calls [NSObject-retain]<br />
* Does nothing when ARC is in use.
*/
#define RETAIN(object) [(id)(object) retain]
#endif
#ifndef RELEASE
/**
* Basic release operation ... calls [NSObject-release]<br />
* Does nothing when ARC is in use.
*/
#define RELEASE(object) [(id)(object) release]
#endif
#ifndef AUTORELEASE
/**
* Basic autorelease operation ... calls [NSObject-autorelease]<br />
* Does nothing when ARC is in use.
*/
#define AUTORELEASE(object) [(id)(object) autorelease]
#endif
#ifndef TEST_RETAIN
/**
* Tested retain - only invoke the
* objective-c method if the receiver is not nil.<br />
* Does nothing when ARC is in use.
*/
#define TEST_RETAIN(object) ({\
void *__object = (void*)(object);\
(__object != 0) ? [(id)__object retain] : nil; })
#endif
#ifndef TEST_RELEASE
/**
* Tested release - only invoke the
* objective-c method if the receiver is not nil.<br />
* Does nothing when ARC is in use.
*/
#define TEST_RELEASE(object) ({\
void *__object = (void*)(object);\
if (__object != 0) [(id)__object release]; })
#endif
#ifndef TEST_AUTORELEASE
/**
* Tested autorelease - only invoke the
* objective-c method if the receiver is not nil.<br />
* Does nothing when ARC is in use.
*/
#define TEST_AUTORELEASE(object) ({\
void *__object = (void*)(object);\
(__object != 0) ? [(id)__object autorelease] : nil; })
#endif
#ifndef ASSIGN
/**
* ASSIGN(object,value) assigns the value to the object with
* appropriate retain and release operations.<br />
* Use this to avoid retain/release errors.
*/
#define ASSIGN(object,value) ({\
void *__object = (void*)object; \
object = (__typeof__(object))[(value) retain]; \
[(id)__object release]; \
})
#endif
#ifndef ASSIGNCOPY
/**
* ASSIGNCOPY(object,value) assigns a copy of the value to the object
* with release of the original.<br />
* Use this to avoid retain/release errors.
*/
#define ASSIGNCOPY(object,value) ({\
void *__object = (void*)object; \
object = (__typeof__(object))[(value) copy];\
[(id)__object release]; \
})
#endif
#ifndef ASSIGNMUTABLECOPY
/**
* ASSIGNMUTABLECOPY(object,value) assigns a mutable copy of the value
* to the object with release of the original.<br />
* Use this to avoid retain/release errors.
*/
#define ASSIGNMUTABLECOPY(object,value) ({\
void *__object = (void*)object; \
object = (__typeof__(object))[(value) mutableCopy];\
[(id)__object release]; \
})
#endif
#ifndef DESTROY
/**
* DESTROY() is a release operation which also sets the variable to be
* a nil pointer for tidiness - we can't accidentally use a DESTROYED
* object later. It also makes sure to set the variable to nil before
* releasing the object - to avoid side-effects of the release trying
* to reference the object being released through the variable.
*/
#define DESTROY(object) ({ \
void *__o = (void*)object; \
object = nil; \
[(id)__o release]; \
})
#endif
#ifndef DEALLOC
/**
* DEALLOC calls the superclass implementation of dealloc, unless
* ARC is in use (in which case it does nothing).
*/
#define DEALLOC [super dealloc];
#endif
#ifndef ENTER_POOL
/**
* ENTER_POOL creates an autorelease pool and places subsequent code
* in a block.<br />
* The block must be terminated with a corresponding LEAVE_POOL.<br />
* You should not break, continue, or return from such a block of code
* (to do so could leak an autorelease pool and give objects a longer
* lifetime than they ought to have. If you wish to leave the block of
* code early, you should ensure that doing so causes the autorelease
* pool outside the block to be released promptly (since that will
* implicitly release the pool created at the start of the block too).
*/
#define ENTER_POOL {NSAutoreleasePool *_lARP=[NSAutoreleasePool new];
#endif
#ifndef LEAVE_POOL
/**
* LEAVE_POOL terminates a block of code started with ENTER_POOL.
*/
#define LEAVE_POOL [_lARP drain];}
#endif
#ifndef __has_feature // Optional.
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif
#ifndef NS_CONSUMED
#if __has_feature(attribute_ns_consumed)
#define NS_CONSUMED __attribute__((ns_consumed))
#else
#define NS_CONSUMED
#endif
#endif
#endif