Skip to content

Commit d410639

Browse files
committed
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer), (run_final), hash.c (rb_hash_aref, rb_hash_lookup2), (rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i), iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink), thread.c (rb_thread_local_aref), variable.c (generic_ivar_remove, ivar_get, rb_const_get_0), (rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method), vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method), ext/iconv/iconv.c (map_charset): use st_data_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 17c48be commit d410639

13 files changed

+73
-40
lines changed

ChangeLog

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
Tue Oct 12 23:35:37 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
1+
Tue Oct 12 23:47:18 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
4+
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
5+
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
6+
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
7+
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
8+
thread.c (rb_thread_local_aref),
9+
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
10+
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
11+
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
12+
ext/iconv/iconv.c (map_charset): use st_data_t.
213

314
* compile.c (iseq_build_body), insns.def (getglobal, setglobal),
415
iseq.c (iseq_load, iseq_data_to_ary), util.c (valid_filename):

compile.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -5257,11 +5257,11 @@ iseq_build_body(rb_iseq_t *iseq, LINK_ANCHOR *anchor,
52575257
else if (TYPE(obj) == T_ARRAY) {
52585258
VALUE *argv = 0;
52595259
int argc = RARRAY_LENINT(obj) - 1;
5260-
VALUE insn_id;
5260+
st_data_t insn_id;
52615261
VALUE insn;
52625262

52635263
insn = (argc < 0) ? Qnil : RARRAY_PTR(obj)[0];
5264-
if (st_lookup(insn_table, insn, &insn_id) == 0) {
5264+
if (st_lookup(insn_table, (st_data_t)insn, &insn_id) == 0) {
52655265
/* TODO: exception */
52665266
RB_GC_GUARD(insn) = rb_inspect(insn);
52675267
rb_compile_error(RSTRING_PTR(iseq->filename), line_no,

error.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ static st_table *syserr_tbl;
980980
static VALUE
981981
set_syserr(int n, const char *name)
982982
{
983-
VALUE error;
983+
st_data_t error;
984984

985985
if (!st_lookup(syserr_tbl, n, &error)) {
986986
error = rb_define_class_under(rb_mErrno, name, rb_eSystemCallError);
@@ -996,7 +996,7 @@ set_syserr(int n, const char *name)
996996
static VALUE
997997
get_syserr(int n)
998998
{
999-
VALUE error;
999+
st_data_t error;
10001000

10011001
if (!st_lookup(syserr_tbl, n, &error)) {
10021002
char name[8]; /* some Windows' errno have 5 digits. */
@@ -1029,11 +1029,13 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
10291029
VALUE klass = rb_obj_class(self);
10301030

10311031
if (klass == rb_eSystemCallError) {
1032+
st_data_t data = (st_data_t)klass;
10321033
rb_scan_args(argc, argv, "11", &mesg, &error);
10331034
if (argc == 1 && FIXNUM_P(mesg)) {
10341035
error = mesg; mesg = Qnil;
10351036
}
1036-
if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &klass)) {
1037+
if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &data)) {
1038+
klass = (VALUE)data;
10371039
/* change class */
10381040
if (TYPE(self) != T_OBJECT) { /* insurance to avoid type crash */
10391041
rb_raise(rb_eTypeError, "invalid instance type");

ext/iconv/iconv.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@ map_charset(VALUE *code)
164164
VALUE val = StringValue(*code);
165165

166166
if (RHASH_SIZE(charset_map)) {
167+
st_data_t data;
167168
VALUE key = rb_funcall2(val, rb_intern("downcase"), 0, 0);
168169
StringValuePtr(key);
169-
if (st_lookup(RHASH_TBL(charset_map), key, &val)) {
170-
*code = val;
170+
if (st_lookup(RHASH_TBL(charset_map), key, &data)) {
171+
*code = (VALUE)data;
171172
}
172173
}
173174
return StringValuePtr(*code);

gc.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -2699,6 +2699,7 @@ define_final(int argc, VALUE *argv, VALUE os)
26992699
{
27002700
rb_objspace_t *objspace = &rb_objspace;
27012701
VALUE obj, block, table;
2702+
st_data_t data;
27022703

27032704
rb_scan_args(argc, argv, "11", &obj, &block);
27042705
if (OBJ_FROZEN(obj)) rb_error_frozen("object");
@@ -2721,7 +2722,8 @@ define_final(int argc, VALUE *argv, VALUE os)
27212722
if (!finalizer_table) {
27222723
finalizer_table = st_init_numtable();
27232724
}
2724-
if (st_lookup(finalizer_table, obj, &table)) {
2725+
if (st_lookup(finalizer_table, obj, &data)) {
2726+
table = (VALUE)data;
27252727
rb_ary_push(table, block);
27262728
}
27272729
else {
@@ -2737,10 +2739,12 @@ rb_gc_copy_finalizer(VALUE dest, VALUE obj)
27372739
{
27382740
rb_objspace_t *objspace = &rb_objspace;
27392741
VALUE table;
2742+
st_data_t data;
27402743

27412744
if (!finalizer_table) return;
27422745
if (!FL_TEST(obj, FL_FINALIZE)) return;
2743-
if (st_lookup(finalizer_table, obj, &table)) {
2746+
if (st_lookup(finalizer_table, obj, &data)) {
2747+
table = (VALUE)data;
27442748
st_insert(finalizer_table, dest, table);
27452749
}
27462750
FL_SET(dest, FL_FINALIZE);
@@ -2777,8 +2781,9 @@ run_finalizer(rb_objspace_t *objspace, VALUE obj, VALUE objid, VALUE table)
27772781
static void
27782782
run_final(rb_objspace_t *objspace, VALUE obj)
27792783
{
2780-
VALUE table, objid;
2784+
VALUE objid;
27812785
RUBY_DATA_FUNC free_func = 0;
2786+
st_data_t key, table;
27822787

27832788
objid = rb_obj_id(obj); /* make obj into id */
27842789
RBASIC(obj)->klass = 0;
@@ -2793,9 +2798,10 @@ run_final(rb_objspace_t *objspace, VALUE obj)
27932798
(*free_func)(DATA_PTR(obj));
27942799
}
27952800

2801+
key = (st_data_t)obj;
27962802
if (finalizer_table &&
2797-
st_delete(finalizer_table, (st_data_t*)&obj, &table)) {
2798-
run_finalizer(objspace, obj, objid, table);
2803+
st_delete(finalizer_table, &key, &table)) {
2804+
run_finalizer(objspace, obj, objid, (VALUE)table);
27992805
}
28002806
}
28012807

hash.c

+15-9
Original file line numberDiff line numberDiff line change
@@ -506,23 +506,23 @@ rb_hash_rehash(VALUE hash)
506506
VALUE
507507
rb_hash_aref(VALUE hash, VALUE key)
508508
{
509-
VALUE val;
509+
st_data_t val;
510510

511511
if (!RHASH(hash)->ntbl || !st_lookup(RHASH(hash)->ntbl, key, &val)) {
512512
return rb_funcall(hash, id_default, 1, key);
513513
}
514-
return val;
514+
return (VALUE)val;
515515
}
516516

517517
VALUE
518518
rb_hash_lookup2(VALUE hash, VALUE key, VALUE def)
519519
{
520-
VALUE val;
520+
st_data_t val;
521521

522522
if (!RHASH(hash)->ntbl || !st_lookup(RHASH(hash)->ntbl, key, &val)) {
523523
return def; /* without Hash#default */
524524
}
525-
return val;
525+
return (VALUE)val;
526526
}
527527

528528
VALUE
@@ -564,7 +564,7 @@ static VALUE
564564
rb_hash_fetch_m(int argc, VALUE *argv, VALUE hash)
565565
{
566566
VALUE key, if_none;
567-
VALUE val;
567+
st_data_t val;
568568
long block_given;
569569

570570
rb_scan_args(argc, argv, "11", &key, &if_none);
@@ -584,7 +584,7 @@ rb_hash_fetch_m(int argc, VALUE *argv, VALUE hash)
584584
}
585585
return if_none;
586586
}
587-
return val;
587+
return (VALUE)val;
588588
}
589589

590590
VALUE
@@ -1094,6 +1094,12 @@ rb_hash_clear(VALUE hash)
10941094
return hash;
10951095
}
10961096

1097+
static st_data_t
1098+
copy_str_key(st_data_t str)
1099+
{
1100+
return (st_data_t)rb_str_new4((VALUE)str);
1101+
}
1102+
10971103
/*
10981104
* call-seq:
10991105
* hsh[key] = value -> value
@@ -1121,7 +1127,7 @@ rb_hash_aset(VALUE hash, VALUE key, VALUE val)
11211127
st_insert(RHASH(hash)->ntbl, key, val);
11221128
}
11231129
else {
1124-
st_insert2(RHASH(hash)->ntbl, key, val, rb_str_new4);
1130+
st_insert2(RHASH(hash)->ntbl, key, val, copy_str_key);
11251131
}
11261132
return val;
11271133
}
@@ -1548,14 +1554,14 @@ static int
15481554
eql_i(VALUE key, VALUE val1, VALUE arg)
15491555
{
15501556
struct equal_data *data = (struct equal_data *)arg;
1551-
VALUE val2;
1557+
st_data_t val2;
15521558

15531559
if (key == Qundef) return ST_CONTINUE;
15541560
if (!st_lookup(data->tbl, key, &val2)) {
15551561
data->result = Qfalse;
15561562
return ST_STOP;
15571563
}
1558-
if (!(data->eql ? rb_eql(val1, val2) : (int)rb_equal(val1, val2))) {
1564+
if (!(data->eql ? rb_eql(val1, (VALUE)val2) : (int)rb_equal(val1, (VALUE)val2))) {
15591565
data->result = Qfalse;
15601566
return ST_STOP;
15611567
}

iseq.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
446446
VALUE name, filename, filepath, line_no;
447447
VALUE type, body, locals, args, exception;
448448

449-
VALUE iseq_type;
449+
st_data_t iseq_type;
450450
struct st_table *type_map = 0;
451451
rb_iseq_t *iseq;
452452
rb_compile_option_t option;
@@ -1304,7 +1304,7 @@ iseq_data_to_ary(rb_iseq_t *iseq)
13041304

13051305
for (i=0, pos=0; i<RARRAY_LEN(nbody); i++) {
13061306
VALUE ary = RARRAY_PTR(nbody)[i];
1307-
VALUE label;
1307+
st_data_t label;
13081308

13091309
if (st_lookup(labels_table, pos, &label)) {
13101310
rb_ary_push(body, (VALUE)label);

marshal.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1137,11 +1137,11 @@ id2encidx(ID id, VALUE val)
11371137
static ID
11381138
r_symlink(struct load_arg *arg)
11391139
{
1140-
ID id;
1140+
st_data_t id;
11411141
long num = r_long(arg);
11421142

11431143
if (st_lookup(arg->symbols, num, &id)) {
1144-
return id;
1144+
return (ID)id;
11451145
}
11461146
rb_raise(rb_eArgError, "bad symbol");
11471147
}

thread.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,7 @@ VALUE
19861986
rb_thread_local_aref(VALUE thread, ID id)
19871987
{
19881988
rb_thread_t *th;
1989-
VALUE val;
1989+
st_data_t val;
19901990

19911991
GetThreadPtr(thread, th);
19921992
if (rb_safe_level() >= 4 && th != GET_THREAD()) {
@@ -1996,7 +1996,7 @@ rb_thread_local_aref(VALUE thread, ID id)
19961996
return Qnil;
19971997
}
19981998
if (st_lookup(th->local_storage, id, &val)) {
1999-
return val;
1999+
return (VALUE)val;
20002000
}
20012001
return Qnil;
20022002
}

variable.c

+12-8
Original file line numberDiff line numberDiff line change
@@ -885,15 +885,16 @@ static int
885885
generic_ivar_remove(VALUE obj, ID id, st_data_t *valp)
886886
{
887887
st_table *tbl;
888-
st_data_t data;
888+
st_data_t data, key = (st_data_t)id;
889889
int status;
890890

891891
if (!generic_iv_tbl) return 0;
892892
if (!st_lookup(generic_iv_tbl, (st_data_t)obj, &data)) return 0;
893893
tbl = (st_table *)data;
894-
status = st_delete(tbl, &id, valp);
894+
status = st_delete(tbl, &key, valp);
895895
if (tbl->num_entries == 0) {
896-
st_delete(generic_iv_tbl, &obj, &data);
896+
key = (st_data_t)obj;
897+
st_delete(generic_iv_tbl, &key, &data);
897898
st_free_table((st_table *)data);
898899
}
899900
return status;
@@ -1006,8 +1007,8 @@ ivar_get(VALUE obj, ID id, int warn)
10061007
break;
10071008
case T_CLASS:
10081009
case T_MODULE:
1009-
if (RCLASS_IV_TBL(obj) && st_lookup(RCLASS_IV_TBL(obj), (st_data_t)id, &val))
1010-
return val;
1010+
if (RCLASS_IV_TBL(obj) && st_lookup(RCLASS_IV_TBL(obj), (st_data_t)id, &index))
1011+
return (VALUE)index;
10111012
break;
10121013
default:
10131014
if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj))
@@ -1575,7 +1576,9 @@ rb_const_get_0(VALUE klass, ID id, int exclude, int recurse)
15751576
retry:
15761577
while (RTEST(tmp)) {
15771578
VALUE am = 0;
1578-
while (RCLASS_IV_TBL(tmp) && st_lookup(RCLASS_IV_TBL(tmp), (st_data_t)id, &value)) {
1579+
st_data_t data;
1580+
while (RCLASS_IV_TBL(tmp) && st_lookup(RCLASS_IV_TBL(tmp), (st_data_t)id, &data)) {
1581+
value = (VALUE)data;
15791582
if (value == Qundef) {
15801583
if (am == tmp) break;
15811584
am = tmp;
@@ -1937,7 +1940,8 @@ rb_cvar_set(VALUE klass, ID id, VALUE val)
19371940
VALUE
19381941
rb_cvar_get(VALUE klass, ID id)
19391942
{
1940-
VALUE value, tmp, front = 0, target = 0;
1943+
VALUE tmp, front = 0, target = 0;
1944+
st_data_t value;
19411945

19421946
tmp = klass;
19431947
CVAR_LOOKUP(&value, {if (!front) front = klass; target = klass;});
@@ -1957,7 +1961,7 @@ rb_cvar_get(VALUE klass, ID id)
19571961
st_delete(RCLASS_IV_TBL(front),&did,0);
19581962
}
19591963
}
1960-
return value;
1964+
return (VALUE)value;
19611965
}
19621966

19631967
VALUE

vm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ static st_table *vm_opt_method_table = 0;
948948
static void
949949
rb_vm_check_redefinition_opt_method(const rb_method_entry_t *me)
950950
{
951-
VALUE bop;
951+
st_data_t bop;
952952
if (!me->def || me->def->type == VM_METHOD_TYPE_CFUNC) {
953953
if (st_lookup(vm_opt_method_table, (st_data_t)me, &bop)) {
954954
ruby_vm_redefined_flag[bop] = 1;

vm_insnhelper.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1167,9 +1167,11 @@ vm_get_ev_const(rb_thread_t *th, const rb_iseq_t *iseq,
11671167

11681168
if (!NIL_P(klass)) {
11691169
VALUE am = 0;
1170+
st_data_t data;
11701171
search_continue:
11711172
if (RCLASS_IV_TBL(klass) &&
1172-
st_lookup(RCLASS_IV_TBL(klass), id, &val)) {
1173+
st_lookup(RCLASS_IV_TBL(klass), id, &data)) {
1174+
val = (st_data_t)data;
11731175
if (val == Qundef) {
11741176
if (am == klass) break;
11751177
am = klass;

vm_method.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ rb_method_entry(VALUE klass, ID id)
454454
static void
455455
remove_method(VALUE klass, ID mid)
456456
{
457-
st_data_t data;
457+
st_data_t key, data;
458458
rb_method_entry_t *me = 0;
459459

460460
if (klass == rb_cObject) {
@@ -475,7 +475,8 @@ remove_method(VALUE klass, ID mid)
475475
rb_name_error(mid, "method `%s' not defined in %s",
476476
rb_id2name(mid), rb_class2name(klass));
477477
}
478-
st_delete(RCLASS_M_TBL(klass), &mid, &data);
478+
key = (st_data_t)mid;
479+
st_delete(RCLASS_M_TBL(klass), &key, &data);
479480

480481
rb_vm_check_redefinition_opt_method(me);
481482
rb_clear_cache_for_undef(klass, mid);

0 commit comments

Comments
 (0)