summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-21 14:51:21 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-21 14:51:21 +0000
commit9060b3355a9d67e547b71e81a6bb20d7199822f2 (patch)
tree5697cce25a4adc8885b1b96aa9cdcb5354147b4b /object.c
parent07cff4bd71d4d71e4901aac5df11746ce96f009b (diff)
* object.c (str_to_id): check for empty string before intern.
[ruby-talk:74006] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/object.c b/object.c
index 1e7c5c1d45..33502dbc3b 100644
--- a/object.c
+++ b/object.c
@@ -779,6 +779,16 @@ rb_class_superclass(klass)
return super;
}
+static ID
+str_to_id(str)
+ VALUE str;
+{
+ if (!RSTRING(str)->ptr || RSTRING(str)->len == 0) {
+ rb_raise(rb_eArgError, "empty symbol string");
+ }
+ return rb_intern(RSTRING(str)->ptr);
+}
+
ID
rb_to_id(name)
VALUE name;
@@ -788,7 +798,7 @@ rb_to_id(name)
switch (TYPE(name)) {
case T_STRING:
- return rb_str_intern(name);
+ return str_to_id(name);
case T_FIXNUM:
rb_warn("do not use Fixnums as Symbols");
id = FIX2LONG(name);
@@ -802,7 +812,7 @@ rb_to_id(name)
default:
tmp = rb_check_string_type(name);
if (!NIL_P(tmp)) {
- return rb_str_intern(tmp);
+ return str_to_id(tmp);
}
rb_raise(rb_eTypeError, "%s is not a symbol", RSTRING(rb_inspect(name))->ptr);
}