summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-10 08:45:26 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-10 08:45:26 +0000
commit19c42c0740145dec1be93c332647f4310ea19918 (patch)
tree88516eac5daf33e2e935c3d38415e13d542ac131 /variable.c
parentff0abdc55e57f42f75204429c9eca471df48d835 (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. * file.c (rb_file_s_extname): new method based on the proposal (and patch) from Mike Hall. [new] * eval.c (error_handle): default to 1 unless status is set. * eval.c (ruby_options): guard error_handle() with PROT_NONE. * eval.c (ruby_stop): ditto. * math.c (math_acosh): added. [new] * math.c (math_asinh): ditto. * math.c (math_atanh): ditto. * struct.c (rb_struct_each_pair): method added. [new] * class.c (rb_singleton_class): wrong condition; was creating unnecessary singleton class. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/variable.c b/variable.c
index e8b8605..9a25caa 100644
--- a/variable.c
+++ b/variable.c
@@ -259,7 +259,7 @@ rb_autoload_id(id, filename)
{
rb_secure(4);
if (!rb_is_const_id(id)) {
- rb_name_error(id, "autoload must be constant name", rb_id2name(id));
+ rb_name_error(id, "autoload must be constant name");
}
if (!autoload_tbl) {
@@ -845,22 +845,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
@@ -1052,16 +1053,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_name_error(id, "instance variable %s not defined", rb_id2name(id));
+ return Qnil; /* not reached */
}
static int