summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-16 07:11:30 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-16 07:11:30 +0000
commit7406260aed6598b4e2769b22c3a1532da85dbe7a (patch)
treeddb494cb3bbba681c83ae0bed6828273df28cff7
parent0caa77e7bceca57b9d684728fbef63790f927424 (diff)
* eval.c (rb_disable_super, rb_enable_super): deprecate.
* eval.c (thgroup_s_alloc): re-implement group struct. * eval.c (thgroup_add): add check for enclose and frozen status. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--class.c11
-rw-r--r--eval.c114
-rw-r--r--ext/stringio/stringio.c1
-rw-r--r--ext/win32ole/win32ole.c4
-rw-r--r--node.h1
6 files changed, 78 insertions, 61 deletions
diff --git a/ChangeLog b/ChangeLog
index dbbc7b9d6c..66d256bdd6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed Jul 16 00:31:00 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (rb_disable_super, rb_enable_super): deprecate.
+
+ * eval.c (thgroup_s_alloc): re-implement group struct.
+
+ * eval.c (thgroup_add): add check for enclose and frozen status.
+
Tue Jul 15 19:50:49 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* eval.c (rb_add_method, rb_alias): need to clear cache by
diff --git a/class.c b/class.c
index 409d5d6957..524c56a450 100644
--- a/class.c
+++ b/class.c
@@ -646,7 +646,7 @@ rb_define_method_id(klass, name, func, argc)
VALUE (*func)();
int argc;
{
- rb_add_method(klass, name, NEW_CFUNC(func,argc), NOEX_PUBLIC|NOEX_CFUNC);
+ rb_add_method(klass, name, NEW_CFUNC(func,argc), NOEX_PUBLIC);
}
void
@@ -660,9 +660,6 @@ rb_define_method(klass, name, func, argc)
int ex = NOEX_PUBLIC;
- if (BUILTIN_TYPE(klass) == T_CLASS) {
- ex |= NOEX_CFUNC;
- }
rb_add_method(klass, id, NEW_CFUNC(func, argc), ex);
}
@@ -673,8 +670,7 @@ rb_define_protected_method(klass, name, func, argc)
VALUE (*func)();
int argc;
{
- rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc),
- NOEX_PROTECTED|NOEX_CFUNC);
+ rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PROTECTED);
}
void
@@ -684,8 +680,7 @@ rb_define_private_method(klass, name, func, argc)
VALUE (*func)();
int argc;
{
- rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc),
- NOEX_PRIVATE|NOEX_CFUNC);
+ rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PRIVATE);
}
void
diff --git a/eval.c b/eval.c
index dc744756dd..4a3850c0e6 100644
--- a/eval.c
+++ b/eval.c
@@ -283,7 +283,7 @@ rb_add_method(klass, mid, node, noex)
if (!FL_TEST(klass, FL_SINGLETON) &&
node && nd_type(node) != NODE_ZSUPER &&
(mid == rb_intern("initialize" )|| mid == rb_intern("initialize_copy"))) {
- noex = NOEX_PRIVATE | (noex & NOEX_NOSUPER);
+ noex = NOEX_PRIVATE | noex;
}
else if (FL_TEST(klass, FL_SINGLETON) && node && nd_type(node) == NODE_CFUNC &&
mid == rb_intern("allocate")) {
@@ -459,20 +459,7 @@ rb_disable_super(klass, name)
VALUE klass;
const char *name;
{
- VALUE origin;
- NODE *body;
- ID mid = rb_intern(name);
-
- body = search_method(klass, mid, &origin);
- if (!body || !body->nd_body) {
- print_undef(klass, mid);
- }
- if (origin == klass) {
- body->nd_noex |= NOEX_NOSUPER;
- }
- else {
- rb_add_method(klass, mid, 0, NOEX_UNDEF);
- }
+ /* obsolete - no use */
}
void
@@ -480,20 +467,7 @@ rb_enable_super(klass, name)
VALUE klass;
const char *name;
{
- VALUE origin;
- NODE *body;
- ID mid = rb_intern(name);
-
- body = search_method(klass, mid, &origin);
- if (!body) {
- print_undef(klass, mid);
- }
- if (!body->nd_body) {
- remove_method(klass, mid);
- }
- else {
- body->nd_noex &= ~NOEX_NOSUPER;
- }
+ rb_warning("rb_enable_super() is obsolete");
}
static void
@@ -5222,8 +5196,7 @@ rb_call_super(argc, argv)
VALUE result, self, klass, k;
if (ruby_frame->last_class == 0) {
- rb_name_error(ruby_frame->last_func,
- "superclass method `%s' must be enabled by rb_enable_super()",
+ rb_name_error(ruby_frame->last_func, "calling `super' from `%s' is prohibited",
rb_id2name(ruby_frame->last_func));
}
@@ -7870,7 +7843,7 @@ struct thread {
int abort;
int priority;
- int gid;
+ VALUE thgroup;
st_table *locals;
@@ -8326,7 +8299,7 @@ static void
rb_thread_die(th)
rb_thread_t th;
{
- th->gid = 0;
+ th->thgroup = 0;
th->status = THREAD_KILLED;
if (th->stk_ptr) free(th->stk_ptr);
th->stk_ptr = 0;
@@ -9012,7 +8985,7 @@ rb_thread_kill(thread)
if (th == th->next || th == main_thread) rb_exit(0);
rb_thread_ready(th);
- th->gid = 0;
+ th->thgroup = 0;
th->status = THREAD_TO_KILL;
if (!rb_thread_critical) rb_thread_schedule();
return thread;
@@ -9134,6 +9107,7 @@ rb_thread_safe_level(thread)
}
static int thread_abort;
+static VALUE thgroup_default;
static VALUE
rb_thread_s_abort_exc()
@@ -9202,7 +9176,7 @@ rb_thread_abort_exc_set(thread, val)
th->last_match = Qnil;\
th->abort = 0;\
th->priority = 0;\
- th->gid = 1;\
+ th->thgroup = thgroup_default;\
th->locals = 0;\
} while (0)
@@ -9315,7 +9289,7 @@ rb_thread_start_0(fn, arg, th_arg)
th->next = curr_thread->next;
curr_thread->next = th;
th->priority = curr_thread->priority;
- th->gid = curr_thread->gid;
+ th->thgroup = curr_thread->thgroup;
}
PUSH_TAG(PROT_THREAD);
@@ -9528,7 +9502,7 @@ rb_thread_cleanup()
FOREACH_THREAD_FROM(curr, th) {
if (th->status != THREAD_KILLED) {
rb_thread_ready(th);
- th->gid = 0;
+ th->thgroup = 0;
th->priority = 0;
if (th != main_thread) {
th->status = THREAD_TO_KILL;
@@ -9864,7 +9838,8 @@ rb_cont_call(argc, argv, cont)
}
struct thgroup {
- int gid;
+ int enclosed;
+ VALUE group;
};
static VALUE thgroup_s_alloc _((VALUE));
@@ -9874,10 +9849,10 @@ thgroup_s_alloc(klass)
{
VALUE group;
struct thgroup *data;
- static int serial = 1;
group = Data_Make_Struct(klass, struct thgroup, 0, free, data);
- data->gid = serial++;
+ data->enclosed = 0;
+ data->group = group;
return group;
}
@@ -9894,7 +9869,7 @@ thgroup_list(group)
ary = rb_ary_new();
FOREACH_THREAD(th) {
- if (th->gid == data->gid) {
+ if (th->thgroup == data->group) {
rb_ary_push(ary, th->thread);
}
}
@@ -9903,6 +9878,30 @@ thgroup_list(group)
return ary;
}
+VALUE
+thgroup_enclose(group)
+ VALUE group;
+{
+ struct thgroup *data;
+ rb_thread_t th;
+
+ Data_Get_Struct(group, struct thgroup, data);
+ data->enclosed = 1;
+
+ return group;
+}
+
+static VALUE
+thgroup_enclosed_p(group)
+ VALUE group;
+{
+ struct thgroup *data;
+
+ Data_Get_Struct(group, struct thgroup, data);
+ if (data->enclosed) return Qtrue;
+ return Qfalse;
+}
+
static VALUE
thgroup_add(group, thread)
VALUE group, thread;
@@ -9912,9 +9911,27 @@ thgroup_add(group, thread)
rb_secure(4);
th = rb_thread_check(thread);
+
+ if (OBJ_FROZEN(th->thgroup)) {
+ rb_raise(rb_eThreadError, "can't move from the frozen thread group");
+ }
+ if (!th->thgroup) {
+ rb_raise(rb_eThreadError, "terminated thread");
+ }
+ Data_Get_Struct(th->thgroup, struct thgroup, data);
+ if (data->enclosed) {
+ rb_raise(rb_eThreadError, "can't move from the enclosed thread group");
+ }
+
+ if (OBJ_FROZEN(group)) {
+ rb_raise(rb_eThreadError, "can't move to the frozen thread group");
+ }
Data_Get_Struct(group, struct thgroup, data);
+ if (data->enclosed) {
+ rb_raise(rb_eThreadError, "can't move to the enclosed thread group");
+ }
- th->gid = data->gid;
+ th->thgroup = group;
return group;
}
@@ -9972,10 +9989,6 @@ Init_Thread()
rb_define_method(rb_cThread, "inspect", rb_thread_inspect, 0);
- /* allocate main thread */
- main_thread = rb_thread_alloc(rb_cThread);
- curr_thread = main_thread->prev = main_thread->next = main_thread;
-
rb_cCont = rb_define_class("Continuation", rb_cObject);
rb_undef_alloc_func(rb_cCont);
rb_undef_method(CLASS_OF(rb_cCont), "new");
@@ -9985,8 +9998,15 @@ Init_Thread()
cThGroup = rb_define_class("ThreadGroup", rb_cObject);
rb_define_alloc_func(cThGroup, thgroup_s_alloc);
rb_define_method(cThGroup, "list", thgroup_list, 0);
+ rb_define_method(cThGroup, "enclose", thgroup_enclose, 0);
+ rb_define_method(cThGroup, "enclosed?", thgroup_enclosed_p, 0);
rb_define_method(cThGroup, "add", thgroup_add, 1);
- rb_define_const(cThGroup, "Default", rb_obj_alloc(cThGroup));
+ thgroup_default = rb_obj_alloc(cThGroup);
+ rb_define_const(cThGroup, "Default", thgroup_default);
+
+ /* allocate main thread */
+ main_thread = rb_thread_alloc(rb_cThread);
+ curr_thread = main_thread->prev = main_thread->next = main_thread;
}
static VALUE
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 93d7460daf..4dff4e1ebf 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -899,7 +899,6 @@ Init_stringio()
rb_define_alloc_func(StringIO, strio_s_allocate);
rb_define_singleton_method(StringIO, "open", strio_s_open, -1);
rb_define_method(StringIO, "initialize", strio_initialize, -1);
- rb_enable_super(StringIO, "initialize");
rb_define_method(StringIO, "copy_object", strio_copy, 1);
rb_define_method(StringIO, "reopen", strio_reopen, -1);
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index b8b5bcf471..2429663a5f 100644
--- a/ext/win32ole/win32ole.c
+++ b/ext/win32ole/win32ole.c
@@ -5275,7 +5275,6 @@ Init_win32ole()
rb_define_alloc_func(cWIN32OLE, fole_s_allocate);
rb_define_method(cWIN32OLE, "initialize", fole_initialize, -1);
- rb_enable_super(cWIN32OLE, "initialize");
rb_define_singleton_method(cWIN32OLE, "connect", fole_s_connect, -1);
rb_define_singleton_method(cWIN32OLE, "const_load", fole_s_const_load, -1);
@@ -5344,7 +5343,6 @@ Init_win32ole()
rb_define_singleton_method(cWIN32OLE_TYPE, "progids", foletype_s_progids, 0);
rb_define_alloc_func(cWIN32OLE_TYPE, foletype_s_allocate);
rb_define_method(cWIN32OLE_TYPE, "initialize", foletype_initialize, 2);
- rb_enable_super(cWIN32OLE_TYPE, "initialize");
rb_define_method(cWIN32OLE_TYPE, "name", foletype_name, 0);
rb_define_method(cWIN32OLE_TYPE, "ole_type", foletype_ole_type, 0);
rb_define_method(cWIN32OLE_TYPE, "guid", foletype_guid, 0);
@@ -5375,7 +5373,6 @@ Init_win32ole()
cWIN32OLE_METHOD = rb_define_class("WIN32OLE_METHOD", rb_cObject);
rb_define_alloc_func(cWIN32OLE_METHOD, folemethod_s_allocate);
rb_define_method(cWIN32OLE_METHOD, "initialize", folemethod_initialize, 2);
- rb_enable_super(cWIN32OLE_METHOD, "initialize");
rb_define_method(cWIN32OLE_METHOD, "name", folemethod_name, 0);
rb_define_method(cWIN32OLE_METHOD, "return_type", folemethod_return_type, 0);
@@ -5411,7 +5408,6 @@ Init_win32ole()
rb_define_alloc_func(cWIN32OLE_EVENT, fev_s_allocate);
rb_define_method(cWIN32OLE_EVENT, "initialize", fev_initialize, -1);
- rb_enable_super(cWIN32OLE_EVENT, "initialize");
rb_define_singleton_method(cWIN32OLE_EVENT, "message_loop", fev_s_msg_loop, 0);
rb_define_method(cWIN32OLE_EVENT, "on_event", fev_on_event, -1);
diff --git a/node.h b/node.h
index a8cf320f05..e335c8dfc4 100644
--- a/node.h
+++ b/node.h
@@ -346,7 +346,6 @@ typedef struct RNode {
#define NOEX_MASK 6
#define NOEX_UNDEF NOEX_NOSUPER
-#define NOEX_CFUNC NOEX_NOSUPER
NODE *rb_compile_cstr _((const char*, const char*, int, int));
NODE *rb_compile_string _((const char*, VALUE, int));