diff --git a/array.c b/array.c index 6eebfdab1c..425e28aa69 100644 --- a/array.c +++ b/array.c @@ -641,11 +641,12 @@ rb_assoc_new(VALUE car, VALUE cdr) return rb_ary_new3(2, car, cdr); } -static VALUE -to_ary(VALUE ary) +VALUE +rb_to_array_type(VALUE ary) { return rb_convert_type_with_id(ary, T_ARRAY, "Array", idTo_ary); } +#define to_ary rb_to_array_type VALUE rb_check_array_type(VALUE ary) diff --git a/compile.c b/compile.c index 0d977fbebc..b3969ff4c4 100644 --- a/compile.c +++ b/compile.c @@ -7058,7 +7058,7 @@ register_label(rb_iseq_t *iseq, struct st_table *labels_table, VALUE obj) { LABEL *label = 0; st_data_t tmp; - obj = rb_convert_type_with_id(obj, T_SYMBOL, "Symbol", idTo_sym); + obj = rb_to_symbol_type(obj); if (st_lookup(labels_table, obj, &tmp) == 0) { label = NEW_LABEL(0); @@ -7111,8 +7111,7 @@ iseq_build_from_ary_exception(rb_iseq_t *iseq, struct st_table *labels_table, LABEL *lstart, *lend, *lcont; unsigned int sp; - v = rb_convert_type_with_id(RARRAY_AREF(exception, i), T_ARRAY, - "Array", idTo_ary); + v = rb_to_array_type(RARRAY_AREF(exception, i)); if (RARRAY_LEN(v) != 6) { rb_raise(rb_eSyntaxError, "wrong exception entry"); } @@ -7300,7 +7299,7 @@ iseq_build_from_ary_body(rb_iseq_t *iseq, LINK_ANCHOR *const anchor, } break; case TS_GENTRY: - op = rb_convert_type_with_id(op, T_SYMBOL, "Symbol", idTo_sym); + op = rb_to_symbol_type(op); argv[j] = (VALUE)rb_global_entry(SYM2ID(op)); break; case TS_IC: @@ -7316,8 +7315,7 @@ iseq_build_from_ary_body(rb_iseq_t *iseq, LINK_ANCHOR *const anchor, argv[j] = Qfalse; break; case TS_ID: - argv[j] = rb_convert_type_with_id(op, T_SYMBOL, - "Symbol", idTo_sym); + argv[j] = rb_to_symbol_type(op); break; case TS_CDHASH: { @@ -7325,7 +7323,7 @@ iseq_build_from_ary_body(rb_iseq_t *iseq, LINK_ANCHOR *const anchor, VALUE map = rb_hash_new_with_size(RARRAY_LEN(op)/2); rb_hash_tbl_raw(map)->type = &cdhash_type; - op = rb_convert_type_with_id(op, T_ARRAY, "Array", idTo_ary); + op = rb_to_array_type(op); for (i=0; i SIZEOF_INT if (n > INT_MAX) { diff --git a/iseq.c b/iseq.c index adb0c79917..ccea4f1549 100644 --- a/iseq.c +++ b/iseq.c @@ -520,10 +520,10 @@ rb_iseq_load_iseq(VALUE fname) return NULL; } -#define CHECK_ARRAY(v) rb_convert_type_with_id((v), T_ARRAY, "Array", idTo_ary) -#define CHECK_HASH(v) rb_convert_type_with_id((v), T_HASH, "Hash", idTo_hash) -#define CHECK_STRING(v) rb_convert_type_with_id((v), T_STRING, "String", idTo_str) -#define CHECK_SYMBOL(v) rb_convert_type_with_id((v), T_SYMBOL, "Symbol", idTo_sym) +#define CHECK_ARRAY(v) rb_to_array_type(v) +#define CHECK_HASH(v) rb_to_hash_type(v) +#define CHECK_STRING(v) rb_str_to_str(v) +#define CHECK_SYMBOL(v) rb_to_symbol_type(v) static inline VALUE CHECK_INTEGER(VALUE v) {(void)NUM2LONG(v); return v;} static enum iseq_type diff --git a/process.c b/process.c index cb3312f859..d915478122 100644 --- a/process.c +++ b/process.c @@ -2386,7 +2386,7 @@ rb_execarg_parent_start1(VALUE execarg_obj) } else { envtbl = rb_const_get(rb_cObject, id_ENV); - envtbl = rb_convert_type_with_id(envtbl, T_HASH, "Hash", idTo_hash); + envtbl = rb_to_hash_type(envtbl); } hide_obj(envtbl); if (envopts != Qfalse) { diff --git a/symbol.c b/symbol.c index 45d49d20d9..147c11f007 100644 --- a/symbol.c +++ b/symbol.c @@ -1044,6 +1044,12 @@ rb_sym_intern_ascii_cstr(const char *ptr) return rb_sym_intern_ascii(ptr, strlen(ptr)); } +VALUE +rb_to_symbol_type(VALUE obj) +{ + return rb_convert_type_with_id(obj, T_SYMBOL, "Symbol", idTo_sym); +} + static ID attrsetname_to_attr_id(VALUE name) { diff --git a/thread.c b/thread.c index baabf405f4..1815d9971b 100644 --- a/thread.c +++ b/thread.c @@ -1867,7 +1867,7 @@ rb_thread_s_handle_interrupt(VALUE self, VALUE mask_arg) } mask = 0; - mask_arg = rb_convert_type_with_id(mask_arg, T_HASH, "Hash", idTo_hash); + mask_arg = rb_to_hash_type(mask_arg); rb_hash_foreach(mask_arg, handle_interrupt_arg_check_i, (VALUE)&mask); if (!mask) { return rb_yield(Qnil); diff --git a/vm.c b/vm.c index 19ec4f4a09..7c8bba9af4 100644 --- a/vm.c +++ b/vm.c @@ -2763,8 +2763,7 @@ core_hash_merge_kwd(int argc, VALUE *argv) VALUE hash, kw; rb_check_arity(argc, 1, 2); hash = argv[0]; - kw = argv[argc-1]; - kw = rb_convert_type_with_id(kw, T_HASH, "Hash", idTo_hash); + kw = rb_to_hash_type(argv[argc-1]); if (argc < 2) hash = kw; rb_hash_foreach(kw, argc < 2 ? kwcheck_i : kwmerge_i, hash); return hash; diff --git a/vm_trace.c b/vm_trace.c index b03f0cc9d4..fe07967606 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -668,7 +668,7 @@ static rb_event_flag_t symbol2event_flag(VALUE v) { ID id; - VALUE sym = rb_convert_type_with_id(v, T_SYMBOL, "Symbol", idTo_sym); + VALUE sym = rb_to_symbol_type(v); const rb_event_flag_t RUBY_EVENT_A_CALL = RUBY_EVENT_CALL | RUBY_EVENT_B_CALL | RUBY_EVENT_C_CALL; const rb_event_flag_t RUBY_EVENT_A_RETURN =