Change each_stack_location to accept data instead of objspace

The callers were abusing each_stack_location and passing data into the objspace
argument.
This commit is contained in:
Peter Zhu 2024-08-28 15:14:19 -04:00
parent c162da69e7
commit 1f114464fc
Notes: git 2024-08-29 18:37:20 +00:00

31
gc.c
View File

@ -2111,19 +2111,19 @@ each_location(register const VALUE *x, register long n, void (*cb)(void *data, V
} }
static void static void
gc_mark_locations(void *objspace, const VALUE *start, const VALUE *end, void (*cb)(void *, VALUE)) gc_mark_locations(const VALUE *start, const VALUE *end, void (*cb)(void *, VALUE), void *data)
{ {
long n; long n;
if (end <= start) return; if (end <= start) return;
n = end - start; n = end - start;
each_location(start, n, cb, objspace); each_location(start, n, cb, data);
} }
void void
rb_gc_mark_locations(const VALUE *start, const VALUE *end) rb_gc_mark_locations(const VALUE *start, const VALUE *end)
{ {
gc_mark_locations(rb_gc_get_objspace(), start, end, gc_mark_maybe_internal); gc_mark_locations(start, end, rb_gc_impl_mark_maybe, rb_gc_get_objspace());
} }
void void
@ -2241,15 +2241,14 @@ mark_m_tbl(void *objspace, struct rb_id_table *tbl)
#endif #endif
static void static void
each_stack_location(void *objspace, const rb_execution_context_t *ec, each_stack_location(const rb_execution_context_t *ec,
const VALUE *stack_start, const VALUE *stack_end, void (*cb)(void *objspace, VALUE obj)) const VALUE *stack_start, const VALUE *stack_end, void (*cb)(void *data, VALUE obj), void *data)
{ {
gc_mark_locations(objspace, stack_start, stack_end, cb); gc_mark_locations(stack_start, stack_end, cb, data);
#if defined(__mc68000__) #if defined(__mc68000__)
gc_mark_locations(objspace, gc_mark_locations((VALUE*)((char*)stack_start + 2),
(VALUE*)((char*)stack_start + 2), (VALUE*)((char*)stack_end - 2), cb, data);
(VALUE*)((char*)stack_end - 2), cb);
#endif #endif
} }
@ -2277,7 +2276,7 @@ gc_mark_machine_stack_location_maybe(void *data, VALUE obj)
&fake_frame_start, &fake_frame_end &fake_frame_start, &fake_frame_end
); );
if (is_fake_frame) { if (is_fake_frame) {
each_stack_location(objspace, ec, fake_frame_start, fake_frame_end, gc_mark_maybe_internal); each_stack_location(ec, fake_frame_start, fake_frame_end, rb_gc_impl_mark_maybe, objspace);
} }
#endif #endif
} }
@ -2300,10 +2299,10 @@ static void
mark_current_machine_context(void *objspace, rb_execution_context_t *ec) mark_current_machine_context(void *objspace, rb_execution_context_t *ec)
{ {
emscripten_scan_stack(rb_mark_locations); emscripten_scan_stack(rb_mark_locations);
each_stack_location(objspace, ec, rb_stack_range_tmp[0], rb_stack_range_tmp[1], gc_mark_maybe_internal); each_stack_location(ec, rb_stack_range_tmp[0], rb_stack_range_tmp[1], rb_gc_impl_mark_maybe, objspace);
emscripten_scan_registers(rb_mark_locations); emscripten_scan_registers(rb_mark_locations);
each_stack_location(objspace, ec, rb_stack_range_tmp[0], rb_stack_range_tmp[1], gc_mark_maybe_internal); each_stack_location(ec, rb_stack_range_tmp[0], rb_stack_range_tmp[1], rb_gc_impl_mark_maybe, objspace);
} }
# else // use Asyncify version # else // use Asyncify version
@ -2313,10 +2312,10 @@ mark_current_machine_context(void *objspace, rb_execution_context_t *ec)
VALUE *stack_start, *stack_end; VALUE *stack_start, *stack_end;
SET_STACK_END; SET_STACK_END;
GET_STACK_BOUNDS(stack_start, stack_end, 1); GET_STACK_BOUNDS(stack_start, stack_end, 1);
each_stack_location(objspace, ec, stack_start, stack_end, gc_mark_maybe_internal); each_stack_location(ec, stack_start, stack_end, rb_gc_impl_mark_maybe, objspace);
rb_wasm_scan_locals(rb_mark_locations); rb_wasm_scan_locals(rb_mark_locations);
each_stack_location(objspace, ec, rb_stack_range_tmp[0], rb_stack_range_tmp[1], gc_mark_maybe_internal); each_stack_location(ec, rb_stack_range_tmp[0], rb_stack_range_tmp[1], rb_gc_impl_mark_maybe, objspace);
} }
# endif # endif
@ -2351,7 +2350,7 @@ mark_current_machine_context(void *objspace, rb_execution_context_t *ec)
}; };
each_location(save_regs_gc_mark.v, numberof(save_regs_gc_mark.v), gc_mark_machine_stack_location_maybe, &data); each_location(save_regs_gc_mark.v, numberof(save_regs_gc_mark.v), gc_mark_machine_stack_location_maybe, &data);
each_stack_location((void *)&data, ec, stack_start, stack_end, gc_mark_machine_stack_location_maybe); each_stack_location(ec, stack_start, stack_end, gc_mark_machine_stack_location_maybe, &data);
} }
#endif #endif
@ -2370,7 +2369,7 @@ rb_gc_mark_machine_context(const rb_execution_context_t *ec)
#endif #endif
}; };
each_stack_location((void *)&data, ec, stack_start, stack_end, gc_mark_machine_stack_location_maybe); each_stack_location(ec, stack_start, stack_end, gc_mark_machine_stack_location_maybe, &data);
int num_regs = sizeof(ec->machine.regs)/(sizeof(VALUE)); int num_regs = sizeof(ec->machine.regs)/(sizeof(VALUE));
each_location((VALUE*)&ec->machine.regs, num_regs, gc_mark_machine_stack_location_maybe, &data); each_location((VALUE*)&ec->machine.regs, num_regs, gc_mark_machine_stack_location_maybe, &data);
} }