Revert "Don't store args as std::string"
This reverts commit 8482575d1f
.
There is weird thing happened if we tried to store raw "argv" on Linux.
This commit is contained in:
parent
9f30933d3a
commit
d9c22396ea
4 changed files with 31 additions and 16 deletions
|
@ -155,7 +155,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||||
content::ContentMainParams params(&delegate);
|
content::ContentMainParams params(&delegate);
|
||||||
params.instance = instance;
|
params.instance = instance;
|
||||||
params.sandbox_info = &sandbox_info;
|
params.sandbox_info = &sandbox_info;
|
||||||
atom::AtomCommandLine::Init(argc, const_cast<const char**>(argv));
|
atom::AtomCommandLine::Init(argc, argv);
|
||||||
return content::ContentMain(params);
|
return content::ContentMain(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,15 +6,13 @@
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
// static
|
void AtomCommandLine::Init(int argc,
|
||||||
std::vector<const char*> AtomCommandLine::argv_;
|
const char* const* argv) {
|
||||||
|
|
||||||
// static
|
|
||||||
void AtomCommandLine::Init(int argc, const char* argv[]) {
|
|
||||||
argv_.reserve(argc);
|
|
||||||
for (int i = 0; i < argc; ++i) {
|
for (int i = 0; i < argc; ++i) {
|
||||||
argv_.push_back(argv[i]);
|
argv_.push_back(argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> AtomCommandLine::argv_;
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -5,22 +5,22 @@
|
||||||
#ifndef ATOM_APP_ATOM_MAIN_ARGS_H_
|
#ifndef ATOM_APP_ATOM_MAIN_ARGS_H_
|
||||||
#define ATOM_APP_ATOM_MAIN_ARGS_H_
|
#define ATOM_APP_ATOM_MAIN_ARGS_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
// Singleton to remember the original "argc" and "argv".
|
|
||||||
class AtomCommandLine {
|
class AtomCommandLine {
|
||||||
public:
|
public:
|
||||||
static void Init(int argc, const char* argv[]);
|
static void Init(int argc, const char* const* argv);
|
||||||
static std::vector<const char*> argv() { return argv_; }
|
static std::vector<std::string> argv() { return argv_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::vector<const char*> argv_;
|
static std::vector<std::string> argv_;
|
||||||
|
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(AtomCommandLine);
|
DISALLOW_COPY_AND_ASSIGN(AtomCommandLine);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
#include "native_mate/locker.h"
|
#include "native_mate/locker.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
#include "base/strings/utf_string_conversions.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
|
||||||
using content::BrowserThread;
|
using content::BrowserThread;
|
||||||
|
@ -88,6 +92,18 @@ namespace {
|
||||||
void UvNoOp(uv_async_t* handle) {
|
void UvNoOp(uv_async_t* handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert the given vector to an array of C-strings. The strings in the
|
||||||
|
// returned vector are only guaranteed valid so long as the vector of strings
|
||||||
|
// is not modified.
|
||||||
|
scoped_ptr<const char*[]> StringVectorToArgArray(
|
||||||
|
const std::vector<std::string>& vector) {
|
||||||
|
scoped_ptr<const char*[]> array(new const char*[vector.size()]);
|
||||||
|
for (size_t i = 0; i < vector.size(); ++i) {
|
||||||
|
array[i] = vector[i].c_str();
|
||||||
|
}
|
||||||
|
return array.Pass();
|
||||||
|
}
|
||||||
|
|
||||||
base::FilePath GetResourcesPath(base::CommandLine* command_line,
|
base::FilePath GetResourcesPath(base::CommandLine* command_line,
|
||||||
bool is_browser) {
|
bool is_browser) {
|
||||||
base::FilePath exec_path(command_line->argv()[0]);
|
base::FilePath exec_path(command_line->argv()[0]);
|
||||||
|
@ -157,9 +173,10 @@ node::Environment* NodeBindings::CreateEnvironment(
|
||||||
std::string script_path_str = script_path.AsUTF8Unsafe();
|
std::string script_path_str = script_path.AsUTF8Unsafe();
|
||||||
args.insert(args.begin() + 1, script_path_str.c_str());
|
args.insert(args.begin() + 1, script_path_str.c_str());
|
||||||
|
|
||||||
|
scoped_ptr<const char*[]> c_argv = StringVectorToArgArray(args);
|
||||||
node::Environment* env = node::CreateEnvironment(
|
node::Environment* env = node::CreateEnvironment(
|
||||||
context->GetIsolate(), uv_default_loop(), context,
|
context->GetIsolate(), uv_default_loop(), context,
|
||||||
args.size(), &args[0], 0, nullptr);
|
args.size(), c_argv.get(), 0, nullptr);
|
||||||
|
|
||||||
mate::Dictionary process(context->GetIsolate(), env->process_object());
|
mate::Dictionary process(context->GetIsolate(), env->process_object());
|
||||||
process.Set("type", process_type);
|
process.Set("type", process_type);
|
||||||
|
|
Loading…
Add table
Reference in a new issue