ruby-changes:16687
From: akr <ko1@a...>
Date: Mon, 19 Jul 2010 18:36:01 +0900 (JST)
Subject: [ruby-changes:16687] Ruby:r28683 (trunk): * ext/pathname/pathname.c (get_strpath): check the type.
akr 2010-07-19 18:35:31 +0900 (Mon, 19 Jul 2010) New Revision: 28683 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28683 Log: * 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. Modified files: trunk/ChangeLog trunk/ext/pathname/lib/pathname.rb trunk/ext/pathname/pathname.c Index: ChangeLog =================================================================== --- ChangeLog (revision 28682) +++ ChangeLog (revision 28683) @@ -1,3 +1,11 @@ +Mon Jul 19 18:34:12 2010 Tanaka Akira <akr@f...> + + * 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@r...> * array.c (rb_ary_clear): should not unshare embedded array, and Index: ext/pathname/lib/pathname.rb =================================================================== --- ext/pathname/lib/pathname.rb (revision 28682) +++ ext/pathname/lib/pathname.rb (revision 28683) @@ -208,7 +208,6 @@ # :startdoc: - def freeze() super; @path.freeze; self end def taint() super; @path.taint; self end def untaint() super; @path.untaint; self end Index: ext/pathname/pathname.c =================================================================== --- ext/pathname/pathname.c (revision 28682) +++ ext/pathname/pathname.c (revision 28683) @@ -6,7 +6,11 @@ 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 @@ 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 @@ 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 @@ 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); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/