| 1 | // |
| 2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 | // See https://llvm.org/LICENSE.txt for license information. |
| 4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | |
| 6 | /* |
| 7 | * byrefcopyint.c |
| 8 | * testObjects |
| 9 | * |
| 10 | * Created by Blaine Garst on 12/1/08. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | // |
| 15 | // byrefcopyid.m |
| 16 | // testObjects |
| 17 | // |
| 18 | // Created by Blaine Garst on 5/13/08. |
| 19 | // |
| 20 | |
| 21 | // Tests copying of blocks with byref ints |
| 22 | // CONFIG rdar://6414583 -C99 |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <string.h> |
| 26 | #include <Block.h> |
| 27 | #include <Block_private.h> |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | typedef void (^voidVoid)(void); |
| 33 | |
| 34 | voidVoid dummy; |
| 35 | |
| 36 | void callVoidVoid(voidVoid closure) { |
| 37 | closure(); |
| 38 | } |
| 39 | |
| 40 | |
| 41 | voidVoid testRoutine(const char *whoami) { |
| 42 | __block int dumbo = strlen(whoami); |
| 43 | dummy = ^{ |
| 44 | //printf("incring dumbo from %d\n", dumbo); |
| 45 | ++dumbo; |
| 46 | }; |
| 47 | |
| 48 | |
| 49 | voidVoid copy = Block_copy(dummy); |
| 50 | |
| 51 | |
| 52 | return copy; |
| 53 | } |
| 54 | |
| 55 | int main(int argc, char *argv[]) { |
| 56 | voidVoid array[100]; |
| 57 | for (int i = 0; i < 100; ++i) { |
| 58 | array[i] = testRoutine(whoami: argv[0]); |
| 59 | array[i](); |
| 60 | } |
| 61 | for (int i = 0; i < 100; ++i) { |
| 62 | Block_release(array[i]); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | printf(format: "%s: success\n" , argv[0]); |
| 67 | return 0; |
| 68 | } |
| 69 | |