aboutsummaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authorSutou Kouhei <kou@clear-code.com>2023-05-24 17:19:01 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-06-28 16:36:51 +0900
commit02661f5e9b03eb54509248755a8fae8b3e8089a4 (patch)
tree3e91c279634e4ee376da42e7a68968841468a443 /ext
parent74e049294eec6290f2a61dd434a9be32c829dd7d (diff)
downloadruby-02661f5e9b03eb54509248755a8fae8b3e8089a4.tar.gz
[ruby/fiddle] Add support for converting "C" (one character string) to char
GitHub: fix https://github.com/ruby/fiddle/pull/96 I wanted to add a test for this but I couldn't find a function that has a "char" argument in libc... Reported by kojix2. Thanks!!! https://github.com/ruby/fiddle/commit/2c863ef8ba
Diffstat (limited to 'ext')
-rw-r--r--ext/fiddle/conversions.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/ext/fiddle/conversions.c b/ext/fiddle/conversions.c
index 3b70f7de4c..c0d323de41 100644
--- a/ext/fiddle/conversions.c
+++ b/ext/fiddle/conversions.c
@@ -209,7 +209,11 @@ rb_fiddle_value_to_generic(int type, VALUE *src, fiddle_generic *dst)
dst->pointer = NUM2PTR(rb_Integer(*src));
break;
case TYPE_CHAR:
- dst->schar = (signed char)NUM2INT(*src);
+ if (RB_TYPE_P(*src) == RUBY_T_STRING && RSTRING_LEN(*src) == 1) {
+ dst->schar = RSTRING_PTR(*src)[0];
+ } else {
+ dst->schar = (signed char)NUM2INT(*src);
+ }
break;
case TYPE_UCHAR:
dst->uchar = (unsigned char)NUM2UINT(*src);