1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2003-06-21 14:51:21 +00:00
parent 07cff4bd71
commit 9060b3355a
2 changed files with 15 additions and 5 deletions

View file

@ -1,7 +1,7 @@
Sat Jun 21 21:27:18 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
Sat Jun 21 23:15:08 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (rb_to_id): use rb_str_intern() instead of rb_intern()
directly, for sanity check.
* object.c (str_to_id): check for empty string before intern.
[ruby-talk:74006]
Sat Jun 21 13:56:09 2003 Takaaki Uematsu <uema2x@jcom.home.ne.jp>

View file

@ -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);
}