]> git.saurik.com Git - apple/objc4.git/blob - test/zone.m
objc4-437.tar.gz
[apple/objc4.git] / test / zone.m
1 #include "test.h"
2 #include <mach/mach.h>
3 #include <malloc/malloc.h>
4
5 // Look for malloc zone "ObjC" iff OBJC_USE_INTERNAL_ZONE is set.
6 // This fails if objc tries to allocate before checking its own
7 // environment variables (rdar://6688423)
8
9 int main()
10 {
11 kern_return_t kr;
12 vm_address_t *zones;
13 unsigned int count, i;
14 BOOL has_objc = NO, want_objc = NO;
15
16 want_objc = (getenv("OBJC_USE_INTERNAL_ZONE") != NULL) ? YES : NO;
17 testprintf("want objc %s\n", want_objc ? "YES" : "NO");
18
19 kr = malloc_get_all_zones(mach_task_self(), NULL, &zones, &count);
20 testassert(!kr);
21 for (i = 0; i < count; i++) {
22 const char *name = malloc_get_zone_name((malloc_zone_t *)zones[i]);
23 if (name) {
24 BOOL is_objc = (0 == strcmp(name, "ObjC")) ? YES : NO;
25 if (is_objc) has_objc = YES;
26 testprintf("zone %s\n", name);
27 }
28 }
29
30 testassert(want_objc == has_objc);
31
32 succeed(__FILE__);
33 }