ObjFW  Check-in [9e6dd00ef5]

Overview
Comment:Rename - free to - (void)dealloc.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9e6dd00ef5b99294746cc93b18234807ece26db3c989c8e25bb81ab40a52d23e
User & Date: js on 2009-05-13 20:31:38
Other Links: manifest | tags
Context
2009-05-13
20:39
Let - release return void again. check-in: 6d589825cd user: js tags: trunk
20:31
Rename - free to - (void)dealloc. check-in: 9e6dd00ef5 user: js tags: trunk
19:49
There's no need for + initialize to return anything. check-in: 917188fdcc user: js tags: trunk
Changes

Modified src/OFArray.m from [a36255520a] to [14d672c6d1].

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
	self = [super init];

	@try {
		array = [[OFDataArray alloc]
		    initWithItemSize: sizeof(OFObject*)];
	} @catch (OFException *e) {
		/*
		 * We can't use [super free] on OS X here. Compiler bug?
		 * [self free] will do here as we check for nil in free.
		 */
		[self free];
		@throw e;
	}

	return self;
}

- (size_t)count







|
|

|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
	self = [super init];

	@try {
		array = [[OFDataArray alloc]
		    initWithItemSize: sizeof(OFObject*)];
	} @catch (OFException *e) {
		/*
		 * We can't use [super dealloc] on OS X here. Compiler bug?
		 * [self dealloc] will do here as we check for nil in dealloc.
		 */
		[self dealloc];
		@throw e;
	}

	return self;
}

- (size_t)count
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
		[objs[i] release];

	[array removeNItems: nobjects];

	return self;
}

- free
{
	OFObject **objs;
	size_t len, i;

	if (array != nil) {
		objs = [array data];
		len = [array count];

		for (i = 0; i < len; i++)
			[objs[i] release];

		[array release];
	}

	return [super free];
}
@end







|














|


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
		[objs[i] release];

	[array removeNItems: nobjects];

	return self;
}

- (void)dealloc
{
	OFObject **objs;
	size_t len, i;

	if (array != nil) {
		objs = [array data];
		len = [array count];

		for (i = 0; i < len; i++)
			[objs[i] release];

		[array release];
	}

	[super dealloc];
}
@end

