summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-04 08:27:48 +0000
committerttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-04 08:27:48 +0000
commit1502ea7c0c91d1384caeefee46b61f8e2fd1567f (patch)
tree4495286806b9985027b917cba43087c4f31c44d9
parentb5856f738a1dc9e89f9cbc492192c8668780e1c3 (diff)
Patch [ruby-dev:16747] (Thanks Nakada)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/dl/dl.c16
-rw-r--r--ext/dl/sym.c22
2 files changed, 16 insertions, 22 deletions
diff --git a/ext/dl/dl.c b/ext/dl/dl.c
index f9b5a145cbd..0eda4926d7a 100644
--- a/ext/dl/dl.c
+++ b/ext/dl/dl.c
@@ -323,7 +323,7 @@ c_parray(VALUE v, long *size)
case T_STRING:
{
char *str, *src;
- src = StringValuePtr(e);
+ src = RSTRING(e)->ptr;
str = dlstrdup(src);
ary[i] = (void*)str;
};
@@ -472,7 +472,7 @@ rb_dl_strdup(VALUE self, VALUE str)
void *p;
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
@@ -482,7 +482,7 @@ rb_dl_sizeof(VALUE self, VALUE str)
}
static VALUE
-rb_dl_callback_type(VALUE str)
+rb_dl_callback_type(VALUE *str)
{
char *type;
int len;
@@ -490,8 +490,8 @@ rb_dl_callback_type(VALUE str)
long ftype;
ftype = 0;
- type = StringValuePtr(str);
- len = RSTRING(str)->len;
+ type = StringValuePtr(*str);
+ len = RSTRING(*str)->len;
if( len - 1 > 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");
};
- key = rb_dl_callback_type(types);
+ key = rb_dl_callback_type(&types);
entry = rb_hash_aref(DLFuncTable, key);
if( entry == Qnil ){
entry = rb_hash_new();
@@ -578,7 +578,7 @@ rb_dl_set_callback(int argc, VALUE argv[], VALUE self)
if( func ){
rb_hash_aset(entry, num, proc);
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{
return Qnil;
@@ -591,7 +591,7 @@ rb_dl_get_callback(VALUE self, VALUE types, VALUE num)
VALUE key;
VALUE entry;
- key = rb_dl_callback_type(types);
+ key = rb_dl_callback_type(&types);
entry = rb_hash_aref(DLFuncTable, key);
if( entry == Qnil ){
return Qnil;
diff --git a/ext/dl/sym.c b/ext/dl/sym.c
index f383d1e786b..48b9dcfb27c 100644
--- a/ext/dl/sym.c
+++ b/ext/dl/sym.c
@@ -142,16 +142,7 @@ rb_dlsym_s_new(int argc, VALUE argv[], VALUE self)
void *saddr;
const char *sname, *stype;
- switch( rb_scan_args(argc, argv, "12", &addr, &name, &type) ){
- case 3:
- break;
- case 2:
- type = Qnil;
- break;
- case 1:
- name = Qnil;
- type = Qnil;
- };
+ rb_scan_args(argc, argv, "12", &addr, &name, &type);
saddr = (void*)(DLNUM2LONG(rb_Integer(addr)));
sname = NIL_P(name) ? NULL : StringValuePtr(name);
@@ -270,7 +261,7 @@ rb_dlsym_inspect(VALUE self)
str = dlmalloc(str_size);
snprintf(str, str_size - 1,
"#<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);
dlfree(str);
@@ -418,16 +409,19 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
ANY2S(args[i]) = DLSTR(0);
}
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);
break;
case 's':
- if( argv[i] == Qnil ){
+ if( TYPE(argv[i]) != T_STRING ){
raise(rb_eDLError, "#%d must be a string",i);
};
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';
PUSH_P(ftype);
break;