Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into Ractor-Local-GC-v…
Browse files Browse the repository at this point in the history
…ersion-1
  • Loading branch information
rm155 committed Aug 18, 2023
2 parents ec3decd + db076d8 commit 6712dab
Show file tree
Hide file tree
Showing 49 changed files with 4,874 additions and 19,138 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,13 @@ lcov*.info

# /wasm/
/wasm/tests/*.wasm

# YARP
/lib/yarp/node.rb
/lib/yarp/serialize.rb
/yarp/api_node.c
/yarp/ast.h
/yarp/node.c
/yarp/prettyprint.c
/yarp/serialize.c
/yarp/token_type.c
6 changes: 3 additions & 3 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,6 @@ ary_make_partial(VALUE ary, VALUE klass, long offset, long len)
FL_SET_EMBED(result);
ary_memcpy(result, 0, len, RARRAY_CONST_PTR(ary) + offset);
ARY_SET_EMBED_LEN(result, len);
return result;
}
else {
VALUE shared = ary_make_shared(ary);
Expand All @@ -1215,9 +1214,10 @@ ary_make_partial(VALUE ary, VALUE klass, long offset, long len)
ARY_SET_LEN(result, len);

ary_verify(shared);
ary_verify(result);
return result;
}

ary_verify(result);
return result;
}

static VALUE
Expand Down
34 changes: 34 additions & 0 deletions bootstraptest/test_yjit.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# regression test for return type of Integer#/
# It can return a T_BIGNUM when inputs are T_FIXNUM.
assert_equal 0x3fffffffffffffff.to_s, %q{
def call(fixnum_min)
(fixnum_min / -1) - 1
end
call(-(2**62))
}

# regression test for return type of String#<<
assert_equal 'Sub', %q{
def call(sub) = (sub << sub).itself
class Sub < String; end
call(Sub.new('o')).class
}

# test splat filling required and feeding rest
assert_equal '[0, 1, 2, [3, 4]]', %q{
public def lead_rest(a, b, *rest)
Expand Down Expand Up @@ -4092,3 +4111,18 @@ def number = super + 2
Sub.new.number { 3 }
}

# Integer multiplication and overflow
assert_equal '[6, -6, 9671406556917033397649408, -9671406556917033397649408, 21267647932558653966460912964485513216]', %q{
def foo(a, b)
a * b
end
r1 = foo(2, 3)
r2 = foo(2, -3)
r3 = foo(2 << 40, 2 << 41)
r4 = foo(2 << 40, -2 << 41)
r5 = foo(1 << 62, 1 << 62)
[r1, r2, r3, r4, r5]
}
34 changes: 34 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,40 @@ $(YARP_BUILD_DIR)/.time $(YARP_BUILD_DIR)/enc/.time $(YARP_BUILD_DIR)/util/.time
$(Q) $(MAKEDIRS) $(@D)
@$(NULLCMD) > $@

main: $(top_srcdir)/lib/yarp/node.rb
srcs: $(top_srcdir)/lib/yarp/node.rb
$(top_srcdir)/lib/yarp/node.rb: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/lib/yarp/node.rb.erb
$(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb lib/yarp/node.rb $(top_srcdir)/lib/yarp/node.rb

main: $(top_srcdir)/lib/yarp/serialize.rb
srcs: $(top_srcdir)/lib/yarp/serialize.rb
$(top_srcdir)/lib/yarp/serialize.rb: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/lib/yarp/serialize.rb.erb
$(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb lib/yarp/serialize.rb $(top_srcdir)/lib/yarp/serialize.rb

srcs: $(top_srcdir)/yarp/api_node.c
$(top_srcdir)/yarp/api_node.c: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/ext/yarp/api_node.c.erb
$(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb ext/yarp/api_node.c $(top_srcdir)/yarp/api_node.c

srcs: $(top_srcdir)/yarp/ast.h
$(top_srcdir)/yarp/ast.h: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/include/yarp/ast.h.erb
$(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb include/yarp/ast.h $(top_srcdir)/yarp/ast.h

srcs: $(top_srcdir)/yarp/node.c
$(top_srcdir)/yarp/node.c: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/src/node.c.erb
$(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb src/node.c $(top_srcdir)/yarp/node.c

srcs: $(top_srcdir)/yarp/prettyprint.c
$(top_srcdir)/yarp/prettyprint.c: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/src/prettyprint.c.erb
$(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb src/prettyprint.c $(top_srcdir)/yarp/prettyprint.c

srcs: $(top_srcdir)/yarp/serialize.c
$(top_srcdir)/yarp/serialize.c: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/src/serialize.c.erb
$(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb src/serialize.c $(top_srcdir)/yarp/serialize.c

srcs: $(top_srcdir)/yarp/token_type.c
$(top_srcdir)/yarp/token_type.c: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/src/token_type.c.erb
$(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb src/token_type.c $(top_srcdir)/yarp/token_type.c

EXPORTOBJS = $(DLNOBJ) \
localeinit.$(OBJEXT) \
loadpath.$(OBJEXT) \
Expand Down
35 changes: 20 additions & 15 deletions ext/io/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ getattr(int fd, conmode *t)
#endif

static ID id_getc, id_console, id_close;
#if ENABLE_IO_GETPASS
static ID id_gets, id_chomp_bang;
#endif
static ID id_gets, id_flush, id_chomp_bang;

#if defined HAVE_RUBY_FIBER_SCHEDULER_H
# include "ruby/fiber/scheduler.h"
Expand Down Expand Up @@ -1534,13 +1532,18 @@ io_getch(int argc, VALUE *argv, VALUE io)
return rb_funcallv(io, id_getc, argc, argv);
}

#if ENABLE_IO_GETPASS
static VALUE
puts_call(VALUE io)
{
return rb_io_write(io, rb_default_rs);
}

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

static VALUE
getpass_call(VALUE io)
{
Expand All @@ -1561,7 +1564,8 @@ static VALUE
str_chomp(VALUE str)
{
if (!NIL_P(str)) {
rb_funcallv(str, id_chomp_bang, 0, 0);
const VALUE rs = rb_default_rs; /* rvalue in TruffleRuby */
rb_funcallv(str, id_chomp_bang, 1, &rs);
}
return str;
}
Expand All @@ -1578,6 +1582,12 @@ str_chomp(VALUE str)
* see String#chomp!.
*
* You must require 'io/console' to use this method.
*
* require 'io/console'
* IO::console.getpass("Enter password:")
* Enter password:
* # => "mypassword"
*
*/
static VALUE
console_getpass(int argc, VALUE *argv, VALUE io)
Expand All @@ -1588,6 +1598,7 @@ console_getpass(int argc, VALUE *argv, VALUE io)
wio = rb_io_get_write_io(io);
if (wio == io && io == rb_stdin) wio = rb_stderr;
prompt(argc, argv, wio);
rb_io_flush(wio);
str = rb_ensure(getpass_call, io, puts_call, wio);
return str_chomp(str);
}
Expand All @@ -1605,11 +1616,10 @@ io_getpass(int argc, VALUE *argv, VALUE io)

