* ext/dl/{closure,function}.c: removed C99 features and warnings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-02-03 02:39:18 +00:00
parent 3c8b23c35a
commit 22ba8368ae
3 changed files with 170 additions and 159 deletions

View File

@ -1,3 +1,7 @@
Wed Feb 3 11:38:44 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/dl/{closure,function}.c: removed C99 features and warnings.
Wed Feb 3 10:12:09 2010 Aaron Patterson <tenderlove@ruby-lang.org> Wed Feb 3 10:12:09 2010 Aaron Patterson <tenderlove@ruby-lang.org>
* ext/dl/function.c: DL::Function now uses libffi * ext/dl/function.c: DL::Function now uses libffi

View File

@ -35,8 +35,8 @@ static size_t
dlclosure_memsize(const void * ptr) dlclosure_memsize(const void * ptr)
{ {
dl_closure * cls = (dl_closure *)ptr; dl_closure * cls = (dl_closure *)ptr;
size_t size = 0; size_t size = 0;
if (ptr) { if (ptr) {
size += sizeof(*cls); size += sizeof(*cls);
size += ffi_raw_size(cls->cif); size += ffi_raw_size(cls->cif);
@ -59,10 +59,11 @@ dlc_callback(ffi_cif *cif, void *resp, void **args, void *ctx)
VALUE ctype = rb_iv_get(self, "@ctype"); VALUE ctype = rb_iv_get(self, "@ctype");
int argc = RARRAY_LEN(rbargs); int argc = RARRAY_LEN(rbargs);
VALUE *params = xcalloc(argc, sizeof(VALUE *)); VALUE *params = xcalloc(argc, sizeof(VALUE *));
VALUE ret;
int i, dl_type;
int i;
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
int dl_type = NUM2INT(RARRAY_PTR(rbargs)[i]); dl_type = NUM2INT(RARRAY_PTR(rbargs)[i]);
switch (dl_type) { switch (dl_type) {
case DLTYPE_VOID: case DLTYPE_VOID:
argc = 0; argc = 0;
@ -95,9 +96,9 @@ dlc_callback(ffi_cif *cif, void *resp, void **args, void *ctx)
} }
} }
VALUE ret = rb_funcall2(self, rb_intern("call"), argc, params); ret = rb_funcall2(self, rb_intern("call"), argc, params);
int dl_type = NUM2INT(ctype); dl_type = NUM2INT(ctype);
switch (dl_type) { switch (dl_type) {
case DLTYPE_VOID: case DLTYPE_VOID:
break; break;
@ -117,7 +118,7 @@ dlc_callback(ffi_cif *cif, void *resp, void **args, void *ctx)
*(double *)resp = NUM2DBL(ret); *(double *)resp = NUM2DBL(ret);
break; break;
case DLTYPE_FLOAT: case DLTYPE_FLOAT:
*(float *)resp = NUM2DBL(ret); *(float *)resp = (float)NUM2DBL(ret);
break; break;
#if HAVE_LONG_LONG #if HAVE_LONG_LONG
case DLTYPE_LONG_LONG: case DLTYPE_LONG_LONG:
@ -155,16 +156,16 @@ rb_dlclosure_init(int rbargc, VALUE argv[], VALUE self)
VALUE ret; VALUE ret;
VALUE args; VALUE args;
VALUE abi; VALUE abi;
dl_closure * cl; dl_closure * cl;
ffi_cif * cif; ffi_cif * cif;
ffi_closure *pcl; ffi_closure *pcl;
ffi_status result;
int i, argc;
if (2 == rb_scan_args(rbargc, argv, "21", &ret, &args, &abi)) if (2 == rb_scan_args(rbargc, argv, "21", &ret, &args, &abi))
abi = INT2NUM(FFI_DEFAULT_ABI); abi = INT2NUM(FFI_DEFAULT_ABI);
int i; argc = RARRAY_LEN(args);
int argc = RARRAY_LEN(args);
TypedData_Get_Struct(self, dl_closure, &dlclosure_data_type, cl); TypedData_Get_Struct(self, dl_closure, &dlclosure_data_type, cl);
@ -182,7 +183,7 @@ rb_dlclosure_init(int rbargc, VALUE argv[], VALUE self)
cif = cl->cif; cif = cl->cif;
pcl = cl->pcl; pcl = cl->pcl;
ffi_status result = ffi_prep_cif(cif, NUM2INT(abi), argc, result = ffi_prep_cif(cif, NUM2INT(abi), argc,
DL2FFI_TYPE(NUM2INT(ret)), DL2FFI_TYPE(NUM2INT(ret)),
cl->argv); cl->argv);
@ -208,10 +209,11 @@ static VALUE
rb_dlclosure_to_i(VALUE self) rb_dlclosure_to_i(VALUE self)
{ {
dl_closure * cl; dl_closure * cl;
void *code;
TypedData_Get_Struct(self, dl_closure, &dlclosure_data_type, cl); TypedData_Get_Struct(self, dl_closure, &dlclosure_data_type, cl);
void * code = cl->code; code = cl->code;
return PTR2NUM(code); return PTR2NUM(code);
} }

View File

@ -11,33 +11,36 @@ VALUE rb_cDLFunction;
typedef union typedef union
{ {
unsigned char uchar; // ffi_type_uchar unsigned char uchar; /* ffi_type_uchar */
signed char schar; // ffi_type_schar signed char schar; /* ffi_type_schar */
unsigned short ushort; // ffi_type_sshort unsigned short ushort; /* ffi_type_sshort */
signed short sshort; // ffi_type_ushort signed short sshort; /* ffi_type_ushort */
unsigned int uint; // ffi_type_uint unsigned int uint; /* ffi_type_uint */
signed int sint; // ffi_type_sint signed int sint; /* ffi_type_sint */
unsigned long ulong; // ffi_type_ulong unsigned long ulong; /* ffi_type_ulong */
signed long slong; // ffi_type_slong signed long slong; /* ffi_type_slong */
float ffloat; // ffi_type_float float ffloat; /* ffi_type_float */
double ddouble; // ffi_type_double double ddouble; /* ffi_type_double */
#if HAVE_LONG_LONG #if HAVE_LONG_LONG
unsigned LONG_LONG long_long; // ffi_type_uint64 unsigned LONG_LONG long_long; /* ffi_type_uint64 */
#endif #endif
void * pointer; // ffi_type_pointer void * pointer; /* ffi_type_pointer */
} dl_generic; } dl_generic;
static void static void
dlfunction_free(ffi_cif *ptr) dlfunction_free(void *p)
{ {
ffi_cif *ptr = p;
if (ptr->arg_types) xfree(ptr->arg_types); if (ptr->arg_types) xfree(ptr->arg_types);
xfree(ptr); xfree(ptr);
} }
static size_t static size_t
dlfunction_memsize(ffi_cif *ptr) dlfunction_memsize(const void *p)
{ {
/* const */ffi_cif *ptr = (ffi_cif *)p;
size_t size = 0; size_t size = 0;
if (ptr) { if (ptr) {
size += sizeof(*ptr); size += sizeof(*ptr);
size += ffi_raw_size(ptr); size += ffi_raw_size(ptr);
@ -63,19 +66,20 @@ rb_dlfunction_native_init(VALUE self, VALUE args, VALUE ret_type, VALUE abi)
{ {
ffi_cif * cif; ffi_cif * cif;
ffi_type **arg_types; ffi_type **arg_types;
ffi_status result;
int i;
TypedData_Get_Struct(self, ffi_cif, &dlfunction_data_type, cif); TypedData_Get_Struct(self, ffi_cif, &dlfunction_data_type, cif);
arg_types = xcalloc(RARRAY_LEN(args) + 1, sizeof(ffi_type *)); arg_types = xcalloc(RARRAY_LEN(args) + 1, sizeof(ffi_type *));
int i;
for (i = 0; i < RARRAY_LEN(args); i++) { for (i = 0; i < RARRAY_LEN(args); i++) {
int type = NUM2INT(RARRAY_PTR(args)[i]); int type = NUM2INT(RARRAY_PTR(args)[i]);
arg_types[i] = DL2FFI_TYPE(type); arg_types[i] = DL2FFI_TYPE(type);
} }
arg_types[RARRAY_LEN(args)] = NULL; arg_types[RARRAY_LEN(args)] = NULL;
ffi_status result = ffi_prep_cif( result = ffi_prep_cif (
cif, cif,
NUM2INT(abi), NUM2INT(abi),
RARRAY_LEN(args), RARRAY_LEN(args),
@ -121,7 +125,7 @@ dl2generic(int dl_type, VALUE src, dl_generic * dst)
break; break;
#endif #endif
case DLTYPE_FLOAT: case DLTYPE_FLOAT:
dst->ffloat = NUM2DBL(src); dst->ffloat = (float)NUM2DBL(src);
break; break;
case DLTYPE_DOUBLE: case DLTYPE_DOUBLE:
dst->ddouble = NUM2DBL(src); dst->ddouble = NUM2DBL(src);
@ -176,16 +180,17 @@ rb_dlfunction_call(int argc, VALUE argv[], VALUE self)
dl_generic *generic_args; dl_generic *generic_args;
void **values; void **values;
void * fun_ptr; void * fun_ptr;
VALUE cfunc, types;
int i;
TypedData_Get_Struct(self, ffi_cif, &dlfunction_data_type, cif); TypedData_Get_Struct(self, ffi_cif, &dlfunction_data_type, cif);
values = xcalloc((size_t)argc + 1, (size_t)sizeof(void *)); values = xcalloc((size_t)argc + 1, (size_t)sizeof(void *));
generic_args = xcalloc((size_t)argc, (size_t)sizeof(dl_generic)); generic_args = xcalloc((size_t)argc, (size_t)sizeof(dl_generic));
VALUE cfunc = rb_iv_get(self, "@cfunc"); cfunc = rb_iv_get(self, "@cfunc");
VALUE types = rb_iv_get(self, "@args"); types = rb_iv_get(self, "@args");
int i;
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
VALUE dl_type = RARRAY_PTR(types)[i]; VALUE dl_type = RARRAY_PTR(types)[i];
VALUE src = rb_funcall(self, VALUE src = rb_funcall(self,