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

ruby-changes:46947

From: nobu <ko1@a...>
Date: Mon, 12 Jun 2017 09:18:37 +0900 (JST)
Subject: [ruby-changes:46947] nobu:r59061 (trunk): win32.c: rb_dir_getwd_ospath

nobu	2017-06-12 09:18:30 +0900 (Mon, 12 Jun 2017)

  New Revision: 59061

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59061

  Log:
    win32.c: rb_dir_getwd_ospath
    
    * win32/win32.c (rb_dir_getwd_ospath): Windows implementation
      moved from dir.c.  get rid of freeing malloced memory by xfree.

  Modified files:
    trunk/dir.c
    trunk/win32/win32.c
Index: dir.c
===================================================================
--- dir.c	(revision 59060)
+++ dir.c	(revision 59061)
@@ -1081,6 +1081,7 @@ dir_s_chdir(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/dir.c#L1081
     return INT2FIX(0);
 }
 
+#ifndef _WIN32
 VALUE
 rb_dir_getwd_ospath(void)
 {
@@ -1093,10 +1094,7 @@ rb_dir_getwd_ospath(void) https://github.com/ruby/ruby/blob/trunk/dir.c#L1094
     path_guard = Data_Wrap_Struct((VALUE)0, NULL, RUBY_DEFAULT_FREE, NULL);
     path = my_getcwd();
     DATA_PTR(path_guard) = path;
-#ifdef _WIN32
-    cwd = rb_utf8_str_new_cstr(path);
-    OBJ_TAINT(cwd);
-#elif defined __APPLE__
+#ifdef __APPLE__
     cwd = rb_str_normalize_ospath(path, strlen(path));
     OBJ_TAINT(cwd);
 #else
@@ -1107,6 +1105,7 @@ rb_dir_getwd_ospath(void) https://github.com/ruby/ruby/blob/trunk/dir.c#L1105
     xfree(path);
     return cwd;
 }
+#endif
 
 VALUE
 rb_dir_getwd(void)
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 59060)
+++ win32/win32.c	(revision 59061)
@@ -4656,7 +4656,7 @@ clock_getres(clockid_t clock_id, struct https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4656
 
 /* License: Ruby's */
 static char *
-w32_getcwd(char *buffer, int size, UINT cp)
+w32_getcwd(char *buffer, int size, UINT cp, void *alloc(int, void *), void *arg)
 {
     WCHAR *p;
     int wlen, len;
@@ -4687,7 +4687,7 @@ w32_getcwd(char *buffer, int size, UINT https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4687
 	}
     }
     else {
-	buffer = malloc(len);
+	buffer = (*alloc)(len, arg);
 	if (!buffer) {
 	    errno = ENOMEM;
 	    return NULL;
@@ -4699,17 +4699,42 @@ w32_getcwd(char *buffer, int size, UINT https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4699
 }
 
 /* License: Ruby's */
+static void *
+getcwd_alloc(int size, void *dummy)
+{
+    return malloc(size);
+}
+
+/* License: Ruby's */
 char *
 rb_w32_getcwd(char *buffer, int size)
 {
-    return w32_getcwd(buffer, size, filecp());
+    return w32_getcwd(buffer, size, filecp(), getcwd_alloc, NULL);
 }
 
 /* License: Ruby's */
 char *
 rb_w32_ugetcwd(char *buffer, int size)
 {
-    return w32_getcwd(buffer, size, CP_UTF8);
+    return w32_getcwd(buffer, size, CP_UTF8, getcwd_alloc, NULL);
+}
+
+/* License: Ruby's */
+static void *
+getcwd_value(int size, void *arg)
+{
+    VALUE str = *(VALUE *)arg = rb_utf8_str_new(0, size - 1);
+    OBJ_TAINT(str);
+    return RSTRING_PTR(str);
+}
+
+/* License: Ruby's */
+VALUE
+rb_dir_getwd_ospath(void)
+{
+    VALUE cwd = Qnil;
+    w32_getcwd(NULL, 0, CP_UTF8, getcwd_value, &cwd);
+    return cwd;
 }
 
 /* License: Artistic or GPL */

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

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