]>
git.saurik.com Git - cycript.git/blob - sig/ffi_type.cpp
1 #include "minimal/stdlib.h"
3 #include "sig/ffi_type.hpp"
4 #include "sig/types.hpp"
10 ffi_type
*(*sig_ffi_type
)(apr_pool_t
*, struct Type
*),
11 struct Signature
*signature
,
16 _assert(signature
->count
>= skip
);
17 for (size_t index
= skip
; index
!= signature
->count
; ++index
)
18 types
[index
- skip
+ offset
] = (*sig_ffi_type
)(pool
, signature
->elements
[index
].type
);
21 ffi_type
*ObjectiveC(apr_pool_t
*pool
, struct Type
*type
) {
22 switch (type
->primitive
) {
23 case typename_P
: return &ffi_type_pointer
;
26 /* XXX: we can totally make this work */
30 case string_P
: return &ffi_type_pointer
;
31 case selector_P
: return &ffi_type_pointer
;
32 case object_P
: return &ffi_type_pointer
;
33 case boolean_P
: return &ffi_type_uchar
;
34 case uchar_P
: return &ffi_type_uchar
;
35 case uint_P
: return &ffi_type_uint
;
36 case ulong_P
: return &ffi_type_ulong
;
37 case ulonglong_P
: return &ffi_type_ulong
;
38 case ushort_P
: return &ffi_type_ushort
;
45 case pointer_P
: return &ffi_type_pointer
;
48 /* XXX: we can totally make this work */
52 case char_P
: return &ffi_type_schar
;
53 case double_P
: return &ffi_type_double
;
54 case float_P
: return &ffi_type_float
;
55 case int_P
: return &ffi_type_sint
;
56 case long_P
: return &ffi_type_sint
;
57 case longlong_P
: return &ffi_type_slong
;
58 case short_P
: return &ffi_type_sshort
;
60 case void_P
: return &ffi_type_void
;
63 ffi_type
*aggregate
= reinterpret_cast<ffi_type
*>(apr_palloc(pool
, sizeof(ffi_type
)));
65 aggregate
->alignment
= 0;
66 aggregate
->type
= FFI_TYPE_STRUCT
;
68 aggregate
->elements
= reinterpret_cast<ffi_type
**>(apr_palloc(pool
, (type
->data
.signature
.count
+ 1) * sizeof(ffi_type
*)));
69 sig_ffi_types(pool
, &ObjectiveC
, &type
->data
.signature
, aggregate
->elements
);
70 aggregate
->elements
[type
->data
.signature
.count
] = NULL
;
81 ffi_type
*Java(apr_pool_t
*pool
, struct Type
*type
) {
82 switch (type
->primitive
) {
83 case typename_P
: return &ffi_type_pointer
;
84 case union_P
: return &ffi_type_pointer
;
85 case string_P
: return &ffi_type_pointer
;
86 case selector_P
: return &ffi_type_pointer
;
87 case object_P
: return &ffi_type_pointer
;
88 case boolean_P
: return &ffi_type_uchar
;
89 case uchar_P
: return &ffi_type_uchar
;
90 case uint_P
: return &ffi_type_uint
;
91 case ulong_P
: return &ffi_type_ulong
;
92 case ulonglong_P
: return &ffi_type_ulong
;
93 case ushort_P
: return &ffi_type_ushort
;
94 case array_P
: return &ffi_type_pointer
;
95 case pointer_P
: return &ffi_type_pointer
;
98 case bit_P
: return &ffi_type_uint
;
100 case char_P
: return &ffi_type_schar
;
101 case double_P
: return &ffi_type_double
;
102 case float_P
: return &ffi_type_double
;
103 case int_P
: return &ffi_type_sint
;
104 case long_P
: return &ffi_type_sint
;
105 case longlong_P
: return &ffi_type_slong
;
106 case short_P
: return &ffi_type_sshort
;
107 case void_P
: return &ffi_type_void
;
108 case struct_P
: return &ffi_type_pointer
;
118 ffi_type
*(*sig_ffi_type
)(apr_pool_t
*, struct Type
*),
119 struct Signature
*signature
,
126 types
= reinterpret_cast<ffi_type
**>(apr_palloc(pool
, (signature
->count
- 1) * sizeof(ffi_type
*)));
127 ffi_type
*type
= (*sig_ffi_type
)(pool
, signature
->elements
[0].type
);
128 sig_ffi_types(pool
, sig_ffi_type
, signature
, types
, 1 + skip
, offset
);
129 ffi_status status
= ffi_prep_cif(cif
, FFI_DEFAULT_ABI
, signature
->count
- 1 - skip
+ offset
, type
, types
);
130 _assert(status
== FFI_OK
);