|
1 | 1 | #include <fiddle.h> |
2 | 2 |
|
| 3 | +VALUE |
| 4 | +rb_fiddle_type_ensure(VALUE type) |
| 5 | +{ |
| 6 | + VALUE original_type = type; |
| 7 | + |
| 8 | + if (!RB_SYMBOL_P(type)) { |
| 9 | + VALUE type_string = rb_check_string_type(type); |
| 10 | + if (!NIL_P(type_string)) { |
| 11 | + type = rb_to_symbol(type_string); |
| 12 | + } |
| 13 | + } |
| 14 | + |
| 15 | + if (RB_SYMBOL_P(type)) { |
| 16 | + ID type_id = rb_sym2id(type); |
| 17 | + ID void_id; |
| 18 | + ID voidp_id; |
| 19 | + ID char_id; |
| 20 | + ID short_id; |
| 21 | + ID int_id; |
| 22 | + ID long_id; |
| 23 | +#ifdef TYPE_LONG_LONG |
| 24 | + ID long_long_id; |
| 25 | +#endif |
| 26 | + ID float_id; |
| 27 | + ID double_id; |
| 28 | + ID variadic_id; |
| 29 | + ID const_string_id; |
| 30 | + ID size_t_id; |
| 31 | + ID ssize_t_id; |
| 32 | + ID ptrdiff_t_id; |
| 33 | + ID intptr_t_id; |
| 34 | + ID uintptr_t_id; |
| 35 | + RUBY_CONST_ID(void_id, "void"); |
| 36 | + RUBY_CONST_ID(voidp_id, "voidp"); |
| 37 | + RUBY_CONST_ID(char_id, "char"); |
| 38 | + RUBY_CONST_ID(short_id, "short"); |
| 39 | + RUBY_CONST_ID(int_id, "int"); |
| 40 | + RUBY_CONST_ID(long_id, "long"); |
| 41 | +#ifdef TYPE_LONG_LONG |
| 42 | + RUBY_CONST_ID(long_long_id, "long_long"); |
| 43 | +#endif |
| 44 | + RUBY_CONST_ID(float_id, "float"); |
| 45 | + RUBY_CONST_ID(double_id, "double"); |
| 46 | + RUBY_CONST_ID(variadic_id, "variadic"); |
| 47 | + RUBY_CONST_ID(const_string_id, "const_string"); |
| 48 | + RUBY_CONST_ID(size_t_id, "size_t"); |
| 49 | + RUBY_CONST_ID(ssize_t_id, "ssize_t"); |
| 50 | + RUBY_CONST_ID(ptrdiff_t_id, "ptrdiff_t"); |
| 51 | + RUBY_CONST_ID(intptr_t_id, "intptr_t"); |
| 52 | + RUBY_CONST_ID(uintptr_t_id, "uintptr_t"); |
| 53 | + if (type_id == void_id) { |
| 54 | + return INT2NUM(TYPE_VOID); |
| 55 | + } |
| 56 | + else if (type_id == voidp_id) { |
| 57 | + return INT2NUM(TYPE_VOIDP); |
| 58 | + } |
| 59 | + else if (type_id == char_id) { |
| 60 | + return INT2NUM(TYPE_CHAR); |
| 61 | + } |
| 62 | + else if (type_id == short_id) { |
| 63 | + return INT2NUM(TYPE_SHORT); |
| 64 | + } |
| 65 | + else if (type_id == int_id) { |
| 66 | + return INT2NUM(TYPE_INT); |
| 67 | + } |
| 68 | + else if (type_id == long_id) { |
| 69 | + return INT2NUM(TYPE_LONG); |
| 70 | + } |
| 71 | +#ifdef TYPE_LONG_LONG |
| 72 | + else if (type_id == long_long_id) { |
| 73 | + return INT2NUM(TYPE_LONG_LONG); |
| 74 | + } |
| 75 | +#endif |
| 76 | + else if (type_id == float_id) { |
| 77 | + return INT2NUM(TYPE_FLOAT); |
| 78 | + } |
| 79 | + else if (type_id == double_id) { |
| 80 | + return INT2NUM(TYPE_DOUBLE); |
| 81 | + } |
| 82 | + else if (type_id == variadic_id) { |
| 83 | + return INT2NUM(TYPE_VARIADIC); |
| 84 | + } |
| 85 | + else if (type_id == const_string_id) { |
| 86 | + return INT2NUM(TYPE_CONST_STRING); |
| 87 | + } |
| 88 | + else if (type_id == size_t_id) { |
| 89 | + return INT2NUM(TYPE_SIZE_T); |
| 90 | + } |
| 91 | + else if (type_id == ssize_t_id) { |
| 92 | + return INT2NUM(TYPE_SSIZE_T); |
| 93 | + } |
| 94 | + else if (type_id == ptrdiff_t_id) { |
| 95 | + return INT2NUM(TYPE_PTRDIFF_T); |
| 96 | + } |
| 97 | + else if (type_id == intptr_t_id) { |
| 98 | + return INT2NUM(TYPE_INTPTR_T); |
| 99 | + } |
| 100 | + else if (type_id == uintptr_t_id) { |
| 101 | + return INT2NUM(TYPE_UINTPTR_T); |
| 102 | + } |
| 103 | + else { |
| 104 | + type = original_type; |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + return rb_to_int(type); |
| 109 | +} |
| 110 | + |
3 | 111 | ffi_type * |
4 | 112 | rb_fiddle_int_to_ffi_type(int type) |
5 | 113 | { |
|
0 commit comments