[前][次][番号順一覧][スレッド一覧]

ruby-changes:48324

From: nobu <ko1@a...>
Date: Thu, 26 Oct 2017 16:23:27 +0900 (JST)
Subject: [ruby-changes:48324] nobu:r60438 (trunk): common conversion functions

nobu	2017-10-26 16:23:23 +0900 (Thu, 26 Oct 2017)

  New Revision: 60438

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60438

  Log:
    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.

  Modified files:
    trunk/array.c
    trunk/compile.c
    trunk/hash.c
    trunk/internal.h
    trunk/io.c
    trunk/iseq.c
    trunk/process.c
    trunk/symbol.c
    trunk/thread.c
    trunk/vm.c
    trunk/vm_trace.c
Index: symbol.c
===================================================================
--- symbol.c	(revision 60437)
+++ symbol.c	(revision 60438)
@@ -1044,6 +1044,12 @@ rb_sym_intern_ascii_cstr(const char *ptr https://github.com/ruby/ruby/blob/trunk/symbol.c#L1044
     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)
 {
Index: hash.c
===================================================================
--- hash.c	(revision 60437)
+++ hash.c	(revision 60438)
@@ -712,11 +712,12 @@ rb_hash_s_create(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/hash.c#L712
     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)
Index: compile.c
===================================================================
--- compile.c	(revision 60437)
+++ compile.c	(revision 60438)
@@ -7058,7 +7058,7 @@ register_label(rb_iseq_t *iseq, struct s https://github.com/ruby/ruby/blob/trunk/compile.c#L7058
 {
     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 https://github.com/ruby/ruby/blob/trunk/compile.c#L7111
 	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 https://github.com/ruby/ruby/blob/trunk/compile.c#L7299
 			}
 			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 https://github.com/ruby/ruby/blob/trunk/compile.c#L7315
 			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 https://github.com/ruby/ruby/blob/trunk/compile.c#L7323
 			    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 https://github.com/ruby/ruby/blob/trunk/compile.c#L7365
     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)
Index: vm_trace.c
===================================================================
--- vm_trace.c	(revision 60437)
+++ vm_trace.c	(revision 60438)
@@ -668,7 +668,7 @@ static rb_event_flag_t https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L668
 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 =
Index: internal.h
===================================================================
--- internal.h	(revision 60437)
+++ internal.h	(revision 60438)
@@ -1037,6 +1037,7 @@ VALUE rb_ary_at(VALUE, VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L1037
 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); https://github.com/ruby/ruby/blob/trunk/internal.h#L1269
 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 cha https://github.com/ruby/ruby/blob/trunk/internal.h#L1688
 	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);
Index: io.c
===================================================================
--- io.c	(revision 60437)
+++ io.c	(revision 60438)
@@ -10166,7 +10166,7 @@ open_key_args(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/io.c#L10166
 	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) {
Index: process.c
===================================================================
--- process.c	(revision 60437)
+++ process.c	(revision 60438)
@@ -2386,7 +2386,7 @@ rb_execarg_parent_start1(VALUE execarg_o https://github.com/ruby/ruby/blob/trunk/process.c#L2386
         }
         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) {
Index: array.c
===================================================================
--- array.c	(revision 60437)
+++ array.c	(revision 60438)
@@ -641,11 +641,12 @@ rb_assoc_new(VALUE car, VALUE cdr) https://github.com/ruby/ruby/blob/trunk/array.c#L641
     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)
Index: thread.c
===================================================================
--- thread.c	(revision 60437)
+++ thread.c	(revision 60438)
@@ -1867,7 +1867,7 @@ rb_thread_s_handle_interrupt(VALUE self, https://github.com/ruby/ruby/blob/trunk/thread.c#L1867
     }
 
     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);
Index: vm.c
===================================================================
--- vm.c	(revision 60437)
+++ vm.c	(revision 60438)
@@ -2763,8 +2763,7 @@ core_hash_merge_kwd(int argc, VALUE *arg https://github.com/ruby/ruby/blob/trunk/vm.c#L2763
     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;
Index: iseq.c
===================================================================
--- iseq.c	(revision 60437)
+++ iseq.c	(revision 60438)
@@ -520,10 +520,10 @@ rb_iseq_load_iseq(VALUE fname) https://github.com/ruby/ruby/blob/trunk/iseq.c#L520
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]