Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Hide the usage of rb_io_t where possible. #7880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10997,6 +10997,7 @@ process.$(OBJEXT): $(top_srcdir)/internal/fixnum.h
process.$(OBJEXT): $(top_srcdir)/internal/gc.h
process.$(OBJEXT): $(top_srcdir)/internal/hash.h
process.$(OBJEXT): $(top_srcdir)/internal/imemo.h
process.$(OBJEXT): $(top_srcdir)/internal/io.h
process.$(OBJEXT): $(top_srcdir)/internal/numeric.h
process.$(OBJEXT): $(top_srcdir)/internal/object.h
process.$(OBJEXT): $(top_srcdir)/internal/process.h
Expand Down
2 changes: 1 addition & 1 deletion debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const union {
RUBY_FMODE_NOREVLOOKUP = 0x00000100,
RUBY_FMODE_TRUNC = FMODE_TRUNC,
RUBY_FMODE_TEXTMODE = FMODE_TEXTMODE,
RUBY_FMODE_PREP = 0x00010000,
RUBY_FMODE_EXTERNAL = 0x00010000,
RUBY_FMODE_SETENC_BY_BOM = FMODE_SETENC_BY_BOM,
RUBY_FMODE_UNIX = 0x00200000,
RUBY_FMODE_INET = 0x00400000,
Expand Down
54 changes: 23 additions & 31 deletions ext/pty/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,10 @@ pty_close_pty(VALUE assoc)

for (i = 0; i < 2; i++) {
io = rb_ary_entry(assoc, i);
if (RB_TYPE_P(io, T_FILE) && 0 <= RFILE(io)->fptr->fd)
if (RB_TYPE_P(io, T_FILE)) {
/* it's OK to call rb_io_close again even if it's already closed */
rb_io_close(io);
}
}
return Qnil;
}
Expand Down Expand Up @@ -499,28 +501,21 @@ 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);

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 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);

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));
VALUE assoc = rb_assoc_new(master_io, slave_file);

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;
}

Expand Down Expand Up @@ -577,30 +572,27 @@ 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);

rfptr->mode = rb_io_modestr_fmode("r");
rfptr->fd = info.fd;
rfptr->pathv = rb_obj_freeze(rb_str_new_cstr(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
);

wfptr->mode = rb_io_modestr_fmode("w") | FMODE_SYNC;
wfptr->fd = rb_cloexec_dup(info.fd);
if (wfptr->fd == -1)
int wpty_fd = rb_cloexec_dup(info.fd);
if (wpty_fd == -1) {
rb_sys_fail("dup()");
rb_update_max_fd(wfptr->fd);
wfptr->pathv = rfptr->pathv;
}
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
);

res = rb_ary_new2(3);
rb_ary_store(res,0,(VALUE)rport);
rb_ary_store(res,1,(VALUE)wport);
rb_ary_store(res, 0, rport);
rb_ary_store(res, 1, wport);
rb_ary_store(res,2,PIDT2NUM(info.child_pid));

if (rb_block_given_p()) {
Expand Down
1 change: 0 additions & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ int flock(int, int);
#include "internal/thread.h"
#include "internal/vm.h"
#include "ruby/encoding.h"
#include "ruby/io.h"
#include "ruby/thread.h"
#include "ruby/util.h"

Expand Down
35 changes: 34 additions & 1 deletion include/ruby/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,16 @@ typedef struct rb_io_enc_t rb_io_enc_t;
* Setting this one and #FMODE_BINMODE at the same time is a contradiction.
*/
#define FMODE_TEXTMODE 0x00001000
/* #define FMODE_PREP 0x00010000 */
/**
* This flag means that an IO object is wrapping an "external" file descriptor,
* which is owned by something outside the Ruby interpreter (usually a C extension).
* Ruby will not close this file when the IO object is garbage collected.
* If this flag is set, then IO#autoclose? is false, and vice-versa.
*
* This flag was previously called FMODE_PREP internally.
*/
#define FMODE_EXTERNAL 0x00010000

/* #define FMODE_SIGNAL_ON_EPIPE 0x00020000 */

/**
Expand All @@ -345,6 +354,18 @@ typedef struct rb_io_enc_t rb_io_enc_t;

/** @} */

/**
* Allocate a new IO object, with the given file descriptor.
*/
VALUE rb_io_open_descriptor(VALUE klass, int descriptor, int mode, VALUE path, VALUE timeout, struct rb_io_enc_t *encoding);

/**
* Returns whether or not the underlying IO is closed.
*
* @return Whether the underlying IO is closed.
*/
VALUE rb_io_closed_p(VALUE io);

/**
* Queries the underlying IO pointer.
*
Expand Down Expand Up @@ -703,6 +724,12 @@ VALUE rb_io_set_write_io(VALUE io, VALUE w);
*/
void rb_io_set_nonblock(rb_io_t *fptr);

/**
* Returns the path for the given IO.
*
*/
VALUE rb_io_path(VALUE io);

/**
* Returns an integer representing the numeric file descriptor for
* <em>io</em>.
Expand All @@ -712,6 +739,12 @@ void rb_io_set_nonblock(rb_io_t *fptr);
*/
int rb_io_descriptor(VALUE io);

/**
* Get the mode of the IO.
*
*/
int rb_io_mode(VALUE io);

/**
* This function breaks down the option hash that `IO#initialize` takes into
* components. This is an implementation detail of rb_io_extract_modeenc()
Expand Down
Loading