ObjFW  Check-in [042a74a6e6]

Overview
Comment:Don't throw an OFNoMemException in - freeMem:. It won't help anyway.

If there's not even enough memory to make the list of memchunks
smaller, there can't be much done anyway. The only way is to ignore
it and hope the whole object gets free'd soon, as the memchunk will
be free'd then as well.

Additionally, the OFOutOfRangeException was replaced by an assert. It
should never overflow here as we're making it smaller. And a size of 0
can't happen as we already found the memchunk before.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 042a74a6e6f28f06f439900b7e511527c7d05325f35e15c8ba877bd9178f0d76
User & Date: js on 2009-05-03 14:48:41
Other Links: manifest | tags
Context
2009-05-03
14:59
Get rid of two unnecessary variables. check-in: 1b7a52cdf5 user: js tags: trunk
14:48
Don't throw an OFNoMemException in - freeMem:. It won't help anyway. check-in: 042a74a6e6 user: js tags: trunk
14:20
Fix wrong free in OFString. Should be [self freeMem:]. check-in: 441e5ec29b user: js tags: trunk
Changes

Modified src/OFObject.m from [a774c5de86] to [a14dce520b].

10
11
12
13
14
15
16

17
18
19
20
21
22
23
 */

#import "config.h"

#include <stdlib.h>
#include <string.h>
#include <limits.h>


#import "OFObject.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "OFMacros.h"

#import <objc/objc-api.h>







>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 */

#import "config.h"

#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <assert.h>

#import "OFObject.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "OFMacros.h"

#import <objc/objc-api.h>
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
	while (iter-- > PRE_IVAR->memchunks) {
		i--;

		if (OF_UNLIKELY(*iter == ptr)) {
			memchunks_size = PRE_IVAR->memchunks_size - 1;
			last = PRE_IVAR->memchunks[memchunks_size];

			if (OF_UNLIKELY(PRE_IVAR->memchunks_size == 0 ||
			    memchunks_size > SIZE_MAX / sizeof(void*)))
				@throw [OFOutOfRangeException
				    newWithClass: isa];

			if (OF_UNLIKELY(memchunks_size == 0)) {
				free(ptr);
				free(PRE_IVAR->memchunks);

				PRE_IVAR->memchunks = NULL;
				PRE_IVAR->memchunks_size = 0;

				return self;
			}

			if (OF_UNLIKELY((memchunks = realloc(
			    PRE_IVAR->memchunks, memchunks_size *
			    sizeof(void*))) == NULL))
				@throw [OFNoMemException
				    newWithClass: isa
					 andSize: memchunks_size];

			free(ptr);
			PRE_IVAR->memchunks = memchunks;
			PRE_IVAR->memchunks[i] = last;
			PRE_IVAR->memchunks_size = memchunks_size;

			return self;







|
|
<
<














|
<
<







323
324
325
326
327
328
329
330
331


332
333
334
335
336
337
338
339
340
341
342
343
344
345
346


347
348
349
350
351
352
353
	while (iter-- > PRE_IVAR->memchunks) {
		i--;

		if (OF_UNLIKELY(*iter == ptr)) {
			memchunks_size = PRE_IVAR->memchunks_size - 1;
			last = PRE_IVAR->memchunks[memchunks_size];

			assert(PRE_IVAR->memchunks_size != 0 &&
			    memchunks_size <= SIZE_MAX / sizeof(void*));



			if (OF_UNLIKELY(memchunks_size == 0)) {
				free(ptr);
				free(PRE_IVAR->memchunks);

				PRE_IVAR->memchunks = NULL;
				PRE_IVAR->memchunks_size = 0;

				return self;
			}

			if (OF_UNLIKELY((memchunks = realloc(
			    PRE_IVAR->memchunks, memchunks_size *
			    sizeof(void*))) == NULL))
				return self;



			free(ptr);
			PRE_IVAR->memchunks = memchunks;
			PRE_IVAR->memchunks[i] = last;
			PRE_IVAR->memchunks_size = memchunks_size;

			return self;