ObjFW  Check-in [7d7b89d775]

Overview
Comment:Remove spaces and tabs at end of line.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7d7b89d7752b3766871f40b903a88006e5088991b5811df81792992b6904d5a0
User & Date: js on 2008-12-23 03:59:27
Other Links: manifest | tags
Context
2008-12-23
13:42
Make it possible to build only a static library.
This way, it works on Windows.
check-in: d8736e1aa3 user: js tags: trunk
03:59
Remove spaces and tabs at end of line. check-in: 7d7b89d775 user: js tags: trunk
02:10
Check for sys/mman.h before trying to use madvise. check-in: 14ebaa7ca1 user: js tags: trunk
Changes

Modified src/OFArray.h from [2a9748db76] to [0520fcd930].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 * \param is The size of each element in the OFArray
 * \return A new allocated and initialized OFArray
 */
+ newWithItemSize: (size_t)is;

/**
 * Initializes an already allocated OFArray whose items all have the same size.
 * 
 * \param is The size of each element in the OFArray
 * \return An initialized OFArray
 */
- initWithItemSize: (size_t)is;

/**
 * \return The number of items in the OFArray







|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 * \param is The size of each element in the OFArray
 * \return A new allocated and initialized OFArray
 */
+ newWithItemSize: (size_t)is;

/**
 * Initializes an already allocated OFArray whose items all have the same size.
 *
 * \param is The size of each element in the OFArray
 * \return An initialized OFArray
 */
- initWithItemSize: (size_t)is;

/**
 * \return The number of items in the OFArray
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{
	size_t size;
}

/**
 * Initializes an already allocated OFBigArray whose items all have the same
 * size.
 * 
 * \param is The size of each element in the OFBigArray
 * \return An initialized OFBigArray
 */
- initWithItemSize: (size_t)is;

/**
 * Adds an item to the OFBigArray.







|







101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{
	size_t size;
}

/**
 * Initializes an already allocated OFBigArray whose items all have the same
 * size.
 *
 * \param is The size of each element in the OFBigArray
 * \return An initialized OFBigArray
 */
- initWithItemSize: (size_t)is;

/**
 * Adds an item to the OFBigArray.

Modified src/OFExceptions.h from [e908641783] to [f3d6211985].

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
 * \return A pointer to the memory which is not part of the object
 */
- (void*)pointer;
@end

/**
 * An OFException indicating the given value is out of range. 
 */
@interface OFOutOfRangeException: OFException {}
/**
 * \return An error message for the exception as a C String
 */
- (const char*)cString;
@end







|







120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
 * \return A pointer to the memory which is not part of the object
 */
- (void*)pointer;
@end

/**
 * An OFException indicating the given value is out of range.
 */
@interface OFOutOfRangeException: OFException {}
/**
 * \return An error message for the exception as a C String
 */
- (const char*)cString;
@end
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
 * \return An error message for the exception as a C string.
 */
- (const char*)cString;
@end

/**
 * An OFException indicating an attempt to connect or bind an already connected
 * or bound socket 
 */
@interface OFAlreadyConnectedException: OFException {}
/**
 * \return An error message for the exception as a C string.
 */
- (const char*)cString;
@end







|







308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
 * \return An error message for the exception as a C string.
 */
- (const char*)cString;
@end

/**
 * An OFException indicating an attempt to connect or bind an already connected
 * or bound socket.
 */
@interface OFAlreadyConnectedException: OFException {}
/**
 * \return An error message for the exception as a C string.
 */
- (const char*)cString;
@end

Modified src/OFExceptions.m from [7e98f0feae] to [8d853c6d4e].

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
@end

@implementation OFInvalidEncodingException
- (const char*)cString
{
	if (string != NULL)
		return string;
	
	asprintf(&string, "The encoding is invalid for object of classs %s!",
	    [object name]);

	return string;
}
@end








|







142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
@end

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

	asprintf(&string, "The encoding is invalid for object of classs %s!",
	    [object name]);

	return string;
}
@end

