diff options
author | NARUSE, Yui <naruse@airemix.jp> | 2023-06-01 08:43:22 +0900 |
---|---|---|
committer | NARUSE, Yui <naruse@airemix.jp> | 2023-06-01 08:43:22 +0900 |
commit | 85dcc4866d9ff29834596e9186cc97d622ee06f8 (patch) | |
tree | d5daa60146c5c8c2de9a9459a05e6e771d934362 /ext/pty | |
parent | e4163112f6b99d9c205f6bc260878dcb00954a13 (diff) | |
download | ruby-85dcc4866d9ff29834596e9186cc97d622ee06f8.tar.gz |
Revert "Hide most of the implementation of `struct rb_io`. (#6511)"
This reverts commit 18e55fc1e1ec20e8f3166e3059e76c885fc9f8f2.
fix [Bug #19704]
https://bugs.ruby-lang.org/issues/19704
This breaks compatibility for extension libraries. Such changes
need a discussion.
Diffstat (limited to 'ext/pty')
-rw-r--r-- | ext/pty/pty.c | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/ext/pty/pty.c b/ext/pty/pty.c index 0aca10bfa0..acec33f9bf 100644 --- a/ext/pty/pty.c +++ b/ext/pty/pty.c @@ -448,10 +448,8 @@ pty_close_pty(VALUE assoc) for (i = 0; i < 2; i++) { io = rb_ary_entry(assoc, i); - if (RB_TYPE_P(io, T_FILE)) { - /* it's OK to call rb_io_close again even if it's already closed */ + if (RB_TYPE_P(io, T_FILE) && 0 <= RFILE(io)->fptr->fd) rb_io_close(io); - } } return Qnil; } @@ -501,21 +499,28 @@ pty_open(VALUE klass) { int master_fd, slave_fd; char slavename[DEVICELEN]; + VALUE master_io, slave_file; + rb_io_t *master_fptr, *slave_fptr; + VALUE assoc; getDevice(&master_fd, &slave_fd, slavename, 1); - VALUE master_path = rb_obj_freeze(rb_sprintf("masterpty:%s", slavename)); - VALUE master_io = rb_io_open_descriptor(rb_cIO, master_fd, FMODE_READWRITE | FMODE_SYNC | FMODE_DUPLEX, master_path, RUBY_IO_TIMEOUT_DEFAULT, NULL); - - VALUE slave_path = rb_obj_freeze(rb_str_new_cstr(slavename)); - VALUE slave_file = rb_io_open_descriptor(rb_cFile, slave_fd, FMODE_READWRITE | FMODE_SYNC | FMODE_DUPLEX | FMODE_TTY, slave_path, RUBY_IO_TIMEOUT_DEFAULT, NULL); + master_io = rb_obj_alloc(rb_cIO); + MakeOpenFile(master_io, master_fptr); + master_fptr->mode = FMODE_READWRITE | FMODE_SYNC | FMODE_DUPLEX; + master_fptr->fd = master_fd; + master_fptr->pathv = rb_obj_freeze(rb_sprintf("masterpty:%s", slavename)); - VALUE assoc = rb_assoc_new(master_io, slave_file); + slave_file = rb_obj_alloc(rb_cFile); + MakeOpenFile(slave_file, slave_fptr); + slave_fptr->mode = FMODE_READWRITE | FMODE_SYNC | FMODE_DUPLEX | FMODE_TTY; + slave_fptr->fd = slave_fd; + slave_fptr->pathv = rb_obj_freeze(rb_str_new_cstr(slavename)); + assoc = rb_assoc_new(master_io, slave_file); if (rb_block_given_p()) { return rb_ensure(rb_yield, assoc, pty_close_pty, assoc); } - return assoc; } @@ -572,27 +577,30 @@ pty_getpty(int argc, VALUE *argv, VALUE self) { VALUE res; struct pty_info info; + rb_io_t *wfptr,*rfptr; + VALUE rport = rb_obj_alloc(rb_cFile); + VALUE wport = rb_obj_alloc(rb_cFile); char SlaveName[DEVICELEN]; + MakeOpenFile(rport, rfptr); + MakeOpenFile(wport, wfptr); + establishShell(argc, argv, &info, SlaveName); - VALUE pty_path = rb_obj_freeze(rb_str_new_cstr(SlaveName)); - VALUE rport = rb_io_open_descriptor( - rb_cFile, info.fd, FMODE_READABLE, pty_path, RUBY_IO_TIMEOUT_DEFAULT, NULL - ); + rfptr->mode = rb_io_modestr_fmode("r"); + rfptr->fd = info.fd; + rfptr->pathv = rb_obj_freeze(rb_str_new_cstr(SlaveName)); - int wpty_fd = rb_cloexec_dup(info.fd); - if (wpty_fd == -1) { + wfptr->mode = rb_io_modestr_fmode("w") | FMODE_SYNC; + wfptr->fd = rb_cloexec_dup(info.fd); + if (wfptr->fd == -1) rb_sys_fail("dup()"); - } - VALUE wport = rb_io_open_descriptor( - rb_cFile, wpty_fd, FMODE_WRITABLE | FMODE_TRUNC | FMODE_CREATE | FMODE_SYNC, - pty_path, RUBY_IO_TIMEOUT_DEFAULT, NULL - ); + rb_update_max_fd(wfptr->fd); + wfptr->pathv = rfptr->pathv; res = rb_ary_new2(3); - rb_ary_store(res, 0, rport); - rb_ary_store(res, 1, wport); + rb_ary_store(res,0,(VALUE)rport); + rb_ary_store(res,1,(VALUE)wport); rb_ary_store(res,2,PIDT2NUM(info.child_pid)); if (rb_block_given_p()) { |