mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Do no use return values from mrb_ensure_ functions.
They return the checking argument without modification, so the values are already there. Maybe we should change the return type to `void` but keep them unchanged for compatibility.
This commit is contained in:
@@ -116,14 +116,14 @@ static mrb_value
|
||||
mrb_file_s_unlink(mrb_state *mrb, mrb_value obj)
|
||||
{
|
||||
const mrb_value *argv;
|
||||
mrb_value pathv;
|
||||
mrb_int argc, i;
|
||||
char *path;
|
||||
|
||||
mrb_get_args(mrb, "*", &argv, &argc);
|
||||
for (i = 0; i < argc; i++) {
|
||||
const char *utf8_path;
|
||||
pathv = mrb_ensure_string_type(mrb, argv[i]);
|
||||
mrb_value pathv = argv[i];
|
||||
mrb_ensure_string_type(mrb, pathv);
|
||||
utf8_path = RSTRING_CSTR(mrb, pathv);
|
||||
path = mrb_locale_from_utf8(utf8_path, -1);
|
||||
if (UNLINK(path) < 0) {
|
||||
|
||||
@@ -202,7 +202,8 @@ mrb_f_hash(mrb_state *mrb, mrb_value self)
|
||||
if (mrb_nil_p(arg) || (mrb_array_p(arg) && RARRAY_LEN(arg) == 0)) {
|
||||
return mrb_hash_new(mrb);
|
||||
}
|
||||
return mrb_ensure_hash_type(mrb, arg);
|
||||
mrb_ensure_hash_type(mrb, arg);
|
||||
return arg;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -195,14 +195,14 @@ static mrb_value
|
||||
mrb_str_start_with(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
const mrb_value *argv;
|
||||
mrb_value sub;
|
||||
mrb_int argc, i;
|
||||
mrb_get_args(mrb, "*", &argv, &argc);
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
size_t len_l, len_r;
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
sub = mrb_ensure_string_type(mrb, argv[i]);
|
||||
mrb_value sub = argv[i];
|
||||
mrb_ensure_string_type(mrb, sub);
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
len_l = RSTRING_LEN(self);
|
||||
len_r = RSTRING_LEN(sub);
|
||||
@@ -225,14 +225,14 @@ static mrb_value
|
||||
mrb_str_end_with(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
const mrb_value *argv;
|
||||
mrb_value sub;
|
||||
mrb_int argc, i;
|
||||
mrb_get_args(mrb, "*", &argv, &argc);
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
size_t len_l, len_r;
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
sub = mrb_ensure_string_type(mrb, argv[i]);
|
||||
mrb_value sub = argv[i];
|
||||
mrb_ensure_string_type(mrb, sub);
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
len_l = RSTRING_LEN(self);
|
||||
len_r = RSTRING_LEN(sub);
|
||||
|
||||
+1
-1
@@ -2379,7 +2379,7 @@ mrb_mod_const_get(mrb_state *mrb, mrb_value mod)
|
||||
}
|
||||
|
||||
/* const get with class path string */
|
||||
path = mrb_ensure_string_type(mrb, path);
|
||||
mrb_ensure_string_type(mrb, path);
|
||||
ptr = RSTRING_PTR(path);
|
||||
len = RSTRING_LEN(path);
|
||||
off = 0;
|
||||
|
||||
@@ -2671,7 +2671,8 @@ RETRY_TRY_BLOCK:
|
||||
int i;
|
||||
int lim = a+b*2+1;
|
||||
|
||||
hash = mrb_ensure_hash_type(mrb, regs[a]);
|
||||
hash = regs[a];
|
||||
mrb_ensure_hash_type(mrb, hash);
|
||||
for (i=a+1; i<lim; i+=2) {
|
||||
mrb_hash_set(mrb, hash, regs[i], regs[i+1]);
|
||||
}
|
||||
@@ -2679,8 +2680,9 @@ RETRY_TRY_BLOCK:
|
||||
NEXT;
|
||||
}
|
||||
CASE(OP_HASHCAT, B) {
|
||||
mrb_value hash = mrb_ensure_hash_type(mrb, regs[a]);
|
||||
mrb_value hash = regs[a];
|
||||
|
||||
mrb_ensure_hash_type(mrb, hash);
|
||||
mrb_hash_merge(mrb, hash, regs[a+1]);
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
NEXT;
|
||||
|
||||
Reference in New Issue
Block a user