|
1 | 1 | #include <fiddle.h> |
2 | 2 |
|
| 3 | +VALUE |
| 4 | +rb_fiddle_type_bool(void) |
| 5 | +{ |
| 6 | + if (sizeof(bool) == sizeof(char)) { |
| 7 | + return INT2NUM(TYPE_UCHAR); |
| 8 | + } else if (sizeof(bool) == sizeof(short)) { |
| 9 | + return INT2NUM(TYPE_USHORT); |
| 10 | + } else if (sizeof(bool) == sizeof(int)) { |
| 11 | + return INT2NUM(TYPE_UINT); |
| 12 | + } else if (sizeof(bool) == sizeof(long)) { |
| 13 | + return INT2NUM(TYPE_ULONG); |
| 14 | + } else { |
| 15 | + rb_raise(rb_eNotImpError, |
| 16 | + "bool isn't supported: %u", |
| 17 | + (unsigned int)sizeof(bool)); |
| 18 | + return RUBY_Qnil; |
| 19 | + } |
| 20 | +} |
| 21 | + |
3 | 22 | VALUE |
4 | 23 | rb_fiddle_type_ensure(VALUE type) |
5 | 24 | { |
@@ -44,6 +63,7 @@ rb_fiddle_type_ensure(VALUE type) |
44 | 63 | ID ptrdiff_t_id; |
45 | 64 | ID intptr_t_id; |
46 | 65 | ID uintptr_t_id; |
| 66 | + ID bool_id; |
47 | 67 | RUBY_CONST_ID(void_id, "void"); |
48 | 68 | RUBY_CONST_ID(voidp_id, "voidp"); |
49 | 69 | RUBY_CONST_ID(char_id, "char"); |
@@ -74,6 +94,7 @@ rb_fiddle_type_ensure(VALUE type) |
74 | 94 | RUBY_CONST_ID(ptrdiff_t_id, "ptrdiff_t"); |
75 | 95 | RUBY_CONST_ID(intptr_t_id, "intptr_t"); |
76 | 96 | RUBY_CONST_ID(uintptr_t_id, "uintptr_t"); |
| 97 | + RUBY_CONST_ID(bool_id, "bool"); |
77 | 98 | if (type_id == void_id) { |
78 | 99 | return INT2NUM(TYPE_VOID); |
79 | 100 | } |
@@ -144,6 +165,9 @@ rb_fiddle_type_ensure(VALUE type) |
144 | 165 | else if (type_id == uintptr_t_id) { |
145 | 166 | return INT2NUM(TYPE_UINTPTR_T); |
146 | 167 | } |
| 168 | + else if (type_id == bool_id) { |
| 169 | + return rb_fiddle_type_bool(); |
| 170 | + } |
147 | 171 | else { |
148 | 172 | type = original_type; |
149 | 173 | } |
|
0 commit comments