* 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
Родитель 3c8b23c35a
Коммит 22ba8368ae
3 изменённых файлов: 170 добавлений и 159 удалений

Просмотреть файл

@ -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>
* ext/dl/function.c: DL::Function now uses libffi
@ -17,7 +21,7 @@ Wed Feb 3 10:12:09 2010 Aaron Patterson <tenderlove@ruby-lang.org>
* ext/dl/lib/dl/callback.rb: Converting internal callbacks to use
DL::Closure
* ext/dl/lib/dl/closure.rb: Ruby parts of the new DL::Closure object
* ext/dl/lib/dl/import.rb: More conversion to use DL::Closure object
@ -171,7 +175,7 @@ Fri Jan 29 01:26:53 2010 Yukihiro Matsumoto <matz@ruby-lang.org>
denote that #to_i raises FloatDomainError for Inf and NaN.
* ext/bigdecimal/bigdecimal.c (BigDecimal_to_i): fast #to_i using
BigDecimal_split().
BigDecimal_split().
* bignum.c (conv_digit): use faster ISDIGIT() assuming ASCII.
@ -403,7 +407,7 @@ Sat Jan 23 19:54:48 2010 Masaki Suketa <masaki.suketa@nifty.ne.jp>
WIN32OLE.ole_uninitialize to use in win32ole.rb.
You must not use these methods.
* ext/win32ole/lib/win32ole.rb: add win32ole.rb
* ext/win32ole/lib/win32ole.rb: add win32ole.rb
re-define Thread#initialize (fix ruby-core:27634)
Sat Jan 23 00:25:19 2010 Yusuke Endoh <mame@tsg.ne.jp>
@ -419,7 +423,7 @@ Sat Jan 23 00:21:18 2010 Yusuke Endoh <mame@tsg.ne.jp>
Fri Jan 22 23:54:04 2010 Yusuke Endoh <mame@tsg.ne.jp>
* test/ruby/test_array.rb: add a test for Array#rotate, rotate!.
* test/ruby/test_dir.rb, test/ruby/test_fnmatch.rb: add some tests
(for coverage of dir.c).
@ -427,7 +431,7 @@ Fri Jan 22 23:54:04 2010 Yusuke Endoh <mame@tsg.ne.jp>
* test/ruby/test_enumerator.rb: add some tests for Enumerator#inspect,
Enumerator::Generator and Yielder.
* test/ruby/test_env.rb: add a test for ENV#index.
* test/ruby/test_exception.rb: add some tests (for coverage of
@ -453,7 +457,7 @@ Fri Jan 22 23:50:03 2010 Yusuke Endoh <mame@tsg.ne.jp>
Fri Jan 22 21:05:34 2010 Tanaka Akira <akr@fsij.org>
* time.c (time_mload): add submicro into vtm.subsecx. [ruby-dev:40133]
* time.c (time_mload): add submicro into vtm.subsecx. [ruby-dev:40133]
Fri Jan 22 14:26:36 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
@ -622,7 +626,7 @@ Wed Jan 13 11:57:38 2010 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* object.c (rb_class_initialize): Make sure BasicObject doesn't get
initialized twice [ruby-core:27577]
* class.c (rb_class_init_copy): ditto
Wed Jan 13 06:54:44 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
@ -859,7 +863,7 @@ Sun Jan 3 23:54:51 2010 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* variable.c (rb_class2name_without_alloc): new utility function.
* tool/rbinstall.rb (install?(:ext, :arch, :'ext-arch')): installs
* tool/rbinstall.rb (install?(:ext, :arch, :'ext-arch')): installs
dtrace.d if necessary.
* thread_pthread.c (add_signal_thread_list): probe "raise".
@ -901,12 +905,12 @@ Sun Jan 3 23:54:51 2010 Yuki Sonoda (Yugui) <yugui@yugui.jp>
(MINIDTRACE_OBJ): ditto.
(GOLFDTRACE_OBJ): ditto.
(LIBRUBY_DTRACE_OBJ): ditto.
(RUBY_DTRACE_POSTPROCESS): new macro. checks whether the dtrace on
(RUBY_DTRACE_POSTPROCESS): new macro. checks whether the dtrace on
the system needs postprocessing.
(RUBY_DTRACE_BSD_BROKEN): new macro. checks whether the dtrace
supports USDT.
* Makefile.in:
* Makefile.in:
(DTRACE): new variable. name of dtrace(1).
(TRACING_MODEL): new variable. name of the chosen tracing mechanism.
(DTRACE_OBJ): same as the one in configure.in.
@ -917,16 +921,16 @@ Sun Jan 3 23:54:51 2010 Yuki Sonoda (Yugui) <yugui@yugui.jp>
(trace_none.h): new target for TRACING_MODEL=none
(RUBY_H_INCLUDES): appended a header for tracing.
(distclean-local): also removes preprocessed version of dtrace.d
($(LIBRUBY_A)): needs $(LIBRUBY_DTRACE_OBJ) if dtrace needs
($(LIBRUBY_A)): needs $(LIBRUBY_DTRACE_OBJ) if dtrace needs
postprocessing.
($(PROGRAM)): ditto.
(golf): ditto.
(miniruby): ditto.
($(arch_hdrdir)/ruby/dtrace.d): new target. preprocessed version
($(arch_hdrdir)/ruby/dtrace.d): new target. preprocessed version
of defs/dtrace.d. generated if necessary.
($(arch_hdrdir)/ruby/trace_dtrace.h): new target.
definition of probes.
($(LIBRUBY_DTRACE_OBJ)): new target. generated if dtrace needs
($(LIBRUBY_DTRACE_OBJ)): new target. generated if dtrace needs
postprocessing.
($(DTRACE_OBJ)): ditto.
($(MINIDTRACE_OBJ)): ditto.
@ -1110,7 +1114,7 @@ Sun Dec 27 10:45:00 2009 Masaki Suketa <masaki.suketa@nifty.ne.jp>
Sun Dec 27 09:41:54 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* tool/rbinstall.rb (install?(:local, :comm, :bin, :'bin-comm')):
Makes it vim friendly. __END__ in a heredoc is confusing with
Makes it vim friendly. __END__ in a heredoc is confusing with
the script end for vim.
Sun Dec 27 09:13:55 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp>

Просмотреть файл

@ -27,7 +27,7 @@ dlclosure_free(void * ptr)
munmap(cls->pcl, sizeof(cls->pcl));
#endif
xfree(cls->cif);
if(cls->argv) xfree(cls->argv);
if (cls->argv) xfree(cls->argv);
xfree(cls);
}
@ -35,9 +35,9 @@ static size_t
dlclosure_memsize(const void * ptr)
{
dl_closure * cls = (dl_closure *)ptr;
size_t size = 0;
if(ptr) {
if (ptr) {
size += sizeof(*cls);
size += ffi_raw_size(cls->cif);
size += sizeof(*cls->argv);
@ -59,73 +59,74 @@ dlc_callback(ffi_cif *cif, void *resp, void **args, void *ctx)
VALUE ctype = rb_iv_get(self, "@ctype");
int argc = RARRAY_LEN(rbargs);
VALUE *params = xcalloc(argc, sizeof(VALUE *));
VALUE ret;
int i, dl_type;
int i;
for(i = 0; i < argc; i++) {
int dl_type = NUM2INT(RARRAY_PTR(rbargs)[i]);
switch(dl_type) {
case DLTYPE_VOID:
argc = 0;
break;
case DLTYPE_INT:
params[i] = INT2NUM(*(int *)args[i]);
break;
case DLTYPE_VOIDP:
params[i] = rb_dlptr_new(*(void **)args[i], 0, NULL);
break;
case DLTYPE_LONG:
params[i] = LONG2NUM(*(long *)args[i]);
break;
case DLTYPE_CHAR:
params[i] = INT2NUM(*(char *)args[i]);
break;
case DLTYPE_DOUBLE:
params[i] = rb_float_new(*(double *)args[i]);
break;
case DLTYPE_FLOAT:
params[i] = rb_float_new(*(float *)args[i]);
break;
for (i = 0; i < argc; i++) {
dl_type = NUM2INT(RARRAY_PTR(rbargs)[i]);
switch (dl_type) {
case DLTYPE_VOID:
argc = 0;
break;
case DLTYPE_INT:
params[i] = INT2NUM(*(int *)args[i]);
break;
case DLTYPE_VOIDP:
params[i] = rb_dlptr_new(*(void **)args[i], 0, NULL);
break;
case DLTYPE_LONG:
params[i] = LONG2NUM(*(long *)args[i]);
break;
case DLTYPE_CHAR:
params[i] = INT2NUM(*(char *)args[i]);
break;
case DLTYPE_DOUBLE:
params[i] = rb_float_new(*(double *)args[i]);
break;
case DLTYPE_FLOAT:
params[i] = rb_float_new(*(float *)args[i]);
break;
#if HAVE_LONG_LONG
case DLTYPE_LONG_LONG:
params[i] = rb_ull2inum(*(unsigned LONG_LONG *)args[i]);
break;
case DLTYPE_LONG_LONG:
params[i] = rb_ull2inum(*(unsigned LONG_LONG *)args[i]);
break;
#endif
default:
rb_raise(rb_eRuntimeError, "closure args: %d", dl_type);
default:
rb_raise(rb_eRuntimeError, "closure args: %d", dl_type);
}
}
VALUE ret = rb_funcall2(self, rb_intern("call"), argc, params);
ret = rb_funcall2(self, rb_intern("call"), argc, params);
int dl_type = NUM2INT(ctype);
switch(dl_type) {
case DLTYPE_VOID:
break;
case DLTYPE_LONG:
*(long *)resp = NUM2LONG(ret);
break;
case DLTYPE_CHAR:
*(char *)resp = NUM2INT(ret);
break;
case DLTYPE_VOIDP:
*(void **)resp = NUM2PTR(ret);
break;
case DLTYPE_INT:
*(int *)resp = NUM2INT(ret);
break;
case DLTYPE_DOUBLE:
*(double *)resp = NUM2DBL(ret);
break;
case DLTYPE_FLOAT:
*(float *)resp = NUM2DBL(ret);
break;
dl_type = NUM2INT(ctype);
switch (dl_type) {
case DLTYPE_VOID:
break;
case DLTYPE_LONG:
*(long *)resp = NUM2LONG(ret);
break;
case DLTYPE_CHAR:
*(char *)resp = NUM2INT(ret);
break;
case DLTYPE_VOIDP:
*(void **)resp = NUM2PTR(ret);
break;
case DLTYPE_INT:
*(int *)resp = NUM2INT(ret);
break;
case DLTYPE_DOUBLE:
*(double *)resp = NUM2DBL(ret);
break;
case DLTYPE_FLOAT:
*(float *)resp = (float)NUM2DBL(ret);
break;
#if HAVE_LONG_LONG
case DLTYPE_LONG_LONG:
*(unsigned LONG_LONG *)resp = rb_big2ull(ret);
break;
case DLTYPE_LONG_LONG:
*(unsigned LONG_LONG *)resp = rb_big2ull(ret);
break;
#endif
default:
rb_raise(rb_eRuntimeError, "closure retval: %d", dl_type);
default:
rb_raise(rb_eRuntimeError, "closure retval: %d", dl_type);
}
xfree(params);
}
@ -155,22 +156,22 @@ rb_dlclosure_init(int rbargc, VALUE argv[], VALUE self)
VALUE ret;
VALUE args;
VALUE abi;
dl_closure * cl;
ffi_cif * cif;
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);
int i;
int argc = RARRAY_LEN(args);
argc = RARRAY_LEN(args);
TypedData_Get_Struct(self, dl_closure, &dlclosure_data_type, cl);
cl->argv = (ffi_type **)xcalloc(argc + 1, sizeof(ffi_type *));
for(i = 0; i < argc; i++) {
for (i = 0; i < argc; i++) {
int dltype = NUM2INT(RARRAY_PTR(args)[i]);
cl->argv[i] = DL2FFI_TYPE(dltype);
}
@ -182,11 +183,11 @@ rb_dlclosure_init(int rbargc, VALUE argv[], VALUE self)
cif = cl->cif;
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)),
cl->argv);
if(FFI_OK != result)
if (FFI_OK != result)
rb_raise(rb_eRuntimeError, "error prepping CIF %d", result);
#ifdef USE_NEW_CLOSURE_API
@ -198,7 +199,7 @@ rb_dlclosure_init(int rbargc, VALUE argv[], VALUE self)
mprotect(pcl, sizeof(pcl), PROT_READ | PROT_EXEC);
#endif
if(FFI_OK != result)
if (FFI_OK != result)
rb_raise(rb_eRuntimeError, "error prepping closure %d", result);
return self;
@ -208,10 +209,11 @@ static VALUE
rb_dlclosure_to_i(VALUE self)
{
dl_closure * cl;
void *code;
TypedData_Get_Struct(self, dl_closure, &dlclosure_data_type, cl);
void * code = cl->code;
code = cl->code;
return PTR2NUM(code);
}

Просмотреть файл

@ -11,34 +11,37 @@ VALUE rb_cDLFunction;
typedef union
{
unsigned char uchar; // ffi_type_uchar
signed char schar; // ffi_type_schar
unsigned short ushort; // ffi_type_sshort
signed short sshort; // ffi_type_ushort
unsigned int uint; // ffi_type_uint
signed int sint; // ffi_type_sint
unsigned long ulong; // ffi_type_ulong
signed long slong; // ffi_type_slong
float ffloat; // ffi_type_float
double ddouble; // ffi_type_double
unsigned char uchar; /* ffi_type_uchar */
signed char schar; /* ffi_type_schar */
unsigned short ushort; /* ffi_type_sshort */
signed short sshort; /* ffi_type_ushort */
unsigned int uint; /* ffi_type_uint */
signed int sint; /* ffi_type_sint */
unsigned long ulong; /* ffi_type_ulong */
signed long slong; /* ffi_type_slong */
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 long_long; /* ffi_type_uint64 */
#endif
void * pointer; // ffi_type_pointer
void * pointer; /* ffi_type_pointer */
} dl_generic;
static void
dlfunction_free(ffi_cif *ptr)
dlfunction_free(void *p)
{
if(ptr->arg_types) xfree(ptr->arg_types);
ffi_cif *ptr = p;
if (ptr->arg_types) xfree(ptr->arg_types);
xfree(ptr);
}
static size_t
dlfunction_memsize(ffi_cif *ptr)
dlfunction_memsize(const void *p)
{
/* const */ffi_cif *ptr = (ffi_cif *)p;
size_t size = 0;
if(ptr) {
if (ptr) {
size += sizeof(*ptr);
size += ffi_raw_size(ptr);
}
@ -63,26 +66,27 @@ rb_dlfunction_native_init(VALUE self, VALUE args, VALUE ret_type, VALUE abi)
{
ffi_cif * cif;
ffi_type **arg_types;
ffi_status result;
int i;
TypedData_Get_Struct(self, ffi_cif, &dlfunction_data_type, cif);
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]);
arg_types[i] = DL2FFI_TYPE(type);
}
arg_types[RARRAY_LEN(args)] = NULL;
ffi_status result = ffi_prep_cif(
result = ffi_prep_cif (
cif,
NUM2INT(abi),
RARRAY_LEN(args),
DL2FFI_TYPE(NUM2INT(ret_type)),
arg_types);
if(result)
if (result)
rb_raise(rb_eRuntimeError, "error creating CIF %d", result);
return self;
@ -93,41 +97,41 @@ dl2generic(int dl_type, VALUE src, dl_generic * dst)
{
int signed_p = 1;
if(dl_type < 0) {
if (dl_type < 0) {
dl_type = -1 * dl_type;
signed_p = 0;
}
switch(dl_type) {
case DLTYPE_VOID:
break;
case DLTYPE_VOIDP:
dst->pointer = NUM2PTR(rb_Integer(src));
break;
case DLTYPE_CHAR:
case DLTYPE_SHORT:
case DLTYPE_INT:
dst->sint = NUM2INT(src);
break;
case DLTYPE_LONG:
if(signed_p)
dst->slong = NUM2LONG(src);
else
dst->ulong = NUM2LONG(src);
break;
switch (dl_type) {
case DLTYPE_VOID:
break;
case DLTYPE_VOIDP:
dst->pointer = NUM2PTR(rb_Integer(src));
break;
case DLTYPE_CHAR:
case DLTYPE_SHORT:
case DLTYPE_INT:
dst->sint = NUM2INT(src);
break;
case DLTYPE_LONG:
if (signed_p)
dst->slong = NUM2LONG(src);
else
dst->ulong = NUM2LONG(src);
break;
#if HAVE_LONG_LONG
case DLTYPE_LONG_LONG:
dst->long_long = rb_big2ull(src);
break;
case DLTYPE_LONG_LONG:
dst->long_long = rb_big2ull(src);
break;
#endif
case DLTYPE_FLOAT:
dst->ffloat = NUM2DBL(src);
break;
case DLTYPE_DOUBLE:
dst->ddouble = NUM2DBL(src);
break;
default:
rb_raise(rb_eRuntimeError, "unknown type %d", dl_type);
case DLTYPE_FLOAT:
dst->ffloat = (float)NUM2DBL(src);
break;
case DLTYPE_DOUBLE:
dst->ddouble = NUM2DBL(src);
break;
default:
rb_raise(rb_eRuntimeError, "unknown type %d", dl_type);
}
}
@ -137,34 +141,34 @@ unwrap_ffi(VALUE rettype, dl_generic retval)
int signed_p = 1;
int dl_type = NUM2INT(rettype);
if(dl_type < 0) {
if (dl_type < 0) {
dl_type = -1 * dl_type;
signed_p = 0;
}
switch(dl_type) {
case DLTYPE_VOID:
return Qnil;
case DLTYPE_VOIDP:
return rb_dlptr_new((void *)retval.pointer, 0, NULL);
case DLTYPE_CHAR:
case DLTYPE_SHORT:
case DLTYPE_INT:
return INT2NUM(retval.sint);
case DLTYPE_LONG:
if(signed_p) return LONG2NUM(retval.slong);
return LONG2NUM(retval.ulong);
switch (dl_type) {
case DLTYPE_VOID:
return Qnil;
case DLTYPE_VOIDP:
return rb_dlptr_new((void *)retval.pointer, 0, NULL);
case DLTYPE_CHAR:
case DLTYPE_SHORT:
case DLTYPE_INT:
return INT2NUM(retval.sint);
case DLTYPE_LONG:
if (signed_p) return LONG2NUM(retval.slong);
return LONG2NUM(retval.ulong);
#if HAVE_LONG_LONG
case DLTYPE_LONG_LONG:
return rb_ll2inum(retval.long_long);
break;
case DLTYPE_LONG_LONG:
return rb_ll2inum(retval.long_long);
break;
#endif
case DLTYPE_FLOAT:
return rb_float_new(retval.ffloat);
case DLTYPE_DOUBLE:
return rb_float_new(retval.ddouble);
default:
rb_raise(rb_eRuntimeError, "unknown type %d", dl_type);
case DLTYPE_FLOAT:
return rb_float_new(retval.ffloat);
case DLTYPE_DOUBLE:
return rb_float_new(retval.ddouble);
default:
rb_raise(rb_eRuntimeError, "unknown type %d", dl_type);
}
}
@ -176,17 +180,18 @@ rb_dlfunction_call(int argc, VALUE argv[], VALUE self)
dl_generic *generic_args;
void **values;
void * fun_ptr;
VALUE cfunc, types;
int i;
TypedData_Get_Struct(self, ffi_cif, &dlfunction_data_type, cif);
values = xcalloc((size_t)argc + 1, (size_t)sizeof(void *));
generic_args = xcalloc((size_t)argc, (size_t)sizeof(dl_generic));
VALUE cfunc = rb_iv_get(self, "@cfunc");
VALUE types = rb_iv_get(self, "@args");
cfunc = rb_iv_get(self, "@cfunc");
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 src = rb_funcall(self,
rb_intern("ruby2ffi"),