未验证 提交 1d034696 编写于 作者: L Leo Chen 提交者: GitHub

use vector instead of pointer, test=develop (#24620)

上级 c9e65ff4
...@@ -50,7 +50,7 @@ std::once_flag glog_init_flag; ...@@ -50,7 +50,7 @@ std::once_flag glog_init_flag;
std::once_flag p2p_init_flag; std::once_flag p2p_init_flag;
std::once_flag glog_warning_once_flag; std::once_flag glog_warning_once_flag;
bool InitGflags(std::vector<std::string> argv) { bool InitGflags(std::vector<std::string> args) {
bool successed = false; bool successed = false;
std::call_once(gflags_init_flag, [&]() { std::call_once(gflags_init_flag, [&]() {
FLAGS_logtostderr = true; FLAGS_logtostderr = true;
...@@ -59,20 +59,23 @@ bool InitGflags(std::vector<std::string> argv) { ...@@ -59,20 +59,23 @@ bool InitGflags(std::vector<std::string> argv) {
// commandline strings from idx 1. // commandline strings from idx 1.
// The reason is, it assumes that the first one (idx 0) is // The reason is, it assumes that the first one (idx 0) is
// the filename of executable file. // the filename of executable file.
argv.insert(argv.begin(), "dummy"); args.insert(args.begin(), "dummy");
int argc = argv.size(); std::vector<char *> argv;
char **arr = new char *[argv.size()];
std::string line; std::string line;
for (size_t i = 0; i < argv.size(); i++) { int argc = args.size();
arr[i] = &argv[i][0]; for (auto &arg : args) {
line += argv[i]; argv.push_back(const_cast<char *>(arg.data()));
line += arg;
line += ' '; line += ' ';
} }
VLOG(1) << "Before Parse: argc is " << argc VLOG(1) << "Before Parse: argc is " << argc
<< ", Init commandline: " << line; << ", Init commandline: " << line;
char **arr = argv.data();
google::ParseCommandLineFlags(&argc, &arr, true); google::ParseCommandLineFlags(&argc, &arr, true);
VLOG(1) << "After Parse: argc is " << argc;
successed = true; successed = true;
VLOG(1) << "After Parse: argc is " << argc;
}); });
return successed; return successed;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册