ObjFW  Check-in [778be56179]

Overview
Comment:Coding style.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 778be56179b4a6716b7d248ed100fc63dd267eb2b6ebdc21d7bf028fcae23f59
User & Date: js on 2008-09-14 15:29:34
Other Links: manifest | tags
Context
2008-09-14
16:43
Lots of changes. See full commit message. check-in: 7b8b7cd06c user: js tags: trunk
15:29
Coding style. check-in: 778be56179 user: js tags: trunk
15:12
Fix a bug in OFWideString and add test for OFWideString. check-in: b4ead4bdd2 user: js tags: trunk
Changes

Modified src/OFConstString.h from [d944b1298b] to [f6b02d3f44].

10
11
12
13
14
15
16
17
18


19
20
21

22
23

24
25
26
27
28
10
11
12
13
14
15
16


17
18
19
20

21
22

23
24
25
26









-
-
+
+


-
+

-
+



-
-
 */

#import <stddef.h>
#import "OFObject.h"

@interface OFConstString: OFObject
{
	const char	*string;
	size_t		length;
	const char *string;
	size_t	   length;
}

+ new:(const char*)str;
+ new: (const char*)str;
- init;
- init:(const char*)str;
- init: (const char*)str;
- (const char*)cString;
- (size_t)length;
@end

/* vim: se syn=objc: */

Modified src/OFConstString.m from [8c3560516b] to [76ce673d4c].

9
10
11
12
13
14
15
16

17
18

19
20
21
22
23

24
25
26

27
28
29
30
31
32
33
9
10
11
12
13
14
15

16
17

18
19
20
21
22

23
24
25

26
27
28
29
30
31
32
33







-
+

-
+




-
+


-
+







 * the packaging of this file.
 */

#import <string.h>
#import "OFConstString.h"

@implementation OFConstString
+ new:(const char*)str
+ new: (const char*)str
{
	return [[OFConstString alloc] init:str];
	return [[OFConstString alloc] init: str];
}

- init
{
	return [self init:NULL];
	return [self init: NULL];
}

- init:(const char*)str
- init: (const char*)str
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			length = strlen(str);

Modified src/OFConstWideString.h from [30aab21810] to [d4d5fd756d].

11
12
13
14
15
16
17
18
19


20
21
22

23
24

25
26
27
28
29
11
12
13
14
15
16
17


18
19
20
21

22
23

24
25
26
27









-
-
+
+


-
+

-
+



-
-

#import <stddef.h>
#import <wchar.h>
#import "OFObject.h"

@interface OFConstWideString: OFObject
{
	const wchar_t	*wstring;
	size_t		length;
	const wchar_t *wstring;
	size_t	      length;
}

+ new:(const wchar_t*)wstr;
+ new: (const wchar_t*)wstr;
- init;
- init:(const wchar_t*)wstr;
- init: (const wchar_t*)wstr;
- (const wchar_t*)wcString;
- (size_t)length;
@end

/* vim: se syn=objc: */

Modified src/OFConstWideString.m from [1ca10a0426] to [a6b7bf4dc0].

9
10
11
12
13
14
15
16

17
18

19
20
21
22
23

24
25
26

27
28
29
30
31
32
33
9
10
11
12
13
14
15

16
17

18
19
20
21
22

23
24
25

26
27
28
29
30
31
32
33







-
+

-
+




-
+


-
+







 * the packaging of this file.
 */

#import <wchar.h>
#import "OFConstWideString.h"

@implementation OFConstWideString
+ new:(const wchar_t*)wstr
+ new: (const wchar_t*)wstr
{
	return [[OFConstWideString alloc] init:wstr];
	return [[OFConstWideString alloc] init: wstr];
}

- init
{
	return [self init:NULL];
	return [self init: NULL];
}

