File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ @interface NoAlloc : Test @end
21
21
@interface NoInit : Test @end
22
22
@interface NoInit2 : NoInit @end
23
23
24
+ @interface ShouldInitSubclassed : NoInit @end
25
+
24
26
@implementation ShouldAlloc
25
27
+ (instancetype )alloc
26
28
{
@@ -91,6 +93,13 @@ + (instancetype)alloc
91
93
}
92
94
@end
93
95
96
+ @implementation ShouldInitSubclassed
97
+ + (instancetype ) alloc
98
+ {
99
+ return [ShouldInit alloc ];
100
+ }
101
+ @end
102
+
94
103
Class getClassNamed (char *name)
95
104
{
96
105
return nil ;
@@ -114,6 +123,10 @@ int main(void)
114
123
[[ShouldInit2 alloc ] init ];
115
124
assert (called);
116
125
126
+ called = NO ;
127
+ [[ShouldInitSubclassed alloc ] init ];
128
+ assert (called);
129
+
117
130
called = NO ;
118
131
[NoAlloc alloc ];
119
132
assert (!called);
Original file line number Diff line number Diff line change @@ -9,9 +9,6 @@ - (id)init;
9
9
@end
10
10
#include < stdio.h>
11
11
12
- /* *
13
- * Equivalent to [cls alloc]. If there's a fast path opt-in, then this skips the message send.
14
- */
15
12
OBJC_PUBLIC
16
13
id
17
14
objc_alloc (Class cls)
@@ -66,6 +63,9 @@ - (id)init;
66
63
return nil ;
67
64
}
68
65
id instance = objc_alloc (cls);
66
+ // If +alloc was overwritten, it is not guaranteed that it returns
67
+ // an instance of cls.
68
+ cls = classForObject (instance);
69
69
if (objc_test_class_flag (cls, objc_class_flag_fast_alloc_init))
70
70
{
71
71
return instance;
You can’t perform that action at this time.
0 commit comments