Skip to content
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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ They are still available on rubygems.org and can be installed with
* 0.6.2 to [v0.6.3][net-imap-v0.6.3], [v0.6.4][net-imap-v0.6.4], [v0.6.4.1][net-imap-v0.6.4.1], [v0.6.5][net-imap-v0.6.5], [v0.6.6][net-imap-v0.6.6]
* rbs 4.2.0
* 3.10.0 to [v3.10.1][rbs-v3.10.1], [v3.10.2][rbs-v3.10.2], [v3.10.3][rbs-v3.10.3], [v3.10.4][rbs-v3.10.4], [v4.0.0.dev.1][rbs-v4.0.0.dev.1], [v4.0.0.dev.2][rbs-v4.0.0.dev.2], [v4.0.0.dev.3][rbs-v4.0.0.dev.3], [v4.0.0.dev.4][rbs-v4.0.0.dev.4], [v4.0.0.dev.5][rbs-v4.0.0.dev.5], [v4.0.0][rbs-v4.0.0], [v4.0.1.dev.1][rbs-v4.0.1.dev.1], [v4.0.1.dev.2][rbs-v4.0.1.dev.2], [v4.0.1][rbs-v4.0.1], [v4.0.2][rbs-v4.0.2], [v4.0.3][rbs-v4.0.3], [v4.1.0.pre.1][rbs-v4.1.0.pre.1], [v4.1.0.pre.2][rbs-v4.1.0.pre.2], [v4.1.0][rbs-v4.1.0], [v4.1.1.pre.1][rbs-v4.1.1.pre.1], [v4.1.1][rbs-v4.1.1], [v4.1.2][rbs-v4.1.2], [v4.1.3][rbs-v4.1.3], [v4.2.0.pre.1][rbs-v4.2.0.pre.1], [v4.2.0][rbs-v4.2.0]
* typeprof 0.32.0
* typeprof 0.33.0
* mutex_m 0.3.0
* bigdecimal 4.1.2
* 4.0.1 to [v4.1.0][bigdecimal-v4.1.0], [v4.1.1][bigdecimal-v4.1.1], [v4.1.2][bigdecimal-v4.1.2]
Expand Down
109 changes: 97 additions & 12 deletions ext/io/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ typedef struct {
# define NIL_OR_UNDEF_P(obj) (NIL_P(obj) || UNDEF_P(obj))
#endif

static int
to_vtime(VALUE vtime)
{
VALUE v10 = INT2FIX(10);
vtime = rb_funcall3(vtime, '*', 1, &v10);
return NUM2INT(vtime);
}

static unsigned char
clamp_uchar(int n)
{
if ((unsigned int)n >= UCHAR_MAX) n = UCHAR_MAX;
else if (n < 0) n = 0;
return (unsigned char)n;
}

static rawmode_arg_t *
rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *opts)
{
Expand Down Expand Up @@ -209,13 +225,11 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
opts->vtime = 0;
opts->intr = 0;
if (!NIL_OR_UNDEF_P(vmin)) {
opts->vmin = NUM2INT(vmin);
opts->vmin = clamp_uchar(NUM2INT(vmin));
optp = opts;
}
if (!NIL_OR_UNDEF_P(vtime)) {
VALUE v10 = INT2FIX(10);
vtime = rb_funcall3(vtime, '*', 1, &v10);
opts->vtime = NUM2INT(vtime);
opts->vtime = clamp_uchar(to_vtime(vtime));
optp = opts;
}
switch (intr) {
Expand Down Expand Up @@ -762,6 +776,13 @@ conmode_init_copy(VALUE obj, VALUE obj2)
return obj;
}

static VALUE
conmode_get_echo(VALUE obj)
{
conmode *t = rb_check_typeddata(obj, &conmode_type);
return echo_p(t) ? Qtrue : Qfalse;
}

static VALUE
conmode_set_echo(VALUE obj, VALUE f)
{
Expand Down Expand Up @@ -794,6 +815,58 @@ conmode_raw_new(int argc, VALUE *argv, VALUE obj)
return conmode_new(rb_obj_class(obj), &t);
}

static VALUE
conmode_get_min(VALUE obj)
{
conmode *t = rb_check_typeddata(obj, &conmode_type);
#ifdef VMIN
return INT2FIX(t->c_cc[VMIN]);
#else
(void)t;
return Qnil;
#endif
}

static VALUE
conmode_set_min(VALUE obj, VALUE min)
{
conmode *t = rb_check_typeddata(obj, &conmode_type);
int vmin = NIL_P(min) ? 1 : clamp_uchar(NUM2INT(min));
#ifdef VMIN
t->c_cc[VMIN] = vmin;
#else
(void)t;
(void)vmin;
#endif
return min;
}

static VALUE
conmode_get_time(VALUE obj)
{
conmode *t = rb_check_typeddata(obj, &conmode_type);
#ifdef VTIME
return rb_rational_new(INT2FIX(t->c_cc[VTIME]), INT2FIX(10));
#else
(void)t;
return Qnil;
#endif
}

static VALUE
conmode_set_time(VALUE obj, VALUE time)
{
conmode *t = rb_check_typeddata(obj, &conmode_type);
int vtime = NIL_P(time) ? 0 : clamp_uchar(to_vtime(time));
#ifdef VTIME
t->c_cc[VTIME] = vtime;
#else
(void)t;
(void)vtime;
#endif
return time;
}

#ifdef _WIN32
/*
* call-seq:
Expand Down Expand Up @@ -2135,10 +2208,17 @@ puts_call(VALUE io)
return rb_io_write(io, rb_default_rs);
}

static VALUE
funcall_with_rs(VALUE obj, ID mid)
{
const VALUE rs = rb_default_rs; /* rvalue in TruffleRuby */
return rb_funcallv(obj, mid, 1, &rs);
}

