-
Notifications
You must be signed in to change notification settings - Fork 517
/
Copy pathclasspairAddMethod.m
36 lines (29 loc) · 1.02 KB
/
classpairAddMethod.m
1
2
3
4
5
6
7
8
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
34
35
36
// TEST_CONFIG
#include "test.h"
#include "testroot.i"
#include <objc/runtime.h>
void fakeIMP() {}
IMP testIMP = (IMP)fakeIMP;
int main()
{
// Make sure that method_getDescription doesn't return a stale cached
// description when creating and destroying dynamic subclasses
// (rdar://91521212). This is a UaF so it's not completely reliable, but
// empirically it happens reliably after five iterations. Run 100 just to be
// safe.
for (int i = 0; i < 100; i++) {
char *name;
asprintf(&name, "test-%d", i);
SEL sel = sel_getUid(name);
Class c = objc_allocateClassPair([TestRoot class], name, 0);
class_addMethod(c, sel, testIMP, name);
objc_registerClassPair(c);
Method m = class_getInstanceMethod(c, sel);
struct objc_method_description *desc = method_getDescription(m);
testassert(strcmp(desc->types, name) == 0);
testassertequal(desc->name, sel);
free(name);
objc_disposeClassPair(c);
}
succeed(__FILE__);
}