1106 Commits

Author SHA1 Message Date
Peter Zhu
1de6133825 [DOC] Fix hash style in Hash#except 2026-01-24 09:43:54 -05:00
Peter Zhu
1d497946af [DOC] Fix hash style in Hash#[] 2026-01-22 20:10:35 -05:00
Burdette Lamar
3d242a82a3
[DOC] Harmonize #> methods 2026-01-09 17:36:26 -05:00
Peter Zhu
c6f9a4d393 Remove check for rb_obj_gen_fields_p in rb_hash_dup
rb_copy_generic_ivar already checks for it, so we don't need to call
rb_obj_gen_fields_p twice.
2026-01-08 17:33:32 -05:00
Burdette Lamar
58fb95af36
[DOC] Harmonize #== methods (#15805) 2026-01-06 17:13:15 -05:00
BurdetteLamar
a25f468917 [DOC] Harmonize #>= methods 2026-01-05 18:23:55 -05:00
Peter Zhu
b9819ad06c Register a dupped identity hash as pinning 2026-01-02 08:54:56 -05:00
Peter Zhu
01cd9c9fad Add rb_gc_register_pinning_obj 2025-12-29 09:03:31 -05:00
BurdetteLamar
d540903ee7 [DOC] Harmonize <= methods 2025-12-19 17:09:10 -05:00
Burdette Lamar
b14f2f0116
[DOC] Harmonize lt methods 2025-12-18 19:21:00 -05:00
Jean Boussier
5770c186d1 Rename rb_obj_exivar_p -> rb_obj_gen_fields_p
The "EXIVAR" terminology has been replaced by "gen fields"
AKA "generic fields".

