<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ruby.git/test/ruby/test_weakmap.rb, branch v3_2_11</title>
<subtitle>The Ruby Programming Language</subtitle>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/'/>
<entry>
<title>merge revision(s) 3592b24cdc07ed89eecb39161f21fe721a89a5de: [Backport #19531]</title>
<updated>2023-07-22T02:44:54+00:00</updated>
<author>
<name>nagachika</name>
<email>nagachika@ruby-lang.org</email>
</author>
<published>2023-07-22T02:44:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=46b62f44ce30bf234a76114c8249081e47ce3da4'/>
<id>46b62f44ce30bf234a76114c8249081e47ce3da4</id>
<content type='text'>
	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" =&gt; 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(-)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	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" =&gt; 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(-)
</pre>
</div>
</content>
</entry>
<entry>
<title>merge revision(s) bffadcd6d46ccfccade79ce0efb60ced8eac4483: [Backport #19529]</title>
<updated>2023-06-25T03:29:49+00:00</updated>
<author>
<name>nagachika</name>
<email>nagachika@ruby-lang.org</email>
</author>
<published>2023-06-25T03:29:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=e3d10dedf106357d2b17fc8786d35035e0b366cf'/>
<id>e3d10dedf106357d2b17fc8786d35035e0b366cf</id>
<content type='text'>
	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(+)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	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(+)
</pre>
</div>
</content>
</entry>
<entry>
<title>merge revision(s) 548086b34e3dd125edabf5dc1e46b891fad3ea9c,3dc8cde70078ccb38f5f4b0818ad5eecded01bd5,e0cf80d666d4b5df3229f030a16d10d21323508e: [Backport #19529]</title>
<updated>2023-06-25T03:26:20+00:00</updated>
<author>
<name>nagachika</name>
<email>nagachika@ruby-lang.org</email>
</author>
<published>2023-06-25T03:26:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=3ebcbb537d7ae37e49c49e05b28d2cc5b324f151'/>
<id>3ebcbb537d7ae37e49c49e05b28d2cc5b324f151</id>
<content type='text'>
	ObjectSpace::WeakMap: fix compaction support

	[Bug #19529]

	`rb_gc_update_tbl_refs` can't be used on `w-&gt;obj2wmap` because it's
	not a `VALUE -&gt; VALUE` table, but a `VALUE -&gt; 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(-)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	ObjectSpace::WeakMap: fix compaction support

	[Bug #19529]

	`rb_gc_update_tbl_refs` can't be used on `w-&gt;obj2wmap` because it's
	not a `VALUE -&gt; VALUE` table, but a `VALUE -&gt; 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(-)
</pre>
</div>
</content>
</entry>
<entry>
<title>merge revision(s) c6f84e918943a0bf8db6fee556fc53180d257510: [Backport #19398]</title>
<updated>2023-02-06T07:41:23+00:00</updated>
<author>
<name>NARUSE, Yui</name>
<email>naruse@airemix.jp</email>
</author>
<published>2023-02-06T07:41:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=3426ebd0489654f951a8b92efaf5e72b9f43efab'/>
<id>3426ebd0489654f951a8b92efaf5e72b9f43efab</id>
<content type='text'>
	[Bug #19398] Memory leak in WeakMap

	There's a memory leak in ObjectSpace::WeakMap due to not freeing
	the `struct weakmap`. It can be seen in the following script:

	```
	100.times do
	  10000.times do
	    ObjectSpace::WeakMap.new
	  end

	  # Output the Resident Set Size (memory usage, in KB) of the current Ruby process
	  puts `ps -o rss= -p #{$$}`
	end
	```
	---
	 gc.c                      | 1 +
	 test/ruby/test_weakmap.rb | 9 +++++++++
	 2 files changed, 10 insertions(+)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	[Bug #19398] Memory leak in WeakMap

	There's a memory leak in ObjectSpace::WeakMap due to not freeing
	the `struct weakmap`. It can be seen in the following script:

	```
	100.times do
	  10000.times do
	    ObjectSpace::WeakMap.new
	  end

	  # Output the Resident Set Size (memory usage, in KB) of the current Ruby process
	  puts `ps -o rss= -p #{$$}`
	end
	```
	---
	 gc.c                      | 1 +
	 test/ruby/test_weakmap.rb | 9 +++++++++
	 2 files changed, 10 insertions(+)
</pre>
</div>
</content>
</entry>
<entry>
<title>Weakmap failure is still pending</title>
<updated>2022-01-16T13:43:04+00:00</updated>
<author>
<name>Nobuyoshi Nakada</name>
<email>nobu@ruby-lang.org</email>
</author>
<published>2022-01-16T13:43:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=4cd6fd338f71278bab5798a556a76c4e1588b892'/>
<id>4cd6fd338f71278bab5798a556a76c4e1588b892</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Remove outdated skips</title>
<updated>2022-01-16T12:35:09+00:00</updated>
<author>
<name>Nobuyoshi Nakada</name>
<email>nobu@ruby-lang.org</email>
</author>
<published>2022-01-16T09:18:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=5ec3450438150e7cb05422c04dc18901161a13ea'/>
<id>5ec3450438150e7cb05422c04dc18901161a13ea</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Use pend for old TODOs</title>
<updated>2022-01-16T12:35:09+00:00</updated>
<author>
<name>Nobuyoshi Nakada</name>
<email>nobu@ruby-lang.org</email>
</author>
<published>2022-01-16T07:40:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=a4a7bf2a63ee5b54080bfbcc7b2dd745c9991507'/>
<id>a4a7bf2a63ee5b54080bfbcc7b2dd745c9991507</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>ObjectSpace::WeakMap#inspect: check if living object [Bug #18392]</title>
<updated>2021-12-07T12:55:41+00:00</updated>
<author>
<name>Nobuyoshi Nakada</name>
<email>nobu@ruby-lang.org</email>
</author>
<published>2021-12-07T10:33:03+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=d6c5a30cfdf658280338dbb8c8b17fab3190b928'/>
<id>d6c5a30cfdf658280338dbb8c8b17fab3190b928</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Allow non-finalizable objects in ObjectSpace::WeakMap</title>
<updated>2019-08-29T11:40:52+00:00</updated>
<author>
<name>Jean Boussier</name>
<email>jean.boussier@gmail.com</email>
</author>
<published>2019-08-01T18:41:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=a4a19b114ba94b8f28d5a91aee5d595a516006d5'/>
<id>a4a19b114ba94b8f28d5a91aee5d595a516006d5</id>
<content type='text'>
[feature #16035]

This goes one step farther than what nobu did in [feature #13498]

With this patch, special objects such as static symbols, integers, etc can be used as either key or values inside WeakMap. They simply don't have a finalizer defined on them.

This is useful if you need to deduplicate value objects
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[feature #16035]

This goes one step farther than what nobu did in [feature #13498]

With this patch, special objects such as static symbols, integers, etc can be used as either key or values inside WeakMap. They simply don't have a finalizer defined on them.

This is useful if you need to deduplicate value objects
</pre>
</div>
</content>
</entry>
<entry>
<title>Frozen objects in WeakMap</title>
<updated>2019-06-22T15:31:16+00:00</updated>
<author>
<name>Nobuyoshi Nakada</name>
<email>nobu@ruby-lang.org</email>
</author>
<published>2019-06-22T15:31:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=f3c81b4e90ec492382e299573f2c3ac272adbb5f'/>
<id>f3c81b4e90ec492382e299573f2c3ac272adbb5f</id>
<content type='text'>
* gc.c (wmap_aset): bypass check for frozen and allow frozen
  object in WeakMap.  [Bug #13498]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* gc.c (wmap_aset): bypass check for frozen and allow frozen
  object in WeakMap.  [Bug #13498]
</pre>
</div>
</content>
</entry>
</feed>
