Project

General

Profile

Bug #12095 » at_exit_fix.patch

evanphx (Evan Phoenix), 03/15/2016 02:47 AM

View differences:

vm.c
void
ruby_vm_at_exit(void (*func)(rb_vm_t *))
{
rb_ary_push((VALUE)&GET_VM()->at_exit, (VALUE)func);
rb_at_exit_list *nl = (rb_at_exit_list*)xmalloc(sizeof(rb_at_exit_list));
nl->func = func;
nl->next = 0;
GET_VM()->at_exit_end->next = nl;
GET_VM()->at_exit_end = nl;
}
static void
ruby_vm_run_at_exit_hooks(rb_vm_t *vm)
{
VALUE hook = (VALUE)&vm->at_exit;
while (RARRAY_LEN(hook) > 0) {
typedef void rb_vm_at_exit_func(rb_vm_t*);
rb_vm_at_exit_func *func = (rb_vm_at_exit_func*)rb_ary_pop(hook);
(*func)(vm);
for(rb_at_exit_list *l = &GET_VM()->at_exit; l; l = l->next) {
if(l->func) {
(*l->func)(vm);
}
}
rb_ary_free(hook);
}
/* Env */
......
MEMZERO(vm, rb_vm_t, 1);
rb_vm_living_threads_init(vm);
vm->src_encoding_index = -1;
vm->at_exit.basic.flags = (T_ARRAY | RARRAY_EMBED_FLAG) & ~RARRAY_EMBED_LEN_MASK; /* len set 0 */
rb_obj_hide((VALUE)&vm->at_exit);
vm->at_exit_end = &vm->at_exit;
vm_default_params_setup(vm);
}
vm_core.h
#define GetVMPtr(obj, ptr) \
GetCoreDataFromValue((obj), rb_vm_t, (ptr))
typedef struct rb_vm_struct rb_vm_t;
typedef void rb_vm_at_exit_func(rb_vm_t*);
typedef struct rb_at_exit_list {
rb_vm_at_exit_func *func;
struct rb_at_exit_list *next;
} rb_at_exit_list;
struct rb_objspace;
struct rb_objspace *rb_objspace_alloc(void);
void rb_objspace_free(struct rb_objspace *);
......
struct rb_objspace *objspace;
/*
* @shyouhei notes that this is not for storing normal Ruby
* objects so do *NOT* mark this when you GC.
*/
struct RArray at_exit;
rb_at_exit_list at_exit;
rb_at_exit_list *at_exit_end;
VALUE *defined_strings;
st_table *frozen_strings;
(1-1/2)