Skip to content

Commit

Permalink
* struct.c (rb_struct_eql): should compare values with "eql?".
Browse files Browse the repository at this point in the history
* range.c (range_check): <=> returns nil for invalid values;
  should check.

* regex.c (re_compile_pattern): should not set RE_OPTIMIZE_ANCHOR,
  if anychar_repeat is enclosed by parentheses.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Apr 18, 2003
1 parent 18cdaa6 commit 6987b08
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 16 deletions.
18 changes: 16 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
Sat Apr 19 00:56:13 2003 Yukihiro Matsumoto <[email protected]>

* struct.c (rb_struct_eql): should compare values with "eql?".

Fri Apr 18 23:29:08 2003 Yukihiro Matsumoto <[email protected]>

* range.c (range_check): <=> returns nil for invalid values;
should check.

Fri Apr 18 15:26:50 2003 NAKAMURA Usaku <[email protected]>

* error.c (rb_raise): workaround for some implementations of
vsnprintf.

Fri Apr 18 02:23:42 2003 Yukihiro Matsumoto <[email protected]>

* regex.c (re_compile_pattern): should not set RE_OPTIMIZE_ANCHOR,
if anychar_repeat is enclosed by parentheses.

Fri Apr 18 01:49:18 2003 Nobuyoshi Nakada <[email protected]>

* util.c (ruby_strtod): improved conversion accuracy.
Expand Down Expand Up @@ -51,13 +65,13 @@ Mon Apr 14 19:45:56 2003 Nobuyoshi Nakada <[email protected]>

Mon Apr 14 03:22:33 2003 Yukihiro Matsumoto <[email protected]>

* rubyio.h (struct OpenFile): add error raise flag to finalizer.
* rubyio.h (struct OpenFile): add noraise flag to finalizer.

* io.c (Init_IO): define $/, $-0, and $\ as string-only
variables.

* string.c (rb_str_split_m): does not generate empty string if
there's no match in the receiver.
the receiver is empty.

* io.c (fptr_finalize): should raise error on EBADF for readable
IOs as well.
Expand Down
8 changes: 4 additions & 4 deletions marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,16 +1112,16 @@ r_object0(arg, proc)

case TYPE_MODULE_OLD:
{
VALUE str = r_bytes(arg);
volatile VALUE str = r_bytes(arg);

v = path2module(RSTRING(str)->ptr);
v = rb_path2class(RSTRING(str)->ptr);
r_regist(v, arg);
}
break;

case TYPE_CLASS:
{
VALUE str = r_bytes(arg);
volatile VALUE str = r_bytes(arg);

v = path2class(RSTRING(str)->ptr);
r_regist(v, arg);
Expand All @@ -1130,7 +1130,7 @@ r_object0(arg, proc)

case TYPE_MODULE:
{
VALUE str = r_bytes(arg);
volatile VALUE str = r_bytes(arg);

v = path2module(RSTRING(str)->ptr);
r_regist(v, arg);
Expand Down
18 changes: 10 additions & 8 deletions range.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ static ID id_cmp, id_succ, id_beg, id_end, id_excl;
#define SET_EXCL(r,v) rb_ivar_set((r), id_excl, (v) ? Qtrue : Qfalse)

static VALUE
range_check(args)
VALUE *args;
range_failed()
{
rb_funcall(args[0], id_cmp, 1, args[1]);
/* rb_funcall(args[0], id_succ, 0, 0); */
return Qnil;
rb_raise(rb_eArgError, "bad value for range");
return Qnil; /* dummy */
}

static VALUE
range_failed()
range_check(args)
VALUE *args;
{
rb_raise(rb_eArgError, "bad value for range");
return Qnil; /* dummy */
VALUE v;

v = rb_funcall(args[0], id_cmp, 1, args[1]);
if (NIL_P(v)) range_failed();
return Qnil;
}

static void
Expand Down
1 change: 0 additions & 1 deletion regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -2397,7 +2397,6 @@ re_compile_pattern(pattern, size, bufp)
/* set optimize flags */
laststart = bufp->buffer;
if (laststart != b) {
if (*laststart == start_memory) laststart += 3;
if (*laststart == dummy_failure_jump) laststart += 3;
else if (*laststart == try_next) laststart += 3;
if (*laststart == anychar_repeat) {
Expand Down
10 changes: 10 additions & 0 deletions sample/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,9 @@ def nan.test(v)
nan.test(1.0/0);
nan.test(-1.0/0);

s = "3.7517675036461267e+17"
test_ok(s == sprintf("%.16e", s.to_f))

test_check "bignum"
def fact(n)
return 1 if n == 0
Expand Down Expand Up @@ -1550,6 +1553,13 @@ module M003; include M002; end
StrClone=String.clone;
test_ok(Marshal.load(Marshal.dump(StrClone.new("abc"))).class == StrClone)

[[1,2,3,4], [81, 2, 118, 3146]].each { |w,x,y,z|
a = (x.to_f + y.to_f / z.to_f) * Math.exp(w.to_f / (x.to_f + y.to_f / z.to_f))
ma = Marshal.dump(a)
b = Marshal.load(ma)
test_ok(a == b)
}

test_check "pack"

$format = "c2x5CCxsdils_l_a6";
Expand Down
21 changes: 20 additions & 1 deletion struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,25 @@ rb_struct_hash(s)
return LONG2FIX(h);
}

static VALUE
rb_struct_eql(s, s2)
VALUE s, s2;
{
long i;

if (s == s2) return Qtrue;
if (TYPE(s2) != T_STRUCT) return Qfalse;
if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse;
if (RSTRUCT(s)->len != RSTRUCT(s2)->len) {
rb_bug("inconsistent struct"); /* should never happen */
}

for (i=0; i<RSTRUCT(s)->len; i++) {
if (!rb_eql(RSTRUCT(s)->ptr[i], RSTRUCT(s2)->ptr[i])) return Qfalse;
}
return Qtrue;
}

static VALUE
rb_struct_size(s)
VALUE s;
Expand All @@ -612,7 +631,7 @@ Init_Struct()
rb_define_method(rb_cStruct, "copy_object", rb_struct_copy_object, 1);

rb_define_method(rb_cStruct, "==", rb_struct_equal, 1);
rb_define_method(rb_cStruct, "eql?", rb_struct_equal, 1);
rb_define_method(rb_cStruct, "eql?", rb_struct_eql, 1);
rb_define_method(rb_cStruct, "hash", rb_struct_hash, 0);

rb_define_method(rb_cStruct, "to_s", rb_struct_to_s, 0);
Expand Down

0 comments on commit 6987b08

Please sign in to comment.