diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-12-19 07:48:32 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-12-19 07:48:32 +0000 |
commit | ee87eb1367f14fe43e58dfb9c528de4fd992a260 (patch) | |
tree | ead300989db37caf61cb6dce6c37b9144ff84945 /eval.c | |
parent | 8e8c76bd5f52ed3974448900ce7056628d64c092 (diff) | |
download | ruby-ee87eb1367f14fe43e58dfb9c528de4fd992a260.tar.gz |
* 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".
* string.c: use RESIZE_CAPA for capacity change.
* ext/socket/socket.c (Init_socket): add listen method to
TCPServer and UNIXServer.
* 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/trunk@1923 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 59 |
1 files changed, 43 insertions, 16 deletions
@@ -357,8 +357,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); } } @@ -407,8 +407,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); } } } @@ -457,7 +457,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; @@ -475,15 +477,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)); } } @@ -1581,8 +1583,8 @@ rb_undef(klass, id) rb_name_error(id, "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); if (FL_TEST(klass, FL_SINGLETON)) { rb_funcall(rb_iv_get(klass, "__attached__"), singleton_undefined, 1, ID2SYM(id)); @@ -1630,9 +1632,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); if (FL_TEST(klass, FL_SINGLETON)) { rb_funcall(rb_iv_get(klass, "__attached__"), singleton_added, 1, ID2SYM(name)); @@ -3102,8 +3104,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); @@ -3148,9 +3150,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; } @@ -5711,8 +5713,8 @@ rb_mod_modfunc(argc, argv, module) } m = RCLASS(m)->super; } - 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; @@ -6940,6 +6942,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]); @@ -6948,26 +6952,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 number 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; } |