-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMABlockClosure.h
More file actions
executable file
·53 lines (40 loc) · 1.11 KB
/
Copy pathMABlockClosure.h
File metadata and controls
executable file
·53 lines (40 loc) · 1.11 KB
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
51
52
53
#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;
NSString * _signature;
}
- (id)initWithBlock: (id)block;
- (id)initWithSignature: (NSString *)signature;
- (void *)fptr;
- (void)returnValue:(void *)returnValue callWithArguments:(NSArray *)arguments funtion:(void *)afunction;
@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