- init:(const wchar_t*)wstr
- init: (const wchar_t*)wstr
{
	if ((self = [super init])) {
		if (wstr == NULL) {
			length = 0;
			wstring = NULL;
		} else {
			length = wcslen(wstr);

Modified src/OFList.h from [93a96d7531] to [08759996d3].

10
11
12
13
14
15
16
17
18


19
20
21
22
23
24
25
26
27


28
29
30
10
11
12
13
14
15
16


17
18
19
20
21
22
23
24
25


26
27
28









-
-
+
+







-
-
+
+

-
-
 */

#import "OFObject.h"
#import "OFListObject.h"

@interface OFList: OFObject
{
	OFListObject	*first;
	OFListObject	*last;
	OFListObject *first;
	OFListObject *last;
}

- init;
- free;
- freeWithData;
- (OFListObject*)first;
- (OFListObject*)last;
- (void)add:(OFListObject*)ptr;
- (void)addNew:(void*)ptr;
- (void)add: (OFListObject*)ptr;
- (void)addNew: (void*)ptr;
@end

/* vim: se syn=objc: */

Modified src/OFList.m from [84092951f3] to [47da29ca93].

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
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







-
+






-
-
+
+




-
+

-
+


}

- (OFListObject*)last
{
	return last;
}

- (void)add:(OFListObject*)ptr
- (void)add: (OFListObject*)ptr
{
	if (!first || !last) {
		first = last = ptr;
		return;
	}

	[ptr setPrev:last];
	[last setNext:ptr];
	[ptr setPrev: last];
	[last setNext: ptr];

	last = ptr;
}

- (void)addNew:(void*)ptr
- (void)addNew: (void*)ptr
{
	return [self add:[OFListObject new:ptr]];
	return [self add: [OFListObject new: ptr]];
}
@end

Modified src/OFListObject.h from [13cfd35f7b] to [25e264f941].

9
10
11
12
13
14
15
16
17
18



19
20
21
22


23
24
25
26
27
28


29
30
31
9
10
11
12
13
14
15



16
17
18
19
20


21
22
23
24
25
26


27
28
29









-
-
-
+
+
+


-
-
+
+




-
-
+
+

-
-
 * the packaging of this file.
 */

#import "OFObject.h"

@interface OFListObject: OFObject
{
	void		*data;
	OFListObject	*next;
	OFListObject	*prev;
	void	     *data;
	OFListObject *next;
	OFListObject *prev;
}

+ new:(void*)ptr;
- init:(void*)ptr;
+ new: (void*)ptr;
- init: (void*)ptr;
- freeWithData;
- (void*)data;
- (OFListObject*)next;
- (OFListObject*)prev;
- (void)setNext:(OFListObject*)ptr;
- (void)setPrev:(OFListObject*)ptr;
- (void)setNext: (OFListObject*)ptr;
- (void)setPrev: (OFListObject*)ptr;
@end

/* vim: se syn=objc: */

Modified src/OFListObject.m from [0141a7e9b7] to [d372822c89].

9
10
11
12
13
14
15
16

17
18

19
20
21

22
23
24
25
26
27
28
9
10
11
12
13
14
15

16
17

18
19
20

21
22
23
24
25
26
27
28







-
+

-
+


-
+







 * the packaging of this file.
 */

#import <stdlib.h>
#import "OFListObject.h"

@implementation OFListObject
+ new:(void*)ptr
+ new: (void*)ptr
{
	return [[OFListObject alloc] init:ptr];
	return [[OFListObject alloc] init: ptr];
}

- init:(void*)ptr
- init: (void*)ptr
{
	if ((self = [super init])) {
		next = nil;
		prev = nil;
		data = ptr;
	}
	return self;
46
47
48
49
50
51
52
53

54
55
56
57
58

59
60
61
62
46
47
48
49
50
51
52

53
54
55
56
57

58
59
60
61
62







-
+




-
+




}

- (OFListObject*)prev
{
	return prev;
}

- (void)setNext:(OFListObject*)ptr
- (void)setNext: (OFListObject*)ptr
{
	next = ptr;
}

- (void)setPrev:(OFListObject*)ptr
- (void)setPrev: (OFListObject*)ptr
{
	prev = ptr;
}
@end

Modified src/OFObject.h from [3d2b1446a8] to [b47bfb1d54].

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28




29
30
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25



26
27
28
29
30
31







-
+










-
-
-
+
+
+
+


 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import <objc/Object.h>

struct __ofobject_allocated_mem {
	void *ptr;
	void				*ptr;
	struct __ofobject_allocated_mem *prev;
	struct __ofobject_allocated_mem *next;
};

@interface OFObject: Object
{
	struct __ofobject_allocated_mem *__mem_pool;
}

- init;
- (void*)getMem:(size_t)size;
- (void*)resizeMem:(void*)ptr toSize:(size_t)size;
- (void)freeMem:(void*)ptr;
- (void*)getMem: (size_t)size;
- (void*)resizeMem: (void*)ptr
	    toSize: (size_t)size;
- (void)freeMem: (void*)ptr;
- free;
@end

Modified src/OFObject.m from [3a6fe1669c] to [b460fe3dcf].

18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32







-
+







- init
{
	if ((self = [super init]) != nil)
		__mem_pool  = NULL;
	return self;
}

- (void*)getMem:(size_t)size
- (void*)getMem: (size_t)size
{
	struct __ofobject_allocated_mem *iter;

	if ((iter = malloc(sizeof(struct __ofobject_allocated_mem))) == NULL)
		return NULL;

	if ((iter->ptr = malloc(size)) == NULL) {
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
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







-
+
+














-
+




-
+


















-
+







		__mem_pool->next = iter;

	__mem_pool = iter;

	return iter->ptr;
}

- (void*)resizeMem:(void*)ptr toSize:(size_t)size
- (void*)resizeMem: (void*)ptr
	    toSize: (size_t)size
{
	struct __ofobject_allocated_mem *iter;

	for (iter = __mem_pool; iter != NULL; iter = iter->prev) {
		if (iter->ptr == ptr) {
			if ((ptr = realloc(iter->ptr, size)) == NULL)
				return NULL;
			
			iter->ptr = ptr;
			return ptr;
		}
	}

	fprintf(stderr, "WARNING: Memory at %p was not allocated as part of "
	    "object %s!\n", ptr, [self name]);
	    "object %s!\n-> Memory was not resized!\n", ptr, [self name]);

	return NULL;
}

- (void)freeMem:(void*)ptr;
- (void)freeMem: (void*)ptr;
{
	struct __ofobject_allocated_mem *iter;

	for (iter = __mem_pool; iter != NULL; iter = iter->prev) {
		if (iter->ptr == ptr) {
			if (iter->prev != NULL)
				iter->prev->next = iter->next;
			if (iter->next != NULL)
				iter->next->prev = iter->prev;

			free(iter);
			free(ptr);

			return;
		}
	}

	fprintf(stderr, "WARNING: Memory at %p was not allocated as part of "
	    "object %s!\n", ptr, [self name]);
	    "object %s!\n-> Memory was not free'd!\n", ptr, [self name]);
}

- free
{
	struct __ofobject_allocated_mem *iter, *iter2;

	for (iter = __mem_pool; iter != NULL; iter = iter2) {

Modified src/OFString.h from [9ae2f04448] to [362876c1c2].

10
11
12
13
14
15
16
17
18


19
20
21

22
23

24
25
26

27
28

29
30
31
10
11
12
13
14
15
16


17
18
19
20

21
22

23
24
25

26
27

28
29









-
-
+
+


-
+

-
+


-
+

-
+

-
-
 */

#import <stddef.h>
#import "OFObject.h"

@interface OFString: OFObject
{
	char	*string;
	size_t	length;
	char   *string;
	size_t length;
}

+ new:(const char*)str;
+ new: (const char*)str;
- init;
- init:(const char*)str;
- init: (const char*)str;
- (char*)cString;
- (size_t)length;
- (OFString*)setTo:(const char*)str;
- (OFString*)setTo: (const char*)str;
- (OFString*)clone;
- (OFString*)append:(const char*)str;
- (OFString*)append: (const char*)str;
@end

/* vim: se syn=objc: */

Modified src/OFString.m from [7b8481ed3a] to [52bd147dc6].

10
11
12
13
14
15
16
17

18
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

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
109
110
111
10
11
12
13
14
15
16

17
18

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
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
109
110
111







-
+

-
+




-
+


-
+







-
+

















-
+





-
+








-
+




-
+









-
+




-
-
+
+







-
-
+
+
+

-











 */

#import <stdlib.h>
#import <string.h>
#import "OFString.h"

@implementation OFString
+ new:(const char*)str
+ new: (const char*)str
{
	return [[OFString alloc] init:str];
	return [[OFString alloc] init: str];
}

- init
{
	return [self init:NULL];
	return [self init: NULL];
}

- init:(const char*)str
- init: (const char*)str
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			length = strlen(str);
			if ((string = [self getMem:length]) == NULL)
			if ((string = [self getMem: length]) == NULL)
				return NULL;
			memcpy(string, str, length);
		}
	}
	return self;
}

