1 // 2 // The LLVM Compiler Infrastructure 3 // 4 // This file is distributed under the University of Illinois Open Source 5 // License. See LICENSE.TXT for details. 6 7 // CONFIG 8 9 10 #include <stdio.h> 11 #include <stdbool.h> 12 #include <stdlib.h> 13 #include <Block.h> 14 15 int 16 main(int argc, char *argv[]) 17 { 18 __block int var = 0; 19 void (^b)(void) = ^{ var++; }; 20 21 //sanity(b); 22 b(); 23 printf("%s: success!\n", argv[0]); 24 return 0; 25 } 26 27 28 #if 1 29 /* replicated internal data structures: BEWARE, MAY CHANGE!!! */ 30 31 enum { 32 BLOCK_REFCOUNT_MASK = (0xffff), 33 BLOCK_NEEDS_FREE = (1 << 24), 34 BLOCK_HAS_COPY_DISPOSE = (1 << 25), 35 BLOCK_NO_COPY = (1 << 26), // interim byref: no copies allowed 36 BLOCK_IS_GC = (1 << 27), 37 BLOCK_IS_GLOBAL = (1 << 28), 38 }; 39 40 struct byref_id { 41 struct byref_id *forwarding; 42 int flags;//refcount; 43 int size; 44 void (*byref_keep)(struct byref_id *dst, struct byref_id *src); 45 void (*byref_destroy)(struct byref_id *); 46 int var; 47 }; 48 struct Block_basic2 { 49 void *isa; 50 int Block_flags; // int32_t 51 int Block_size; // XXX should be packed into Block_flags 52 void (*Block_invoke)(void *); 53 void (*Block_copy)(void *dst, void *src); 54 void (*Block_dispose)(void *); 55 struct byref_id *ref; 56 }; 57 58 void sanity(void *arg) { 59 struct Block_basic2 *bb = (struct Block_basic2 *)arg; 60 if ( ! (bb->Block_flags & BLOCK_HAS_COPY_DISPOSE)) { 61 printf("missing copy/dispose helpers for byref data\n"); 62 exit(1); 63 } 64 struct byref_id *ref = bb->ref; 65 if (ref->forwarding != ref) { 66 printf("forwarding pointer should be %p but is %p\n", ref, ref->forwarding); 67 exit(1); 68 } 69 } 70 #endif 71 72 73 74