diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2021-02-03 16:17:28 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2021-02-04 09:49:00 -0800 |
commit | 75b96c3a056d9e50bdabd87fa4676e6aaffbcff0 (patch) | |
tree | 1f26dd9f8ccdb4899e116e89a6d62b408bb0480d /gc.c | |
parent | b79d44348216e293f35801984f109ec9b02dcf83 (diff) | |
download | ruby-75b96c3a056d9e50bdabd87fa4676e6aaffbcff0.tar.gz |
Don't register non-heap allocated objects
`rb_define_const` can add objects as "mark objects". This is to make
code like this work:
https://github.com/ruby/ruby/blob/33d6e92e0c6eaf1308ce7108e653c53bb5fb106c/ext/etc/etc.c#L1201
```
rb_define_const(rb_cStruct, "Passwd", sPasswd); /* deprecated name */
```
sPasswd is a heap allocated object that is also a C global, so we can't
move it (it needs to be pinned). However, we have many calls to
`rb_define_const` that just pass in an integer like this:
```
rb_define_const(rb_cDBM, "WRITER", INT2FIX(O_RDWR|RUBY_DBM_RW_BIT));
```
Non heap allocated objects like integers will never move, so there is no
reason to waste time in the GC marking / pinning them.
Diffstat (limited to 'gc.c')
-rw-r--r-- | gc.c | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -8051,6 +8051,9 @@ rb_gc_force_recycle(VALUE obj) void rb_gc_register_mark_object(VALUE obj) { + if (!is_pointer_to_heap(&rb_objspace, (void *)obj)) + return; + RB_VM_LOCK_ENTER(); { VALUE ary_ary = GET_VM()->mark_object_ary; |