ObjFW  Check-in [6e4eb3c2ec]

Overview
Comment:Partly revert 13945ed73147 and add testcase.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6e4eb3c2ece8060c75a195cf84c262fc7dfed794fa22ea32292cd573f800c537
User & Date: js on 2009-04-20 01:42:49
Other Links: manifest | tags
Context
2009-04-20
01:55
Improve tests. check-in: 16f1025d5c user: js tags: trunk
01:42
Partly revert 13945ed73147 and add testcase. check-in: 6e4eb3c2ec user: js tags: trunk
01:16
Fix forgotten change of - release in OFAutoreleasePool. check-in: cc4fe36d83 user: js tags: trunk
Changes

Modified src/OFObject.m from [850b7969ab] to [18bfba4e77].

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
	if (oldimp == (IMP)0 || newimp == (IMP)0)
		@throw [OFInvalidArgumentException newWithClass: self
						    andSelector: _cmd];

	method->method_imp = newimp;
	return oldimp;
#else
	Method m;
	IMP imp;

	if ((m = class_getInstanceMethod(self, selector)) == NULL ||
	    (imp = method_getImplementation(m)) == NULL)
		@throw [OFInvalidArgumentException newWithClass: self
						    andSelector: _cmd];

	return method_setImplementation(m, imp);
#endif
}

- init
{
	return self;
}







|
|

|
<



|







107
108
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126
127
128
	if (oldimp == (IMP)0 || newimp == (IMP)0)
		@throw [OFInvalidArgumentException newWithClass: self
						    andSelector: _cmd];

	method->method_imp = newimp;
	return oldimp;
#else
	Method method = class_getInstanceMethod(self, selector);
	IMP imp = class_getMethodImplementation(class, selector);

	if (method == NULL || imp == NULL)

		@throw [OFInvalidArgumentException newWithClass: self
						    andSelector: _cmd];

	return method_setImplementation(method, imp);
#endif
}

- init
{
	return self;
}

Modified tests/OFAutoreleasePool/OFAutoreleasePool.m from [fb6e30ee9b] to [cbd70c4bb1].

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

#ifndef _WIN32
#define ZD "%zd"
#else
#define ZD "%u"
#endif





IMP init;
IMP retain;
IMP release;

@interface TestObject: OFObject
- init;
- retain;
- release;
@end

@implementation TestObject
- init
{
	id ret;


       
	ret = init(self, _cmd);
	printf("New %s with retain cnt " ZD "\n", [self name],
	    [ret retainCount]);

	return ret;
}

- retain
{
	id ret;



	ret = retain(self, _cmd);
	printf("Retaining %s to " ZD "\n", [self name], [ret retainCount]);

	return ret;
}

- release
{


	printf("Releasing %s to " ZD "\n", [self name], [self retainCount] - 1);

	return release(self, _cmd);
}
@end

int
main()
{


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








>
>
>
>














>
>











>
>









>
>









>
>







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

#ifndef _WIN32
#define ZD "%zd"
#else
#define ZD "%u"
#endif

int inits;
int retains;
int releases;

IMP init;
IMP retain;
IMP release;

@interface TestObject: OFObject
- init;
- retain;
- release;
@end

@implementation TestObject
- init
{
	id ret;

	inits++;
       
	ret = init(self, _cmd);
	printf("New %s with retain cnt " ZD "\n", [self name],
	    [ret retainCount]);

	return ret;
}

- retain
{
	id ret;

	retains++;

	ret = retain(self, _cmd);
	printf("Retaining %s to " ZD "\n", [self name], [ret retainCount]);

	return ret;
}

- release
{
	releases++;

	printf("Releasing %s to " ZD "\n", [self name], [self retainCount] - 1);

	return release(self, _cmd);
}
@end

int
main()
{
	inits = retains = releases = 0;

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

81
82
83
84
85
86
87


88
89
90
91
92
	[pool1 releaseObjects];

	o2 = [[OFObject new] autorelease];

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



	[pool1 release];
	[o3 free];

	return 0;
}







>
>



|

93
94
95
96
97
98
99
100
101
102
103
104
105
106
	[pool1 releaseObjects];

	o2 = [[OFObject new] autorelease];

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

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

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