static VALUE
gets_call(VALUE io)
{
return rb_funcallv(io, id_gets, 0, 0);
return funcall_with_rs(io, id_gets);
}

static VALUE
Expand All @@ -2161,8 +2241,7 @@ static VALUE
str_chomp(VALUE str)
{
if (!NIL_P(str)) {
const VALUE rs = rb_default_rs; /* rvalue in TruffleRuby */
rb_funcallv(str, id_chomp_bang, 1, &rs);
funcall_with_rs(str, id_chomp_bang);
}
return str;
}
Expand Down Expand Up @@ -2223,7 +2302,7 @@ io_getpass(int argc, VALUE *argv, VALUE io)
* call-seq:
* io.ttyname -> string or nil
*
* Returns name of associated terminal (tty) if +io+ is not a tty.
* Returns name of associated terminal (tty) if +io+ is a tty.
* Returns +nil+ otherwise.
*/
static VALUE
Expand All @@ -2238,17 +2317,17 @@ console_ttyname(VALUE io)
char termname[1024], *tn = termname;
size_t size = sizeof(termname);
int e;
if (ttyname_r(fd, tn, size) == 0)
if ((e = ttyname_r(fd, tn, size)) == 0)
return rb_interned_str_cstr(tn);
if ((e = errno) == ERANGE) {
if (e == ERANGE) {
VALUE s = rb_str_new(0, size);
while (1) {
tn = RSTRING_PTR(s);
size = rb_str_capacity(s);
if (ttyname_r(fd, tn, size) == 0) {
if ((e = ttyname_r(fd, tn, size)) == 0) {
return rb_str_to_interned_str(rb_str_resize(s, strlen(tn)));
}
if ((e = errno) != ERANGE) break;
if (e != ERANGE) break;
if ((size *= 2) >= INT_MAX/2) break;
rb_str_resize(s, size);
}
Expand Down Expand Up @@ -2502,9 +2581,15 @@ InitVM_console(void)
rb_define_alloc_func(cConmode, conmode_alloc);
rb_undef_method(cConmode, "initialize");
rb_define_method(cConmode, "initialize_copy", conmode_init_copy, 1);
rb_define_method(cConmode, "echo?", conmode_get_echo, 0);
rb_define_method(cConmode, "echo", conmode_get_echo, 0);
rb_define_method(cConmode, "echo=", conmode_set_echo, 1);
rb_define_method(cConmode, "raw!", conmode_set_raw, -1);
rb_define_method(cConmode, "raw", conmode_raw_new, -1);
rb_define_method(cConmode, "min", conmode_get_min, 0);
rb_define_method(cConmode, "min=", conmode_set_min, 1);
rb_define_method(cConmode, "time", conmode_get_time, 0);
rb_define_method(cConmode, "time=", conmode_set_time, 1);
#ifdef _WIN32
rb_define_method(cConmode, "virtual_terminal_processing?", conmode_virtual_terminal_processing_p, 0);
rb_define_method(cConmode, "virtual_terminal_processing=", conmode_set_virtual_terminal_processing, 1);
Expand Down
2 changes: 1 addition & 1 deletion ext/io/console/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
have_func("rb_prepend_module") # not exported by TruffleRuby
vk_tool = find_executable("gperf")
create_makefile("io/console") {|conf|
conf << "###\n" "all: # the default target\n"
if vk_header
conf << <<~MK
VK_HEADER = #{vk_header}
all:
console.#$OBJEXT: $(VK_HEADER)
MK
end
Expand Down
6 changes: 4 additions & 2 deletions ext/io/console/lib/console/size.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# frozen_string_literal: false
# fallback to console window size
def IO.default_console_size
lines = ENV["LINES"].to_i
columns = ENV["COLUMNS"].to_i
[
ENV["LINES"].to_i.nonzero? || 25,
ENV["COLUMNS"].to_i.nonzero? || 80,
lines.positive? ? lines : 25,
columns.positive? ? columns : 80,
]
end

Expand Down
2 changes: 1 addition & 1 deletion gems/bundled_gems
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ net-smtp 0.5.1 https://github.com/ruby/net-smtp
matrix 0.4.3 https://github.com/ruby/matrix
prime 0.1.4 https://github.com/ruby/prime
rbs 4.2.0 https://github.com/ruby/rbs
typeprof 0.32.0 https://github.com/ruby/typeprof b950f910c6b6e4736988637f46a1ae256384c9f7
typeprof 0.33.0 https://github.com/ruby/typeprof
debug 1.11.1 https://github.com/ruby/debug 6510cfbc7496c55ebbefa437a25c17ca58f7c5eb
racc 1.8.1 https://github.com/ruby/racc
mutex_m 0.3.0 https://github.com/ruby/mutex_m
Expand Down
4 changes: 2 additions & 2 deletions spec/bundler/runtime/env_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def run_bundler_script(env, script)
create_file("source.rb", <<-RUBY)
print Bundler.original_env["PATH"]
RUBY
path = `getconf PATH`.strip + "#{File::PATH_SEPARATOR}/foo"
path = default_system_path + "#{File::PATH_SEPARATOR}/foo"
with_path_as(path) do
bundle_exec_ruby(bundled_app("source.rb").to_s)
expect(stdboth).to eq(path)
Expand Down Expand Up @@ -49,7 +49,7 @@ def run_bundler_script(env, script)
end
exec(Gem.ruby, __FILE__, (count - 1).to_s)
RUBY
path = `getconf PATH`.strip + File::PATH_SEPARATOR + File.dirname(Gem.ruby)
path = default_system_path + File::PATH_SEPARATOR + File.dirname(Gem.ruby)
with_path_as(path) do
build_bundler_context
bundle_exec_ruby("#{bundled_app("exe.rb")} 2")
Expand Down
6 changes: 6 additions & 0 deletions spec/bundler/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ def with_gem_path_as(path)
end
end

# Windows has no `getconf`, and its current PATH holds the directories the
# Ruby under test finds its DLLs in, so keep it as is there.
def default_system_path
Gem.win_platform? ? ENV["PATH"] : `getconf PATH`.strip
end

def with_path_as(path)
without_env_side_effects do
ENV["PATH"] = path.to_s
Expand Down
11 changes: 6 additions & 5 deletions spec/ruby/library/etc/getlogin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
else
# Etc.getlogin returns the same result of logname(2)
# if it returns non NULL
if system("which logname", out: File::NULL, err: File::NULL)
Etc.getlogin.should == `logname`.chomp
else
# fallback to `id` command since `logname` is not available
Etc.getlogin.should == `id -un`.chomp
logname = [%w[logname], %w[id -un]].find do |cmd|
name = IO.popen(cmd, err: File::NULL, &:read) rescue next
break name.chomp if $?.success?
end
if logname
Etc.getlogin.should == logname
end
end
else
Expand Down
1 change: 1 addition & 0 deletions spec/ruby/optional/capi/ext/io_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ void Init_io_spec(void) {
rb_define_method(cls, "rb_eIOTimeoutError", io_spec_rb_eIOTimeoutError, 0);
rb_define_const(cls, "FMODE_READABLE", INT2FIX(FMODE_READABLE));
rb_define_const(cls, "FMODE_WRITABLE", INT2FIX(FMODE_WRITABLE));
rb_define_const(cls, "FMODE_SYNC", INT2FIX(FMODE_SYNC));
rb_define_const(cls, "FMODE_BINMODE", INT2FIX(FMODE_BINMODE));
rb_define_const(cls, "FMODE_TEXTMODE", INT2FIX(FMODE_TEXTMODE));
rb_define_const(cls, "ECONV_UNIVERSAL_NEWLINE_DECORATOR", INT2FIX(ECONV_UNIVERSAL_NEWLINE_DECORATOR));
Expand Down
8 changes: 8 additions & 0 deletions spec/ruby/optional/capi/io_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,14 @@
io.should_not.binmode?
end

it "sets sync mode" do
mode = CApiIOSpecs::FMODE_READABLE | CApiIOSpecs::FMODE_SYNC
io = @o.rb_io_open_descriptor(File, @r_io.fileno, mode, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})

io.should.sync
@o.rb_io_mode_sync_flag(io).should == true
end

it "sets the specified timeout" do
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
io.timeout.should == 60
Expand Down
Loading