Add rb_ec_close function to manage execution context cleanup. (#15253)

This commit is contained in:
Samuel Williams 2025-12-01 17:49:31 +13:00 committed by GitHub
parent 8eea9a5020
commit bc9ea585be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2025-12-01 04:49:59 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
3 changed files with 12 additions and 0 deletions

1
cont.c
View File

@ -2907,6 +2907,7 @@ void
rb_fiber_close(rb_fiber_t *fiber)
{
fiber_status_set(fiber, FIBER_TERMINATED);
rb_ec_close(&fiber->cont.saved_ec);
}
static void

7
vm.c
View File

@ -3890,6 +3890,13 @@ rb_ec_clear_vm_stack(rb_execution_context_t *ec)
rb_ec_set_vm_stack(ec, NULL, 0);
}
void
rb_ec_close(rb_execution_context_t *ec)
{
// Fiber storage is not accessible from outside the running fiber, so it is safe to clear it here.
ec->storage = Qnil;
}
static void
th_init(rb_thread_t *th, VALUE self, rb_vm_t *vm)
{

View File

@ -1104,6 +1104,10 @@ void rb_ec_initialize_vm_stack(rb_execution_context_t *ec, VALUE *stack, size_t
// @param ec the execution context to update.
void rb_ec_clear_vm_stack(rb_execution_context_t *ec);
// Close an execution context and free related resources that are no longer needed.
// @param ec the execution context to close.
void rb_ec_close(rb_execution_context_t *ec);
struct rb_ext_config {
bool ractor_safe;
};