summaryrefslogtreecommitdiff
path: root/ext/fiddle/conversions.c
diff options
context:
space:
mode:
authorngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-09 05:31:47 +0000
committerngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-09 05:31:47 +0000
commit4d71d348555f75ea705f8a0e4782e0e5935a7094 (patch)
tree4d5a050ca37c0c9b09e0d6afd96fb39495296e91 /ext/fiddle/conversions.c
parente26cead1e99e10ab3e672e0894ebdc8c277c833c (diff)
* ext/fiddle/conversions.c (generic_to_value): ffi_arg and ffi_sarg
should be used to handle shorter return value. fix [Bug #3861] [ruby-core:32504] * ext/fiddle/closure.c (callback): ditto * ext/fiddle/conversions.h (fiddle_generic): ditto * ext/fiddle/conversions.c (value_to_generic): char, short and int are strictly distinguished on big-endian CPU, e.g. sparc64. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/fiddle/conversions.c')
-rw-r--r--ext/fiddle/conversions.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/ext/fiddle/conversions.c b/ext/fiddle/conversions.c
index bb5361a..8ffd7c5 100644
--- a/ext/fiddle/conversions.c
+++ b/ext/fiddle/conversions.c
@@ -56,7 +56,11 @@ value_to_generic(int type, VALUE src, fiddle_generic * dst)
dst->pointer = NUM2PTR(rb_Integer(src));
break;
case TYPE_CHAR:
+ dst->schar = NUM2INT(src);
+ break;
case TYPE_SHORT:
+ dst->sshort = NUM2INT(src);
+ break;
case TYPE_INT:
dst->sint = NUM2INT(src);
break;
@@ -103,9 +107,14 @@ generic_to_value(VALUE rettype, fiddle_generic retval)
return rb_funcall(cPointer, rb_intern("[]"), 1,
PTR2NUM((void *)retval.pointer));
case TYPE_CHAR:
+ if (signed_p) return INT2NUM((char)retval.fffi_sarg);
+ return INT2NUM((unsigned char)retval.fffi_arg);
case TYPE_SHORT:
+ if (signed_p) return INT2NUM((short)retval.fffi_sarg);
+ return INT2NUM((unsigned short)retval.fffi_arg);
case TYPE_INT:
- return INT2NUM(retval.sint);
+ if (signed_p) return INT2NUM((int)retval.fffi_sarg);
+ return UINT2NUM((unsigned int)retval.fffi_arg);
case TYPE_LONG:
if (signed_p) return LONG2NUM(retval.slong);
return ULONG2NUM(retval.ulong);