/*
* Copyright (c) 2010 Apple Inc. All rights reserved.
*
* @APPLE_LLVM_LICENSE_HEADER@
*/
// TEST_CONFIG SDK=macosx GC=1
// TEST_CFLAGS -framework Foundation
#import <objc/objc-auto.h>
#import <Foundation/Foundation.h>
#import <Block.h>
#import "test.h"
int countem(NSHashTable *table) {
int result = 0;
for (id elem in table)
++result;
return result;
}
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSHashTable *weakSet = [NSHashTable hashTableWithWeakObjects];
void (^local)(void) = ^{ [weakSet count]; };
extern id _Block_copy_collectable(void *);
//[weakSet addObject:_Block_copy_collectable(local)];
[weakSet addObject:Block_copy(local)];
[weakSet addObject:Block_copy(local)];
[weakSet addObject:Block_copy(local)];
[weakSet addObject:Block_copy(local)];
[weakSet addObject:Block_copy(local)];
[weakSet addObject:Block_copy(local)];
//printf("gc block... we hope\n if (objc_collectingEnabled()) {
objc_collect(OBJC_EXHAUSTIVE_COLLECTION|OBJC_WAIT_UNTIL_DONE);
int count = countem(weakSet);
if (count != 6) {
fail("didn't recover }
}
[pool release];
succeed(__FILE__);
}