ObjFW
Loading...
Searching...
No Matches
OFBlock.h
1/*
2 * Copyright (c) 2008-2024 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#import "OFObject.h"
17
18OF_ASSUME_NONNULL_BEGIN
19
25@interface OFBlock: OFObject
26+ (instancetype)alloc OF_UNAVAILABLE;
27- (instancetype)init OF_UNAVAILABLE;
28@end
29
30OF_SUBCLASSING_RESTRICTED
31@interface OFStackBlock: OFBlock
32@end
33
34OF_SUBCLASSING_RESTRICTED
35@interface OFGlobalBlock: OFBlock
36@end
37
38OF_SUBCLASSING_RESTRICTED
39@interface OFMallocBlock: OFBlock
40@end
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45extern void *_Nullable _Block_copy(const void *_Nullable);
46extern void _Block_release(const void *_Nullable);
47
48# if defined(OF_WINDOWS) && \
49 (defined(OF_NO_SHARED) || defined(OF_COMPILING_OBJFW))
50/*
51 * Clang has implicit declarations for these, but they are dllimport. When
52 * compiling ObjFW itself or using it as a static library, these need to be
53 * dllexport. Interestingly, this still works when using it as a shared library.
54 */
55extern __declspec(dllexport) struct objc_class _NSConcreteStackBlock;
56extern __declspec(dllexport) struct objc_class _NSConcreteGlobalBlock;
57extern __declspec(dllexport) void _Block_object_assign(void *, const void *,
58 const int);
59extern __declspec(dllexport) void _Block_object_dispose(const void *,
60 const int);
61# endif
62#ifdef __cplusplus
63}
64#endif
65
66#ifndef Block_copy
67# define Block_copy(...) \
68 ((__typeof__(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__)))
69#endif
70#ifndef Block_release
71# define Block_release(...) _Block_release((const void *)(__VA_ARGS__))
72#endif
73
74OF_ASSUME_NONNULL_END
The class for all blocks, since all blocks are also objects.
Definition OFBlock.h:26
The root class for all other classes inside ObjFW.
Definition OFObject.h:688
instancetype init()
Initializes an already allocated object.
Definition OFObject.m:586
instancetype alloc()
Allocates memory for an instance of the class and sets up the memory pool for the object.
Definition OFObject.m:438
A pointer to a class.
Definition private.h:33