* ext/pathname/pathname.c (get_strpath): check the type.

(path_initialize): bypass to_path call for T_STRING.
  (path_freeze): implemented.

* ext/pathname/lib/pathname.rb (Pathname#freeze): removed.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2010-07-19 09:35:31 +00:00
Родитель 79dfc605ff
Коммит a0d5258df0
3 изменённых файлов: 30 добавлений и 5 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Mon Jul 19 18:34:12 2010 Tanaka Akira <akr@fsij.org>
* ext/pathname/pathname.c (get_strpath): check the type.
(path_initialize): bypass to_path call for T_STRING.
(path_freeze): implemented.
* ext/pathname/lib/pathname.rb (Pathname#freeze): removed.
Mon Jul 19 12:33:29 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (rb_ary_clear): should not unshare embedded array, and

Просмотреть файл

@ -208,7 +208,6 @@ class Pathname
# :startdoc:
def freeze() super; @path.freeze; self end
def taint() super; @path.taint; self end
def untaint() super; @path.untaint; self end

Просмотреть файл

@ -6,7 +6,11 @@ static ID id_at_path, id_to_path;
static VALUE
get_strpath(VALUE obj)
{
return rb_ivar_get(obj, id_at_path);
VALUE strpath;
strpath = rb_ivar_get(obj, id_at_path);
if (TYPE(strpath) != T_STRING)
rb_raise(rb_eTypeError, "unexpected @path");
return strpath;
}
static void
@ -23,10 +27,15 @@ static VALUE
path_initialize(VALUE self, VALUE arg)
{
VALUE str;
str = rb_check_funcall(arg, id_to_path, 0, NULL);
if (str == Qundef)
if (TYPE(arg) == T_STRING) {
str = arg;
StringValue(str);
}
else {
str = rb_check_funcall(arg, id_to_path, 0, NULL);
if (str == Qundef)
str = arg;
StringValue(str);
}
if (memchr(RSTRING_PTR(str), '\0', RSTRING_LEN(str)))
rb_raise(rb_eArgError, "pathname contains null byte");
str = rb_obj_dup(str);
@ -36,6 +45,14 @@ path_initialize(VALUE self, VALUE arg)
return self;
}
static VALUE
path_freeze(VALUE self)
{
rb_call_super(0, 0);
rb_str_freeze(get_strpath(self));
return self;
}
void
Init_pathname()
{
@ -44,4 +61,5 @@ Init_pathname()
rb_cPathname = rb_define_class("Pathname", rb_cObject);
rb_define_method(rb_cPathname, "initialize", path_initialize, 1);
rb_define_method(rb_cPathname, "freeze", path_freeze, 0);
}