aboutsummaryrefslogtreecommitdiffstats
path: root/ext/pathname
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-19 09:35:31 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-19 09:35:31 +0000
commita0d5258df027dd309f4208cdff89084eb24b904f (patch)
tree20e0fcdb809095e6a76d19eb4b88227fd3922bd5 /ext/pathname
parent79dfc605ff239213cc67d9e5429669764f52a0c7 (diff)
downloadruby-a0d5258df027dd309f4208cdff89084eb24b904f.tar.gz
* 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
Diffstat (limited to 'ext/pathname')
-rw-r--r--ext/pathname/lib/pathname.rb1
-rw-r--r--ext/pathname/pathname.c26
2 files changed, 22 insertions, 5 deletions
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);
}