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

ruby-changes:30127

From: nobu <ko1@a...>
Date: Fri, 26 Jul 2013 13:00:39 +0900 (JST)
Subject: [ruby-changes:30127] nobu:r42179 (trunk): win32/file.c: refine convert_mb_to_wchar

nobu	2013-07-26 13:00:28 +0900 (Fri, 26 Jul 2013)

  New Revision: 42179

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

  Log:
    win32/file.c: refine convert_mb_to_wchar
    
    * win32/file.c (convert_mb_to_wchar): use bare pointer instead of
      VALUE, and remove useless argument.

  Modified files:
    trunk/ChangeLog
    trunk/win32/file.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42178)
+++ ChangeLog	(revision 42179)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jul 26 13:00:24 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* win32/file.c (convert_mb_to_wchar): use bare pointer instead of
+	  VALUE, and remove useless argument.
+
 Fri Jul 26 11:42:07 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* rational.c (f_round_common): Rational is expected to be returned by
Index: win32/file.c
===================================================================
--- win32/file.c	(revision 42178)
+++ win32/file.c	(revision 42179)
@@ -33,19 +33,17 @@ replace_wchar(wchar_t *s, int find, int https://github.com/ruby/ruby/blob/trunk/win32/file.c#L33
 
 /* Convert str from multibyte char to wchar with specified code page */
 static inline void
-convert_mb_to_wchar(VALUE str, wchar_t **wstr, wchar_t **wstr_pos, size_t *wstr_len, UINT code_page)
+convert_mb_to_wchar(const char *str, wchar_t **wstr, size_t *wstr_len, UINT code_page)
 {
     size_t len;
 
-    if (NIL_P(str))
+    if (!str)
 	return;
 
-    len = MultiByteToWideChar(code_page, 0, RSTRING_PTR(str), -1, NULL, 0) + 1;
+    len = MultiByteToWideChar(code_page, 0, str, -1, NULL, 0) + 1;
     *wstr = (wchar_t *)xmalloc(len * sizeof(wchar_t));
-    if (wstr_pos)
-	*wstr_pos = *wstr;
 
-    MultiByteToWideChar(code_page, 0, RSTRING_PTR(str), -1, *wstr, len);
+    MultiByteToWideChar(code_page, 0, str, -1, *wstr, len);
     *wstr_len = len - 2;
 }
 
@@ -388,7 +386,10 @@ rb_file_expand_path_internal(VALUE fname https://github.com/ruby/ruby/blob/trunk/win32/file.c#L386
     }
 
     /* convert char * to wchar_t */
-    convert_mb_to_wchar(path, &wpath, &wpath_pos, &wpath_len, cp);
+    if (!NIL_P(path)) {
+	convert_mb_to_wchar(RSTRING_PTR(path), &wpath, &wpath_len, cp);
+	wpath_pos = wpath;
+    }
 
     /* determine if we need the user's home directory */
     /* expand '~' only if NOT rb_file_absolute_path() where `abs_mode` is 1 */
@@ -453,7 +454,10 @@ rb_file_expand_path_internal(VALUE fname https://github.com/ruby/ruby/blob/trunk/win32/file.c#L454
 	}
 
 	/* convert char * to wchar_t */
-	convert_mb_to_wchar(dir, &wdir, &wdir_pos, &wdir_len, cp);
+	if (!NIL_P(dir)) {
+	    convert_mb_to_wchar(RSTRING_PTR(dir), &wdir, &wdir_len, cp);
+	    wdir_pos = wdir;
+	}
 
 	if (abs_mode == 0 && wdir_len > 0 && wdir_pos[0] == L'~' &&
 	    (wdir_len == 1 || IS_DIR_SEPARATOR_P(wdir_pos[1]))) {

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

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