1 // TEST_CONFIG MEM=mrc LANGUAGE=objective-c
4 [\S\s]*0 leaks for 0 total leaked bytes[\S\s]*
14 void noopIMP(id self __unused, SEL _cmd __unused) {}
16 id test(int n, int methodCount) {
18 asprintf(&name, "TestClass%d", n);
19 Class c = objc_allocateClassPair([TestRoot class], name, 0);
22 SEL *sels = malloc(methodCount * sizeof(*sels));
23 for(int i = 0; i < methodCount; i++) {
24 asprintf(&name, "selector%d", i);
25 sels[i] = sel_getUid(name);
29 for(int i = 0; i < methodCount; i++) {
30 class_addMethod(c, sels[i], (IMP)noopIMP, "v@:");
33 objc_registerClassPair(c);
35 id obj = [[c alloc] init];
36 for (int i = 0; i < methodCount; i++) {
37 ((void (*)(id, SEL))objc_msgSend)(obj, sels[i]);
46 id *objs = malloc(classCount * sizeof(*objs));
47 for (int i = 0; i < classCount; i++) {
48 objs[i] = test(i, 1 << i);
52 int result = asprintf(&pidstr, "%u", getpid());
55 extern char **environ;
56 char *argv[] = { "/usr/bin/leaks", pidstr, NULL };
58 result = posix_spawn(&pid, "/usr/bin/leaks", NULL, NULL, argv, environ);
60 perror("posix_spawn");
63 wait4(pid, NULL, 0, NULL);
65 // Clean up. Otherwise leaks can end up seeing this as a leak, oddly enough.
66 for (int i = 0; i < classCount; i++) {