rb_check_arity(argc, 0, 1);
prompt(argc, argv, io);
str = str_chomp(rb_funcallv(io, id_gets, 0, 0));
puts_call(io);
return str;
rb_check_funcall(io, id_flush, 0, 0);
str = rb_ensure(gets_call, io, puts_call, io);
return str_chomp(str);
}
#endif

/*
* IO console methods
Expand All @@ -1619,10 +1629,9 @@ Init_console(void)
{
#undef rb_intern
id_getc = rb_intern("getc");
#if ENABLE_IO_GETPASS
id_gets = rb_intern("gets");
id_flush = rb_intern("flush");
id_chomp_bang = rb_intern("chomp!");
#endif
id_console = rb_intern("console");
id_close = rb_intern("close");
#define init_rawmode_opt_id(name) \
Expand Down Expand Up @@ -1670,16 +1679,12 @@ InitVM_console(void)
rb_define_method(rb_cIO, "clear_screen", console_clear_screen, 0);
rb_define_method(rb_cIO, "pressed?", console_key_pressed_p, 1);
rb_define_method(rb_cIO, "check_winsize_changed", console_check_winsize_changed, 0);
#if ENABLE_IO_GETPASS
rb_define_method(rb_cIO, "getpass", console_getpass, -1);
#endif
rb_define_singleton_method(rb_cIO, "console", console_dev, -1);
{
VALUE mReadable = rb_define_module_under(rb_cIO, "generic_readable");
rb_define_method(mReadable, "getch", io_getch, -1);
#if ENABLE_IO_GETPASS
rb_define_method(mReadable, "getpass", io_getpass, -1);
#endif
}
{
/* :stopdoc: */
Expand Down
1 change: 0 additions & 1 deletion ext/io/console/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
elsif have_func("rb_scheduler_timeout") # 3.0
have_func("rb_io_wait")
end
$defs << "-D""ENABLE_IO_GETPASS=1"
create_makefile("io/console") {|conf|
conf << "\n""VK_HEADER = #{vk_header}\n"
}
Expand Down
8 changes: 6 additions & 2 deletions lib/rubygems/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ def contents
return @contents
end
end
rescue Zlib::GzipFile::Error, EOFError, Gem::Package::TarInvalidError => e
raise Gem::Package::FormatError.new e.message, @gem
end

