From 469c1f3f40f279906aceceb7cd4aef80eeffd642 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Date: Mon, 4 Jun 2001 09:02:30 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'v1_6_4'. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_6_4@1498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 73 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 4e3d5dd856..1656bd319c 100644 --- a/object.c +++ b/object.c @@ -162,6 +162,7 @@ inspect_i(id, value, str) if (!rb_is_instance_id(id)) return ST_CONTINUE; if (RSTRING(str)->ptr[0] == '-') { /* first element */ RSTRING(str)->ptr[0] = '#'; + rb_str_cat2(str, " "); } else { rb_str_cat2(str, ", "); @@ -182,6 +183,7 @@ inspect_obj(obj, str) { st_foreach(ROBJECT(obj)->iv_tbl, inspect_i, str); rb_str_cat2(str, ">"); + RSTRING(str)->ptr[0] = '#'; OBJ_INFECT(str, obj); return str; @@ -227,12 +229,10 @@ rb_obj_is_instance_of(obj, c) return Qfalse; case T_FALSE: - if (obj) return Qfalse; - return Qtrue; + return RTEST(obj) ? Qfalse : Qtrue; case T_TRUE: - if (obj) return Qtrue; - return Qfalse; + return RTEST(obj) ? Qtrue : Qfalse; default: rb_raise(rb_eTypeError, "class or module required"); @@ -286,7 +286,12 @@ rb_obj_taint(obj) VALUE obj; { rb_secure(4); - OBJ_TAINT(obj); + if (!OBJ_TAINTED(obj)) { + if (OBJ_FROZEN(obj)) { + rb_error_frozen("object"); + } + OBJ_TAINT(obj); + } return obj; } @@ -295,7 +300,12 @@ rb_obj_untaint(obj) VALUE obj; { rb_secure(3); - FL_UNSET(obj, FL_TAINT); + if (OBJ_TAINTED(obj)) { + if (OBJ_FROZEN(obj)) { + rb_error_frozen("object"); + } + FL_UNSET(obj, FL_TAINT); + } return obj; } @@ -513,33 +523,6 @@ sym_to_s(sym) return rb_str_new2(rb_id2name(SYM2ID(sym))); } -static VALUE -rb_mod_clone(module) - VALUE module; -{ - NEWOBJ(clone, struct RClass); - CLONESETUP(clone, module); - - clone->super = RCLASS(module)->super; - if (RCLASS(module)->iv_tbl) { - clone->iv_tbl = st_copy(RCLASS(module)->iv_tbl); - } - if (RCLASS(module)->m_tbl) { - clone->m_tbl = st_copy(RCLASS(module)->m_tbl); - } - - return (VALUE)clone; -} - -static VALUE -rb_mod_dup(module) - VALUE module; -{ - VALUE dup = rb_mod_clone(module); - OBJSETUP(dup, RBASIC(module)->klass, BUILTIN_TYPE(module)); - return dup; -} - static VALUE rb_mod_to_s(klass) VALUE klass; @@ -776,14 +759,24 @@ static VALUE rb_mod_const_get(mod, name) VALUE mod, name; { - return rb_const_get(mod, rb_to_id(name)); + ID id = rb_to_id(name); + + if (!rb_is_const_id(id)) { + rb_raise(rb_eNameError, "wrong constant name %s", name); + } + return rb_const_get(mod, id); } static VALUE rb_mod_const_set(mod, name, value) VALUE mod, name, value; { - rb_const_set(mod, rb_to_id(name), value); + ID id = rb_to_id(name); + + if (!rb_is_const_id(id)) { + rb_raise(rb_eNameError, "wrong constant name %s", name); + } + rb_const_set(mod, id, value); return value; } @@ -791,7 +784,12 @@ static VALUE rb_mod_const_defined(mod, name) VALUE mod, name; { - return rb_const_defined_at(mod, rb_to_id(name)); + ID id = rb_to_id(name); + + if (!rb_is_const_id(id)) { + rb_raise(rb_eNameError, "wrong constant name %s", name); + } + return rb_const_defined_at(mod, id); } static VALUE @@ -1036,6 +1034,9 @@ rb_str2cstr(str, len) str = rb_str_to_str(str); } if (len) *len = RSTRING(str)->len; + else if (ruby_verbose && RSTRING(str)->len != strlen(RSTRING(str)->ptr)) { + rb_warn("string contains \\0 character"); + } return RSTRING(str)->ptr; } -- cgit v1.2.3