Modified src/OFFile.m from [ade2f827ca] to [d2aa51b6f7].

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
	size_t ret;

	if ((ret = fwrite(buf, size, nitems, fp)) == 0 &&
	    size != 0 && nitems != 0)
		@throw [OFWriteFailedException newWithObject: self
						     andSize: size
						   andNItems: nitems];
	
	return ret;
}

- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const uint8_t*)buf
{
	return [self writeNItems: size







|







156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
	size_t ret;

	if ((ret = fwrite(buf, size, nitems, fp)) == 0 &&
	    size != 0 && nitems != 0)
		@throw [OFWriteFailedException newWithObject: self
						     andSize: size
						   andNItems: nitems];

	return ret;
}

- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const uint8_t*)buf
{
	return [self writeNItems: size

Modified src/OFHashes.h from [e8ac1f901b] to [3a54f34787].

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
	BOOL	 calculated;
}

- init;

/**
 * Adds a buffer to the hash to be calculated.
 * 
 * \param buf The buffer which should be included into calculation.
 * \param size The size of the buffer
 */
- updateWithBuffer: (const uint8_t*)buf
	    ofSize: (size_t)size;

/**







|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
	BOOL	 calculated;
}

- init;

/**
 * Adds a buffer to the hash to be calculated.
 *
 * \param buf The buffer which should be included into calculation.
 * \param size The size of the buffer
 */
- updateWithBuffer: (const uint8_t*)buf
	    ofSize: (size_t)size;

/**
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
	BOOL	 calculated;
}

- init;

/**
 * Adds a buffer to the hash to be calculated.
 * 
 * \param buf The buffer which should be included into calculation.
 * \param size The size of the buffer
 */
- updateWithBuffer: (const uint8_t*)buf
	    ofSize: (size_t)size;

/**
 * \return A buffer containing the hash (SHA1_DIGEST_SIZE = 20 bytes).
 *	   The buffer is part of object's memory pool.
 */
- (uint8_t*)digest;
@end







|












57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
	BOOL	 calculated;
}

- init;

/**
 * Adds a buffer to the hash to be calculated.
 *
 * \param buf The buffer which should be included into calculation.
 * \param size The size of the buffer
 */
- updateWithBuffer: (const uint8_t*)buf
	    ofSize: (size_t)size;

/**
 * \return A buffer containing the hash (SHA1_DIGEST_SIZE = 20 bytes).
 *	   The buffer is part of object's memory pool.
 */
- (uint8_t*)digest;
@end

