Commit graph

16449 commits

Author SHA1 Message Date
nagachika
a191cf5617 merge revision(s) c42261059d: [Backport #19901]
[Bug #19901]

	fix leak in module clone

	Co-authored-by: Peter Zhu <peter@peterzhu.ca>
	---
	 class.c                  |  1 +
	 test/ruby/test_module.rb | 12 ++++++++++++
	 2 files changed, 13 insertions(+)
2023-09-30 13:47:33 +09:00
nagachika
97b7070ebd merge revision(s) 8b236e0c66: [Backport #19896]
[Bug #19896]

	fix memory leak in vm_method

	This introduces a unified reference_count to clarify who is referencing a method.
	This also allows us to treat the refinement method as the def owner since it counts itself as a reference

	Co-authored-by: Peter Zhu <peter@peterzhu.ca>
	---
	 gc.c                     |   4 +-
	 method.h                 |   6 +--
	 rjit_c.rb                |   6 +--
	 test/ruby/test_module.rb |   4 +-
	 vm_insnhelper.c          |   2 +-
	 vm_method.c              | 105 +++++++++++++++++++----------------------------
	 6 files changed, 54 insertions(+), 73 deletions(-)
2023-09-30 13:46:29 +09:00
nagachika
9ee58b2054 merge revision(s) 96c5a4be7b: [Backport #19894]
Fix memory leak in complemented method entries

	[Bug #19894]

	When a copy of a complemented method entry is created, there are two
	issues:

	1. IMEMO_FL_USER3 is not copied, so the complemented status is not
	   copied over.
	2. In rb_method_entry_clone we increment both alias_count and
	   complemented_count. However, when we free the method entry in
	   rb_method_definition_release, we only decrement one of the two
	   counters, resulting in the rb_method_definition_t being leaked.

	Co-authored-by: Adam Hess <adamhess1991@gmail.com>
	---
	 method.h                 |  5 +++--
	 test/ruby/test_module.rb | 29 +++++++++++++++++++++++++++++
	 vm_method.c              |  8 +++++---
	 3 files changed, 37 insertions(+), 5 deletions(-)
2023-09-24 15:13:32 +09:00
nagachika
9cd28caa7c merge revision(s) 901b6d9c50: [Backport #19853]
Validate the typed data before dereferencing the internal struct.
	 (#8315)

	---
	 process.c                  |  5 +++--
	 test/fiber/test_process.rb | 21 +++++++++++++++++++++
	 2 files changed, 24 insertions(+), 2 deletions(-)
2023-09-24 14:16:10 +09:00
nagachika
217ef2bf89 merge revision(s) 25711683e8: [Backport #19864]
Fix regression when testing inclusion in unbounded ranges

	Caused by 04a92a6764.  This treats
	unbounded ranges of arbitrary objects the same as how unbounded
	string ranges are treated:

	  (..x)  === y  # (y <=> x) <= 0
	  (...x) === y  # (y <=> x) <  0
	  (x..)  === y  # (x <=> y) <= 0

	Fixes [Bug #19864]
	---
	 range.c                 |  9 +++++++++
	 test/ruby/test_range.rb | 23 +++++++++++++++++++++++
	 2 files changed, 32 insertions(+)
2023-09-24 13:48:08 +09:00
nagachika
bb877e5b4f merge revision(s) 382678d411: [Backport #19788]
[Bug #19788] Use the result of `tCOLON2` event

	---
	 parse.y                            | 16 ++++++++--------
	 test/ripper/test_parser_events.rb  | 17 +++++++++++++++++
	 test/ripper/test_scanner_events.rb |  5 +++++
	 3 files changed, 30 insertions(+), 8 deletions(-)
2023-09-09 19:33:29 +09:00
KJ Tsanaktsidis
0b7a4fbaa9 Allow waitpid(-1) to be woken if a waitpid(pid) call is pending
If two threads are running, with one calling waitpid(-1), and another
calling waitpid($some_pid), and then $some_other_pid exits, we would
expect the waitpid(-1) call to retrieve that exit status; however, it
cannot actually do so until $some_pid _also_ exits.

This patch fixes the issue by unconditionally checking for pending
process group waits on SIGCHLD, and then allowing pending pid-only waits
to "steal" the notification.

[Fixes #19387]
2023-09-09 18:51:25 +09:00
Hiroshi SHIBATA
ab1eacc8bc Merge RubyGems-3.4.19 and Bundler-2.4.19 2023-08-29 23:25:18 +09:00
Hiroshi SHIBATA
1434059ab5 Merge RubyGems-3.4.18 and Bundler-2.4.18 2023-08-29 23:25:18 +09:00
Hiroshi SHIBATA
d6c3a1778c Merge RubyGems-3.4.17 and Bundler-2.4.17 2023-08-29 23:25:18 +09:00
Hiroshi SHIBATA
e44e42c303 Merge RubyGems-3.4.15 and Bundler-2.4.15 2023-08-29 23:25:18 +09:00
Hiroshi SHIBATA
a36c836433 Merge RubyGems-3.4.14 and Bundler-2.4.14 2023-08-29 23:25:18 +09:00
Hiroshi SHIBATA
c71a89f785 Merge RubyGems-3.4.12 and Bundler-2.4.12 2023-08-29 23:25:18 +09:00
Hiroshi SHIBATA
dd91a17560 Merge RubyGems-3.4.11 and Bundler-2.4.11 2023-08-29 23:25:18 +09:00
nagachika
5d568e1898 merge revision(s) a28c5151f5: [Backport #19855]
Fix Array#bsearch when block returns a non-integer numeric value

	---
	 array.c                 | 4 ++--
	 test/ruby/test_array.rb | 4 ++++
	 2 files changed, 6 insertions(+), 2 deletions(-)
2023-08-29 21:06:04 +09:00
nagachika
e777064e4b Revert "Re-apply "Ruby 3.2 - Speed up rebuilding the loaded feature index and realpath cache (#8023)" (#8252)"
This reverts commit 788b03d5ba.
2023-08-24 16:06:32 +09:00
MSP-Greg
788b03d5ba
Re-apply "Ruby 3.2 - Speed up rebuilding the loaded feature index and realpath cache (#8023)" (#8252)
* Re-apply "Ruby 3.2 - Speed up rebuilding the loaded feature index and realpath cache (#8023)"

* [CI] mingw.yml - remove IBM437 encoding for test-all, use cmd shell for test & test-all

* Skip failing test on mingw with readline.so

Co-authored-by: nagachika <nagachika@ruby-lang.org>

---------

Co-authored-by: nagachika <nagachika@ruby-lang.org>
2023-08-21 23:33:47 +00:00
nagachika
0c908fa681 merge revision(s) 0b8f15575a: [Backport #19836]
Fix memory leak for incomplete lambdas

	[Bug #19836]

	The parser does not free the chain of `struct vtable`, which causes
	memory leaks.

	The following script reproduces this issue:

	```
	10.times do
	  100_000.times do
	    Ripper.parse("-> {")
	  end

	  puts `ps -o rss= -p #{$$}`
	end
	```
	---
	 parse.y                    | 24 ++++++++++++++----------
	 test/ripper/test_ripper.rb |  7 +++++++
	 2 files changed, 21 insertions(+), 10 deletions(-)
2023-08-13 13:35:25 +09:00
nagachika
6898389a0f merge revision(s) 5bc8fceca8: [Backport #19835]
Fix memory leak in parser for incomplete tokens

	[Bug #19835]

	The parser does not free the `tbl` of the `struct vtable` when there are
	leftover `lvtbl` in the parser. This causes a memory leak.

	The following script reproduces this issue:

	```
	10.times do
	  100_000.times do
	    Ripper.parse("class Foo")
	  end

	  puts `ps -o rss= -p #{$$}`
	end
	```
	---
	 parse.y                    | 42 ++++++++++++++++++++++++++++--------------
	 test/ripper/test_ripper.rb |  7 +++++++
	 2 files changed, 35 insertions(+), 14 deletions(-)
2023-08-13 13:21:30 +09:00
nagachika
b11f238a81 merge revision(s) 72d1a790cf: [Backport #19833]
[Bug #19833] Fix index underflow at superclasses of `BasicObject`

	---
	 object.c                | 4 ++++
	 test/ruby/test_class.rb | 7 +++++++
	 2 files changed, 11 insertions(+)
2023-08-12 13:51:03 +09:00
nagachika
3c9cb70311 merge revision(s) 1d096c1e53: [Backport #19793]
Fix crash in NoMethodError for dummy frames
	MIME-Version: 1.0
	Content-Type: text/plain; charset=UTF-8
	Content-Transfer-Encoding: 8bit

	[Bug #19793]

	Dummy frames are created at the top level when requiring another file.
	While requiring a file, it will try to convert using encodings. Some of
	these encodings will not respond to to_str. If method_missing is
	redefined on Object, then it will call method_missing and attempt raise
	an error. However, the iseq is invalid as it's a dummy frame so it will
	write an invalid iseq to the created NoMethodError.

	The following script crashes:

	```
	GC.stress = true

	class Object
	  public :method_missing
	end

	File.write("/tmp/empty.rb", "")
	require "/tmp/empty.rb"
	```

	With the following backtrace:

	```
	frame #0: 0x00000001000fa8b8 miniruby`RVALUE_MARKED(obj=4308637824) at gc.c:1638:12
	frame #1: 0x00000001000fb440 miniruby`RVALUE_BLACK_P(obj=4308637824) at gc.c:1763:12
	frame #2: 0x00000001000facdc miniruby`gc_writebarrier_incremental(a=4308637824, b=4308332208, objspace=0x000000010180b000) at gc.c:8822:9
	frame #3: 0x00000001000faad8 miniruby`rb_gc_writebarrier(a=4308637824, b=4308332208) at gc.c:8864:17
	frame #4: 0x000000010016aff0 miniruby`rb_obj_written(a=4308637824, oldv=36, b=4308332208, filename="../iseq.c", line=1279) at gc.h:804:9
	frame #5: 0x0000000100162a60 miniruby`rb_obj_write(a=4308637824, slot=0x0000000100d09888, b=4308332208, filename="../iseq.c", line=1279) at gc.h:837:5
	frame #6: 0x0000000100165b0c miniruby`iseqw_new(iseq=0x0000000100d09880) at iseq.c:1279:9
	frame #7: 0x0000000100165a64 miniruby`rb_iseqw_new(iseq=0x0000000100d09880) at iseq.c:1289:12
	frame #8: 0x00000001000d8324 miniruby`name_err_init_attr(exc=4309777920, recv=4304780496, method=827660) at error.c:1830:35
	frame #9: 0x00000001000d1b80 miniruby`name_err_init(exc=4309777920, mesg=4308332496, recv=4304780496, method=827660) at error.c:1869:12
	frame #10: 0x00000001000d1bd4 miniruby`rb_nomethod_err_new(mesg=4308332496, recv=4304780496, method=827660, args=4308332448, priv=0) at error.c:1957:5
	frame #11: 0x000000010039049c miniruby`rb_make_no_method_exception(exc=4304914512, format=4308332496, obj=4304780496, argc=1, argv=0x000000016fdfab00, priv=0) at vm_eval.c:959:16
	frame #12: 0x00000001003b3274 miniruby`raise_method_missing(ec=0x0000000100b06f40, argc=1, argv=0x000000016fdfab00, obj=4304780496, last_call_status=MISSING_NOENTRY) at vm_eval.c:999:15
	frame #13: 0x00000001003945d4 miniruby`rb_method_missing(argc=1, argv=0x000000016fdfab00, obj=4304780496) at vm_eval.c:944:5
	...
	frame #23: 0x000000010038f5e4 miniruby`rb_vm_call_kw(ec=0x0000000100b06f40, recv=4304780496, id=2865, argc=1, argv=0x000000016fdfab00, me=0x0000000100cbfcf0, kw_splat=0) at vm_eval.c:326:12
	frame #24: 0x00000001003c18e4 miniruby`call_method_entry(ec=0x0000000100b06f40, defined_class=4304927952, obj=4304780496, id=2865, cme=0x0000000100cbfcf0, argc=1, argv=0x000000016fdfab00, kw_splat=0) at vm_method.c:2720:20
	frame #25: 0x00000001003c440c miniruby`check_funcall_exec(v=6171896792) at vm_eval.c:589:12
	frame #26: 0x00000001000dec00 miniruby`rb_vrescue2(b_proc=(miniruby`check_funcall_exec at vm_eval.c:587), data1=6171896792, r_proc=(miniruby`check_funcall_failed at vm_eval.c:596), data2=6171896792, args="Pȗ") at eval.c:919:18
	frame #27: 0x00000001000deab0 miniruby`rb_rescue2(b_proc=(miniruby`check_funcall_exec at vm_eval.c:587), data1=6171896792, r_proc=(miniruby`check_funcall_failed at vm_eval.c:596), data2=6171896792) at eval.c:900:17
	frame #28: 0x000000010039008c miniruby`check_funcall_missing(ec=0x0000000100b06f40, klass=4304923536, recv=4304780496, mid=3233, argc=0, argv=0x0000000000000000, respond=-1, def=36, kw_splat=0) at vm_eval.c:666:15
	frame #29: 0x000000010038fa60 miniruby`rb_check_funcall_default_kw(recv=4304780496, mid=3233, argc=0, argv=0x0000000000000000, def=36, kw_splat=0) at vm_eval.c:703:21
	frame #30: 0x000000010038fb04 miniruby`rb_check_funcall(recv=4304780496, mid=3233, argc=0, argv=0x0000000000000000) at vm_eval.c:685:12
	frame #31: 0x00000001001c469c miniruby`convert_type_with_id(val=4304780496, tname="String", method=3233, raise=0, index=-1) at object.c:3061:15
	frame #32: 0x00000001001c4a4c miniruby`rb_check_convert_type_with_id(val=4304780496, type=5, tname="String", method=3233) at object.c:3153:9
	frame #33: 0x00000001002d59f8 miniruby`rb_check_string_type(str=4304780496) at string.c:2571:11
	frame #34: 0x000000010014b7b0 miniruby`io_encoding_set(fptr=0x0000000100d09ca0, v1=4304780496, v2=4, opt=4) at io.c:11655:19
	frame #35: 0x0000000100139a58 miniruby`rb_io_set_encoding(argc=1, argv=0x000000016fdfb450, io=4308334032) at io.c:13497:5
	frame #36: 0x00000001003c0004 miniruby`ractor_safe_call_cfunc_m1(recv=4308334032, argc=1, argv=0x000000016fdfb450, func=(miniruby`rb_io_set_encoding at io.c:13487)) at vm_insnhelper.c:3271:12
	...
	frame #43: 0x0000000100390b08 miniruby`rb_funcall(recv=4308334032, mid=16593, n=1) at vm_eval.c:1137:12
	frame #44: 0x00000001002a43d8 miniruby`load_file_internal(argp_v=6171899936) at ruby.c:2500:5
	...
	```
	---
	 error.c                   |  4 +++-
	 test/ruby/test_require.rb | 15 +++++++++++++++
	 2 files changed, 18 insertions(+), 1 deletion(-)
2023-08-12 13:48:14 +09:00
nagachika
0b3ed6043c merge revision(s) 5d4fff8456: [Backport #19293]
Tighten Time.new(string) parsing

	Disallow:

	* Only year-month
	* Only year-month-day
	* Preceding whitespace
	* Trailing whitespace

	Fixes [Bug #19293]
	---
	 test/ruby/test_time.rb | 13 +++++++++++++
	 time.c                 | 13 ++++++++++++-
	 2 files changed, 25 insertions(+), 1 deletion(-)
2023-07-23 12:20:12 +09:00
nagachika
3354aacb73 merge revision(s) 3874381c44: [Backport #19759]
Fix autosplat conditions to handle ruby2_keywords case

	Autosplat should not occur if there are two arguments but second
	argument is an array containing a ruby2_keywords splat. Only
	autosplat if a single argument to be yielded to the block, and there
	is no splatted flagged keyword hash passed.

	Fixes [Bug #19759]
	---
	 test/ruby/test_proc.rb | 26 ++++++++++++++++++++++++++
	 vm_args.c              |  3 ++-
	 2 files changed, 28 insertions(+), 1 deletion(-)
2023-07-23 12:01:21 +09:00
nagachika
b97a744a37 merge revision(s) 9c94db7cfc584e982a6449b72e58a1cf25024177,fe4d906f5fbacbe6e9267af3bd3503339bad63a9: [Backport #19774]
Add tests for `return` in `BEGIN` and `END` blocks

	---
	 spec/ruby/language/return_spec.rb | 15 +++++++++++++++
	 test/ruby/test_syntax.rb          |  1 +
	 2 files changed, 16 insertions(+)

	[Bug #19774] Fix segfault at `return` in `END`

	---
	 eval_error.c             | 7 ++++++-
	 test/ruby/test_syntax.rb | 5 +++++
	 2 files changed, 11 insertions(+), 1 deletion(-)
2023-07-22 14:01:55 +09:00
nagachika
65d294ad01 merge revision(s) bc3ac1872e: [Backport #19748]
[Bug #19748] Fix out-of-bound access in `String#byteindex`

	---
	 string.c                 | 17 +++++++----------
	 test/ruby/test_string.rb |  3 +++
	 2 files changed, 10 insertions(+), 10 deletions(-)
2023-07-22 13:39:44 +09:00
nagachika
4e0653db33 merge revision(s) 2c8f2871a8: [Backport #19532]
Fix handling of 6-byte codepoints in left_adjust_char_head in CESU-8
	 encoding

	---
	 enc/cesu_8.c                | 23 +++++++++++++++++++----
	 test/ruby/enc/test_cesu8.rb |  4 ++++
	 2 files changed, 23 insertions(+), 4 deletions(-)
2023-07-22 13:31:34 +09:00
nagachika
fa72ba72f8 merge revision(s) 54dbd8bea8: [Backport #19535]
Use an st table for "too complex" objects

	st tables will maintain insertion order so we can marshal dump / load
	objects with instance variables in the same order they were set on that
	particular instance

	[ruby-core:112926] [Bug #19535]

	Co-Authored-By: Jemma Issroff <jemmaissroff@gmail.com>
	---
	 gc.c                     | 10 ++++------
	 include/ruby/st.h        |  2 ++
	 object.c                 |  2 +-
	 ractor.c                 | 43 ++++++++++++++++++++++---------------------
	 shape.h                  |  6 +++---
	 st.c                     |  6 ++++++
	 test/ruby/test_shapes.rb | 21 +++++++++++++++++++++
	 variable.c               | 28 ++++++++++++++--------------
	 vm_insnhelper.c          |  2 +-
	 9 files changed, 74 insertions(+), 46 deletions(-)
2023-07-22 13:24:55 +09:00
nagachika
a3911b965f merge revision(s) 0402193723: [Backport #19709]
Fix `Thread#join(timeout)` when running inside the fiber scheduler.
	 (#7903)

	---
	 test/fiber/test_thread.rb | 22 ++++++++++++++++++++++
	 thread.c                  |  5 +++++
	 2 files changed, 27 insertions(+)
2023-07-22 13:08:16 +09:00
nagachika
ea89527a76 merge revision(s) 0b2613f443: [Backport #19640]
`rb_io_puts` should not write zero length strings. (#7806)

	---
	 io.c                  | 40 ++++++++++++++++++++++++----------------
	 test/fiber/test_io.rb | 28 ++++++++++++++++++++++++++++
	 2 files changed, 52 insertions(+), 16 deletions(-)
2023-07-22 13:03:22 +09:00
nagachika
465eb7418d merge revision(s) 91c004885f: [Backport #19025]
[Bug #19025] Numbered parameter names are always local variables

	---
	 parse.y                  | 2 +-
	 test/ruby/test_syntax.rb | 1 +
	 2 files changed, 2 insertions(+), 1 deletion(-)
2023-07-22 11:55:49 +09:00
nagachika
46b62f44ce merge revision(s) 3592b24cdc: [Backport #19531]
ObjectSpace::WeakMap: clean inverse reference when an entry is
	 re-assigned

	[Bug #19531]

	```ruby
	wmap[1] = "A"
	wmap[1] = "B"
	```

	In the example above, we need to remove the `"A" => 1` inverse reference
	so that when `"A"` is GCed the `1` key isn't deleted.
	---
	 test/ruby/test_weakmap.rb | 17 +++++++++
	 weakmap.c                 | 91 ++++++++++++++++++++++++++++++++++++++---------
	 2 files changed, 91 insertions(+), 17 deletions(-)
2023-07-22 11:44:54 +09:00
nagachika
3f6187a947 merge revision(s) 1bc8838d60: [Backport #19750]
Handle unterminated unicode escapes in regexps

	This fixes an infinite loop possible after ec3542229b.
	For \u{} escapes in regexps, skip validation in the parser, and rely on the regexp
	code to handle validation. This is necessary so that invalid unicode escapes in
	comments in extended regexps are allowed.

	Fixes [Bug #19750]

	Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
	---
	 parse.y                 | 97 ++++++++++++++++++++++++++++++++-----------------
	 test/ruby/test_parse.rb | 16 ++++++++
	 2 files changed, 79 insertions(+), 34 deletions(-)
2023-07-17 18:04:41 +09:00
nagachika
be09d77b96 merge revision(s) a8ba1ddd78: [Backport #19455]
Use UTF-8 encoding for literal extended regexps with UTF-8 characters
	 in comments

	Fixes [Bug #19455]
	---
	 re.c                     | 9 ++++++++-
	 test/ruby/test_regexp.rb | 7 +++++++
	 2 files changed, 15 insertions(+), 1 deletion(-)
2023-07-17 17:23:31 +09:00
nagachika
5328c58c7d merge revision(s) 1a149aab776aa6741628eb35482eff1ded197fd2,fb17c833f542222afdf482924877d43aa577782d,60f22ebf86248388b41b4ec751d16700f2b4b621: [Backport #19533]
Extract range type check functions

	---
	 range.c | 55 ++++++++++++++++++++++++++++++++++++-------------------
	 1 file changed, 36 insertions(+), 19 deletions(-)

	[Bug #19533] Fix infinite range inclusion with numeric value

	---
	 range.c                 | 10 +++++++---
	 test/ruby/test_range.rb |  2 ++
	 2 files changed, 9 insertions(+), 3 deletions(-)

	[Bug #19533] Add spec of infinite range inclusion

	---
	 spec/ruby/core/range/case_compare_spec.rb | 6 ++++++
	 1 file changed, 6 insertions(+)
2023-07-17 16:07:39 +09:00
nagachika
8165db0f46 merge revision(s) 8c360ce713: [Backport #19589]
hash.c: Fix hash_iter_lev_dec corrupting shape

	[Bug #19589]

	When decrementing `iter_lev` from `65` to `64` the flags would be
	corrupted, causing the shape_id to be invalid.
	---
	 hash.c                 | 12 +++++++++---
	 test/ruby/test_hash.rb | 11 +++++++++++
	 2 files changed, 20 insertions(+), 3 deletions(-)
2023-07-17 14:21:39 +09:00
nagachika
a7b0d3c9db merge revision(s) 0ac3f2c20e: [Backport #19587]
[Bug #19587] Fix `reset_match_cache` arguments

	---
	 regexec.c                | 2 +-
	 test/ruby/test_regexp.rb | 8 ++++++++
	 2 files changed, 9 insertions(+), 1 deletion(-)
2023-07-17 14:20:00 +09:00
nagachika
cb8d656100 merge revision(s) a84c99468f: [Backport #19575]
Fix crash in Time on 32-bit systems

	[Bug #19575]

	struct vtm is packed causing it to have a size that is not aligned on
	32-bit systems. When allocating it on the stack, it will have unaligned
	addresses which means that the fields won't be marked by the GC when
	scanning the stack (since the GC only marks aligned addresses). This can
	cause crashes when the fields are heap allocated objects like Bignums.

	This commit moves the flags in struct time_object into struct vtm for
	space efficiency and removes the need for packing.

	This is an example of a crash:

	    ruby(rb_print_backtrace+0xd) [0x56848945] ../src/vm_dump.c:785
	    ruby(rb_vm_bugreport) ../src/vm_dump.c:1101
	    ruby(rb_assert_failure+0x7a) [0x56671857] ../src/error.c:878
	    ruby(vm_search_cc+0x0) [0x56666e47] ../src/vm_method.c:1366
	    ruby(rb_vm_search_method_slowpath) ../src/vm_insnhelper.c:2090
	    ruby(callable_method_entry+0x5) [0x568232d3] ../src/vm_method.c:1406
	    ruby(rb_callable_method_entry) ../src/vm_method.c:1413
	    ruby(gccct_method_search_slowpath) ../src/vm_eval.c:427
	    ruby(gccct_method_search+0x20f) [0x568237ef] ../src/vm_eval.c:476
	    ruby(opt_equality_by_mid_slowpath+0x2c) [0x5682388c] ../src/vm_insnhelper.c:2338
	    ruby(rb_equal+0x37) [0x566fe577] ../src/object.c:133
	    ruby(rb_big_eq+0x34) [0x56876ee4] ../src/bignum.c:5554
	    ruby(rb_int_equal+0x14) [0x566f3ed4] ../src/numeric.c:4640
	    ruby(rb_int_equal) ../src/numeric.c:4634
	    ruby(vm_call0_cfunc_with_frame+0x6d) [0x568303c2] ../src/vm_eval.c:148
	    ruby(vm_call0_cfunc) ../src/vm_eval.c:162
	    ruby(vm_call0_body) ../src/vm_eval.c:208
	    ruby(rb_funcallv_scope+0xd1) [0x56833971] ../src/vm_eval.c:85
	    ruby(RB_TEST+0x0) [0x567e8488] ../src/time.c:78
	    ruby(eq) ../src/time.c:78
	    ruby(small_vtm_sub) ../src/time.c:1523
	    ruby(timelocalw+0x23b) [0x567f3e9b] ../src/time.c:1593
	    ruby(time_s_alloc+0x0) [0x567f536b] ../src/time.c:3698
	    ruby(time_new_timew) ../src/time.c:2694
	    ruby(time_s_mktime) ../src/time.c:3698
	---
	 test/ruby/test_time.rb |  7 ++-----
	 time.c                 | 57 ++++++++++++++++++++++++--------------------------
	 timev.h                |  7 +++++--
	 3 files changed, 34 insertions(+), 37 deletions(-)
2023-07-17 09:45:57 +09:00
nagachika
9fb94407b9 merge revision(s) 417b1a3644: [Backport #19550]
Fix memory leak for iclass

	[Bug #19550]

	If !RCLASS_EXT_EMBEDDED (e.g. 32 bit systems) then the rb_classext_t is
	allocated throug malloc so it must be freed.

	The issue can be seen in the following script:

	```
	20.times do
	  100_000.times do
	    mod = Module.new
	    Class.new do
	      include mod
	    end
	  end

	  # Output the Resident Set Size (memory usage, in KB) of the current Ruby process
	  puts `ps -o rss= -p #{$$}`
	end
	```

	Before this fix, the max RSS is 280MB, while after this change, it's
	30MB.
	---
	 gc.c                     |  2 +-
	 test/ruby/test_module.rb | 15 +++++++++++++++
	 2 files changed, 16 insertions(+), 1 deletion(-)
2023-07-17 09:29:04 +09:00
nagachika
c911cbd6c3 merge revision(s) bd786e7896: [Backport #19084]
Fix mutation on shared strings. (#7837)

	---
	 io_buffer.c                 | 19 ++++++++++++-------
	 test/ruby/test_io_buffer.rb |  4 ----
	 2 files changed, 12 insertions(+), 11 deletions(-)
2023-07-16 16:50:13 +09:00
nagachika
5ad2390b55 merge revision(s) 466aa8010f: [Backport #19546]
Fix incorrect usage of `rb_fiber_scheduler_io_(p)(read|write)`.
	 (#7593)

	---
	 io_buffer.c                  |  8 ++++----
	 scheduler.c                  | 48 ++++++++++++++++++++++----------------------
	 test/fiber/test_io_buffer.rb | 33 ++++++++++++++++++++++++++++++
	 3 files changed, 61 insertions(+), 28 deletions(-)
2023-07-16 16:44:22 +09:00
nagachika
c13757ed9a merge revision(s) 09295ea796: [Backport #19543]
IO::Buffer#resize: Free internal buffer if new size is zero (#7569)

	`#resize(0)` on an IO::Buffer with internal buffer allocated will
	result in calling `realloc(data->base, 0)`. The behavior of `realloc`
	with size = 0 is implementation-defined (glibc frees the object
	and returns NULL, while BSDs return an inaccessible object). And
	thus such usage is deprecated in standard C (upcoming C23 will make it
	UB).

	To avoid this problem, just `free`s the memory when the new size is zero.
	---
	 io_buffer.c                 |  5 +++++
	 test/ruby/test_io_buffer.rb | 18 ++++++++++++++++++
	 2 files changed, 23 insertions(+)
2023-07-16 16:42:12 +09:00
nagachika
141402d11c merge revision(s) e1bd45624c: [Backport #19482]
Fix crash when allocating classes with newobj hook

	We need to zero out the whole slot when running the newobj hook for a
	newly allocated class because the slot could be filled with garbage,
	which would cause a crash if a GC runs inside of the newobj hook.

	For example, the following script crashes:

	```
	require "objspace"

	GC.stress = true

	ObjectSpace.trace_object_allocations {
	  100.times do
	    Class.new
	  end
	}
	```

	[Bug #19482]
	---
	 gc.c                           | 8 +++++++-
	 test/objspace/test_objspace.rb | 7 +++++++
	 2 files changed, 14 insertions(+), 1 deletion(-)
2023-07-16 12:58:21 +09:00
nagachika
293a00e622 merge revision(s) 33edcc112081f96856d52e73253d73c97a5c4a3c,b4e438d8aabaf4bba2b27f374c787543fae07c58: [Backport #19483]
YJIT: Protect strings from GC on String#<< (#7466)

	Fix https://github.com/Shopify/yjit/issues/310

	[Bug #19483]

	Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
	Co-authored-by: Jimmy Miller <jimmy.miller@shopify.com>
	---
	 yjit/src/codegen.rs | 3 +++
	 1 file changed, 3 insertions(+)

	YJIT: Save PC on rb_str_concat (#7586)

	[Bug #19483]

	Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
	---
	 test/ruby/test_yjit.rb | 19 +++++++++++++++++++
	 yjit/src/codegen.rs    |  6 ++++--
	 2 files changed, 23 insertions(+), 2 deletions(-)
2023-07-16 11:25:45 +09:00
nagachika
0ba10fd850 merge revision(s) 132934b82b: [Backport #19463]
YJIT: Generate Block::entry_exit with block entry PC

	Previously, when Block::entry_exit is requested from any instruction
	that is not the first one in the block, we generated the exit with an
	incorrect PC. We should always be using the PC for the entry of the
	block for Block::entry_exit.

	It was a simple typo. The bug was [introduced][1] while we were
	refactoring to use the current backend. Later, we had a chance to spot
	this issue while [preparing][2] to enable unused variable warnings, but
	didn't spot the issue.

	Fixes [Bug #19463]

	[1]: 27fcab995e
	[2]: 31461c7e0e
	---
	 test/ruby/test_yjit.rb | 41 +++++++++++++++++++++++++++++++++++++++++
	 yjit/src/codegen.rs    |  4 ++--
	 2 files changed, 43 insertions(+), 2 deletions(-)
2023-07-16 11:25:45 +09:00
eileencodes
8a3d57971c Fix cvar caching when class is cloned
The class variable cache that was added in
https://github.com/ruby/ruby/pull/4544 changed the behavior of class
variables on cloned classes. As reported when a class is cloned AND a
class variable was set, and the class variable was read from the
original class, reading a class variable from the cloned class would
return the value from the original class.

This was happening because the IC (inline cache) is stored on the ISEQ
which is shared between the original and cloned class, therefore they
share the cache too.

To fix this we are now storing the `cref` in the cache so that we can
check if it's equal to the current `cref`. If it's different we don't
want to read from the cache. If it's the same we do. Cloned classes
don't share the same cref with their original class.

This will need to be backported to 3.1 in addition to 3.2 since the bug
exists in both versions.

We also added a marking function which was missing.

Fixes [Bug #19379]

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2023-07-01 14:17:30 +09:00
eileencodes
06dae46036 Copy cvar table on clone
When a class with a class variable is cloned we need to also copy the
cvar cache table from the original table to the clone. I found this bug
while working on fixing [Bug #19379]. While this does not fix that bug
directly it is still a required change to fix another bug revealed by
the fix in https://github.com/ruby/ruby/pull/7265

This needs to be backported to 3.2.x and 3.1.x.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2023-07-01 14:17:30 +09:00
Hiroshi SHIBATA
dd73fe077c Merge URI-0.12.2 2023-07-01 13:46:09 +09:00
nagachika
b422c3523c merge revision(s) 7bd7aee02e: [Backport #18464]
Fix interpreter crash caused by RUBY_INTERNAL_EVENT_NEWOBJ + Ractors

	When a Ractor is created whilst a tracepoint for
	RUBY_INTERNAL_EVENT_NEWOBJ is active, the interpreter crashes. This is
	because during the early setup of the Ractor, the stdio objects are
	created, which allocates Ruby objects, which fires the tracepoint.
	However, the tracepoint machinery tries to dereference the control frame
	(ec->cfp->pc), which isn't set up yet and so crashes with a null pointer
	dereference.

	Fix this by not firing GC tracepoints if cfp isn't yet set up.
	---
	 gc.c                         |  1 +
	 test/objspace/test_ractor.rb | 17 +++++++++++++++++
	 2 files changed, 18 insertions(+)
	 create mode 100644 test/objspace/test_ractor.rb
2023-06-25 15:20:43 +09:00
nagachika
e3d10dedf1 merge revision(s) bffadcd6d4: [Backport #19529]
Add guard to compaction test in WeakMap

	Some platforms don't support compaction, so we should skip this test.
	---
	 test/ruby/test_weakmap.rb | 2 ++
	 1 file changed, 2 insertions(+)
2023-06-25 12:29:49 +09:00
nagachika
3ebcbb537d merge revision(s) 548086b34e3dd125edabf5dc1e46b891fad3ea9c,3dc8cde70078ccb38f5f4b0818ad5eecded01bd5,e0cf80d666d4b5df3229f030a16d10d21323508e: [Backport #19529]
ObjectSpace::WeakMap: fix compaction support

	[Bug #19529]

	`rb_gc_update_tbl_refs` can't be used on `w->obj2wmap` because it's
	not a `VALUE -> VALUE` table, but a `VALUE -> VALUE *` table, so
	we need some dedicated iterator.
	---
	 test/ruby/test_weakmap.rb |  8 ++++++++
	 weakmap.c                 | 37 ++++++++++++++++++++++++++++++++++++-
	 2 files changed, 44 insertions(+), 1 deletion(-)

	Fix crash during compaction

	[Bug #19529]

	The fix for [Bug #19529] in commit 548086b contained a bug that crashes
	on the following script:

	```
	wm = ObjectSpace::WeakMap.new
	obj = Object.new
	100.times do
	  wm[Object.new] = obj
	  GC.start
	end
	GC.compact
	```
	---
	 test/ruby/test_weakmap.rb | 10 ++++++++++
	 weakmap.c                 |  2 +-
	 2 files changed, 11 insertions(+), 1 deletion(-)

	Fix incorrect size of WeakMap buffer

	In wmap_final_func, j is the number of elements + 1 (since j also
	includes the length at the 0th index), so we should resize the buffer
	to size j and the new length is j - 1.
	---
	 weakmap.c | 4 ++--
	 1 file changed, 2 insertions(+), 2 deletions(-)
2023-06-25 12:26:20 +09:00