- (char*)cString
{
	return string;
}

- (size_t)length
{
	return length;
}

- (OFString*)setTo:(const char*)str
- (OFString*)setTo: (const char*)str
{
	char *newstr;
	size_t newlen;
	
	if (str == NULL) {
		[self freeMem:string];
		[self freeMem: string];

		length = 0;
		string = NULL;

		return self;
	}

	newlen = strlen(str);
	if ((newstr = [self getMem:newlen]) == NULL)
	if ((newstr = [self getMem: newlen]) == NULL)
		return nil;
	memcpy(newstr, str, newlen);

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

	length = newlen;
	string = newstr;

	return self;
}

- (OFString*)clone
{
	return [OFString new:string];
	return [OFString new: string];
}

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

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

	strlength = strlen(str);
	newlen = length + strlength;

	if ((newstr = [self resizeMem:string toSize:newlen + 1]) == NULL) {
		/* FIXME: Add error handling */
	/* FIXME: Add error handling */
	if ((newstr = [self resizeMem: string
			       toSize: newlen + 1]) == NULL)
		return nil;
	}

	string = newstr;

	memcpy(string + length, str, strlength);
	string[newlen] = '\0';

	length = newlen;

	return self;
}
@end

Modified src/OFWideString.h from [7d19c57893] to [1f0b56cce2].

