1*7c3d14c8STreehugger Robot // 2*7c3d14c8STreehugger Robot // The LLVM Compiler Infrastructure 3*7c3d14c8STreehugger Robot // 4*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source 5*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details. 6*7c3d14c8STreehugger Robot 7*7c3d14c8STreehugger Robot // 8*7c3d14c8STreehugger Robot // byrefcopy.m 9*7c3d14c8STreehugger Robot // testObjects 10*7c3d14c8STreehugger Robot // 11*7c3d14c8STreehugger Robot // Created by Blaine Garst on 5/13/08. 12*7c3d14c8STreehugger Robot // 13*7c3d14c8STreehugger Robot 14*7c3d14c8STreehugger Robot #include <stdio.h> 15*7c3d14c8STreehugger Robot #include <Block.h> 16*7c3d14c8STreehugger Robot #include <Block_private.h> 17*7c3d14c8STreehugger Robot 18*7c3d14c8STreehugger Robot // CONFIG 19*7c3d14c8STreehugger Robot 20*7c3d14c8STreehugger Robot void callVoidVoid(void (^closure)(void)) { 21*7c3d14c8STreehugger Robot closure(); 22*7c3d14c8STreehugger Robot } 23*7c3d14c8STreehugger Robot main(int argc,char * argv[])24*7c3d14c8STreehugger Robotint main(int argc, char *argv[]) { 25*7c3d14c8STreehugger Robot int __block i = 10; 26*7c3d14c8STreehugger Robot 27*7c3d14c8STreehugger Robot void (^block)(void) = ^{ ++i; }; 28*7c3d14c8STreehugger Robot //printf("original (old style) is %s\n", _Block_dump_old(block)); 29*7c3d14c8STreehugger Robot //printf("original (new style) is %s\n", _Block_dump(block)); 30*7c3d14c8STreehugger Robot void (^blockcopy)(void) = Block_copy(block); 31*7c3d14c8STreehugger Robot //printf("copy is %s\n", _Block_dump(blockcopy)); 32*7c3d14c8STreehugger Robot // use a copy & see that it updates i 33*7c3d14c8STreehugger Robot callVoidVoid(block); 34*7c3d14c8STreehugger Robot 35*7c3d14c8STreehugger Robot if (i != 11) { 36*7c3d14c8STreehugger Robot printf("*** %s didn't update i\n", argv[0]); 37*7c3d14c8STreehugger Robot return 1; 38*7c3d14c8STreehugger Robot } 39*7c3d14c8STreehugger Robot printf("%s: success\n", argv[0]); 40*7c3d14c8STreehugger Robot return 0; 41*7c3d14c8STreehugger Robot } 42