ObjFW  Check-in [87cd99ff88]

Overview
Comment:Don't retain delegates to prevent reference cycles.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 87cd99ff884ce8b029dbcb44338d2f9dcbe2f0ea319e6cbeee21f8abdb8c316f
User & Date: js on 2011-10-24 18:28:28
Other Links: manifest | tags
Context
2011-10-25
00:02
Always release the pool in -[OFStreamObserver observe]. check-in: 95fdb174f6 user: js tags: trunk
2011-10-24
18:28
Don't retain delegates to prevent reference cycles. check-in: 87cd99ff88 user: js tags: trunk
15:47
Make sure the fullness of a hashtable is always at max 3/4. check-in: 1bec445dd2 user: js tags: trunk
Changes

Modified src/OFApplication.h from [530227dea1] to [a8719ab12b].

65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79







-
+







	char ***argv;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, copy) OFString *programName;
@property (readonly, copy) OFArray *arguments;
@property (readonly, copy) OFDictionary *environment;
@property (retain) id <OFApplicationDelegate> delegate;
@property (assign) id <OFApplicationDelegate> delegate;
#endif

/**
 * \brief Returns the only OFApplication instance in the application.
 *
 * \return The only OFApplication instance in the application
 */

Modified src/OFApplication.m from [e705f7e9ee] to [741469d176].

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
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







-
-
-
+












-


+
+







#endif

static OFApplication *app = nil;

static void
atexit_handler(void)
{
	id <OFApplicationDelegate> delegate = [app delegate];

	[delegate applicationWillTerminate];
	[[app delegate] applicationWillTerminate];
}

int
of_application_main(int *argc, char **argv[], Class cls)
{
	OFApplication *app = [OFApplication sharedApplication];
	id <OFApplicationDelegate> delegate = [[cls alloc] init];

	[app setArgumentCount: argc
	    andArgumentValues: argv];

	[app setDelegate: delegate];
	[(id)delegate release];

	[app run];

	[(id)delegate release];

	return 0;
}

@implementation OFApplication
+ sharedApplication
{
227
228
229
230
231
232
233
234

235
236
237
238
239

240
241
242
243
244
245
246
226
227
228
229
230
231
232

233
234
235
236
237

238
239
240
241
242
243
244
245







-
+




-
+







- (OFDictionary*)environment
{
	OF_GETTER(environment, YES)
}

- (id <OFApplicationDelegate>)delegate
{
	OF_GETTER(delegate, YES)
	return delegate;
}

- (void)setDelegate: (id <OFApplicationDelegate>)delegate_
{
	OF_SETTER(delegate, delegate_, YES, NO)
	delegate = delegate_;
}

- (void)run
{
	[delegate applicationDidFinishLaunching];
}

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
253
254
255
256
257
258
259

260
261
262
263
264
265
266







-







	exit(status);
}

- (void)dealloc
{
	[arguments release];
	[environment release];
	[(id)delegate release];

	[super dealloc];
}
@end

@implementation OFObject (OFApplicationDelegate)
- (void)applicationDidFinishLaunching

Modified src/OFHTTPRequest.h from [73f77fc69e] to [de1dce9f3b].

101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115







-
+








#ifdef OF_HAVE_PROPERTIES
@property (copy) OFURL *URL;
@property (assign) of_http_request_type_t requestType;
@property (copy) OFString *queryString;
@property (copy) OFDictionary *headers;
@property (assign) BOOL redirectsFromHTTPSToHTTPAllowed;
@property (retain) id <OFHTTPRequestDelegate> delegate;
@property (assign) id <OFHTTPRequestDelegate> delegate;
@property (assign) BOOL storesData;
#endif

/**
 * \brief Creates a new OFHTTPRequest.
 *
 * \return A new, autoreleased OFHTTPRequest

Modified src/OFHTTPRequest.m from [66f489833f] to [58e168ad78].

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
99
100
101
102
103
104
105

106
107
108
109
110
111
112







-







}

- (void)dealloc
{
	[URL release];
	[queryString release];
	[headers release];
	[(id)delegate release];

	[super dealloc];
}

- (void)setURL: (OFURL*)URL_
{
	OF_SETTER(URL, URL_, YES, YES)
156
157
158
159
160
161
162
163

164
165
166
167
168

169
170
171
172
173
174
175
155
156
157
158
159
160
161

162
163
164
165
166

167
168
169
170
171
172
173
174







-
+




-
+







- (BOOL)redirectsFromHTTPSToHTTPAllowed
{
	return redirectsFromHTTPSToHTTPAllowed;
}

- (void)setDelegate: (id <OFHTTPRequestDelegate>)delegate_
{
	OF_SETTER(delegate, delegate_, YES, NO)
	delegate = delegate_;
}

- (id <OFHTTPRequestDelegate>)delegate
{
	OF_GETTER(delegate, YES)
	return delegate;
}

- (void)setStoresData: (BOOL)storesData_
{
	storesData = storesData_;
}

Modified src/OFStreamObserver.h from [c3f9253037] to [b5736c8412].

89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103







-
+







#ifdef _WIN32
	struct sockaddr_in cancelAddr;
#endif
	OFMutex *mutex;
}

#ifdef OF_HAVE_PROPERTIES
@property (retain) id <OFStreamObserverDelegate> delegate;
@property (assign) id <OFStreamObserverDelegate> delegate;
#endif

/**
 * \brief Creates a new OFStreamObserver.
 *
 * \return A new, autoreleased OFStreamObserver
 */

