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

ruby-changes:24240

From: naruse <ko1@a...>
Date: Wed, 4 Jul 2012 00:39:13 +0900 (JST)
Subject: [ruby-changes:24240] naruse:r36291 (ruby_1_9_3): Revert r36279; it breaks C API compatibility.

naruse	2012-07-04 00:38:58 +0900 (Wed, 04 Jul 2012)

  New Revision: 36291

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

  Log:
    Revert r36279; it breaks C API compatibility.

  Modified files:
    branches/ruby_1_9_3/dir.c
    branches/ruby_1_9_3/ext/pathname/pathname.c
    branches/ruby_1_9_3/file.c
    branches/ruby_1_9_3/include/ruby/encoding.h
    branches/ruby_1_9_3/include/ruby/intern.h
    branches/ruby_1_9_3/test/pathname/test_pathname.rb
    branches/ruby_1_9_3/test/ruby/test_file_exhaustive.rb
    branches/ruby_1_9_3/version.h

Index: ruby_1_9_3/include/ruby/intern.h
===================================================================
--- ruby_1_9_3/include/ruby/intern.h	(revision 36290)
+++ ruby_1_9_3/include/ruby/intern.h	(revision 36291)
@@ -402,9 +402,15 @@
 VALUE rb_find_file_safe(VALUE, int);
 int rb_find_file_ext(VALUE*, const char* const*);
 VALUE rb_find_file(VALUE);
+char *rb_path_next(const char *);
+char *rb_path_skip_prefix(const char *);
+char *rb_path_last_separator(const char *);
+char *rb_path_end(const char *);
 VALUE rb_file_directory_p(VALUE,VALUE);
 VALUE rb_str_encode_ospath(VALUE);
 int rb_is_absolute_path(const char *);
+const char *ruby_find_basename(const char *name, long *baselen, long *alllen);
+const char *ruby_find_extname(const char *name, long *len);
 /* gc.c */
 void ruby_set_stack_size(size_t);
 NORETURN(void rb_memerror(void));
Index: ruby_1_9_3/include/ruby/encoding.h
===================================================================
--- ruby_1_9_3/include/ruby/encoding.h	(revision 36290)
+++ ruby_1_9_3/include/ruby/encoding.h	(revision 36291)
@@ -211,12 +211,6 @@
 void rb_enc_set_default_internal(VALUE encoding);
 VALUE rb_locale_charmap(VALUE klass);
 long rb_memsearch(const void*,long,const void*,long,rb_encoding*);
-char *rb_enc_path_next(const char *,const char *,rb_encoding*);
-char *rb_enc_path_skip_prefix(const char *,const char *,rb_encoding*);
-char *rb_enc_path_last_separator(const char *,const char *,rb_encoding*);
-char *rb_enc_path_end(const char *,const char *,rb_encoding*);
-const char *ruby_enc_find_basename(const char *name, long *baselen, long *alllen, rb_encoding *enc);
-const char *ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc);
 
 RUBY_EXTERN VALUE rb_cEncoding;
 #define ENC_DUMMY_FLAG (1<<24)
