summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-01-17 11:21:21 -0500
committerPeter Zhu <peter@peterzhu.ca>2023-01-19 11:23:35 -0500
commit41bf2354e30fc585a61528560c291fd8ee77d107 (patch)
tree7617b29ea0e6313b6ae3adc12b64ac7f89a7cae2 /internal
parent6f3aff3961a4c5ce87e05096a1a9dcf1055b7647 (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.h8
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);