Skip to content

Update RB_GC_OBJECT_METADATA_ENTRY_COUNT #13179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025

Conversation

casperisfine
Copy link
Contributor

Ref: http://ci.rvm.jp/results/trunk_asan@ruby-sp1/5731894

In cb1ea54 I added one more metadata flag, but didn't notice RB_GC_OBJECT_METADATA_ENTRY_COUNT had to be incremented.

This should fix ASAN builds.

Interestingly, bdb2595 already caused the count to be off by one, so I had to increment it by 2.

FYI: @ko1 @peterzhu2118

In cb1ea54 I added one more
metadata flag, but didn't notice `RB_GC_OBJECT_METADATA_ENTRY_COUNT`
had to be incremented.

This should fix ASAN builds.

Interestingly, bdb2595 already
caused the count to be off by one, so I had to increment it by
2.
Copy link
Contributor

@ko1 ko1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW why it is "meta" data...?

@casperisfine
Copy link
Contributor Author

"meta" data...?

Well, it's data about the data, so metadata. That's how I understand it at least.

@byroot byroot merged commit 62a7f17 into ruby:master Apr 25, 2025
86 checks passed
@casperisfine casperisfine deleted the dbg-asan-shareable branch April 25, 2025 09:18
@nobu
Copy link
Member

nobu commented Apr 25, 2025

Counting by hand doesn't sound a nice idea.

diff --git i/gc/default/default.c w/gc/default/default.c
index 038a330e9ed..0073f123e44 100644
--- i/gc/default/default.c
+++ w/gc/default/default.c
@@ -6191,7 +6191,11 @@ rb_gc_impl_writebarrier_remember(void *objspace_ptr, VALUE obj)
     }
 }
 
-#define RB_GC_OBJECT_METADATA_ENTRY_COUNT 9
+struct rb_gc_object_metadata_names {
+    ID ID_wb_protected, ID_age, ID_old, ID_uncollectible, ID_marking, ID_marked, ID_pinned, ID_object_id, ID_shareable;
+};
+
+#define RB_GC_OBJECT_METADATA_ENTRY_COUNT (sizeof(struct rb_gc_object_metadata_names) / sizeof(ID))
 static struct rb_gc_object_metadata_entry object_metadata_entries[RB_GC_OBJECT_METADATA_ENTRY_COUNT + 1];
 
 struct rb_gc_object_metadata_entry *
@@ -6199,10 +6203,10 @@ rb_gc_impl_object_metadata(void *objspace_ptr, VALUE obj)
 {
     rb_objspace_t *objspace = objspace_ptr;
     size_t n = 0;
-    static ID ID_wb_protected, ID_age, ID_old, ID_uncollectible, ID_marking, ID_marked, ID_pinned, ID_object_id, ID_shareable;
+    static struct rb_gc_object_metadata_names names;
 
-    if (!ID_marked) {
-#define I(s) ID_##s = rb_intern(#s);
+    if (!names.ID_marked) {
+#define I(s) names.ID_##s = rb_intern(#s)
         I(wb_protected);
         I(age);
         I(old);
@@ -6217,7 +6221,7 @@ rb_gc_impl_object_metadata(void *objspace_ptr, VALUE obj)
 
 #define SET_ENTRY(na, v) do { \
     GC_ASSERT(n <= RB_GC_OBJECT_METADATA_ENTRY_COUNT); \
-    object_metadata_entries[n].name = ID_##na; \
+    object_metadata_entries[n].name = names.ID_##na; \
     object_metadata_entries[n].val = v; \
     n++; \
 } while (0)

@byroot
Copy link
Member

byroot commented Apr 25, 2025

Counting by hand doesn't sound a nice idea.

You mean a bad idea?

Feel free to make that change. I'm not as skilled as you in this sort of tricks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants