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

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

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