-
Notifications
You must be signed in to change notification settings - Fork 31
/
MABlockClosure.h
50 lines (37 loc) · 943 Bytes
/
MABlockClosure.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#import <Foundation/Foundation.h>
#if (TARGET_OS_IPHONE && TARGET_OS_EMBEDDED) || TARGET_IPHONE_SIMULATOR
#define USE_CUSTOM_LIBFFI 1
#endif
#if USE_CUSTOM_LIBFFI
#import <ffi.h>
#define USE_LIBFFI_CLOSURE_ALLOC 1
#else // use system libffi
#import <ffi/ffi.h>
#endif
@interface MABlockClosure : NSObject
{
NSMutableArray *_allocations;
ffi_cif _closureCIF;
ffi_cif _innerCIF;
int _closureArgCount;
ffi_closure *_closure;
void *_closureFptr;
id _block;
}
- (id)initWithBlock: (id)block;
- (void *)fptr;
@end
#ifdef __cplusplus
extern "C" {
#endif /// __cplusplus
// convenience function, returns a function pointer
// whose lifetime is tied to 'block'
// block MUST BE a heap block (pre-copied)
// or a global block
void *BlockFptr(id block);
// copies/autoreleases the block, then returns
// function pointer associated to it
void *BlockFptrAuto(id block);
#ifdef __cplusplus
}
#endif /// __cplusplus