Skip to content

Commit

Permalink
* io.c (rb_io_s_new): block check moved from initialize to this
Browse files Browse the repository at this point in the history
  method.

* io.c (rb_io_s_open): open should call initialize too. IO#for_fd
  also calls initialize. [new]

* error.c (rb_sys_fail): replace INT2FIX() by INT2NUM() since
  errno value may not fit in Fixnum size on Hurd.

* error.c (set_syserr): ditto.

* dir.c (dir_s_glob): returns nil if block given.

* io.c (rb_io_each_byte): should return self.

* io.c (rb_io_close_m): close check added.

* dir.c (dir_seek): should return pos.

* parse.y (fixpos): orig may be (NODE*)1, which should not be
  dereferenced.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Jan 18, 2002
1 parent 9bb8210 commit a7a7324
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 109 deletions.
30 changes: 30 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
Fri Jan 18 17:32:09 2002 Yukihiro Matsumoto <[email protected]>

* io.c (rb_io_s_new): block check moved from initialize to this
method.

* io.c (rb_io_s_open): open should call initialize too. IO#for_fd
also calls initialize. [new]

Fri Jan 18 10:26:33 2002 Yukihiro Matsumoto <[email protected]>

* error.c (rb_sys_fail): replace INT2FIX() by INT2NUM() since
errno value may not fit in Fixnum size on Hurd.

* error.c (set_syserr): ditto.

Fri Jan 18 10:12:00 2002 Usaku Nakamura <[email protected]>

* ext/socket/socket.c (tcp_svr_s_open): fix typo.

Fri Jan 18 02:27:48 2002 Yukihiro Matsumoto <[email protected]>

* dir.c (dir_s_glob): returns nil if block given.

* io.c (rb_io_each_byte): should return self.

* io.c (rb_io_close_m): close check added.

* dir.c (dir_seek): should return pos.

Fri Jan 18 01:21:53 2002 Yukihiro Matsumoto <[email protected]>

* parse.y (fixpos): orig may be (NODE*)1, which should not be
dereferenced.

Thu Jan 17 16:21:42 2002 Yukihiro Matsumoto <[email protected]>

* eval.c (block_pass): allow "retry" from within argument passed
Expand Down
11 changes: 7 additions & 4 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ dir_seek(dir, pos)
#ifdef HAVE_SEEKDIR
GetDIR(dir, dirp);
seekdir(dirp->dir, NUM2INT(pos));
return dir;
return pos;
#else
rb_notimplement();
#endif
Expand Down Expand Up @@ -930,10 +930,13 @@ dir_s_glob(dir, str)
}
if (buf != buffer)
free(buf);
if (ary && RARRAY(ary)->len == 0) {
rb_warning("no matches found: %s", RSTRING(str)->ptr);
if (ary) {
if (RARRAY(ary)->len == 0) {
rb_warning("no matches found: %s", RSTRING(str)->ptr);
}
return ary;
}
return ary;
return Qnil;
}

static VALUE
Expand Down
4 changes: 2 additions & 2 deletions error.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ set_syserr(i, name)
int ix, offset;
#endif
VALUE error = rb_define_class_under(rb_mErrno, name, rb_eSystemCallError);
rb_define_const(error, "Errno", INT2FIX(i));
rb_define_const(error, "Errno", INT2NUM(i));
#ifdef __BEOS__
if (i == B_ERROR) {
syserr_error = error;
Expand Down Expand Up @@ -764,7 +764,7 @@ rb_sys_fail(mesg)
}
#endif
ee = rb_exc_new2(ee, buf);
rb_iv_set(ee, "errno", INT2FIX(n));
rb_iv_set(ee, "errno", INT2NUM(n));
rb_exc_raise(ee);
}

Expand Down
28 changes: 14 additions & 14 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -6672,7 +6672,7 @@ block_pass(self, node)
}

