diff options
author | Peter Zhu <peter@peterzhu.ca> | 2023-01-17 11:21:21 -0500 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2023-01-19 11:23:35 -0500 |
commit | 41bf2354e30fc585a61528560c291fd8ee77d107 (patch) | |
tree | 7617b29ea0e6313b6ae3adc12b64ac7f89a7cae2 /internal | |
parent | 6f3aff3961a4c5ce87e05096a1a9dcf1055b7647 (diff) |
Add rb_gc_mark_and_move and implement on iseq
This commit adds rb_gc_mark_and_move which takes a pointer to an object
and marks it during marking phase and updates references during compaction.
This allows for marking and reference updating to be combined into a
single function, which reduces code duplication and prevents bugs if
marking and reference updating goes out of sync.
This commit also implements rb_gc_mark_and_move on iseq as an example.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7140
Diffstat (limited to 'internal')
-rw-r--r-- | internal/gc.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/internal/gc.h b/internal/gc.h index c9123b3c7f..0c6fb2bcaf 100644 --- a/internal/gc.h +++ b/internal/gc.h @@ -113,6 +113,14 @@ size_t rb_gc_obj_slot_size(VALUE obj); bool rb_gc_size_allocatable_p(size_t size); int rb_objspace_garbage_object_p(VALUE obj); +void rb_gc_mark_and_move(VALUE *ptr); + +#define rb_gc_mark_and_move_ptr(ptr) do { \ + VALUE _obj = (VALUE)*(ptr); \ + rb_gc_mark_and_move(&_obj); \ + if (_obj != (VALUE)*(ptr)) *(ptr) = (void *)_obj; \ +} while (0) + RUBY_SYMBOL_EXPORT_BEGIN /* gc.c (export) */ const char *rb_objspace_data_type_name(VALUE obj); |