diff --git a/ext/dl/dl.c b/ext/dl/dl.c index a05453bb1f..5a492b577b 100644 --- a/ext/dl/dl.c +++ b/ext/dl/dl.c @@ -175,7 +175,7 @@ dlsizeof(const char *cstr) } else{ dlen = 0; - }; + } switch( cstr[i] ){ case 'I': @@ -215,9 +215,9 @@ dlsizeof(const char *cstr) default: rb_raise(rb_eDLTypeError, "unexpected type '%c'", cstr[i]); break; - }; + } i += dlen; - }; + } return size; } @@ -244,8 +244,8 @@ c_farray(VALUE v, long *size) default: rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); break; - }; - }; + } + } return ary; } @@ -272,8 +272,8 @@ c_darray(VALUE v, long *size) default: rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); break; - }; - }; + } + } return ary; } @@ -301,8 +301,8 @@ c_larray(VALUE v, long *size) default: rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); break; - }; - }; + } + } return ary; } @@ -330,8 +330,8 @@ c_iarray(VALUE v, long *size) default: rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); break; - }; - }; + } + } return ary; } @@ -359,8 +359,8 @@ c_harray(VALUE v, long *size) default: rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); break; - }; - }; + } + } return ary; } @@ -388,8 +388,8 @@ c_carray(VALUE v, long *size) default: rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); break; - }; - }; + } + } return ary; } @@ -413,7 +413,7 @@ c_parray(VALUE v, long *size) src = RSTRING(e)->ptr; str = dlstrdup(src); ary[i] = (void*)str; - }; + } break; case T_NIL: ary[i] = NULL; @@ -426,13 +426,13 @@ c_parray(VALUE v, long *size) } else{ rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); - }; + } break; default: rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i); break; - }; - }; + } + } return ary; } @@ -445,16 +445,16 @@ rb_ary2cary(char t, VALUE v, long *size) if( TYPE(v) != T_ARRAY ){ rb_raise(rb_eDLTypeError, "an array is expected."); - }; + } len = RARRAY(v)->len; if( len == 0 ){ return NULL; - }; + } if( !size ){ size = ALLOCA_N(long,1); - }; + } val0 = rb_ary_entry(v,0); switch( TYPE(val0) ){ @@ -471,7 +471,7 @@ rb_ary2cary(char t, VALUE v, long *size) return (void*)c_larray(v,size); default: rb_raise(rb_eDLTypeError, "type mismatch"); - }; + } case T_STRING: return (void*)c_parray(v,size); case T_FLOAT: @@ -480,18 +480,18 @@ rb_ary2cary(char t, VALUE v, long *size) return (void*)c_farray(v,size); case 'D': case 'd': case 0: return (void*)c_darray(v,size); - }; + } rb_raise(rb_eDLTypeError, "type mismatch"); case T_DATA: if( rb_obj_is_kind_of(val0, rb_cDLPtrData) ){ return (void*)c_parray(v,size); - }; + } rb_raise(rb_eDLTypeError, "type mismatch"); case T_NIL: return (void*)c_parray(v, size); default: rb_raise(rb_eDLTypeError, "unsupported type"); - }; + } } VALUE @@ -521,7 +521,7 @@ rb_ary_to_ptr(int argc, VALUE argv[], VALUE self) case 0: ptr = rb_ary2cary(0, self, &size); break; - }; + } return ptr ? rb_dlptr_new(ptr, size, dlfree) : Qnil; } @@ -535,7 +535,7 @@ rb_io_to_ptr(VALUE self) fp = fptr->f; return fp ? rb_dlptr_new(fp, sizeof(FILE), 0) : Qnil; -}; +} VALUE 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_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, "DLSTACK", rb_tainted_str_new2(DLSTACK_METHOD)); diff --git a/ext/dl/dl.h b/ext/dl/dl.h index 19ec859f6a..c390e18bbb 100644 --- a/ext/dl/dl.h +++ b/ext/dl/dl.h @@ -8,11 +8,6 @@ #include #include -#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) # include # /* some stranger systems may not define all of these */ diff --git a/ext/dl/handle.c b/ext/dl/handle.c index 4b0a129793..ea3b98b3c6 100644 --- a/ext/dl/handle.c +++ b/ext/dl/handle.c @@ -12,7 +12,7 @@ dlhandle_free(struct dl_handle *dlhandle) { if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){ dlclose(dlhandle->ptr); - }; + } } VALUE @@ -61,18 +61,18 @@ rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self) break; default: rb_bug("rb_dlhandle_new"); - }; + } ptr = dlopen(clib, cflag); #if defined(HAVE_DLERROR) if( (err = dlerror()) ){ rb_raise(rb_eRuntimeError, err); - }; + } #else if( !ptr ){ err = dlerror(); rb_raise(rb_eRuntimeError, err); - }; + } #endif Data_Get_Struct(self, struct dl_handle, dlhandle); 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() ){ rb_ensure(rb_yield, self, rb_dlhandle_close, self); - }; + } return Qnil; } @@ -146,7 +146,7 @@ rb_dlhandle_sym(int argc, VALUE argv[], VALUE self) } else{ stype = NULL; - }; + } if( sym == Qnil ){ #if defined(RTLD_NEXT) @@ -157,7 +157,7 @@ rb_dlhandle_sym(int argc, VALUE argv[], VALUE self) } else{ name = StringValuePtr(sym); - }; + } Data_Get_Struct(self, struct dl_handle, dlhandle); @@ -189,12 +189,12 @@ rb_dlhandle_sym(int argc, VALUE argv[], VALUE self) #endif { rb_raise(rb_eRuntimeError, "Unknown symbol \"%sA\".", name); - }; + } } #else rb_raise(rb_eRuntimeError, "Unknown symbol \"%s\".", name); #endif - }; + } val = rb_dlsym_new(func, name, stype); return val; diff --git a/ext/dl/mkcall.rb b/ext/dl/mkcall.rb index dad101744b..6a85570152 100644 --- a/ext/dl/mkcall.rb +++ b/ext/dl/mkcall.rb @@ -5,12 +5,6 @@ $:.unshift File.dirname(__FILE__) require 'type' require 'dlconfig' -$int_eq_long = try_run(<ptr:0x%x)\n",data->free,data->ptr); }); (*(data->free))(data->ptr); - }; - }; + } + } if( data->stype ) dlfree(data->stype); if( data->ssize ) dlfree(data->ssize); if( data->ids ) dlfree(data->ids); @@ -108,12 +108,12 @@ rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func) if( func ){ Data_Get_Struct(val, struct ptr_data, data); data->free = func; - }; - }; + } + } } else{ val = Qnil; - }; + } return val; } @@ -149,7 +149,7 @@ rb_dlptr2cptr(VALUE val) } else{ rb_raise(rb_eTypeError, "DL::PtrData was expected"); - }; + } return ptr; } @@ -346,12 +346,12 @@ rb_dlptr_to_array(int argc, VALUE argv[], VALUE self) } else{ n = 0; - }; - }; + } + } break; default: rb_bug("rb_dlptr_to_array"); - }; + } ary = rb_ary_new(); @@ -382,8 +382,8 @@ rb_dlptr_to_array(int argc, VALUE argv[], VALUE self) } else{ rb_ary_push(ary, Qnil); - }; - }; + } + } break; case 's': { @@ -394,8 +394,8 @@ rb_dlptr_to_array(int argc, VALUE argv[], VALUE self) } else{ rb_ary_push(ary, Qnil); - }; - }; + } + } break; case 'P': 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_dlptr_new(((void**)(data->ptr))[i],0,dlfree)); break; - }; - }; + } + } return ary; } @@ -429,7 +429,7 @@ rb_dlptr_to_s(int argc, VALUE argv[], VALUE self) break; default: rb_bug("rb_dlptr_to_s"); - }; + } return val; } @@ -452,7 +452,7 @@ rb_dlptr_to_str(int argc, VALUE argv[], VALUE self) break; default: rb_bug("rb_dlptr_to_str"); - }; + } return val; } @@ -533,17 +533,17 @@ rb_dlptr_define_data_type(int argc, VALUE argv[], VALUE self) if( data->stype ){ dlfree(data->stype); data->stype = NULL; - }; + } if( data->ids ){ dlfree(data->ids); data->ids = NULL; - }; + } return Qnil; } else{ rb_raise(rb_eArgError, "wrong arguments"); - }; - }; + } + } t = NUM2INT(data_type); StringValue(type); @@ -553,8 +553,8 @@ rb_dlptr_define_data_type(int argc, VALUE argv[], VALUE self) vid = rb_ary_entry(rest,i); if( !(TYPE(vid)==T_STRING || TYPE(vid)==T_SYMBOL) ){ rb_raise(rb_eTypeError, "#%d must be a string or symbol", i + 2); - }; - }; + } + } data->ctype = t; data->slen = num; @@ -583,12 +583,12 @@ rb_dlptr_define_data_type(int argc, VALUE argv[], VALUE self) } else{ data->ssize[i] = 1; - }; - }; + } + } if( *ctype ){ rb_raise(rb_eArgError, "too few/many arguments"); - }; + } if( !data->size ) 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); for( i=1; istype[i]); - }; + } return cary2ary((char *)data->ptr + offset, data->stype[i], data->ssize[i]); - }; + } switch( data->stype[i] ){ case 'I': offset += sizeof(int) * data->ssize[i]; @@ -806,17 +806,17 @@ rb_dlptr_aref(int argc, VALUE argv[], VALUE self) break; default: rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]); - }; - }; + } + } break; case DLPTR_CTYPE_UNION: for( i=0; i < data->ids_num; i++ ){ if( data->ids[i] == id ){ return cary2ary((char *)data->ptr + offset, data->stype[i], data->ssize[i]); - }; - }; + } + } break; - }; /* end of switch */ + } /* end of switch */ rb_raise(rb_eNameError, "undefined key `%s' for %s", rb_id2name(id), rb_class2name(CLASS_OF(self))); @@ -834,7 +834,7 @@ ary2cary(char t, VALUE val, long *size) } else{ ptr = rb_ary2cary(t, rb_ary_new3(1, val), size); - }; + } return ptr; } @@ -854,7 +854,7 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self) val = num; num = Qnil; break; - }; + } if( TYPE(key) == T_FIXNUM || TYPE(key) == T_BIGNUM ){ void *dst, *src; @@ -872,13 +872,13 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self) long n = NUM2INT(num); memcpy(dst, src, n < len ? n : len); if( n > len ) MEMZERO((char*)dst + len, char, n - len); - }; + } return val; - }; + } if( ! (TYPE(key) == T_STRING || TYPE(key) == T_SYMBOL ) ){ rb_raise(rb_eTypeError, "the key must be a string or symbol"); - }; + } id = rb_to_id(key); Data_Get_Struct(self, struct ptr_data, data); @@ -910,11 +910,11 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self) break; default: rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]); - }; + } memimg = ary2cary(data->stype[i], val, &memsize); memcpy((char *)data->ptr + offset, memimg, memsize); return val; - }; + } switch( data->stype[i] ){ case 'I': case 'i': @@ -946,8 +946,8 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self) break; default: rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]); - }; - }; + } + } return val; /* break; */ case DLPTR_CTYPE_UNION: @@ -977,14 +977,14 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self) break; default: rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]); - }; + } memimg = ary2cary(data->stype[i], val, NULL); memcpy(data->ptr, memimg, memsize); - }; - }; + } + } return val; /* break; */ - }; + } rb_raise(rb_eNameError, "undefined key `%s' for %s", rb_id2name(id), rb_class2name(CLASS_OF(self))); @@ -1003,7 +1003,7 @@ rb_dlptr_size(int argc, VALUE argv[], VALUE self) else{ RDLPTR(self)->size = DLNUM2LONG(size); return size; - }; + } } static VALUE diff --git a/ext/dl/sym.c b/ext/dl/sym.c index 7531c7969f..7868f07411 100644 --- a/ext/dl/sym.c +++ b/ext/dl/sym.c @@ -49,7 +49,7 @@ char2type(int ch) return "[]"; case 'a': return "[]"; /* ?? */ - }; + } return NULL; } @@ -61,13 +61,13 @@ dlsym_free(struct sym_data *data) printf("dlsym_free(): free(data->name:%s)\n",data->name); }); free(data->name); - }; + } if( data->type ){ DEBUG_CODE({ printf("dlsym_free(): free(data->type:%s)\n",data->type); }); free(data->type); - }; + } } VALUE @@ -79,13 +79,13 @@ rb_dlsym_new(void (*func)(), const char *name, const char *type) if( !type || !type[0] ){ return rb_dlptr_new((void*)func, 0, 0); - }; + } for( ptype = type; *ptype; ptype ++ ){ if( ! char2type(*ptype) ){ rb_raise(rb_eDLTypeError, "unknown type specifier '%c'", *ptype); - }; - }; + } + } if( func ){ 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( data->len - 1 > MAX_ARG ){ rb_raise(rb_eDLError, "maximum number of arguments is %d.", MAX_ARG); - }; + } #endif } else{ val = Qnil; - }; + } return val; } @@ -121,7 +121,7 @@ rb_dlsym2csym(VALUE val) } else{ rb_raise(rb_eTypeError, "DL::Symbol was expected"); - }; + } return func; } @@ -225,7 +225,7 @@ rb_dlsym_cproto(VALUE self) } else{ rb_str_cat2(val, "(null)"); - }; + } rb_str_cat(val, "(", 1); while (*ptype) { @@ -244,9 +244,9 @@ rb_dlsym_cproto(VALUE self) } else{ rb_str_cat2(val, "(null)"); - }; + } rb_str_cat2(val, ")()"); - }; + } return val; } @@ -336,7 +336,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self) }); if( (sym->len - 1) != argc ){ rb_raise(rb_eArgError, "%d arguments are needed", sym->len - 1); - }; + } ftype = 0; 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); if( !rb_obj_is_kind_of(pval, rb_cDLPtrData) ){ rb_raise(rb_eDLTypeError, "unexpected type of argument #%d", i); - }; - }; + } + } Data_Get_Struct(pval, struct ptr_data, data); ANY2P(args[i]) = DLVOIDP(data->ptr); - }; - }; + } + } PUSH_P(ftype); break; case 'a': @@ -384,7 +384,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self) } else{ ANY2P(args[i]) = DLVOIDP(rb_ary2cary(0, argv[i], NULL)); - }; + } PUSH_P(ftype); break; case 'C': @@ -458,15 +458,15 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self) else{ if( TYPE(argv[i]) != T_STRING ){ rb_raise(rb_eDLError, "#%d must be a string",i); - }; + } ANY2S(args[i]) = DLSTR(RSTRING(argv[i])->ptr); - }; + } PUSH_P(ftype); break; case 's': if( TYPE(argv[i]) != T_STRING ){ rb_raise(rb_eDLError, "#%d must be a string",i); - }; + } ANY2S(args[i]) = DLSTR(dlmalloc(RSTRING(argv[i])->len + 1)); memcpy((char*)(ANY2S(args[i])), RSTRING(argv[i])->ptr, RSTRING(argv[i])->len + 1); dtypes[i] = 's'; @@ -477,8 +477,8 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self) rb_raise(rb_eDLTypeError, "unknown type '%c' of the return value.", sym->type[i+1]); - }; - }; + } + } switch( sym->type[0] ){ case '0': @@ -521,7 +521,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self) rb_raise(rb_eDLTypeError, "unknown type `%c' of the return value.", sym->type[0]); - }; + } func = sym->func; @@ -601,7 +601,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self) case 's': DLSTACK_PUSH_P(ANY2S(args[i])); break; - }; + } } DLSTACK_END(sym->type); @@ -611,63 +611,63 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self) { void (*f)(DLSTACK_PROTO) = func; f(DLSTACK_ARGS); - }; + } break; case 'P': case 'p': { void * (*f)(DLSTACK_PROTO) = func; ret.p = f(DLSTACK_ARGS); - }; + } break; case 'C': case 'c': { char (*f)(DLSTACK_PROTO) = func; ret.c = f(DLSTACK_ARGS); - }; + } break; case 'H': case 'h': { short (*f)(DLSTACK_PROTO) = func; ret.h = f(DLSTACK_ARGS); - }; + } break; case 'I': case 'i': { int (*f)(DLSTACK_PROTO) = func; ret.i = f(DLSTACK_ARGS); - }; + } break; case 'L': case 'l': { long (*f)(DLSTACK_PROTO) = func; ret.l = f(DLSTACK_ARGS); - }; + } break; case 'F': case 'f': { float (*f)(DLSTACK_PROTO) = func; ret.f = f(DLSTACK_ARGS); - }; + } break; case 'D': case 'd': { double (*f)(DLSTACK_PROTO) = func; ret.d = f(DLSTACK_ARGS); - }; + } break; case 'S': case 's': { char * (*f)(DLSTACK_PROTO) = func; ret.s = f(DLSTACK_ARGS); - }; + } break; default: FREE_ARGS; @@ -681,7 +681,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self) default: FREE_ARGS; rb_raise(rb_eDLTypeError, "unsupported function type `%s'", sym->type); - }; + } #endif /* defined(DLSTACK) */ switch( sym->type[0] ){ @@ -724,7 +724,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self) } else{ val = Qnil; - }; + } break; case 's': if( ANY2S(ret) ){ @@ -736,12 +736,12 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self) } else{ val = Qnil; - }; + } break; default: FREE_ARGS; rb_raise(rb_eDLTypeError, "unknown type `%c'", sym->type[0]); - }; + } dvals = rb_ary_new(); 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]; FREE_ARGS; rb_raise(rb_eRuntimeError, "unknown argument type '%c'", i, c); - }; - }; + } + } } else{ switch( sym->type[i+1] ){ case 'A': dlfree((void*)ANY2P(args[i])); break; - }; + } rb_ary_push(dvals, argv[i]); - }; - }; + } + } #undef FREE_ARGS return rb_assoc_new(val,dvals); diff --git a/ext/dl/test/test.rb b/ext/dl/test/test.rb index 3e124783fa..52be04699f 100644 --- a/ext/dl/test/test.rb +++ b/ext/dl/test/test.rb @@ -32,10 +32,6 @@ def debug(*xs) 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("MAX_ARG = #{DL::MAX_ARG}\n") print("\n") @@ -289,6 +285,11 @@ assert("struct!", :must, ptr["i"] == 3 && 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")