summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorDmitry Polienko <dmitry@eldis.ru>2016-07-19 20:33:25 -0700
committerDmitry Polienko <dmitry@eldis.ru>2016-07-19 20:33:25 -0700
commit9bd952d2c2928f2e75eacf7fca4889e0a4b39c38 (patch)
tree0c4e02146edc52b955e937100d8038921c7fc5a5 /lib/pure
parent5f773bf478b57af7cdb56a895feec610908ffdeb (diff)
downloadNim-9bd952d2c2928f2e75eacf7fca4889e0a4b39c38.tar.gz
Revert changes in osproc.nim
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/osproc.nim49
1 files changed, 6 insertions, 43 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index 3ebc80f30..03b77572a 100644
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -400,7 +400,7 @@ when defined(Windows) and not defined(useNimRtl):
     result = cast[cstring](alloc0(res.len+1))
     copyMem(result, cstring(res), res.len)
 
-  proc envToCString(env: StringTableRef): cstring =
+  proc buildEnv(env: StringTableRef): cstring =
     var L = 0
     for key, val in pairs(env): inc(L, key.len + val.len + 2)
     result = cast[cstring](alloc0(L+2))
@@ -410,45 +410,6 @@ when defined(Windows) and not defined(useNimRtl):
       copyMem(addr(result[L]), cstring(x), x.len+1) # copy \0
       inc(L, x.len+1)
 
-  proc envToWideCString(env: StringTableRef): WideCString =
-    # newWideCString stops on \0 characters, so we have to
-    # convert every pair separately.
-    const wcharSize = 2
-    var rows = newSeq[tuple[str: WideCString, len: int]]()
-    var L = 0  # length in wide chars
-
-    for key, val in pairs(env):
-      let str = newWideCString(key & "=" & val)
-      let row = (str: str, len: str.len)
-      rows.add(row)
-      inc(L, succ row.len)
-
-    # Leave space for trailing \0
-    result = cast[WideCString](alloc0(wcharSize * (succ L)))
-
-    L = 0
-    for row in rows:
-      # Copy \0 too
-      copyMem(
-        addr(result[L]),
-        addr(row.str[0]),
-        wcharSize * (succ row.len)
-      )
-      inc(L, succ row.len)
-
-    # Trailing \0
-    result[L] = Utf16Char(0)
-
-  proc buildEnv(env: StringTableRef): auto =
-    # return type is WideCString if useWinUnicode is enabled,
-    # otherwise cstring
-    if env.isNil: nil
-    else:
-      when useWinUnicode:
-        envToWideCString(env)
-      else:
-        envToCString(env)
-
   #proc open_osfhandle(osh: Handle, mode: int): int {.
   #  importc: "_open_osfhandle", header: "<fcntl.h>".}
 
@@ -565,16 +526,18 @@ when defined(Windows) and not defined(useNimRtl):
     else:
       cmdl = buildCommandLine(command, args)
     var wd: cstring = nil
-    let e = buildEnv(env)
+    var e: cstring = nil
     if len(workingDir) > 0: wd = workingDir
+    if env != nil: e = buildEnv(env)
     if poEchoCmd in options: echo($cmdl)
     when useWinUnicode:
       var tmp = newWideCString(cmdl)
+      var ee = newWideCString(e)
       var wwd = newWideCString(wd)
       var flags = NORMAL_PRIORITY_CLASS or CREATE_UNICODE_ENVIRONMENT
       if poDemon in options: flags = flags or CREATE_NO_WINDOW
       success = winlean.createProcessW(nil, tmp, nil, nil, 1, flags,
-        e, wwd, si, procInfo)
+        ee, wwd, si, procInfo)
     else:
       success = winlean.createProcessA(nil,
         cmdl, nil, nil, 1, NORMAL_PRIORITY_CLASS, e, wd, si, procInfo)
@@ -586,7 +549,7 @@ when defined(Windows) and not defined(useNimRtl):
       if poStdErrToStdOut notin options:
         fileClose(si.hStdError)
 
-    if e != nil: dealloc(addr(e[0]))
+    if e != nil: dealloc(e)
     if success == 0:
       if poInteractive in result.options: close(result)
       const errInvalidParameter = 87.int