1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Get rid of ineffective symbols, lines, constants and so on.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ttate 2002-11-07 16:42:07 +00:00
parent 56cddaf082
commit 8e3721dfa8
7 changed files with 143 additions and 157 deletions

View file

@ -175,7 +175,7 @@ dlsizeof(const char *cstr)
} }
else{ else{
dlen = 0; dlen = 0;
}; }
switch( cstr[i] ){ switch( cstr[i] ){
case 'I': case 'I':
@ -215,9 +215,9 @@ dlsizeof(const char *cstr)
default: default:
rb_raise(rb_eDLTypeError, "unexpected type '%c'", cstr[i]); rb_raise(rb_eDLTypeError, "unexpected type '%c'", cstr[i]);
break; break;
}; }
i += dlen; i += dlen;
}; }
return size; return size;
} }
@ -244,8 +244,8 @@ c_farray(VALUE v, long *size)
default: default:
rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
break; break;
}; }
}; }
return ary; return ary;
} }
@ -272,8 +272,8 @@ c_darray(VALUE v, long *size)
default: default:
rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
break; break;
}; }
}; }
return ary; return ary;
} }
@ -301,8 +301,8 @@ c_larray(VALUE v, long *size)
default: default:
rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
break; break;
}; }
}; }
return ary; return ary;
} }
@ -330,8 +330,8 @@ c_iarray(VALUE v, long *size)
default: default:
rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
break; break;
}; }
}; }
return ary; return ary;
} }
@ -359,8 +359,8 @@ c_harray(VALUE v, long *size)
default: default:
rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
break; break;
}; }
}; }
return ary; return ary;
} }
@ -388,8 +388,8 @@ c_carray(VALUE v, long *size)
default: default:
rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
break; break;
}; }
}; }
return ary; return ary;
} }
@ -413,7 +413,7 @@ c_parray(VALUE v, long *size)
src = RSTRING(e)->ptr; src = RSTRING(e)->ptr;
str = dlstrdup(src); str = dlstrdup(src);
ary[i] = (void*)str; ary[i] = (void*)str;
}; }
break; break;
case T_NIL: case T_NIL:
ary[i] = NULL; ary[i] = NULL;
@ -426,13 +426,13 @@ c_parray(VALUE v, long *size)
} }
else{ else{
rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
}; }
break; break;
default: default:
rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
break; break;
}; }
}; }
return ary; return ary;
} }
@ -445,16 +445,16 @@ rb_ary2cary(char t, VALUE v, long *size)
if( TYPE(v) != T_ARRAY ){ if( TYPE(v) != T_ARRAY ){
rb_raise(rb_eDLTypeError, "an array is expected."); rb_raise(rb_eDLTypeError, "an array is expected.");
}; }
len = RARRAY(v)->len; len = RARRAY(v)->len;
if( len == 0 ){ if( len == 0 ){
return NULL; return NULL;
}; }
if( !size ){ if( !size ){
size = ALLOCA_N(long,1); size = ALLOCA_N(long,1);
}; }
val0 = rb_ary_entry(v,0); val0 = rb_ary_entry(v,0);
switch( TYPE(val0) ){ switch( TYPE(val0) ){
@ -471,7 +471,7 @@ rb_ary2cary(char t, VALUE v, long *size)
return (void*)c_larray(v,size); return (void*)c_larray(v,size);
default: default:
rb_raise(rb_eDLTypeError, "type mismatch"); rb_raise(rb_eDLTypeError, "type mismatch");
}; }
case T_STRING: case T_STRING:
return (void*)c_parray(v,size); return (void*)c_parray(v,size);
case T_FLOAT: case T_FLOAT:
@ -480,18 +480,18 @@ rb_ary2cary(char t, VALUE v, long *size)
return (void*)c_farray(v,size); return (void*)c_farray(v,size);
case 'D': case 'd': case 0: case 'D': case 'd': case 0:
return (void*)c_darray(v,size); return (void*)c_darray(v,size);
}; }
rb_raise(rb_eDLTypeError, "type mismatch"); rb_raise(rb_eDLTypeError, "type mismatch");
case T_DATA: case T_DATA:
if( rb_obj_is_kind_of(val0, rb_cDLPtrData) ){ if( rb_obj_is_kind_of(val0, rb_cDLPtrData) ){
return (void*)c_parray(v,size); return (void*)c_parray(v,size);
}; }
rb_raise(rb_eDLTypeError, "type mismatch"); rb_raise(rb_eDLTypeError, "type mismatch");
case T_NIL: case T_NIL:
return (void*)c_parray(v, size); return (void*)c_parray(v, size);
default: default:
rb_raise(rb_eDLTypeError, "unsupported type"); rb_raise(rb_eDLTypeError, "unsupported type");
}; }
} }
VALUE VALUE
@ -521,7 +521,7 @@ rb_ary_to_ptr(int argc, VALUE argv[], VALUE self)
case 0: case 0:
ptr = rb_ary2cary(0, self, &size); ptr = rb_ary2cary(0, self, &size);
break; break;
}; }
return ptr ? rb_dlptr_new(ptr, size, dlfree) : Qnil; return ptr ? rb_dlptr_new(ptr, size, dlfree) : Qnil;
} }
@ -535,7 +535,7 @@ rb_io_to_ptr(VALUE self)
fp = fptr->f; fp = fptr->f;
return fp ? rb_dlptr_new(fp, sizeof(FILE), 0) : Qnil; return fp ? rb_dlptr_new(fp, sizeof(FILE), 0) : Qnil;
}; }
VALUE VALUE
rb_dl_dlopen(int argc, VALUE argv[], VALUE self) rb_dl_dlopen(int argc, VALUE argv[], VALUE self)
@ -679,10 +679,6 @@ Init_dl()
rb_define_const(rb_mDL, "ALIGN_DOUBLE",INT2NUM(ALIGN_DOUBLE)); rb_define_const(rb_mDL, "ALIGN_DOUBLE",INT2NUM(ALIGN_DOUBLE));
rb_define_const(rb_mDL, "ALIGN_VOIDP", INT2NUM(ALIGN_VOIDP)); rb_define_const(rb_mDL, "ALIGN_VOIDP", INT2NUM(ALIGN_VOIDP));
rb_define_const(rb_mDL, "VERSION", rb_tainted_str_new2(DL_VERSION));
rb_define_const(rb_mDL, "MAJOR_VERSION", INT2NUM(DL_MAJOR_VERSION));
rb_define_const(rb_mDL, "MINOR_VERSION", INT2NUM(DL_MINOR_VERSION));
rb_define_const(rb_mDL, "PATCH_VERSION", INT2NUM(DL_PATCH_VERSION));
rb_define_const(rb_mDL, "MAX_ARG", INT2NUM(MAX_ARG)); rb_define_const(rb_mDL, "MAX_ARG", INT2NUM(MAX_ARG));
rb_define_const(rb_mDL, "DLSTACK", rb_tainted_str_new2(DLSTACK_METHOD)); rb_define_const(rb_mDL, "DLSTACK", rb_tainted_str_new2(DLSTACK_METHOD));

