Skip to content

Commit

Permalink
* variable.c (rb_copy_generic_ivar): remove old generic instance
Browse files Browse the repository at this point in the history
	  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
matz committed Sep 3, 2002
1 parent 20254d4 commit 6f484e4
Show file tree
Hide file tree
Showing 22 changed files with 277 additions and 239 deletions.
41 changes: 41 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ Mon Sep 2 21:21:46 2002 Minero Aoki <[email protected]>

* intern.h (ruby_parser_stack_on_heap): added.

Mon Sep 2 18:45:07 2002 Yukihiro Matsumoto <[email protected]>

* variable.c (rb_copy_generic_ivar): remove old generic instance
variable table if it existes.

Sun Sep 1 15:54:33 2002 WATANABE Hirofumi <[email protected]>

* config.guess: fixed for Linux/PPC.

Sat Aug 31 09:38:12 2002 Yukihiro Matsumoto <[email protected]>

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

Fri Aug 30 22:45:16 2002 Akinori MUSHA <[email protected]>

* lib/set.rb: Added.
Expand Down Expand Up @@ -45,6 +55,37 @@ Fri Aug 30 19:40:28 2002 Nobuyoshi Nakada <[email protected]>

* ext/tcltklib/tcltklib.c (ip_toUTF8, ip_fromUTF8): ditto.

Fri Aug 30 01:32:17 2002 Yukihiro Matsumoto <[email protected]>

* 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 <[email protected]>

* bcc32/MakeFile.sub (sitearch): add.
Expand Down
38 changes: 15 additions & 23 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
56 changes: 22 additions & 34 deletions class.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
40 changes: 26 additions & 14 deletions compar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions error.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading

0 comments on commit 6f484e4

Please sign in to comment.