Modified src/OFObject.m from [6f88f8ea70] to [59a115d6f5].

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
		return NULL;

	memchunks_size = __memchunks_size + 1;

	if (SIZE_MAX - __memchunks_size == 0 ||
	    memchunks_size > SIZE_MAX / sizeof(void*))
		@throw [OFOutOfRangeException newWithObject: self];
	
	if ((memchunks = realloc(__memchunks,
	    memchunks_size * sizeof(void*))) == NULL)
		@throw [OFNoMemException newWithObject: self
					       andSize: memchunks_size];

	if ((ptr = malloc(size)) == NULL) {
		free(memchunks);







|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
		return NULL;

	memchunks_size = __memchunks_size + 1;

	if (SIZE_MAX - __memchunks_size == 0 ||
	    memchunks_size > SIZE_MAX / sizeof(void*))
		@throw [OFOutOfRangeException newWithObject: self];

	if ((memchunks = realloc(__memchunks,
	    memchunks_size * sizeof(void*))) == NULL)
		@throw [OFNoMemException newWithObject: self
					       andSize: memchunks_size];

	if ((ptr = malloc(size)) == NULL) {
		free(memchunks);
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
	iter = __memchunks + __memchunks_size;

	while (iter-- > __memchunks) {
		if (OF_UNLIKELY(*iter == ptr)) {
			if (OF_UNLIKELY((ptr = realloc(ptr, size)) == NULL))
				@throw [OFNoMemException newWithObject: self
							       andSize: size];
			
			*iter = ptr;
			return ptr;
		}
	}

	@throw [OFMemNotPartOfObjException newWithObject: self
					      andPointer: ptr];
	return NULL;	/* never reached, but makes gcc happy */
}

- (void*)resizeMem: (void*)ptr
	  toNItems: (size_t)nitems
	    ofSize: (size_t)size
{
	size_t memsize;

	if (ptr == NULL)
		return [self getMemForNItems: nitems
				      ofSize: size];
	
	if (nitems == 0 || size == 0) {
		[self freeMem: ptr];
		return NULL;
	}

	if (nitems > SIZE_MAX / size)
		@throw [OFOutOfRangeException newWithObject: self];







|



















|







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
	iter = __memchunks + __memchunks_size;

	while (iter-- > __memchunks) {
		if (OF_UNLIKELY(*iter == ptr)) {
			if (OF_UNLIKELY((ptr = realloc(ptr, size)) == NULL))
				@throw [OFNoMemException newWithObject: self
							       andSize: size];

			*iter = ptr;
			return ptr;
		}
	}

	@throw [OFMemNotPartOfObjException newWithObject: self
					      andPointer: ptr];
	return NULL;	/* never reached, but makes gcc happy */
}

- (void*)resizeMem: (void*)ptr
	  toNItems: (size_t)nitems
	    ofSize: (size_t)size
{
	size_t memsize;

	if (ptr == NULL)
		return [self getMemForNItems: nitems
				      ofSize: size];

	if (nitems == 0 || size == 0) {
		[self freeMem: ptr];
		return NULL;
	}

	if (nitems > SIZE_MAX / size)
		@throw [OFOutOfRangeException newWithObject: self];

Modified src/OFString.h from [e46bf07ec6] to [eb7e2198d6].

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
	char   *string;
	size_t length;
	BOOL   is_utf8;
}

/**
 * Creates a new OFString.
 * 
 * \return An initialized OFString
 */
+ new;

/**
 * Creates a new OFString from a C string.
 * 
 * \param str A C string to initialize the OFString with
 * \return A new OFString
 */
+ newFromCString: (const char*)str;

/**
 * Initializes an already allocated OFString.
 *
 * \return An initialized OFString
 */
- init;

/**
 * Initializes an already allocated OFString from a C string.
 * 
 * \param str A C string to initialize the OFString with
 * \return An initialized OFString
 */
- initFromCString: (const char*)str;

/**
 * \return The OFString as a wide C string
 */
- (const char*)cString;

/**
 * \return The length of the OFString
 */
- (size_t)length;

/**
 * Clones the OFString, creating a new one.
 * 
 * \return A copy of the OFString
 */
- (OFString*)clone;

/**
 * Frees the OFString and sets it to the specified OFString.
 *







|






|














|

















|







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
	char   *string;
	size_t length;
	BOOL   is_utf8;
}

/**
 * Creates a new OFString.
 *
 * \return An initialized OFString
 */
+ new;

/**
 * Creates a new OFString from a C string.
 *
 * \param str A C string to initialize the OFString with
 * \return A new OFString
 */
+ newFromCString: (const char*)str;

/**
 * Initializes an already allocated OFString.
 *
 * \return An initialized OFString
 */
- init;

/**
 * Initializes an already allocated OFString from a C string.
 *
 * \param str A C string to initialize the OFString with
 * \return An initialized OFString
 */
- initFromCString: (const char*)str;

/**
 * \return The OFString as a wide C string
 */
- (const char*)cString;

/**
 * \return The length of the OFString
 */
- (size_t)length;

/**
 * Clones the OFString, creating a new one.
 *
 * \return A copy of the OFString
 */
- (OFString*)clone;

/**
 * Frees the OFString and sets it to the specified OFString.
 *

Modified src/OFString.m from [845a3454e0] to [37b9bc8f4c].

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
}

- appendCString: (const char*)str
{
	char   *newstr;
	size_t newlen, strlength;

	if (string == NULL) 
		return [self setTo: [OFString newFromCString: str]];

	strlength = strlen(str);

	switch (check_utf8(str, strlength)) {
	case 1:
		is_utf8 = YES;







|







173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
}

- appendCString: (const char*)str
{
	char   *newstr;
	size_t newlen, strlength;

	if (string == NULL)
		return [self setTo: [OFString newFromCString: str]];

	strlength = strlen(str);

	switch (check_utf8(str, strlength)) {
	case 1:
		is_utf8 = YES;
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
- upper
{
	size_t i = length;

	if (is_utf8)
		@throw [OFInvalidEncodingException newWithObject: self];

	while (i--) 
		string[i] = toupper(string[i]);

	return self;
}

- lower
{
	size_t i = length;

	if (is_utf8)
		@throw [OFInvalidEncodingException newWithObject: self];

	while (i--) 
		string[i] = tolower(string[i]);

	return self;
}
@end







|












|





296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
- upper
{
	size_t i = length;

	if (is_utf8)
		@throw [OFInvalidEncodingException newWithObject: self];

	while (i--)
		string[i] = toupper(string[i]);

	return self;
}

- lower
{
	size_t i = length;

	if (is_utf8)
		@throw [OFInvalidEncodingException newWithObject: self];

	while (i--)
		string[i] = tolower(string[i]);

	return self;
}
@end

Modified src/OFTCPSocket.m from [7656e7376a] to [03aa5d92f4].

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
			close(sock);
			sock = -1;
			continue;
		}

		break;
	}
	
	freeaddrinfo(res0);

	if (sock < 0)
		@throw [OFConnectionFailedException newWithObject: self
							  andHost: host
							  andPort: port];








|







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
			close(sock);
			sock = -1;
			continue;
		}

		break;
	}

	freeaddrinfo(res0);

	if (sock < 0)
		@throw [OFConnectionFailedException newWithObject: self
							  andHost: host
							  andPort: port];

203
204
205
206
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
}

- (size_t)readNBytes: (size_t)size
	  intoBuffer: (uint8_t*)buf
{
	ssize_t ret;

	if (sock < 0) 
		@throw [OFNotConnectedException newWithObject: self];

	if ((ret = recv(sock, buf, size, 0)) < 0)
		@throw [OFReadFailedException newWithObject: self
						    andSize: size];

	/* This is safe, as we already checked < 0 */
	return ret;
}

