ObjFW  Check-in [d57228d9d6]

Overview
Comment:Allow NULL as parameter for -[freeMemory:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d57228d9d6debae39021003e8cbe8e3583fa6213f14c86a47d21fa59365a6adc
User & Date: js on 2009-11-29 16:23:12
Other Links: manifest | tags
Context
2009-12-01
12:55
Make sure we never even check for CC by using OBJCPP as CPP. check-in: 9a733d824f user: js tags: trunk
2009-11-29
16:23
Allow NULL as parameter for -[freeMemory:]. check-in: d57228d9d6 user: js tags: trunk
14:00
Fix inline assembly on x86_64 for gcc with -O. check-in: 1f38dbc88e user: js tags: trunk
Changes

Modified src/OFMutableString.m from [ae31141f77] to [8b3fe48252].

121
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
121
122
123
124
125
126
127


128
129
130
131
132
133
134
135







-
-
+







}

@implementation OFMutableString
- setToCString: (const char*)str
{
	size_t len;

	if (string != NULL)
		[self freeMemory: string];
	[self freeMemory: string];

	len = strlen(str);

	switch (of_string_check_utf8(str, len)) {
	case 0:
		is_utf8 = NO;
		break;

Modified src/OFObject.h from [65d50f6e31] to [a9bb10dc6d].

244
245
246
247
248
249
250

251
252
253
254
255
256
257
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258







+







 */
- (void*)resizeMemory: (void*)ptr
	     toNItems: (size_t)nitems
	     withSize: (size_t)size;

/**
 * Frees allocated memory and removes it from the object's memory pool.
 * Does nothing if ptr is NULL.
 *
 * \param ptr A pointer to the allocated memory
 */
- freeMemory: (void*)ptr;

/**
 * Increases the retain count.

Modified src/OFObject.m from [81f4a12608] to [f65ab03140].

387
388
389
390
391
392
393



394
395
396
397
398
399
400
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403







+
+
+







			   toSize: nitems * size];
}

- freeMemory: (void*)ptr;
{
	void **iter, *last, **memchunks;
	size_t i, memchunks_size;

	if (ptr == NULL)
		return self;

	iter = PRE_IVAR->memchunks + PRE_IVAR->memchunks_size;
	i = PRE_IVAR->memchunks_size;

	while (iter-- > PRE_IVAR->memchunks) {
		i--;

Modified src/OFStream.m from [1e66caad30] to [2c5ce7298e].

148
149
150
151
152
153
154
155
156

157
158
159
160
161

162
163
164
165
166
167
168
148
149
150
151
152
153
154


155
156
157
158


159
160
161
162
163
164
165
166







-
-
+



-
-
+







					} @catch (OFException *e) {
						[self freeMemory: ret_c];
						[self freeMemory: tmp];
						@throw e;
					}
					memcpy(tmp2, tmp + i + 1, len - i - 1);

					if (cache != NULL)
						[self freeMemory: cache];
					[self freeMemory: cache];
					cache = tmp2;
					cache_len = len - i - 1;
				} else {
					if (cache != NULL)
						[self freeMemory: cache];
					[self freeMemory: cache];
					cache = NULL;
					cache_len = 0;
				}
				[self freeMemory: tmp];

				@try {
					ret = [OFString
215
216
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231
232
233
234
235
236
213
214
215
216
217
218
219


220
221
222
223
224
225
226
227
228
229
230
231
232
233







-
-
+













		*ptr = cache;

	return cache_len;
}

- clearCache
{
	if (cache != NULL)
		[self freeMemory: cache];
	[self freeMemory: cache];

	cache = NULL;
	cache_len = 0;

	return self;
}

- close
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}
@end

Modified src/OFTCPSocket.m from [37839d79ab] to [00e6aa5037].

310
311
312
313
314
315
316

317
318
319

320
321
322
323
324
325
310
311
312
313
314
315
316
317
318


319

320
321
322
323
324







+

-
-
+
-





}

- close
{
	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa];

	[self freeMemory: saddr];
	sock = INVALID_SOCKET;

	if (saddr != NULL)
	saddr = NULL;
		[self freeMemory: saddr];
	saddr_len = 0;

	return self;
}
@end