ruby-changes:40647
From: normal <ko1@a...>
Date: Tue, 24 Nov 2015 07:51:08 +0900 (JST)
Subject: [ruby-changes:40647] normal:r52726 (trunk): use rb_gc_for_fd for more callers
normal 2015-11-24 07:50:53 +0900 (Tue, 24 Nov 2015) New Revision: 52726 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52726 Log: use rb_gc_for_fd for more callers * dir.c (dir_initialize): use rb_gc_for_fd for ENOMEM * ext/socket/init.c (rsock_socket): ditto * ext/socket/socket.c (rsock_socketpair): ditto * internal.h (rb_gc_for_fd): prototype * io.c (rb_gc_for_fd): remove static [ruby-core:71623] [Feature #11727] Manpages for opendir(2), socket(2), and socketpair(3posix) describe ENOMEM as a possible error for each of these; handle it consistently with our existing wrappers for open(2)/pipe(2) etc... Modified files: trunk/ChangeLog trunk/dir.c trunk/ext/socket/init.c trunk/ext/socket/socket.c trunk/internal.h trunk/io.c Index: ChangeLog =================================================================== --- ChangeLog (revision 52725) +++ ChangeLog (revision 52726) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Nov 24 07:50:15 2015 Eric Wong <e@8...> + + * dir.c (dir_initialize): use rb_gc_for_fd for ENOMEM + * ext/socket/init.c (rsock_socket): ditto + * ext/socket/socket.c (rsock_socketpair): ditto + * internal.h (rb_gc_for_fd): prototype + * io.c (rb_gc_for_fd): remove static + [ruby-core:71623] [Feature #11727] + Tue Nov 24 06:46:27 2015 Eric Wong <e@8...> * io.c (rb_gc_for_fd): new helper function Index: io.c =================================================================== --- io.c (revision 52725) +++ io.c (revision 52726) @@ -884,7 +884,7 @@ rb_io_read_check(rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/io.c#L884 return; } -static int +int rb_gc_for_fd(int err) { if (err == EMFILE || err == ENFILE || err == ENOMEM) { Index: dir.c =================================================================== --- dir.c (revision 52725) +++ dir.c (revision 52726) @@ -519,8 +519,7 @@ dir_initialize(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/dir.c#L519 path = RSTRING_PTR(dirname); dp->dir = opendir(path); if (dp->dir == NULL) { - if (errno == EMFILE || errno == ENFILE) { - rb_gc(); + if (rb_gc_for_fd(errno)) { dp->dir = opendir(path); } #ifdef HAVE_GETATTRLIST Index: ext/socket/init.c =================================================================== --- ext/socket/init.c (revision 52725) +++ ext/socket/init.c (revision 52726) @@ -358,8 +358,7 @@ rsock_socket(int domain, int type, int p https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L358 fd = rsock_socket0(domain, type, proto); if (fd < 0) { - if (errno == EMFILE || errno == ENFILE) { - rb_gc(); + if (rb_gc_for_fd(errno)) { fd = rsock_socket0(domain, type, proto); } } Index: ext/socket/socket.c =================================================================== --- ext/socket/socket.c (revision 52725) +++ ext/socket/socket.c (revision 52726) @@ -241,8 +241,7 @@ rsock_socketpair(int domain, int type, i https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L241 int ret; ret = rsock_socketpair0(domain, type, protocol, sv); - if (ret < 0 && (errno == EMFILE || errno == ENFILE)) { - rb_gc(); + if (ret < 0 && rb_gc_for_fd(errno)) { ret = rsock_socketpair0(domain, type, protocol, sv); } Index: internal.h =================================================================== --- internal.h (revision 52725) +++ internal.h (revision 52726) @@ -851,6 +851,7 @@ void rb_stdio_set_default_encoding(void) https://github.com/ruby/ruby/blob/trunk/internal.h#L851 void rb_write_error_str(VALUE mesg); VALUE rb_io_flush_raw(VALUE, int); size_t rb_io_memsize(const rb_io_t *); +int rb_gc_for_fd(int err); /* load.c */ VALUE rb_get_load_path(void); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/