Modified src/OFStreamObserver.m from [fa968ce497] to [b9eb3c11d8].

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
43
44
45
46
47
48
49


50
51
52
53
54
55
56







-
-







# import "OFStreamObserver_select.h"
#endif

#import "OFInitializationFailedException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfRangeException.h"

#import "macros.h"

enum {
	QUEUE_ADD = 0,
	QUEUE_REMOVE = 1,
	QUEUE_READ = 0,
	QUEUE_WRITE = 2
};
#define QUEUE_ACTION (QUEUE_ADD | QUEUE_REMOVE)
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

185
186
187
188
189
190
191
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
185
186
187
188







-














-
+




-
+







}

- (void)dealloc
{
	close(cancelFD[0]);
	close(cancelFD[1]);

	[(id)delegate release];
	[readStreams release];
	[writeStreams release];
	[queue release];
	[queueInfo release];
	[queueFDs release];
#ifdef OF_THREADS
	[mutex release];
#endif

	[super dealloc];
}

- (id <OFStreamObserverDelegate>)delegate
{
	OF_GETTER(delegate, YES)
	return delegate;
}

- (void)setDelegate: (id <OFStreamObserverDelegate>)delegate_
{
	OF_SETTER(delegate, delegate_, YES, NO)
	delegate = delegate_;
}

- (void)addStreamForReading: (OFStream*)stream
{
	[mutex lock];
	@try {
		int qi = QUEUE_ADD | QUEUE_READ;

Modified src/OFXMLElementBuilder.h from [96a89a4612] to [1346588c64].

105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119







-
+







@interface OFXMLElementBuilder: OFObject <OFXMLParserDelegate>
{
	OFMutableArray *stack;
	id <OFXMLElementBuilderDelegate> delegate;
}

#ifdef OF_HAVE_PROPERTIES
@property (retain) id <OFXMLElementBuilderDelegate> delegate;
@property (assign) id <OFXMLElementBuilderDelegate> delegate;
#endif

/**
 * \brief Creates a new element builder.
 *
 * \return A new, autoreleased OFXMLElementBuilder
 */

Modified src/OFXMLElementBuilder.m from [975d3652b4] to [1a6ed6de0a].

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
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







-






-
+




-
+








	return self;
}

- (void)dealloc
{
	[stack release];
	[(id)delegate release];

	[super dealloc];
}

- (id <OFXMLElementBuilderDelegate>)delegate
{
	OF_GETTER(delegate, YES)
	return delegate;
}

- (void)setDelegate: (id <OFXMLElementBuilderDelegate>)delegate_
{
	OF_SETTER(delegate, delegate_, YES, NO)
	delegate = delegate_;
}

-		 (void)parser: (OFXMLParser*)parser
  foundProcessingInstructions: (OFString*)pi
{
}

Modified src/OFXMLParser.h from [6eacff2ae6] to [32c6093d57].

166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
166
167
168
169
170
171
172

173
174
175
176
177
178
179
180







-
+







	size_t lineNumber;
	BOOL lastCarriageReturn;
	BOOL finishedParsing;
	of_string_encoding_t encoding;
}

#ifdef OF_HAVE_PROPERTIES
@property (retain) id <OFXMLParserDelegate> delegate;
@property (assign) id <OFXMLParserDelegate> delegate;
#endif

/**
 * \brief Creates a new XML parser.
 *
 * \return A new, autoreleased OFXMLParser
 */

Modified src/OFXMLParser.m from [e2b24f34eb] to [6cac706d3c].

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
32
33
34
35
36
37
38


39
40
41
42
43
44
45







-
-







#import "OFFile.h"
#import "OFAutoreleasePool.h"

#import "OFInitializationFailedException.h"
#import "OFMalformedXMLException.h"
#import "OFUnboundNamespaceException.h"

#import "macros.h"

typedef void (*state_function)(id, SEL, const char*, size_t*, size_t*);
static SEL selectors[OF_XMLPARSER_NUM_STATES];
static state_function lookupTable[OF_XMLPARSER_NUM_STATES];

static OF_INLINE void
cache_append(OFDataArray *cache, const char *string,
    of_string_encoding_t encoding, size_t length)
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

233
234
235
236
237

238
239
240
241
242
243
244
207
208
209
210
211
212
213


214
215
216
217
218
219
220
221
222
223
224
225
226
227

228
229
230
231
232

233
234
235
236
237
238
239
240







-
-














-
+




-
+







	}

	return self;
}

- (void)dealloc
{
	[(id)delegate release];

	[cache release];
	[name release];
	[prefix release];
	[namespaces release];
	[attributes release];
	[attributeName release];
	[attributePrefix release];
	[previous release];

	[super dealloc];
}

- (id <OFXMLParserDelegate>)delegate
{
	OF_GETTER(delegate, YES)
	return delegate;
}

- (void)setDelegate: (id <OFXMLParserDelegate>)delegate_
{
	OF_SETTER(delegate, delegate_, YES, NO)
	delegate = delegate_;
}

- (void)parseBuffer: (const char*)buffer
	 withLength: (size_t)length
{
	size_t i, last = 0;