ObjFW
block.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3  * Jonathan Schleifer <js@webkeks.org>
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 #ifdef __cplusplus
45 }
46 #endif
47 
48 #ifndef Block_copy
49 # define Block_copy(...) \
50  ((__typeof__(__VA_ARGS__))_Block_copy((const void*)(__VA_ARGS__)))
51 #endif
52 #ifndef Block_release
53 # define Block_release(...) _Block_release((const void*)(__VA_ARGS__))
54 #endif
55 
56 OF_ASSUME_NONNULL_END