diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/array.c | 7 | ||||
| -rw-r--r-- | src/class.c | 5 | ||||
| -rw-r--r-- | src/error.c | 16 | ||||
| -rw-r--r-- | src/hash.c | 2 | ||||
| -rw-r--r-- | src/string.c | 2 | ||||
| -rw-r--r-- | src/value_array.h | 27 | ||||
| -rw-r--r-- | src/variable.c | 4 | ||||
| -rw-r--r-- | src/vm.c | 22 |
8 files changed, 47 insertions, 38 deletions
diff --git a/src/array.c b/src/array.c index bfdb1bb97..61b27a678 100644 --- a/src/array.c +++ b/src/array.c @@ -9,6 +9,7 @@ #include <string.h> #include "mruby/string.h" #include "mruby/class.h" +#include "value_array.h" /* SIZE_MAX is not supported by VC++. */ #ifndef SIZE_MAX @@ -519,7 +520,7 @@ mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item) ary_modify(mrb, a); if (a->aux.capa < a->len + 1) ary_expand_capa(mrb, a, a->len + 1); - memmove(a->ptr + 1, a->ptr, sizeof(mrb_value)*a->len); + value_move(a->ptr + 1, a->ptr, a->len); a->ptr[0] = item; } a->len++; @@ -546,7 +547,7 @@ mrb_ary_unshift_m(mrb_state *mrb, mrb_value self) if (len == 0) return self; if (a->aux.capa < a->len + len) ary_expand_capa(mrb, a, a->len + len); - memmove(a->ptr + len, a->ptr, sizeof(mrb_value)*a->len); + value_move(a->ptr + len, a->ptr, a->len); } array_copy(a->ptr, vals, len); a->len += len; @@ -631,7 +632,7 @@ mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_val ary_fill_with_nil(a->ptr + a->len, (int)(head - a->len)); } else if (head < a->len) { - memmove(a->ptr + head + argc, a->ptr + tail, sizeof(mrb_value)*(a->len - tail)); + value_move(a->ptr + head + argc, a->ptr + tail, a->len - tail); } for(i = 0; i < argc; i++) { diff --git a/src/class.c b/src/class.c index 63b9b39da..da898383d 100644 --- a/src/class.c +++ b/src/class.c @@ -1354,7 +1354,7 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass) mrb_value s = mrb_str_new(mrb, "#<", 2); mrb_value v = mrb_iv_get(mrb, klass, mrb_intern2(mrb, "__attached__", 12)); - mrb_str_cat2(mrb, s, "Class:"); + mrb_str_cat(mrb, s, "Class:", 6); switch (mrb_type(v)) { case MRB_TT_CLASS: case MRB_TT_MODULE: @@ -1365,7 +1365,7 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass) mrb_str_append(mrb, s, mrb_any_to_s(mrb, v)); break; } - mrb_str_cat2(mrb, s, ">"); + mrb_str_cat(mrb, s, ">", 1); return s; } @@ -1803,6 +1803,7 @@ mrb_init_class(mrb_state *mrb) mrb_define_method(mrb, cls, "new", mrb_instance_new, ARGS_ANY()); /* 15.2.3.3.3 */ mrb_define_method(mrb, cls, "inherited", mrb_bob_init, ARGS_REQ(1)); + MRB_SET_INSTANCE_TT(mod, MRB_TT_MODULE); mrb_define_method(mrb, mod, "class_variable_defined?", mrb_mod_cvar_defined, ARGS_REQ(1)); /* 15.2.2.4.16 */ mrb_define_method(mrb, mod, "class_variable_get", mrb_mod_cvar_get, ARGS_REQ(1)); /* 15.2.2.4.17 */ mrb_define_method(mrb, mod, "class_variable_set", mrb_mod_cvar_set, ARGS_REQ(2)); /* 15.2.2.4.18 */ diff --git a/src/error.c b/src/error.c index 7cb6b53ef..f46887465 100644 --- a/src/error.c +++ b/src/error.c @@ -129,26 +129,26 @@ exc_inspect(mrb_state *mrb, mrb_value exc) if (!mrb_nil_p(file) && !mrb_nil_p(line)) { str = file; - mrb_str_cat2(mrb, str, ":"); + mrb_str_cat(mrb, str, ":", 1); mrb_str_append(mrb, str, line); - mrb_str_cat2(mrb, str, ": "); + mrb_str_cat(mrb, str, ": ", 2); if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) { mrb_str_append(mrb, str, mesg); - mrb_str_cat2(mrb, str, " ("); + mrb_str_cat(mrb, str, " (", 2); } - mrb_str_cat2(mrb, str, mrb_obj_classname(mrb, exc)); + mrb_str_cat_cstr(mrb, str, mrb_obj_classname(mrb, exc)); if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) { - mrb_str_cat2(mrb, str, ")"); + mrb_str_cat(mrb, str, ")", 1); } } else { str = mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, exc)); if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) { - mrb_str_cat2(mrb, str, ": "); + mrb_str_cat(mrb, str, ": ", 2); mrb_str_append(mrb, str, mesg); } else { - mrb_str_cat2(mrb, str, ": "); - mrb_str_cat2(mrb, str, mrb_obj_classname(mrb, exc)); + mrb_str_cat(mrb, str, ": ", 2); + mrb_str_cat_cstr(mrb, str, mrb_obj_classname(mrb, exc)); } } return str; diff --git a/src/hash.c b/src/hash.c index 6976530e1..8de7b55c8 100644 --- a/src/hash.c +++ b/src/hash.c @@ -894,7 +894,7 @@ inspect_hash(mrb_state *mrb, mrb_value hash, int recur) ai = mrb_gc_arena_save(mrb); - if (RSTRING_LEN(str) > 1) mrb_str_cat2(mrb, str, ", "); + if (RSTRING_LEN(str) > 1) mrb_str_cat(mrb, str, ", ", 2); str2 = mrb_inspect(mrb, kh_key(h,k)); mrb_str_append(mrb, str, str2); diff --git a/src/string.c b/src/string.c index 97d53cd6c..165cdbccd 100644 --- a/src/string.c +++ b/src/string.c @@ -2548,7 +2548,7 @@ mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, mrb_int len) } mrb_value -mrb_str_cat2(mrb_state *mrb, mrb_value str, const char *ptr) +mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *ptr) { return mrb_str_cat(mrb, str, ptr, strlen(ptr)); } diff --git a/src/value_array.h b/src/value_array.h new file mode 100644 index 000000000..cabd2426d --- /dev/null +++ b/src/value_array.h @@ -0,0 +1,27 @@ +#ifndef MRB_VALUE_ARRAY_H__ +#define MRB_VALUE_ARRAY_H__ + +#include "mruby.h" + +static inline void +value_move(mrb_value *s1, const mrb_value *s2, size_t n) +{ + if (s1 > s2 && s1 < s2 + n) + { + s1 += n; + s2 += n; + while (n-- > 0) { + *--s1 = *--s2; + } + } + else if (s1 != s2) { + while (n-- > 0) { + *s1++ = *s2++; + } + } + else { + /* nothing to do. */ + } +} + +#endif /* MRB_VALUE_ARRAY_H__ */ diff --git a/src/variable.c b/src/variable.c index 4345f49a7..df89397d7 100644 --- a/src/variable.c +++ b/src/variable.c @@ -525,10 +525,10 @@ inspect_i(mrb_state *mrb, mrb_sym sym, mrb_value v, void *p) /* need not to show internal data */ if (RSTRING_PTR(str)[0] == '-') { /* first element */ RSTRING_PTR(str)[0] = '#'; - mrb_str_cat2(mrb, str, " "); + mrb_str_cat(mrb, str, " ", 1); } else { - mrb_str_cat2(mrb, str, ", "); + mrb_str_cat(mrb, str, ", ", 2); } s = mrb_sym2name_len(mrb, sym, &len); mrb_str_cat(mrb, str, s, len); @@ -16,6 +16,7 @@ #include "mruby/class.h" #include "mruby/numeric.h" #include "error.h" +#include "value_array.h" #include <string.h> #include <setjmp.h> @@ -55,27 +56,6 @@ The value below allows about 60000 recursive calls in the simplest case. */ #endif static inline void -value_move(mrb_value *s1, const mrb_value *s2, size_t n) -{ - if (s1 > s2 && s1 < s2 + n) - { - s1 += n; - s2 += n; - while (n-- > 0) { - *--s1 = *--s2; - } - } - else if (s1 != s2) { - while (n-- > 0) { - *s1++ = *s2++; - } - } - else { - /* nothing to do. */ - } -} - -static inline void stack_clear(mrb_value *from, size_t count) { const mrb_value mrb_value_zero = { { 0 } }; |
