diff options
author | Sutou Kouhei <[email protected]> | 2023-07-03 16:43:41 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2023-08-02 18:17:18 +0900 |
commit | 15e8cf7ad95f5ea9ec95783e85a9ac5943f020f4 (patch) | |
tree | 74f9378920b7ea4302f4044c97b01943274e9525 /ext/fiddle/conversions.c | |
parent | 10588fa12136b30b44affa209cb49afd4a8d7aa7 (diff) |
[ruby/fiddle] Add support for bool
GitHub: fix https://github.com/ruby/fiddle/pull/130
Reported by Benoit Daloze. Thanks!!!
https://github.com/ruby/fiddle/commit/bc6c66bbb9
Diffstat (limited to 'ext/fiddle/conversions.c')
-rw-r--r-- | ext/fiddle/conversions.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/ext/fiddle/conversions.c b/ext/fiddle/conversions.c index af18f8b31e..b0dcf84873 100644 --- a/ext/fiddle/conversions.c +++ b/ext/fiddle/conversions.c @@ -1,6 +1,25 @@ #include <fiddle.h> VALUE +rb_fiddle_type_bool(void) +{ + if (sizeof(bool) == sizeof(char)) { + return INT2NUM(TYPE_UCHAR); + } else if (sizeof(bool) == sizeof(short)) { + return INT2NUM(TYPE_USHORT); + } else if (sizeof(bool) == sizeof(int)) { + return INT2NUM(TYPE_UINT); + } else if (sizeof(bool) == sizeof(long)) { + return INT2NUM(TYPE_ULONG); + } else { + rb_raise(rb_eNotImpError, + "bool isn't supported: %u", + (unsigned int)sizeof(bool)); + return RUBY_Qnil; + } +} + +VALUE rb_fiddle_type_ensure(VALUE type) { VALUE original_type = type; @@ -44,6 +63,7 @@ rb_fiddle_type_ensure(VALUE type) ID ptrdiff_t_id; ID intptr_t_id; ID uintptr_t_id; + ID bool_id; RUBY_CONST_ID(void_id, "void"); RUBY_CONST_ID(voidp_id, "voidp"); RUBY_CONST_ID(char_id, "char"); @@ -74,6 +94,7 @@ rb_fiddle_type_ensure(VALUE type) RUBY_CONST_ID(ptrdiff_t_id, "ptrdiff_t"); RUBY_CONST_ID(intptr_t_id, "intptr_t"); RUBY_CONST_ID(uintptr_t_id, "uintptr_t"); + RUBY_CONST_ID(bool_id, "bool"); if (type_id == void_id) { return INT2NUM(TYPE_VOID); } @@ -144,6 +165,9 @@ rb_fiddle_type_ensure(VALUE type) else if (type_id == uintptr_t_id) { return INT2NUM(TYPE_UINTPTR_T); } + else if (type_id == bool_id) { + return rb_fiddle_type_bool(); + } else { type = original_type; } |