aboutsummaryrefslogtreecommitdiffstats
path: root/weakmap.c
Commit message (Collapse)AuthorAgeFilesLines
* [DOC] Fix typos in WeakMap docsEarlopain2024-05-061-3/+3
|
* chore: remove repetitive words (#10573)careworry2024-04-181-1/+1
| | | Signed-off-by: careworry <worrycare@outlook.com>
* Remove duplicated include in weakmap.cPeter Zhu2024-02-141-1/+0
|
* Replace assert with RUBY_ASSERT in weakmap.cPeter Zhu2024-02-121-5/+5
| | | | | | assert does not print the bug report, only the file and line number of the assertion that failed. RUBY_ASSERT prints the full bug report, which makes it much easier to debug.
* Use `UNDEF_P`Nobuyoshi Nakada2024-01-301-2/+2
|
* [DOC] Enhance docs for WeakMap and WeakKeyMap (#9160)Victor Shepelev2023-12-141-24/+205
| | | | | | | Enhance docs for WeakMap and WeakKeyMap * WeakKeyMap: more class-level explanations, more details on #getkey, fix a slight bug in code of #delete example; * WeekMap: a bit more detailed class- and method-level docs.
* Make WeakKeyMap safe for compaction during allocationPeter Zhu2023-12-121-1/+3
| | | | | During allocation, the table may not have been allocated yet which would crash in the st_foreach.
* Make WeakMap safe for compaction during allocationPeter Zhu2023-12-121-1/+3
| | | | | During allocation, the table may not have been allocated yet which would crash in the st_foreach.
* Implement WeakKeyMap on VWAPeter Zhu2023-11-211-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | Benchmark: ``` puts(Benchmark.measure do 10_000_000.times do ObjectSpace::WeakKeyMap.new end end) ``` Before: ``` 2.554772 0.014167 2.568939 ( 2.575763) ``` After: ``` 1.994920 0.013583 2.008503 ( 2.012139) ```
* Implement WeakMap on VWAPeter Zhu2023-11-211-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | Benchmark: ``` puts(Benchmark.measure do 10_000_000.times do ObjectSpace::WeakMap.new end end) ``` Before: ``` 2.568662 0.014001 2.582663 ( 2.601743) ``` After: ``` 2.025523 0.008676 2.034199 ( 2.041760) ```
* Fix crash in WeakMap during compactionPeter Zhu2023-09-061-1/+5
| | | | | WeakMap can crash during compaction because the st_insert could allocate memory.
* Introduce rb_gc_remove_weakPeter Zhu2023-09-051-1/+6
| | | | | | If we're during incremental marking, then Ruby code can execute that deallocates certain memory buffers that have been called with rb_gc_mark_weak, which can cause use-after-free bugs.
* Reuse allocated buffer in WeakMapPeter Zhu2023-09-051-19/+18
| | | | | If the key exists in WeakMap and WeakKeyMap, then we can reuse the buffer and we can avoid an allocation.
* Implement WeakKeyMap using weak referencesPeter Zhu2023-08-251-139/+163
|
* Implement WeakMap using weak referencesPeter Zhu2023-08-251-288/+209
|
* [DOC] Improve doc guide compliance (#8221)Burdette Lamar2023-08-151-2/+2
|
* Implement ObjectSpace::WeakMap#delete and ObjectSpace::WeakKeyMap#deleteJean Boussier2023-04-151-0/+82
| | | | | | [Feature #19561] It's useful to be able to remove references from weak maps.
* Add specs for ObjectSpace::WeakKeyMapJean Boussier2023-04-151-1/+2
| | | | [Feature #18498]
* ObjectSpace::WeakMap: clean inverse reference when an entry is re-assignedJean Boussier2023-03-171-17/+74
| | | | | | | | | | | | [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.
* Fix incorrect size of WeakMap bufferPeter Zhu2023-03-161-2/+2
| | | | | | 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.
* Fix crash during compactionPeter Zhu2023-03-141-1/+1
| | | | | | | | | | | | | | | | | [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 ```
* ObjectSpace::WeakMap: fix compaction supportJean Boussier2023-03-141-1/+36
| | | | | | | | [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.
* Mark weak maps as write barrier protectedJean Boussier2023-03-101-4/+6
| | | | | | | | For both we mark the lambda finalizer. ObjectSpace::WeakMap doesn't mark any other reference, so we can just add the flag. ObjectSpace::WeakKeyMap only ever add new refs in `wkmap_aset`, so we can just trigger the write barrier there.
* Move WeakMap and WeakKeyMap code to weakmap.cPeter Zhu2023-03-101-0/+800
These classes don't belong in gc.c as they're not actually part of the GC. This commit refactors the code by moving all the code into a weakmap.c file.