Skip to content

Commit 2c863ef

Browse files
committed
Add support for converting "C" (one character string) to char
GitHub: fix GH-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!!!
1 parent 4598e6c commit 2c863ef

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ext/fiddle/conversions.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ rb_fiddle_value_to_generic(int type, VALUE *src, fiddle_generic *dst)
209209
dst->pointer = NUM2PTR(rb_Integer(*src));
210210
break;
211211
case TYPE_CHAR:
212-
dst->schar = (signed char)NUM2INT(*src);
212+
if (RB_TYPE_P(*src) == RUBY_T_STRING && RSTRING_LEN(*src) == 1) {
213+
dst->schar = RSTRING_PTR(*src)[0];
214+
} else {
215+
dst->schar = (signed char)NUM2INT(*src);
216+
}
213217
break;
214218
case TYPE_UCHAR:
215219
dst->uchar = (unsigned char)NUM2UINT(*src);

0 commit comments

Comments
 (0)