From 1d03469685f7b1f0ce2113a44e93c573f8329c05 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Tue, 19 May 2020 13:06:48 +0800 Subject: [PATCH] use vector instead of pointer, test=develop (#24620) --- paddle/fluid/platform/init.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/paddle/fluid/platform/init.cc b/paddle/fluid/platform/init.cc index 4113379f5b..8ec57d7719 100644 --- a/paddle/fluid/platform/init.cc +++ b/paddle/fluid/platform/init.cc @@ -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 argv) { +bool InitGflags(std::vector args) { bool successed = false; std::call_once(gflags_init_flag, [&]() { FLAGS_logtostderr = true; @@ -59,20 +59,23 @@ bool InitGflags(std::vector 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 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(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; } -- GitLab