summaryrefslogtreecommitdiff
path: root/hash.c
AgeCommit message (Collapse)Author
2025-03-16merge revision(s) 3f07bc76ff6a11232d9f18e5eaa31835c195e8f0, ↵nagachika
34098b669c0cbc024cd08e686891f1dfe0a10aaf: [Backport #21144] [Bug #21144] Win32: Use Windows time zone ID if TZ is not set If the TZ environment variable is not set, the time zone names retrieved from the system are localized for UI display and may vary across editions and language packs for the same time zone. Use the time zone IDs that are invariant across environments instead. [Bug #21144] Win32: Convert the time zone name to the current locale The Windows time zone IDs provided by Microsoft as of 24H1 are ASCII only all, but the API itself is not impossible to set non-ASCII key name. Prefer the current locale encoding for now until we move to UTF-8 including environment variables and command line arguments.
2025-01-14merge revision(s) 19c39e4cfaa467e69b9848c9c5496d7f50d39c7f: [Backport #20984]Takashi Kokubun
[Bug #20984] ENV.inspect should be encoding aware
2024-05-28merge revision(s) f36a71e26995b69ff72bc132bbcf40ad89571414: [Backport #20307]Takashi Kokubun
[Bug #20307] Fix `Hash#update` to make frozen copy of string keys
2024-05-28Extract `RHASH_STRING_KEY_P`Nobuyoshi Nakada
2024-05-28Extract `RHASH_IDENTHASH_P`Nobuyoshi Nakada
2024-02-01merge revision(s) 6c252912af4981f016a9abdb4c1689307a4f1d2f: [Backport #20145]NARUSE, Yui
Memory leak when duplicating identhash [Bug #20145] Before this commit, both copy_compare_by_id and hash_copy will create a copy of the ST table, so the ST table created in copy_compare_by_id will be leaked. h = { 1 => 2 }.compare_by_identity 10.times do 1_000_000.times do h.select { false } end puts `ps -o rss= -p #{$$}` end Before: 110736 204352 300272 395520 460704 476736 542000 604704 682624 770528 After: 15504 16048 16144 16256 16320 16320 16752 16752 16752 16752 --- hash.c | 10 +++++++++- test/ruby/test_hash.rb | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-)
2023-12-18compare_by_identity: remove alloc for non-empty HashAlexander Momchilov
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`.
2023-12-18compare_by_identity: remove alloc for empty HashAlexander Momchilov
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.
2023-12-18[DOC] No document for internal or debug methodsNobuyoshi Nakada
2023-12-15check modifcation whil ar->stKoichi Sasada
* 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]
2023-12-13Fix memory leak in Hash#compare_by_identityAlan Wu
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>
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 <adamhess1991@gmail.com>
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 <nobu@ruby-lang.org>
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 <nobu@ruby-lang.org>
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 <nobu@ruby-lang.org>
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 <byroot@ruby-lang.org> Notes: Merged-By: byroot <byroot@ruby-lang.org>
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 <nobu@ruby-lang.org>
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