Modified src/OFAutoreleasePool.m from [5bcc5ee828] to [4d907e6ad8].

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
+ (void)addToPool: (OFObject*)obj
{
	OFList *pool_list;

	@try {
		pool_list = [OFThread objectForTLSKey: pool_list_key];
	} @catch (OFNotInSetException *e) {
		[e free];
		[[self alloc] init];
		pool_list = [OFThread objectForTLSKey: pool_list_key];
	}

	if ([pool_list last] == NULL)
		[[self alloc] init];








|







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
+ (void)addToPool: (OFObject*)obj
{
	OFList *pool_list;

	@try {
		pool_list = [OFThread objectForTLSKey: pool_list_key];
	} @catch (OFNotInSetException *e) {
		[e dealloc];
		[[self alloc] init];
		pool_list = [OFThread objectForTLSKey: pool_list_key];
	}

	if ([pool_list last] == NULL)
		[[self alloc] init];

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
	self = [super init];

	objects = nil;

	@try {
		pool_list = [OFThread objectForTLSKey: pool_list_key];
	} @catch (OFNotInSetException *e) {
		[e free];
		pool_list = [[OFList alloc] initWithoutRetainAndRelease];
		[OFThread setObject: pool_list
			  forTLSKey: pool_list_key];
		[pool_list release];
	}

	listobj = [pool_list append: self];

	return self;
}

- free
{
	/*
	 * FIXME:
	 * Maybe we should get the objects ourself, release them and then
	 * release the pool without calling its release method? This way,
	 * there wouldn't be a recursion.
	 */
	if (listobj->next != NULL)
		[listobj->next->object release];

	[[OFThread objectForTLSKey: pool_list_key] remove: listobj];

	return [super free];
}

- addToPool: (OFObject*)obj
{
	if (objects == nil)
		objects = [[OFArray alloc] init];








|











|












|







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
	self = [super init];

	objects = nil;

	@try {
		pool_list = [OFThread objectForTLSKey: pool_list_key];
	} @catch (OFNotInSetException *e) {
		[e dealloc];
		pool_list = [[OFList alloc] initWithoutRetainAndRelease];
		[OFThread setObject: pool_list
			  forTLSKey: pool_list_key];
		[pool_list release];
	}

	listobj = [pool_list append: self];

	return self;
}

- (void)dealloc
{
	/*
	 * FIXME:
	 * Maybe we should get the objects ourself, release them and then
	 * release the pool without calling its release method? This way,
	 * there wouldn't be a recursion.
	 */
	if (listobj->next != NULL)
		[listobj->next->object release];

	[[OFThread objectForTLSKey: pool_list_key] remove: listobj];

	[super dealloc];
}

- addToPool: (OFObject*)obj
{
	if (objects == nil)
		objects = [[OFArray alloc] init];

Modified src/OFDataArray.m from [8ce162a9da] to [f9593924bb].

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{
	Class c;

	self = [super init];

	if (is == 0) {
		c = isa;
		[super free];
		@throw [OFInvalidArgumentException newWithClass: c];
	}

	data = NULL;
	itemsize = is;
	count = 0;








|







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{
	Class c;

	self = [super init];

	if (is == 0) {
		c = isa;
		[super dealloc];
		@throw [OFInvalidArgumentException newWithClass: c];
	}

	data = NULL;
	itemsize = is;
	count = 0;

Modified src/OFDictionary.m from [8b4c9a4782] to [967868d132].

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
	size = 4096;

	@try {
		data = [self allocNItems: size
				withSize: sizeof(OFList*)];
	} @catch (OFException *e) {
		/*
		 * We can't use [super free] on OS X here. Compiler bug?
		 * Anyway, set size to 0 so that [self free] works.
		 */
		size = 0;
		[self free];
		@throw e;
	}
	memset(data, 0, size * sizeof(OFList*));

	return self;
}

- initWithHashSize: (int)hashsize
{
	self = [super init];

	if (hashsize < 8 || hashsize >= 28) {
		Class c = isa;
		[super free];
		@throw [OFInvalidArgumentException newWithClass: c
						    andSelector: _cmd];
	}

	size = (size_t)1 << hashsize;

	@try {
		data = [self allocNItems: size
				withSize: sizeof(OFList*)];
	} @catch (OFException *e) {
		/*
		 * We can't use [super free] on OS X here. Compiler bug?
		 * Anyway, set size to 0 so that [self free] works.
		 */
		size = 0;
		[self free];
		@throw e;
	}
	memset(data, 0, size * sizeof(OFList*));

	return self;
}

- free
{
	size_t i;

	for (i = 0; i < size; i++)
		if (data[i] != nil)
			[data[i] release];

	return [super free];
}

- set: (OFObject*)key
   to: (OFObject*)obj
{
	uint32_t hash;
	of_list_object_t *iter;







|
|


|













|











|
|


|







|







|







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
	size = 4096;

	@try {
		data = [self allocNItems: size
				withSize: sizeof(OFList*)];
	} @catch (OFException *e) {
		/*
		 * We can't use [super dealloc] on OS X here. Compiler bug?
		 * Anyway, set size to 0 so that [self dealloc] works.
		 */
		size = 0;
		[self dealloc];
		@throw e;
	}
	memset(data, 0, size * sizeof(OFList*));

	return self;
}

- initWithHashSize: (int)hashsize
{
	self = [super init];

	if (hashsize < 8 || hashsize >= 28) {
		Class c = isa;
		[super dealloc];
		@throw [OFInvalidArgumentException newWithClass: c
						    andSelector: _cmd];
	}

	size = (size_t)1 << hashsize;

	@try {
		data = [self allocNItems: size
				withSize: sizeof(OFList*)];
	} @catch (OFException *e) {
		/*
		 * We can't use [super dealloc] on OS X here. Compiler bug?
		 * Anyway, set size to 0 so that [self dealloc] works.
		 */
		size = 0;
		[self dealloc];
		@throw e;
	}
	memset(data, 0, size * sizeof(OFList*));

	return self;
}

- (void)dealloc
{
	size_t i;

	for (i = 0; i < size; i++)
		if (data[i] != nil)
			[data[i] release];

	[super dealloc];
}

- set: (OFObject*)key
   to: (OFObject*)obj
{
	uint32_t hash;
	of_list_object_t *iter;

Modified src/OFExceptions.h from [a500d93cbc] to [df20b2266d].

11
12
13
14
15
16
17
18

19
20
21
22
23
24
25

#import "OFObject.h"

/**
 * An exception indicating an object could not be allocated.
 *
 * This exception is preallocated, as if there's no memory, no exception can
 * be allocated of course. That's why you shouldn't and even can't free it.

 *
 * This is the only exception that is not an OFException as it's special.
 * It does not know for which class allocation failed and it should not be
 * handled like other exceptions, as the exception handling code is not
 * allowed to allocate ANY memory.
 */
@interface OFAllocFailedException







|
>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

#import "OFObject.h"

/**
 * An exception indicating an object could not be allocated.
 *
 * This exception is preallocated, as if there's no memory, no exception can
 * be allocated of course. That's why you shouldn't and even can't deallocate
 *it.
 *
 * This is the only exception that is not an OFException as it's special.
 * It does not know for which class allocation failed and it should not be
 * handled like other exceptions, as the exception handling code is not
 * allowed to allocate ANY memory.
 */
@interface OFAllocFailedException

Modified src/OFExceptions.m from [ff4dc30f8c] to [0cbb296450].

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

	class = class_;
	string = NULL;

	return self;
}

- free
{
	if (string != NULL)
		free(string);

	return [super free];
}

- (Class)inClass
{
	return class;
}








|




|







69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

	class = class_;
	string = NULL;

	return self;
}

- (void)dealloc
{
	if (string != NULL)
		free(string);

	[super dealloc];
}

- (Class)inClass
{
	return class;
}

305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
	path = (path_ != NULL ? strdup(path_) : NULL);
	mode = (mode_ != NULL ? strdup(mode_) : NULL);
	err = GET_ERR;

	return self;
}

- free
{
	if (path != NULL)
		free(path);
	if (mode != NULL)
		free(mode);

	return [super free];
}

- (const char*)cString
{
	if (string != NULL)
		return string;








|






|







305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
	path = (path_ != NULL ? strdup(path_) : NULL);
	mode = (mode_ != NULL ? strdup(mode_) : NULL);
	err = GET_ERR;

	return self;
}

- (void)dealloc
{
	if (path != NULL)
		free(path);
	if (mode != NULL)
		free(mode);

	[super dealloc];
}

- (const char*)cString
{
	if (string != NULL)
		return string;

527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
	node = (node_ != NULL ? strdup(node_) : NULL);
	service = (service_ != NULL ? strdup(service_) : NULL);
	err = GET_SOCK_ERR;

	return self;
}

- free
{
	if (node != NULL)
		free(node);
	if (service != NULL)
		free(node);

	return [super free];
}

- (const char*)cString
{
	if (string != NULL)
		return string;








|






|







527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
	node = (node_ != NULL ? strdup(node_) : NULL);
	service = (service_ != NULL ? strdup(service_) : NULL);
	err = GET_SOCK_ERR;

	return self;
}

- (void)dealloc
{
	if (node != NULL)
		free(node);
	if (service != NULL)
		free(node);

	[super dealloc];
}

- (const char*)cString
{
	if (string != NULL)
		return string;

591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
	host = (host_ != NULL ? strdup(host_) : NULL);
	port = port_;
	err = GET_SOCK_ERR;

	return self;
}

- free
{
	if (host != NULL)
		free(host);

	return [super free];
}

- (const char*)cString
{
	if (string != NULL)
		return string;








|




|







591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
	host = (host_ != NULL ? strdup(host_) : NULL);
	port = port_;
	err = GET_SOCK_ERR;

	return self;
}

- (void)dealloc
{
	if (host != NULL)
		free(host);

	[super dealloc];
}

- (const char*)cString
{
	if (string != NULL)
		return string;

653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
	port = port_;
	family = family_;
	err = GET_SOCK_ERR;

	return self;
}

- free
{
	if (host != NULL)
		free(host);

	return [super free];
}

- (const char*)cString
{
	if (string != NULL)
		return string;








|




|







653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
	port = port_;
	family = family_;
	err = GET_SOCK_ERR;

	return self;
}

- (void)dealloc
{
	if (host != NULL)
		free(host);

	[super dealloc];
}

- (const char*)cString
{
	if (string != NULL)
		return string;

Modified src/OFFile.m from [3e41bb8976] to [57318981b1].

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
{
	Class c;

	self = [super init];

	if ((fp = fopen(path, mode)) == NULL) {
		c = isa;
		[super free];
		@throw [OFOpenFileFailedException newWithClass: c 
						       andPath: path
						       andMode: mode];
	}

	return self;
}

- free
{
	if (fp != NULL)
		fclose(fp);

	return [super free];
}

- (BOOL)atEndOfFile
{
	if (fp == NULL)
		return YES;








|








|




|







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
{
	Class c;

	self = [super init];

	if ((fp = fopen(path, mode)) == NULL) {
		c = isa;
		[super dealloc];
		@throw [OFOpenFileFailedException newWithClass: c 
						       andPath: path
						       andMode: mode];
	}

	return self;
}

- (void)dealloc
{
	if (fp != NULL)
		fclose(fp);

	[super dealloc];
}

- (BOOL)atEndOfFile
{
	if (fp == NULL)
		return YES;

Modified src/OFList.m from [d0531ab5cf] to [e1882a13b8].

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
	first = NULL;
	last = NULL;
	retain_and_release = NO;

	return self;
}

- free
{
	of_list_object_t *iter;

	for (iter = first; iter != NULL; iter = iter->next)
		[iter->object release];

	return [super free];
}

- (of_list_object_t*)first
{
	return first;
}








|






|







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
	first = NULL;
	last = NULL;
	retain_and_release = NO;

	return self;
}

- (void)dealloc
{
	of_list_object_t *iter;

	for (iter = first; iter != NULL; iter = iter->next)
		[iter->object release];

	[super dealloc];
}

- (of_list_object_t*)first
{
	return first;
}

Modified src/OFMutableString.m from [d47bbbd95a] to [f3d57089d4].

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

		switch (check_utf8(str, length)) {
			case 1:
				is_utf8 = YES;
				break;
			case -1:
				c = isa;
				[super free];
				@throw [OFInvalidEncodingException
					newWithClass: c];
		}

		@try {
			string = [self allocWithSize: length + 1];
		} @catch (OFException *e) {
			/*
			 * We can't use [super free] on OS X here. Compiler bug?

			 * [self free] will do here as we don't reimplement
			 * free.
			 */
			[self free];
			@throw e;
		}
		memcpy(string, str, length + 1);
	}

	return self;
}