struct METHOD {
VALUE klass, oklass;
VALUE klass, rklass;
VALUE recv;
ID id, oid;
NODE *body;
Expand All @@ -6682,7 +6682,7 @@ static void
bm_mark(data)
struct METHOD *data;
{
rb_gc_mark(data->oklass);
rb_gc_mark(data->rklass);
rb_gc_mark(data->klass);
rb_gc_mark(data->recv);
rb_gc_mark((VALUE)data->body);
Expand All @@ -6697,12 +6697,12 @@ mnew(klass, obj, id, mklass)
NODE *body;
int noex;
struct METHOD *data;
VALUE oklass = klass;
VALUE rklass = klass;
ID oid = id;

again:
if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) {
print_undef(oklass, oid);
print_undef(rklass, oid);
}

if (nd_type(body) == NODE_ZSUPER) {
Expand All @@ -6715,7 +6715,7 @@ mnew(klass, obj, id, mklass)
data->recv = obj;
data->id = id;
data->body = body;
data->oklass = oklass;
data->rklass = rklass;
data->oid = oid;
OBJ_INFECT(method, klass);

Expand All @@ -6736,7 +6736,7 @@ method_eq(method, other)
Data_Get_Struct(method, struct METHOD, m1);
Data_Get_Struct(other, struct METHOD, m2);

if (m1->klass != m2->klass || m1->oklass != m2->oklass ||
if (m1->klass != m2->klass || m1->rklass != m2->rklass ||
m1->recv != m2->recv || m1->body != m2->body)
return Qfalse;

Expand All @@ -6756,7 +6756,7 @@ method_unbind(obj)
data->recv = 0;
data->id = orig->id;
data->body = orig->body;
data->oklass = orig->oklass;
data->rklass = orig->rklass;
data->oid = orig->oid;
OBJ_INFECT(method, obj);

Expand Down Expand Up @@ -6845,19 +6845,19 @@ umethod_bind(method, recv)
struct METHOD *data, *bound;

Data_Get_Struct(method, struct METHOD, data);
if (data->oklass != CLASS_OF(recv)) {
if (FL_TEST(data->oklass, FL_SINGLETON)) {
if (data->rklass != CLASS_OF(recv)) {
if (FL_TEST(data->rklass, FL_SINGLETON)) {
rb_raise(rb_eTypeError, "singleton method called for a different object");
}
if (FL_TEST(CLASS_OF(recv), FL_SINGLETON) &&
st_lookup(RCLASS(CLASS_OF(recv))->m_tbl, data->oid, 0)) {
rb_raise(rb_eTypeError, "method `%s' overridden", rb_id2name(data->oid));
}
if (!((TYPE(data->oklass) == T_MODULE) ?
rb_obj_is_kind_of(recv, data->oklass) :
rb_obj_is_instance_of(recv, data->oklass))) {
if (!((TYPE(data->rklass) == T_MODULE) ?
rb_obj_is_kind_of(recv, data->rklass) :
rb_obj_is_instance_of(recv, data->rklass))) {
rb_raise(rb_eTypeError, "bind argument must be an instance of %s",
rb_class2name(data->oklass));
rb_class2name(data->rklass));
}
}

Expand Down Expand Up @@ -6914,7 +6914,7 @@ method_inspect(method)
s = rb_class2name(CLASS_OF(method));
rb_str_buf_cat2(str, s);
rb_str_buf_cat2(str, ": ");
s = rb_class2name(data->oklass);
s = rb_class2name(data->rklass);
rb_str_buf_cat2(str, s);
rb_str_buf_cat2(str, "(");
s = rb_class2name(data->klass);
Expand Down
56 changes: 0 additions & 56 deletions ext/socket/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,15 +909,6 @@ tcp_init(argc, argv, sock)
local_host, local_serv, INET_CLIENT);
}

static VALUE
tcp_s_open(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
return tcp_init(argc, argv, rb_obj_alloc(klass));
}

#ifdef SOCKS
static VALUE
socks_init(sock, host, serv)
Expand All @@ -933,13 +924,6 @@ socks_init(sock, host, serv)
return init_inetsock(class, host, serv, Qnil, Qnil, INET_SOCKS);
}

static VALUE
socks_s_open(klass, host, serv)
VALUE klass, host, serv;
{
return socks_init(rb_obj_alloc(klass), host, serv);
}

#ifdef SOCKS5
static VALUE
socks_s_close(sock)
Expand Down Expand Up @@ -1085,15 +1069,6 @@ tcp_svr_init(argc, argv, sock)
return init_inetsock(sock, Qnil, arg1, NULL, Qnil, INET_SERVER);
}

static VALUE
tcp_svr_s_open(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
return tcp_svr_init(argc, argv, rb_obj_alloc(klass));
}

static VALUE
s_accept(klass, fd, sockaddr, len)
VALUE klass;
Expand Down Expand Up @@ -1264,15 +1239,6 @@ udp_init(argc, argv, sock)
return init_sock(sock, fd);
}

static VALUE
udp_s_open(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
return udp_init(argc, argv, rb_obj_alloc(klass));
}

static VALUE
udp_connect(sock, host, port)
VALUE sock, host, port;
Expand Down Expand Up @@ -1361,13 +1327,6 @@ udp_send(argc, argv, sock)
}