##
Expand All @@ -363,7 +365,7 @@ def digest(entry) # :nodoc:
algorithms.each do |algorithm|
digester = Gem::Security.create_digest(algorithm)

digester << entry.read(16_384) until entry.eof?
digester << entry.readpartial(16_384) until entry.eof?

entry.rewind

Expand Down Expand Up @@ -395,6 +397,8 @@ def extract_files(destination_dir, pattern = "*")
break # ignore further entries
end
end
rescue Zlib::GzipFile::Error, EOFError, Gem::Package::TarInvalidError => e
raise Gem::Package::FormatError.new e.message, @gem
end

##
Expand Down Expand Up @@ -626,7 +630,7 @@ def verify
raise
rescue Errno::ENOENT => e
raise Gem::Package::FormatError.new e.message
rescue Gem::Package::TarInvalidError => e
rescue Zlib::GzipFile::Error, EOFError, Gem::Package::TarInvalidError => e
raise Gem::Package::FormatError.new e.message, @gem
end

Expand Down
5 changes: 0 additions & 5 deletions lib/rubygems/package/tar_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
class Gem::Package::TarReader
include Enumerable

##
# Raised if the tar IO is not seekable

class UnexpectedEOF < StandardError; end

##
# Creates a new TarReader on +io+ and yields it to the block, if given.

Expand Down
38 changes: 18 additions & 20 deletions lib/rubygems/package/tar_reader/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ def full_name
# Read one byte from the tar entry

def getc
check_closed

return nil if @read >= @header.size
return nil if eof?

ret = @io.getc
@read += 1 if ret
Expand Down Expand Up @@ -156,30 +154,28 @@ def size
alias_method :length, :size

##
# Reads +len+ bytes from the tar file entry, or the rest of the entry if
# nil

def read(len = nil)
check_closed

len ||= @header.size - @read
# Reads +maxlen+ bytes from the tar file entry, or the rest of the entry if nil

return nil if len > 0 && @read >= @header.size
def read(maxlen = nil)
if eof?
return maxlen.to_i.zero? ? "" : nil
end

max_read = [len, @header.size - @read].min
max_read = [maxlen, @header.size - @read].compact.min

ret = @io.read max_read
if ret.nil?
return maxlen ? nil : "" # IO.read returns nil on EOF with len argument
end
@read += ret.size

ret
end

def readpartial(maxlen = nil, outbuf = "".b)
check_closed

maxlen ||= @header.size - @read

raise EOFError if maxlen > 0 && @read >= @header.size
def readpartial(maxlen, outbuf = "".b)
if eof? && maxlen > 0
raise EOFError, "end of file reached"
end

max_read = [maxlen, @header.size - @read].min

Expand Down Expand Up @@ -213,6 +209,8 @@ def seek(offset, whence = IO::SEEK_SET)

pending = new_pos - @io.pos

return 0 if pending == 0

if @io.respond_to?(:seek)
begin
# avoid reading if the @io supports seeking
Expand All @@ -230,8 +228,8 @@ def seek(offset, whence = IO::SEEK_SET)
end

while pending > 0 do
size_read = @io.read([pending, 4096].min).size
raise UnexpectedEOF if @io.eof?
size_read = @io.read([pending, 4096].min)&.size
raise(EOFError, "end of file reached") if size_read.nil?
pending -= size_read
end

Expand Down
12 changes: 8 additions & 4 deletions lib/rubygems/specification_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def validate_array_attribute(field)
String
end

unless Array === val && val.all? {|x| x.is_a?(klass) }
unless Array === val && val.all? {|x| x.is_a?(klass) || (field == :licenses && x.nil?) }
error "#{field} must be an Array of #{klass}"
end
end
Expand All @@ -358,6 +358,8 @@ def validate_licenses_length
licenses = @specification.licenses

licenses.each do |license|
next if license.nil?

if license.length > 64
error "each license must be 64 characters or less"
end
Expand All @@ -368,19 +370,21 @@ def validate_licenses
licenses = @specification.licenses

licenses.each do |license|
next if Gem::Licenses.match?(license)
next if Gem::Licenses.match?(license) || license.nil?
suggestions = Gem::Licenses.suggestions(license)
message = <<-WARNING
license value '#{license}' is invalid. Use a license identifier from
http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license.
http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license,
or set it to nil if you don't want to specify a license.
WARNING
message += "Did you mean #{suggestions.map {|s| "'#{s}'" }.join(", ")}?\n" unless suggestions.nil?
warning(message)
end

warning <<-WARNING if licenses.empty?
licenses is empty, but is recommended. Use a license identifier from
http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license.
http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license,
or set it to nil if you don't want to specify a license.
WARNING
end

Expand Down
Loading

0 comments on commit 6712dab

Please sign in to comment.