View file

@ -8,11 +8,6 @@
#include <ruby.h> #include <ruby.h>
#include <dlconfig.h> #include <dlconfig.h>
#define DL_VERSION "1.2.0"
#define DL_MAJOR_VERSION 1
#define DL_MINOR_VERSION 2
#define DL_PATCH_VERSION 0
#if defined(HAVE_DLFCN_H) #if defined(HAVE_DLFCN_H)
# include <dlfcn.h> # include <dlfcn.h>
# /* some stranger systems may not define all of these */ # /* some stranger systems may not define all of these */

View file

@ -12,7 +12,7 @@ dlhandle_free(struct dl_handle *dlhandle)
{ {
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){ if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
dlclose(dlhandle->ptr); dlclose(dlhandle->ptr);
}; }
} }
VALUE VALUE
@ -61,18 +61,18 @@ rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
break; break;
default: default:
rb_bug("rb_dlhandle_new"); rb_bug("rb_dlhandle_new");
}; }
ptr = dlopen(clib, cflag); ptr = dlopen(clib, cflag);
#if defined(HAVE_DLERROR) #if defined(HAVE_DLERROR)
if( (err = dlerror()) ){ if( (err = dlerror()) ){
rb_raise(rb_eRuntimeError, err); rb_raise(rb_eRuntimeError, err);
}; }
#else #else
if( !ptr ){ if( !ptr ){
err = dlerror(); err = dlerror();
rb_raise(rb_eRuntimeError, err); rb_raise(rb_eRuntimeError, err);
}; }
#endif #endif
Data_Get_Struct(self, struct dl_handle, dlhandle); Data_Get_Struct(self, struct dl_handle, dlhandle);
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){ if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
@ -84,7 +84,7 @@ rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
if( rb_block_given_p() ){ if( rb_block_given_p() ){
rb_ensure(rb_yield, self, rb_dlhandle_close, self); rb_ensure(rb_yield, self, rb_dlhandle_close, self);
}; }
return Qnil; return Qnil;
} }
@ -146,7 +146,7 @@ rb_dlhandle_sym(int argc, VALUE argv[], VALUE self)
} }
else{ else{
stype = NULL; stype = NULL;
}; }
if( sym == Qnil ){ if( sym == Qnil ){
#if defined(RTLD_NEXT) #if defined(RTLD_NEXT)
@ -157,7 +157,7 @@ rb_dlhandle_sym(int argc, VALUE argv[], VALUE self)
} }
else{ else{
name = StringValuePtr(sym); name = StringValuePtr(sym);
}; }
Data_Get_Struct(self, struct dl_handle, dlhandle); Data_Get_Struct(self, struct dl_handle, dlhandle);
@ -189,12 +189,12 @@ rb_dlhandle_sym(int argc, VALUE argv[], VALUE self)
#endif #endif
{ {
rb_raise(rb_eRuntimeError, "Unknown symbol \"%sA\".", name); rb_raise(rb_eRuntimeError, "Unknown symbol \"%sA\".", name);
}; }
} }
#else #else
rb_raise(rb_eRuntimeError, "Unknown symbol \"%s\".", name); rb_raise(rb_eRuntimeError, "Unknown symbol \"%s\".", name);
#endif #endif
}; }
val = rb_dlsym_new(func, name, stype); val = rb_dlsym_new(func, name, stype);
return val; return val;

