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 program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#import "OFObject.h"
21
22OF_ASSUME_NONNULL_BEGIN
23
29@interface OFBlock: OFObject
30+ (instancetype)alloc OF_UNAVAILABLE;
31- (instancetype)init OF_UNAVAILABLE;
32@end
33
34OF_SUBCLASSING_RESTRICTED
35@interface OFStackBlock: OFBlock
36@end
37
38OF_SUBCLASSING_RESTRICTED
39@interface OFGlobalBlock: OFBlock
40@end
41
42OF_SUBCLASSING_RESTRICTED
43@interface OFMallocBlock: OFBlock
44@end
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49extern void *_Nullable _Block_copy(const void *_Nullable);
50extern void _Block_release(const void *_Nullable);
51
52# if defined(OF_WINDOWS) && \
53 (defined(OF_NO_SHARED) || defined(OF_COMPILING_OBJFW))
54/*
55 * Clang has implicit declarations for these, but they are dllimport. When
56 * compiling ObjFW itself or using it as a static library, these need to be
57 * dllexport. Interestingly, this still works when using it as a shared library.
58 */
59extern __declspec(dllexport) struct objc_class _NSConcreteStackBlock;
60extern __declspec(dllexport) struct objc_class _NSConcreteGlobalBlock;
61extern __declspec(dllexport) void _Block_object_assign(void *, const void *,
62 const int);
63extern __declspec(dllexport) void _Block_object_dispose(const void *,
64 const int);
65# endif
66#ifdef __cplusplus
67}
68#endif
69
70#ifndef Block_copy
71# define Block_copy(...) \
72 ((__typeof__(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__)))
73#endif
74#ifndef Block_release
75# define Block_release(...) _Block_release((const void *)(__VA_ARGS__))
76#endif
77
78OF_ASSUME_NONNULL_END
The class for all blocks, since all blocks are also objects.
Definition OFBlock.h:30
The root class for all other classes inside ObjFW.
Definition OFObject.h:692
instancetype init()
Initializes an already allocated object.
Definition OFObject.m:652
instancetype alloc()
Allocates memory for an instance of the class and sets up the memory pool for the object.
Definition OFObject.m:504
A pointer to a class.
Definition private.h:37