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