summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-10 08:47:46 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-10 08:47:46 +0000
commitdaadb8bd53c9a0038fe7f51652b72aaa9b93a220 (patch)
treee26b224da6f99cc1806e4288a6a4946f269a9a2e /variable.c
parent34159dac1c819b95d2e6a56f24350a83b8217e54 (diff)
* variable.c (rb_obj_remove_instance_variable): raise NameError if
specified instance variable is not defined. * variable.c (generic_ivar_remove): modified to check ivar existence. * class.c (rb_singleton_class): wrong condition; was creating unnecessary singleton class. * numeric.c (int_step): step may be a float less than 1. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@2349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/variable.c b/variable.c
index a1335eb443..087f5e6cdd 100644
--- a/variable.c
+++ b/variable.c
@@ -254,8 +254,7 @@ rb_autoload_id(id, filename)
{
rb_secure(4);
if (!rb_is_const_id(id)) {
- rb_raise(rb_eNameError, "autoload must be constant name",
- rb_id2name(id));
+ rb_raise(rb_eNameError, "autoload must be constant name");
}
if (!autoload_tbl) {
@@ -812,22 +811,23 @@ generic_ivar_defined(obj, id)
return Qfalse;
}
-static VALUE
-generic_ivar_remove(obj, id)
+static int
+generic_ivar_remove(obj, id, valp)
VALUE obj;
ID id;
+ VALUE *valp;
{
st_table *tbl;
- VALUE val;
+ int status;
- if (!generic_iv_tbl) return Qnil;
- if (!st_lookup(generic_iv_tbl, obj, &tbl)) return Qnil;
- st_delete(tbl, &id, &val);
+ if (!generic_iv_tbl) return 0;
+ if (!st_lookup(generic_iv_tbl, obj, &tbl)) return 0;
+ status = st_delete(tbl, &id, valp);
if (tbl->num_entries == 0) {
st_delete(generic_iv_tbl, &obj, &tbl);
st_free_table(tbl);
}
- return val;
+ return status;
}
void
@@ -1020,16 +1020,20 @@ rb_obj_remove_instance_variable(obj, name)
case T_OBJECT:
case T_CLASS:
case T_MODULE:
- if (ROBJECT(obj)->iv_tbl) {
- st_delete(ROBJECT(obj)->iv_tbl, &id, &val);
+ if (ROBJECT(obj)->iv_tbl && st_delete(ROBJECT(obj)->iv_tbl, &id, &val)) {
+ return val;
}
break;
default:
- if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj))
- return generic_ivar_remove(obj, id);
+ if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj)) {
+ if (generic_ivar_remove(obj, id, &val)) {
+ return val;
+ }
+ }
break;
}
- return val;
+ rb_raise(rb_eNameError, "instance variable %s not defined", rb_id2name(id));
+ return Qnil; /* not reached */
}
static int