View file

@ -5,12 +5,6 @@ $:.unshift File.dirname(__FILE__)
require 'type' require 'type'
require 'dlconfig' require 'dlconfig'
$int_eq_long = try_run(<<EOF)
int main() {
return sizeof(int) == sizeof(long) ? 0 : 1;
}
EOF
def output_arg(x,i) def output_arg(x,i)
"args[#{i}].#{DLTYPE[x][:stmem]}" "args[#{i}].#{DLTYPE[x][:stmem]}"
end end

View file

@ -36,7 +36,7 @@ rb_dlmem_aset(void *ptr, VALUE obj)
} }
else{ else{
rb_hash_aset(DLMemoryTable, DLLONG2NUM(ptr), DLLONG2NUM(obj)); rb_hash_aset(DLMemoryTable, DLLONG2NUM(ptr), DLLONG2NUM(obj));
}; }
} }
static VALUE static VALUE
@ -62,8 +62,8 @@ dlptr_free(struct ptr_data *data)
printf("dlptr_free(): 0x%x(data->ptr:0x%x)\n",data->free,data->ptr); printf("dlptr_free(): 0x%x(data->ptr:0x%x)\n",data->free,data->ptr);
}); });
(*(data->free))(data->ptr); (*(data->free))(data->ptr);
}; }
}; }
if( data->stype ) dlfree(data->stype); if( data->stype ) dlfree(data->stype);
if( data->ssize ) dlfree(data->ssize); if( data->ssize ) dlfree(data->ssize);
if( data->ids ) dlfree(data->ids); if( data->ids ) dlfree(data->ids);
@ -108,12 +108,12 @@ rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func)
if( func ){ if( func ){
Data_Get_Struct(val, struct ptr_data, data); Data_Get_Struct(val, struct ptr_data, data);
data->free = func; data->free = func;
}; }
}; }
} }
else{ else{
val = Qnil; val = Qnil;
}; }
return val; return val;
} }
@ -149,7 +149,7 @@ rb_dlptr2cptr(VALUE val)
} }
else{ else{
rb_raise(rb_eTypeError, "DL::PtrData was expected"); rb_raise(rb_eTypeError, "DL::PtrData was expected");
}; }
return ptr; return ptr;
} }
@ -346,12 +346,12 @@ rb_dlptr_to_array(int argc, VALUE argv[], VALUE self)
} }
else{ else{
n = 0; n = 0;
}; }
}; }
break; break;
default: default:
rb_bug("rb_dlptr_to_array"); rb_bug("rb_dlptr_to_array");
}; }
ary = rb_ary_new(); ary = rb_ary_new();
@ -382,8 +382,8 @@ rb_dlptr_to_array(int argc, VALUE argv[], VALUE self)
} }
else{ else{
rb_ary_push(ary, Qnil); rb_ary_push(ary, Qnil);
}; }
}; }
break; break;
case 's': case 's':
{ {
@ -394,8 +394,8 @@ rb_dlptr_to_array(int argc, VALUE argv[], VALUE self)
} }
else{ else{
rb_ary_push(ary, Qnil); rb_ary_push(ary, Qnil);
}; }
}; }
break; break;
case 'P': case 'P':
rb_ary_push(ary, rb_dlptr_new(((void**)(data->ptr))[i],0,0)); rb_ary_push(ary, rb_dlptr_new(((void**)(data->ptr))[i],0,0));
@ -404,8 +404,8 @@ rb_dlptr_to_array(int argc, VALUE argv[], VALUE self)
rb_ary_push(ary, rb_ary_push(ary,
rb_dlptr_new(((void**)(data->ptr))[i],0,dlfree)); rb_dlptr_new(((void**)(data->ptr))[i],0,dlfree));
break; break;
}; }
}; }
return ary; return ary;
} }
@ -429,7 +429,7 @@ rb_dlptr_to_s(int argc, VALUE argv[], VALUE self)
break; break;
default: default:
rb_bug("rb_dlptr_to_s"); rb_bug("rb_dlptr_to_s");
}; }
return val; return val;
} }
@ -452,7 +452,7 @@ rb_dlptr_to_str(int argc, VALUE argv[], VALUE self)
break; break;
default: default:
rb_bug("rb_dlptr_to_str"); rb_bug("rb_dlptr_to_str");
}; }
return val; return val;
} }
@ -533,17 +533,17 @@ rb_dlptr_define_data_type(int argc, VALUE argv[], VALUE self)
if( data->stype ){ if( data->stype ){
dlfree(data->stype); dlfree(data->stype);
data->stype = NULL; data->stype = NULL;
}; }
if( data->ids ){ if( data->ids ){
dlfree(data->ids); dlfree(data->ids);
data->ids = NULL; data->ids = NULL;
}; }
return Qnil; return Qnil;
} }
else{ else{
rb_raise(rb_eArgError, "wrong arguments"); rb_raise(rb_eArgError, "wrong arguments");
}; }
}; }
t = NUM2INT(data_type); t = NUM2INT(data_type);
StringValue(type); StringValue(type);
@ -553,8 +553,8 @@ rb_dlptr_define_data_type(int argc, VALUE argv[], VALUE self)
vid = rb_ary_entry(rest,i); vid = rb_ary_entry(rest,i);
if( !(TYPE(vid)==T_STRING || TYPE(vid)==T_SYMBOL) ){ if( !(TYPE(vid)==T_STRING || TYPE(vid)==T_SYMBOL) ){
rb_raise(rb_eTypeError, "#%d must be a string or symbol", i + 2); rb_raise(rb_eTypeError, "#%d must be a string or symbol", i + 2);
}; }
}; }
data->ctype = t; data->ctype = t;
data->slen = num; data->slen = num;
@ -583,12 +583,12 @@ rb_dlptr_define_data_type(int argc, VALUE argv[], VALUE self)
} }
else{ else{
data->ssize[i] = 1; data->ssize[i] = 1;
}; }
}; }
if( *ctype ){ if( *ctype ){
rb_raise(rb_eArgError, "too few/many arguments"); rb_raise(rb_eArgError, "too few/many arguments");
}; }
if( !data->size ) if( !data->size )
data->size = dlsizeof(RSTRING(type)->ptr); data->size = dlsizeof(RSTRING(type)->ptr);
@ -607,7 +607,7 @@ rb_dlptr_define_struct(int argc, VALUE argv[], VALUE self)
pass_argv[0] = INT2FIX(DLPTR_CTYPE_STRUCT); pass_argv[0] = INT2FIX(DLPTR_CTYPE_STRUCT);
for( i=1; i<pass_argc; i++ ){ for( i=1; i<pass_argc; i++ ){
pass_argv[i] = argv[i-1]; pass_argv[i] = argv[i-1];
}; }
return rb_dlptr_define_data_type(pass_argc, pass_argv, self); return rb_dlptr_define_data_type(pass_argc, pass_argv, self);
} }
@ -622,7 +622,7 @@ rb_dlptr_define_union(int argc, VALUE argv[], VALUE self)
pass_argv[0] = INT2FIX(DLPTR_CTYPE_UNION); pass_argv[0] = INT2FIX(DLPTR_CTYPE_UNION);
for( i=1; i<pass_argc; i++ ){ for( i=1; i<pass_argc; i++ ){
pass_argv[i] = argv[i-1]; pass_argv[i] = argv[i-1];
}; }
return rb_dlptr_define_data_type(pass_argc, pass_argv, self); return rb_dlptr_define_data_type(pass_argc, pass_argv, self);
} }
@ -681,9 +681,9 @@ cary2ary(void *ptr, char t, int len)
break; break;
default: default:
rb_raise(rb_eDLTypeError, "unsupported type '%c'", t); rb_raise(rb_eDLTypeError, "unsupported type '%c'", t);
}; }
return elem; return elem;
}; }
ary = rb_ary_new(); ary = rb_ary_new();
for( i=0; i < len; i++ ){ for( i=0; i < len; i++ ){
@ -718,9 +718,9 @@ cary2ary(void *ptr, char t, int len)
break; break;
default: default:
rb_raise(rb_eDLTypeError, "unsupported type '%c'", t); rb_raise(rb_eDLTypeError, "unsupported type '%c'", t);
}; }
rb_ary_push(ary, elem); rb_ary_push(ary, elem);
}; }
return ary; return ary;
} }
@ -737,17 +737,17 @@ rb_dlptr_aref(int argc, VALUE argv[], VALUE self)
if( rb_scan_args(argc, argv, "11", &key, &num) == 1 ){ if( rb_scan_args(argc, argv, "11", &key, &num) == 1 ){
num = INT2NUM(0); num = INT2NUM(0);
}; }
if( TYPE(key) == T_FIXNUM || TYPE(key) == T_BIGNUM ){ if( TYPE(key) == T_FIXNUM || TYPE(key) == T_BIGNUM ){
VALUE pass[1]; VALUE pass[1];
pass[0] = num; pass[0] = num;
return rb_dlptr_to_str(1, pass, rb_dlptr_plus(self, key)); return rb_dlptr_to_str(1, pass, rb_dlptr_plus(self, key));
}; }
if( ! (TYPE(key) == T_STRING || TYPE(key) == T_SYMBOL ) ){ if( ! (TYPE(key) == T_STRING || TYPE(key) == T_SYMBOL ) ){
rb_raise(rb_eTypeError, "the key must be a string or symbol"); rb_raise(rb_eTypeError, "the key must be a string or symbol");
}; }
id = rb_to_id(key); id = rb_to_id(key);
Data_Get_Struct(self, struct ptr_data, data); Data_Get_Struct(self, struct ptr_data, data);
@ -779,9 +779,9 @@ rb_dlptr_aref(int argc, VALUE argv[], VALUE self)
break; break;
default: default:
rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]); rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]);
}; }
return cary2ary((char *)data->ptr + offset, data->stype[i], data->ssize[i]); return cary2ary((char *)data->ptr + offset, data->stype[i], data->ssize[i]);
}; }
switch( data->stype[i] ){ switch( data->stype[i] ){
case 'I': case 'I':
offset += sizeof(int) * data->ssize[i]; offset += sizeof(int) * data->ssize[i];
@ -806,17 +806,17 @@ rb_dlptr_aref(int argc, VALUE argv[], VALUE self)
break; break;
default: default:
rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]); rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]);
}; }
}; }
break; break;
case DLPTR_CTYPE_UNION: case DLPTR_CTYPE_UNION:
for( i=0; i < data->ids_num; i++ ){ for( i=0; i < data->ids_num; i++ ){
if( data->ids[i] == id ){ if( data->ids[i] == id ){
return cary2ary((char *)data->ptr + offset, data->stype[i], data->ssize[i]); return cary2ary((char *)data->ptr + offset, data->stype[i], data->ssize[i]);
}; }
}; }
break; break;
}; /* end of switch */ } /* end of switch */
rb_raise(rb_eNameError, "undefined key `%s' for %s", rb_raise(rb_eNameError, "undefined key `%s' for %s",
rb_id2name(id), rb_class2name(CLASS_OF(self))); rb_id2name(id), rb_class2name(CLASS_OF(self)));
@ -834,7 +834,7 @@ ary2cary(char t, VALUE val, long *size)
} }
else{ else{
ptr = rb_ary2cary(t, rb_ary_new3(1, val), size); ptr = rb_ary2cary(t, rb_ary_new3(1, val), size);
}; }
return ptr; return ptr;
} }
@ -854,7 +854,7 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
val = num; val = num;
num = Qnil; num = Qnil;
break; break;
}; }
if( TYPE(key) == T_FIXNUM || TYPE(key) == T_BIGNUM ){ if( TYPE(key) == T_FIXNUM || TYPE(key) == T_BIGNUM ){
void *dst, *src; void *dst, *src;
@ -872,13 +872,13 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
long n = NUM2INT(num); long n = NUM2INT(num);
memcpy(dst, src, n < len ? n : len); memcpy(dst, src, n < len ? n : len);
if( n > len ) MEMZERO((char*)dst + len, char, n - len); if( n > len ) MEMZERO((char*)dst + len, char, n - len);
}; }
return val; return val;
}; }
if( ! (TYPE(key) == T_STRING || TYPE(key) == T_SYMBOL ) ){ if( ! (TYPE(key) == T_STRING || TYPE(key) == T_SYMBOL ) ){
rb_raise(rb_eTypeError, "the key must be a string or symbol"); rb_raise(rb_eTypeError, "the key must be a string or symbol");
}; }
id = rb_to_id(key); id = rb_to_id(key);
Data_Get_Struct(self, struct ptr_data, data); Data_Get_Struct(self, struct ptr_data, data);
@ -910,11 +910,11 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
break; break;
default: default:
rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]); rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]);
}; }
memimg = ary2cary(data->stype[i], val, &memsize); memimg = ary2cary(data->stype[i], val, &memsize);
memcpy((char *)data->ptr + offset, memimg, memsize); memcpy((char *)data->ptr + offset, memimg, memsize);
return val; return val;
}; }
switch( data->stype[i] ){ switch( data->stype[i] ){
case 'I': case 'I':
case 'i': case 'i':
@ -946,8 +946,8 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
break; break;
default: default:
rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]); rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]);
}; }
}; }
return val; return val;
/* break; */ /* break; */
case DLPTR_CTYPE_UNION: case DLPTR_CTYPE_UNION:
@ -977,14 +977,14 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
break; break;
default: default:
rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]); rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]);
}; }
memimg = ary2cary(data->stype[i], val, NULL); memimg = ary2cary(data->stype[i], val, NULL);
memcpy(data->ptr, memimg, memsize); memcpy(data->ptr, memimg, memsize);
}; }
}; }
return val; return val;
/* break; */ /* break; */
}; }
rb_raise(rb_eNameError, "undefined key `%s' for %s", rb_raise(rb_eNameError, "undefined key `%s' for %s",
rb_id2name(id), rb_class2name(CLASS_OF(self))); rb_id2name(id), rb_class2name(CLASS_OF(self)));
@ -1003,7 +1003,7 @@ rb_dlptr_size(int argc, VALUE argv[], VALUE self)
else{ else{
RDLPTR(self)->size = DLNUM2LONG(size); RDLPTR(self)->size = DLNUM2LONG(size);
return size; return size;
}; }
} }
static VALUE static VALUE

