[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/08: Use std::vector::data()
From: |
Ludovic Courtès |
Subject: |
02/08: Use std::vector::data() |
Date: |
Thu, 02 Jul 2015 22:34:04 +0000 |
civodul pushed a commit to branch nix
in repository guix.
commit 5dfea34048aa8541f20aeb2fbcd163561b609a49
Author: Eelco Dolstra <address@hidden>
Date: Thu Jul 2 22:51:33 2015 +0200
Use std::vector::data()
---
nix/libstore/build.cc | 7 ++-----
nix/libutil/util.cc | 11 +++++------
nix/libutil/util.hh | 2 +-
3 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 11ca6cf..7159d7b 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -2174,7 +2174,6 @@ void DerivationGoal::runChild()
Strings envStrs;
foreach (Environment::const_iterator, i, env)
envStrs.push_back(rewriteHashes(i->first + "=" + i->second,
rewritesToTmp));
- auto envArr = stringsToCharPtrs(envStrs);
/* If we are running in `build-users' mode, then switch to the
user we allocated above. Make sure that we drop all root
@@ -2205,7 +2204,6 @@ void DerivationGoal::runChild()
args.push_back(builderBasename);
foreach (Strings::iterator, i, drv.args)
args.push_back(rewriteHashes(*i, rewritesToTmp));
- auto argArr = stringsToCharPtrs(args);
restoreSIGPIPE();
@@ -2213,7 +2211,7 @@ void DerivationGoal::runChild()
writeFull(STDERR_FILENO, "\n");
/* Execute the program. This should not return. */
- execve(drv.builder.c_str(), (char * *) &argArr[0], (char * *)
&envArr[0]);
+ execve(drv.builder.c_str(), stringsToCharPtrs(args).data(),
stringsToCharPtrs(envStrs).data());
throw SysError(format("executing `%1%'") % drv.builder);
@@ -2843,7 +2841,6 @@ void SubstitutionGoal::tryToRun()
args.push_back("--substitute");
args.push_back(storePath);
args.push_back(destPath);
- auto argArr = stringsToCharPtrs(args);
/* Fork the substitute program. */
pid = startProcess([&]() {
@@ -2853,7 +2850,7 @@ void SubstitutionGoal::tryToRun()
if (dup2(outPipe.writeSide, STDOUT_FILENO) == -1)
throw SysError("cannot dup output pipe into stdout");
- execv(sub.c_str(), (char * *) &argArr[0]);
+ execv(sub.c_str(), stringsToCharPtrs(args).data());
throw SysError(format("executing `%1%'") % sub);
});
diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc
index dab4235..14026ab 100644
--- a/nix/libutil/util.cc
+++ b/nix/libutil/util.cc
@@ -897,10 +897,10 @@ pid_t startProcess(std::function<void()> fun,
}
-std::vector<const char *> stringsToCharPtrs(const Strings & ss)
+std::vector<char *> stringsToCharPtrs(const Strings & ss)
{
- std::vector<const char *> res;
- for (auto & s : ss) res.push_back(s.c_str());
+ std::vector<char *> res;
+ for (auto & s : ss) res.push_back((char *) s.c_str());
res.push_back(0);
return res;
}
@@ -921,12 +921,11 @@ string runProgram(Path program, bool searchPath, const
Strings & args)
Strings args_(args);
args_.push_front(program);
- auto cargs = stringsToCharPtrs(args_);
if (searchPath)
- execvp(program.c_str(), (char * *) &cargs[0]);
+ execvp(program.c_str(), stringsToCharPtrs(args_).data());
else
- execv(program.c_str(), (char * *) &cargs[0]);
+ execv(program.c_str(), stringsToCharPtrs(args_).data());
throw SysError(format("executing `%1%'") % program);
});
diff --git a/nix/libutil/util.hh b/nix/libutil/util.hh
index 6a84ed8..24e16ba 100644
--- a/nix/libutil/util.hh
+++ b/nix/libutil/util.hh
@@ -284,7 +284,7 @@ MakeError(ExecError, Error)
/* Convert a list of strings to a null-terminated vector of char
*'s. The result must not be accessed beyond the lifetime of the
list of strings. */
-std::vector<const char *> stringsToCharPtrs(const Strings & ss);
+std::vector<char *> stringsToCharPtrs(const Strings & ss);
/* Close all file descriptors except stdin, stdout, stderr, and those
listed in the given set. Good practice in child processes. */
- branch nix updated (e531520 -> 0dccab9), Ludovic Courtès, 2015/07/02
- 01/08: Allow substitutes for builds that have preferLocalBuild set, Ludovic Courtès, 2015/07/02
- 03/08: Export outputPaths function, Ludovic Courtès, 2015/07/02
- 04/08: Make /nix/var/nix/db/reserved bigger, Ludovic Courtès, 2015/07/02
- 05/08: Use posix_fallocate to create /nix/var/nix/db/reserved, Ludovic Courtès, 2015/07/02
- 06/08: GC: Handle ENOSPC creating/moving to the trash directory, Ludovic Courtès, 2015/07/02
- 02/08: Use std::vector::data(),
Ludovic Courtès <=
- 08/08: Typo, Ludovic Courtès, 2015/07/02
- 07/08: Preserve supplementary groups of build users, Ludovic Courtès, 2015/07/02