#ifdef HAVE_SYS_UN_H
static VALUE
unix_s_sock_open(klass, path)
VALUE klass, path;
{
return init_unixsock(rb_obj_alloc(klass), path, 0);
}

static VALUE
unix_init(sock, path)
VALUE sock, path;
Expand Down Expand Up @@ -1574,13 +1533,6 @@ sock_init(sock, domain, type, protocol)
return init_sock(sock, fd);
}

static VALUE
sock_s_open(klass, domain, type, protocol)
VALUE klass, domain, type, protocol;
{
return init_sock(rb_obj_alloc(klass), domain, type, protocol);
}

static VALUE
sock_s_for_fd(klass, fd)
VALUE klass, fd;
Expand Down Expand Up @@ -2164,7 +2116,6 @@ Init_socket()
rb_eSocket = rb_define_class("SocketError", rb_eStandardError);

rb_cBasicSocket = rb_define_class("BasicSocket", rb_cIO);
rb_undef_method(CLASS_OF(rb_cBasicSocket), "open");
rb_undef_method(rb_cBasicSocket, "initialize");

rb_define_singleton_method(rb_cBasicSocket, "do_not_reverse_lookup",
Expand All @@ -2191,14 +2142,12 @@ Init_socket()

rb_cTCPSocket = rb_define_class("TCPSocket", rb_cIPSocket);
rb_define_global_const("TCPsocket", rb_cTCPSocket);
rb_define_singleton_method(rb_cTCPSocket, "open", tcp_s_open, -1);
rb_define_singleton_method(rb_cTCPSocket, "gethostbyname", tcp_s_gethostbyname, 1);
rb_define_method(rb_cTCPSocket, "initialize", tcp_init, -1);

#ifdef SOCKS
rb_cSOCKSSocket = rb_define_class("SOCKSSocket", rb_cTCPSocket);
rb_define_global_const("SOCKSsocket", rb_cSOCKSSocket);
rb_define_singleton_method(rb_cSOCKSSocket, "open", socks_s_open, 2);
rb_define_method(rb_cSOCKSSocket, "initialize", socks_init, 2);
#ifdef SOCKS5
rb_define_method(rb_cSOCKSSocket, "close", socks_s_close, 0);
Expand All @@ -2207,14 +2156,12 @@ Init_socket()

rb_cTCPServer = rb_define_class("TCPServer", rb_cTCPSocket);
rb_define_global_const("TCPserver", rb_cTCPServer);
rb_define_singleton_method(rb_cTCPServer, "open", tcp_svr_s_open, -1);
rb_define_method(rb_cTCPServer, "accept", tcp_accept, 0);
rb_define_method(rb_cTCPServer, "initialize", tcp_svr_init, -1);
rb_define_method(rb_cTCPServer, "listen", sock_listen, 1);

rb_cUDPSocket = rb_define_class("UDPSocket", rb_cIPSocket);
rb_define_global_const("UDPsocket", rb_cUDPSocket);
rb_define_singleton_method(rb_cUDPSocket, "open", udp_s_open, -1);
rb_define_method(rb_cUDPSocket, "initialize", udp_init, -1);
rb_define_method(rb_cUDPSocket, "connect", udp_connect, 2);
rb_define_method(rb_cUDPSocket, "bind", udp_bind, 2);
Expand All @@ -2223,7 +2170,6 @@ Init_socket()
#ifdef HAVE_SYS_UN_H
rb_cUNIXSocket = rb_define_class("UNIXSocket", rb_cBasicSocket);
rb_define_global_const("UNIXsocket", rb_cUNIXSocket);
rb_define_singleton_method(rb_cUNIXSocket, "open", unix_s_sock_open, 1);
rb_define_method(rb_cUNIXSocket, "initialize", unix_init, 1);
rb_define_method(rb_cUNIXSocket, "path", unix_path, 0);
rb_define_method(rb_cUNIXSocket, "addr", unix_addr, 0);
Expand All @@ -2232,14 +2178,12 @@ Init_socket()

rb_cUNIXServer = rb_define_class("UNIXServer", rb_cUNIXSocket);
rb_define_global_const("UNIXserver", rb_cUNIXServer);
rb_define_singleton_method(rb_cUNIXServer, "open", unix_svr_s_open, 1);
rb_define_method(rb_cUNIXServer, "initialize", unix_svr_init, 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);
rb_define_singleton_method(rb_cSocket, "open", sock_s_open, 3);
rb_define_singleton_method(rb_cSocket, "for_fd", sock_s_for_fd, 1);

rb_define_method(rb_cSocket, "initialize", sock_init, 3);
Expand Down
Loading

0 comments on commit a7a7324

Please sign in to comment.