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