From fcda66ffe2df3d15042d161c09f5d5eb03fd4179 Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Tue, 16 Aug 2022 16:19:45 -0400 Subject: [PATCH] Merge commits from `ruby/master` into `yjit_backend_ir` (#406) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Only allow procs created by Symbol#to_proc to call public methods Fixes [Bug #18826] Co-authored-by: Nobuyoshi Nakada * Revert "Add {Method,UnboundMethod}#{public?,private?,protected?}" This reverts commit 27278150685e738f84105d09843d3ba371146c7a and 58dc8bf8f15df9a33d191074e8a5d4946a3d59d5. Visibility is an attribute of the method entry in a class, not an attribute of the Method object. Fixes [#18729] Fixes [#18751] Fixes [#18435] * [ruby/rdoc] Treat text markup (italic, bold, monofont) as blocks (https://github.com/ruby/rdoc/pull/911) https://github.com/ruby/rdoc/commit/dc88f1b425 * Add `--enable-devel` configure option Since `RUBY_DEVEL` in cppflags has no effect in the configure script and makefiles. * Fix paths of exts.mk to clean exts.mk files are one level under the top of extension directories. * The "gems" build directory was rename as ".bundle" * Fix race conditions when cleaning extensions Clean built directories by `make distclean`, and then clean leftover makefiles for skipped extensions. * Fix Array#[] with ArithmeticSequence with negative steps (#5739) * Fix Array#[] with ArithmeticSequence with negative steps Previously, Array#[] when called with an ArithmeticSequence with a negative step did not handle all cases correctly, especially cases involving infinite ranges, inverted ranges, and/or exclusive ends. Fixes [Bug #18247] * Add Array#slice tests for ArithmeticSequence with negative step to test_array Add tests of rb_arithmetic_sequence_beg_len_step C-API function. * Fix ext/-test-/arith_seq/beg_len_step/depend * Rename local variables * Fix a variable name Co-authored-by: Kenta Murata <3959+mrkn@users.noreply.github.com> * [ruby/rdoc] [DOC] Make example formats explicit and consistent (https://github.com/ruby/rdoc/pull/913) https://github.com/ruby/rdoc/commit/7e6ef6c855 * Fix inspect for unicode codepoint 0x85 This is an inelegant hack, by manually checking for this specific code point in rb_str_inspect. Some testing indicates that this is the only code point affected. It's possible a better fix would be inside of lower-level encoding code, such that rb_enc_isprint would return false and not true for codepoint 0x85. Fixes [Bug #16842] * * 2022-08-12 [ci skip] * [ruby/rdoc] Improvements to Text Markup examples (https://github.com/ruby/rdoc/pull/915) https://github.com/ruby/rdoc/commit/d00ddfe57c * [ruby/rdoc] Mods to section Text Markup (https://github.com/ruby/rdoc/pull/916) https://github.com/ruby/rdoc/commit/5506d4d67e * [ruby/error_highlight] Add a note about the current limitation of ErrorHighlight.spot https://github.com/ruby/error_highlight/commit/489ce80a62 * All extensions in bundled gems are built by build-ext now `RbInstall::GemInstaller#build_extensions` has nothing to do. * No bundled gems to be installed from gem now * [DOC] Use `true`/`false` for `@retval`s which are `bool` * Add missing `rb_enc_iscntrl` * Stop defining `RUBY_ABI_VERSION` if released versions As commented in include/ruby/internal/abi.h, since teeny versions of Ruby should guarantee ABI compatibility, `RUBY_ABI_VERSION` has no role in released versions of Ruby. * Add Numeric#ceildiv and Integer#ceildiv * Remove Numeric#ceildiv * Improve performance of Integer#ceildiv This patch is suggested by nobu. Benchmark result: ``` require 'benchmark' n = 10 ** 7 Benchmark.bm do |x| x.report("Fixnum/Fixnum") { a, b = 5, 2; n.times { a.ceildiv(b) } } x.report("Bignum/Bignum") { a, b = 10**100, 10**99 - 1; n.times { a.ceildiv(b) } } x.report("Bignum/Fixnum") { a, b = 10**100, 3; n.times { a.ceildiv(b) } } end ``` Original: ``` user system total real Fixnum/Fixnum 3.340009 0.043029 3.383038 ( 3.384022) Bignum/Bignum 8.229500 0.118543 8.348043 ( 8.349574) Bignum/Fixnum 8.328971 0.097842 8.426813 ( 8.426952) ``` Improved: ``` user system total real Fixnum/Fixnum 0.699140 0.000961 0.700101 ( 0.700199) Bignum/Bignum 5.076165 0.083160 5.159325 ( 5.159360) Bignum/Fixnum 5.548684 0.115372 5.664056 ( 5.666735) ``` * [Bug #18962] Do not read again once reached EOF `Ripper::Lexer#parse` re-parses the source code with syntax errors when `raise_errors: false`. Co-Authored-By: tompng * Short-circuit `Process._fork` * Introduce with_warn_vsprintf macro * Bundle unreleased debug * Preserve each column positions in gems/bundled_gems * Adjust columns in gems/bundled_gems [ci skip] * [ruby/rdoc] [DOC] Enhances text about escapes (https://github.com/ruby/rdoc/pull/917) https://github.com/ruby/rdoc/commit/c40bac829c * * 2022-08-13 [ci skip] * Add a NEWS entry about Integer#ceildiv [ci skip] * [DOC] Add the link to [Feature #18809] * Silent configure does not output cached configurations * * 2022-08-14 [ci skip] * Update dependencies * [ruby/rinda] Handle situations where IPv4 multicast is not available Fixes [Bug #13864] https://github.com/ruby/rinda/commit/3cd620f38c * * 2022-08-15 [ci skip] * [rubygems/rubygems] Fix Ruby platform incorrectly removed on `bundle update` https://github.com/rubygems/rubygems/commit/0d321c9e3a * [ruby/date] [DOC] Enhanced intro for Date (https://github.com/ruby/date/pull/72) https://github.com/ruby/date/commit/59a6673221 * Add test for GC thrashing of young object creation This test will prevent performance regressions like [Bug #18929]. * Simplify around `USE_YJIT` macro (#6240) * Simplify around `USE_YJIT` macro - Use `USE_YJIT` macro only instead of `YJIT_BUILD`. - An intermediate macro `YJIT_SUPPORTED_P` is no longer used. * Bail out if YJIT is enabled on unsupported platforms * * 2022-08-16 [ci skip] * [ruby/rdoc] [DOC] Remove duplicated line in RDoc::MarkupReference https://github.com/ruby/rdoc/commit/488f89aee4 * Allow aarch64 to build YJIT Co-authored-by: Jeremy Evans Co-authored-by: Nobuyoshi Nakada Co-authored-by: Burdette Lamar Co-authored-by: Kenta Murata <3959+mrkn@users.noreply.github.com> Co-authored-by: git Co-authored-by: Yusuke Endoh Co-authored-by: Kouhei Yanagita Co-authored-by: tompng Co-authored-by: S-H-GAMELINKS Co-authored-by: David Rodríguez Co-authored-by: Peter Zhu Co-authored-by: Takashi Kokubun --- NEWS.md | 4 + common.mk | 9 +- configure.ac | 6 + doc/rdoc/markup_reference.rb | 145 ++++++++++---- error.c | 49 +++-- ext/-test-/abi/extconf.rb | 1 + ext/date/date_core.c | 184 +++++------------- gems/bundled_gems | 30 +-- include/ruby/internal/abi.h | 6 +- include/ruby/internal/encoding/ctype.h | 101 ++++++---- iseq.c | 6 +- lib/bundler/definition.rb | 2 +- lib/error_highlight/base.rb | 8 + numeric.rb | 17 ++ parse.y | 1 + process.c | 31 ++- ruby.c | 20 +- .../install/gemfile/specific_platform_spec.rb | 41 ++++ template/Makefile.in | 5 +- test/-ext-/test_abi.rb | 2 + test/rinda/test_rinda.rb | 71 ++++--- test/ripper/test_lexer.rb | 14 ++ test/ruby/test_gc.rb | 22 +++ test/ruby/test_integer.rb | 17 ++ tool/rbinstall.rb | 31 +-- tool/update-bundled_gems.rb | 4 +- version.h | 13 +- vm.c | 2 +- vm_core.h | 1 - win32/Makefile.sub | 8 +- win32/setup.mak | 4 +- yjit.h | 23 +-- 32 files changed, 505 insertions(+), 373 deletions(-) diff --git a/NEWS.md b/NEWS.md index b391702821b654..6498621712270b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -104,6 +104,9 @@ Note: We're only listing outstanding class updates. empty, instead of returning the default value or calling the default proc. [[Bug #16908]] +* Integer + * Integer#ceildiv has been added. [[Feature #18809]] + * Kernel * Kernel#binding raises RuntimeError if called from a non-Ruby frame (such as a method defined in C). [[Bug #18487]] @@ -276,3 +279,4 @@ The following deprecated APIs are removed. [Feature #18685]: https://bugs.ruby-lang.org/issues/18685 [Bug #18782]: https://bugs.ruby-lang.org/issues/18782 [Feature #18788]: https://bugs.ruby-lang.org/issues/18788 +[Feature #18809]: https://bugs.ruby-lang.org/issues/18809 diff --git a/common.mk b/common.mk index 9f89e0ec8af26c..ec5e4ae2522ef1 100644 --- a/common.mk +++ b/common.mk @@ -13822,7 +13822,6 @@ signal.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h signal.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h signal.$(OBJEXT): $(CCAN_DIR)/list/list.h signal.$(OBJEXT): $(CCAN_DIR)/str/str.h -signal.$(OBJEXT): $(hdrdir)/ruby.h signal.$(OBJEXT): $(hdrdir)/ruby/ruby.h signal.$(OBJEXT): $(top_srcdir)/internal/array.h signal.$(OBJEXT): $(top_srcdir)/internal/compilers.h @@ -14008,7 +14007,6 @@ signal.$(OBJEXT): {$(VPATH)}internal/warning_push.h signal.$(OBJEXT): {$(VPATH)}internal/xmalloc.h signal.$(OBJEXT): {$(VPATH)}method.h signal.$(OBJEXT): {$(VPATH)}missing.h -signal.$(OBJEXT): {$(VPATH)}mjit.h signal.$(OBJEXT): {$(VPATH)}node.h signal.$(OBJEXT): {$(VPATH)}onigmo.h signal.$(OBJEXT): {$(VPATH)}oniguruma.h @@ -14024,7 +14022,6 @@ signal.$(OBJEXT): {$(VPATH)}thread_native.h signal.$(OBJEXT): {$(VPATH)}vm_core.h signal.$(OBJEXT): {$(VPATH)}vm_debug.h signal.$(OBJEXT): {$(VPATH)}vm_opts.h -signal.$(OBJEXT): {$(VPATH)}yjit.h sprintf.$(OBJEXT): $(hdrdir)/ruby/ruby.h sprintf.$(OBJEXT): $(top_srcdir)/internal/bignum.h sprintf.$(OBJEXT): $(top_srcdir)/internal/bits.h @@ -17593,16 +17590,14 @@ yjit.$(OBJEXT): $(top_srcdir)/internal/array.h yjit.$(OBJEXT): $(top_srcdir)/internal/class.h yjit.$(OBJEXT): $(top_srcdir)/internal/compile.h yjit.$(OBJEXT): $(top_srcdir)/internal/compilers.h +yjit.$(OBJEXT): $(top_srcdir)/internal/fixnum.h yjit.$(OBJEXT): $(top_srcdir)/internal/gc.h yjit.$(OBJEXT): $(top_srcdir)/internal/hash.h yjit.$(OBJEXT): $(top_srcdir)/internal/imemo.h -yjit.$(OBJEXT): $(top_srcdir)/internal/object.h -yjit.$(OBJEXT): $(top_srcdir)/internal/re.h yjit.$(OBJEXT): $(top_srcdir)/internal/sanitizers.h yjit.$(OBJEXT): $(top_srcdir)/internal/serial.h yjit.$(OBJEXT): $(top_srcdir)/internal/static_assert.h yjit.$(OBJEXT): $(top_srcdir)/internal/string.h -yjit.$(OBJEXT): $(top_srcdir)/internal/struct.h yjit.$(OBJEXT): $(top_srcdir)/internal/variable.h yjit.$(OBJEXT): $(top_srcdir)/internal/vm.h yjit.$(OBJEXT): $(top_srcdir)/internal/warnings.h @@ -17620,6 +17615,7 @@ yjit.$(OBJEXT): {$(VPATH)}backward/2/stdarg.h yjit.$(OBJEXT): {$(VPATH)}builtin.h yjit.$(OBJEXT): {$(VPATH)}config.h yjit.$(OBJEXT): {$(VPATH)}constant.h +yjit.$(OBJEXT): {$(VPATH)}debug.h yjit.$(OBJEXT): {$(VPATH)}debug_counter.h yjit.$(OBJEXT): {$(VPATH)}defines.h yjit.$(OBJEXT): {$(VPATH)}encoding.h @@ -17798,6 +17794,7 @@ yjit.$(OBJEXT): {$(VPATH)}thread_native.h yjit.$(OBJEXT): {$(VPATH)}vm_callinfo.h yjit.$(OBJEXT): {$(VPATH)}vm_core.h yjit.$(OBJEXT): {$(VPATH)}vm_debug.h +yjit.$(OBJEXT): {$(VPATH)}vm_insnhelper.h yjit.$(OBJEXT): {$(VPATH)}vm_opts.h yjit.$(OBJEXT): {$(VPATH)}vm_sync.h yjit.$(OBJEXT): {$(VPATH)}yjit.c diff --git a/configure.ac b/configure.ac index bc21c262922161..0f4a31af7e7dce 100644 --- a/configure.ac +++ b/configure.ac @@ -88,7 +88,9 @@ AC_SUBST(GIT) AC_SUBST(HAVE_GIT) eval `sed -n -e ['s/^@%:@define RUBY_[A-Z_]*VERSION_\([A-Z][A-Z][A-Z_0-9]*\) \([0-9][0-9]*\)$/\1=\2/p'] \ + -e ['s/^@%:@define \(RUBY_ABI_VERSION\) \([0-9][0-9]*\).*/\1=\2/p'] \ -e ['s/^@%:@define \(RUBY_PATCHLEVEL\) \(.*\)/\1=\2/p'] \ + $srcdir/include/ruby/internal/abi.h \ $srcdir/include/ruby/version.h $srcdir/version.h` for v in MAJOR MINOR TEENY; do AS_IF([eval "test \"\$$v\" = ''"], [ @@ -100,6 +102,9 @@ AC_SUBST(MINOR) AC_SUBST(TEENY) AC_SUBST(RUBY_API_VERSION, '$(MAJOR).$(MINOR)') AC_SUBST(RUBY_PROGRAM_VERSION, '$(MAJOR).$(MINOR).$(TEENY)') +AS_CASE([$RUBY_PATCHLEVEL], [-*], [ + AC_DEFINE_UNQUOTED(RUBY_ABI_VERSION, [${RUBY_ABI_VERSION}]) +], [RUBY_ABI_VERSION=]) AS_IF([test "$program_prefix" = NONE], [ program_prefix= @@ -4118,6 +4123,7 @@ AS_CASE(["$ruby_version"], AS_IF([test ${RUBY_LIB_VERSION_STYLE+set}], [ { echo "#define RUBY_LIB_VERSION_STYLE $RUBY_LIB_VERSION_STYLE" + echo '@%:@include "confdefs.h"' echo '#define STRINGIZE(x) x' test -f revision.h -o -f "${srcdir}/revision.h" || echo '#define RUBY_REVISION 0' echo '#include "version.h"' diff --git a/doc/rdoc/markup_reference.rb b/doc/rdoc/markup_reference.rb index c7578f3581107f..66ec6786c07aa4 100644 --- a/doc/rdoc/markup_reference.rb +++ b/doc/rdoc/markup_reference.rb @@ -94,7 +94,7 @@ # - {Directive}[rdoc-ref:RDoc::MarkupReference@Directives]: # various special directions for the rendering. # - {Text Markup}[rdoc-ref:RDoc:MarkupReference@Text+Markup]: -# text to be rendered in italic, bold, or monofont. +# text to be rendered in a special way. # # About the blocks: # @@ -632,18 +632,24 @@ # # ==== Text Markup # -# Text markup is metatext that marks text as: +# Text markup is metatext that affects HTML rendering: # -# - Italic. -# - Bold. -# - Monofont. +# - Typeface: italic, bold, monofont. +# - Character conversions: copyright, trademark, certain punctuation. +# - Links. +# - Escapes: marking text as "not markup." # -# Text markup may contain only one type of nested block: +# ===== Typeface Markup # -# - More text markup: +# Typeface markup can specify that text is to be rendered +# as italic, bold, or monofont. +# +# Typeface markup may contain only one type of nested block: +# +# - More typeface markup: # italic, bold, monofont. # -# ===== Italic +# ====== Italic # # Text may be marked as italic via HTML tag or . # @@ -698,7 +704,7 @@ # # ====== _Italic_ in a Heading # -# ===== Bold +# ====== Bold # # Text may be marked as bold via HTML tag . # @@ -755,7 +761,7 @@ # # ===== *Bold* in a Heading # -# ===== Monofont +# ====== Monofont # # Text may be marked as monofont # -- sometimes called 'typewriter font' -- @@ -814,37 +820,6 @@ # # ====== +Monofont+ in a Heading # -# ==== Escaping Text Markup -# -# Text markup can be escaped with a backslash, as in \, which was obtained -# with \\. Except in verbatim sections and between \ tags, -# to produce a backslash you have to double it unless it is followed by a -# space, tab or newline. Otherwise, the HTML formatter will discard it, as it -# is used to escape potential links: -# -# * The \ must be doubled if not followed by white space: \\. -# * But not in \ tags: in a Regexp, \S matches non-space. -# * This is a link to {ruby-lang}[https://www.ruby-lang.org]. -# * This is not a link, however: \{ruby-lang.org}[https://www.ruby-lang.org]. -# * This will not be linked to \RDoc::RDoc#document -# -# generates: -# -# * The \ must be doubled if not followed by white space: \\. -# * But not in \ tags: in a Regexp, \S matches non-space. -# * This is a link to {ruby-lang}[https://www.ruby-lang.org] -# * This is not a link, however: \{ruby-lang.org}[https://www.ruby-lang.org] -# * This will not be linked to \RDoc::RDoc#document -# -# Inside \ tags, more precisely, leading backslashes are removed only if -# followed by a markup character (<*_+), a backslash, or a known link -# reference (a known class or method). So in the example above, the backslash -# of \S would be removed if there was a class or module named +S+ in -# the current context. -# -# This behavior is inherited from RDoc version 1, and has been kept for -# compatibility with existing RDoc documentation. -# # ==== Character Conversions # # Certain combinations of characters may be converted to special characters; @@ -891,7 +866,6 @@ # # - On-page: ::dummy_singleton_method links to ::dummy_singleton_method. # - Off-pageRDoc::TokenStream::to_html links to RDoc::TokenStream::to_html. -# to \RDoc::TokenStream::to_html. # # Note: Occasionally \RDoc is not linked to a method whose name # has only special characters. Check whether the links you were expecting @@ -1068,6 +1042,93 @@ # # {rdoc-image:https://www.ruby-lang.org/images/header-ruby-logo@2x.png}[./Alias.html] # +# === Escaping Text +# +# Text that would otherwise be interpreted as markup +# can be "escaped," so that it is not interpreted as markup; +# the escape character is the backslash ('\\'). +# +# In a verbatim text block or a code block, +# the escape character is always preserved: +# +# Example input: +# +# This is not verbatim text. +# +# This is verbatim text, with an escape character \. +# +# This is not a code block. +# +# def foo +# 'String with an escape character.' +# end +# +# Rendered HTML: +# +# >>> +# This is not verbatim text. +# +# This is verbatim text, with an escape character \. +# +# This is not a code block. +# +# def foo +# 'This is a code block with an escape character \.' +# end +# +# In typeface markup (italic, bold, or monofont), +# an escape character is preserved unless it is immediately +# followed by nested typeface markup. +# +# Example input: +# +# This list is about escapes; it contains: +# +# - Monofont text with unescaped nested _italic_. +# - Monofont text with escaped nested \_italic_. +# - Monofont text with an escape character \. +# +# Rendered HTML: +# +# >>> +# This list is about escapes; it contains: +# +# - Monofont text with unescaped nested _italic_. +# - Monofont text with escaped nested \_italic_. +# - Monofont text with an escape character \ . +# +# In other text-bearing blocks +# (paragraphs, block quotes, list items, headings): +# +# - A single escape character immediately followed by markup +# escapes the markup. +# - A single escape character followed by whitespace is preserved. +# - A single escape character anywhere else is ignored. +# - A double escape character is rendered as a single backslash. +# +# Example input: +# +# This list is about escapes; it contains: +# +# - An unescaped class name, RDoc, that will become a link. +# - An escaped class name, \RDoc, that will not become a link. +# - An escape character followed by whitespace \ . +# - An escape character \that is ignored. +# - A double escape character \\ that is rendered +# as a single backslash. +# +# Rendered HTML: +# +# >>> +# This list is about escapes; it contains: +# +# - An unescaped class name, RDoc, that will become a link. +# - An escaped class name, \RDoc, that will not become a link. +# - An escape character followed by whitespace \ . +# - An escape character \that is ignored. +# - A double escape character \\ that is rendered +# as a single backslash. +# # == Documentation Derived from Ruby Code # # [Class] diff --git a/error.c b/error.c index 21a532a8faedc4..07fa04627e8d5d 100644 --- a/error.c +++ b/error.c @@ -357,47 +357,42 @@ warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_ return rb_str_cat2(str, "\n"); } +#define with_warn_vsprintf(file, line, fmt) \ + VALUE str; \ + va_list args; \ + va_start(args, fmt); \ + str = warn_vsprintf(NULL, file, line, fmt, args); \ + va_end(args); + void rb_compile_warn(const char *file, int line, const char *fmt, ...) { - VALUE str; - va_list args; - - if (NIL_P(ruby_verbose)) return; - - va_start(args, fmt); - str = warn_vsprintf(NULL, file, line, fmt, args); - va_end(args); - rb_write_warning_str(str); + if (!NIL_P(ruby_verbose)) { + with_warn_vsprintf(file, line, fmt) { + rb_write_warning_str(str); + } + } } /* rb_compile_warning() reports only in verbose mode */ void rb_compile_warning(const char *file, int line, const char *fmt, ...) { - VALUE str; - va_list args; - - if (!RTEST(ruby_verbose)) return; - - va_start(args, fmt); - str = warn_vsprintf(NULL, file, line, fmt, args); - va_end(args); - rb_write_warning_str(str); + if (RTEST(ruby_verbose)) { + with_warn_vsprintf(file, line, fmt) { + rb_write_warning_str(str); + } + } } void rb_category_compile_warn(rb_warning_category_t category, const char *file, int line, const char *fmt, ...) { - VALUE str; - va_list args; - - if (NIL_P(ruby_verbose)) return; - - va_start(args, fmt); - str = warn_vsprintf(NULL, file, line, fmt, args); - va_end(args); - rb_warn_category(str, rb_warning_category_to_name(category)); + if (!NIL_P(ruby_verbose)) { + with_warn_vsprintf(file, line, fmt) { + rb_warn_category(str, rb_warning_category_to_name(category)); + } + } } RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 0) diff --git a/ext/-test-/abi/extconf.rb b/ext/-test-/abi/extconf.rb index d786b15db98c7f..3b090b75531d90 100644 --- a/ext/-test-/abi/extconf.rb +++ b/ext/-test-/abi/extconf.rb @@ -1,3 +1,4 @@ # frozen_string_literal: false +return unless RUBY_PATCHLEVEL < 0 require_relative "../auto_ext.rb" auto_ext(inc: true) diff --git a/ext/date/date_core.c b/ext/date/date_core.c index c68f70e5f88f95..83d493c794842a 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -4505,6 +4505,9 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass) * Note: * This method recognizes many forms in +string+, * but it is not a validator. + * For formats, see + * {"Specialized Format Strings" in Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-Specialized+Format+Strings] + * * If +string+ does not specify a valid date, * the result is unpredictable; * consider using Date._strptime instead. @@ -4537,6 +4540,8 @@ date_s__parse(int argc, VALUE *argv, VALUE klass) * Note: * This method recognizes many forms in +string+, * but it is not a validator. + * For formats, see + * {"Specialized Format Strings" in Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-Specialized+Format+Strings] * If +string+ does not specify a valid date, * the result is unpredictable; * consider using Date._strptime instead. @@ -4671,7 +4676,7 @@ date_s_iso8601(int argc, VALUE *argv, VALUE klass) * Date._rfc3339(string, limit: 128) -> hash * * Returns a hash of values parsed from +string+, which should be a valid - * {RFC 3339 format}[https://datatracker.ietf.org/doc/html/rfc3339]: + * {RFC 3339 format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-RFC+3339+Format]: * * d = Date.new(2001, 2, 3) * s = d.rfc3339 # => "2001-02-03T00:00:00+00:00" @@ -4699,7 +4704,7 @@ date_s__rfc3339(int argc, VALUE *argv, VALUE klass) * * Returns a new \Date object with values parsed from +string+, * which should be a valid - * {RFC 3339 format}[https://datatracker.ietf.org/doc/html/rfc3339]: + * {RFC 3339 format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-RFC+3339+Format]: * * d = Date.new(2001, 2, 3) * s = d.rfc3339 # => "2001-02-03T00:00:00+00:00" @@ -4811,7 +4816,7 @@ date_s_xmlschema(int argc, VALUE *argv, VALUE klass) * Date._rfc2822(string, limit: 128) -> hash * * Returns a hash of values parsed from +string+, which should be a valid - * {RFC 2822 date format}[https://datatracker.ietf.org/doc/html/rfc2822]: + * {RFC 2822 date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-RFC+2822+Format]: * * d = Date.new(2001, 2, 3) * s = d.rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000" @@ -4841,7 +4846,7 @@ date_s__rfc2822(int argc, VALUE *argv, VALUE klass) * * Returns a new \Date object with values parsed from +string+, * which should be a valid - * {RFC 2822 date format}[https://datatracker.ietf.org/doc/html/rfc2822]: + * {RFC 2822 date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-RFC+2822+Format]: * * d = Date.new(2001, 2, 3) * s = d.rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000" @@ -4885,7 +4890,7 @@ date_s_rfc2822(int argc, VALUE *argv, VALUE klass) * Date._httpdate(string, limit: 128) -> hash * * Returns a hash of values parsed from +string+, which should be a valid - * HTTP date format: + * {HTTP date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-HTTP+Format]: * * d = Date.new(2001, 2, 3) * s = d.httpdate # => "Sat, 03 Feb 2001 00:00:00 GMT" @@ -4911,7 +4916,7 @@ date_s__httpdate(int argc, VALUE *argv, VALUE klass) * * Returns a new \Date object with values parsed from +string+, * which should be a valid - * {RFC 2616 date format}[https://datatracker.ietf.org/doc/html/rfc2616]: + * {HTTP date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-HTTP+Format]: * * d = Date.new(2001, 2, 3) s = d.httpdate # => "Sat, 03 Feb 2001 00:00:00 GMT" @@ -4953,7 +4958,7 @@ date_s_httpdate(int argc, VALUE *argv, VALUE klass) * Date._jisx0301(string, limit: 128) -> hash * * Returns a hash of values parsed from +string+, which should be a valid - * JIS X 0301 date format: + * {JIS X 0301 date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-JIS+X+0301+Format]: * * d = Date.new(2001, 2, 3) * s = d.jisx0301 # => "H13.02.03" @@ -4979,7 +4984,7 @@ date_s__jisx0301(int argc, VALUE *argv, VALUE klass) * Date.jisx0301(string = '-4712-01-01', start = Date::ITALY, limit: 128) -> date * * Returns a new \Date object with values parsed from +string+, - * which should be a valid JIS X 0301 format: + * which should be a valid {JIS X 0301 format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-JIS+X+0301+Format]: * * d = Date.new(2001, 2, 3) * s = d.jisx0301 # => "H13.02.03" @@ -9383,151 +9388,65 @@ Init_date_core(void) negative_inf = -INFINITY; /* - * date and datetime class - Tadayoshi Funaba 1998-2011 - * - * 'date' provides two classes: Date and DateTime. - * - * == Terms and Definitions - * - * Some terms and definitions are based on ISO 8601 and JIS X 0301. - * - * === Calendar Date - * - * The calendar date is a particular day of a calendar year, - * identified by its ordinal number within a calendar month within - * that year. + * \Class \Date provides methods for storing and manipulating + * calendar dates. * - * In those classes, this is so-called "civil". + * Consider using + * {class Time}[https://docs.ruby-lang.org/en/master/Time.html] + * instead of class \Date if: * - * === Ordinal Date + * - You need both dates and times; \Date handles only dates. + * - You need only Gregorian dates (and not Julian dates); + * see {Julian and Gregorian Calendars}[rdoc-ref:calendars.rdoc]. * - * The ordinal date is a particular day of a calendar year identified - * by its ordinal number within the year. + * A \Date object, once created, is immutable, and cannot be modified. * - * In those classes, this is so-called "ordinal". + * == Creating a \Date * - * === Week Date + * You can create a date for the current date, using Date.today: * - * The week date is a date identified by calendar week and day numbers. + * Date.today # => # * - * The calendar week is a seven day period within a calendar year, - * starting on a Monday and identified by its ordinal number within - * the year; the first calendar week of the year is the one that - * includes the first Thursday of that year. In the Gregorian - * calendar, this is equivalent to the week which includes January 4. + * You can create a specific date from various combinations of arguments: * - * In those classes, this is so-called "commercial". + * - Date.new takes integer year, month, and day-of-month: * - * === Julian Day Number + * Date.new(1999, 12, 31) # => # * - * The Julian day number is in elapsed days since noon (Greenwich Mean - * Time) on January 1, 4713 BCE (in the Julian calendar). + * - Date.ordinal takes integer year and day-of-year: * - * In this document, the astronomical Julian day number is the same as - * the original Julian day number. And the chronological Julian day - * number is a variation of the Julian day number. Its days begin at - * midnight on local time. + * Date.ordinal(1999, 365) # => # * - * In this document, when the term "Julian day number" simply appears, - * it just refers to "chronological Julian day number", not the - * original. + * - Date.jd takes integer Julian day: * - * In those classes, those are so-called "ajd" and "jd". + * Date.jd(2451544) # => # * - * === Modified Julian Day Number + * - Date.commercial takes integer commercial data (year, week, day-of-week): * - * The modified Julian day number is in elapsed days since midnight - * (Coordinated Universal Time) on November 17, 1858 CE (in the - * Gregorian calendar). + * Date.commercial(1999, 52, 5) # => # * - * In this document, the astronomical modified Julian day number is - * the same as the original modified Julian day number. And the - * chronological modified Julian day number is a variation of the - * modified Julian day number. Its days begin at midnight on local - * time. + * - Date.parse takes a string, which it parses heuristically: * - * In this document, when the term "modified Julian day number" simply - * appears, it just refers to "chronological modified Julian day - * number", not the original. + * Date.parse('1999-12-31') # => # + * Date.parse('31-12-1999') # => # + * Date.parse('1999-365') # => # + * Date.parse('1999-W52-5') # => # * - * In those classes, those are so-called "amjd" and "mjd". - * - * == Date - * - * A subclass of Object that includes the Comparable module and - * easily handles date. - * - * A Date object is created with Date::new, Date::jd, Date::ordinal, - * Date::commercial, Date::parse, Date::strptime, Date::today, - * Time#to_date, etc. - * - * require 'date' + * - Date.strptime takes a date string and a format string, + * then parses the date string according to the format string: * - * Date.new(2001,2,3) - * #=> # - * Date.jd(2451944) - * #=> # - * Date.ordinal(2001,34) - * #=> # - * Date.commercial(2001,5,6) - * #=> # - * Date.parse('2001-02-03') - * #=> # - * Date.strptime('03-02-2001', '%d-%m-%Y') - * #=> # - * Time.new(2001,2,3).to_date - * #=> # + * Date.strptime('1999-12-31', '%Y-%m-%d') # => # + * Date.strptime('31-12-1999', '%d-%m-%Y') # => # + * Date.strptime('1999-365', '%Y-%j') # => # + * Date.strptime('1999-W52-5', '%G-W%V-%u') # => # + * Date.strptime('1999 52 5', '%Y %U %w') # => # + * Date.strptime('1999 52 5', '%Y %W %u') # => # + * Date.strptime('fri31dec99', '%a%d%b%y') # => # * - * All date objects are immutable; hence cannot modify themselves. + * See also the specialized methods in + * {"Specialized Format Strings" in Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-Specialized+Format+Strings] * - * The concept of a date object can be represented as a tuple - * of the day count, the offset and the day of calendar reform. - * - * The day count denotes the absolute position of a temporal - * dimension. The offset is relative adjustment, which determines - * decoded local time with the day count. The day of calendar - * reform denotes the start day of the new style. The old style - * of the West is the Julian calendar which was adopted by - * Caesar. The new style is the Gregorian calendar, which is the - * current civil calendar of many countries. - * - * The day count is virtually the astronomical Julian day number. - * The offset in this class is usually zero, and cannot be - * specified directly. - * - * A Date object can be created with an optional argument, - * the day of calendar reform as a Julian day number, which - * should be 2298874 to 2426355 or negative/positive infinity. - * The default value is +Date::ITALY+ (2299161=1582-10-15). - * See also sample/cal.rb. - * - * $ ruby sample/cal.rb -c it 10 1582 - * October 1582 - * S M Tu W Th F S - * 1 2 3 4 15 16 - * 17 18 19 20 21 22 23 - * 24 25 26 27 28 29 30 - * 31 - * - * $ ruby sample/cal.rb -c gb 9 1752 - * September 1752 - * S M Tu W Th F S - * 1 2 14 15 16 - * 17 18 19 20 21 22 23 - * 24 25 26 27 28 29 30 - * - * A Date object has various methods. See each reference. - * - * d = Date.parse('3rd Feb 2001') - * #=> # - * d.year #=> 2001 - * d.mon #=> 2 - * d.mday #=> 3 - * d.wday #=> 6 - * d += 1 #=> # - * d.strftime('%a %d %b %Y') #=> "Sun 04 Feb 2001" - * - * === Argument +limit+ + * == Argument +limit+ * * Certain singleton methods in \Date that parse string arguments * also take optional keyword argument +limit+, @@ -9541,7 +9460,6 @@ Init_date_core(void) * - Other non-numeric: raises TypeError. * */ - cDate = rb_define_class("Date", rb_cObject); /* Exception for invalid date/time */ diff --git a/gems/bundled_gems b/gems/bundled_gems index a053812f0a8146..5faa75c5e228ca 100644 --- a/gems/bundled_gems +++ b/gems/bundled_gems @@ -1,16 +1,16 @@ # gem-name version-to-bundle repository-url [optional-commit-hash-to-test-or-defaults-to-v-version] -minitest 5.16.2 https://github.com/seattlerb/minitest -power_assert 2.0.1 https://github.com/ruby/power_assert -rake 13.0.6 https://github.com/ruby/rake -test-unit 3.5.3 https://github.com/test-unit/test-unit -rexml 3.2.5 https://github.com/ruby/rexml -rss 0.2.9 https://github.com/ruby/rss -net-ftp 0.1.3 https://github.com/ruby/net-ftp -net-imap 0.2.3 https://github.com/ruby/net-imap -net-pop 0.1.1 https://github.com/ruby/net-pop -net-smtp 0.3.1 https://github.com/ruby/net-smtp -matrix 0.4.2 https://github.com/ruby/matrix -prime 0.1.2 https://github.com/ruby/prime -rbs 2.6.0 https://github.com/ruby/rbs 5202d4eeed3257448f19004b4baac4bcf4127717 -typeprof 0.21.3 https://github.com/ruby/typeprof -debug 1.6.2 https://github.com/ruby/debug +minitest 5.16.2 https://github.com/seattlerb/minitest +power_assert 2.0.1 https://github.com/ruby/power_assert +rake 13.0.6 https://github.com/ruby/rake +test-unit 3.5.3 https://github.com/test-unit/test-unit +rexml 3.2.5 https://github.com/ruby/rexml +rss 0.2.9 https://github.com/ruby/rss +net-ftp 0.1.3 https://github.com/ruby/net-ftp +net-imap 0.2.3 https://github.com/ruby/net-imap +net-pop 0.1.1 https://github.com/ruby/net-pop +net-smtp 0.3.1 https://github.com/ruby/net-smtp +matrix 0.4.2 https://github.com/ruby/matrix +prime 0.1.2 https://github.com/ruby/prime +rbs 2.6.0 https://github.com/ruby/rbs 5202d4eeed3257448f19004b4baac4bcf4127717 +typeprof 0.21.3 https://github.com/ruby/typeprof +debug 1.6.2 https://github.com/ruby/debug e7c37486ff9579251e5d25645b8d38ec96708f12 diff --git a/include/ruby/internal/abi.h b/include/ruby/internal/abi.h index e42a1777ff5eae..fe1977a9a181a0 100644 --- a/include/ruby/internal/abi.h +++ b/include/ruby/internal/abi.h @@ -1,6 +1,8 @@ #ifndef RUBY_ABI_H #define RUBY_ABI_H +#ifdef RUBY_ABI_VERSION /* should match the definition in config.h */ + /* This number represents Ruby's ABI version. * * In development Ruby, it should be bumped every time an ABI incompatible @@ -19,7 +21,7 @@ * - Backwards compatible refactors. * - Editing comments. * - * In released versions of Ruby, this number should not be changed since teeny + * In released versions of Ruby, this number is not defined since teeny * versions of Ruby should guarantee ABI compatibility. */ #define RUBY_ABI_VERSION 2 @@ -49,3 +51,5 @@ ruby_abi_version(void) #endif #endif + +#endif diff --git a/include/ruby/internal/encoding/ctype.h b/include/ruby/internal/encoding/ctype.h index 64aaf0a990898a..05c314aeb3d487 100644 --- a/include/ruby/internal/encoding/ctype.h +++ b/include/ruby/internal/encoding/ctype.h @@ -36,8 +36,8 @@ RBIMPL_SYMBOL_EXPORT_BEGIN() * @param[in] p Pointer to a possibly-middle of a character. * @param[in] end End of the string. * @param[in] enc Encoding. - * @retval 0 It isn't. - * @retval otherwise It is. + * @retval false It isn't. + * @retval true It is. */ static inline bool rb_enc_is_newline(const char *p, const char *e, rb_encoding *enc) @@ -53,11 +53,11 @@ rb_enc_is_newline(const char *p, const char *e, rb_encoding *enc) * encoding. The "character type" here is a set of macros defined in onigmo.h, * like `ONIGENC_CTYPE_PUNCT`. * - * @param[in] c An `OnigCodePoint` value. - * @param[in] t An `OnigCtype` value. - * @param[in] enc A `rb_encoding*` value. - * @retval 1 `c` is of `t` in `enc`. - * @retval 0 Otherwise. + * @param[in] c An `OnigCodePoint` value. + * @param[in] t An `OnigCtype` value. + * @param[in] enc A `rb_encoding*` value. + * @retval true `c` is of `t` in `enc`. + * @retval false Otherwise. */ static inline bool rb_enc_isctype(OnigCodePoint c, OnigCtype t, rb_encoding *enc) @@ -68,10 +68,10 @@ rb_enc_isctype(OnigCodePoint c, OnigCtype t, rb_encoding *enc) /** * Identical to rb_isascii(), except it additionally takes an encoding. * - * @param[in] c A code point. - * @param[in] enc An encoding. - * @retval 0 `c` is out of range of ASCII character set in `enc`. - * @retval 1 Otherwise. + * @param[in] c A code point. + * @param[in] enc An encoding. + * @retval false `c` is out of range of ASCII character set in `enc`. + * @retval true Otherwise. * * @internal * @@ -87,10 +87,10 @@ rb_enc_isascii(OnigCodePoint c, rb_encoding *enc) /** * Identical to rb_isalpha(), except it additionally takes an encoding. * - * @param[in] c A code point. - * @param[in] enc An encoding. - * @retval 1 `enc` classifies `c` as "ALPHA". - * @retval 0 Otherwise. + * @param[in] c A code point. + * @param[in] enc An encoding. + * @retval true `enc` classifies `c` as "ALPHA". + * @retval false Otherwise. */ static inline bool rb_enc_isalpha(OnigCodePoint c, rb_encoding *enc) @@ -101,10 +101,10 @@ rb_enc_isalpha(OnigCodePoint c, rb_encoding *enc) /** * Identical to rb_islower(), except it additionally takes an encoding. * - * @param[in] c A code point. - * @param[in] enc An encoding. - * @retval 1 `enc` classifies `c` as "LOWER". - * @retval 0 Otherwise. + * @param[in] c A code point. + * @param[in] enc An encoding. + * @retval true `enc` classifies `c` as "LOWER". + * @retval false Otherwise. */ static inline bool rb_enc_islower(OnigCodePoint c, rb_encoding *enc) @@ -115,10 +115,10 @@ rb_enc_islower(OnigCodePoint c, rb_encoding *enc) /** * Identical to rb_isupper(), except it additionally takes an encoding. * - * @param[in] c A code point. - * @param[in] enc An encoding. - * @retval 1 `enc` classifies `c` as "UPPER". - * @retval 0 Otherwise. + * @param[in] c A code point. + * @param[in] enc An encoding. + * @retval true `enc` classifies `c` as "UPPER". + * @retval false Otherwise. */ static inline bool rb_enc_isupper(OnigCodePoint c, rb_encoding *enc) @@ -126,13 +126,27 @@ rb_enc_isupper(OnigCodePoint c, rb_encoding *enc) return ONIGENC_IS_CODE_UPPER(enc, c); } +/** + * Identical to rb_iscntrl(), except it additionally takes an encoding. + * + * @param[in] c A code point. + * @param[in] enc An encoding. + * @retval true `enc` classifies `c` as "CNTRL". + * @retval false Otherwise. + */ +static inline bool +rb_enc_iscntrl(OnigCodePoint c, rb_encoding *enc) +{ + return ONIGENC_IS_CODE_CNTRL(enc, c); +} + /** * Identical to rb_ispunct(), except it additionally takes an encoding. * - * @param[in] c A code point. - * @param[in] enc An encoding. - * @retval 1 `enc` classifies `c` as "PUNCT". - * @retval 0 Otherwise. + * @param[in] c A code point. + * @param[in] enc An encoding. + * @retval true `enc` classifies `c` as "PUNCT". + * @retval false Otherwise. */ static inline bool rb_enc_ispunct(OnigCodePoint c, rb_encoding *enc) @@ -143,10 +157,10 @@ rb_enc_ispunct(OnigCodePoint c, rb_encoding *enc) /** * Identical to rb_isalnum(), except it additionally takes an encoding. * - * @param[in] c A code point. - * @param[in] enc An encoding. - * @retval 1 `enc` classifies `c` as "ANUM". - * @retval 0 Otherwise. + * @param[in] c A code point. + * @param[in] enc An encoding. + * @retval true `enc` classifies `c` as "ANUM". + * @retval false Otherwise. */ static inline bool rb_enc_isalnum(OnigCodePoint c, rb_encoding *enc) @@ -157,10 +171,10 @@ rb_enc_isalnum(OnigCodePoint c, rb_encoding *enc) /** * Identical to rb_isprint(), except it additionally takes an encoding. * - * @param[in] c A code point. - * @param[in] enc An encoding. - * @retval 1 `enc` classifies `c` as "PRINT". - * @retval 0 Otherwise. + * @param[in] c A code point. + * @param[in] enc An encoding. + * @retval true `enc` classifies `c` as "PRINT". + * @retval false Otherwise. */ static inline bool rb_enc_isprint(OnigCodePoint c, rb_encoding *enc) @@ -171,10 +185,10 @@ rb_enc_isprint(OnigCodePoint c, rb_encoding *enc) /** * Identical to rb_isspace(), except it additionally takes an encoding. * - * @param[in] c A code point. - * @param[in] enc An encoding. - * @retval 1 `enc` classifies `c` as "PRINT". - * @retval 0 Otherwise. + * @param[in] c A code point. + * @param[in] enc An encoding. + * @retval true `enc` classifies `c` as "PRINT". + * @retval false Otherwise. */ static inline bool rb_enc_isspace(OnigCodePoint c, rb_encoding *enc) @@ -185,10 +199,10 @@ rb_enc_isspace(OnigCodePoint c, rb_encoding *enc) /** * Identical to rb_isdigit(), except it additionally takes an encoding. * - * @param[in] c A code point. - * @param[in] enc An encoding. - * @retval 1 `enc` classifies `c` as "DIGIT". - * @retval 0 Otherwise. + * @param[in] c A code point. + * @param[in] enc An encoding. + * @retval true `enc` classifies `c` as "DIGIT". + * @retval false Otherwise. */ static inline bool rb_enc_isdigit(OnigCodePoint c, rb_encoding *enc) @@ -235,6 +249,7 @@ RBIMPL_SYMBOL_EXPORT_END() #define rb_enc_isdigit rb_enc_isdigit #define rb_enc_islower rb_enc_islower #define rb_enc_isprint rb_enc_isprint +#define rb_enc_iscntrl rb_enc_iscntrl #define rb_enc_ispunct rb_enc_ispunct #define rb_enc_isspace rb_enc_isspace #define rb_enc_isupper rb_enc_isupper diff --git a/iseq.c b/iseq.c index 3d40b88a0de1bc..f17a2d49b61278 100644 --- a/iseq.c +++ b/iseq.c @@ -175,7 +175,7 @@ rb_iseq_free(const rb_iseq_t *iseq) iseq_clear_ic_references(iseq); struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq); mjit_free_iseq(iseq); /* Notify MJIT */ -#if YJIT_BUILD +#if USE_YJIT rb_yjit_iseq_free(body->yjit_payload); #endif ruby_xfree((void *)body->iseq_encoded); @@ -438,7 +438,7 @@ rb_iseq_update_references(rb_iseq_t *iseq) #if USE_MJIT mjit_update_references(iseq); #endif -#if YJIT_BUILD +#if USE_YJIT rb_yjit_iseq_update_references(body->yjit_payload); #endif } @@ -526,7 +526,7 @@ rb_iseq_mark(const rb_iseq_t *iseq) #if USE_MJIT mjit_mark_cc_entries(body); #endif -#if YJIT_BUILD +#if USE_YJIT rb_yjit_iseq_mark(body->yjit_payload); #endif } diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 21c06e55bab503..0ab0451695b36e 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -888,7 +888,7 @@ def remove_ruby_from_platforms_if_necessary!(dependencies) Bundler.local_platform == Gem::Platform::RUBY || !platforms.include?(Gem::Platform::RUBY) || (@new_platform && platforms.last == Gem::Platform::RUBY) || - !@originally_locked_specs.incomplete_ruby_specs?(dependencies) + !@originally_locked_specs.incomplete_ruby_specs?(expand_dependencies(dependencies)) remove_platform(Gem::Platform::RUBY) add_current_platform diff --git a/lib/error_highlight/base.rb b/lib/error_highlight/base.rb index dbd173a5cd4768..4c115cc8285c6b 100644 --- a/lib/error_highlight/base.rb +++ b/lib/error_highlight/base.rb @@ -22,6 +22,14 @@ module ErrorHighlight # snippet: String, # script_lines: [String], # } | nil + # + # Limitations: + # + # Currently, ErrorHighlight.spot only supports a single-line code fragment. + # Therefore, if the return value is not nil, first_lineno and last_lineno will have + # the same value. If the relevant code fragment spans multiple lines + # (e.g., Array#[] of +ary[(newline)expr(newline)]+), the method will return nil. + # This restriction may be removed in the future. def self.spot(obj, **opts) case obj when Exception diff --git a/numeric.rb b/numeric.rb index 9f2200d2a87642..c2091465f88fd5 100644 --- a/numeric.rb +++ b/numeric.rb @@ -227,6 +227,23 @@ def zero? Primitive.attr! 'inline' Primitive.cexpr! 'rb_int_zero_p(self)' end + + # call-seq: + # ceildiv(other) -> integer + # + # Returns the result of division +self+ by +other+. The result is rounded up to the nearest integer. + # + # 3.ceildiv(3) # => 1 + # 4.ceildiv(3) # => 2 + # + # 4.ceildiv(-3) # => -1 + # -4.ceildiv(3) # => -1 + # -4.ceildiv(-3) # => 2 + # + # 3.ceildiv(1.2) # => 3 + def ceildiv(other) + -div(-other) + end end # call-seq: diff --git a/parse.y b/parse.y index b4c3106b8cf141..d0f37a18ccb1ac 100644 --- a/parse.y +++ b/parse.y @@ -9299,6 +9299,7 @@ parser_yylex(struct parser_params *p) case '\004': /* ^D */ case '\032': /* ^Z */ case -1: /* end of script. */ + p->eofp = 1; return 0; /* white spaces */ diff --git a/process.c b/process.c index 0e4dbc40f4d26c..57df2dc06fbf89 100644 --- a/process.c +++ b/process.c @@ -4328,12 +4328,30 @@ rb_fork_ruby(int *status) return pid; } +static rb_pid_t +proc_fork_pid(void) +{ + rb_pid_t pid = rb_fork_ruby(NULL); + + if (pid == -1) { + rb_sys_fail("fork(2)"); + } + + return pid; +} + rb_pid_t rb_call_proc__fork(void) { - VALUE pid = rb_funcall(rb_mProcess, rb_intern("_fork"), 0); - - return NUM2PIDT(pid); + ID id__fork; + CONST_ID(id__fork, "_fork"); + if (rb_method_basic_definition_p(CLASS_OF(rb_mProcess), id__fork)) { + return proc_fork_pid(); + } + else { + VALUE pid = rb_funcall(rb_mProcess, id__fork, 0); + return NUM2PIDT(pid); + } } #endif @@ -4360,12 +4378,7 @@ rb_call_proc__fork(void) VALUE rb_proc__fork(VALUE _obj) { - rb_pid_t pid = rb_fork_ruby(NULL); - - if (pid == -1) { - rb_sys_fail("fork(2)"); - } - + rb_pid_t pid = proc_fork_pid(); return PIDT2NUM(pid); } diff --git a/ruby.c b/ruby.c index 7c6742cac47905..66feeb797e6cf6 100644 --- a/ruby.c +++ b/ruby.c @@ -111,7 +111,7 @@ void rb_warning_category_update(unsigned int mask, unsigned int bits); enum feature_flag_bits { EACH_FEATURES(DEFINE_FEATURE, COMMA), feature_debug_flag_first, -#if defined(MJIT_FORCE_ENABLE) || !YJIT_BUILD +#if defined(MJIT_FORCE_ENABLE) || !USE_YJIT DEFINE_FEATURE(jit) = feature_mjit, #else DEFINE_FEATURE(jit) = feature_yjit, @@ -248,7 +248,7 @@ usage(const char *name, int help, int highlight, int columns) #define M(shortopt, longopt, desc) RUBY_OPT_MESSAGE(shortopt, longopt, desc) -#if YJIT_BUILD +#if USE_YJIT # define PLATFORM_JIT_OPTION "--yjit" #else # define PLATFORM_JIT_OPTION "--mjit" @@ -278,7 +278,7 @@ usage(const char *name, int help, int highlight, int columns) #if USE_MJIT M("--mjit", "", "enable C compiler-based JIT compiler (experimental)"), #endif -#if YJIT_BUILD +#if USE_YJIT M("--yjit", "", "enable in-process JIT compiler (experimental)"), #endif M("-h", "", "show this message, --help for more info"), @@ -312,7 +312,7 @@ usage(const char *name, int help, int highlight, int columns) #if USE_MJIT M("mjit", "", "C compiler-based JIT compiler (default: disabled)"), #endif -#if YJIT_BUILD +#if USE_YJIT M("yjit", "", "in-process JIT compiler (default: disabled)"), #endif }; @@ -323,7 +323,7 @@ usage(const char *name, int help, int highlight, int columns) #if USE_MJIT extern const struct ruby_opt_message mjit_option_messages[]; #endif -#if YJIT_BUILD +#if USE_YJIT static const struct ruby_opt_message yjit_options[] = { #if YJIT_STATS M("--yjit-stats", "", "Enable collecting YJIT statistics"), @@ -365,7 +365,7 @@ usage(const char *name, int help, int highlight, int columns) for (i = 0; mjit_option_messages[i].str; ++i) SHOW(mjit_option_messages[i]); #endif -#if YJIT_BUILD +#if USE_YJIT printf("%s""YJIT options (experimental):%s\n", sb, se); for (i = 0; i < numberof(yjit_options); ++i) SHOW(yjit_options[i]); @@ -1047,7 +1047,7 @@ set_option_encoding_once(const char *type, VALUE *name, const char *e, long elen #define yjit_opt_match_arg(s, l, name) \ opt_match(s, l, name) && (*(s) && *(s+1) ? 1 : (rb_raise(rb_eRuntimeError, "--yjit-" name " needs an argument"), 0)) -#if YJIT_BUILD +#if USE_YJIT static bool setup_yjit_options(const char *s) { @@ -1452,7 +1452,7 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt) #endif } else if (is_option_with_optarg("yjit", '-', true, false, false)) { -#if YJIT_BUILD +#if USE_YJIT FEATURE_SET(opt->features, FEATURE_BIT(yjit)); setup_yjit_options(s); #else @@ -1831,7 +1831,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior"); if (!(FEATURE_SET_BITS(opt->features) & feature_jit_mask)) { -#if YJIT_BUILD +#if USE_YJIT if (!FEATURE_USED_P(opt->features, yjit) && getenv("RUBY_YJIT_ENABLE")) { FEATURE_SET(opt->features, FEATURE_BIT(yjit)); } @@ -1847,7 +1847,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) opt->mjit.on = TRUE; /* set mjit.on for ruby_show_version() API and check to call mjit_init() */ } #endif -#if YJIT_BUILD +#if USE_YJIT if (FEATURE_SET_P(opt->features, yjit)) { rb_yjit_init(); } diff --git a/spec/bundler/install/gemfile/specific_platform_spec.rb b/spec/bundler/install/gemfile/specific_platform_spec.rb index fe1c3b71fe1913..bb5526203fc376 100644 --- a/spec/bundler/install/gemfile/specific_platform_spec.rb +++ b/spec/bundler/install/gemfile/specific_platform_spec.rb @@ -445,6 +445,47 @@ L end + it "does not remove ruby if gems for other platforms, and not present in the lockfile, exist in the Gemfile" do + build_repo4 do + build_gem "nokogiri", "1.13.8" + build_gem "nokogiri", "1.13.8" do |s| + s.platform = Gem::Platform.local + end + end + + gemfile <<~G + source "#{file_uri_for(gem_repo4)}" + + gem "nokogiri" + + gem "tzinfo", "~> 1.2", platform: :#{not_local_tag} + G + + original_lockfile = <<~L + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + nokogiri (1.13.8) + nokogiri (1.13.8-#{Gem::Platform.local}) + + PLATFORMS + #{lockfile_platforms_for([specific_local_platform, "ruby"])} + + DEPENDENCIES + nokogiri + tzinfo (~> 1.2) + + BUNDLED WITH + #{Bundler::VERSION} + L + + lockfile original_lockfile + + bundle "lock --update" + + expect(lockfile).to eq(original_lockfile) + end + it "can fallback to a source gem when platform gems are incompatible with current ruby version" do setup_multiplatform_gem_with_source_gem diff --git a/template/Makefile.in b/template/Makefile.in index 7968619f9a1a16..facbf062f42a6a 100644 --- a/template/Makefile.in +++ b/template/Makefile.in @@ -397,12 +397,13 @@ uncommon.mk: $(srcdir)/common.mk reconfig-args = $(srcdir)/$(CONFIGURE) $(yes_silence:yes=--silent) $(configure_args) config.status-args = ./config.status $(yes_silence:yes=--silent) --recheck reconfig-exec-0 = test -t 1 && { : $${CONFIGURE_TTY=yes}; export CONFIGURE_TTY; }; exec 3>&1; exit `exec 4>&1; { "$$@" 3>&- 4>&-; echo $$? 1>&4; } | fgrep -v '(cached)' 1>&3 3>&- 4>&-` -reconfig-exec-1 = set -x; "$$@" +reconfig-exec-1 = set -x; exec "$$@" +reconfig-exec-yes = $(reconfig-exec-1) reconfig config.status: $(srcdir)/$(CONFIGURE) $(srcdir)/enc/Makefile.in \ $(hdrdir)/ruby/version.h $(ABI_VERSION_HDR) @PWD= MINIRUBY="$(MINIRUBY)"; export MINIRUBY; \ - set $(SHELL) $($@-args); $(reconfig-exec-$(V)) + set $(SHELL) $($@-args); $(reconfig-exec-$(silence:no=$(V))) $(srcdir)/$(CONFIGURE): $(srcdir)/configure.ac $(CHDIR) $(srcdir) && exec $(AUTOCONF) -o $(@F) diff --git a/test/-ext-/test_abi.rb b/test/-ext-/test_abi.rb index 59e70107a5dd57..d3ea6bb9b105fe 100644 --- a/test/-ext-/test_abi.rb +++ b/test/-ext-/test_abi.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +return unless RUBY_PATCHLEVEL < 0 + class TestABI < Test::Unit::TestCase def test_require_lib_with_incorrect_abi_on_dev_ruby omit "ABI is not checked" unless abi_checking_supported? diff --git a/test/rinda/test_rinda.rb b/test/rinda/test_rinda.rb index d8340e0fc48dff..dbe414b783fefd 100644 --- a/test/rinda/test_rinda.rb +++ b/test/rinda/test_rinda.rb @@ -583,6 +583,22 @@ def test_take_bug_8215 end end +module RingIPv4 + def ipv4_mc(rf) + begin + v4mc = rf.make_socket('239.0.0.1') + rescue Errno::ENETUNREACH, Errno::ENOBUFS, Errno::ENODEV + omit 'IPv4 multicast not available' + end + + begin + yield v4mc + ensure + v4mc.close + end + end +end + module RingIPv6 def prepare_ipv6(r) begin @@ -625,6 +641,7 @@ def ipv6_mc(rf, hops = nil) end class TestRingServer < Test::Unit::TestCase + include RingIPv4 def setup @port = Rinda::Ring_PORT @@ -697,27 +714,23 @@ def test_make_socket_unicast end def test_make_socket_ipv4_multicast - begin - v4mc = @rs.make_socket('239.0.0.1') - rescue Errno::ENOBUFS => e - omit "Missing multicast support in OS: #{e.message}" - end - - begin - if Socket.const_defined?(:SO_REUSEPORT) then - assert(v4mc.getsockopt(:SOCKET, :SO_REUSEPORT).bool) - else - assert(v4mc.getsockopt(:SOCKET, :SO_REUSEADDR).bool) - end - rescue TypeError - if /aix/ =~ RUBY_PLATFORM - omit "Known bug in getsockopt(2) on AIX" + ipv4_mc(@rs) do |v4mc| + begin + if Socket.const_defined?(:SO_REUSEPORT) then + assert(v4mc.getsockopt(:SOCKET, :SO_REUSEPORT).bool) + else + assert(v4mc.getsockopt(:SOCKET, :SO_REUSEADDR).bool) + end + rescue TypeError + if /aix/ =~ RUBY_PLATFORM + omit "Known bug in getsockopt(2) on AIX" + end + raise $! end - raise $! - end - assert_equal('0.0.0.0', v4mc.local_address.ip_address) - assert_equal(@port, v4mc.local_address.ip_port) + assert_equal('0.0.0.0', v4mc.local_address.ip_address) + assert_equal(@port, v4mc.local_address.ip_port) + end end def test_make_socket_ipv6_multicast @@ -746,7 +759,7 @@ def test_ring_server_ipv4_multicast @rs.shutdown begin @rs = Rinda::RingServer.new(@ts, [['239.0.0.1', '0.0.0.0']], @port) - rescue Errno::ENOBUFS => e + rescue Errno::ENOBUFS, Errno::ENODEV => e omit "Missing multicast support in OS: #{e.message}" end @@ -848,6 +861,7 @@ def wait_for(n) class TestRingFinger < Test::Unit::TestCase include RingIPv6 + include RingIPv4 def setup @rf = Rinda::RingFinger.new @@ -867,12 +881,10 @@ def test_make_socket_unicast end def test_make_socket_ipv4_multicast - v4mc = @rf.make_socket('239.0.0.1') - - assert_equal(1, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_LOOP).ipv4_multicast_loop) - assert_equal(1, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL).ipv4_multicast_ttl) - ensure - v4mc.close if v4mc + ipv4_mc(@rf) do |v4mc| + assert_equal(1, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_LOOP).ipv4_multicast_loop) + assert_equal(1, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL).ipv4_multicast_ttl) + end end def test_make_socket_ipv6_multicast @@ -884,10 +896,9 @@ def test_make_socket_ipv6_multicast def test_make_socket_ipv4_multicast_hops @rf.multicast_hops = 2 - v4mc = @rf.make_socket('239.0.0.1') - assert_equal(2, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL).ipv4_multicast_ttl) - ensure - v4mc.close if v4mc + ipv4_mc(@rf) do |v4mc| + assert_equal(2, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL).ipv4_multicast_ttl) + end end def test_make_socket_ipv6_multicast_hops diff --git a/test/ripper/test_lexer.rb b/test/ripper/test_lexer.rb index 83130668be79b0..4f3f4657efe4df 100644 --- a/test/ripper/test_lexer.rb +++ b/test/ripper/test_lexer.rb @@ -100,6 +100,20 @@ def test_stack_at_on_heredoc_beg assert_equal expect, Ripper.lex(src).map {|e| e[1]} end + def test_end_of_script_char + all_assertions do |all| + ["a", %w"[a ]", %w"{, }", "if"].each do |src, append| + expected = Ripper.lex(src).map {|e| e[1]} + ["\0b", "\4b", "\32b"].each do |eof| + c = "#{src}#{eof}#{append}" + all.for(c) do + assert_equal expected, Ripper.lex(c).map {|e| e[1]} + end + end + end + end + end + def test_slice assert_equal "string\#{nil}\n", Ripper.slice(%(< $(@) @$(CPP) -I$(srcdir) -I$(srcdir)/include <<"Creating $(@)" > $(*F).bat && cmd /c $(*F).bat > $(@) @echo off #define RUBY_REVISION 0 @@ -198,8 +199,9 @@ echo RUBY_RELEASE_DAY = %ruby_release_day:~-2% echo MAJOR = RUBY_VERSION_MAJOR echo MINOR = RUBY_VERSION_MINOR echo TEENY = RUBY_VERSION_TEENY -echo ABI_VERSION = RUBY_ABI_VERSION #if defined RUBY_PATCHLEVEL && RUBY_PATCHLEVEL < 0 +#include "$(@F)" +echo ABI_VERSION = RUBY_ABI_VERSION #endif set /a MSC_VER = _MSC_VER #if _MSC_VER >= 1920 diff --git a/yjit.h b/yjit.h index d912f6e2080485..c9dc52c9b670e3 100644 --- a/yjit.h +++ b/yjit.h @@ -15,24 +15,15 @@ # define YJIT_STATS RUBY_DEBUG #endif -// YJIT is supported on Mac/Linux platforms with x86-64 or ARM64 CPUs -#if (defined(__x86_64__) && !defined(_WIN32)) || (defined(__ARM_ARCH_ISA_A64) && !defined(_WIN32)) || (defined(_WIN32) && defined(_M_AMD64)) // x64 platforms without mingw/msys -# define YJIT_SUPPORTED_P 1 -#else -# define YJIT_SUPPORTED_P 0 -#endif +#if USE_YJIT -// Is the output binary going to include YJIT? -#if USE_MJIT && USE_YJIT && YJIT_SUPPORTED_P -# define YJIT_BUILD 1 +// We generate x86 or arm64 assembly +#if defined(_WIN32) ? defined(_M_AMD64) : (defined(__x86_64__) || defined(__aarch64__)) +// x86_64 platforms without mingw/msys or x64-mswin #else -# define YJIT_BUILD 0 +# error YJIT unsupported platform #endif -#undef YJIT_SUPPORTED_P - -#if YJIT_BUILD - // Expose these as declarations since we are building YJIT. bool rb_yjit_enabled_p(void); unsigned rb_yjit_call_threshold(void); @@ -54,7 +45,7 @@ void rb_yjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic); void rb_yjit_tracing_invalidate_all(void); #else -// !YJIT_BUILD +// !USE_YJIT // In these builds, YJIT could never be turned on. Provide dummy implementations. static inline bool rb_yjit_enabled_p(void) { return false; } @@ -76,6 +67,6 @@ static inline void rb_yjit_before_ractor_spawn(void) {} static inline void rb_yjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic) {} static inline void rb_yjit_tracing_invalidate_all(void) {} -#endif // #if YJIT_BUILD +#endif // #if USE_YJIT #endif // #ifndef YJIT_H