Permalink
Browse files

* variable.c (rb_copy_generic_ivar): remove old generic instance

	  variable table if it existes.

	* class.c (rb_make_metaclass): metaclass of a metaclass is a
	  metaclass itself.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 20254d4 commit 6f484e4930be69c58462dd11c97663e6c8488b8e matz committed Sep 3, 2002
Showing with 277 additions and 239 deletions.
  1. +41 −0 ChangeLog
  2. +15 −23 array.c
  3. +22 −34 class.c
  4. +26 −14 compar.c
  5. +7 −0 error.c
  6. +41 −64 ext/digest/digest.c
  7. +2 −5 ext/digest/md5/md5init.c
  8. +1 −1 ext/extmk.rb.in
  9. +11 −9 ext/stringio/stringio.c
  10. +10 −8 file.c
  11. +2 −26 hash.c
  12. +0 −1 intern.h
  13. +2 −0 io.c
  14. +32 −20 object.c
  15. +4 −2 range.c
  16. +27 −10 re.c
  17. +1 −1 ruby.h
  18. +2 −2 string.c
  19. +9 −7 struct.c
  20. +11 −9 time.c
  21. +9 −1 variable.c
  22. +2 −2 version.h
View
@@ -14,10 +14,20 @@ Mon Sep 2 21:21:46 2002 Minero Aoki <aamine@loveruby.net>
* intern.h (ruby_parser_stack_on_heap): added.
+Mon Sep 2 18:45:07 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * variable.c (rb_copy_generic_ivar): remove old generic instance
+ variable table if it existes.
+
Sun Sep 1 15:54:33 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* config.guess: fixed for Linux/PPC.
+Sat Aug 31 09:38:12 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * class.c (rb_make_metaclass): metaclass of a metaclass is a
+ metaclass itself.
+
Fri Aug 30 22:45:16 2002 Akinori MUSHA <knu@iDaemons.org>
* lib/set.rb: Added.
@@ -45,6 +55,37 @@ Fri Aug 30 19:40:28 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* ext/tcltklib/tcltklib.c (ip_toUTF8, ip_fromUTF8): ditto.
+Fri Aug 30 01:32:17 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * class.c (rb_singleton_class): superclass of a metaclass
+ should be a metaclass of superclass.
+
+ * range.c (range_eq): two instances must belong to a same class to
+ be equal.
+
+ * range.c (range_eql): ditto.
+
+ * io.c (rb_io_taint_check): frozen check added.
+
+ * file.c (rb_stat_become): frozen check added.
+
+ * object.c (rb_obj_become): ditto.
+
+ * re.c (rb_reg_become): ditto.
+
+ * struct.c (rb_struct_become): ditto.
+
+ * time.c (time_become): ditto.
+
+ * array.c (rb_ary_become): should call rb_ary_modify().
+
+ * hash.c (rb_hash_become): should call rb_hash_modify().
+
+ * compar.c (cmp_equal): should not use NUM2LONG(), since <=> may
+ return bignum.
+
+ * compar.c (cmp_gt, cmp_ge, cmp_lt, cmp_le, cmp_between): ditto.
+
Thu Aug 29 23:34:42 2002 KONISHI Hiromasa <konishih@fd6.so-net.ne.jp>
* bcc32/MakeFile.sub (sitearch): add.
View
38 array.c
@@ -795,22 +795,6 @@ rb_ary_empty_p(ary)
return Qfalse;
}
-static VALUE
-rb_ary_become(copy, orig)
- VALUE copy, orig;
-{
- orig = to_ary(orig);
- ary_make_shared(orig);
- if (RARRAY(copy)->ptr && !FL_TEST(copy, ELTS_SHARED))
- free(RARRAY(copy)->ptr);
- RARRAY(copy)->ptr = RARRAY(orig)->ptr;
- RARRAY(copy)->len = RARRAY(orig)->len;
- RARRAY(copy)->aux.shared = RARRAY(orig)->aux.shared;
- FL_SET(copy, ELTS_SHARED);
-
- return copy;
-}
-
VALUE
rb_ary_dup(ary)
VALUE ary;
@@ -1316,13 +1300,21 @@ rb_ary_delete_if(ary)
}
static VALUE
-rb_ary_replace(ary, ary2)
- VALUE ary, ary2;
+rb_ary_replace(copy, orig)
+ VALUE copy, orig;
{
- if (ary == ary2) return ary;
- ary2 = to_ary(ary2);
- rb_ary_update(ary, 0, RARRAY(ary)->len, ary2);
- return ary;
+ rb_ary_modify(copy);
+ orig = to_ary(orig);
+ if (copy == orig) return copy;
+ ary_make_shared(orig);
+ if (RARRAY(copy)->ptr && !FL_TEST(copy, ELTS_SHARED))
+ free(RARRAY(copy)->ptr);
+ RARRAY(copy)->ptr = RARRAY(orig)->ptr;
+ RARRAY(copy)->len = RARRAY(orig)->len;
+ RARRAY(copy)->aux.shared = RARRAY(orig)->aux.shared;
+ FL_SET(copy, ELTS_SHARED);
+
+ return copy;
}
VALUE
@@ -1857,7 +1849,7 @@ Init_Array()
rb_define_method(rb_cArray, "rindex", rb_ary_rindex, 1);
rb_define_method(rb_cArray, "indexes", rb_ary_indexes, -1);
rb_define_method(rb_cArray, "indices", rb_ary_indexes, -1);
- rb_define_method(rb_cArray, "become", rb_ary_become, 1);
+ rb_define_method(rb_cArray, "become", rb_ary_replace, 1);
rb_define_method(rb_cArray, "join", rb_ary_join_m, -1);
rb_define_method(rb_cArray, "reverse", rb_ary_reverse_m, 0);
rb_define_method(rb_cArray, "reverse!", rb_ary_reverse_bang, 0);
View
56 class.c
@@ -94,25 +94,24 @@ rb_mod_dup(mod)
}
VALUE
-rb_singleton_class_new(super)
- VALUE super;
+rb_singleton_class_clone(obj)
+ VALUE obj;
{
- VALUE klass = rb_class_boot(super);
-
- FL_SET(klass, FL_SINGLETON);
- return klass;
-}
+ VALUE klass = RBASIC(obj)->klass;
-VALUE
-rb_singleton_class_clone(klass)
- VALUE klass;
-{
if (!FL_TEST(klass, FL_SINGLETON))
return klass;
else {
/* copy singleton(unnamed) class */
NEWOBJ(clone, struct RClass);
- CLONESETUP(clone, klass);
+ OBJSETUP(clone, 0, RBASIC(klass)->flags);
+
+ if (BUILTIN_TYPE(obj) == T_CLASS) {
+ RBASIC(clone)->klass = (VALUE)clone;
+ }
+ else {
+ RBASIC(clone)->klass = rb_singleton_class_clone(klass);
+ }
clone->super = RCLASS(klass)->super;
clone->iv_tbl = 0;
@@ -122,6 +121,7 @@ rb_singleton_class_clone(klass)
}
clone->m_tbl = st_init_numtable();
st_foreach(RCLASS(klass)->m_tbl, clone_method, clone->m_tbl);
+ rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
FL_SET(clone, FL_SINGLETON);
return (VALUE)clone;
}
@@ -140,12 +140,17 @@ rb_singleton_class_attached(klass, obj)
}
VALUE
-rb_make_metaclass(obj, klass)
- VALUE obj, klass;
+rb_make_metaclass(obj, super)
+ VALUE obj, super;
{
- klass = rb_singleton_class_new(klass);
+ VALUE klass = rb_class_boot(super);
+ FL_SET(klass, FL_SINGLETON);
RBASIC(obj)->klass = klass;
rb_singleton_class_attached(klass, obj);
+ if (BUILTIN_TYPE(obj) == T_CLASS) {
+ RBASIC(klass)->klass = klass;
+ }
+
return klass;
}
@@ -667,28 +672,12 @@ rb_undef_method(klass, name)
rb_add_method(klass, rb_intern(name), 0, NOEX_UNDEF);
}
-#if 0
-
-#define SPECIAL_SINGLETON(x,c) do {
- if (obj == (x)) {\
- if (!FL_TEST(c, FL_SINGLETON)) {\
- c = rb_singleton_class_new(c);\
- rb_singleton_class_attached(c,obj);\
- }\
- return c;\
- }\
-} while (0)
-
-#else
-
#define SPECIAL_SINGLETON(x,c) do {\
if (obj == (x)) {\
return c;\
}\
} while (0)
-#endif
-
VALUE
rb_singleton_class(obj)
VALUE obj;
@@ -707,13 +696,12 @@ rb_singleton_class(obj)
DEFER_INTS;
if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON) &&
- ((BUILTIN_TYPE(obj) != T_CLASS && BUILTIN_TYPE(obj) != T_MODULE) ||
- rb_iv_get(RBASIC(obj)->klass, "__attached__") == obj)) {
+ (BUILTIN_TYPE(obj) == T_CLASS || /* metaclass (or metaclass of metaclass) */
+ rb_iv_get(RBASIC(obj)->klass, "__attached__") == obj)) {
klass = RBASIC(obj)->klass;
}
else {
klass = rb_make_metaclass(obj, RBASIC(obj)->klass);
- RBASIC(klass)->klass = CLASS_OF(RCLASS(klass)->super);
}
if (OBJ_TAINTED(obj)) {
OBJ_TAINT(klass);
View
@@ -23,7 +23,10 @@ cmp_equal(x, y)
VALUE c = rb_funcall(x, cmp, 1, y);
if (NIL_P(c)) return Qfalse;
- if (NUM2LONG(c) == 0) return Qtrue;
+ if (c == INT2FIX(0)) return Qtrue;
+ if (TYPE(c) == T_BIGNUM) {
+ if (rb_big_norm(c) == INT2FIX(0)) return Qtrue;
+ }
return Qfalse;
}
@@ -34,7 +37,11 @@ cmp_gt(x, y)
VALUE c = rb_funcall(x, cmp, 1, y);
if (NIL_P(c)) return Qfalse;
- if (NUM2LONG(c) > 0) return Qtrue;
+ if (FIXNUM_P(c) && FIX2INT(c) > 0) return Qtrue;
+ if (TYPE(c) == T_BIGNUM) {
+ if (rb_big_norm(x) == INT2FIX(0)) return Qfalse;
+ if (RBIGNUM(c)->sign) return Qtrue;
+ }
return Qfalse;
}
@@ -45,7 +52,11 @@ cmp_ge(x, y)
VALUE c = rb_funcall(x, cmp, 1, y);
if (NIL_P(c)) return Qfalse;
- if (NUM2LONG(c) >= 0) return Qtrue;
+ if (FIXNUM_P(c) && FIX2INT(c) >= 0) return Qtrue;
+ if (TYPE(c) == T_BIGNUM) {
+ if (rb_big_norm(x) == INT2FIX(0)) return Qtrue;
+ if (RBIGNUM(c)->sign) return Qtrue;
+ }
return Qfalse;
}
@@ -55,8 +66,11 @@ cmp_lt(x, y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
- if (NIL_P(c)) return Qfalse;
- if (NUM2LONG(c) < 0) return Qtrue;
+ if (FIXNUM_P(c) && FIX2INT(c) < 0) return Qtrue;
+ if (TYPE(c) == T_BIGNUM) {
+ if (rb_big_norm(x) == INT2FIX(0)) return Qfalse;
+ if (!RBIGNUM(c)->sign) return Qtrue;
+ }
return Qfalse;
}
@@ -67,22 +81,20 @@ cmp_le(x, y)
VALUE c = rb_funcall(x, cmp, 1, y);
if (NIL_P(c)) return Qfalse;
- if (NUM2LONG(c) <= 0) return Qtrue;
+ if (FIXNUM_P(c) && FIX2INT(c) <= 0) return Qtrue;
+ if (TYPE(c) == T_BIGNUM) {
+ if (rb_big_norm(x) == INT2FIX(0)) return Qtrue;
+ if (!RBIGNUM(c)->sign) return Qtrue;
+ }
return Qfalse;
}
static VALUE
cmp_between(x, min, max)
VALUE x, min, max;
{
- VALUE c = rb_funcall(x, cmp, 1, min);
-
- if (NIL_P(c)) return Qfalse;
- if (NUM2LONG(c) < 0) return Qfalse;
-
- c = rb_funcall(x, cmp, 1, max);
- if (NIL_P(c)) return Qfalse;
- if (NUM2LONG(c) > 0) return Qfalse;
+ if (cmp_lt(x, min)) return Qfalse;
+ if (cmp_gt(x, max)) return Qfalse;
return Qtrue;
}
View
@@ -813,6 +813,13 @@ rb_error_frozen(what)
rb_raise(rb_eTypeError, "can't modify frozen %s", what);
}
+void
+rb_check_frozen(obj)
+ VALUE obj;
+{
+ if (OBJ_FROZEN(obj)) rb_error_frozen(rb_class2name(CLASS_OF(obj)));
+}
+
static void
init_syserr()
{
Oops, something went wrong.

0 comments on commit 6f484e4

Please sign in to comment.