Exivar implies variable, but generic fields include more than
just variables, e.g. `object_id`.
2025-12-03 15:57:26 +01:00
Stan Lo
4cd6661e18
Reorganize page documentations (#15154)
Re-organize page docs
2025-11-27 20:12:24 +00:00
Peter Zhu
6014ed9968 Remove dead rb_hash_dump 2025-11-05 22:31:17 -05:00
Sam Westerman
17a7b4e031
[DOC] Fix typo in Hash#compare_by_identity docs 2025-11-01 09:18:01 +09:00
Koichi Sasada
bc00c4468e use SET_SHAREABLE
to adopt strict shareable rule.

* (basically) shareable objects only refer shareable objects
* (exception) shareable objects can refere unshareable objects
  but should not leak reference to unshareable objects to Ruby world
2025-10-23 13:08:26 +09:00
MSP-Greg
b92db45b98 [DOC] hash.c - fix 3 class doc typos 2025-10-03 11:08:45 +09:00
Yaroslav
8a704783f8
[DOC] Fix outdated ENV::clone method description
It does raise an exception rather than just issuing a warning:

```shell
$ docker run -e ALL_RUBY_SINCE=2.7 --rm rubylang/all-ruby ./all-ruby -We 'ENV.clone'
ruby-2.7.0
...
ruby-3.0.7
ruby-3.1.0-preview1 -e:1: warning: ENV.clone is deprecated; use ENV.to_h instead
...
ruby-3.2.0-preview1 -e:1: warning: ENV.clone is deprecated; use ENV.to_h instead
ruby-3.2.0-preview2 -e:1:in `clone': Cannot clone ENV, use ENV.to_h to get a copy of ENV as a hash (TypeError)
                    	from -e:1:in `<main>'
                exit 1
...
ruby-3.3.9          -e:1:in `clone': Cannot clone ENV, use ENV.to_h to get a copy of ENV as a hash (TypeError)
                    	from -e:1:in `<main>'
                exit 1
ruby-3.4.0-preview1 -e:1:in 'clone': Cannot clone ENV, use ENV.to_h to get a copy of ENV as a hash (TypeError)
                    	from -e:1:in '<main>'
                exit 1
...
ruby-3.5.0-preview1 -e:1:in 'clone': Cannot clone ENV, use ENV.to_h to get a copy of ENV as a hash (TypeError)
                    	from -e:1:in '<main>'
                exit 1

```
2025-08-24 06:46:32 +09:00
Burdette Lamar
b3053cbb34
[DOC] Tweaks for Object#hash 2025-08-19 19:34:40 -04:00
Luke Gruber
1afc07e815 Allow encodings to be autoloaded through transcoding functions
Make sure VM lock is not held when calling `load_transcoder_entry`, as
that causes deadlock inside ractors. `String#encode` now works inside
ractors, among others.

Atomic load the rb_encoding_list

Without this, wbcheck would sometimes hit a missing write barrier.

Co-authored-by: John Hawthorn <john.hawthorn@shopify.com>

Hold VM lock when iterating over global_enc_table.names

This st_table can be inserted into at runtime when autoloading
encodings.

minor optimization when calling Encoding.list
2025-08-12 15:19:02 -07:00
Jean Boussier
cbe5241c77 [DOC] Mention that Hash#replace also replaces defaults 2025-07-30 10:40:34 +02:00
Peter Zhu
23000e7123 Remove unnecessary internal/gc.h include in hash.c
hash.c compiles just fine on HASH_DEBUG without including internal/gc.h.
2025-07-28 17:18:35 -04:00
Nobuyoshi Nakada
abafb662ea
Adjust indents [ci skip] 2025-07-26 22:07:28 +09:00
Peter Zhu
a2e165e8a0 Remove dsymbol_fstr_hash
We don't need to delay the freeing of the fstr for the symbol if we store
the hash of the fstr in the dynamic symbol and we use compare-by-identity
for removing the dynamic symbol from the sym_set.
2025-07-21 10:58:30 -04:00
Alan Wu
b49ae45b88
Remove dead post-hoc rehash check
Hash#rehash checks whether the hash is iterating, and with VWA,
RHASH_ST_TABLE() always returns the same thing for the same
hash.

    RHASH_ST_TABLE(VALUE h)
    {
        return (st_table *)((uintptr_t)h + sizeof(struct RHash));
    }

So this check can never fail and raise an exception. Remove it.
2025-07-18 23:30:24 +00:00
Erik Berlin
bd27460c06
Remove rehash checking TODO (GH-13919)
Hash#rehash checks for rehash during iteration, and there
seems to be no efficient way to check for it after the fact,
so remove the TODO.
2025-07-18 17:58:04 -04:00
Erik Berlin
abc8745fc3 Avoid second RHASH_AR_TABLE_REF lookup 2025-07-16 16:13:21 -04:00
John Hawthorn
fcf2c3b4d1 Fix write barriers in rb_hash_add_new_element
The write barriers must be run after the st_update callback returns,
as the objects are not on the object until then and there may be
allocation when there is a new object inserted.

This is hard to reproduce, and I haven't seen an actual crash due to it,
but it is detected by wbcheck

    RUBY_GC_LIBRARY=wbcheck WBCHECK_VERIFY_AFTER_WB=1 ./miniruby -e '("a".."zz").uniq.to_a'
    WBCHECK ERROR: Missed write barrier detected!
      Parent object: 0x720db01f99c0 (wb_protected: true)
        rb_obj_info_dump: 0x0000720db01f99c0 T_HASH/[S] 18
      Reference counts - snapshot: 32, writebarrier: 2, current: 36, missed: 2
      Missing reference to: 0x716db02e3450
        rb_obj_info_dump: 0x0000716db02e3450 T_STRING/String  len: 1, capa: 15 "q"
      Missing reference to: 0x716db02e3450
        rb_obj_info_dump: 0x0000716db02e3450 T_STRING/String  len: 1, capa: 15 "q"

A part of why this is hard to reproduce and it's unlikely to crash is
that the insertion only rarely allocates.

Co-authored-by: Luke Gruber <luke.gruber@shopify.com>
2025-06-24 13:08:35 -07:00
Nobuyoshi Nakada
a60bf9e693
* adjust indent 2025-06-17 12:30:18 +09:00
Jean Boussier
6dbe24fe56 Use the shape_id rather than FL_EXIVAR
We still keep setting `FL_EXIVAR` so that `rb_shape_verify_consistency`
can detect discrepancies.
2025-06-13 23:50:30 +02:00
Nobuyoshi Nakada
aad9fa2853
Use RB_VM_LOCKING 2025-05-25 15:22:43 +09:00
Daniel Colson
0564973196 [Bug #21357] Fix crash in Hash#merge with block
Prior to 49b306ecb9
the `optional_arg` passed from `rb_hash_update_block_i` to `tbl_update`
was a hash value (i.e. a VALUE). After that commit it changed to an
`update_call_args`.

If the block sets or changes the value, `tbl_update_modify` will set the
`arg.value` back to an actual value and we won't crash. But in the case
where the block returns the original value we end up calling
`RB_OBJ_WRITTEN` with the `update_call_args` which is not expected and
may crash.

`arg.value` appears to only be used to pass to `RB_OBJ_WRITTEN` (others
who need the `update_call_args` get it from `arg.arg`), so I don't think
it needs to be set to anything upfront. And `tbl_update_modify` will set
the `arg.value` in the cases we need the write barrier.
2025-05-22 12:25:55 +09:00
Nobuyoshi Nakada
49b306ecb9 [Bug #21333] Prohibit hash modification inside Hash#update block 2025-05-15 15:39:15 +09:00
Nobuyoshi Nakada
7793b59c8d
[Bug #21331] Prohibit hash modification during stlike loop 2025-05-14 10:37:59 +09:00
Nobuyoshi Nakada
7f5b4fb26e
Remove unused retval assignments 2025-05-14 10:26:04 +09:00
Nobuyoshi Nakada
b66c5c3b1b
Revert "[Bug #21331] Prohibit modification during stlike loop"
This reverts commit bb180b87b43c45e17ff49735a26d7a188d5c8396, which
caused "malloc during GC" error on wasm.
2025-05-14 10:23:16 +09:00
Nobuyoshi Nakada
bb180b87b4 [Bug #21331] Prohibit modification during stlike loop 2025-05-13 23:16:58 +09:00
Jeremy Evans
926411171d
Support Marshal.{dump,load} for core Set
This was missed when adding core Set, because it's handled
implicitly for T_OBJECT.

Keep marshal compatibility between core Set and stdlib Set,
so you can unmarshal core Set with stdlib Set and vice versa.

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2025-04-28 08:38:35 -07:00
BurdetteLamar
3a7b03242f [DOC] Tweaks for Hash doc 2025-04-02 12:10:56 -04:00
BurdetteLamar
2d9036498e [DOC] Tweaks for Hash doc 2025-03-31 14:49:40 -04:00
Burdette Lamar
cdb1bf1e53
[DOC] Tweaks for Hash#update 2025-03-31 14:47:20 -04:00
BurdetteLamar
9e87323ad0 [DOC] Tweaks for Hash#values_at 2025-03-29 17:05:21 -04:00
BurdetteLamar
dbc1ceca32 [DOC] Tweaks for Hash#values 2025-03-29 17:04:56 -04:00
BurdetteLamar
4e3bc65e88 [DOC] Tweaks for Hash#has_value? 2025-03-29 17:04:33 -04:00
Burdette Lamar
0b186ed413
[DOC] Doc for Hash#transform_keys! (#12942) 2025-03-25 15:26:51 -04:00
Burdette Lamar
12b2b577b7
[DOC] Doc for Hash#transform_values! 2025-03-23 11:09:08 -04:00
BurdetteLamar
383af53a56 [DOC] Doc for Hash#transform_values 2025-03-23 11:07:31 -04:00
Peter Zhu
2dc501497e [DOC] Fix indentation for documentation of Hash#compact 2025-03-17 16:12:34 -04:00
BurdetteLamar
70a9e5f6eb [DOC] Doc for Hash#transform_keys 2025-03-16 11:35:32 -04:00
Burdette Lamar
efb2d43637
[DOC] Tweaks for Hash#to_h (#12918) 2025-03-14 10:41:27 -04:00
BurdetteLamar
a4328a424b [DOC] Tweaks for Hash#to_hash 2025-03-13 21:12:08 -04:00