From 62b486b6a280310c463fd4c1dbade70eb4da5385 Mon Sep 17 00:00:00 2001 From: dabretin Date: Wed, 21 May 2014 14:58:19 +0200 Subject: [PATCH 1/2] Update winpty --- .gitmodules | 2 +- deps/winpty | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index abfec21..04f4fa5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "deps/winpty"] path = deps/winpty - url = https://github.com/peters/winpty.git + url = https://github.com/dabretin/winpty.git diff --git a/deps/winpty b/deps/winpty index 25e3186..af026b4 160000 --- a/deps/winpty +++ b/deps/winpty @@ -1 +1 @@ -Subproject commit 25e3186e9eb792d21ac02d69797a1aefc64c45d9 +Subproject commit af026b4b66c24531db3463b25b3987bd9d6a0e3a From 8a007ab749ead1c5d6a504524e2a76bc75241300 Mon Sep 17 00:00:00 2001 From: dabretin Date: Wed, 21 May 2014 15:01:54 +0200 Subject: [PATCH 2/2] Use wstring for environment vars --- src/win/pty.cc | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/win/pty.cc b/src/win/pty.cc index daddc13..67e0f06 100644 --- a/src/win/pty.cc +++ b/src/win/pty.cc @@ -187,7 +187,7 @@ static NAN_METHOD(PtyOpen) { return NanThrowError("Usage: pty.open(dataPipe, cols, rows, debug)"); } - std::wstring pipeName = to_wstring(String::Utf8Value(args[0]->ToString())); + const wchar_t* pipeName = to_wstring(String::Utf8Value(args[0]->ToString())); int cols = args[1]->Int32Value(); int rows = args[2]->Int32Value(); bool debug = args[3]->ToBoolean()->IsTrue(); @@ -196,7 +196,7 @@ static NAN_METHOD(PtyOpen) { SetEnvironmentVariable(WINPTY_DBG_VARIABLE, debug ? "1" : NULL); // NULL = deletes variable // Open a new pty session. - winpty_t *pc = winpty_open_use_own_datapipe(pipeName.c_str(), cols, rows); + winpty_t *pc = winpty_open_use_own_datapipe(pipeName, cols, rows); // Error occured during startup of agent process. assert(pc != nullptr); @@ -247,25 +247,18 @@ static NAN_METHOD(PtyStartProcess) { const wchar_t *cwd = to_wstring(String::Utf8Value(args[4]->ToString())); // create environment block - wchar_t *env = NULL; - const Handle envValues = Handle::Cast(args[3]); - if(!envValues.IsEmpty()) { - - std::wstringstream envBlock; - - for(uint32_t i = 0; i < envValues->Length(); i++) { - std::wstring envValue(to_wstring(String::Utf8Value(envValues->Get(i)->ToString()))); - envBlock << envValue << L' '; - } - - std::wstring output = envBlock.str(); - - size_t count = output.size(); - env = new wchar_t[count + 2]; - wcsncpy(env, output.c_str(), count); - - wcscat(env, L"\0"); - } + std::wstring env; + const Handle envValues = Handle::Cast(args[3]); + uint32_t envValueCount = envValues->Length(); + if (envValueCount > 0) + { + for(uint32_t i=0; iGet(i)->ToString()))); + env.push_back(L'\0'); + } + env.push_back(L'\0'); + } // use environment 'Path' variable to determine location of // the relative path that we have recieved (e.g cmd.exe) @@ -301,7 +294,6 @@ static NAN_METHOD(PtyStartProcess) { delete filename; delete cmdline; delete cwd; - delete env; if(!exception.IsEmpty()) { return exception;