mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
8e8c76bd5f
commit
ee87eb1367
6 changed files with 104 additions and 59 deletions
34
ChangeLog
34
ChangeLog
|
@ -1,9 +1,32 @@
|
|||
Wed Dec 19 14:05:00 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* 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".
|
||||
|
||||
Wed Dec 19 11:42:13 2001 K.Kosako <kosako@sofnec.co.jp>
|
||||
|
||||
* string.c: use RESIZE_CAPA for capacity change.
|
||||
|
||||
Wed Dec 19 03:08:40 2001 Tanaka Akira <akr@m17n.org>
|
||||
|
||||
* lib/time.rb: date.rb is not required anymore.
|
||||
|
||||
* lib/resolv.rb: fix document. refine IPv6 regex.
|
||||
|
||||
Tue Dec 18 23:24:53 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* ext/socket/socket.c (Init_socket): add listen method to
|
||||
TCPServer and UNIXServer.
|
||||
|
||||
Tue Dec 18 17:54:53 2001 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||
|
||||
* sample/test.rb: Hash#indexes -> Hash#select.
|
||||
|
@ -264,6 +287,17 @@ Wed Dec 5 23:36:56 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
|||
|
||||
* regex.c (WC2MBC1ST): should not pass through > 0x80 number in UTF-8.
|
||||
|
||||
Wed Dec 5 20:05:18 2001 Florian Frank <flori@ping.de>
|
||||
|
||||
* 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.
|
||||
|
||||
Tue Dec 4 17:43:10 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* ruby.h (DUPSETUP): new SETUP macro for duplication.
|
||||
|
|
59
eval.c
59
eval.c
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -385,12 +385,6 @@ bsock_send(argc, argv, sock)
|
|||
case EINTR:
|
||||
rb_thread_schedule();
|
||||
goto retry;
|
||||
case EWOULDBLOCK:
|
||||
#if EAGAIN != EWOULDBLOCK
|
||||
case EAGAIN:
|
||||
#endif
|
||||
rb_thread_fd_writable(fd);
|
||||
goto retry;
|
||||
}
|
||||
rb_sys_fail("send(2)");
|
||||
}
|
||||
|
@ -448,12 +442,6 @@ s_recvfrom(sock, argc, argv, from)
|
|||
case EINTR:
|
||||
rb_thread_schedule();
|
||||
goto retry;
|
||||
|
||||
case EWOULDBLOCK:
|
||||
#if EAGAIN != EWOULDBLOCK
|
||||
case EAGAIN:
|
||||
#endif
|
||||
goto retry;
|
||||
}
|
||||
rb_sys_fail("recvfrom(2)");
|
||||
}
|
||||
|
@ -1119,12 +1107,6 @@ s_accept(class, fd, sockaddr, len)
|
|||
case EINTR:
|
||||
rb_thread_schedule();
|
||||
goto retry;
|
||||
|
||||
case EWOULDBLOCK:
|
||||
#if EAGAIN != EWOULDBLOCK
|
||||
case EAGAIN:
|
||||
#endif
|
||||
goto retry;
|
||||
}
|
||||
rb_sys_fail(0);
|
||||
}
|
||||
|
@ -1345,13 +1327,6 @@ udp_send(argc, argv, sock)
|
|||
case EINTR:
|
||||
rb_thread_schedule();
|
||||
goto retry;
|
||||
|
||||
case EWOULDBLOCK:
|
||||
#if EAGAIN != EWOULDBLOCK
|
||||
case EAGAIN:
|
||||
#endif
|
||||
rb_thread_fd_writable(fileno(f));
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
freeaddrinfo(res0);
|
||||
|
@ -2188,6 +2163,7 @@ Init_socket()
|
|||
rb_define_singleton_method(rb_cTCPServer, "open", tcp_svr_s_open, -1);
|
||||
rb_define_singleton_method(rb_cTCPServer, "new", tcp_svr_s_open, -1);
|
||||
rb_define_method(rb_cTCPServer, "accept", tcp_accept, 0);
|
||||
rb_define_method(rb_cTCPServer, "listen", sock_listen, 1);
|
||||
|
||||
rb_cUDPSocket = rb_define_class("UDPSocket", rb_cIPSocket);
|
||||
rb_define_global_const("UDPsocket", rb_cUDPSocket);
|
||||
|
@ -2212,6 +2188,7 @@ Init_socket()
|
|||
rb_define_singleton_method(rb_cUNIXServer, "open", unix_svr_s_open, 1);
|
||||
rb_define_singleton_method(rb_cUNIXServer, "new", unix_svr_s_open, 1);
|
||||
rb_define_method(rb_cUNIXServer, "accept", unix_accept, 0);
|
||||
rb_define_method(rb_cUNIXServer, "listen", sock_listen, 1);
|
||||
#endif
|
||||
|
||||
rb_cSocket = rb_define_class("Socket", rb_cBasicSocket);
|
||||
|
|
11
io.c
11
io.c
|
@ -512,11 +512,16 @@ io_fread(ptr, len, f)
|
|||
if (c == EOF) {
|
||||
eof:
|
||||
if (ferror(f)) {
|
||||
if (errno == EINTR) continue;
|
||||
if (errno == EAGAIN) return len - n;
|
||||
switch (errno) {
|
||||
case EINTR:
|
||||
continue;
|
||||
|
||||
case EAGAIN:
|
||||
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
|
||||
if (errno == EWOULDBLOCK) return len - n;
|
||||
case EWOULDBLOCK:
|
||||
#endif
|
||||
return len - n;
|
||||
}
|
||||
rb_sys_fail(0);
|
||||
}
|
||||
*ptr = '\0';
|
||||
|
|
28
string.c
28
string.c
|
@ -29,6 +29,11 @@ VALUE rb_cString;
|
|||
|
||||
#define STR_ASSOC FL_USER3
|
||||
|
||||
#define RESIZE_CAPA(str,capacity) do {\
|
||||
REALLOC_N(RSTRING(str)->ptr, char, (capacity)+1);\
|
||||
RSTRING(str)->aux.capa = (capacity);\
|
||||
} while (0)
|
||||
|
||||
VALUE rb_fs;
|
||||
|
||||
static VALUE
|
||||
|
@ -238,7 +243,7 @@ rb_str_associate(str, add)
|
|||
else if (RSTRING(str)->aux.shared) {
|
||||
/* str_buf */
|
||||
if (RSTRING(str)->aux.capa != RSTRING(str)->len) {
|
||||
REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len + 1);
|
||||
RESIZE_CAPA(str, RSTRING(str)->len);
|
||||
}
|
||||
}
|
||||
RSTRING(str)->aux.shared = add;
|
||||
|
@ -521,7 +526,7 @@ rb_str_resize(str, len)
|
|||
|
||||
if (len >= 0) {
|
||||
if (RSTRING(str)->len < len || RSTRING(str)->len - len > 1024) {
|
||||
REALLOC_N(RSTRING(str)->ptr, char, len + 1);
|
||||
RESIZE_CAPA(str, len);
|
||||
}
|
||||
RSTRING(str)->len = len;
|
||||
RSTRING(str)->ptr[len] = '\0'; /* sentinel */
|
||||
|
@ -547,8 +552,7 @@ rb_str_buf_cat(str, ptr, len)
|
|||
while (total > capa) {
|
||||
capa = (capa + 1) * 2;
|
||||
}
|
||||
REALLOC_N(RSTRING(str)->ptr, char, capa+1);
|
||||
RSTRING(str)->aux.capa = capa;
|
||||
RESIZE_CAPA(str, capa);
|
||||
}
|
||||
memcpy(RSTRING(str)->ptr + RSTRING(str)->len, ptr, len);
|
||||
RSTRING(str)->len = total;
|
||||
|
@ -578,7 +582,7 @@ rb_str_cat(str, ptr, len)
|
|||
if (!FL_TEST(str, ELTS_SHARED) && !FL_TEST(str, STR_ASSOC)) {
|
||||
return rb_str_buf_cat(str, ptr, len);
|
||||
}
|
||||
REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len+len+1);
|
||||
RESIZE_CAPA(str, RSTRING(str)->len + len);
|
||||
if (ptr) {
|
||||
memcpy(RSTRING(str)->ptr + RSTRING(str)->len, ptr, len);
|
||||
}
|
||||
|
@ -616,8 +620,7 @@ rb_str_buf_append(str, str2)
|
|||
while (len > capa) {
|
||||
capa = (capa + 1) * 2;
|
||||
}
|
||||
REALLOC_N(RSTRING(str)->ptr, char, capa+1);
|
||||
RSTRING(str)->aux.capa = capa;
|
||||
RESIZE_CAPA(str, capa);
|
||||
}
|
||||
memcpy(RSTRING(str)->ptr + RSTRING(str)->len,
|
||||
RSTRING(str2)->ptr, RSTRING(str2)->len);
|
||||
|
@ -642,7 +645,7 @@ rb_str_append(str, str2)
|
|||
OBJ_INFECT(str, str2);
|
||||
return str;
|
||||
}
|
||||
REALLOC_N(RSTRING(str)->ptr, char, len+1);
|
||||
RESIZE_CAPA(str, len);
|
||||
memcpy(RSTRING(str)->ptr + RSTRING(str)->len,
|
||||
RSTRING(str2)->ptr, RSTRING(str2)->len);
|
||||
RSTRING(str)->len += RSTRING(str2)->len;
|
||||
|
@ -1046,7 +1049,7 @@ rb_str_succ(orig)
|
|||
}
|
||||
}
|
||||
if (s < sbeg) {
|
||||
REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len + 2);
|
||||
RESIZE_CAPA(str, RSTRING(str)->len + 1);
|
||||
s = RSTRING(str)->ptr + n;
|
||||
memmove(s+1, s, RSTRING(str)->len - n);
|
||||
*s = c;
|
||||
|
@ -1197,7 +1200,7 @@ rb_str_update(str, beg, len, val)
|
|||
StringValue(val);
|
||||
if (len < RSTRING(val)->len) {
|
||||
/* expand string */
|
||||
REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len+RSTRING(val)->len-len+1);
|
||||
RESIZE_CAPA(str, RSTRING(str)->len + RSTRING(val)->len - len);
|
||||
}
|
||||
|
||||
if (RSTRING(val)->len != len) {
|
||||
|
@ -1272,7 +1275,7 @@ rb_str_aset(str, indx, val)
|
|||
if (FIXNUM_P(val)) {
|
||||
if (RSTRING(str)->len == idx) {
|
||||
RSTRING(str)->len += 1;
|
||||
REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len);
|
||||
RESIZE_CAPA(str, RSTRING(str)->len);
|
||||
}
|
||||
RSTRING(str)->ptr[idx] = NUM2INT(val) & 0xff;
|
||||
}
|
||||
|
@ -1427,8 +1430,7 @@ rb_str_sub_bang(argc, argv, str)
|
|||
if (OBJ_TAINTED(repl)) tainted = 1;
|
||||
plen = END(0) - BEG(0);
|
||||
if (RSTRING(repl)->len > plen) {
|
||||
REALLOC_N(RSTRING(str)->ptr, char,
|
||||
RSTRING(str)->len + RSTRING(repl)->len - plen + 1);
|
||||
RESIZE_CAPA(str, RSTRING(str)->len + RSTRING(repl)->len - plen);
|
||||
}
|
||||
if (RSTRING(repl)->len != plen) {
|
||||
memmove(RSTRING(str)->ptr + BEG(0) + RSTRING(repl)->len,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#define RUBY_VERSION "1.7.2"
|
||||
#define RUBY_RELEASE_DATE "2001-12-18"
|
||||
#define RUBY_RELEASE_DATE "2001-12-19"
|
||||
#define RUBY_VERSION_CODE 172
|
||||
#define RUBY_RELEASE_CODE 20011218
|
||||
#define RUBY_RELEASE_CODE 20011219
|
||||
|
|
Loading…
Add table
Reference in a new issue