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

ruby-changes:54130

From: mrkn <ko1@a...>
Date: Wed, 12 Dec 2018 15:40:03 +0900 (JST)
Subject: [ruby-changes:54130] mrkn:r66351 (trunk): enumerator.c: rb_arithmetic_sequence_extract

mrkn	2018-12-12 15:39:58 +0900 (Wed, 12 Dec 2018)

  New Revision: 66351

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

  Log:
    enumerator.c: rb_arithmetic_sequence_extract
    
    New public C-API for extracting components of Enumerator::ArithmeticSequence
    or Range.

  Modified files:
    trunk/enumerator.c
    trunk/include/ruby/intern.h
    trunk/internal.h
    trunk/range.c
Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 66350)
+++ include/ruby/intern.h	(revision 66351)
@@ -244,6 +244,7 @@ VALUE rb_enumeratorize_with_size(VALUE, https://github.com/ruby/ruby/blob/trunk/include/ruby/intern.h#L244
 	    return SIZED_ENUMERATOR(obj, argc, argv, size_fn);		\
     } while (0)
 #define RETURN_ENUMERATOR(obj, argc, argv) RETURN_SIZED_ENUMERATOR(obj, argc, argv, 0)
+int rb_arithmetic_sequence_extract(VALUE, VALUE *, VALUE *, VALUE *, int *);
 /* error.c */
 VALUE rb_exc_new(VALUE, const char*, long);
 VALUE rb_exc_new_cstr(VALUE, const char*);
Index: enumerator.c
===================================================================
--- enumerator.c	(revision 66350)
+++ enumerator.c	(revision 66351)
@@ -2777,6 +2777,27 @@ arith_seq_exclude_end_p(VALUE self) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L2777
     return RTEST(arith_seq_exclude_end(self));
 }
 
+int
+rb_arithmetic_sequence_extract(VALUE obj, VALUE *begin, VALUE *end, VALUE *step, int *exclude_end)
+{
+    if (rb_obj_is_kind_of(obj, rb_cArithSeq)) {
+        *begin = arith_seq_begin(obj);
+        *end   = arith_seq_end(obj);
+        *step  = arith_seq_step(obj);
+        *exclude_end = arith_seq_exclude_end_p(obj);
+        return 1;
+    }
+    else if (rb_obj_is_kind_of(obj, rb_cRange)) {
+        *begin = RANGE_BEG(obj);
+        *end   = RANGE_END(obj);
+        *step  = INT2FIX(1);
+        *exclude_end = RTEST(RANGE_EXCL(obj));
+        return 1;
+    }
+
+    return 0;
+}
+
 /*
  * call-seq:
  *   aseq.first -> num or nil
Index: range.c
===================================================================
--- range.c	(revision 66350)
+++ range.c	(revision 66351)
@@ -24,9 +24,6 @@ static ID id_beg, id_end, id_excl; https://github.com/ruby/ruby/blob/trunk/range.c#L24
 
 static VALUE r_cover_p(VALUE, VALUE, VALUE, VALUE);
 
-#define RANGE_BEG(r) (RSTRUCT(r)->as.ary[0])
-#define RANGE_END(r) (RSTRUCT(r)->as.ary[1])
-#define RANGE_EXCL(r) (RSTRUCT(r)->as.ary[2])
 #define RANGE_SET_BEG(r, v) (RSTRUCT_SET(r, 0, v))
 #define RANGE_SET_END(r, v) (RSTRUCT_SET(r, 1, v))
 #define RANGE_SET_EXCL(r, v) (RSTRUCT_SET(r, 2, v))
Index: internal.h
===================================================================
--- internal.h	(revision 66350)
+++ internal.h	(revision 66351)
@@ -1964,6 +1964,11 @@ ARGVSTR2ARGC(VALUE argv_str) https://github.com/ruby/ruby/blob/trunk/internal.h#L1964
 rb_pid_t rb_fork_ruby(int *status);
 void rb_last_status_clear(void);
 
+/* range.c */
+#define RANGE_BEG(r) (RSTRUCT(r)->as.ary[0])
+#define RANGE_END(r) (RSTRUCT(r)->as.ary[1])
+#define RANGE_EXCL(r) (RSTRUCT(r)->as.ary[2])
+
 /* rational.c */
 VALUE rb_rational_canonicalize(VALUE x);
 VALUE rb_rational_uminus(VALUE self);

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

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