diff --git a/ChangeLog b/ChangeLog index e8c0fc5fbb..200fffff82 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Mon Jul 19 18:34:12 2010 Tanaka Akira + + * 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 * array.c (rb_ary_clear): should not unshare embedded array, and diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index 54be13868f..56e3a4525f 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -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 diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index d9917058da..cba325b0dc 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -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); }