Skip to content

Commit 61e5fe0

Browse files
author
normal
committed
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
1 parent a936bd5 commit 61e5fe0

File tree

6 files changed

+14
-7
lines changed

6 files changed

+14
-7
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Tue Nov 24 07:50:15 2015 Eric Wong <e@80x24.org>
2+
3+
* dir.c (dir_initialize): use rb_gc_for_fd for ENOMEM
4+
* ext/socket/init.c (rsock_socket): ditto
5+
* ext/socket/socket.c (rsock_socketpair): ditto
6+
* internal.h (rb_gc_for_fd): prototype
7+
* io.c (rb_gc_for_fd): remove static
8+
[ruby-core:71623] [Feature #11727]
9+
110
Tue Nov 24 06:46:27 2015 Eric Wong <e@80x24.org>
211

312
* io.c (rb_gc_for_fd): new helper function

dir.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,7 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
519519
path = RSTRING_PTR(dirname);
520520
dp->dir = opendir(path);
521521
if (dp->dir == NULL) {
522-
if (errno == EMFILE || errno == ENFILE) {
523-
rb_gc();
522+
if (rb_gc_for_fd(errno)) {
524523
dp->dir = opendir(path);
525524
}
526525
#ifdef HAVE_GETATTRLIST

ext/socket/init.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ rsock_socket(int domain, int type, int proto)
358358

359359
fd = rsock_socket0(domain, type, proto);
360360
if (fd < 0) {
361-
if (errno == EMFILE || errno == ENFILE) {
362-
rb_gc();
361+
if (rb_gc_for_fd(errno)) {
363362
fd = rsock_socket0(domain, type, proto);
364363
}
365364
}

ext/socket/socket.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ rsock_socketpair(int domain, int type, int protocol, int sv[2])
241241
int ret;
242242

243243
ret = rsock_socketpair0(domain, type, protocol, sv);
244-
if (ret < 0 && (errno == EMFILE || errno == ENFILE)) {
245-
rb_gc();
244+
if (ret < 0 && rb_gc_for_fd(errno)) {
246245
ret = rsock_socketpair0(domain, type, protocol, sv);
247246
}
248247

internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ void rb_stdio_set_default_encoding(void);
851851
void rb_write_error_str(VALUE mesg);
852852
VALUE rb_io_flush_raw(VALUE, int);
853853
size_t rb_io_memsize(const rb_io_t *);
854+
int rb_gc_for_fd(int err);
854855

855856
/* load.c */
856857
VALUE rb_get_load_path(void);

io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ rb_io_read_check(rb_io_t *fptr)
884884
return;
885885
}
886886

887-
static int
887+
int
888888
rb_gc_for_fd(int err)
889889
{
890890
if (err == EMFILE || err == ENFILE || err == ENOMEM) {

0 commit comments

Comments
 (0)