- (uint8_t*)readNBytes: (size_t)size
{
	uint8_t *ret;

	if (sock < 0) 
		@throw [OFNotConnectedException newWithObject: self];

	ret = [self getMemWithSize: size];

	@try {
		[self readNBytes: size
		      intoBuffer: ret];
	} @catch (id exception) {
		[self freeMem: ret];
		@throw exception;
	}

	return ret;
}

- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const uint8_t*)buf
{
	ssize_t ret;

	if (sock < 0) 
		@throw [OFNotConnectedException newWithObject: self];

	if ((ret = send(sock, buf, size, 0)) < 0)
		@throw [OFWriteFailedException newWithObject: self
						     andSize: size];

	/* This is safe, as we already checked < 0 */
	return ret;
}

- (size_t)writeCString: (const char*)str
{
	if (sock < 0) 
		@throw [OFNotConnectedException newWithObject: self];

	return [self writeNBytes: strlen(str)
		      fromBuffer: (const uint8_t*)str];
}

- setBlocking: (BOOL)enable







|














|




















|












|







203
204
205
206
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
}

- (size_t)readNBytes: (size_t)size
	  intoBuffer: (uint8_t*)buf
{
	ssize_t ret;

	if (sock < 0)
		@throw [OFNotConnectedException newWithObject: self];

	if ((ret = recv(sock, buf, size, 0)) < 0)
		@throw [OFReadFailedException newWithObject: self
						    andSize: size];

	/* This is safe, as we already checked < 0 */
	return ret;
}

