Project

General

Profile

Feature #11634 ยป 0001-variable.c-rb_global_tbl-convert-to-id_table.patch

normalperson (Eric Wong), 10/29/2015 08:11 PM

View differences:

variable.c
17 17
#include "constant.h"
18 18
#include "id.h"
19 19
#include "ccan/list/list.h"
20
#include "id_table.h"
20 21

  
21
st_table *rb_global_tbl;
22
struct rb_id_table *rb_global_tbl;
22 23
static ID autoload, classpath, tmp_classpath, classid;
23 24

  
24 25
static void check_before_mod_set(VALUE, ID, VALUE, const char *);
......
45 46
void
46 47
Init_var_tables(void)
47 48
{
48
    rb_global_tbl = st_init_numtable();
49
    rb_global_tbl = rb_id_table_create(0);
49 50
    generic_iv_tbl = st_init_numtable();
50 51
    autoload = rb_intern_const("__autoload__");
51 52
    /* __classpath__: fully qualified class path */
......
500 501
rb_global_entry(ID id)
501 502
{
502 503
    struct global_entry *entry;
503
    st_data_t data;
504
    VALUE data;
504 505

  
505
    if (!st_lookup(rb_global_tbl, (st_data_t)id, &data)) {
506
    if (!rb_id_table_lookup(rb_global_tbl, id, &data)) {
506 507
	struct global_variable *var;
507 508
	entry = ALLOC(struct global_entry);
508 509
	var = ALLOC(struct global_variable);
......
516 517

  
517 518
	var->block_trace = 0;
518 519
	var->trace = 0;
519
	st_add_direct(rb_global_tbl, id, (st_data_t)entry);
520
	rb_id_table_insert(rb_global_tbl, id, (VALUE)entry);
520 521
    }
521 522
    else {
522 523
	entry = (struct global_entry *)data;
......
592 593
    rb_name_error(id, "%"PRIsVALUE" is a read-only variable", QUOTE_ID(id));
593 594
}
594 595

  
595
static int
596
mark_global_entry(st_data_t k, st_data_t v, st_data_t a)
596
static enum rb_id_table_iterator_result
597
mark_global_entry(VALUE v, void *ignored)
597 598
{
598 599
    struct global_entry *entry = (struct global_entry *)v;
599 600
    struct trace_var *trace;
......
605 606
	if (trace->data) rb_gc_mark_maybe(trace->data);
606 607
	trace = trace->next;
607 608
    }
608
    return ST_CONTINUE;
609
    return ID_TABLE_CONTINUE;
609 610
}
610 611

  
611 612
void
612 613
rb_gc_mark_global_tbl(void)
613 614
{
614 615
    if (rb_global_tbl)
615
        st_foreach_safe(rb_global_tbl, mark_global_entry, 0);
616
        rb_id_table_foreach_values(rb_global_tbl, mark_global_entry, 0);
616 617
}
617 618

  
618 619
static ID
......
768 769
    ID id;
769 770
    struct global_entry *entry;
770 771
    struct trace_var *trace;
771
    st_data_t data;
772
    VALUE data;
772 773

  
773 774
    rb_scan_args(argc, argv, "11", &var, &cmd);
774 775
    id = rb_check_id(&var);
775 776
    if (!id) {
776 777
	rb_name_error_str(var, "undefined global variable %"PRIsVALUE"", QUOTE(var));
777 778
    }
778
    if (!st_lookup(rb_global_tbl, (st_data_t)id, &data)) {
779
    if (!rb_id_table_lookup(rb_global_tbl, id, &data)) {
779 780
	rb_name_error(id, "undefined global variable %"PRIsVALUE"", QUOTE_ID(id));
780 781
    }
781 782

  
......
881 882
    return Qtrue;
882 883
}
883 884

  
884
static int
885
gvar_i(st_data_t k, st_data_t v, st_data_t a)
885
static enum rb_id_table_iterator_result
886
gvar_i(ID key, VALUE val, void *a)
886 887
{
887
    ID key = (ID)k;
888 888
    VALUE ary = (VALUE)a;
889 889
    rb_ary_push(ary, ID2SYM(key));
890
    return ST_CONTINUE;
890
    return ID_TABLE_CONTINUE;
891 891
}
892 892

  
893 893
/*
......
906 906
    char buf[2];
907 907
    int i;
908 908

  
909
    st_foreach_safe(rb_global_tbl, gvar_i, ary);
909
    rb_id_table_foreach(rb_global_tbl, gvar_i, (void *)ary);
910 910
    buf[0] = '$';
911 911
    for (i = 1; i <= 9; ++i) {
912 912
	buf[1] = (char)(i + '0');
......
919 919
rb_alias_variable(ID name1, ID name2)
920 920
{
921 921
    struct global_entry *entry1, *entry2;
922
    st_data_t data1;
922
    VALUE data1;
923 923

  
924 924
    entry2 = rb_global_entry(name2);
925
    if (!st_lookup(rb_global_tbl, (st_data_t)name1, &data1)) {
925
    if (!rb_id_table_lookup(rb_global_tbl, name1, &data1)) {
926 926
	entry1 = ALLOC(struct global_entry);
927 927
	entry1->id = name1;
928
	st_add_direct(rb_global_tbl, name1, (st_data_t)entry1);
928
	rb_id_table_insert(rb_global_tbl, name1, (VALUE)entry1);
929 929
    }
930 930
    else if ((entry1 = (struct global_entry *)data1)->var != entry2->var) {
931 931
	struct global_variable *var = entry1->var;
932
-