15
16
17
18
19
20
21
22

23
24

25
26
27

28
29

30
31
32
15
16
17
18
19
20
21

22
23

24
25
26

27
28

29
30









-
+

-
+


-
+

-
+

-
-

@interface OFWideString: OFObject
{
	wchar_t	*wstring;
	size_t	length;
}

+ new:(const wchar_t*)wstr;
+ new: (const wchar_t*)wstr;
- init;
- init:(const wchar_t*)wstr;
- init: (const wchar_t*)wstr;
- (wchar_t*)wcString;
- (size_t)length;
- (OFWideString*)setTo:(const wchar_t*)wstr;
- (OFWideString*)setTo: (const wchar_t*)wstr;
- (OFWideString*)clone;
- (OFWideString*)append:(const wchar_t*)wstr;
- (OFWideString*)append: (const wchar_t*)wstr;
@end

/* vim: se syn=objc: */

Modified src/OFWideString.m from [f3e926533b] to [3d87632f9d].

11
12
13
14
15
16
17
18

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
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
109
110
111
112
113
114
115
11
12
13
14
15
16
17

18
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
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
109
110
111
112
113
114







-
+

-
+




-
+


-
+








-
+

















-
+














-
+




-
+









-
+








-
+




+
-
-
+
+
-

-













#import <stdlib.h>
#import <string.h>
#import <wchar.h>
#import "OFWideString.h"

@implementation OFWideString
+ new:(const wchar_t*)wstr
+ new: (const wchar_t*)wstr
{
	return [[OFWideString alloc] init:wstr];
	return [[OFWideString alloc] init: wstr];
}

- init
{
	return [self init:NULL];
	return [self init: NULL];
}

- init:(const wchar_t*)wstr
- init: (const wchar_t*)wstr
{
	if ((self = [super init])) {
		if (wstr == NULL) {
			length = 0;
			wstring = NULL;
		} else {
			length = wcslen(wstr);
			if ((wstring =
			    [self getMem:length * sizeof(wchar_t)]) == NULL)
			    [self getMem: length * sizeof(wchar_t)]) == NULL)
				return NULL;
			memcpy(wstring, wstr, length * sizeof(wchar_t));
		}
	}
	return self;
}

- (wchar_t*)wcString
{
	return wstring;
}

- (size_t)length
{
	return length;
}

- (OFWideString*)setTo:(const wchar_t*)wstr
- (OFWideString*)setTo: (const wchar_t*)wstr
{
	wchar_t *newstr;
	size_t  newlen;
	
	if (wstr == NULL) {
		[self freeMem:wstring];

		length = 0;
		wstring = NULL;

		return self;
	}

	newlen = wcslen(wstr);
	if ((newstr = [self getMem:newlen * sizeof(wchar_t)]) == NULL)
	if ((newstr = [self getMem: newlen * sizeof(wchar_t)]) == NULL)
		return nil;
	memcpy(newstr, wstr, newlen * sizeof(wchar_t));

	if (wstring != NULL)
		[self freeMem:wstring];
		[self freeMem: wstring];

	length = newlen;
	wstring = newstr;

	return self;
}