View file

@ -49,7 +49,7 @@ char2type(int ch)
return "[]"; return "[]";
case 'a': case 'a':
return "[]"; /* ?? */ return "[]"; /* ?? */
}; }
return NULL; return NULL;
} }
@ -61,13 +61,13 @@ dlsym_free(struct sym_data *data)
printf("dlsym_free(): free(data->name:%s)\n",data->name); printf("dlsym_free(): free(data->name:%s)\n",data->name);
}); });
free(data->name); free(data->name);
}; }
if( data->type ){ if( data->type ){
DEBUG_CODE({ DEBUG_CODE({
printf("dlsym_free(): free(data->type:%s)\n",data->type); printf("dlsym_free(): free(data->type:%s)\n",data->type);
}); });
free(data->type); free(data->type);
}; }
} }
VALUE VALUE
@ -79,13 +79,13 @@ rb_dlsym_new(void (*func)(), const char *name, const char *type)
if( !type || !type[0] ){ if( !type || !type[0] ){
return rb_dlptr_new((void*)func, 0, 0); return rb_dlptr_new((void*)func, 0, 0);
}; }
for( ptype = type; *ptype; ptype ++ ){ for( ptype = type; *ptype; ptype ++ ){
if( ! char2type(*ptype) ){ if( ! char2type(*ptype) ){
rb_raise(rb_eDLTypeError, "unknown type specifier '%c'", *ptype); rb_raise(rb_eDLTypeError, "unknown type specifier '%c'", *ptype);
}; }
}; }
if( func ){ if( func ){
val = Data_Make_Struct(rb_cDLSymbol, struct sym_data, 0, dlsym_free, data); val = Data_Make_Struct(rb_cDLSymbol, struct sym_data, 0, dlsym_free, data);
@ -96,12 +96,12 @@ rb_dlsym_new(void (*func)(), const char *name, const char *type)
#if !(defined(DLSTACK)) #if !(defined(DLSTACK))
if( data->len - 1 > MAX_ARG ){ if( data->len - 1 > MAX_ARG ){
rb_raise(rb_eDLError, "maximum number of arguments is %d.", MAX_ARG); rb_raise(rb_eDLError, "maximum number of arguments is %d.", MAX_ARG);
}; }
#endif #endif
} }
else{ else{
val = Qnil; val = Qnil;
}; }
return val; return val;
} }
@ -121,7 +121,7 @@ rb_dlsym2csym(VALUE val)
} }
else{ else{
rb_raise(rb_eTypeError, "DL::Symbol was expected"); rb_raise(rb_eTypeError, "DL::Symbol was expected");
}; }
return func; return func;
} }
@ -225,7 +225,7 @@ rb_dlsym_cproto(VALUE self)
} }
else{ else{
rb_str_cat2(val, "(null)"); rb_str_cat2(val, "(null)");
}; }
rb_str_cat(val, "(", 1); rb_str_cat(val, "(", 1);
while (*ptype) { while (*ptype) {
@ -244,9 +244,9 @@ rb_dlsym_cproto(VALUE self)
} }
else{ else{
rb_str_cat2(val, "(null)"); rb_str_cat2(val, "(null)");
}; }
rb_str_cat2(val, ")()"); rb_str_cat2(val, ")()");
}; }
return val; return val;
} }
@ -336,7 +336,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
}); });
if( (sym->len - 1) != argc ){ if( (sym->len - 1) != argc ){
rb_raise(rb_eArgError, "%d arguments are needed", sym->len - 1); rb_raise(rb_eArgError, "%d arguments are needed", sym->len - 1);
}; }
ftype = 0; ftype = 0;
dvals = Qnil; dvals = Qnil;
@ -368,12 +368,12 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
pval = rb_funcall(argv[i], rb_intern("to_ptr"), 0); pval = rb_funcall(argv[i], rb_intern("to_ptr"), 0);
if( !rb_obj_is_kind_of(pval, rb_cDLPtrData) ){ if( !rb_obj_is_kind_of(pval, rb_cDLPtrData) ){
rb_raise(rb_eDLTypeError, "unexpected type of argument #%d", i); rb_raise(rb_eDLTypeError, "unexpected type of argument #%d", i);
}; }
}; }
Data_Get_Struct(pval, struct ptr_data, data); Data_Get_Struct(pval, struct ptr_data, data);
ANY2P(args[i]) = DLVOIDP(data->ptr); ANY2P(args[i]) = DLVOIDP(data->ptr);
}; }
}; }
PUSH_P(ftype); PUSH_P(ftype);
break; break;
case 'a': case 'a':
@ -384,7 +384,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
} }
else{ else{
ANY2P(args[i]) = DLVOIDP(rb_ary2cary(0, argv[i], NULL)); ANY2P(args[i]) = DLVOIDP(rb_ary2cary(0, argv[i], NULL));
}; }
PUSH_P(ftype); PUSH_P(ftype);
break; break;
case 'C': case 'C':
@ -458,15 +458,15 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
else{ else{
if( TYPE(argv[i]) != T_STRING ){ if( TYPE(argv[i]) != T_STRING ){
rb_raise(rb_eDLError, "#%d must be a string",i); rb_raise(rb_eDLError, "#%d must be a string",i);
}; }
ANY2S(args[i]) = DLSTR(RSTRING(argv[i])->ptr); ANY2S(args[i]) = DLSTR(RSTRING(argv[i])->ptr);
}; }
PUSH_P(ftype); PUSH_P(ftype);
break; break;
case 's': case 's':
if( TYPE(argv[i]) != T_STRING ){ if( TYPE(argv[i]) != T_STRING ){
rb_raise(rb_eDLError, "#%d must be a string",i); rb_raise(rb_eDLError, "#%d must be a string",i);
}; }
ANY2S(args[i]) = DLSTR(dlmalloc(RSTRING(argv[i])->len + 1)); ANY2S(args[i]) = DLSTR(dlmalloc(RSTRING(argv[i])->len + 1));
memcpy((char*)(ANY2S(args[i])), RSTRING(argv[i])->ptr, RSTRING(argv[i])->len + 1); memcpy((char*)(ANY2S(args[i])), RSTRING(argv[i])->ptr, RSTRING(argv[i])->len + 1);
dtypes[i] = 's'; dtypes[i] = 's';
@ -477,8 +477,8 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
rb_raise(rb_eDLTypeError, rb_raise(rb_eDLTypeError,
"unknown type '%c' of the return value.", "unknown type '%c' of the return value.",
sym->type[i+1]); sym->type[i+1]);
}; }
}; }
switch( sym->type[0] ){ switch( sym->type[0] ){
case '0': case '0':
@ -521,7 +521,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
rb_raise(rb_eDLTypeError, rb_raise(rb_eDLTypeError,
"unknown type `%c' of the return value.", "unknown type `%c' of the return value.",
sym->type[0]); sym->type[0]);
}; }
func = sym->func; func = sym->func;
@ -601,7 +601,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
case 's': case 's':
DLSTACK_PUSH_P(ANY2S(args[i])); DLSTACK_PUSH_P(ANY2S(args[i]));
break; break;
}; }
} }
DLSTACK_END(sym->type); DLSTACK_END(sym->type);
@ -611,63 +611,63 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
{ {
void (*f)(DLSTACK_PROTO) = func; void (*f)(DLSTACK_PROTO) = func;
f(DLSTACK_ARGS); f(DLSTACK_ARGS);
}; }
break; break;
case 'P': case 'P':
case 'p': case 'p':
{ {
void * (*f)(DLSTACK_PROTO) = func; void * (*f)(DLSTACK_PROTO) = func;
ret.p = f(DLSTACK_ARGS); ret.p = f(DLSTACK_ARGS);
}; }
break; break;
case 'C': case 'C':
case 'c': case 'c':
{ {
char (*f)(DLSTACK_PROTO) = func; char (*f)(DLSTACK_PROTO) = func;
ret.c = f(DLSTACK_ARGS); ret.c = f(DLSTACK_ARGS);
}; }
break; break;
case 'H': case 'H':
case 'h': case 'h':
{ {
short (*f)(DLSTACK_PROTO) = func; short (*f)(DLSTACK_PROTO) = func;
ret.h = f(DLSTACK_ARGS); ret.h = f(DLSTACK_ARGS);
}; }
break; break;
case 'I': case 'I':
case 'i': case 'i':
{ {
int (*f)(DLSTACK_PROTO) = func; int (*f)(DLSTACK_PROTO) = func;
ret.i = f(DLSTACK_ARGS); ret.i = f(DLSTACK_ARGS);
}; }
break; break;
case 'L': case 'L':
case 'l': case 'l':
{ {
long (*f)(DLSTACK_PROTO) = func; long (*f)(DLSTACK_PROTO) = func;
ret.l = f(DLSTACK_ARGS); ret.l = f(DLSTACK_ARGS);
}; }
break; break;
case 'F': case 'F':
case 'f': case 'f':
{ {
float (*f)(DLSTACK_PROTO) = func; float (*f)(DLSTACK_PROTO) = func;
ret.f = f(DLSTACK_ARGS); ret.f = f(DLSTACK_ARGS);
}; }
break; break;
case 'D': case 'D':
case 'd': case 'd':
{ {
double (*f)(DLSTACK_PROTO) = func; double (*f)(DLSTACK_PROTO) = func;
ret.d = f(DLSTACK_ARGS); ret.d = f(DLSTACK_ARGS);
}; }
break; break;
case 'S': case 'S':
case 's': case 's':
{ {
char * (*f)(DLSTACK_PROTO) = func; char * (*f)(DLSTACK_PROTO) = func;
ret.s = f(DLSTACK_ARGS); ret.s = f(DLSTACK_ARGS);
}; }
break; break;
default: default:
FREE_ARGS; FREE_ARGS;
@ -681,7 +681,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
default: default:
FREE_ARGS; FREE_ARGS;
rb_raise(rb_eDLTypeError, "unsupported function type `%s'", sym->type); rb_raise(rb_eDLTypeError, "unsupported function type `%s'", sym->type);
}; }
#endif /* defined(DLSTACK) */ #endif /* defined(DLSTACK) */
switch( sym->type[0] ){ switch( sym->type[0] ){
@ -724,7 +724,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
} }
else{ else{
val = Qnil; val = Qnil;
}; }
break; break;
case 's': case 's':
if( ANY2S(ret) ){ if( ANY2S(ret) ){
@ -736,12 +736,12 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
} }
else{ else{
val = Qnil; val = Qnil;
}; }
break; break;
default: default:
FREE_ARGS; FREE_ARGS;
rb_raise(rb_eDLTypeError, "unknown type `%c'", sym->type[0]); rb_raise(rb_eDLTypeError, "unknown type `%c'", sym->type[0]);
}; }
dvals = rb_ary_new(); dvals = rb_ary_new();
for( i = 0; i <= sym->len - 2; i++ ){ for( i = 0; i <= sym->len - 2; i++ ){
@ -783,18 +783,18 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
char c = dtypes[i]; char c = dtypes[i];
FREE_ARGS; FREE_ARGS;
rb_raise(rb_eRuntimeError, "unknown argument type '%c'", i, c); rb_raise(rb_eRuntimeError, "unknown argument type '%c'", i, c);
}; }
}; }
} }
else{ else{
switch( sym->type[i+1] ){ switch( sym->type[i+1] ){
case 'A': case 'A':
dlfree((void*)ANY2P(args[i])); dlfree((void*)ANY2P(args[i]));
break; break;
}; }
rb_ary_push(dvals, argv[i]); rb_ary_push(dvals, argv[i]);
}; }
}; }
#undef FREE_ARGS #undef FREE_ARGS
return rb_assoc_new(val,dvals); return rb_assoc_new(val,dvals);

View file

@ -32,10 +32,6 @@ def debug(*xs)
end end
end end
print("VERSION = #{DL::VERSION}\n")
print("MAJOR_VERSION = #{DL::MAJOR_VERSION}\n")
print("MINOR_VERSION = #{DL::MINOR_VERSION}\n")
print("\n")
print("DLSTACK = #{DL::DLSTACK}\n") print("DLSTACK = #{DL::DLSTACK}\n")
print("MAX_ARG = #{DL::MAX_ARG}\n") print("MAX_ARG = #{DL::MAX_ARG}\n")
print("\n") print("\n")
@ -289,6 +285,11 @@ assert("struct!", :must,
ptr["i"] == 3 && ptr["i"] == 3 &&
ptr["l"] == 4) ptr["l"] == 4)
GC.start ptr = DL::malloc(DL::sizeof("IP"))
ptr.struct!("IP", "n", "ptr")
ptr["n"] = 10
ptr["ptr"] = nil
assert("struct!", :must, ptr["n"] == 10 && ptr["ptr"] == nil)
GC.start
printf("fail/total = #{$FAIL}/#{$TOTAL}\n") printf("fail/total = #{$FAIL}/#{$TOTAL}\n")