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...

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2015-11-23 22:50:53 +00:00
parent a936bd5c63
commit 61e5fe0674
6 changed files with 14 additions and 7 deletions

View File

@ -1,3 +1,12 @@
Tue Nov 24 07:50:15 2015 Eric Wong <e@80x24.org>
* 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@80x24.org> Tue Nov 24 06:46:27 2015 Eric Wong <e@80x24.org>
* io.c (rb_gc_for_fd): new helper function * io.c (rb_gc_for_fd): new helper function

3
dir.c
View File

@ -519,8 +519,7 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
path = RSTRING_PTR(dirname); path = RSTRING_PTR(dirname);
dp->dir = opendir(path); dp->dir = opendir(path);
if (dp->dir == NULL) { if (dp->dir == NULL) {
if (errno == EMFILE || errno == ENFILE) { if (rb_gc_for_fd(errno)) {
rb_gc();
dp->dir = opendir(path); dp->dir = opendir(path);
} }
#ifdef HAVE_GETATTRLIST #ifdef HAVE_GETATTRLIST

View File

@ -358,8 +358,7 @@ rsock_socket(int domain, int type, int proto)
fd = rsock_socket0(domain, type, proto); fd = rsock_socket0(domain, type, proto);
if (fd < 0) { if (fd < 0) {
if (errno == EMFILE || errno == ENFILE) { if (rb_gc_for_fd(errno)) {
rb_gc();
fd = rsock_socket0(domain, type, proto); fd = rsock_socket0(domain, type, proto);
} }
} }

View File

@ -241,8 +241,7 @@ rsock_socketpair(int domain, int type, int protocol, int sv[2])
int ret; int ret;
ret = rsock_socketpair0(domain, type, protocol, sv); ret = rsock_socketpair0(domain, type, protocol, sv);
if (ret < 0 && (errno == EMFILE || errno == ENFILE)) { if (ret < 0 && rb_gc_for_fd(errno)) {
rb_gc();
ret = rsock_socketpair0(domain, type, protocol, sv); ret = rsock_socketpair0(domain, type, protocol, sv);
} }

View File

@ -851,6 +851,7 @@ void rb_stdio_set_default_encoding(void);
void rb_write_error_str(VALUE mesg); void rb_write_error_str(VALUE mesg);
VALUE rb_io_flush_raw(VALUE, int); VALUE rb_io_flush_raw(VALUE, int);
size_t rb_io_memsize(const rb_io_t *); size_t rb_io_memsize(const rb_io_t *);
int rb_gc_for_fd(int err);
/* load.c */ /* load.c */
VALUE rb_get_load_path(void); VALUE rb_get_load_path(void);

2
io.c
View File

@ -884,7 +884,7 @@ rb_io_read_check(rb_io_t *fptr)
return; return;
} }
static int int
rb_gc_for_fd(int err) rb_gc_for_fd(int err)
{ {
if (err == EMFILE || err == ENFILE || err == ENOMEM) { if (err == EMFILE || err == ENFILE || err == ENOMEM) {