- (uint8_t*)readNBytes: (size_t)size
{
	uint8_t *ret;

	if (sock < 0)
		@throw [OFNotConnectedException newWithObject: self];

	ret = [self getMemWithSize: size];

	@try {
		[self readNBytes: size
		      intoBuffer: ret];
	} @catch (id exception) {
		[self freeMem: ret];
		@throw exception;
	}

	return ret;
}

- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const uint8_t*)buf
{
	ssize_t ret;

	if (sock < 0)
		@throw [OFNotConnectedException newWithObject: self];

	if ((ret = send(sock, buf, size, 0)) < 0)
		@throw [OFWriteFailedException newWithObject: self
						     andSize: size];

	/* This is safe, as we already checked < 0 */
	return ret;
}

- (size_t)writeCString: (const char*)str
{
	if (sock < 0)
		@throw [OFNotConnectedException newWithObject: self];

	return [self writeNBytes: strlen(str)
		      fromBuffer: (const uint8_t*)str];
}

- setBlocking: (BOOL)enable
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
		@throw [OFSetOptionFailedException newWithObject: self];

	return self;
}

- close
{
	if (sock < 0) 
		@throw [OFNotConnectedException newWithObject: self];

	sock = -1;

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

	return self;
}
@end
#endif







|












288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
		@throw [OFSetOptionFailedException newWithObject: self];

	return self;
}

- close
{
	if (sock < 0)
		@throw [OFNotConnectedException newWithObject: self];

	sock = -1;

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

	return self;
}
@end
#endif

Modified src/OFXMLFactory.m from [c933d562df] to [95cdbcf61d].

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
			 * escapeCString already throws an exception,
			 * no need to throw a second one here.
			 */
			free(xml);
			return NULL;
		}

		if (OF_UNLIKELY(!xf_resize_chars(&xml, &len, 1 + strlen(arg) + 
		    2 + strlen(esc_val) + 1))) {
			free(esc_val);
			@throw [OFNoMemException
			    newWithObject: nil
				  andSize: len + 1 + strlen(arg) + 2 +
					   strlen(esc_val) + 1];
		}







|







162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
			 * escapeCString already throws an exception,
			 * no need to throw a second one here.
			 */
			free(xml);
			return NULL;
		}

		if (OF_UNLIKELY(!xf_resize_chars(&xml, &len, 1 + strlen(arg) +
		    2 + strlen(esc_val) + 1))) {
			free(esc_val);
			@throw [OFNoMemException
			    newWithObject: nil
				  andSize: len + 1 + strlen(arg) + 2 +
					   strlen(esc_val) + 1];
		}

Modified tests/OFList/OFList.m from [f9365c3c47] to [c9c2390a0d].

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
}
#define CHECK(cond)							\
	if (cond)							\
		SUCCESS							\
	else								\
		FAIL							\
	i++;
 
const char *strings[] = {
	"First String Object",
	"Second String Object",
	"Third String Object"
};

int
main()
{
	size_t	     i;
	OFList	     *list;
	OFListObject *iter;

	list = [OFList new];
 
	[list addNew: [OFString newFromCString: strings[0]]];
	[list addNew: [OFString newFromCString: strings[1]]];
	[list addNew: [OFString newFromCString: strings[2]]];
 
	for (iter = [list first], i = 0; iter != nil; iter = [iter next], i++)
		if (!strcmp([[iter data] cString], strings[i]))
			SUCCESS
		else
			FAIL

	CHECK(!strcmp([[[list first] data] cString], strings[0]))
	CHECK(!strcmp([[[list last] data] cString], strings[2]))

	puts("");
 
	[list freeIncludingData];

	return 0;
}







|














|



|










|




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
}
#define CHECK(cond)							\
	if (cond)							\
		SUCCESS							\
	else								\
		FAIL							\
	i++;

const char *strings[] = {
	"First String Object",
	"Second String Object",
	"Third String Object"
};

