diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-17 15:03:31 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-17 15:03:31 +0000 |
commit | 03bb750d5654f4ff4890fd1d39e680ac0860340f (patch) | |
tree | 0eaac7f26201b190212ec6332f263295e58e43f4 /ext | |
parent | 327da86aafc7cb4f5437ed0a9c46f61260aedf56 (diff) | |
download | ruby-03bb750d5654f4ff4890fd1d39e680ac0860340f.tar.gz |
* ext/pathname/lib/pathname.rb (Pathname#initialize): removed.
* ext/pathname/pathname.c (path_initialize): implemented.
(get_strpath): new function.
(set_strpath): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/pathname/lib/pathname.rb | 15 | ||||
-rw-r--r-- | ext/pathname/pathname.c | 37 |
2 files changed, 37 insertions, 15 deletions
diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index b150a31f69..54be13868f 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -208,21 +208,6 @@ class Pathname # :startdoc: - # - # Create a Pathname object from the given String (or String-like object). - # If +path+ contains a NUL character (<tt>\0</tt>), an ArgumentError is raised. - # - def initialize(path) - path = path.__send__(TO_PATH) if path.respond_to? TO_PATH - @path = path.dup - - if /\0/ =~ @path - raise ArgumentError, "pathname contains \\0: #{@path.inspect}" - end - - self.taint if @path.tainted? - end - 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 36ad9c8708..b91cd470ad 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -1,9 +1,46 @@ #include "ruby.h" static VALUE rb_cPathname; +static ID id_at_path, id_to_path; + +static VALUE +get_strpath(VALUE obj) +{ + return rb_ivar_get(obj, id_at_path); +} + +static void +set_strpath(VALUE obj, VALUE val) +{ + rb_ivar_set(obj, id_at_path, val); +} + +/* + * Create a Pathname object from the given String (or String-like object). + * If +path+ contains a NUL character (<tt>\0</tt>), an ArgumentError is raised. + */ +static VALUE +path_initialize(VALUE self, VALUE arg) +{ + VALUE str; + 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); + + set_strpath(self, str); + OBJ_INFECT(self, str); +} void Init_pathname() { + id_at_path = rb_intern("@path"); + id_to_path = rb_intern("to_path"); + rb_cPathname = rb_define_class("Pathname", rb_cObject); + rb_define_method(rb_cPathname, "initialize", path_initialize, 1); } |