summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-10-03 07:19:19 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-10-03 07:19:19 +0000
commit1fe40b7cc5e92105f636d670d77b059fe4a4c50b (patch)
tree02dfc7bab198fc494d9d4f1f3bf1072d292fed66 /hash.c
parentd902111a57dfcf3c9b017b0ebd1b49f19142168c (diff)
* marshal.c (r_object): better allocation type check for
TYPE_UCLASS. usage of allocation framework is disabled for now. * variable.c (rb_class_path): Module may have subclass. * string.c (rb_str_update): should maintain original negative offset. * string.c (rb_str_subpat_set): ditto * string.c (rb_str_aset): ditto. * re.c (rb_reg_nth_match): should check negative nth. * re.c (rb_reg_nth_defined): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c38
1 files changed, 12 insertions, 26 deletions
diff --git a/hash.c b/hash.c
index 35d950a..2f9511a 100644
--- a/hash.c
+++ b/hash.c
@@ -172,7 +172,7 @@ rb_hash_foreach(hash, func, farg)
}
static VALUE
-rb_hash_new2(klass)
+rb_hash_s_alloc(klass)
VALUE klass;
{
NEWOBJ(hash, struct RHash);
@@ -187,19 +187,7 @@ rb_hash_new2(klass)
VALUE
rb_hash_new()
{
- return rb_hash_new2(rb_cHash);
-}
-
-static VALUE
-rb_hash_s_new(argc, argv, klass)
- int argc;
- VALUE *argv;
- VALUE klass;
-{
- VALUE hash = rb_hash_new2(klass);
-
- rb_obj_call_init(hash, argc, argv);
- return hash;
+ return rb_hash_s_alloc(rb_cHash);
}
static VALUE
@@ -227,19 +215,18 @@ rb_hash_s_create(argc, argv, klass)
int i;
if (argc == 1 && TYPE(argv[0]) == T_HASH) {
- NEWOBJ(hash, struct RHash);
- OBJSETUP(hash, klass, T_HASH);
+ VALUE hash = rb_obj_alloc(klass);
- hash->ifnone = Qnil;
- hash->tbl = st_copy(RHASH(argv[0])->tbl);
+ RHASH(hash)->ifnone = Qnil;
+ RHASH(hash)->tbl = st_copy(RHASH(argv[0])->tbl);
- return (VALUE)hash;
+ return hash;
}
if (argc % 2 != 0) {
rb_raise(rb_eArgError, "odd number args for Hash");
}
- hash = rb_hash_new2(klass);
+ hash = rb_hash_s_alloc(klass);
for (i=0; i<argc; i+=2) {
st_insert(RHASH(hash)->tbl, argv[i], argv[i+1]);
@@ -252,13 +239,12 @@ static VALUE
rb_hash_clone(hash)
VALUE hash;
{
- NEWOBJ(clone, struct RHash);
- CLONESETUP(clone, hash);
+ VALUE clone = rb_obj_clone(hash);
- clone->ifnone = RHASH(hash)->ifnone;
- clone->tbl = (st_table*)st_copy(RHASH(hash)->tbl);
+ RHASH(clone)->ifnone = RHASH(hash)->ifnone;
+ RHASH(clone)->tbl = (st_table*)st_copy(RHASH(hash)->tbl);
- return (VALUE)clone;
+ return clone;
}
static VALUE
@@ -1454,7 +1440,7 @@ Init_Hash()
rb_include_module(rb_cHash, rb_mEnumerable);
- rb_define_singleton_method(rb_cHash, "new", rb_hash_s_new, -1);
+ rb_define_singleton_method(rb_cHash, "allocate", rb_hash_s_alloc, 0);
rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1);
rb_define_method(rb_cHash,"initialize", rb_hash_initialize, -1);