summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-19 07:45:30 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-19 07:45:30 +0000
commitf55f4e1aeb133d1235c4bfe5529b6207b3090aba (patch)
treec641e948e54d12c3a859464f171e092d99b83016 /eval.c
parent74097260aeac51cb2839d90f5cf7eb4c84c9124f (diff)
* eval.c (rb_mod_define_method): define_method should follow
default method visibility. * eval.c (rb_attr): should warn if the default method visibility is "module_function" (can be error). * eval.c (rb_mod_define_method): should define class/module method also if the visibility is "module_function". * eval.c (rb_mod_define_method): should call hook method "method_added", and "singleton_method_added". * ext/socket/socket.c (bsock_send): should raise EWOULDBLOCK exception. * ext/socket/socket.c (s_recvfrom): ditto. * ext/socket/socket.c (s_accept): ditto. * ext/socket/socket.c (udp_send): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c59
1 files changed, 43 insertions, 16 deletions
diff --git a/eval.c b/eval.c
index 60ca4f7831..c0e2dc2012 100644
--- a/eval.c
+++ b/eval.c
@@ -353,8 +353,8 @@ rb_disable_super(klass, name)
body->nd_noex |= NOEX_UNDEF;
}
else {
- rb_add_method(klass, mid, 0, NOEX_UNDEF);
rb_clear_cache_by_id(mid);
+ rb_add_method(klass, mid, 0, NOEX_UNDEF);
}
}
@@ -403,8 +403,8 @@ rb_export_method(klass, name, noex)
body->nd_noex = noex;
}
else {
- rb_add_method(klass, name, NEW_ZSUPER(), noex);
rb_clear_cache_by_id(name);
+ rb_add_method(klass, name, NEW_ZSUPER(), noex);
}
}
}
@@ -453,7 +453,9 @@ rb_attr(klass, id, read, write, ex)
else {
if (SCOPE_TEST(SCOPE_PRIVATE)) {
noex = NOEX_PRIVATE;
- rb_warning("private attribute?");
+ rb_warning((scope_vmode == SCOPE_MODFUNC) ?
+ "attribute accessor as module_function" :
+ "private attribute?");
}
else if (SCOPE_TEST(SCOPE_PROTECTED)) {
noex = NOEX_PROTECTED;
@@ -471,15 +473,15 @@ rb_attr(klass, id, read, write, ex)
sprintf(buf, "@%s", name);
attriv = rb_intern(buf);
if (read) {
- rb_add_method(klass, id, NEW_IVAR(attriv), noex);
rb_clear_cache_by_id(id);
+ rb_add_method(klass, id, NEW_IVAR(attriv), noex);
rb_funcall(klass, added, 1, ID2SYM(id));
}
if (write) {
sprintf(buf, "%s=", name);
id = rb_intern(buf);
- rb_add_method(klass, id, NEW_ATTRSET(attriv), noex);
rb_clear_cache_by_id(id);
+ rb_add_method(klass, id, NEW_ATTRSET(attriv), noex);
rb_funcall(klass, added, 1, ID2SYM(id));
}
}
@@ -1547,8 +1549,8 @@ rb_undef(klass, id)
rb_raise(rb_eNameError, "undefined method `%s' for%s `%s'",
rb_id2name(id),s0,rb_class2name(c));
}
- rb_add_method(klass, id, 0, NOEX_PUBLIC);
rb_clear_cache_by_id(id);
+ rb_add_method(klass, id, 0, NOEX_PUBLIC);
}
static VALUE
@@ -1589,9 +1591,9 @@ rb_alias(klass, name, def)
body = body->nd_head;
}
+ rb_clear_cache_by_id(name);
st_insert(RCLASS(klass)->m_tbl, name,
NEW_METHOD(NEW_FBODY(body, def, origin), orig->nd_noex));
- rb_clear_cache_by_id(name);
}
static VALUE
@@ -2979,8 +2981,8 @@ rb_eval(self, n)
}
defn = copy_node_scope(node->nd_defn, ruby_cref);
- rb_add_method(ruby_class, node->nd_mid, defn, noex);
rb_clear_cache_by_id(node->nd_mid);
+ rb_add_method(ruby_class, node->nd_mid, defn, noex);
if (scope_vmode == SCOPE_MODFUNC) {
rb_add_method(rb_singleton_class(ruby_class),
node->nd_mid, defn, NOEX_PUBLIC);
@@ -3025,9 +3027,9 @@ rb_eval(self, n)
}
defn = copy_node_scope(node->nd_defn, ruby_cref);
defn->nd_rval = (VALUE)ruby_cref;
+ rb_clear_cache_by_id(node->nd_mid);
rb_add_method(klass, node->nd_mid, defn,
NOEX_PUBLIC|(body?body->nd_noex&NOEX_UNDEF:0));
- rb_clear_cache_by_id(node->nd_mid);
rb_funcall(recv, singleton_added, 1, ID2SYM(node->nd_mid));
result = Qnil;
}
@@ -5634,8 +5636,8 @@ rb_mod_modfunc(argc, argv, module)
if (body == 0 || body->nd_body == 0) {
rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
}
- rb_add_method(rb_singleton_class(module), id, body->nd_body, NOEX_PUBLIC);
rb_clear_cache_by_id(id);
+ rb_add_method(rb_singleton_class(module), id, body->nd_body, NOEX_PUBLIC);
rb_funcall(module, singleton_added, 1, ID2SYM(id));
}
return module;
@@ -6862,6 +6864,8 @@ rb_mod_define_method(argc, argv, mod)
{
ID id;
VALUE body;
+ NODE *node;
+ int noex;
if (argc == 1) {
id = rb_to_id(argv[0]);
@@ -6870,26 +6874,49 @@ rb_mod_define_method(argc, argv, mod)
else if (argc == 2) {
id = rb_to_id(argv[0]);
body = argv[1];
+ if (rb_obj_is_kind_of(body, rb_cMethod)) {
+ body = method_proc(body);
+ }
+ else if (!rb_obj_is_proc(body)) {
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc)",
+ rb_class2name(CLASS_OF(body)));
+ }
}
else {
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)", argc);
}
- if (TYPE(body) != T_DATA) {
- /* type error */
- rb_raise(rb_eTypeError, "wrong argument type (expected Proc)");
- }
if (RDATA(body)->dmark == (RUBY_DATA_FUNC)bm_mark) {
- rb_add_method(mod, id, NEW_DMETHOD(method_unbind(body)), NOEX_PUBLIC);
+ node = NEW_DMETHOD(method_unbind(body));
}
else if (RDATA(body)->dmark == (RUBY_DATA_FUNC)blk_mark) {
- rb_add_method(mod, id, NEW_BMETHOD(body), NOEX_PUBLIC);
+ node = NEW_BMETHOD(body);
}
else {
/* type error */
rb_raise(rb_eTypeError, "wrong argument type (expected Proc)");
}
+ if (SCOPE_TEST(SCOPE_PRIVATE)) {
+ noex = NOEX_PRIVATE;
+ }
+ else if (SCOPE_TEST(SCOPE_PROTECTED)) {
+ noex = NOEX_PROTECTED;
+ }
+ else {
+ noex = NOEX_PUBLIC;
+ }
rb_clear_cache_by_id(id);
+ rb_add_method(mod, id, node, noex);
+ if (scope_vmode == SCOPE_MODFUNC) {
+ rb_add_method(rb_singleton_class(mod), id, node, NOEX_PUBLIC);
+ rb_funcall(mod, singleton_added, 1, ID2SYM(id));
+ }
+ if (FL_TEST(mod, FL_SINGLETON)) {
+ rb_funcall(rb_iv_get(mod, "__attached__"), singleton_added, 1, ID2SYM(id));
+ }
+ else {
+ rb_funcall(mod, added, 1, ID2SYM(id));
+ }
return body;
}