diff --git a/NEWS.md b/NEWS.md index c6bcce74e338f2..0b622064720f22 100644 --- a/NEWS.md +++ b/NEWS.md @@ -182,9 +182,11 @@ The following default gems are updated. * RubyGems 4.0.0.dev * bundler 4.0.0.dev +* date 3.5.0 * erb 5.1.3 * etc 1.4.6 * fcntl 1.3.0 +* fileutils 1.8.0 * io-console 0.8.1 * io-nonblock 0.3.2 * io-wait 0.3.2 @@ -197,6 +199,7 @@ The following default gems are updated. * resolv 0.6.2 * stringio 3.1.8.dev * strscan 3.1.6.dev +* timeout 0.4.4 * uri 1.0.4 * weakref 0.1.4 * zlib 3.2.2 diff --git a/doc/maintainers.md b/doc/maintainers.md index fdd7697ee6b370..244912cb20c9ca 100644 --- a/doc/maintainers.md +++ b/doc/maintainers.md @@ -622,6 +622,12 @@ It may needs to make consensus on ruby-core/ruby-dev before making major changes * https://github.com/ruby/fiddle * https://rubygems.org/gems/fiddle +#### repl_type_completor + +* Tomoya Ishida ([tompng]) +* https://github.com/ruby/repl_type_completor +* https://rubygems.org/gems/repl_type_completor + ## Platform Maintainers ### mswin64 (Microsoft Windows) diff --git a/ext/date/lib/date.rb b/ext/date/lib/date.rb index aa630eb6d172b5..b33f6e65f466b0 100644 --- a/ext/date/lib/date.rb +++ b/ext/date/lib/date.rb @@ -4,7 +4,7 @@ require 'date_core' class Date - VERSION = "3.4.1" # :nodoc: + VERSION = "3.5.0" # :nodoc: # call-seq: # infinite? -> false diff --git a/ext/io/wait/wait.c b/ext/io/wait/wait.c index 88e6dd2af1fb58..bec04cb727e054 100644 --- a/ext/io/wait/wait.c +++ b/ext/io/wait/wait.c @@ -84,7 +84,7 @@ io_nread(VALUE io) ioctl_arg n; GetOpenFile(io, fptr); - rb_io_check_readable(fptr); + rb_io_check_char_readable(fptr); len = rb_io_read_pending(fptr); if (len > 0) return INT2FIX(len); @@ -143,7 +143,7 @@ io_ready_p(VALUE io) #endif GetOpenFile(io, fptr); - rb_io_check_readable(fptr); + rb_io_check_char_readable(fptr); if (rb_io_read_pending(fptr)) return Qtrue; #ifndef HAVE_RB_IO_WAIT @@ -178,7 +178,7 @@ io_wait_readable(int argc, VALUE *argv, VALUE io) #endif GetOpenFile(io, fptr); - rb_io_check_readable(fptr); + rb_io_check_char_readable(fptr); #ifndef HAVE_RB_IO_WAIT tv = get_timeout(argc, argv, &timerec); @@ -252,7 +252,7 @@ io_wait_priority(int argc, VALUE *argv, VALUE io) rb_io_t *fptr = NULL; RB_IO_POINTER(io, fptr); - rb_io_check_readable(fptr); + rb_io_check_char_readable(fptr); if (rb_io_read_pending(fptr)) return Qtrue; diff --git a/io.c b/io.c index d412d14963bded..78ac0bb2c65d9e 100644 --- a/io.c +++ b/io.c @@ -9832,7 +9832,7 @@ io_wait_readable(int argc, VALUE *argv, VALUE io) rb_io_t *fptr; RB_IO_POINTER(io, fptr); - rb_io_check_readable(fptr); + rb_io_check_char_readable(fptr); if (rb_io_read_pending(fptr)) return Qtrue; @@ -9879,7 +9879,7 @@ io_wait_priority(int argc, VALUE *argv, VALUE io) rb_io_t *fptr = NULL; RB_IO_POINTER(io, fptr); - rb_io_check_readable(fptr); + rb_io_check_char_readable(fptr); if (rb_io_read_pending(fptr)) return Qtrue; diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 6ef71d75ef39f3..0706e007ca4979 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -181,7 +181,7 @@ # module FileUtils # The version number. - VERSION = "1.7.3" + VERSION = "1.8.0" def self.private_module_function(name) #:nodoc: module_function name diff --git a/lib/timeout.rb b/lib/timeout.rb index f5f232ad2ae072..e1f0a4a78c6f59 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -20,7 +20,7 @@ module Timeout # The version - VERSION = "0.4.3" + VERSION = "0.4.4" # Internal error raised to when a timeout is triggered. class ExitException < Exception diff --git a/test/date/test_date_conv.rb b/test/date/test_date_conv.rb index 772fbee9a4e6ce..8d810844355956 100644 --- a/test/date/test_date_conv.rb +++ b/test/date/test_date_conv.rb @@ -82,21 +82,17 @@ def test_to_time__from_datetime assert_equal([1582, 10, 13, 1, 2, 3, 456789], [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec]) - if Time.allocate.respond_to?(:nsec) - d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123.to_r/86400000000000 - t = d.to_time.utc - assert_equal([2004, 9, 19, 1, 2, 3, 456789123], - [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.nsec]) - end + d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123.to_r/86400000000000 + t = d.to_time.utc + assert_equal([2004, 9, 19, 1, 2, 3, 456789123], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.nsec]) # TruffleRuby does not support more than nanoseconds unless RUBY_ENGINE == 'truffleruby' - if Time.allocate.respond_to?(:subsec) - d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123456789123.to_r/86400000000000000000000 - t = d.to_time.utc - assert_equal([2004, 9, 19, 1, 2, 3, Rational(456789123456789123,1000000000000000000)], - [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.subsec]) - end + d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123456789123.to_r/86400000000000000000000 + t = d.to_time.utc + assert_equal([2004, 9, 19, 1, 2, 3, Rational(456789123456789123,1000000000000000000)], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.subsec]) end end diff --git a/test/io/wait/test_io_wait_uncommon.rb b/test/io/wait/test_io_wait_uncommon.rb index 0f922f4e24b34f..0f97ac35d9124e 100644 --- a/test/io/wait/test_io_wait_uncommon.rb +++ b/test/io/wait/test_io_wait_uncommon.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true require 'test/unit' +require 'io/wait' # test uncommon device types to check portability problems # We may optimize IO#wait_*able for non-Linux kernels in the future @@ -74,4 +75,33 @@ def test_wait_readable_zero def test_wait_writable_null check_dev(IO::NULL, :wait_writable) end + + def test_after_ungetc_ready? + check_dev(IO::NULL, mode: "r") {|fp| + assert_respond_to fp, :ready? + fp.ungetc(?a) + assert_predicate fp, :ready? + } + end + + def test_after_ungetc_wait_readable + check_dev(IO::NULL, mode: "r") {|fp| + fp.ungetc(?a) + assert_predicate fp, :wait_readable + } + end + + def test_after_ungetc_in_text_ready? + check_dev(IO::NULL, mode: "rt") {|fp| + fp.ungetc(?a) + assert_predicate fp, :ready? + } + end + + def test_after_ungetc_in_text_wait_readable + check_dev(IO::NULL, mode: "rt") {|fp| + fp.ungetc(?a) + assert_predicate fp, :wait_readable + } + end end diff --git a/test/ruby/test_namespace.rb b/test/ruby/test_namespace.rb index bfbbe38e051ab2..5a014ad7148a51 100644 --- a/test/ruby/test_namespace.rb +++ b/test/ruby/test_namespace.rb @@ -690,5 +690,9 @@ def test_root_and_main_methods assert !$LOADED_FEATURES.include?("/tmp/barbaz") assert !Object.const_defined?(:FooClass) end; + ensure + tmp = ENV["TMPDIR"] || ENV["TMP"] || Etc.systmpdir || "/tmp" + pat = "_ruby_ns_*."+RbConfig::CONFIG["DLEXT"] + File.unlink(*Dir.glob(pat, base: tmp).map {|so| "#{tmp}/#{so}"}) end end diff --git a/win32/win32.c b/win32/win32.c index c13c4e17320268..e7dfe2b065975a 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -4724,27 +4724,36 @@ waitpid(rb_pid_t pid, int *stat_loc, int options) #include +/* License: Ruby's */ +#define filetime_unit (10UL * 1000 * 1000) +#define filetime_diff_days ((1970-1601)*3652425UL/10000) +#define filetime_diff_secs (filetime_diff_days * (24ULL * 60 * 60)) +#define unix_to_filetime(sec) (((sec) + filetime_diff_secs) * filetime_unit) +#define filetime_unix_offset unix_to_filetime(0ULL) + +/* License: Ruby's */ +typedef union { + /* FILETIME and ULARGE_INTEGER::u are the same layout */ + FILETIME ft; + ULARGE_INTEGER i; +} FILETIME_INTEGER; + /* License: Ruby's */ /* split FILETIME value into UNIX time and sub-seconds in NT ticks */ static time_t filetime_split(const FILETIME* ft, long *subsec) { - ULARGE_INTEGER tmp; - unsigned LONG_LONG lt; - const unsigned LONG_LONG subsec_unit = (unsigned LONG_LONG)10 * 1000 * 1000; - - tmp.LowPart = ft->dwLowDateTime; - tmp.HighPart = ft->dwHighDateTime; - lt = tmp.QuadPart; + FILETIME_INTEGER fi = {.ft = *ft}; + ULONGLONG lt = fi.i.QuadPart; /* lt is now 100-nanosec intervals since 1601/01/01 00:00:00 UTC, convert it into UNIX time (since 1970/01/01 00:00:00 UTC). the first leap second is at 1972/06/30, so we doesn't need to think about it. */ - lt -= (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60 * subsec_unit; + lt -= unix_to_filetime(0); - *subsec = (long)(lt % subsec_unit); - return (time_t)(lt / subsec_unit); + *subsec = (long)(lt % filetime_unit); + return (time_t)(lt / filetime_unit); } /* License: Ruby's */ @@ -4762,15 +4771,6 @@ gettimeofday(struct timeval *tv, struct timezone *tz) } /* License: Ruby's */ -static FILETIME -filetimes_plus(FILETIME t1, FILETIME t2) -{ - ULARGE_INTEGER i1 = {.u = {.LowPart = t1.dwLowDateTime, .HighPart = t1.dwHighDateTime}}; - ULARGE_INTEGER i2 = {.u = {.LowPart = t2.dwLowDateTime, .HighPart = t2.dwHighDateTime}}; - ULARGE_INTEGER i = {.QuadPart = i1.QuadPart + i2.QuadPart}; - return (FILETIME){.dwLowDateTime = i.LowPart, .dwHighDateTime = i.HighPart}; -} - static void filetime_to_timespec(FILETIME ft, struct timespec *sp) { @@ -4800,11 +4800,11 @@ clock_gettime(clockid_t clock_id, struct timespec *sp) { LARGE_INTEGER freq; LARGE_INTEGER count; - if (!QueryPerformanceFrequency(&freq)) { + if (UNLIKELY(!QueryPerformanceFrequency(&freq))) { errno = map_errno(GetLastError()); return -1; } - if (!QueryPerformanceCounter(&count)) { + if (UNLIKELY(!QueryPerformanceCounter(&count))) { errno = map_errno(GetLastError()); return -1; } @@ -4818,19 +4818,20 @@ clock_gettime(clockid_t clock_id, struct timespec *sp) case CLOCK_PROCESS_CPUTIME_ID: case CLOCK_THREAD_CPUTIME_ID: { - FILETIME ct, et, kt, ut; + FILETIME_INTEGER c, e, k, u, total; BOOL ok; if (clock_id == CLOCK_PROCESS_CPUTIME_ID) { - ok = GetProcessTimes(GetCurrentProcess(), &ct, &et, &kt, &ut); + ok = GetProcessTimes(GetCurrentProcess(), &c.ft, &e.ft, &k.ft, &u.ft); } else { - ok = GetThreadTimes(GetCurrentThread(), &ct, &et, &kt, &ut); + ok = GetThreadTimes(GetCurrentThread(), &c.ft, &e.ft, &k.ft, &u.ft); } - if (!ok) { + if (UNLIKELY(!ok)) { errno = map_errno(GetLastError()); return -1; } - filetime_to_timespec(filetimes_plus(kt, ut), sp); + total.i.QuadPart = k.i.QuadPart + u.i.QuadPart; + filetime_to_timespec(total.ft, sp); return 0; } default: @@ -7598,7 +7599,7 @@ unixtime_to_filetime(time_t time, FILETIME *ft) { ULARGE_INTEGER tmp; - tmp.QuadPart = ((LONG_LONG)time + (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60) * 10 * 1000 * 1000; + tmp.QuadPart = unix_to_filetime((ULONGLONG)time); ft->dwLowDateTime = tmp.LowPart; ft->dwHighDateTime = tmp.HighPart; return 0; @@ -7611,7 +7612,7 @@ timespec_to_filetime(const struct timespec *ts, FILETIME *ft) { ULARGE_INTEGER tmp; - tmp.QuadPart = ((LONG_LONG)ts->tv_sec + (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60) * 10 * 1000 * 1000; + tmp.QuadPart = unix_to_filetime((ULONGLONG)ts->tv_sec); tmp.QuadPart += ts->tv_nsec / 100; ft->dwLowDateTime = tmp.LowPart; ft->dwHighDateTime = tmp.HighPart;