|








|
>
|
<

|







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

		switch (check_utf8(str, length)) {
			case 1:
				is_utf8 = YES;
				break;
			case -1:
				c = isa;
				[super dealloc];
				@throw [OFInvalidEncodingException
					newWithClass: c];
		}

		@try {
			string = [self allocWithSize: length + 1];
		} @catch (OFException *e) {
			/*
			 * We can't use [super dealloc] on OS X here.
			 * Compiler bug? Anyway, [self dealloc] will do here as
			 * we don't reimplement dealloc.

			 */
			[self dealloc];
			@throw e;
		}
		memcpy(string, str, length + 1);
	}

	return self;
}
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
	int t;
	Class c;

	self = [super init];

	if (fmt == NULL) {
		c = isa;
		[super free];
		@throw [OFInvalidFormatException newWithClass: c];
	}

	if ((t = vasprintf(&string, fmt, args)) == -1) {
		c = isa;
		[super free];
		@throw [OFInitializationFailedException newWithClass: c];
	}
	length = t;

	switch (check_utf8(string, length)) {
		case 1:
			is_utf8 = YES;
			break;
		case -1:
			free(string);
			c = isa;
			[super free];
			@throw [OFInvalidEncodingException newWithClass: c];
	}

	@try {
		[self addToMemoryPool: string];
	} @catch (OFException *e) {
		free(string);







|





|











|







168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
	int t;
	Class c;

	self = [super init];

	if (fmt == NULL) {
		c = isa;
		[super dealloc];
		@throw [OFInvalidFormatException newWithClass: c];
	}

	if ((t = vasprintf(&string, fmt, args)) == -1) {
		c = isa;
		[super dealloc];
		@throw [OFInitializationFailedException newWithClass: c];
	}
	length = t;

	switch (check_utf8(string, length)) {
		case 1:
			is_utf8 = YES;
			break;
		case -1:
			free(string);
			c = isa;
			[super dealloc];
			@throw [OFInvalidEncodingException newWithClass: c];
	}

	@try {
		[self addToMemoryPool: string];
	} @catch (OFException *e) {
		free(string);

Modified src/OFObject.h from [daf333a5b7] to [aacf1f5953].

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
 *
 * \return A 32 bit hash for the object
 */
- (uint32_t)hash;

/**
 * Adds a pointer to the memory pool.

 * This is useful to add memory allocated by functions such as asprintf to the
 * pool so it gets freed automatically when the object is freed.
 *
 * \param ptr A pointer to add to the memory pool
 */
- addToMemoryPool: (void*)ptr;

/**
 * Allocate memory and store it in the objects memory pool so it can be free'd
 * automatically when the object is free'd.
 *
 * \param size The size of the memory to allocate
 * \return A pointer to the allocated memory
 */
- (void*)allocWithSize: (size_t)size;

/**
 * Allocate memory for a specified number of items and store it in the objects
 * memory pool so it can be free'd automatically when the object is free'd.
 *
 * \param nitems The number of items to allocate
 * \param size The size of each item to allocate
 * \return A pointer to the allocated memory
 */
- (void*)allocNItems: (size_t)nitems
	    withSize: (size_t)size;







>

|







|








|







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
 *
 * \return A 32 bit hash for the object
 */
- (uint32_t)hash;

/**
 * Adds a pointer to the memory pool.
 *
 * This is useful to add memory allocated by functions such as asprintf to the
 * pool so it gets free'd automatically when the object is deallocated.
 *
 * \param ptr A pointer to add to the memory pool
 */
- addToMemoryPool: (void*)ptr;

/**
 * Allocate memory and store it in the objects memory pool so it can be free'd
 * automatically when the object is deallocated.
 *
 * \param size The size of the memory to allocate
 * \return A pointer to the allocated memory
 */
- (void*)allocWithSize: (size_t)size;

/**
 * Allocate memory for a specified number of items and store it in the objects
 * memory pool so it can be free'd automatically when the object is deallocated.
 *
 * \param nitems The number of items to allocate
 * \param size The size of each item to allocate
 * \return A pointer to the allocated memory
 */
- (void*)allocNItems: (size_t)nitems
	    withSize: (size_t)size;
196
197
198
199
200
201
202
203
204
205
206
207
208

209
210
211

/**
 * \return The retain count
 */
- (size_t)retainCount;

/**
 * Decreases the retain cound and frees the object if it reaches 0.
 */
- release;

/**
 * Frees the object and also frees all memory allocated via its memory pool.

 */
- free;
@end







|




|
>

|

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

/**
 * \return The retain count
 */
- (size_t)retainCount;

/**
 * Decreases the retain cound and deallocates the object if it reaches 0.
 */
- release;

/**
 * Deallocates the object and also frees all memory allocated via its memory
 * pool.
 */
- (void)dealloc;
@end

Modified src/OFObject.m from [168ac17ab0] to [e6b5b1a83b].

366
367
368
369
370
371
372
373

374

375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
- (size_t)retainCount
{
	return PRE_IVAR->retain_count;
}

- release
{
	if (!--PRE_IVAR->retain_count)

		return [self free];


	return self;
}

- free
{
	void **iter = PRE_IVAR->memchunks + PRE_IVAR->memchunks_size;

	while (iter-- > PRE_IVAR->memchunks)
		free(*iter);

	if (PRE_IVAR->memchunks != NULL)
		free(PRE_IVAR->memchunks);

	free((char*)self - PRE_IVAR_ALIGN);
	return nil;
}
@end







|
>
|
>




|










<


366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391

392
393
- (size_t)retainCount
{
	return PRE_IVAR->retain_count;
}

- release
{
	if (!--PRE_IVAR->retain_count) {
		[self dealloc];
		return nil;
	}

	return self;
}

- (void)dealloc
{
	void **iter = PRE_IVAR->memchunks + PRE_IVAR->memchunks_size;

	while (iter-- > PRE_IVAR->memchunks)
		free(*iter);

	if (PRE_IVAR->memchunks != NULL)
		free(PRE_IVAR->memchunks);

	free((char*)self - PRE_IVAR_ALIGN);

}
@end

Modified src/OFPlugin.m from [b318936bd6] to [0c45c3aa04].

51
52
53
54
55
56
57
58
59
60
61
62
63
64
		@throw [OFInitializationFailedException newWithClass: self];
	}

	plugin->handle = handle;
	return plugin;
}

