summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-16 06:52:29 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-16 06:52:29 +0000
commit5e65d8f433f555af052ae6a32f42adb897778c58 (patch)
tree98a659fb41343c8a310749c8a55c4aaeba2ef4fb /range.c
parenteb9bc2d2655c336a1e5a34af69fdf5bf2c7d0788 (diff)
downloadbundler-5e65d8f433f555af052ae6a32f42adb897778c58.tar.gz
* bignum.c (rb_big_new, rb_bigzero_p), range.c (rb_range_values):
added for random.c. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/range.c b/range.c
index 0d25a37d55..ce2df63100 100644
--- a/range.c
+++ b/range.c
@@ -601,12 +601,11 @@ range_max(VALUE range)
}
}
-
-VALUE
-rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
+int
+rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp)
{
VALUE b, e;
- long beg, end, excl;
+ int excl;
if (rb_obj_is_kind_of(range, rb_cRange)) {
b = RANGE_BEG(range);
@@ -620,9 +619,25 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
e = rb_funcall(range, id_end, 0);
excl = RTEST(rb_funcall(range, rb_intern("exclude_end?"), 0));
}
+ *begp = b;
+ *endp = e;
+ *exclp = excl;
+ return Qtrue;
+}
+
+VALUE
+rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
+{
+ long beg, end, origbeg, origend;
+ VALUE b, e;
+ int excl;
+
+ if (!rb_range_values(range, &b, &e, &excl))
+ return Qfalse;
beg = NUM2LONG(b);
end = NUM2LONG(e);
-
+ origbeg = beg;
+ origend = end;
if (beg < 0) {
beg += len;
if (beg < 0)
@@ -649,7 +664,7 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
out_of_range:
if (err) {
rb_raise(rb_eRangeError, "%ld..%s%ld out of range",
- NUM2LONG(b), excl ? "." : "", NUM2LONG(e));
+ origbeg, excl ? "." : "", origend);
}
return Qnil;
}