[前][次][番号順一覧][スレッド一覧]

ruby-changes:16675

From: akr <ko1@a...>
Date: Sun, 18 Jul 2010 00:13:19 +0900 (JST)
Subject: [ruby-changes:16675] Ruby:r28670 (trunk): * ext/pathname/lib/pathname.rb (Pathname#initialize): removed.

akr	2010-07-18 00:03:31 +0900 (Sun, 18 Jul 2010)

  New Revision: 28670

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28670

  Log:
    * ext/pathname/lib/pathname.rb (Pathname#initialize): removed.
    
    * ext/pathname/pathname.c (path_initialize): implemented.
      (get_strpath): new function.
      (set_strpath): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/ext/pathname/lib/pathname.rb
    trunk/ext/pathname/pathname.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 28669)
+++ ChangeLog	(revision 28670)
@@ -1,3 +1,11 @@
+Sun Jul 18 00:02:19 2010  Tanaka Akira  <akr@f...>
+
+	* ext/pathname/lib/pathname.rb (Pathname#initialize): removed.
+
+	* ext/pathname/pathname.c (path_initialize): implemented.
+	  (get_strpath): new function.
+	  (set_strpath): ditto.
+
 Sat Jul 17 19:01:47 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/test/unit.rb (MiniTest::Unit#process_args): refactored.
Index: ext/pathname/lib/pathname.rb
===================================================================
--- ext/pathname/lib/pathname.rb	(revision 28669)
+++ ext/pathname/lib/pathname.rb	(revision 28670)
@@ -208,21 +208,6 @@
 
   # :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
Index: ext/pathname/pathname.c
===================================================================
--- ext/pathname/pathname.c	(revision 28669)
+++ ext/pathname/pathname.c	(revision 28670)
@@ -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);
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]