aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c
Commit message (Collapse)AuthorAgeFilesLines
* compare_by_identity: remove alloc for non-empty HashAlexander Momchilov2023-12-181-4/+9
| | | | If a Hash is non-empty, there's no point calling `ar_force_convert_table`. We'll be immediately discarding that new st table, and replacing it with the new `identtable` st table that we're stealing out of `tmp`.
* compare_by_identity: remove alloc for empty HashAlexander Momchilov2023-12-181-7/+14
| | | | | | For non-empty Hashes, this function needs to rehash all the stored values (using the new `compare` and `hash` functions from `identhash`). It does so by writing into a newly allocated `tmp` Hash, and then transferring ownership of its st table into `self`. For empty Hashes, we can skip allocating this `tmp`, because there's nothing to re-hash. We can just modify our new st table's `type` in-place.
* [DOC] No document for internal or debug methodsNobuyoshi Nakada2023-12-181-0/+1
|
* check modifcation whil ar->stKoichi Sasada2023-12-151-42/+57
| | | | | | | | | | | | | * delete `ar_try_convert` but use `ar_force_convert_table` to make program simple. * `ar_force_convert_table` checks hash modification while calling `#hash` method with the following strategy: 1. copy keys (and vals) of ar_table 2. calc hashes from keys 3. check copied keys and hash's keys. if not matched, repeat from 1 fix [Bug #20050]
* Fix memory leak in Hash#compare_by_identityAlan Wu2023-12-131-0/+1
| | | | | | | We didn't free the old ST before overwriting it which caused a leak. Found with RUBY_FREE_ON_EXIT. Co-authored-by: Peter Zhu <peter@peterzhu.ca>
* Use xfree in hash_st_freeJohn Hawthorn2023-12-071-2/+2
| | | | | | | 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.
* Do not change hash type in Hash#assocNobuyoshi Nakada2023-11-211-34/+27
|
* Raise an exception when Hash#compare_by_identity during its iterationYusuke Endoh2023-11-211-0/+3
|
* Raise an exception if ar_table is converted to st_table during iterationYusuke Endoh2023-11-211-0/+11
| | | | | | | | | | | 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)
* Just check if iteration level is non-zerov3_3_0_preview3Nobuyoshi Nakada2023-11-121-23/+16
| | | | | The level in ivar is no longer needed to check if iterating, only used for increment/decrement.
* Refactor hash iteration levelNobuyoshi Nakada2023-11-121-23/+31
| | | | | | - Make it unsigned like as in-flags bits - Make it long since it should be fixable - Reduce it to in-flags bits after decrement
* [Bug #19969] Compact st_table after deleted if possibleNobuyoshi Nakada2023-11-111-0/+19
|
* [DOC] Update documentation for typical implementation of hashYuki Tsujimoto2023-10-221-1/+1
|
* [DOC] Missing comment markerNobuyoshi Nakada2023-09-271-1/+1
|
* Add rb_hash_free for the GC to usePeter Zhu2023-09-241-0/+8
|
* Add hash_st_freePeter Zhu2023-09-241-2/+8
|
* Fix memory leak in Hash#rehash for ST hashesPeter Zhu2023-09-231-8/+9
| | | | | | We need to free the old ST table in Hash#rehash. Co-authored-by: Adam Hess <adamhess1991@gmail.com>
* `RHASH_AR_TABLE` never returns NULL now [ci skip]Nobuyoshi Nakada2023-09-061-5/+1
|
* [DOC] Typo in Hash#key description "so/no such value"Dorian MariƩ (perso)2023-09-031-1/+1
|
* [DOC] FIx typo in description of Hash#hash (regardless or/of order)Dorian MariƩ (perso)2023-09-031-1/+1
|
* [DOC] Don't suppress autolinksBurdetteLamar2023-08-121-61/+61
|
* Add assertion in `RHASH_AR_TABLE_BOUND`Nobuyoshi Nakada2023-08-031-4/+10
|
* Remove RARRAY_PTR_USE_TRANSIENTPeter Zhu2023-07-131-3/+3
| | | | RARRAY_PTR_USE now does the same things as RARRAY_PTR_USE_TRANSIENT.
* Don't check for null pointer in calls to freePeter Zhu2023-06-301-1/+1
| | | | | | | | 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.
* Fix memory leak in Hash#replacePeter Zhu2023-06-291-1/+14
| | | | Hash#replace can leak memory if the receiver has an ST table.
* Fix memory leak when copying ST tablesPeter Zhu2023-06-291-2/+5
| | | | | | | | | | | | | | | | | 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 ```
* Refactor rb_hash_replace to use hash_copyPeter Zhu2023-06-291-28/+21
|
* Declare `RHASH_AR_TABLE` and `RHASH_ST_TABLE` return non-nullNobuyoshi Nakada2023-06-231-4/+2
|
* Remove dead code in hash.cPeter Zhu2023-06-221-53/+0
| | | | | RHASH_TABLE_NULL_P and ar_alloc_table are no longer needed since all Hash will have AR tables.
* hash.c no longer needs the transient heapPeter Zhu2023-06-121-5/+2
|
* * remove trailing spaces. [ci skip]git2023-06-081-1/+1
|
* [DOC] Add comment about flags for HashPeter Zhu2023-06-081-0/+17
|
* [DOC] Mention the edge case of `any?`/`all?`Nobuyoshi Nakada2023-06-011-0/+5
|
* Remove dead code in rb_hash_replacePeter Zhu2023-05-231-5/+0
| | | | | We now always copy the ST table, so we don't need to initialize the ST table of hash when hash2 is empty.
* Fix crash when replacing ST hash with AR hashPeter Zhu2023-05-231-3/+27
| | | | | | | | | 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.
* Remove dead code in ar_copyPeter Zhu2023-05-231-4/+0
| | | | new_tab can no longer ever be NULL so this is dead code.
* Hash.new: print a deprecation warning when receiving keyword arguments (#7828)Jean byroot Boussier2023-05-231-5/+9
| | | | | | | | | | [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 <byroot@ruby-lang.org>
* Move ar_hint to ar_table_structPeter Zhu2023-05-171-14/+17
| | | | This allows Hashes with ST tables to fit int he 80 byte size pool.
* Implement Hash ST tables on VWAPeter Zhu2023-05-171-71/+39
|
* Implement Hash AR tables on VWAPeter Zhu2023-05-171-77/+22
|
* Add `rb_sys_fail_sprintf` macroNobuyoshi Nakada2023-05-121-4/+4
|
* [DOC] hash.c: fix typo in `#<=>` docsPiotr Szotkowski2023-05-011-1/+1
|
* Adjust function style [ci skip]Nobuyoshi Nakada2023-04-151-3/+1
|
* hash.c: Fix hash_iter_lev_dec corrupting shapeJean Boussier2023-04-111-3/+9
| | | | | | | [Bug #19589] When decrementing `iter_lev` from `65` to `64` the flags would be corrupted, causing the shape_id to be invalid.
* [Feature #19474] Refactor NEWOBJ macrosMatt Valentine-House2023-04-061-1/+1
| | | | NEWOBJ_OF is now our canonical newobj macro. It takes an optional ec
* Change Hash#compact to keep default values and compare_by_identity flagJeremy Evans2023-03-241-11/+5
| | | | | | | | | 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]
* Copy compare_by_identity flag for empty hashes in Hash.ruby2_keywords_hashJeremy Evans2023-03-241-3/+6
| | | | | | | 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]
* Do not copy compare_by_identity flag for non-empty hashes in Hash.[]Jeremy Evans2023-03-241-4/+16
| | | | | | | | 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]
* Resurrect symbols used by ObjectSpaceTakashi Kokubun2023-03-061-1/+1
|
* Stop exporting symbols for MJITTakashi Kokubun2023-03-061-8/+8
|