- (OFWideString*)clone
{
	return [OFWideString new:wstring];
	return [OFWideString new: wstring];
}

- (OFWideString*)append: (const wchar_t*)wstr
{
	wchar_t	*newstr;
	size_t	newlen, strlength;

	if (wstr == NULL)
		return [self setTo:wstr];
		return [self setTo: wstr];

	strlength = wcslen(wstr);
	newlen = length + strlength;

	/* FIXME: Add error handling */
	if ((newstr = [self resizeMem:wstring toSize:(newlen + 1) * 
				      sizeof(wchar_t)]) == NULL) {
	if ((newstr = [self resizeMem: wstring
			       toSize: newlen  * sizeof(wchar_t) + 2]) == NULL)
		/* FIXME: Add error handling */
		return nil;
	}

	wstring = newstr;

	memcpy(wstring + length * sizeof(wchar_t), wstr,
	    strlength * sizeof(wchar_t));
	wstring[newlen] = '\0';

	length = newlen;

	return self;
}
@end

Modified tests/OFList/OFList.m from [031f4c03f0] to [a32f1b4343].

13
14
15
16
17
18
19
20
21


22
23
24
25
26
27
28
13
14
15
16
17
18
19


20
21
22
23
24
25
26
27
28







-
-
+
+








#import "OFString.h"
#import "OFList.h"
 
int
main()
{
	OFList		*list;
	OFListObject	*iter;
	OFList	     *list;
	OFListObject *iter;

	list = [OFList new];
 
	[list addNew: [OFString new: "First String Object"]];
	[list addNew: [OFString new: "Second String Object"]];
	[list addNew: [OFString new: "Third String Object"]];
 

Modified tests/OFString/OFString.m from [6917f1112f] to [04cad32cc2].

13
14
15
16
17
18
19
20
21


22
23
24
25

26
27
28

29
30
31
32
33
34
35
13
14
15
16
17
18
19


20
21
22
23
24

25
26
27

28
29
30
31
32
33
34
35







-
-
+
+



-
+


-
+







#import <string.h>

#import "OFString.h"

int
main()
{
	OFString *s1 = [OFString new:"foo"];
	OFString *s2 = [[OFString alloc] init:""];
	OFString *s1 = [OFString new: "foo"];
	OFString *s2 = [[OFString alloc] init: ""];
	OFString *s3;
	OFString *s4 = [OFString new];

	[s2 append:"bar"];
	[s2 append: "bar"];
	s3 = [s1 clone];

	[s4 setTo:[s2 cString]];
	[s4 setTo: [s2 cString]];

	printf("s1 = %s\n", [s1 cString]);
	printf("s2 = %s\n", [s2 cString]);
	printf("s3 = %s\n", [s3 cString]);
	printf("s4 = %s\n", [s4 cString]);

	[s1 append: [s2 cString]];

Modified tests/OFWideString/OFWideString.m from [2a8f622845] to [8d262602dc].

13
14
15
16
17
18
19
20
21


22
23
24
25

26
27
28

29
30
31
32
33
34
35
13
14
15
16
17
18
19


20
21
22
23
24

25
26
27

28
29
30
31
32
33
34
35







-
-
+
+



-
+


-
+







#import <wchar.h>

#import "OFWideString.h"

int
main()
{
	OFWideString *s1 = [OFWideString new:L"foo"];
	OFWideString *s2 = [[OFWideString alloc] init:L""];
	OFWideString *s1 = [OFWideString new: L"foo"];
	OFWideString *s2 = [[OFWideString alloc] init: L""];
	OFWideString *s3;
	OFWideString *s4 = [OFWideString new];

	printf("%p\n", [s2 append:L"bar"]);
	printf("%p\n", [s2 append: L"bar"]);
	s3 = [s1 clone];

	[s4 setTo:[s2 wcString]];
	[s4 setTo: [s2 wcString]];

	wprintf(L"s1 = %S\n", [s1 wcString]);
	wprintf(L"s2 = %S\n", [s2 wcString]);
	wprintf(L"s3 = %S\n", [s3 wcString]);
	wprintf(L"s4 = %S\n", [s4 wcString]);

	[s1 append: [s2 wcString]];