ObjFW  Check-in [de929f3cde]

Overview
Comment:Make more use of exceptions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: de929f3cde4842ba637040c5cd239173f5d541cb96d48bd063323b59bf9926fa
User & Date: js on 2008-09-14 20:19:20
Other Links: manifest | tags
Context
2008-09-14
20:30
Same again. check-in: 1df0de873b user: js tags: trunk
20:19
Make more use of exceptions. check-in: de929f3cde user: js tags: trunk
19:54
More portable test running. check-in: 7700e033a9 user: js tags: trunk
Changes

Modified src/OFString.m from [fb3d19ec1b] to [bb64dfc30f].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			length = strlen(str);
			if ((string = [self getMem: length + 1]) == NULL)
				return NULL;
			memcpy(string, str, length + 1);
		}
	}
	return self;
}

- (char*)cString







|
<







29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			length = strlen(str);
			string = [self getMem: length + 1];

			memcpy(string, str, length + 1);
		}
	}
	return self;
}

- (char*)cString

Modified src/OFWideString.m from [a3637e3c40] to [5e1c99f438].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
	if ((self = [super init])) {
		if (wstr == NULL) {
			length = 0;
			wstring = NULL;
		} else {
			length = wcslen(wstr);
			if (NULL == (wstring =
			    [self getMem: (length + 1) * sizeof(wchar_t)]))
				return NULL;
			memcpy(wstring, wstr, (length + 1) * sizeof(wchar_t));
		}
	}
	return self;
}

- (wchar_t*)wcString







<
|
<







30
31
32
33
34
35
36

37

38
39
40
41
42
43
44
{
	if ((self = [super init])) {
		if (wstr == NULL) {
			length = 0;
			wstring = NULL;
		} else {
			length = wcslen(wstr);

			wstring = [self getMem: (length + 1) * sizeof(wchar_t)];

			memcpy(wstring, wstr, (length + 1) * sizeof(wchar_t));
		}
	}
	return self;
}

- (wchar_t*)wcString

Modified tests/OFObject/OFObject.m from [9d8c2f0a96] to [436ef088ef].

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
	OFObject *obj = [OFObject new];
	bool caught;
	void *p, *q, *r;

	/* Test freeing memory not allocated by obj */
	puts("Freeing memory not allocated by object (should throw an "
	    "exception)...");
	CATCH_EXCEPTION([obj freeMem: (void*)123], OFMemNotPartOfObjException)

	/* Test allocating memory */
	puts("Allocating memory through object...");
	p = [obj getMem: 4096];
	puts("Allocated 4096 bytes.");

	/* Test freeing the just allocated memory */







|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
	OFObject *obj = [OFObject new];
	bool caught;
	void *p, *q, *r;

	/* Test freeing memory not allocated by obj */
	puts("Freeing memory not allocated by object (should throw an "
	    "exception)...");
	CATCH_EXCEPTION([obj freeMem: NULL], OFMemNotPartOfObjException)

	/* Test allocating memory */
	puts("Allocating memory through object...");
	p = [obj getMem: 4096];
	puts("Allocated 4096 bytes.");

	/* Test freeing the just allocated memory */