mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-14 17:01:22 +00:00
bfda4e776f
The common idiom for self init (below) causes a double-call when compiling with --advanced, resulting in an incorrect retain count. if (!(self = [super init])) { return nil; }
56 lines
849 B
R
56 lines
849 B
R
#pragma advanced
|
|
#include "test-harness.h"
|
|
|
|
int obj_increment_retaincount (id object) = #0;
|
|
int obj_get_retaincount (id object) = #0;
|
|
id (Class class) class_create_instance = #0;
|
|
id obj_msgSend_super (Super *class, SEL op, ...) = #0;
|
|
|
|
@interface Object
|
|
{
|
|
Class isa;
|
|
}
|
|
+(id) alloc;
|
|
-(id) init;
|
|
@end
|
|
|
|
@interface Foo : Object
|
|
-(id) init;
|
|
@end
|
|
|
|
@implementation Object
|
|
+(id) alloc
|
|
{
|
|
return class_create_instance (self);
|
|
}
|
|
-(id) init
|
|
{
|
|
obj_increment_retaincount (self);
|
|
return self;
|
|
}
|
|
@end
|
|
|
|
@implementation Foo
|
|
-(id) init
|
|
{
|
|
if (!(self = [super init])) {
|
|
return nil;
|
|
}
|
|
return self;
|
|
}
|
|
@end
|
|
|
|
int main ()
|
|
{
|
|
Foo *foo = [[Foo alloc] init];
|
|
if (!foo) {
|
|
printf ("foo is nil\n");
|
|
return 1;
|
|
}
|
|
int retain = obj_get_retaincount (foo);
|
|
if (retain != 1) {
|
|
printf ("retain count != 1: %d\n", retain);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|