Permalink
Browse files

* numeric.c (num_step): better iteration condition for float

  values;  suggested by Masahiro TANAKA <masa@ir.isas.ac.jp>.

* range.c (range_step): step (for Range#step method) <= 0 makes no
  sence, thus ArgError will be raised.

* range.c (range_each): Range#each method is special case for
  Range#step(1)

* file.c (rb_find_file): load must be done from an abolute path if
  $SAFE >= 4.

* enum.c (enum_partition): new method. [new]

* re.c (rb_reg_s_quote): quote whitespaces for /x cases.


git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@2420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
matz committed May 1, 2002
1 parent 93195b1 commit b6b8afad4a603190ac3b3376b413a40588c84246
Showing with 155 additions and 104 deletions.
  1. +26 −0 ChangeLog
  2. +27 −0 enum.c
  3. +16 −16 eval.c
  4. +4 −0 file.c
  5. +7 −11 numeric.c
  6. +45 −66 range.c
  7. +30 −11 re.c
View
@@ -1,7 +1,33 @@
+Tue Apr 30 09:23:05 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * numeric.c (num_step): better iteration condition for float
+ values; suggested by Masahiro TANAKA <masa@ir.isas.ac.jp>.
+
+Tue Apr 30 05:59:42 2002 Michal Rokos <m.rokos@sh.cvut.cz>
+
+ * range.c (range_step): step (for Range#step method) <= 0 makes no
+ sence, thus ArgError will be raised.
+
+ * range.c (range_each): Range#each method is special case for
+ Range#step(1)
+
+Mon Apr 29 18:46:42 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * file.c (rb_find_file): load must be done from an abolute path if
+ $SAFE >= 4.
+
Sun Apr 28 17:01:56 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* win32/win32.c (insert): fix prototype for ANSI C.
+Fri Apr 26 13:47:15 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * enum.c (enum_partition): new method. [new]
+
+Fri Apr 26 13:41:00 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * re.c (rb_reg_s_quote): quote whitespaces for /x cases.
+
Fri Apr 26 06:48:23 2002 Takaaki Tateishi <ttate@kt.jaist.ac.jp>
* ext/dl/ptr.c (cary2ary): missing break in switch statements.
View
27 enum.c
@@ -216,6 +216,32 @@ enum_inject(argc, argv, obj)
return n;
}
+static VALUE
+partition_i(i, ary)
+ VALUE i, *ary;
+{
+ if (RTEST(rb_yield(i))) {
+ rb_ary_push(ary[0], i);
+ }
+ else {
+ rb_ary_push(ary[1], i);
+ }
+ return Qnil;
+}
+
+static VALUE
+enum_partition(obj)
+ VALUE obj;
+{
+ VALUE ary[2];
+
+ ary[0] = rb_ary_new();
+ ary[1] = rb_ary_new();
+ rb_iterate(rb_each, obj, partition_i, (VALUE)ary);
+
+ return rb_assoc_new(ary[0], ary[1]);
+}
+
static VALUE
enum_sort(obj)
VALUE obj;
@@ -475,6 +501,7 @@ Init_Enumerable()
rb_define_method(rb_mEnumerable,"collect", enum_collect, 0);
rb_define_method(rb_mEnumerable,"map", enum_collect, 0);
rb_define_method(rb_mEnumerable,"inject", enum_inject, -1);
+ rb_define_method(rb_mEnumerable,"partition", enum_partition, 0);
rb_define_method(rb_mEnumerable,"all?", enum_all, 0);
rb_define_method(rb_mEnumerable,"any?", enum_any, 0);
rb_define_method(rb_mEnumerable,"min", enum_min, 0);
View
32 eval.c
@@ -227,7 +227,7 @@ rb_add_method(klass, mid, node, noex)
NODE *body;
if (NIL_P(klass)) klass = rb_cObject;
- if (rb_safe_level() >= 4 && (klass == rb_cObject || !OBJ_TAINTED(klass))) {
+ if (ruby_safe_level >= 4 && (klass == rb_cObject || !OBJ_TAINTED(klass))) {
rb_raise(rb_eSecurityError, "Insecure: can't define method");
}
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
@@ -310,7 +310,7 @@ remove_method(klass, mid)
if (klass == rb_cObject) {
rb_secure(4);
}
- if (rb_safe_level() >= 4 && !OBJ_TAINTED(klass)) {
+ if (ruby_safe_level >= 4 && !OBJ_TAINTED(klass)) {
rb_raise(rb_eSecurityError, "Insecure: can't remove method");
}
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
@@ -1588,7 +1588,7 @@ rb_undef(klass, id)
if (ruby_class == rb_cObject) {
rb_secure(4);
}
- if (rb_safe_level() >= 4 && !OBJ_TAINTED(klass)) {
+ if (ruby_safe_level >= 4 && !OBJ_TAINTED(klass)) {
rb_raise(rb_eSecurityError, "Insecure: can't undef");
if (id == __id__ || id == __send__ || id == init) {
rb_name_error(id, "undefining `%s' prohibited", rb_id2name(id));
@@ -3166,7 +3166,7 @@ rb_eval(self, n)
VALUE klass;
NODE *body = 0, *defn;
- if (rb_safe_level() >= 4 && !OBJ_TAINTED(recv)) {
+ if (ruby_safe_level >= 4 && !OBJ_TAINTED(recv)) {
rb_raise(rb_eSecurityError, "Insecure: can't define singleton method");
}
if (FIXNUM_P(recv) || SYMBOL_P(recv)) {
@@ -3179,7 +3179,7 @@ rb_eval(self, n)
if (OBJ_FROZEN(recv)) rb_error_frozen("object");
klass = rb_singleton_class(recv);
if (st_lookup(RCLASS(klass)->m_tbl, node->nd_mid, &body)) {
- if (rb_safe_level() >= 4) {
+ if (ruby_safe_level >= 4) {
rb_raise(rb_eSecurityError, "redefining method prohibited");
}
if (RTEST(ruby_verbose)) {
@@ -3248,7 +3248,7 @@ rb_eval(self, n)
goto override_class;
}
}
- if (rb_safe_level() >= 4) {
+ if (ruby_safe_level >= 4) {
rb_raise(rb_eSecurityError, "extending class prohibited");
}
}
@@ -3288,7 +3288,7 @@ rb_eval(self, n)
rb_raise(rb_eTypeError, "%s is not a module",
rb_id2name(node->nd_cname));
}
- if (rb_safe_level() >= 4) {
+ if (ruby_safe_level >= 4) {
rb_raise(rb_eSecurityError, "extending module prohibited");
}
}
@@ -3315,7 +3315,7 @@ rb_eval(self, n)
rb_raise(rb_eTypeError, "no virtual class for %s",
rb_class2name(CLASS_OF(result)));
}
- if (rb_safe_level() >= 4 && !OBJ_TAINTED(result))
+ if (ruby_safe_level >= 4 && !OBJ_TAINTED(result))
rb_raise(rb_eSecurityError, "Insecure: can't extend object");
klass = rb_singleton_class(result);
@@ -5603,7 +5603,7 @@ static void
secure_visibility(self)
VALUE self;
{
- if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
+ if (ruby_safe_level >= 4 && !OBJ_TAINTED(self)) {
rb_raise(rb_eSecurityError, "Insecure: can't change method visibility");
}
}
@@ -6315,15 +6315,15 @@ proc_save_safe_level(data)
VALUE data;
{
if (OBJ_TAINTED(data)) {
- switch (rb_safe_level()) {
+ switch (ruby_safe_level) {
case 3:
FL_SET(data, PROC_T3);
break;
case 4:
FL_SET(data, PROC_T4);
break;
default:
- if (rb_safe_level() > 4) {
+ if (ruby_safe_level > 4) {
FL_SET(data, PROC_TMAX);
}
break;
@@ -6621,8 +6621,8 @@ block_pass(self, node)
block = b;
}
- if (rb_safe_level() >= 1 && OBJ_TAINTED(block)) {
- if (rb_safe_level() > proc_get_safe_level(block)) {
+ if (ruby_safe_level >= 1 && OBJ_TAINTED(block)) {
+ if (ruby_safe_level > proc_get_safe_level(block)) {
rb_raise(rb_eSecurityError, "Insecure: tainted block value");
}
}
@@ -8316,7 +8316,7 @@ rb_thread_safe_level(thread)
th = rb_thread_check(thread);
if (th == curr_thread) {
- return INT2NUM(rb_safe_level());
+ return INT2NUM(ruby_safe_level);
}
return INT2NUM(th->safe);
}
@@ -8859,7 +8859,7 @@ rb_thread_local_aref(thread, id)
VALUE val;
th = rb_thread_check(thread);
- if (rb_safe_level() >= 4 && th != curr_thread) {
+ if (ruby_safe_level >= 4 && th != curr_thread) {
rb_raise(rb_eSecurityError, "Insecure: thread locals");
}
if (!th->locals) return Qnil;
@@ -8884,7 +8884,7 @@ rb_thread_local_aset(thread, id, val)
{
rb_thread_t th = rb_thread_check(thread);
- if (rb_safe_level() >= 4 && th != curr_thread) {
+ if (ruby_safe_level >= 4 && th != curr_thread) {
rb_raise(rb_eSecurityError, "Insecure: can't modify thread locals");
}
if (OBJ_FROZEN(thread)) rb_error_frozen("thread locals");
View
4 file.c
@@ -2482,6 +2482,10 @@ rb_find_file(path)
if (file_load_ok(f)) return path;
}
+ if (rb_safe_level() >= 4) {
+ rb_raise(rb_eSecurityError, "loading from non-absolute path %s", f);
+ }
+
if (rb_load_path) {
int i;
View
@@ -788,6 +788,7 @@ num_step(argc, argv, from)
while (i <= end) {
rb_yield(INT2FIX(i));
i += diff;
+ printf("<<%g>>\n", i - end);
}
}
else {
@@ -798,21 +799,16 @@ num_step(argc, argv, from)
}
}
else if (TYPE(from) == T_FLOAT || TYPE(to) == T_FLOAT || TYPE(step) == T_FLOAT) {
+ const double epsilon = 2.2204460492503131E-16;
double beg = NUM2DBL(from);
double end = NUM2DBL(to);
double unit = NUM2DBL(step);
- double n = beg;
- long i = 0;
+ double n = (end - beg)/unit;
+ long i;
- if (unit > 0) {
- for (i=0; n<=end; i++, n=beg+unit*i) {
- rb_yield(rb_float_new(n));
- }
- }
- else {
- for (i=0; n>=end; i++, n=beg+unit*i) {
- rb_yield(rb_float_new(n));
- }
+ n = floor(n + n*epsilon) + 1;
+ for (i=0; i<n; i++) {
+ rb_yield(rb_float_new(i*unit+beg));
}
}
else {
Oops, something went wrong.

0 comments on commit b6b8afa

Please sign in to comment.