summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-27 08:31:08 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-27 08:31:08 +0000
commitc45908e41f47c88674b73a754ecd0535449b667a (patch)
treea27bb0f2ca80fa80b9582ddcb8312eee673b0bd5 /hash.c
parentcd3d4a01f248fad1a73ff0b66b7a8d1653f64c19 (diff)
* file.c (rb_find_file): $LOAD_PATH must not be empty.
* file.c (rb_find_file_ext): ditto. * range.c (range_eq): class check should be based on range.class, instead of Range to work with Range.dup. * range.c (range_eql): ditto. * class.c (rb_mod_dup): need to preserve metaclass and flags. * object.c (rb_cstr_to_dbl): had a buffer overrun. * marshal.c (w_class): integrate singleton check into a funciton to follow DRY principle. * marshal.c (w_uclass): should check singleton method. * object.c (rb_obj_dup): dmark and dfree functions must be match for T_DATA type. * object.c (rb_obj_dup): class of the duped object must be match to the class of the original. * re.c (rb_reg_quote): do not escape \t, \f, \r, \n, for they are not regular expression metacharacters. * time.c (time_s_alloc): use time_free instead of free (null check, also serves for type mark). * time.c (time_s_at): check dfree function too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c44
1 files changed, 17 insertions, 27 deletions
diff --git a/hash.c b/hash.c
index 46b7cec..e7fa574 100644
--- a/hash.c
+++ b/hash.c
@@ -248,37 +248,28 @@ rb_hash_s_create(argc, argv, klass)
}
static VALUE
-rb_hash_clone(hash)
+to_hash(hash)
VALUE hash;
{
- VALUE clone = rb_obj_clone(hash);
-
- RHASH(clone)->ifnone = RHASH(hash)->ifnone;
- RHASH(clone)->tbl = (st_table*)st_copy(RHASH(hash)->tbl);
-
- return clone;
+ return rb_convert_type(hash, T_HASH, "Hash", "to_hash");
}
static VALUE
-rb_hash_dup(hash)
- VALUE hash;
+rb_hash_become(copy, orig)
+ VALUE copy, orig;
{
- VALUE dup = rb_obj_dup(hash);
-
- if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
- FL_SET(dup, HASH_PROC_DEFAULT);
+ orig = to_hash(orig);
+ if (RHASH(copy)->tbl) st_free_table(RHASH(copy)->tbl);
+ RHASH(copy)->tbl = (st_table*)st_copy(RHASH(orig)->tbl);
+ RHASH(copy)->ifnone = RHASH(orig)->ifnone;
+ if (FL_TEST(orig, HASH_PROC_DEFAULT)) {
+ FL_SET(copy, HASH_PROC_DEFAULT);
}
- if (FL_TEST(hash, HASH_DELETED)) {
- FL_SET(dup, HASH_DELETED);
+ if (FL_TEST(orig, HASH_DELETED)) {
+ FL_SET(copy, HASH_DELETED);
}
- return dup;
-}
-static VALUE
-to_hash(hash)
- VALUE hash;
-{
- return rb_convert_type(hash, T_HASH, "Hash", "to_hash");
+ return copy;
}
static int
@@ -983,7 +974,7 @@ env_delete(obj, name)
char *nam, *val;
rb_secure(4);
- StringValue(name);
+ SafeStringValue(name);
nam = RSTRING(name)->ptr;
if (strlen(nam) != RSTRING(name)->len) {
rb_raise(rb_eArgError, "bad environment variable name");
@@ -994,9 +985,9 @@ env_delete(obj, name)
ruby_setenv(nam, 0);
#ifdef __BORLANDC__
- if (strcmpi(nam, "PATH") == 0 && !OBJ_TAINTED(name)) {
+ if (strcmpi(nam, "PATH") == 0) {
#else
- if (strcmp(nam, "PATH") == 0 && !OBJ_TAINTED(name)) {
+ if (strcmp(nam, "PATH") == 0) {
#endif
path_tainted = 0;
}
@@ -1616,8 +1607,7 @@ Init_Hash()
rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1);
rb_define_method(rb_cHash,"initialize", rb_hash_initialize, -1);
- rb_define_method(rb_cHash,"clone", rb_hash_clone, 0);
- rb_define_method(rb_cHash,"dup", rb_hash_dup, 0);
+ rb_define_method(rb_cHash,"become", rb_hash_become, 1);
rb_define_method(rb_cHash,"rehash", rb_hash_rehash, 0);
rb_define_method(rb_cHash,"to_hash", rb_hash_to_hash, 0);