Patch [ruby-dev:16747] (Thanks Nakada)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ttate 2002-04-04 08:27:48 +00:00
parent b5856f738a
commit 1502ea7c0c
2 changed files with 16 additions and 22 deletions

View File

@ -323,7 +323,7 @@ c_parray(VALUE v, long *size)
case T_STRING: case T_STRING:
{ {
char *str, *src; char *str, *src;
src = StringValuePtr(e); src = RSTRING(e)->ptr;
str = dlstrdup(src); str = dlstrdup(src);
ary[i] = (void*)str; ary[i] = (void*)str;
}; };
@ -472,7 +472,7 @@ rb_dl_strdup(VALUE self, VALUE str)
void *p; void *p;
str = rb_String(str); str = rb_String(str);
return rb_dlptr_new(strdup(StringValuePtr(str)), RSTRING(str)->len, dlfree); return rb_dlptr_new(strdup(RSTRING(str)->ptr), RSTRING(str)->len, dlfree);
} }
static VALUE static VALUE
@ -482,7 +482,7 @@ rb_dl_sizeof(VALUE self, VALUE str)
} }
static VALUE static VALUE
rb_dl_callback_type(VALUE str) rb_dl_callback_type(VALUE *str)
{ {
char *type; char *type;
int len; int len;
@ -490,8 +490,8 @@ rb_dl_callback_type(VALUE str)
long ftype; long ftype;
ftype = 0; ftype = 0;
type = StringValuePtr(str); type = StringValuePtr(*str);
len = RSTRING(str)->len; len = RSTRING(*str)->len;
if( len - 1 > MAX_CBARG ){ if( len - 1 > MAX_CBARG ){
rb_raise(rb_eDLError, "maximum number of the argument is %d.", MAX_CBARG); rb_raise(rb_eDLError, "maximum number of the argument is %d.", MAX_CBARG);
@ -567,7 +567,7 @@ rb_dl_set_callback(int argc, VALUE argv[], VALUE self)
rb_bug("rb_dl_set_callback"); rb_bug("rb_dl_set_callback");
}; };
key = rb_dl_callback_type(types); key = rb_dl_callback_type(&types);
entry = rb_hash_aref(DLFuncTable, key); entry = rb_hash_aref(DLFuncTable, key);
if( entry == Qnil ){ if( entry == Qnil ){
entry = rb_hash_new(); entry = rb_hash_new();
@ -578,7 +578,7 @@ rb_dl_set_callback(int argc, VALUE argv[], VALUE self)
if( func ){ if( func ){
rb_hash_aset(entry, num, proc); rb_hash_aset(entry, num, proc);
snprintf(func_name, 1023, "rb_dl_func%d_%d", NUM2INT(key), NUM2INT(num)); snprintf(func_name, 1023, "rb_dl_func%d_%d", NUM2INT(key), NUM2INT(num));
return rb_dlsym_new(func, func_name, StringValuePtr(types)); return rb_dlsym_new(func, func_name, RSTRING(types)->ptr);
} }
else{ else{
return Qnil; return Qnil;
@ -591,7 +591,7 @@ rb_dl_get_callback(VALUE self, VALUE types, VALUE num)
VALUE key; VALUE key;
VALUE entry; VALUE entry;
key = rb_dl_callback_type(types); key = rb_dl_callback_type(&types);
entry = rb_hash_aref(DLFuncTable, key); entry = rb_hash_aref(DLFuncTable, key);
if( entry == Qnil ){ if( entry == Qnil ){
return Qnil; return Qnil;

View File

@ -142,16 +142,7 @@ rb_dlsym_s_new(int argc, VALUE argv[], VALUE self)
void *saddr; void *saddr;
const char *sname, *stype; const char *sname, *stype;
switch( rb_scan_args(argc, argv, "12", &addr, &name, &type) ){ rb_scan_args(argc, argv, "12", &addr, &name, &type);
case 3:
break;
case 2:
type = Qnil;
break;
case 1:
name = Qnil;
type = Qnil;
};
saddr = (void*)(DLNUM2LONG(rb_Integer(addr))); saddr = (void*)(DLNUM2LONG(rb_Integer(addr)));
sname = NIL_P(name) ? NULL : StringValuePtr(name); sname = NIL_P(name) ? NULL : StringValuePtr(name);
@ -270,7 +261,7 @@ rb_dlsym_inspect(VALUE self)
str = dlmalloc(str_size); str = dlmalloc(str_size);
snprintf(str, str_size - 1, snprintf(str, str_size - 1,
"#<DL::Symbol:0x%x func=0x%x '%s'>", "#<DL::Symbol:0x%x func=0x%x '%s'>",
sym, sym->func, StringValuePtr(proto)); sym, sym->func, RSTRING(proto)->len);
val = rb_tainted_str_new2(str); val = rb_tainted_str_new2(str);
dlfree(str); dlfree(str);
@ -418,16 +409,19 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
ANY2S(args[i]) = DLSTR(0); ANY2S(args[i]) = DLSTR(0);
} }
else{ else{
ANY2S(args[i]) = DLSTR(StringValuePtr(argv[i])); if( TYPE(argv[i]) != T_STRING ){
raise(rb_eDLError, "#%d must be a string",i);
};
ANY2S(args[i]) = DLSTR(argv[i]);
}; };
PUSH_P(ftype); PUSH_P(ftype);
break; break;
case 's': case 's':
if( argv[i] == Qnil ){ if( TYPE(argv[i]) != T_STRING ){
raise(rb_eDLError, "#%d must be a string",i); 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])), StringValuePtr(argv[i]), 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';
PUSH_P(ftype); PUSH_P(ftype);
break; break;