summaryrefslogtreecommitdiff
path: root/hash.c
AgeCommit message (Collapse)Author
2023-12-07Use xfree in hash_st_freeJohn Hawthorn
st.c redefines malloc and free to be ruby_xmalloc and ruby_xfree, so when this was copied into hash.c it ended up mismatching an xmalloc with a regular free, which ended up inflating oldmalloc_increase_bytes when hashes were freed by minor GC.
2023-11-21Do not change hash type in Hash#assocNobuyoshi Nakada
2023-11-21Raise an exception when Hash#compare_by_identity during its iterationYusuke Endoh
2023-11-21Raise an exception if ar_table is converted to st_table during iterationYusuke Endoh
ar_table may be converted to st_table by `ar_force_convert_table`. If the conversion occurs during the iteration of ar_table, the iteration may lead to memory corruption. This change prevents the catastrophy by throwing an exception when the conversion is detected. This issue is reported by [SuperS](https://hackerone.com/superss)
2023-11-12Just check if iteration level is non-zerov3_3_0_preview3Nobuyoshi Nakada
The level in ivar is no longer needed to check if iterating, only used for increment/decrement.
2023-11-12Refactor hash iteration levelNobuyoshi Nakada
- Make it unsigned like as in-flags bits - Make it long since it should be fixable - Reduce it to in-flags bits after decrement
2023-11-11[Bug #19969] Compact st_table after deleted if possibleNobuyoshi Nakada
2023-10-22[DOC] Update documentation for typical implementation of hashYuki Tsujimoto
2023-09-27[DOC] Missing comment markerNobuyoshi Nakada
2023-09-24Add rb_hash_free for the GC to usePeter Zhu
2023-09-24Add hash_st_freePeter Zhu
2023-09-23Fix memory leak in Hash#rehash for ST hashesPeter Zhu
We need to free the old ST table in Hash#rehash. Co-authored-by: Adam Hess <[email protected]>
2023-09-06`RHASH_AR_TABLE` never returns NULL now [ci skip]Nobuyoshi Nakada
2023-09-03[DOC] Typo in Hash#key description "so/no such value"Dorian MariƩ (perso)
Notes: Merged: https://github.com/ruby/ruby/pull/8357 Merged-By: nobu <[email protected]>
2023-09-03[DOC] FIx typo in description of Hash#hash (regardless or/of order)Dorian MariƩ (perso)
Notes: Merged: https://github.com/ruby/ruby/pull/8356 Merged-By: nobu <[email protected]>
2023-08-12[DOC] Don't suppress autolinksBurdetteLamar
Notes: Merged: https://github.com/ruby/ruby/pull/8211
2023-08-03Add assertion in `RHASH_AR_TABLE_BOUND`Nobuyoshi Nakada
2023-07-13Remove RARRAY_PTR_USE_TRANSIENTPeter Zhu
RARRAY_PTR_USE now does the same things as RARRAY_PTR_USE_TRANSIENT. Notes: Merged: https://github.com/ruby/ruby/pull/8071
2023-06-30Don't check for null pointer in calls to freePeter Zhu
According to the C99 specification section 7.20.3.2 paragraph 2: > If ptr is a null pointer, no action occurs. So we do not need to check that the pointer is a null pointer. Notes: Merged: https://github.com/ruby/ruby/pull/8004
2023-06-29Fix memory leak in Hash#replacePeter Zhu
Hash#replace can leak memory if the receiver has an ST table. Notes: Merged: https://github.com/ruby/ruby/pull/8001
2023-06-29Fix memory leak when copying ST tablesPeter Zhu
st_copy allocates a st_table, which is not needed for hashes since it is allocated by VWA and embedded, so this causes a memory leak. The following script demonstrates the issue: ```ruby 20.times do 100_000.times do {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9} end puts `ps -o rss= -p #{$$}` end ``` Notes: Merged: https://github.com/ruby/ruby/pull/8000
2023-06-29Refactor rb_hash_replace to use hash_copyPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/8000
2023-06-23Declare `RHASH_AR_TABLE` and `RHASH_ST_TABLE` return non-nullNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7976 Merged-By: nobu <[email protected]>
2023-06-22Remove dead code in hash.cPeter Zhu
RHASH_TABLE_NULL_P and ar_alloc_table are no longer needed since all Hash will have AR tables.
2023-06-12hash.c no longer needs the transient heapPeter Zhu
2023-06-08* remove trailing spaces. [ci skip]git
2023-06-08[DOC] Add comment about flags for HashPeter Zhu
2023-06-01[DOC] Mention the edge case of `any?`/`all?`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7883
2023-05-23Remove dead code in rb_hash_replacePeter Zhu
We now always copy the ST table, so we don't need to initialize the ST table of hash when hash2 is empty. Notes: Merged: https://github.com/ruby/ruby/pull/7846
2023-05-23Fix crash when replacing ST hash with AR hashPeter Zhu
With VWA, AR hashes are much larger than ST hashes. Hash#replace attempts to directly copy the contents of AR hashes into ST hashes so there will be memory corruption caused by writing past the end of memory. This commit changes it so that if a ST hash is being replaced with an AR hash it will insert each element into the ST hash. Notes: Merged: https://github.com/ruby/ruby/pull/7846
2023-05-23Remove dead code in ar_copyPeter Zhu
new_tab can no longer ever be NULL so this is dead code.
2023-05-23Hash.new: print a deprecation warning when receiving keyword arguments (#7828)Jean byroot Boussier
[Feature #19236] In Ruby 3.3, `Hash.new` shall print a deprecation warning if keyword arguments are passed instead of treating them as an implicit positional Hash. This will allow to safely introduce a `capacity` keyword argument in 3.4 Co-authored-by: Jean Boussier <[email protected]> Notes: Merged-By: byroot <[email protected]>
2023-05-17Move ar_hint to ar_table_structPeter Zhu
This allows Hashes with ST tables to fit int he 80 byte size pool. Notes: Merged: https://github.com/ruby/ruby/pull/7742
2023-05-17Implement Hash ST tables on VWAPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/7742
2023-05-17Implement Hash AR tables on VWAPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/7742
2023-05-12Add `rb_sys_fail_sprintf` macroNobuyoshi Nakada
2023-05-01[DOC] hash.c: fix typo in `#<=>` docsPiotr Szotkowski
Notes: Merged: https://github.com/ruby/ruby/pull/7771 Merged-By: nobu <[email protected]>
2023-04-15Adjust function style [ci skip]Nobuyoshi Nakada
2023-04-11hash.c: Fix hash_iter_lev_dec corrupting shapeJean Boussier
[Bug #19589] When decrementing `iter_lev` from `65` to `64` the flags would be corrupted, causing the shape_id to be invalid. Notes: Merged: https://github.com/ruby/ruby/pull/7686
2023-04-06[Feature #19474] Refactor NEWOBJ macrosMatt Valentine-House
NEWOBJ_OF is now our canonical newobj macro. It takes an optional ec Notes: Merged: https://github.com/ruby/ruby/pull/7393
2023-03-24Change Hash#compact to keep default values and compare_by_identity flagJeremy Evans
The documentation states it returns a copy of self with nil value entries removed. However, the previous behavior was creating a plain new hash with non-nil values copied into it. This change aligns the behavior with the documentation. Fixes [Bug #19113] Notes: Merged: https://github.com/ruby/ruby/pull/6702
2023-03-24Copy compare_by_identity flag for empty hashes in Hash.ruby2_keywords_hashJeremy Evans
This was already copied for non-empty hashes. As Hash.ruby2_keywords_hash copies default values, it should also copy the compare_by_identity flag. Partially Fixes [Bug #19113] Notes: Merged: https://github.com/ruby/ruby/pull/6702
2023-03-24Do not copy compare_by_identity flag for non-empty hashes in Hash.[]Jeremy Evans
It wasn't copied for empty hashes, and Hash.[] doesn't copy the default value, so copying the compare_by_identity flag does not make sense. Partially Fixes [Bug #19113] Notes: Merged: https://github.com/ruby/ruby/pull/6702
2023-03-06Resurrect symbols used by ObjectSpaceTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7459
2023-03-06Stop exporting symbols for MJITTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7459
2023-02-23Implement ObjectSpace::WeakKeyMap basic allocatorJean Boussier
[Feature #18498] Notes: Merged: https://github.com/ruby/ruby/pull/5570
2023-02-19Remove (newly unneeded) remarks about aliasesBurdetteLamar
2023-02-09Merge gc.h and internal/gc.hMatt Valentine-House
[Feature #19425] Notes: Merged: https://github.com/ruby/ruby/pull/7273
2023-02-03Remove dead code in ar_copyPeter Zhu
All of the callers of ar_copy guarantee that hash2 has an ar table, so we don't need the logic to handle the case when hash2 doesn't have an ar table. Notes: Merged: https://github.com/ruby/ruby/pull/7230
2023-02-02Remove redundant else if statement in hash.cPeter Zhu
Hashes can only be ar or st, so the else if is redundant.