Commit graph

1088 commits

Author SHA1 Message Date
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 bb180b87b4, 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
BurdetteLamar
057ee25d1b [DOC] Tweaks for Hash#to_proc 2025-03-13 21:11:47 -04:00
Burdette Lamar
1b2cc9c2b8
[DOC] Tweaks for Hash#slice 2025-03-11 21:54:49 -04:00
BurdetteLamar
86eff8565b [DOC] Tweaks for Hash#to_a 2025-03-11 21:54:06 -04:00
BurdetteLamar
5208d2f440 [DOC] Tweaks for Hash#shift 2025-03-11 21:52:38 -04:00
Burdette Lamar
b52f789520
[DOC] Tweaks for Hash#select! (#12904) 2025-03-11 15:19:38 -04:00
Burdette Lamar
a5f29213dc
[DOC] Tweaks for Hash#select (#12903) 2025-03-11 15:18:47 -04:00
Burdette Lamar
51e2ff1ef7
[DOC] Tweaks for Hash#reject! 2025-03-11 15:18:06 -04:00
Burdette Lamar
497f409ba4
[DOC] Tweaks for Hash#reject (#12876) 2025-03-11 11:43:50 -04:00
Burdette Lamar
e99026784a
[DOC] Tweaks for Hash#update 2025-03-11 11:43:20 -04:00
Burdette Lamar
17f6a68962
[DOC] Tweaks for Hash#rehash 2025-03-07 09:38:51 -05:00
BurdetteLamar
8774530ce1 [DOC] Tweaks for Hash#rassoc 2025-03-07 09:36:51 -05:00
Burdette Lamar
42b75a9c64
[DOC] Tweaks for Hash#merge (#12825) 2025-03-07 09:34:36 -05:00
BurdetteLamar
5de02d6487 [DOC] Tweaks for Hash#size 2025-03-04 09:22:19 -05:00
BurdetteLamar
1b6fddf4db [DOC] Tweaks for Hash#keep_if 2025-02-26 15:52:45 -05:00
BurdetteLamar
04e46bd75c [DOC] Tweaks for Hash#key 2025-02-26 15:52:13 -05:00
BurdetteLamar
8dce189078 [DOC] Tweaks for Hash#keys 2025-02-26 15:51:58 -05:00
Burdette Lamar
3bbb029d44
[DOC] Tweaks for Hash#invert 2025-02-26 09:28:52 -05:00
BurdetteLamar
43a729b1be [DOC] Tweaks for Hash#replace 2025-02-26 09:28:05 -05:00