- free
{
	dlclose(handle);

	return [super free];
}
@end







|



|


51
52
53
54
55
56
57
58
59
60
61
62
63
64
		@throw [OFInitializationFailedException newWithClass: self];
	}

	plugin->handle = handle;
	return plugin;
}

- (void)dealloc
{
	dlclose(handle);

	[super dealloc];
}
@end

Modified src/OFTCPSocket.m from [6d74cb7c82] to [713f66fbf8].

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
	sock = INVALID_SOCKET;
	saddr = NULL;
	saddr_len = 0;

	return self;
}

- free
{
	if (sock != INVALID_SOCKET)
		close(sock);

	return [super free];
}

- connectTo: (const char*)host
     onPort: (uint16_t)port
{
	struct addrinfo hints, *res, *res0;
	char portstr[6];







|




|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
	sock = INVALID_SOCKET;
	saddr = NULL;
	saddr_len = 0;

	return self;
}

- (void)dealloc
{
	if (sock != INVALID_SOCKET)
		close(sock);

	[super dealloc];
}

- connectTo: (const char*)host
     onPort: (uint16_t)port
{
	struct addrinfo hints, *res, *res0;
	char portstr[6];
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

	newsock = [OFTCPSocket tcpSocket];
	addrlen = sizeof(struct sockaddr);

	@try {
		addr = [newsock allocWithSize: sizeof(struct sockaddr)];
	} @catch (OFException *e) {
		[newsock free];
		@throw e;
	}

	if ((s = accept(sock, addr, &addrlen)) == INVALID_SOCKET) {
		[newsock free];
		@throw [OFAcceptFailedException newWithClass: isa];
	}

	newsock->sock = s;
	newsock->saddr = addr;
	newsock->saddr_len = addrlen;








|




|







172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

	newsock = [OFTCPSocket tcpSocket];
	addrlen = sizeof(struct sockaddr);

	@try {
		addr = [newsock allocWithSize: sizeof(struct sockaddr)];
	} @catch (OFException *e) {
		[newsock dealloc];
		@throw e;
	}

	if ((s = accept(sock, addr, &addrlen)) == INVALID_SOCKET) {
		[newsock dealloc];
		@throw [OFAcceptFailedException newWithClass: isa];
	}

	newsock->sock = s;
	newsock->saddr = addr;
	newsock->saddr_len = addrlen;

Modified src/OFThread.m from [afc7a8ea8e] to [e453479303].

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  forTLSKey: (OFTLSKey*)key
{
	id old;

	@try {
		old = [self objectForTLSKey: key];
	} @catch (OFNotInSetException *e) {
		[e free];
		old = nil;
	}

#ifndef _WIN32
	if (pthread_setspecific(key->key, obj))
#else
	if (!TlsSetValue(key->key, obj))







|







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  forTLSKey: (OFTLSKey*)key
{
	id old;

	@try {
		old = [self objectForTLSKey: key];
	} @catch (OFNotInSetException *e) {
		[e dealloc];
		old = nil;
	}

#ifndef _WIN32
	if (pthread_setspecific(key->key, obj))
#else
	if (!TlsSetValue(key->key, obj))
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef _WIN32
	if (pthread_create(&thread, NULL, call_main, self)) {
#else
	if ((thread =
	    CreateThread(NULL, 0, call_main, self, 0, NULL)) == NULL) {
#endif
		c = isa;
		[super free];
		@throw [OFInitializationFailedException newWithClass: c];
	}

	return self;
}

- main







|







104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef _WIN32
	if (pthread_create(&thread, NULL, call_main, self)) {
#else
	if ((thread =
	    CreateThread(NULL, 0, call_main, self, 0, NULL)) == NULL) {
#endif
		c = isa;
		[super dealloc];
		@throw [OFInitializationFailedException newWithClass: c];
	}

	return self;
}

- main
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
	CloseHandle(thread);
	thread = INVALID_HANDLE_VALUE;

	return retval;
#endif
}

- free
{
	/*
	 * No need to handle errors - if canceling the thread fails, we can't
	 * do anything anyway. Most likely, it finished already or was already
	 * canceled.
	 */
#ifndef _WIN32
	pthread_cancel(thread);
#else
	if (thread != INVALID_HANDLE_VALUE) {
		TerminateThread(thread, 1);
		CloseHandle(thread);
	}
#endif

	return [super free];
}
@end

@implementation OFTLSKey
+ tlsKeyWithDestructor: (void(*)(void*))destructor
{
	return [[[OFTLSKey alloc] initWithDestructor: destructor] autorelease];







|















|







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
	CloseHandle(thread);
	thread = INVALID_HANDLE_VALUE;

	return retval;
#endif
}

- (void)dealloc
{
	/*
	 * No need to handle errors - if canceling the thread fails, we can't
	 * do anything anyway. Most likely, it finished already or was already
	 * canceled.
	 */
#ifndef _WIN32
	pthread_cancel(thread);
#else
	if (thread != INVALID_HANDLE_VALUE) {
		TerminateThread(thread, 1);
		CloseHandle(thread);
	}
#endif

	[super dealloc];
}
@end

@implementation OFTLSKey
+ tlsKeyWithDestructor: (void(*)(void*))destructor
{
	return [[[OFTLSKey alloc] initWithDestructor: destructor] autorelease];
178
179
180
181
182
183
184
185
186
187
188
189
190
191
	/* FIXME: Call destructor on Win32 */
#ifndef _WIN32
	if (pthread_key_create(&key, destructor)) {
#else
	if ((key = TlsAlloc()) == TLS_OUT_OF_INDEXES) {
#endif
		c = isa;
		[super free];
		@throw [OFInitializationFailedException newWithClass: c];
	}

	return self;
}
@end







|






178
179
180
181
182
183
184
185
186
187
188
189
190
191
	/* FIXME: Call destructor on Win32 */
#ifndef _WIN32
	if (pthread_key_create(&key, destructor)) {
#else
	if ((key = TlsAlloc()) == TLS_OUT_OF_INDEXES) {
#endif
		c = isa;
		[super dealloc];
		@throw [OFInitializationFailedException newWithClass: c];
	}

	return self;
}
@end

Modified tests/OFString/OFString.m from [1b4738a285] to [a3755365c5].

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
	CHECK_EXCEPT(s1 = [OFString stringWithCString: "\xE0\x80"],
	    OFInvalidEncodingException)
	CHECK_EXCEPT(s1 = [OFString stringWithCString: "\xF0\x80\x80\xC0"],
	    OFInvalidEncodingException)

	s1 = [OFString stringWithCString: "äöü€𝄞"];
	CHECK(!strcmp([[s1 reverse] cString], "𝄞€üöä"))
	[s1 free];

	/* Format tests */
	s1 = [OFString stringWithFormat: "%s: %d", "test", 123];
	CHECK(!strcmp([s1 cString], "test: 123"))

	[s1 appendWithFormatCString: "%02X", 15];
	CHECK(!strcmp([s1 cString], "test: 1230F"))







|







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
	CHECK_EXCEPT(s1 = [OFString stringWithCString: "\xE0\x80"],
	    OFInvalidEncodingException)
	CHECK_EXCEPT(s1 = [OFString stringWithCString: "\xF0\x80\x80\xC0"],
	    OFInvalidEncodingException)

	s1 = [OFString stringWithCString: "äöü€𝄞"];
	CHECK(!strcmp([[s1 reverse] cString], "𝄞€üöä"))
	[s1 dealloc];

	/* Format tests */
	s1 = [OFString stringWithFormat: "%s: %d", "test", 123];
	CHECK(!strcmp([s1 cString], "test: 123"))

	[s1 appendWithFormatCString: "%02X", 15];
	CHECK(!strcmp([s1 cString], "test: 1230F"))