ObjFW
block.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "macros.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
21 typedef struct of_block_literal_t {
22 #ifdef __OBJC__
23  Class isa;
24 #else
25  void *isa;
26 #endif
27  int flags;
28  int reserved;
29  void (*invoke)(void *block, ...);
30  struct of_block_descriptor_t {
31  unsigned long reserved;
32  unsigned long size;
33  void (*copy_helper)(void *dest, void *src);
34  void (*dispose_helper)(void *src);
35  const char *signature;
36  } *descriptor;
37 } of_block_literal_t;
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 extern void *_Block_copy(const void *);
43 extern void _Block_release(const void *);
44 
45 # ifdef OF_WINDOWS
46 /*
47  * Clang has implicit declarations for these, but they are dllimport. When
48  * compiling ObjFW itself or using it as a static library, these need to be
49  * dllexport. Interestingly, this still works when using it as a shared library.
50  */
51 extern __declspec(dllexport) struct objc_abi_class _NSConcreteStackBlock;
52 extern __declspec(dllexport) struct objc_abi_class _NSConcreteGlobalBlock;
53 extern __declspec(dllexport) void _Block_object_assign(void *, const void *,
54  const int);
55 extern __declspec(dllexport) void _Block_object_dispose(const void *,
56  const int);
57 # endif
58 #ifdef __cplusplus
59 }
60 #endif
61 
62 #ifndef Block_copy
63 # define Block_copy(...) \
64  ((__typeof__(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__)))
65 #endif
66 #ifndef Block_release
67 # define Block_release(...) _Block_release((const void *)(__VA_ARGS__))
68 #endif
69 
70 OF_ASSUME_NONNULL_END