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

ruby-changes:49954

From: nobu <ko1@a...>
Date: Sat, 27 Jan 2018 18:27:53 +0900 (JST)
Subject: [ruby-changes:49954] nobu:r62072 (trunk): array.c: rb_check_to_array

nobu	2018-01-27 18:27:47 +0900 (Sat, 27 Jan 2018)

  New Revision: 62072

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

  Log:
    array.c: rb_check_to_array
    
    * array.c (rb_check_to_array): conversion to array by to_a method.
      returns nil if not possible.

  Modified files:
    trunk/array.c
    trunk/internal.h
    trunk/object.c
    trunk/vm_insnhelper.c
Index: array.c
===================================================================
--- array.c	(revision 62071)
+++ array.c	(revision 62072)
@@ -655,6 +655,12 @@ rb_check_array_type(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L655
     return rb_check_convert_type_with_id(ary, T_ARRAY, "Array", idTo_ary);
 }
 
+VALUE
+rb_check_to_array(VALUE ary)
+{
+    return rb_check_convert_type_with_id(ary, T_ARRAY, "Array", idTo_a);
+}
+
 /*
  *  call-seq:
  *     Array.try_convert(obj) -> array or nil
Index: object.c
===================================================================
--- object.c	(revision 62071)
+++ object.c	(revision 62072)
@@ -3595,7 +3595,7 @@ rb_Array(VALUE val) https://github.com/ruby/ruby/blob/trunk/object.c#L3595
     VALUE tmp = rb_check_array_type(val);
 
     if (NIL_P(tmp)) {
-	tmp = rb_check_convert_type_with_id(val, T_ARRAY, "Array", idTo_a);
+	tmp = rb_check_to_array(val);
 	if (NIL_P(tmp)) {
 	    return rb_ary_new3(1, val);
 	}
Index: internal.h
===================================================================
--- internal.h	(revision 62071)
+++ internal.h	(revision 62072)
@@ -1059,6 +1059,7 @@ VALUE rb_ary_aref1(VALUE ary, VALUE i); https://github.com/ruby/ruby/blob/trunk/internal.h#L1059
 VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e);
 size_t rb_ary_memsize(VALUE);
 VALUE rb_to_array_type(VALUE obj);
+VALUE rb_check_to_array(VALUE ary);
 #if defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
 #define rb_ary_new_from_args(n, ...) \
     __extension__ ({ \
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 62071)
+++ vm_insnhelper.c	(revision 62072)
@@ -2968,8 +2968,8 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2968
 vm_concat_array(VALUE ary1, VALUE ary2st)
 {
     const VALUE ary2 = ary2st;
-    VALUE tmp1 = rb_check_convert_type_with_id(ary1, T_ARRAY, "Array", idTo_a);
-    VALUE tmp2 = rb_check_convert_type_with_id(ary2, T_ARRAY, "Array", idTo_a);
+    VALUE tmp1 = rb_check_to_array(ary1);
+    VALUE tmp2 = rb_check_to_array(ary2);
 
     if (NIL_P(tmp1)) {
 	tmp1 = rb_ary_new3(1, ary1);
@@ -2988,7 +2988,7 @@ vm_concat_array(VALUE ary1, VALUE ary2st https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2988
 static VALUE
 vm_splat_array(VALUE flag, VALUE ary)
 {
-    VALUE tmp = rb_check_convert_type_with_id(ary, T_ARRAY, "Array", idTo_a);
+    VALUE tmp = rb_check_to_array(ary);
     if (NIL_P(tmp)) {
 	return rb_ary_new3(1, ary);
     }

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

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