mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/fiddle/closure.c (callback): deal with unsinged integers.
[ruby-core:42458][Bug #5991][Bug #6022] * ext/fiddle/conversions.c (value_to_generic, generic_to_value): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fa65df0d08
commit
34be46a32e
5 changed files with 80 additions and 31 deletions
|
@ -1,4 +1,10 @@
|
|||
Wed Feb 15 19:52:28 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Wed Feb 15 19:57:02 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/fiddle/closure.c (callback): deal with unsinged integers.
|
||||
[ruby-core:42458][Bug #5991][Bug #6022]
|
||||
|
||||
* ext/fiddle/conversions.c (value_to_generic, generic_to_value):
|
||||
ditto.
|
||||
|
||||
* ext/fiddle/closure.c (callback): same as r34506.
|
||||
|
||||
|
|
|
@ -72,6 +72,9 @@ callback(ffi_cif *cif, void *resp, void **args, void *ctx)
|
|||
case TYPE_INT:
|
||||
rb_ary_push(params, INT2NUM(*(int *)args[i]));
|
||||
break;
|
||||
case -TYPE_INT:
|
||||
rb_ary_push(params, UINT2NUM(*(unsigned int *)args[i]));
|
||||
break;
|
||||
case TYPE_VOIDP:
|
||||
rb_ary_push(params,
|
||||
rb_funcall(cPointer, rb_intern("[]"), 1,
|
||||
|
@ -80,8 +83,20 @@ callback(ffi_cif *cif, void *resp, void **args, void *ctx)
|
|||
case TYPE_LONG:
|
||||
rb_ary_push(params, LONG2NUM(*(long *)args[i]));
|
||||
break;
|
||||
case -TYPE_LONG:
|
||||
rb_ary_push(params, ULONG2NUM(*(unsigned long *)args[i]));
|
||||
break;
|
||||
case TYPE_CHAR:
|
||||
rb_ary_push(params, INT2NUM(*(char *)args[i]));
|
||||
rb_ary_push(params, INT2NUM(*(signed char *)args[i]));
|
||||
break;
|
||||
case -TYPE_CHAR:
|
||||
rb_ary_push(params, UINT2NUM(*(unsigned char *)args[i]));
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
rb_ary_push(params, INT2NUM(*(signed short *)args[i]));
|
||||
break;
|
||||
case -TYPE_SHORT:
|
||||
rb_ary_push(params, UINT2NUM(*(unsigned short *)args[i]));
|
||||
break;
|
||||
case TYPE_DOUBLE:
|
||||
rb_ary_push(params, rb_float_new(*(double *)args[i]));
|
||||
|
@ -91,7 +106,10 @@ callback(ffi_cif *cif, void *resp, void **args, void *ctx)
|
|||
break;
|
||||
#if HAVE_LONG_LONG
|
||||
case TYPE_LONG_LONG:
|
||||
rb_ary_push(params, rb_ull2inum(*(unsigned LONG_LONG *)args[i]));
|
||||
rb_ary_push(params, LL2NUM(*(LONG_LONG *)args[i]));
|
||||
break;
|
||||
case -TYPE_LONG_LONG:
|
||||
rb_ary_push(params, ULL2NUM(*(unsigned LONG_LONG *)args[i]));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
|
@ -109,11 +127,19 @@ callback(ffi_cif *cif, void *resp, void **args, void *ctx)
|
|||
case TYPE_LONG:
|
||||
*(long *)resp = NUM2LONG(ret);
|
||||
break;
|
||||
case -TYPE_LONG:
|
||||
*(unsigned long *)resp = NUM2ULONG(ret);
|
||||
break;
|
||||
case TYPE_CHAR:
|
||||
case TYPE_SHORT:
|
||||
case TYPE_INT:
|
||||
*(ffi_sarg *)resp = NUM2INT(ret);
|
||||
break;
|
||||
case -TYPE_CHAR:
|
||||
case -TYPE_SHORT:
|
||||
case -TYPE_INT:
|
||||
*(ffi_arg *)resp = NUM2UINT(ret);
|
||||
break;
|
||||
case TYPE_VOIDP:
|
||||
*(void **)resp = NUM2PTR(ret);
|
||||
break;
|
||||
|
@ -125,6 +151,9 @@ callback(ffi_cif *cif, void *resp, void **args, void *ctx)
|
|||
break;
|
||||
#if HAVE_LONG_LONG
|
||||
case TYPE_LONG_LONG:
|
||||
*(LONG_LONG *)resp = NUM2LL(ret);
|
||||
break;
|
||||
case -TYPE_LONG_LONG:
|
||||
*(unsigned LONG_LONG *)resp = NUM2ULL(ret);
|
||||
break;
|
||||
#endif
|
||||
|
|
|
@ -27,7 +27,7 @@ int_to_ffi_type(int type)
|
|||
return rb_ffi_type_of(long);
|
||||
#if HAVE_LONG_LONG
|
||||
case TYPE_LONG_LONG:
|
||||
return rb_ffi_type_of(int64);
|
||||
return rb_ffi_type_of(long_long);
|
||||
#endif
|
||||
case TYPE_FLOAT:
|
||||
return &ffi_type_float;
|
||||
|
@ -42,13 +42,6 @@ int_to_ffi_type(int type)
|
|||
void
|
||||
value_to_generic(int type, VALUE src, fiddle_generic * dst)
|
||||
{
|
||||
int signed_p = 1;
|
||||
|
||||
if (type < 0) {
|
||||
type = -1 * type;
|
||||
signed_p = 0;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case TYPE_VOID:
|
||||
break;
|
||||
|
@ -56,23 +49,35 @@ value_to_generic(int type, VALUE src, fiddle_generic * dst)
|
|||
dst->pointer = NUM2PTR(rb_Integer(src));
|
||||
break;
|
||||
case TYPE_CHAR:
|
||||
dst->schar = NUM2INT(src);
|
||||
dst->schar = (signed char)NUM2INT(src);
|
||||
break;
|
||||
case -TYPE_CHAR:
|
||||
dst->uchar = (unsigned char)NUM2UINT(src);
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
dst->sshort = NUM2INT(src);
|
||||
dst->sshort = (unsigned short)NUM2INT(src);
|
||||
break;
|
||||
case -TYPE_SHORT:
|
||||
dst->sshort = (signed short)NUM2UINT(src);
|
||||
break;
|
||||
case TYPE_INT:
|
||||
dst->sint = NUM2INT(src);
|
||||
break;
|
||||
case -TYPE_INT:
|
||||
dst->uint = NUM2UINT(src);
|
||||
break;
|
||||
case TYPE_LONG:
|
||||
if (signed_p)
|
||||
dst->slong = NUM2LONG(src);
|
||||
else
|
||||
dst->ulong = NUM2LONG(src);
|
||||
dst->slong = NUM2LONG(src);
|
||||
break;
|
||||
case -TYPE_LONG:
|
||||
dst->ulong = NUM2ULONG(src);
|
||||
break;
|
||||
#if HAVE_LONG_LONG
|
||||
case TYPE_LONG_LONG:
|
||||
dst->long_long = NUM2ULL(src);
|
||||
dst->slong_long = NUM2LL(src);
|
||||
break;
|
||||
case -TYPE_LONG_LONG:
|
||||
dst->ulong_long = NUM2ULL(src);
|
||||
break;
|
||||
#endif
|
||||
case TYPE_FLOAT:
|
||||
|
@ -89,17 +94,11 @@ value_to_generic(int type, VALUE src, fiddle_generic * dst)
|
|||
VALUE
|
||||
generic_to_value(VALUE rettype, fiddle_generic retval)
|
||||
{
|
||||
int signed_p = 1;
|
||||
int type = NUM2INT(rettype);
|
||||
VALUE cPointer;
|
||||
|
||||
cPointer = rb_const_get(mFiddle, rb_intern("Pointer"));
|
||||
|
||||
if (type < 0) {
|
||||
type = -1 * type;
|
||||
signed_p = 0;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case TYPE_VOID:
|
||||
return Qnil;
|
||||
|
@ -107,21 +106,26 @@ 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((signed char)retval.fffi_sarg);
|
||||
case -TYPE_CHAR:
|
||||
return INT2NUM((unsigned char)retval.fffi_arg);
|
||||
case TYPE_SHORT:
|
||||
if (signed_p) return INT2NUM((short)retval.fffi_sarg);
|
||||
return INT2NUM((signed short)retval.fffi_sarg);
|
||||
case -TYPE_SHORT:
|
||||
return INT2NUM((unsigned short)retval.fffi_arg);
|
||||
case TYPE_INT:
|
||||
if (signed_p) return INT2NUM((int)retval.fffi_sarg);
|
||||
return INT2NUM((signed int)retval.fffi_sarg);
|
||||
case -TYPE_INT:
|
||||
return UINT2NUM((unsigned int)retval.fffi_arg);
|
||||
case TYPE_LONG:
|
||||
if (signed_p) return LONG2NUM(retval.slong);
|
||||
return LONG2NUM(retval.slong);
|
||||
case -TYPE_LONG:
|
||||
return ULONG2NUM(retval.ulong);
|
||||
#if HAVE_LONG_LONG
|
||||
case TYPE_LONG_LONG:
|
||||
return rb_ll2inum(retval.long_long);
|
||||
break;
|
||||
return LL2NUM(retval.slong_long);
|
||||
case -TYPE_LONG_LONG:
|
||||
return ULL2NUM(retval.ulong_long);
|
||||
#endif
|
||||
case TYPE_FLOAT:
|
||||
return rb_float_new(retval.ffloat);
|
||||
|
|
|
@ -18,7 +18,8 @@ typedef union
|
|||
float ffloat; /* ffi_type_float */
|
||||
double ddouble; /* ffi_type_double */
|
||||
#if HAVE_LONG_LONG
|
||||
unsigned LONG_LONG long_long; /* ffi_type_uint64 */
|
||||
unsigned LONG_LONG ulong_long; /* ffi_type_ulong_long */
|
||||
signed LONG_LONG slong_long; /* ffi_type_ulong_long */
|
||||
#endif
|
||||
void * pointer; /* ffi_type_pointer */
|
||||
} fiddle_generic;
|
||||
|
|
|
@ -67,6 +67,15 @@
|
|||
# error "long size not supported"
|
||||
# endif
|
||||
|
||||
#if HAVE_LONG_LONG
|
||||
# if SIZEOF_LONG_LONG == 8
|
||||
# define ffi_type_slong_long ffi_type_sint64
|
||||
# define ffi_type_ulong_long ffi_type_uint64
|
||||
# else
|
||||
# error "long long size not supported"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <closure.h>
|
||||
#include <conversions.h>
|
||||
#include <function.h>
|
||||
|
|
Loading…
Reference in a new issue