int
main()
{
	size_t	     i;
	OFList	     *list;
	OFListObject *iter;

	list = [OFList new];

	[list addNew: [OFString newFromCString: strings[0]]];
	[list addNew: [OFString newFromCString: strings[1]]];
	[list addNew: [OFString newFromCString: strings[2]]];

	for (iter = [list first], i = 0; iter != nil; iter = [iter next], i++)
		if (!strcmp([[iter data] cString], strings[i]))
			SUCCESS
		else
			FAIL

	CHECK(!strcmp([[[list first] data] cString], strings[0]))
	CHECK(!strcmp([[[list last] data] cString], strings[2]))

	puts("");

	[list freeIncludingData];

	return 0;
}

Modified tests/OFObject/OFObject.m from [63219e8b9b] to [080970b224].

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

	/* Try to free again */
	puts("Now trying to free them again...");
	CATCH_EXCEPTION([obj freeMem: p], OFMemNotPartOfObjException)
	CATCH_EXCEPTION([obj freeMem: q], OFMemNotPartOfObjException)
	CATCH_EXCEPTION([obj freeMem: r], OFMemNotPartOfObjException)
	puts("Got all 3!");
	
	puts("Trying to allocate more memory than possible...");
	CATCH_EXCEPTION(p = [obj getMemWithSize: SIZE_MAX], OFNoMemException)

	puts("Allocating 1 byte...");
	p = [obj getMemWithSize: 1];

	puts("Trying to resize that 1 byte to more than possible...");
	CATCH_EXCEPTION(p = [obj resizeMem: p
				    toSize: SIZE_MAX],
	    OFNoMemException)

	puts("Trying to resize NULL to 1024 bytes...");
	p = [obj resizeMem: NULL
		    toSize: 1024];
	[obj freeMem: p];

	puts("Trying to resize memory that is not part of object...");
	CATCH_EXCEPTION(p = [obj resizeMem: (void*)1
				    toSize: 1024],
	    OFMemNotPartOfObjException)
	
	/* TODO: Test if freeing object frees all memory */

	return 0;
}







|




















|




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

	/* Try to free again */
	puts("Now trying to free them again...");
	CATCH_EXCEPTION([obj freeMem: p], OFMemNotPartOfObjException)
	CATCH_EXCEPTION([obj freeMem: q], OFMemNotPartOfObjException)
	CATCH_EXCEPTION([obj freeMem: r], OFMemNotPartOfObjException)
	puts("Got all 3!");

	puts("Trying to allocate more memory than possible...");
	CATCH_EXCEPTION(p = [obj getMemWithSize: SIZE_MAX], OFNoMemException)

	puts("Allocating 1 byte...");
	p = [obj getMemWithSize: 1];

	puts("Trying to resize that 1 byte to more than possible...");
	CATCH_EXCEPTION(p = [obj resizeMem: p
				    toSize: SIZE_MAX],
	    OFNoMemException)

	puts("Trying to resize NULL to 1024 bytes...");
	p = [obj resizeMem: NULL
		    toSize: 1024];
	[obj freeMem: p];

	puts("Trying to resize memory that is not part of object...");
	CATCH_EXCEPTION(p = [obj resizeMem: (void*)1
				    toSize: 1024],
	    OFMemNotPartOfObjException)

	/* TODO: Test if freeing object frees all memory */

	return 0;
}

Modified tests/OFTCPSocket/OFTCPSocket.m from [2ff21729c6] to [f183df46e9].

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
		else {
			puts("Received INCORRECT string!");
			return 1;
		}

#ifdef HAVE_IPV6
		memset(buf, 0, 7);
		
		[accepted free];
		[client close];
		[server close];

		puts("== IPv6 ==");
		port = get_port();








|







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
		else {
			puts("Received INCORRECT string!");
			return 1;
		}

#ifdef HAVE_IPV6
		memset(buf, 0, 7);

		[accepted free];
		[client close];
		[server close];

		puts("== IPv6 ==");
		port = get_port();