Index: ruby_1_9_3/dir.c
===================================================================
--- ruby_1_9_3/dir.c	(revision 36290)
+++ ruby_1_9_3/dir.c	(revision 36291)
@@ -910,16 +910,11 @@
 {
     VALUE d = *dir;
     char *path, *pend;
-    long len;
-    rb_encoding *enc;
 
     rb_secure(2);
     FilePathValue(d);
-    enc = rb_enc_get(d);
-    RSTRING_GETMEM(d, path, len);
-    pend = path + len;
-    pend = rb_enc_path_end(rb_enc_path_skip_prefix(path, pend, enc), pend, enc);
-    if (pend - path < len) {
+    path = RSTRING_PTR(d);
+    if (path && *(pend = rb_path_end(rb_path_skip_prefix(path)))) {
 	d = rb_str_subseq(d, 0, pend - path);
     }
     *dir = rb_str_encode_ospath(d);
@@ -1499,7 +1494,7 @@
     start = root = path;
     flags |= FNM_SYSCASE;
 #if defined DOSISH
-    root = rb_enc_path_skip_prefix(root, root + strlen(root), enc);
+    root = rb_path_skip_prefix(root);
 #endif
 
     if (root && *root == '/') root++;
Index: ruby_1_9_3/ext/pathname/pathname.c
===================================================================
--- ruby_1_9_3/ext/pathname/pathname.c	(revision 36290)
+++ ruby_1_9_3/ext/pathname/pathname.c	(revision 36291)
@@ -1,5 +1,4 @@
 #include "ruby.h"
-#include "ruby/encoding.h"
 
 static VALUE rb_cPathname;
 static ID id_at_path, id_to_path;
@@ -185,15 +184,15 @@
 
     StringValue(repl);
     p = RSTRING_PTR(str);
-    extlen = RSTRING_LEN(str);
-    ext = ruby_enc_find_extname(p, &extlen, rb_enc_get(str));
+    ext = ruby_find_extname(p, &extlen);
     if (ext == NULL) {
         ext = p + RSTRING_LEN(str);
     }
     else if (extlen <= 1) {
         ext += extlen;
     }
-    str2 = rb_str_subseq(str, 0, ext-p);
+    str2 = rb_str_dup(str);
+    rb_str_resize(str2, ext-p);
     rb_str_append(str2, repl);
     OBJ_INFECT(str2, str);
     return rb_class_new_instance(1, &str2, rb_obj_class(self));
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 36290)
+++ ruby_1_9_3/version.h	(revision 36291)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 250
+#define RUBY_PATCHLEVEL 251
 
 #define RUBY_RELEASE_DATE "2012-07-03"
 #define RUBY_RELEASE_YEAR 2012
Index: ruby_1_9_3/test/ruby/test_file_exhaustive.rb
===================================================================
--- ruby_1_9_3/test/ruby/test_file_exhaustive.rb	(revision 36290)
+++ ruby_1_9_3/test/ruby/test_file_exhaustive.rb	(revision 36291)
@@ -3,8 +3,6 @@
 require "tmpdir"
 
 class TestFileExhaustive < Test::Unit::TestCase
-  DRIVE = Dir.pwd[%r'\A(?:[a-z]:|//[^/]+/[^/]+)'i]
-
   def assert_incompatible_encoding
     d = "\u{3042}\u{3044}".encode("utf-16le")
     assert_raise(Encoding::CompatibilityError) {yield d}
@@ -402,29 +400,13 @@
       assert_match(/\Ac:\//i, File.expand_path('c:foo', 'd:/bar'))
       assert_match(%r'\Ac:/bar/foo\z'i, File.expand_path('c:foo', 'c:/bar'))
     end
-    if DRIVE
+    if drive = Dir.pwd[%r'\A(?:[a-z]:|//[^/]+/[^/]+)'i]
       assert_match(%r"\Az:/foo\z"i, File.expand_path('/foo', "z:/bar"))
       assert_match(%r"\A//host/share/foo\z"i, File.expand_path('/foo', "//host/share/bar"))
-      assert_match(%r"\A#{DRIVE}/foo\z"i, File.expand_path('/foo'))
+      assert_match(%r"\A#{drive}/foo\z"i, File.expand_path('/foo'))
     else
       assert_equal("/foo", File.expand_path('/foo'))
     end
-    drive = (DRIVE ? 'C:' : '')
-    if Encoding.find("filesystem") == Encoding::CP1251
-      a = "#{drive}/\u3042\u3044\u3046\u3048\u304a".encode("cp932")
-    else
-      a = "#{drive}/\u043f\u0440\u0438\u0432\u0435\u0442".encode("cp1251")
-    end
-    assert_equal(a, File.expand_path(a))
-    a = "#{drive}/\225\\\\"
-    if File::ALT_SEPARATOR == '\\'
-      [%W"cp437 #{drive}/\225", %W"cp932 #{drive}/\225\\"]
-    else
-      [["cp437", a], ["cp932", a]]
-    end.each do |cp, expected|
-      assert_equal(expected.force_encoding(cp), File.expand_path(a.dup.force_encoding(cp)), cp)
-    end
-
     assert_kind_of(String, File.expand_path("~")) if ENV["HOME"]
     assert_raise(ArgumentError) { File.expand_path("~foo_bar_baz_unknown_user_wahaha") }
     assert_raise(ArgumentError) { File.expand_path("~foo_bar_baz_unknown_user_wahaha", "/") }
@@ -465,31 +447,16 @@
       assert_equal(basename, File.basename(@file + ".", ".*"))
       assert_equal(basename, File.basename(@file + "::$DATA", ".*"))
     end
-    if File::ALT_SEPARATOR == '\\'
-      a = "foo/\225\\\\"
-      [%W"cp437 \225", %W"cp932 \225\\"].each do |cp, expected|
-        assert_equal(expected.force_encoding(cp), File.basename(a.dup.force_encoding(cp)), cp)
-      end
-    end
 
     assert_incompatible_encoding {|d| File.basename(d)}
     assert_incompatible_encoding {|d| File.basename(d, ".*")}
     assert_raise(Encoding::CompatibilityError) {File.basename("foo.ext", ".*".encode("utf-16le"))}
-
-    s = "foo\x93_a".force_encoding("cp932")
-    assert_equal(s, File.basename(s, "_a"))
   end
 
   def test_dirname
     assert(@file.start_with?(File.dirname(@file)))
     assert_equal(".", File.dirname(""))
     assert_incompatible_encoding {|d| File.dirname(d)}
-    if File::ALT_SEPARATOR == '\\'
-      a = "\225\\\\foo"
-      [%W"cp437 \225", %W"cp932 \225\\"].each do |cp, expected|
-        assert_equal(expected.force_encoding(cp), File.dirname(a.dup.force_encoding(cp)), cp)
-      end
-    end
   end
 
   def test_extname
@@ -533,13 +500,6 @@
     def o.to_path; "foo"; end
     assert_equal(s, File.join(o, "bar", "baz"))
     assert_equal(s, File.join("foo" + File::SEPARATOR, "bar", File::SEPARATOR + "baz"))
-    if File::ALT_SEPARATOR == '\\'
-      a = "\225\\"
-      b = "foo"
-      [%W"cp437 \225\\foo", %W"cp932 \225\\/foo"].each do |cp, expected|
-        assert_equal(expected.force_encoding(cp), File.join(a.dup.force_encoding(cp), b.dup.force_encoding(cp)), cp)
-      end
-    end
   end
 
   def test_truncate
Index: ruby_1_9_3/test/pathname/test_pathname.rb
===================================================================
--- ruby_1_9_3/test/pathname/test_pathname.rb	(revision 36290)
+++ ruby_1_9_3/test/pathname/test_pathname.rb	(revision 36291)
@@ -1,3 +1,5 @@
+#!/usr/bin/env ruby
+
 require 'test/unit'
 require 'pathname'
 
@@ -183,8 +185,10 @@
 
   if DOSISH
     defassert(:del_trailing_separator, "a", "a\\")
-    defassert(:del_trailing_separator, "\225\\".force_encoding("cp932"), "\225\\\\".force_encoding("cp932"))
-    defassert(:del_trailing_separator, "\225".force_encoding("cp437"), "\225\\\\".force_encoding("cp437"))
+    require 'Win32API'
+    if Win32API.new('kernel32', 'GetACP', nil, 'L').call == 932
+      defassert(:del_trailing_separator, "\225\\", "\225\\\\") # SJIS
+    end
   end
 
   def test_plus
Index: ruby_1_9_3/file.c
===================================================================
--- ruby_1_9_3/file.c	(revision 36290)
+++ ruby_1_9_3/file.c	(revision 36291)
@@ -2425,8 +2425,6 @@
 #endif
 
 #ifdef HAVE_READLINK
-static VALUE rb_readlink(VALUE path);
-
 /*
  *  call-seq:
  *     File.readlink(link_name)  ->  file_name
@@ -2441,12 +2439,6 @@
 static VALUE
 rb_file_s_readlink(VALUE klass, VALUE path)
 {
-    return rb_readlink(path);
-}
-
-static VALUE
-rb_readlink(VALUE path)
-{
     char *buf;
     int size = 100;
     ssize_t rv;
@@ -2612,8 +2604,9 @@
 #define istrailinggarbage(x) 0
 #endif
 
-#define Next(p, e, enc) ((p) + rb_enc_mbclen((p), (e), (enc)))
-#define Inc(p, e, enc) ((p) = Next((p), (e), (enc)))
+#ifndef CharNext		/* defined as CharNext[AW] on Windows. */
+# define CharNext(p) ((p) + 1)
+#endif
 
 #if defined(DOSISH_UNC)
 #define has_unc(buf) (isdirsep((buf)[0]) && isdirsep((buf)[1]))
@@ -2675,40 +2668,40 @@
 #endif
 
 static inline char *
-skiproot(const char *path, const char *end, rb_encoding *enc)
+skiproot(const char *path)
 {
 #ifdef DOSISH_DRIVE_LETTER
-    if (path + 2 <= end && has_drive_letter(path)) path += 2;
+    if (has_drive_letter(path)) path += 2;
 #endif
-    while (path < end && isdirsep(*path)) path++;
+    while (isdirsep(*path)) path++;
     return (char *)path;
 }
 
-#define nextdirsep rb_enc_path_next
+#define nextdirsep rb_path_next
 char *
-rb_enc_path_next(const char *s, const char *e, rb_encoding *enc)
+rb_path_next(const char *s)
 {
-    while (s < e && !isdirsep(*s)) {
-	Inc(s, e, enc);
+    while (*s && !isdirsep(*s)) {
+	s = CharNext(s);
     }
     return (char *)s;
 }
 
 #if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER)
-#define skipprefix rb_enc_path_skip_prefix
+#define skipprefix rb_path_skip_prefix
 #else
-#define skipprefix(path, end, enc) (path)
+#define skipprefix(path) (path)
 #endif
 char *
-rb_enc_path_skip_prefix(const char *path, const char *end, rb_encoding *enc)
+rb_path_skip_prefix(const char *path)
 {
 #if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER)
 #ifdef DOSISH_UNC
-    if (path + 2 <= end && isdirsep(path[0]) && isdirsep(path[1])) {
+    if (isdirsep(path[0]) && isdirsep(path[1])) {
 	path += 2;
-	while (path < end && isdirsep(*path)) path++;
-	if ((path = rb_enc_path_next(path, end, enc)) < end && path[0] && path[1] && !isdirsep(path[1]))
-	    path = rb_enc_path_next(path + 1, end, enc);
+	while (isdirsep(*path)) path++;
+	if (*(path = nextdirsep(path)) && path[1] && !isdirsep(path[1]))
+	    path = nextdirsep(path + 1);
 	return (char *)path;
     }
 #endif
@@ -2721,78 +2714,78 @@
 }
 
 static inline char *
-skipprefixroot(const char *path, const char *end, rb_encoding *enc)
+skipprefixroot(const char *path)
 {
 #if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER)
-    char *p = skipprefix(path, end, enc);
+    char *p = skipprefix(path);
     while (isdirsep(*p)) p++;
     return p;
 #else
-    return skiproot(path, end, enc);
+    return skiproot(path);
 #endif
 }
 
-#define strrdirsep rb_enc_path_last_separator
+#define strrdirsep rb_path_last_separator
 char *
-rb_enc_path_last_separator(const char *path, const char *end, rb_encoding *enc)
+rb_path_last_separator(const char *path)
 {
     char *last = NULL;
-    while (path < end) {
+    while (*path) {
 	if (isdirsep(*path)) {
 	    const char *tmp = path++;
-	    while (path < end && isdirsep(*path)) path++;
-	    if (path >= end) break;
+	    while (isdirsep(*path)) path++;
+	    if (!*path) break;
 	    last = (char *)tmp;
 	}
 	else {
-	    Inc(path, end, enc);
+	    path = CharNext(path);
 	}
     }
     return last;
 }
 
 static char *
-chompdirsep(const char *path, const char *end, rb_encoding *enc)
+chompdirsep(const char *path)
 {
-    while (path < end) {
+    while (*path) {
 	if (isdirsep(*path)) {
 	    const char *last = path++;
-	    while (path < end && isdirsep(*path)) path++;
-	    if (path >= end) return (char *)last;
+	    while (isdirsep(*path)) path++;
+	    if (!*path) return (char *)last;
 	}
 	else {
-	    Inc(path, end, enc);
+	    path = CharNext(path);
 	}
     }
     return (char *)path;
 }
 
 char *
-rb_enc_path_end(const char *path, const char *end, rb_encoding *enc)
+rb_path_end(const char *path)
 {
-    if (path < end && isdirsep(*path)) path++;
-    return chompdirsep(path, end, enc);
+    if (isdirsep(*path)) path++;
+    return chompdirsep(path);
 }
 
 #if USE_NTFS
 static char *
-ntfs_tail(const char *path, const char *end, rb_encoding *enc)
+ntfs_tail(const char *path)
 {
-    while (path < end && *path == '.') path++;
-    while (path < end && *path != ':') {
+    while (*path == '.') path++;
+    while (*path && *path != ':') {
 	if (istrailinggarbage(*path)) {
 	    const char *last = path++;
-	    while (path < end && istrailinggarbage(*path)) path++;
-	    if (path >= end || *path == ':') return (char *)last;
+	    while (istrailinggarbage(*path)) path++;
+	    if (!*path || *path == ':') return (char *)last;
 	}
 	else if (isdirsep(*path)) {
 	    const char *last = path++;
-	    while (path < end && isdirsep(*path)) path++;
-	    if (path >= end) return (char *)last;
+	    while (isdirsep(*path)) path++;
+	    if (!*path) return (char *)last;
 	    if (*path == ':') path++;
 	}
 	else {
-	    Inc(path, end, enc);
+	    path = CharNext(path);
 	}
     }
     return (char *)path;
@@ -2821,10 +2814,9 @@
     const char *dir;
     char *buf;
 #if defined DOSISH || defined __CYGWIN__
-    char *p, *bend;
+    char *p;
 #endif
     long dirlen;
-    rb_encoding *enc;
 
     if (!user || !*user) {
 	if (!(dir = getenv("HOME"))) {
@@ -2843,61 +2835,32 @@
 	}
 	dirlen = strlen(pwPtr->pw_dir);
 	rb_str_resize(result, dirlen);
-	memcpy(buf = RSTRING_PTR(result), pwPtr->pw_dir, dirlen + 1);
+	strcpy(buf = RSTRING_PTR(result), pwPtr->pw_dir);
 	endpwent();
 #else
 	return Qnil;
 #endif
     }
-    enc = rb_filesystem_encoding();
-    rb_enc_associate(result, enc);
 #if defined DOSISH || defined __CYGWIN__
-    for (bend = (p = buf) + dirlen; p < bend; Inc(p, bend, enc)) {
+    for (p = buf; *p; p = CharNext(p)) {
 	if (*p == '\\') {
 	    *p = '/';
 	}
     }
 #endif
+    rb_enc_associate_index(result, rb_filesystem_encindex());
     return result;
 }
 
-static char *
-append_fspath(VALUE result, VALUE fname, char *dir, rb_encoding **enc, rb_encoding *fsenc)
-{
-    char *buf, *cwdp = dir;
-    VALUE dirname = Qnil;
-    size_t dirlen = strlen(dir), buflen = rb_str_capacity(result);
-
-    if (*enc != fsenc) {
-	rb_encoding *direnc = rb_enc_check(fname, dirname = rb_enc_str_new(dir, dirlen, fsenc));
-	if (direnc != fsenc) {
-	    dirname = rb_str_conv_enc(dirname, fsenc, direnc);
-	    RSTRING_GETMEM(dirname, cwdp, dirlen);
-	}
-	*enc = direnc;
-	rb_enc_associate(result, direnc);
-    }
-    do {buflen *= 2;} while (dirlen > buflen);
-    rb_str_resize(result, buflen);
-    buf = RSTRING_PTR(result);
-    memcpy(buf, cwdp, dirlen);
-    xfree(dir);
-    if (!NIL_P(dirname)) rb_str_resize(dirname, 0);
-    return buf + dirlen;
-}
-
 static VALUE
 file_expand_path(VALUE fname, VALUE dname, int abs_mode, VALUE result)
 {
-    const char *s, *b, *fend;
+    const char *s, *b;
     char *buf, *p, *pend, *root;
-    size_t buflen, bdiff;
+    size_t buflen, dirlen, bdiff;
     int tainted;
-    rb_encoding *enc, *fsenc = rb_filesystem_encoding();
 
     s = StringValuePtr(fname);
-    fend = s + RSTRING_LEN(fname);
-    enc = rb_enc_get(fname);
     BUFINIT();
     tainted = OBJ_TAINTED(fname);
 
@@ -2911,7 +2874,7 @@
 	    if (*++s) ++s;
 	}
 	else {
-	    s = nextdirsep(b = s, fend, enc);
+	    s = nextdirsep(b = s);
 	    userlen = s - b;
 	    BUFCHECK(bdiff + userlen >= buflen);
 	    memcpy(p, b, userlen);
@@ -2957,16 +2920,18 @@
 		}
 	    }
 	    if (!same) {
-		char *e = append_fspath(result, fname, getcwdofdrv(*s), &enc, fsenc);
+		char *dir = getcwdofdrv(*s);
+
 		tainted = 1;
-		BUFINIT();
-		p = e;
+		dirlen = strlen(dir);
+		BUFCHECK(dirlen > buflen);
+		strcpy(buf, dir);
+		xfree(dir);
+		rb_enc_associate_index(result, rb_filesystem_encindex());
 	    }
-	    else {
-		rb_enc_associate(result, enc = rb_enc_check(result, fname));
-		p = pend;
-	    }
-	    p = chompdirsep(skiproot(buf, p, enc), p, enc);
+	    else
+		rb_enc_associate(result, rb_enc_check(result, fname));
+	    p = chompdirsep(skiproot(buf));
 	    s += 2;
 	}
     }
@@ -2974,25 +2939,28 @@
     else if (!rb_is_absolute_path(s)) {
 	if (!NIL_P(dname)) {
 	    file_expand_path(dname, Qnil, abs_mode, result);
-	    rb_enc_associate(result, rb_enc_check(result, fname));
 	    BUFINIT();
-	    p = pend;
+	    rb_enc_associate(result, rb_enc_check(result, fname));
 	}
 	else {
-	    char *e = append_fspath(result, fname, my_getcwd(), &enc, fsenc);
+	    char *dir = my_getcwd();
+
 	    tainted = 1;
-	    BUFINIT();
-	    p = e;
+	    dirlen = strlen(dir);
+	    BUFCHECK(dirlen > buflen);
+	    strcpy(buf, dir);
+	    xfree(dir);
+	    rb_enc_associate_index(result, rb_filesystem_encindex());
 	}
 #if defined DOSISH || defined __CYGWIN__
 	if (isdirsep(*s)) {
 	    /* specified full path, but not drive letter nor UNC */
 	    /* we need to get the drive letter or UNC share name */
-	    p = skipprefix(buf, p, enc);
+	    p = skipprefix(buf);
 	}
 	else
 #endif
-	    p = chompdirsep(skiproot(buf, p, enc), p, enc);
+	    p = chompdirsep(skiproot(buf));
     }
     else {
 	size_t len;
@@ -3016,7 +2984,7 @@
     rb_str_set_len(result, p-buf+1);
     BUFCHECK(bdiff + 1 >= buflen);
     p[1] = 0;
-    root = skipprefix(buf, p+1, enc);
+    root = skipprefix(buf);
 
     b = s;
     while (*s) {
@@ -3032,7 +3000,7 @@
 			/* We must go back to the parent */
 			char *n;
 			*p = '\0';
-			if (!(n = strrdirsep(root, p, enc))) {
+			if (!(n = strrdirsep(root))) {
 			    *p = '/';
 			}
 			else {
@@ -3062,7 +3030,7 @@
 		--s;
 	      case ' ': {
 		const char *e = s;
-		while (s < fend && istrailinggarbage(*s)) s++;
+		while (istrailinggarbage(*s)) s++;
 		if (!*s) {
 		    s = e;
 		    goto endpath;
@@ -3087,7 +3055,7 @@
 	    b = ++s;
 	    break;
 	  default:
-	    Inc(s, fend, enc);
+	    s = CharNext(s);
 	    break;
 	}
     }
@@ -3112,18 +3080,14 @@
 	BUFCHECK(bdiff + (s-b) >= buflen);
 	memcpy(++p, b, s-b);
 	p += s-b;
-	rb_str_set_len(result, p-buf);
     }
-    if (p == skiproot(buf, p + !!*p, enc) - 1) p++;
+    if (p == skiproot(buf) - 1) p++;
 
 #if USE_NTFS
     *p = '\0';
-    if ((s = strrdirsep(b = buf, p, enc)) != 0 && !strpbrk(s, "*?")) {
-	VALUE tmp, v;
+    if ((s = strrdirsep(b = buf)) != 0 && !strpbrk(s, "*?")) {
 	size_t len;
-	rb_encoding *enc;
-	WCHAR *wstr;
-	WIN32_FIND_DATAW wfd;
+	WIN32_FIND_DATA wfd;
 	HANDLE h;
 #ifdef __CYGWIN__
 #ifdef HAVE_CYGWIN_CONV_PATH
@@ -3173,43 +3137,21 @@
 	}
 	*p = '/';
 #endif
-	rb_str_set_len(result, p - buf + strlen(p));
-	enc = rb_enc_get(result);
-	tmp = result;
-	if (enc != rb_utf8_encoding() && rb_enc_str_coderange(result) != ENC_CODERANGE_7BIT) {
-	    tmp = rb_str_encode_ospath(result);
-	}
-	len = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(tmp), -1, NULL, 0);
-	wstr = ALLOCV_N(WCHAR, v, len);
-	MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(tmp), -1, wstr, len);
-	if (tmp != result) rb_str_resize(tmp, 0);
-	h = FindFirstFileW(wstr, &wfd);
-	ALLOCV_END(v);
+	h = FindFirstFile(b, &wfd);
 	if (h != INVALID_HANDLE_VALUE) {
-	    size_t wlen;
 	    FindClose(h);
-	    len = lstrlenW(wfd.cFileName);
+	    len = strlen(wfd.cFileName);
 #ifdef __CYGWIN__ (... truncated)

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

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