Revert "Allow each_stack_location to accept context for the callback"

This reverts commit 179228cd83.
This commit is contained in:
KJ Tsanaktsidis 2024-01-12 17:32:16 +11:00
Родитель 33a03cb236
Коммит ac0ba3c07e
1 изменённых файлов: 19 добавлений и 27 удалений

46
gc.c
Просмотреть файл

@ -6548,38 +6548,32 @@ ruby_stack_check(void)
return stack_check(GET_EC(), STACKFRAME_FOR_CALL_CFUNC); return stack_check(GET_EC(), STACKFRAME_FOR_CALL_CFUNC);
} }
ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(static void each_location(rb_objspace_t *objspace, register const VALUE *x, register long n, void *ctx, void (*cb)(rb_objspace_t *, void *, VALUE))); ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(static void each_location(rb_objspace_t *objspace, register const VALUE *x, register long n, void (*cb)(rb_objspace_t *, VALUE)));
static void static void
each_location(rb_objspace_t *objspace, register const VALUE *x, register long n, void *ctx, void (*cb)(rb_objspace_t *, void *, VALUE)) each_location(rb_objspace_t *objspace, register const VALUE *x, register long n, void (*cb)(rb_objspace_t *, VALUE))
{ {
VALUE v; VALUE v;
while (n--) { while (n--) {
v = *x; v = *x;
cb(objspace, ctx, v); cb(objspace, v);
x++; x++;
} }
} }
static void static void
gc_mark_locations(rb_objspace_t *objspace, const VALUE *start, const VALUE *end, void *ctx, void (*cb)(rb_objspace_t *, void *, VALUE)) gc_mark_locations(rb_objspace_t *objspace, const VALUE *start, const VALUE *end, void (*cb)(rb_objspace_t *, VALUE))
{ {
long n; long n;
if (end <= start) return; if (end <= start) return;
n = end - start; n = end - start;
each_location(objspace, start, n, ctx, cb); each_location(objspace, start, n, cb);
}
static void
gc_mark_maybe_cb(rb_objspace_t *objspace, void *ctx, VALUE obj)
{
gc_mark_maybe(objspace, obj);
} }
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_objspace, start, end, NULL, gc_mark_maybe_cb); gc_mark_locations(&rb_objspace, start, end, gc_mark_maybe);
} }
void void
@ -6825,8 +6819,7 @@ mark_const_tbl(rb_objspace_t *objspace, struct rb_id_table *tbl)
#endif #endif
static void each_stack_location(rb_objspace_t *objspace, const rb_execution_context_t *ec, static void each_stack_location(rb_objspace_t *objspace, const rb_execution_context_t *ec,
const VALUE *stack_start, const VALUE *stack_end, void *ctx, const VALUE *stack_start, const VALUE *stack_end, void (*cb)(rb_objspace_t *, VALUE));
void (*cb)(rb_objspace_t *, void *, VALUE));
#if defined(__wasm__) #if defined(__wasm__)
@ -6846,10 +6839,10 @@ static void
mark_current_machine_context(rb_objspace_t *objspace, rb_execution_context_t *ec) mark_current_machine_context(rb_objspace_t *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_cb); each_stack_location(objspace, ec, rb_stack_range_tmp[0], rb_stack_range_tmp[1], gc_mark_maybe);
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_cb); each_stack_location(objspace, ec, rb_stack_range_tmp[0], rb_stack_range_tmp[1], gc_mark_maybe);
} }
# else // use Asyncify version # else // use Asyncify version
@ -6859,10 +6852,10 @@ mark_current_machine_context(rb_objspace_t *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_cb); each_stack_location(objspace, ec, stack_start, stack_end, gc_mark_maybe);
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_cb); each_stack_location(objspace, ec, rb_stack_range_tmp[0], rb_stack_range_tmp[1], gc_mark_maybe);
} }
# endif # endif
@ -6889,41 +6882,40 @@ mark_current_machine_context(rb_objspace_t *objspace, rb_execution_context_t *ec
SET_STACK_END; SET_STACK_END;
GET_STACK_BOUNDS(stack_start, stack_end, 1); GET_STACK_BOUNDS(stack_start, stack_end, 1);
each_location(objspace, save_regs_gc_mark.v, numberof(save_regs_gc_mark.v), NULL, gc_mark_maybe_cb); each_location(objspace, save_regs_gc_mark.v, numberof(save_regs_gc_mark.v), gc_mark_maybe);
each_stack_location(objspace, ec, stack_start, stack_end, NULL, gc_mark_maybe_cb); each_stack_location(objspace, ec, stack_start, stack_end, gc_mark_maybe);
} }
#endif #endif
static void static void
each_machine_stack_value(const rb_execution_context_t *ec, void *ctx, void (*cb)(rb_objspace_t *, void *, VALUE)) each_machine_stack_value(const rb_execution_context_t *ec, void (*cb)(rb_objspace_t *, VALUE))
{ {
rb_objspace_t *objspace = &rb_objspace; rb_objspace_t *objspace = &rb_objspace;
VALUE *stack_start, *stack_end; VALUE *stack_start, *stack_end;
GET_STACK_BOUNDS(stack_start, stack_end, 0); GET_STACK_BOUNDS(stack_start, stack_end, 0);
RUBY_DEBUG_LOG("ec->th:%u stack_start:%p stack_end:%p", rb_ec_thread_ptr(ec)->serial, stack_start, stack_end); RUBY_DEBUG_LOG("ec->th:%u stack_start:%p stack_end:%p", rb_ec_thread_ptr(ec)->serial, stack_start, stack_end);
each_stack_location(objspace, ec, stack_start, stack_end, ctx, cb); each_stack_location(objspace, ec, stack_start, stack_end, cb);
} }
void void
rb_gc_mark_machine_stack(const rb_execution_context_t *ec) rb_gc_mark_machine_stack(const rb_execution_context_t *ec)
{ {
each_machine_stack_value(ec, NULL, gc_mark_maybe_cb); each_machine_stack_value(ec, gc_mark_maybe);
} }
static void static void
each_stack_location(rb_objspace_t *objspace, const rb_execution_context_t *ec, each_stack_location(rb_objspace_t *objspace, const rb_execution_context_t *ec,
const VALUE *stack_start, const VALUE *stack_end, void *ctx, const VALUE *stack_start, const VALUE *stack_end, void (*cb)(rb_objspace_t *, VALUE))
void (*cb)(rb_objspace_t *, void *, VALUE))
{ {
gc_mark_locations(objspace, stack_start, stack_end, ctx, cb); gc_mark_locations(objspace, stack_start, stack_end, cb);
#if defined(__mc68000__) #if defined(__mc68000__)
gc_mark_locations(objspace, gc_mark_locations(objspace,
(VALUE*)((char*)stack_start + 2), (VALUE*)((char*)stack_start + 2),
(VALUE*)((char*)stack_end - 2), ctx, cb); (VALUE*)((char*)stack_end - 2), cb);
#endif #endif
} }