]>
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"
6 #define ffi_type_slonglong ffi_type_sint64
7 #define ffi_type_ulonglong ffi_type_uint64
13 ffi_type
*(*sig_ffi_type
)(apr_pool_t
*, struct Type
*),
14 struct Signature
*signature
,
19 _assert(signature
->count
>= skip
);
20 for (size_t index
= skip
; index
!= signature
->count
; ++index
)
21 types
[index
- skip
+ offset
] = (*sig_ffi_type
)(pool
, signature
->elements
[index
].type
);
24 ffi_type
*ObjectiveC(apr_pool_t
*pool
, struct Type
*type
) {
25 switch (type
->primitive
) {
26 case typename_P
: return &ffi_type_pointer
;
29 /* XXX: we can totally make this work */
33 case string_P
: return &ffi_type_pointer
;
34 case selector_P
: return &ffi_type_pointer
;
35 case object_P
: return &ffi_type_pointer
;
36 case boolean_P
: return &ffi_type_uchar
;
37 case uchar_P
: return &ffi_type_uchar
;
38 case uint_P
: return &ffi_type_uint
;
39 case ulong_P
: return &ffi_type_ulong
;
40 case ulonglong_P
: return &ffi_type_ulonglong
;
41 case ushort_P
: return &ffi_type_ushort
;
48 case pointer_P
: return &ffi_type_pointer
;
51 /* XXX: we can totally make this work */
55 case char_P
: return &ffi_type_schar
;
56 case double_P
: return &ffi_type_double
;
57 case float_P
: return &ffi_type_float
;
58 case int_P
: return &ffi_type_sint
;
59 case long_P
: return &ffi_type_slong
;
60 case longlong_P
: return &ffi_type_slonglong
;
61 case short_P
: return &ffi_type_sshort
;
63 case void_P
: return &ffi_type_void
;
66 ffi_type
*aggregate
= reinterpret_cast<ffi_type
*>(apr_palloc(pool
, sizeof(ffi_type
)));
68 aggregate
->alignment
= 0;
69 aggregate
->type
= FFI_TYPE_STRUCT
;
71 aggregate
->elements
= reinterpret_cast<ffi_type
**>(apr_palloc(pool
, (type
->data
.signature
.count
+ 1) * sizeof(ffi_type
*)));
72 sig_ffi_types(pool
, &ObjectiveC
, &type
->data
.signature
, aggregate
->elements
);
73 aggregate
->elements
[type
->data
.signature
.count
] = NULL
;
84 ffi_type
*Java(apr_pool_t
*pool
, struct Type
*type
) {
85 switch (type
->primitive
) {
86 case typename_P
: return &ffi_type_pointer
;
87 case union_P
: return &ffi_type_pointer
;
88 case string_P
: return &ffi_type_pointer
;
89 case selector_P
: return &ffi_type_pointer
;
90 case object_P
: return &ffi_type_pointer
;
91 case boolean_P
: return &ffi_type_uchar
;
92 case uchar_P
: return &ffi_type_uchar
;
93 case uint_P
: return &ffi_type_uint
;
94 case ulong_P
: return &ffi_type_ulong
;
95 case ulonglong_P
: return &ffi_type_ulonglong
;
96 case ushort_P
: return &ffi_type_ushort
;
97 case array_P
: return &ffi_type_pointer
;
98 case pointer_P
: return &ffi_type_pointer
;
101 case bit_P
: return &ffi_type_uint
;
103 case char_P
: return &ffi_type_schar
;
104 case double_P
: return &ffi_type_double
;
105 case float_P
: return &ffi_type_double
;
106 case int_P
: return &ffi_type_sint
;
107 case long_P
: return &ffi_type_slong
;
108 case longlong_P
: return &ffi_type_slonglong
;
109 case short_P
: return &ffi_type_sshort
;
110 case void_P
: return &ffi_type_void
;
111 case struct_P
: return &ffi_type_pointer
;
121 ffi_type
*(*sig_ffi_type
)(apr_pool_t
*, struct Type
*),
122 struct Signature
*signature
,
129 types
= reinterpret_cast<ffi_type
**>(apr_palloc(pool
, (signature
->count
- 1) * sizeof(ffi_type
*)));
130 ffi_type
*type
= (*sig_ffi_type
)(pool
, signature
->elements
[0].type
);
131 sig_ffi_types(pool
, sig_ffi_type
, signature
, types
, 1 + skip
, offset
);
132 ffi_status status
= ffi_prep_cif(cif
, FFI_DEFAULT_ABI
, signature
->count
- 1 - skip
+ offset
, type
, types
);
133 _assert(status
== FFI_OK
);