summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-18 14:48:15 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-18 14:48:15 +0000
commit32378c5abea38a8278dae28eae9abcd547ac8a95 (patch)
tree487ef01d777ec0d46b709b9173dc808becb0f87b
parent74efef0be85061c3c9e24ee0cfdf5f83c2af9a22 (diff)
Merge r16206 and r16239 from ruby_1_8.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@16457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog15
-rw-r--r--class.c73
-rw-r--r--eval.c36
-rw-r--r--intern.h2
-rw-r--r--re.c5
-rw-r--r--version.h8
6 files changed, 104 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index 1ce27b6aab..fe1aab9ea8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Wed Apr 30 17:47:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * re.c (rb_reg_search): use local variable. a patch from wanabe
+ <s.wanabe AT gmail.com> in [ruby-dev:34537]. [ruby-dev:34492]
+
+Sat Apr 26 19:40:34 2008 Guy Decoux <decoux@moulon.inra.fr>
+
+ * class.c (struct clone_method_data): Add cref.
+ (clone_method): Properly handle NODE_BMETHOD and NODE_DMETHOD.
+ (rb_singleton_class_clone, singleton_class_clone_int): Set a
+ proper value to klass and propagate cref. [ruby-core:16238]
+
+ * eval.c (rb_block_dup, rb_method_dup), intern.h: Add duplicator
+ methods for use from class.c#clone_method().
+
Fri Apr 25 15:46:37 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb, ext/tk/lib/tk/scrollbar.rb, ext/tk/lib/tk/scale.rb:
diff --git a/class.c b/class.c
index 106f796140..228d18802a 100644
--- a/class.c
+++ b/class.c
@@ -51,6 +51,7 @@ rb_class_new(super)
struct clone_method_data {
st_table *tbl;
VALUE klass;
+ VALUE cref;
};
static int
@@ -61,16 +62,33 @@ clone_method(mid, body, data)
{
NODE *fbody = body->nd_body;
- if (fbody && nd_type(fbody) == NODE_SCOPE) {
- VALUE cref = data->klass ?
- (VALUE)NEW_NODE(NODE_CREF,data->klass,0,fbody->nd_rval) :
- fbody->nd_rval;
- fbody = NEW_NODE(NODE_SCOPE, fbody->nd_tbl, cref, fbody->nd_next);
+ if (fbody && data->cref) {
+ VALUE body;
+
+ switch (nd_type(fbody)) {
+ case NODE_SCOPE:
+ if (fbody->nd_rval) {
+ NODE *tmp = NEW_NODE(nd_type(fbody->u2.node), data->cref,
+ fbody->u2.node->u2.node, fbody->u2.node->u3.node);
+ fbody = NEW_NODE(nd_type(fbody), fbody->u1.node, tmp, fbody->u3.node);
+ }
+ break;
+ case NODE_BMETHOD:
+ body = rb_block_dup(fbody->nd_cval, data->klass, data->cref);
+ fbody = NEW_BMETHOD(body);
+ break;
+ case NODE_DMETHOD:
+ body = rb_method_dup(fbody->nd_cval, data->klass, data->cref);
+ fbody = NEW_DMETHOD(body);
+ break;
+ }
}
st_insert(data->tbl, mid, (st_data_t)NEW_METHOD(fbody, body->nd_noex));
return ST_CONTINUE;
}
+static VALUE singleton_class_clone_int _((VALUE, VALUE));
+
/* :nodoc: */
VALUE
rb_mod_init_copy(clone, orig)
@@ -78,8 +96,7 @@ rb_mod_init_copy(clone, orig)
{
rb_obj_init_copy(clone, orig);
if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
- RBASIC(clone)->klass = RBASIC(orig)->klass;
- RBASIC(clone)->klass = rb_singleton_class_clone(clone);
+ RBASIC(clone)->klass = singleton_class_clone_int(orig, clone);
}
RCLASS(clone)->super = RCLASS(orig)->super;
if (RCLASS(orig)->iv_tbl) {
@@ -94,9 +111,10 @@ rb_mod_init_copy(clone, orig)
if (RCLASS(orig)->m_tbl) {
struct clone_method_data data;
- data.tbl = RCLASS(clone)->m_tbl = st_init_numtable();
- data.klass = (VALUE)clone;
-
+ RCLASS(clone)->m_tbl = st_init_numtable();
+ data.tbl = RCLASS(clone)->m_tbl;
+ data.klass = clone;
+ data.cref = clone;
st_foreach(RCLASS(orig)->m_tbl, clone_method, (st_data_t)&data);
}
@@ -117,15 +135,16 @@ rb_class_init_copy(clone, orig)
return rb_mod_init_copy(clone, orig);
}
-VALUE
-rb_singleton_class_clone(obj)
- VALUE obj;
+static VALUE
+singleton_class_clone_int(obj, cref)
+ VALUE obj, cref;
{
VALUE klass = RBASIC(obj)->klass;
if (!FL_TEST(klass, FL_SINGLETON))
return klass;
else {
+ struct clone_method_data data;
/* copy singleton(unnamed) class */
NEWOBJ(clone, struct RClass);
OBJSETUP(clone, 0, RBASIC(klass)->flags);
@@ -143,28 +162,24 @@ rb_singleton_class_clone(obj)
if (RCLASS(klass)->iv_tbl) {
clone->iv_tbl = st_copy(RCLASS(klass)->iv_tbl);
}
- {
- struct clone_method_data data;
-
- data.tbl = clone->m_tbl = st_init_numtable();
- switch (TYPE(obj)) {
- case T_CLASS:
- case T_MODULE:
- data.klass = obj;
- break;
- default:
- data.klass = 0;
- break;
- }
-
- st_foreach(RCLASS(klass)->m_tbl, clone_method, (st_data_t)&data);
- }
+ clone->m_tbl = st_init_numtable();
+ data.tbl = clone->m_tbl;
+ data.klass = (VALUE)clone;
+ data.cref = cref;
+ st_foreach(RCLASS(klass)->m_tbl, clone_method, (st_data_t)&data);
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
FL_SET(clone, FL_SINGLETON);
return (VALUE)clone;
}
}
+VALUE
+rb_singleton_class_clone(obj)
+ VALUE obj;
+{
+ return singleton_class_clone_int(obj, 0);
+}
+
void
rb_singleton_class_attached(klass, obj)
VALUE klass, obj;
diff --git a/eval.c b/eval.c
index f691514c26..e665bad6bb 100644
--- a/eval.c
+++ b/eval.c
@@ -8414,6 +8414,19 @@ proc_dup(self)
return bind;
}
+VALUE
+rb_block_dup(self, klass, cref)
+ VALUE self, klass, cref;
+{
+ struct BLOCK *block;
+ VALUE obj = proc_dup(self);
+ Data_Get_Struct(obj, struct BLOCK, block);
+ block->klass = klass;
+ block->cref = NEW_NODE(nd_type(block->cref), cref, block->cref->u2.node,
+ block->cref->u3.node);
+ return obj;
+}
+
/*
* call-seq:
* binding -> a_binding
@@ -9340,6 +9353,29 @@ method_clone(self)
return clone;
}
+VALUE
+rb_method_dup(self, klass, cref)
+ VALUE self;
+ VALUE klass;
+ VALUE cref;
+{
+ VALUE clone;
+ struct METHOD *orig, *data;
+
+ Data_Get_Struct(self, struct METHOD, orig);
+ clone = Data_Make_Struct(CLASS_OF(self),struct METHOD, bm_mark, free, data);
+ *data = *orig;
+ data->rklass = klass;
+ if (data->body->nd_rval) {
+ NODE *tmp = NEW_NODE(nd_type(data->body->u2.node), cref,
+ data->body->u2.node->u2.node,
+ data->body->u2.node->u3.node);
+ data->body = NEW_NODE(nd_type(data->body), data->body->u1.node, tmp,
+ data->body->u3.node);
+ }
+ return clone;
+}
+
/*
* call-seq:
* meth.call(args, ...) => obj
diff --git a/intern.h b/intern.h
index a676720530..e7e06efb0a 100644
--- a/intern.h
+++ b/intern.h
@@ -193,6 +193,8 @@ VALUE rb_require_safe _((VALUE, int));
void rb_obj_call_init _((VALUE, int, VALUE*));
VALUE rb_class_new_instance _((int, VALUE*, VALUE));
VALUE rb_block_proc _((void));
+VALUE rb_block_dup _((VALUE, VALUE, VALUE));
+VALUE rb_method_dup _((VALUE, VALUE, VALUE));
VALUE rb_f_lambda _((void));
VALUE rb_proc_call _((VALUE, VALUE));
VALUE rb_obj_method _((VALUE, VALUE));
diff --git a/re.c b/re.c
index 1a7f9a8c19..c1b1c7e34a 100644
--- a/re.c
+++ b/re.c
@@ -78,7 +78,7 @@ rb_memcicmp(x, y, len)
int tmp;
while (len--) {
- if (tmp = casetable[(unsigned)*p1++] - casetable[(unsigned)*p2++])
+ if ((tmp = casetable[(unsigned)*p1++] - casetable[(unsigned)*p2++]) != 0)
return tmp;
}
return 0;
@@ -892,7 +892,7 @@ rb_reg_search(re, str, pos, reverse)
{
long result;
VALUE match;
- static struct re_registers regs;
+ struct re_registers regs;
long range;
if (pos > RSTRING(str)->len || pos < 0) {
@@ -914,6 +914,7 @@ rb_reg_search(re, str, pos, reverse)
else {
range = RSTRING(str)->len - pos;
}
+ MEMZERO(&regs, struct re_registers, 1);
result = re_search(RREGEXP(re)->ptr,RSTRING(str)->ptr,RSTRING(str)->len,
pos, range, &regs);
diff --git a/version.h b/version.h
index 39e52831aa..5d8c05baa4 100644
--- a/version.h
+++ b/version.h
@@ -1,15 +1,15 @@
#define RUBY_VERSION "1.8.7"
-#define RUBY_RELEASE_DATE "2008-04-25"
+#define RUBY_RELEASE_DATE "2008-05-18"
#define RUBY_VERSION_CODE 187
-#define RUBY_RELEASE_CODE 20080425
+#define RUBY_RELEASE_CODE 20080518
#define RUBY_PATCHLEVEL 0
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8
#define RUBY_VERSION_TEENY 7
#define RUBY_RELEASE_YEAR 2008
-#define RUBY_RELEASE_MONTH 4
-#define RUBY_RELEASE_DAY 25
+#define RUBY_RELEASE_MONTH 5
+#define RUBY_RELEASE_DAY 18
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];