ObjFW  Check-in [5ca127891c]

Overview
Comment:Get rid of + new.
Additionally, make - accept return an autoreleased OFTCPSocket.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5ca127891ca12cb8498ba6a9c6c5f4351c3a02f271ae531fb88e5669d7d60a09
User & Date: js on 2009-05-03 21:33:49
Other Links: manifest | tags
Context
2009-05-04
12:57
Add Thread Local Storage support to OFThread. check-in: 4d1d644283 user: js tags: trunk
2009-05-03
21:33
Get rid of + new.
Additionally, make - accept return an autoreleased OFTCPSocket.
check-in: 5ca127891c user: js tags: trunk
17:19
Make OFStream a class instead of a protocol and move readLine there. check-in: 7bf4b144ad user: js tags: trunk
Changes

Modified src/OFDictionary.m from [e7cc2d1d1a] to [9fb096432b].

104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118







-
+








	if (key == nil || obj == nil)
		@throw [OFInvalidArgumentException newWithClass: isa];

	hash = [key hash] & (size - 1);

	if (data[hash] == nil)
		data[hash] = [OFList new];
		data[hash] = [[OFList alloc] init];

	for (iter = [data[hash] first]; iter != NULL; iter = iter->next->next) {
		if ([iter->object isEqual: key]) {
			[iter->next->object release];
			[obj retain];
			iter->next->object = obj;

Modified src/OFObject.h from [8b1380da52] to [1bd5addeee].

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
39
40
41
42
43
44
45





46
47
48
49
50
51
52







-
-
-
-
-







 * alloc will never return nil, instead, it will throw an 
 * OFAllocFailedException.
 *
 * \return The allocated object.
 */
+ alloc;

/**
 * Allocated memory for an instance of the class and initializes the instance.
 */
+ new;

/**
 * \return The class pointer
 */
+ (Class)class;

/**
 * \return The name of the class as a C string

Modified src/OFObject.m from [ed4919e346] to [0826af6e82].

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
67
68
69
70
71
72
73





74
75
76
77
78
79
80







-
-
-
-
-







	instance = (OFObject*)((char*)instance + PRE_IVAR_ALIGN);
	memset(instance, 0, isize);
	instance->isa = self;

	return instance;
}

+ new
{
	return [[self alloc] init];
}

+ (Class)class
{
	return self;
}

+ (const char*)name
{

Modified src/OFTCPSocket.h from [91d2dde531] to [5f9ebf21be].

89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104
89
90
91
92
93
94
95

96

97
98
99
100
101
102
103







-
+
-







/**
 * Listen on the socket.
 */
- listen;

/**
 * Accept an incoming connection.
 * \return An OFTCPSocket for the accepted connection, which is NOT
 * \return An autoreleased OFTCPSocket for the accepted connection.
 *	   autoreleased!
 */
- (OFTCPSocket*)accept;

/**
 * Enables/disables non-blocking I/O.
 */
- setBlocking: (BOOL)enable;

Modified src/OFTCPSocket.m from [645f0b0d2c] to [cec4aee89e].

180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194







-
+







- (OFTCPSocket*)accept
{
	OFTCPSocket *newsock;
	struct sockaddr *addr;
	socklen_t addrlen;
	int s;

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

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

Modified tests/OFArray/OFArray.m from [45d0c67eff] to [5f4c7ca67b].

123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137







-
+








	puts("== TESTING OFArray ==");
	TEST(OFArray)

	puts("== TESTING OFBigArray ==");
	TEST(OFBigArray)

	pool = [OFAutoreleasePool new];
	pool = [[OFAutoreleasePool alloc] init];
	x = [OFArray arrayWithItemSize: 1];
	y = [OFArray bigArrayWithItemSize: 1];

	if (![x isEqual: y]) {
		puts("FAIL 1!");
		return 1;
	}

Modified tests/OFAutoreleasePool/OFAutoreleasePool.m from [7a5cd85d7e] to [d3298de97f].

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







-
+

-
-
+
+


-
+

-
-
+
+








		      withMethodFromClass: [TestObject class]];
	release = [OFObject replaceMethod: @selector(release)
		      withMethodFromClass: [TestObject class]];

	OFObject *o1, *o2, *o3;
	OFAutoreleasePool *pool1, *pool2;

	o1 = [[OFObject new] autorelease];
	o1 = [[[OFObject alloc] init] autorelease];

	pool1 = [OFAutoreleasePool new];
	o2 = [[OFObject new] autorelease];
	pool1 = [[OFAutoreleasePool alloc] init];
	o2 = [[[OFObject alloc] init] autorelease];
	[pool1 releaseObjects];

	o2 = [[OFObject new] autorelease];
	o2 = [[[OFObject alloc] init] autorelease];

	pool2 = [OFAutoreleasePool new];
	o3 = [[OFObject new] autorelease];
	pool2 = [[OFAutoreleasePool alloc] init];
	o3 = [[[OFObject alloc] init] autorelease];

	[pool1 retain];
	[pool1 release];
	[pool1 release];
	[o3 free];

	return (inits == 12 && retains == 1 && releases == 6 ? 0 : 1);
}

Modified tests/OFDictionary/OFDictionary.m from [672670fbeb] to [51f348148f].

25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39







-
+







main()
{
	BOOL caught;

	OFDictionary *dict = [OFDictionary dictionaryWithHashSize: 16];
	OFIterator *iter = [dict iterator];

	OFAutoreleasePool *pool = [OFAutoreleasePool new];
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFString *key1 = [OFString stringWithCString: "key1"];
	OFString *key2 = [OFString stringWithCString: "key2"];
	OFString *value1 = [OFString stringWithCString: "value1"];
	OFString *value2 = [OFString stringWithCString: "value2"];

	[dict set: key1
	       to: value1];

Modified tests/OFObject/OFObject.m from [a82f199588] to [020015e81a].

29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43







-
+







		puts([e cString]);			\
		puts("Resuming...");			\
	}

int
main()
{
	OFObject *obj = [OFObject new];
	OFObject *obj = [[OFObject alloc] init];
	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)

Modified tests/OFPlugin/TestPlugin/TestPlugin.m from [616318c30f] to [d0407bc1f1].

17
18
19
20
21
22
23
24

25
17
18
19
20
21
22
23

24
25







-
+

	return num * 2;
}
@end

id
init_plugin()
{
	return [TestPlugin new];
	return [[TestPlugin alloc] init];
}

Modified tests/OFString/OFString.m from [50c9f80545] to [a863061368].

50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73







-
+








-
+







	i++;

int
main()
{
	size_t i = 0;

	OFAutoreleasePool *pool = [OFAutoreleasePool new];
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFString *s1 = [OFString stringWithCString: "test"];
	OFString *s2 = [OFString stringWithCString: ""];
	OFString *s3;
	OFString *s4 = [OFString string];

	s3 = [s1 copy];

	CHECK([s1 isEqual: s3])
	CHECK(![s1 isEqual: [OFObject new]])
	CHECK(![s1 isEqual: [[OFObject alloc] init]])
	CHECK([s1 hash] == [s3 hash])

	[s2 appendCString: "123"];
	[s4 setTo: [s2 cString]];

	CHECK(![s2 compare: s4])
	CHECK(!strcmp([[s1 append: s2] cString], "test123"))