Project

General

Profile

Bug #12095 ยป at_exit_fix.patch

evanphx (Evan Phoenix), 03/15/2016 04:21 PM

View differences:

vm.c
468 468
void
469 469
ruby_vm_at_exit(void (*func)(rb_vm_t *))
470 470
{
471
    rb_ary_push((VALUE)&GET_VM()->at_exit, (VALUE)func);
471
    rb_at_exit_list *nl = (rb_at_exit_list*)xmalloc(sizeof(rb_at_exit_list));
472
    nl->func = func;
473
    nl->next = 0;
474

  
475
    GET_VM()->at_exit_end->next = nl;
476
    GET_VM()->at_exit_end = nl;
472 477
}
473 478

  
474 479
static void
475 480
ruby_vm_run_at_exit_hooks(rb_vm_t *vm)
476 481
{
477
    VALUE hook = (VALUE)&vm->at_exit;
482
    for(rb_at_exit_list *l = &vm->at_exit; l; l = l->next) {
483
	if(l->func) {
484
	    (*l->func)(vm);
485
	}
486
    }
478 487

  
479
    while (RARRAY_LEN(hook) > 0) {
480
	typedef void rb_vm_at_exit_func(rb_vm_t*);
481
	rb_vm_at_exit_func *func = (rb_vm_at_exit_func*)rb_ary_pop(hook);
482
	(*func)(vm);
488
    for(rb_at_exit_list *l = vm->at_exit.next; l;) {
489
	rb_at_exit_list* t = l->next;
490
	free(l);
491
	l = t;
483 492
    }
484
    rb_ary_free(hook);
485 493
}
486 494

  
487 495
/* Env */
......
2170 2178
    MEMZERO(vm, rb_vm_t, 1);
2171 2179
    rb_vm_living_threads_init(vm);
2172 2180
    vm->src_encoding_index = -1;
2173
    vm->at_exit.basic.flags = (T_ARRAY | RARRAY_EMBED_FLAG) & ~RARRAY_EMBED_LEN_MASK; /* len set 0 */
2174
    rb_obj_hide((VALUE)&vm->at_exit);
2181
    vm->at_exit_end = &vm->at_exit;
2175 2182

  
2176 2183
    vm_default_params_setup(vm);
2177 2184
}
vm_core.h
459 459
#define GetVMPtr(obj, ptr) \
460 460
  GetCoreDataFromValue((obj), rb_vm_t, (ptr))
461 461

  
462
struct rb_vm_struct;
463
typedef void rb_vm_at_exit_func(struct rb_vm_struct*);
464

  
465
typedef struct rb_at_exit_list {
466
    rb_vm_at_exit_func *func;
467
    struct rb_at_exit_list *next;
468
} rb_at_exit_list;
469

  
462 470
struct rb_objspace;
463 471
struct rb_objspace *rb_objspace_alloc(void);
464 472
void rb_objspace_free(struct rb_objspace *);
......
527 535

  
528 536
    struct rb_objspace *objspace;
529 537

  
530
    /*
531
     * @shyouhei notes that this is not for storing normal Ruby
532
     * objects so do *NOT* mark this when you GC.
533
     */
534
    struct RArray at_exit;
538
    rb_at_exit_list at_exit;
539
    rb_at_exit_list *at_exit_end;
535 540

  
536 541
    VALUE *defined_strings;
537 542
    st_table *frozen_strings;