diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-26 07:23:23 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-26 07:23:23 +0000 |
commit | 6b818dd9616ce6f0c849ab32c5869cc55b624b0a (patch) | |
tree | 57a01309af17a79bcf3f47f2bb95cf135fa955ca | |
parent | 7e3bd6646ca88a285f0eb369a668c6596e0d6c83 (diff) |
common conversion functions
* array.c (rb_to_array_type): make public to share common code
internally.
* hash.c (rb_to_hash_type): make public to share common code
internally.
* symbol.c (rb_to_symbol_type): make public to share common code
internally.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | array.c | 5 | ||||
-rw-r--r-- | compile.c | 16 | ||||
-rw-r--r-- | hash.c | 5 | ||||
-rw-r--r-- | internal.h | 3 | ||||
-rw-r--r-- | io.c | 2 | ||||
-rw-r--r-- | iseq.c | 8 | ||||
-rw-r--r-- | process.c | 2 | ||||
-rw-r--r-- | symbol.c | 6 | ||||
-rw-r--r-- | thread.c | 2 | ||||
-rw-r--r-- | vm.c | 3 | ||||
-rw-r--r-- | vm_trace.c | 2 |
11 files changed, 31 insertions, 23 deletions
@@ -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) @@ -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<RARRAY_LEN(op); i+=2) { VALUE key = RARRAY_AREF(op, i); VALUE sym = RARRAY_AREF(op, i+1); @@ -7367,8 +7365,8 @@ iseq_build_from_ary_body(rb_iseq_t *iseq, LINK_ANCHOR *const anchor, return iseq_setup(iseq, anchor); } -#define CHECK_ARRAY(v) rb_convert_type_with_id((v), T_ARRAY, "Array", idTo_ary) -#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_SYMBOL(v) rb_to_symbol_type(v) static int int_param(int *dst, VALUE param, VALUE sym) @@ -712,11 +712,12 @@ rb_hash_s_create(int argc, VALUE *argv, VALUE klass) return hash; } -static VALUE -to_hash(VALUE hash) +VALUE +rb_to_hash_type(VALUE hash) { return rb_convert_type_with_id(hash, T_HASH, "Hash", idTo_hash); } +#define to_hash rb_to_hash_type VALUE rb_check_hash_type(VALUE hash) diff --git a/internal.h b/internal.h index 401dfa5c74..25fcf238f4 100644 --- a/internal.h +++ b/internal.h @@ -1037,6 +1037,7 @@ VALUE rb_ary_at(VALUE, VALUE); VALUE rb_ary_aref1(VALUE ary, VALUE i); VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e); size_t rb_ary_memsize(VALUE); +VALUE rb_to_array_type(VALUE obj); #ifdef __GNUC__ #define rb_ary_new_from_args(n, ...) \ __extension__ ({ \ @@ -1268,6 +1269,7 @@ long rb_dbl_long_hash(double d); st_table *rb_init_identtable(void); st_table *rb_init_identtable_with_size(st_index_t size); VALUE rb_hash_compare_by_id_p(VALUE hash); +VALUE rb_to_hash_type(VALUE obj); #define RHASH_TBL_RAW(h) rb_hash_tbl_raw(h) VALUE rb_hash_keys(VALUE hash); @@ -1686,6 +1688,7 @@ VALUE rb_sym_intern_ascii_cstr(const char *ptr); rb_sym_intern_ascii_cstr(ptr); \ }) #endif +VALUE rb_to_symbol_type(VALUE obj); /* struct.c */ VALUE rb_struct_init_copy(VALUE copy, VALUE s); @@ -10166,7 +10166,7 @@ open_key_args(int argc, VALUE *argv, VALUE opt, struct foreach_arg *arg) VALUE args; long n; - v = rb_convert_type_with_id(v, T_ARRAY, "Array", idTo_ary); + v = rb_to_array_type(v); n = RARRAY_LEN(v) + 1; #if SIZEOF_LONG > SIZEOF_INT if (n > INT_MAX) { @@ -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 @@ -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) { @@ -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) { @@ -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); @@ -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 = |