ruby-changes:8183
From: nobu <ko1@a...>
Date: Wed, 8 Oct 2008 11:23:15 +0900 (JST)
Subject: [ruby-changes:8183] Ruby:r19711 (trunk, ruby_1_8): * variable.c (classname, rb_obj_remove_instance_variable),
nobu 2008-10-08 11:23:04 +0900 (Wed, 08 Oct 2008) New Revision: 19711 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19711 Log: * variable.c (classname, rb_obj_remove_instance_variable), (autoload_delete, autoload_file, rb_mod_remove_const), (rb_mod_remove_cvar): fixed type-punned pointer casts. Modified files: branches/ruby_1_8/variable.c trunk/variable.c Index: variable.c =================================================================== --- variable.c (revision 19710) +++ variable.c (revision 19711) @@ -143,6 +143,7 @@ if (RCLASS_IV_TBL(klass)) { if (!st_lookup(RCLASS_IV_TBL(klass), classpath, &path)) { ID classid; + st_data_t n; CONST_ID(classid, "__classid__"); @@ -152,7 +153,8 @@ path = rb_str_dup(rb_id2str(SYM2ID(path))); OBJ_FREEZE(path); st_insert(RCLASS_IV_TBL(klass), classpath, path); - st_delete(RCLASS_IV_TBL(klass), (st_data_t*)&classid, 0); + n = classid; + st_delete(RCLASS_IV_TBL(klass), &n, 0); } if (TYPE(path) != T_STRING) { rb_bug("class path is not set properly"); @@ -1220,7 +1222,8 @@ rb_obj_remove_instance_variable(VALUE obj, VALUE name) { VALUE val = Qnil; - ID id = rb_to_id(name); + const ID id = rb_to_id(name); + st_data_t n, v; struct st_table *iv_index_tbl; st_data_t index; @@ -1245,8 +1248,9 @@ break; case T_CLASS: case T_MODULE: - if (RCLASS_IV_TBL(obj) && st_delete(RCLASS_IV_TBL(obj), (st_data_t*)&id, &val)) { - return val; + n = id; + if (RCLASS_IV_TBL(obj) && st_delete(RCLASS_IV_TBL(obj), &n, &v)) { + return (VALUE)v; } break; default: @@ -1364,18 +1368,17 @@ static NODE* autoload_delete(VALUE mod, ID id) { - VALUE val; - st_data_t load = 0; + st_data_t val, load = 0, n = id; - st_delete(RCLASS_IV_TBL(mod), (st_data_t*)&id, 0); + st_delete(RCLASS_IV_TBL(mod), &n, 0); if (st_lookup(RCLASS_IV_TBL(mod), autoload, &val)) { - struct st_table *tbl = check_autoload_table(val); + struct st_table *tbl = check_autoload_table((VALUE)val); - st_delete(tbl, (st_data_t*)&id, &load); + st_delete(tbl, &n, &load); if (tbl->num_entries == 0) { - id = autoload; - st_delete(RCLASS_IV_TBL(mod), (st_data_t*)&id, &val); + n = autoload; + st_delete(RCLASS_IV_TBL(mod), &n, &val); } } @@ -1397,12 +1400,12 @@ static VALUE autoload_file(VALUE mod, ID id) { - VALUE val, file; + VALUE file; struct st_table *tbl; - st_data_t load; + st_data_t val, load, n = id; if (!st_lookup(RCLASS_IV_TBL(mod), autoload, &val) || - !(tbl = check_autoload_table(val)) || !st_lookup(tbl, id, &load)) { + !(tbl = check_autoload_table((VALUE)val)) || !st_lookup(tbl, n, &load)) { return Qnil; } file = ((NODE *)load)->nd_lit; @@ -1415,10 +1418,10 @@ } /* already loaded but not defined */ - st_delete(tbl, (st_data_t*)&id, 0); + st_delete(tbl, &n, 0); if (!tbl->num_entries) { - id = autoload; - st_delete(RCLASS_IV_TBL(mod), (st_data_t*)&id, &val); + n = autoload; + st_delete(RCLASS_IV_TBL(mod), &n, &val); } return Qnil; } @@ -1497,8 +1500,9 @@ VALUE rb_mod_remove_const(VALUE mod, VALUE name) { - ID id = rb_to_id(name); + const ID id = rb_to_id(name); VALUE val; + st_data_t v, n = id; rb_vm_change_state(); @@ -1509,7 +1513,8 @@ rb_raise(rb_eSecurityError, "Insecure: can't remove constant"); if (OBJ_FROZEN(mod)) rb_error_frozen("class/module"); - if (RCLASS_IV_TBL(mod) && st_delete(RCLASS_IV_TBL(mod), (st_data_t*)&id, &val)) { + if (RCLASS_IV_TBL(mod) && st_delete(RCLASS_IV_TBL(mod), &n, &v)) { + val = (VALUE)v; if (val == Qundef) { autoload_delete(mod, id); val = Qnil; @@ -1916,8 +1921,8 @@ VALUE rb_mod_remove_cvar(VALUE mod, VALUE name) { - ID id = rb_to_id(name); - VALUE val; + const ID id = rb_to_id(name); + st_data_t val, n; if (!rb_is_class_id(id)) { rb_name_error(id, "wrong class variable name %s", rb_id2name(id)); @@ -1926,8 +1931,8 @@ rb_raise(rb_eSecurityError, "Insecure: can't remove class variable"); if (OBJ_FROZEN(mod)) rb_error_frozen("class/module"); - if (RCLASS_IV_TBL(mod) && st_delete(RCLASS_IV_TBL(mod), (st_data_t*)&id, &val)) { - return val; + if (RCLASS_IV_TBL(mod) && st_delete(RCLASS_IV_TBL(mod), &n, &val)) { + return (VALUE)val; } if (rb_cvar_defined(mod, id)) { rb_name_error(id, "cannot remove %s for %s", Index: ruby_1_8/variable.c =================================================================== --- ruby_1_8/variable.c (revision 19710) +++ ruby_1_8/variable.c (revision 19711) @@ -149,14 +149,16 @@ if (!klass) klass = rb_cObject; if (ROBJECT(klass)->iv_tbl) { if (!st_lookup(ROBJECT(klass)->iv_tbl, classpath, &path)) { - ID classid = rb_intern("__classid__"); + const ID classid = rb_intern("__classid__"); + st_data_t n; if (!st_lookup(ROBJECT(klass)->iv_tbl, classid, &path)) { return find_class_path(klass); } path = rb_str_new2(rb_id2name(SYM2ID(path))); st_insert(ROBJECT(klass)->iv_tbl, classpath, path); - st_delete(RCLASS(klass)->iv_tbl, (st_data_t*)&classid, 0); + n = classid; + st_delete(RCLASS(klass)->iv_tbl, &n, 0); } if (TYPE(path) != T_STRING) { rb_bug("class path is not set properly"); @@ -1186,7 +1188,8 @@ VALUE obj, name; { VALUE val = Qnil; - ID id = rb_to_id(name); + const ID id = rb_to_id(name); + st_data_t n = id; if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4) rb_raise(rb_eSecurityError, "Insecure: can't modify instance variable"); @@ -1199,7 +1202,7 @@ case T_OBJECT: case T_CLASS: case T_MODULE: - if (ROBJECT(obj)->iv_tbl && st_delete(ROBJECT(obj)->iv_tbl, (st_data_t*)&id, &val)) { + if (ROBJECT(obj)->iv_tbl && st_delete(ROBJECT(obj)->iv_tbl, &n, &val)) { return val; } break; @@ -1328,18 +1331,16 @@ VALUE mod; ID id; { - VALUE val; - st_data_t load = 0; + st_data_t val, load = 0, n = id; - st_delete(RCLASS(mod)->iv_tbl, (st_data_t*)&id, 0); + st_delete(RCLASS(mod)->iv_tbl, &n, 0); if (st_lookup(RCLASS(mod)->iv_tbl, autoload, &val)) { - struct st_table *tbl = check_autoload_table(val); + struct st_table *tbl = check_autoload_table((VALUE)val); - st_delete(tbl, (st_data_t*)&id, &load); - + st_delete(tbl, &n, &load); if (tbl->num_entries == 0) { - id = autoload; - st_delete(RCLASS(mod)->iv_tbl, (st_data_t*)&id, &val); + n = autoload; + st_delete(RCLASS(mod)->iv_tbl, &n, &val); } } @@ -1365,12 +1366,12 @@ VALUE mod; ID id; { - VALUE val, file; + VALUE file; struct st_table *tbl; - st_data_t load; + st_data_t val, load, n = id; if (!st_lookup(RCLASS(mod)->iv_tbl, autoload, &val) || - !(tbl = check_autoload_table(val)) || !st_lookup(tbl, id, &load)) { + !(tbl = check_autoload_table((VALUE)val)) || !st_lookup(tbl, n, &load)) { return Qnil; } file = ((NODE *)load)->nd_lit; @@ -1383,10 +1384,10 @@ } /* already loaded but not defined */ - st_delete(tbl, (st_data_t*)&id, 0); + st_delete(tbl, &n, 0); if (!tbl->num_entries) { - id = autoload; - st_delete(RCLASS(mod)->iv_tbl, (st_data_t*)&id, &val); + n = autoload; + st_delete(RCLASS(mod)->iv_tbl, &n, &val); } return Qnil; } @@ -1477,8 +1478,9 @@ rb_mod_remove_const(mod, name) VALUE mod, name; { - ID id = rb_to_id(name); + const ID id = rb_to_id(name); VALUE val; + st_data_t v, n = id; if (!rb_is_const_id(id)) { rb_name_error(id, "`%s' is not allowed as a constant name", rb_id2name(id)); @@ -1487,7 +1489,8 @@ rb_raise(rb_eSecurityError, "Insecure: can't remove constant"); if (OBJ_FROZEN(mod)) rb_error_frozen("class/module"); - if (RCLASS(mod)->iv_tbl && st_delete(ROBJECT(mod)->iv_tbl, (st_data_t*)&id, &val)) { + if (RCLASS(mod)->iv_tbl && st_delete(ROBJECT(mod)->iv_tbl, &n, &v)) { + val = (VALUE)v; if (val == Qundef) { autoload_delete(mod, id); val = Qnil; @@ -1927,8 +1930,8 @@ rb_mod_remove_cvar(mod, name) VALUE mod, name; { - ID id = rb_to_id(name); - VALUE val; + const ID id = rb_to_id(name); + st_data_t val, n; if (!rb_is_class_id(id)) { rb_name_error(id, "wrong class variable name %s", rb_id2name(id)); @@ -1937,8 +1940,8 @@ rb_raise(rb_eSecurityError, "Insecure: can't remove class variable"); if (OBJ_FROZEN(mod)) rb_error_frozen("class/module"); - if (RCLASS(mod)->iv_tbl && st_delete(ROBJECT(mod)->iv_tbl, (st_data_t*)&id, &val)) { - return val; + if (RCLASS(mod)->iv_tbl && st_delete(ROBJECT(mod)->iv_tbl, &n, &val)) { + return (VALUE)val; } if (rb_cvar_defined(mod, id)) { rb_name_error(id, "cannot remove %s for %s", -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/