7570 Commits
Author SHA1 Message Date
Hiroshi SHIBATA 5483bfc1ae Bump up to 3.2.11 2026-03-27 06:53:23 +09:00
Hiroshi SHIBATA 2051ac34b7 merge revision(s) d209e6f1c0: [Backport #21715]
search_nonascii(): Replace UB pointer cast with memcpy

	Casting a pointer to create an unaligned one is undefined behavior in C
	standards. Use memcpy to express the unaligned load instead to play by
	the rules.

	Practically, this yields the same binary output in many situations
	while fixing the crash in [Bug #21715].
2026-01-19 11:23:42 +09:00
Hiroshi SHIBATA a3a6d25788 Bump up to 3.2.10 2026-01-14 09:56:38 +09:00
Hiroshi SHIBATA 8f611e0c46 bump teeny 2025-07-24 17:27:18 +09:00
Hiroshi SHIBATA f91480d7a6 merge revision(s) 719486a642: [Backport #21286]
Fix C23 (GCC 15) WIN32 compatibility for rb_define_* functions

	Fixes [Bug #21286]
2025-05-13 11:22:38 +09:00
Hiroshi SHIBATA 13f495dc2c bump teeny 2025-03-26 13:18:02 +09:00
Hiroshi SHIBATA 469a0a4a08 merge revision(s) da4464b824: [Backport #19426]
[Bug #19426] Fix endless `Range#step` with `#succ` method
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA 998c26cd28 merge revision(s) 79eb75a8dd: [Backport #20025]
[Bug #20025] Check if upper/lower before fallback to case-folding
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA 774e3f0003 merge revision(s) 08b3a45bc9: [Backport #21180]
Push a real iseq in rb_vm_push_frame_fname()

	Previously, vm_make_env_each() (used during proc
	creation and for the debug inspector C API) picked up the
	non-GC-allocated iseq that rb_vm_push_frame_fname() creates,
	which led to a SEGV when the GC tried to mark the non GC object.

	Put a real iseq imemo instead. Speed should be about the same since
	the old code also did a imemo allocation and a malloc allocation.

	Real iseq allows ironing out the special-casing of dummy frames in
	rb_execution_context_mark() and rb_execution_context_update(). A check
	is added to RubyVM::ISeq#eval, though, to stop attempts to run dummy
	iseqs.

	[Bug #21180]

	Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA f89a334b55 merge revision(s) bccec7fb46, 5f8ebcada0, e13575bb79, 4adcfc8cd7: [Backport #19584]
Fix crash in rb_gc_register_address

	[Bug #19584]

	Some C extensions pass a pointer to a global variable to
	rb_gc_register_address. However, if a GC is triggered inside of
	rb_gc_register_address, then the object could get swept since it does
	not exist on the stack.

	[Bug #19584] Register global variable address before assignment

	[Bug #19584] Register global variables before assignment

	[Bug #19584] [DOC] Tweek description of `rb_gc_register_address`
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA 6dd8bd0d90 merge revision(s) f423f6e10c: [Backport #21131]
Ensure IO.copy_stream buffer is an independent string

	Otherwise, changes to the buffer by the destination write method
	could result in data changing for supposedly independent strings.

	Fixes [Bug #21131]
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA 1c9af6c10f merge revision(s) d4a1a2780c: [Backport #21032]
rb_feature_p: skip `get_expanded_load_path` for absolute paths

	Ref: https://github.com/fxn/zeitwerk/pull/308

	```ruby
	require 'benchmark'

	$LOAD_PATH << 'relative-path'

	autoload :FOO, '/tmp/foo.rb'

	puts Benchmark.realtime {
	  500_000.times do
	    Object.autoload?(:FOO)
	  end
	}
	```

	The above script takes 2.5 seconds on `master`, and only
	50ms on this branch.

	When we're looking for a feature with an absolute path, we don't
	need to call the expensive `get_expanded_load_path`.
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA 0ef3411b98 merge revision(s) 6473903082: [Backport #18257]
[Bug #18257] Register the class path of FrozenCore to mark

	ICLASS does not have the path usually, so it needs to be registered
	separately.
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA f7ec9546ee merge revision(s) 3f07bc76ff, 34098b669c: [Backport #21144]
[Bug #21144] Win32: Use Windows time zone ID if TZ is not set

	If the TZ environment variable is not set, the time zone names
	retrieved from the system are localized for UI display and may vary
	across editions and language packs for the same time zone.
	Use the time zone IDs that are invariant across environments instead.

	[Bug #21144] Win32: Convert the time zone name to the current locale

	The Windows time zone IDs provided by Microsoft as of 24H1 are ASCII
	only all, but the API itself is not impossible to set non-ASCII key
	name.  Prefer the current locale encoding for now until we move to
	UTF-8 including environment variables and command line arguments.
2025-03-10 15:48:58 +09:00
Hiroshi SHIBATA 98fc456891 merge revision(s) 2b6fc9ea72: [Backport #21092]
[Bug #21092] Fallback variables after execonf has done

	When reading from a dummy makefile, the global variables initialized
	in `init_mkmf` may not be overridden.
	---
	 ext/extmk.rb | 6 +++---
	 1 file changed, 3 insertions(+), 3 deletions(-)
2025-02-28 15:06:44 +09:00
nagachika 02ec315244 bump teeny 2025-02-04 20:33:29 +09:00
nagachika 7c0c2df9b4 merge revision(s) dd80d9b089: [Backport #20997]
YJIT: Filter `&` calls from specialized C method codegen

	Evident with the crash reported in [Bug #20997], the C replacement
	codegen functions aren't authored to handle block arguments (nor
	should they because the extra code from the complexity defeats
	optimization). Filter sites with VM_CALL_ARGS_BLOCKARG.
2025-01-25 14:51:31 +09:00
nagachika 97243cc9c7 merge revision(s) 04ec077946: [Backport #21038]
Preserve `errno` in `rb_fiber_scheduler_unblock`. (#12576)

	[Bug #21038]

	Co-authored-by: Julian Scheid <julians37@gmail.com>
2025-01-25 14:39:22 +09:00
nagachika f9adaab928 merge revision(s) e0d600ec19: [Backport #21012]
Avoid opt_aset_with optimization inside multiple assignment

	Previously, since the opt_aset_with optimization was introduced,
	use of the opt_aset_with optimization inside multiple assignment
	would result in a segfault or incorrect instructions.

	Fixes [Bug #21012]

	Co-authored-by: Nobuyoshi Nakada <nobu.nakada@gmail.com>
2025-01-25 14:37:41 +09:00
nagachika 845763fdf3 merge revision(s) b176d4f52e: [Backport #21008]
[Bug #21008] Normalize before sum to float

	After switching to `Float`-mode when summing `Numeric` objects,
	normalization for `Float` is still needed.
2025-01-11 15:32:49 +09:00
nagachika f150d67b7d merge revision(s) 8034e9c3d0: [Backport #20995]
[Bug #20995] Protect `IO.popen` block from exiting by exception
2025-01-11 15:30:06 +09:00
nagachika 4e59c10646 merge revision(s) 19c39e4cfa, d78ff6a767: [Backport #20984]
[Bug #20984] ENV.inspect should be encoding aware

	[Bug #20984] Fix test with locale encoding
2025-01-11 15:28:05 +09:00
nagachika 1d57924d69 merge revision(s) a1758fbd7f:
Crash when malloc during GC

	This feature was introduced in commit 2ccf6e5, but I realized that
	using rb_warn is a bad idea because it allocates objects, which causes
	a different crash ("object allocation during garbage collection phase").
	We should just hard crash here instead.
2024-12-21 13:31:11 +09:00
nagachika 3110d5c8ab merge revision(s) e90b447655: [Backport #20924]
[Bug #20924] Fix reading with delimiter in wide character encodings
2024-12-15 16:18:43 +09:00
nagachika 59254caff0 merge revision(s) 055613fd86: [Backport #20447]
Fix pointer incompatiblity

	Since the subsecond part is discarded, WIDEVAL to VALUE conversion is
	needed.
2024-12-15 15:31:58 +09:00
nagachika 303a83d35c merge revision(s) 660b995365: [Backport #20915]
[Bug #20915] Fix SEGV with `TracePoint#parameters` and aliased C method

	The following snippet results with a SEGV:

	```ruby
	C = Class.new do
	  alias_method :new_to_s, :to_s
	end

	TracePoint.new(:c_call, &:parameters).enable { C.new.new_to_s }
	```

	at MRI 3.3.6 and ruby 3.4.0dev

	The root cause of the issue lies in the `rb_tracearg_parameters` function
	within the `RUBY_EVENT_C_RETURN` branch. Specifically, when the invoked
	method is an alias for a C function,
	`rb_method_entry_without_refinements(..., trace_arg->called_id, ...)`
	may return NULL. In that case we can fallback to `trace_arg->id`.
2024-12-15 15:28:25 +09:00
nagachika d78e1a4133 merge revision(s) f65a6c090c: [Backport #20921]
Fix use-after-free in constant cache

	[Bug #20921]

	When we create a cache entry for a constant, the following sequence of
	events could happen:

	- vm_track_constant_cache is called to insert a constant cache.
	- In vm_track_constant_cache, we first look up the ST table for the ID
	  of the constant. Assume the ST table exists because another iseq also
	  holds a cache entry for this ID.
	- We then insert into this ST table with the iseq_inline_constant_cache.
	- However, while inserting into this ST table, it allocates memory, which
	  could trigger a GC. Assume that it does trigger a GC.
	- The GC frees the one and only other iseq that holds a cache entry for
	  this ID.
	- In remove_from_constant_cache, it will appear that the ST table is now
	  empty because there are no more iseq with cache entries for this ID, so
	  we free the ST table.
	- We complete GC and continue our st_insert. However, this ST table has
	  been freed so we now have a use-after-free.

	This issue is very hard to reproduce, because it requires that the GC runs
	at a very specific time. However, we can make it show up by applying this
	patch which runs GC right before the st_insert to mimic the st_insert
	triggering a GC:

	    diff --git a/vm_insnhelper.c b/vm_insnhelper.c
	    index 3cb23f06f0..a93998136a 100644
	    --- a/vm_insnhelper.c
	    +++ b/vm_insnhelper.c
	    @@ -6338,6 +6338,10 @@ vm_track_constant_cache(ID id, void *ic)
	            rb_id_table_insert(const_cache, id, (VALUE)ics);
	        }

	    +    if (id == rb_intern("MyConstant")) rb_gc();
	    +
	        st_insert(ics, (st_data_t) ic, (st_data_t) Qtrue);
	    }

	And if we run this script:

	    Object.const_set("MyConstant", "Hello!")

	    my_proc = eval("-> { MyConstant }")
	    my_proc.call

	    my_proc = eval("-> { MyConstant }")
	    my_proc.call

	We can see that ASAN outputs a use-after-free error:

	    ==36540==ERROR: AddressSanitizer: heap-use-after-free on address 0x606000049528 at pc 0x000102f3ceac bp 0x00016d607a70 sp 0x00016d607a68
	    READ of size 8 at 0x606000049528 thread T0
	        #0 0x102f3cea8 in do_hash st.c:321
	        #1 0x102f3ddd0 in rb_st_insert st.c:1132
	        #2 0x103140700 in vm_track_constant_cache vm_insnhelper.c:6345
	        #3 0x1030b91d8 in vm_ic_track_const_chain vm_insnhelper.c:6356
	        #4 0x1030b8cf8 in rb_vm_opt_getconstant_path vm_insnhelper.c:6424
	        #5 0x1030bc1e0 in vm_exec_core insns.def:263
	        #6 0x1030b55fc in rb_vm_exec vm.c:2585
	        #7 0x1030fe0ac in rb_iseq_eval_main vm.c:2851
	        #8 0x102a82588 in rb_ec_exec_node eval.c:281
	        #9 0x102a81fe0 in ruby_run_node eval.c:319
	        #10 0x1027f3db4 in rb_main main.c:43
	        #11 0x1027f3bd4 in main main.c:68
	        #12 0x183900270  (<unknown module>)

	    0x606000049528 is located 8 bytes inside of 56-byte region [0x606000049520,0x606000049558)
	    freed by thread T0 here:
	        #0 0x104174d40 in free+0x98 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x54d40)
	        #1 0x102ada89c in rb_gc_impl_free default.c:8183
	        #2 0x102ada7dc in ruby_sized_xfree gc.c:4507
	        #3 0x102ac4d34 in ruby_xfree gc.c:4518
	        #4 0x102f3cb34 in rb_st_free_table st.c:663
	        #5 0x102bd52d8 in remove_from_constant_cache iseq.c:119
	        #6 0x102bbe2cc in iseq_clear_ic_references iseq.c:153
	        #7 0x102bbd2a0 in rb_iseq_free iseq.c:166
	        #8 0x102b32ed0 in rb_imemo_free imemo.c:564
	        #9 0x102ac4b44 in rb_gc_obj_free gc.c:1407
	        #10 0x102af4290 in gc_sweep_plane default.c:3546
	        #11 0x102af3bdc in gc_sweep_page default.c:3634
	        #12 0x102aeb140 in gc_sweep_step default.c:3906
	        #13 0x102aeadf0 in gc_sweep_rest default.c:3978
	        #14 0x102ae4714 in gc_sweep default.c:4155
	        #15 0x102af8474 in gc_start default.c:6484
	        #16 0x102afbe30 in garbage_collect default.c:6363
	        #17 0x102ad37f0 in rb_gc_impl_start default.c:6816
	        #18 0x102ad3634 in rb_gc gc.c:3624
	        #19 0x1031406ec in vm_track_constant_cache vm_insnhelper.c:6342
	        #20 0x1030b91d8 in vm_ic_track_const_chain vm_insnhelper.c:6356
	        #21 0x1030b8cf8 in rb_vm_opt_getconstant_path vm_insnhelper.c:6424
	        #22 0x1030bc1e0 in vm_exec_core insns.def:263
	        #23 0x1030b55fc in rb_vm_exec vm.c:2585
	        #24 0x1030fe0ac in rb_iseq_eval_main vm.c:2851
	        #25 0x102a82588 in rb_ec_exec_node eval.c:281
	        #26 0x102a81fe0 in ruby_run_node eval.c:319
	        #27 0x1027f3db4 in rb_main main.c:43
	        #28 0x1027f3bd4 in main main.c:68
	        #29 0x183900270  (<unknown module>)

	    previously allocated by thread T0 here:
	        #0 0x104174c04 in malloc+0x94 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x54c04)
	        #1 0x102ada0ec in rb_gc_impl_malloc default.c:8198
	        #2 0x102acee44 in ruby_xmalloc gc.c:4438
	        #3 0x102f3c85c in rb_st_init_table_with_size st.c:571
	        #4 0x102f3c900 in rb_st_init_table st.c:600
	        #5 0x102f3c920 in rb_st_init_numtable st.c:608
	        #6 0x103140698 in vm_track_constant_cache vm_insnhelper.c:6337
	        #7 0x1030b91d8 in vm_ic_track_const_chain vm_insnhelper.c:6356
	        #8 0x1030b8cf8 in rb_vm_opt_getconstant_path vm_insnhelper.c:6424
	        #9 0x1030bc1e0 in vm_exec_core insns.def:263
	        #10 0x1030b55fc in rb_vm_exec vm.c:2585
	        #11 0x1030fe0ac in rb_iseq_eval_main vm.c:2851
	        #12 0x102a82588 in rb_ec_exec_node eval.c:281
	        #13 0x102a81fe0 in ruby_run_node eval.c:319
	        #14 0x1027f3db4 in rb_main main.c:43
	        #15 0x1027f3bd4 in main main.c:68
	        #16 0x183900270  (<unknown module>)

	This commit fixes this bug by adding a inserting_constant_cache_id field
	to the VM, which stores the ID that is currently being inserted and, in
	remove_from_constant_cache, we don't free the ST table for ID equal to
	this one.

	Co-Authored-By: Alan Wu <alanwu@ruby-lang.org>
2024-12-15 15:26:55 +09:00
nagachika 937319126a merge revision(s) 02b70256b5, 6b4f8945d6: [Backport #20909]
Check negative integer underflow

	Many of Oniguruma functions need valid encoding strings
2024-11-30 18:34:32 +09:00
nagachika 87249cbddb merge revision(s) a8c2d5e7be: [Backport #20907]
Ensure fiber scheduler re-acquires mutex when interrupted from sleep. (#12158)

	[Bug #20907]
2024-11-30 14:31:31 +09:00
nagachika bb065f0844 merge revision(s) 3b7892b6e4: [Backport #20871]
Fix a bug in rb_include_module that stops nested inclusion into module subclasses

	This bug was present since the code was originally added by me
	in 3556a834a2.

	Fixes [Bug #20871]
2024-11-30 14:29:18 +09:00
nagachika 1fc0895971 merge revision(s) 0d4de0f4b1: [Backport #20898]
wasm: align fiber stack pointer to 16 bytes

	In WebAssembly C ABI, the linear stack pointer must be always aligned
	to 16 bytes like other archs.
	The misaligned stack pointer causes some weird memory corruption since
	compiler assumes the aligned stack pointer.
2024-11-30 14:25:56 +09:00
nagachika a7b013b392 merge revision(s) d71be7274b: [Backport #20873]
[Bug #20873] Consider `-FIXNUM_MIN` overflow

	`-FIXNUM_MIN` is usually greater than `FIXNUM_MAX` on platforms using
	two's complement representation.
2024-11-10 15:15:53 +09:00
nagachika ee3428aa0e merge revision(s) 56ecc243e2: [Backport #20868]
[Bug #20868] Fix Method#hash to not change after compaction

	The hash value of a Method must remain constant after a compaction, otherwise
	it may not work as the key in a hash table.

	For example:

	    def a; end

	    # Need this method here because otherwise the iseq may be on the C stack
	    # which would get pinned and not move during compaction
	    def get_hash
	      method(:a).hash
	    end

	    puts get_hash # => 2993401401091578131

	    GC.verify_compaction_references(expand_heap: true, toward: :empty)

	    puts get_hash # => -2162775864511574135
2024-11-10 13:04:43 +09:00
nagachika 288e24b73a merge revision(s) 29c480dd6f: [Backport #20853]
[Bug #20853] Fix Proc#hash to not change after compaction

	The hash value of a Proc must remain constant after a compaction, otherwise
	it may not work as the key in a hash table.
2024-11-10 12:55:34 +09:00
nagachika 63aeb018eb bump teeny 2024-10-30 18:47:11 +09:00
nagachika d09b47ddf5 merge revision(s) 70d20ce473:
Update bundled gems list
2024-10-28 13:31:57 +09:00
nagachika e55b1af257 merge revision(s) ce20367a0e: [Backport #20500]
Define `incflags` also on mswin
2024-10-20 14:21:15 +09:00
nagachika 2fbae07c42 merge revision(s) bcb3247072: [Backport #20500]
[Bug #19778] Pass additional include options to INCFLAGS in common.mk
2024-10-20 14:19:52 +09:00
nagachika f70e3254e0 merge revision(s) 5fa6ba9568: [Backport #20500]
[Bug #20500] Search non-default directories for jemalloc

	Co-Authored-by: lish82 (Hiroki Katagiri)
2024-10-20 13:56:22 +09:00
nagachika cb75fcef6f merge revision(s) 6118e8a473, dc64448202: [Backport #20716]
Fix method caching bug when including/prepend module A that prepends module B

	Fix by always adding the generated iclass to the subclasses list,
	otherwise the method cache for the iclass is not cleared when
	the method in the module is overwritten.

	Fixes [Bug #20716]

	Remove an unused variable
2024-10-18 13:57:08 +09:00
nagachika 087e4ed6cc merge revision(s) 35e124832e: [Backport #20755]
[Bug #20755] Frozen string should not be writable via IO::Buffer
2024-10-18 13:57:08 +09:00
nagachika 5777fe5ab5 merge revision(s) 637067440f: [Backport #20752]
[Bug #20752] Slice of readonly `IO::Buffer` also should be readonly
2024-10-18 11:30:05 +09:00
nagachika 18074c5081 merge revision(s) c1862cbb89: [Backport #20719]
[Bug #20719] `Float` argument must be ASCII compatible
2024-10-18 11:25:12 +09:00
nagachika 48af30b068 merge revision(s) d33e3d47b8: [Backport #20704]
[Bug #20704] Win32: Fix chdir to non-ASCII path

	On Windows, `chdir` in compilers' runtime libraries uses the active
	code page, but command line arguments in ruby are always UTF-8, since
	commit:33ea2646b98adb49ae2e1781753bf22d33729ac0.
2024-10-18 11:22:30 +09:00
nagachika 2d62c5d3d9 merge revision(s) 0d16c36d0a: [Backport #13831]
[win32/registry] Fallback to UTF-8 for unknown codepages

	There are some codepages like cp708 for which no ruby encoding exists:

	    $ ruby -e "Encoding.find('cp708')"
	    Traceback (most recent call last):
	    	1: from -e:1:in `<main>'
	    -e:1:in `find': unknown encoding name - cp708 (ArgumentError)

	win32/registry uses ENCODING to transcode error messages and expand environment
	variables from UTF-16LE, so using UTF-8 seems like the best choice and is better
	than a hard failure.

	This should resolve [Bug #13831]
2024-09-26 13:00:19 +09:00
nagachika b6f7d54485 merge revision(s) 29500e3034: [Backport #20698]
Update bundled gems list as of 2024-08-22
2024-08-31 19:10:29 +09:00
nagachika 04fab1dfd9 merge revision(s) bb849ffdb1:
Added explicitly begin-end block for Ruby 2.4.

	  strscan, ipaddr and some default gems still support Ruby 2.4.

	  After this, I extract this CoreAssertions to their repositories.
2024-08-31 19:09:13 +09:00
nagachika f095a085a4 merge revision(s) 8a7e6f6852:
Improve base time of assert_linear_performance (#11369)

	Remove `.ceil` from base time calculation that makes 10x gap.
	This will make the assertion more strict and also less flaky.
2024-08-31 18:51:41 +09:00
nagachika f4847607ee merge revision(s) f1c78b2331:
Suppress warning for shadowing outer local variable
2024-08-31 18:49:58 +09:00
nagachika b5bb0ee64b merge revision(s) d239643603:
core_assertions.rb: Support old rubies

	Some symbol argument might not be accepted by Process.clock_gettime.
2024-08-31 18:49:27 +09:00