]> git.saurik.com Git - apple/objc4.git/blobdiff - test/zone.m
objc4-437.tar.gz
[apple/objc4.git] / test / zone.m
diff --git a/test/zone.m b/test/zone.m
new file mode 100644 (file)
index 0000000..9023308
--- /dev/null
@@ -0,0 +1,33 @@
+#include "test.h"
+#include <mach/mach.h>
+#include <malloc/malloc.h>
+
+// Look for malloc zone "ObjC" iff OBJC_USE_INTERNAL_ZONE is set.
+// This fails if objc tries to allocate before checking its own 
+// environment variables (rdar://6688423)
+
+int main()
+{
+    kern_return_t kr;
+    vm_address_t *zones;
+    unsigned int count, i;
+    BOOL has_objc = NO, want_objc = NO;
+
+    want_objc = (getenv("OBJC_USE_INTERNAL_ZONE") != NULL) ? YES : NO;
+    testprintf("want objc %s\n", want_objc ? "YES" : "NO");
+
+    kr = malloc_get_all_zones(mach_task_self(), NULL, &zones, &count);
+    testassert(!kr);
+    for (i = 0; i < count; i++) {
+        const char *name = malloc_get_zone_name((malloc_zone_t *)zones[i]);
+        if (name) {
+            BOOL is_objc = (0 == strcmp(name, "ObjC")) ? YES : NO;
+            if (is_objc) has_objc = YES;
+            testprintf("zone %s\n", name);
+        }
+    }
+
+    testassert(want_objc == has_objc);
+
+    succeed(__FILE__);
+}