aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-01-16 22:24:29 +0100
committerEelco Dolstra <edolstra@gmail.com>2017-01-16 22:24:49 +0100
commit2b9d0a99cbf7649c20492bc539e2823a2d2e57c5 (patch)
treebdf06b8448c4f8b619383bda5284e7b4ee1219d6
parent40dfac968a87c1d90b5b3c9e3ffe72a370165047 (diff)
AutoDeleteArray -> std::unique_ptr
Also, switch to C++14 for std::make_unique.
-rw-r--r--Makefile2
-rw-r--r--src/libstore/remote-store.cc5
-rw-r--r--src/libutil/serialise.cc8
-rw-r--r--src/libutil/util.cc7
-rw-r--r--src/libutil/util.hh12
5 files changed, 10 insertions, 24 deletions
diff --git a/Makefile b/Makefile
index 2ee40b56b..3f80aafb8 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@ makefiles = \
tests/local.mk
#src/download-via-ssh/local.mk \
-GLOBAL_CXXFLAGS += -std=c++11 -g -Wall
+GLOBAL_CXXFLAGS += -std=c++14 -g -Wall
-include Makefile.config
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 77faa2f80..816d95ba6 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -599,9 +599,8 @@ void RemoteStore::Connection::processStderr(Sink * sink, Source * source)
else if (msg == STDERR_READ) {
if (!source) throw Error("no source");
size_t len = readInt(from);
- unsigned char * buf = new unsigned char[len];
- AutoDeleteArray<unsigned char> d(buf);
- writeString(buf, source->read(buf, len), to);
+ auto buf = std::make_unique<unsigned char[]>(len);
+ writeString(buf.get(), source->read(buf.get(), len), to);
to.flush();
}
else
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index 24c6d1073..a68f7a0fa 100644
--- a/src/libutil/serialise.cc
+++ b/src/libutil/serialise.cc
@@ -3,6 +3,7 @@
#include <cstring>
#include <cerrno>
+#include <memory>
namespace nix {
@@ -236,11 +237,10 @@ size_t readString(unsigned char * buf, size_t max, Source & source)
string readString(Source & source)
{
size_t len = readInt(source);
- unsigned char * buf = new unsigned char[len];
- AutoDeleteArray<unsigned char> d(buf);
- source(buf, len);
+ auto buf = std::make_unique<unsigned char[]>(len);
+ source(buf.get(), len);
readPadding(len, source);
- return string((char *) buf, len);
+ return string((char *) buf.get(), len);
}
Source & operator >> (Source & in, string & s)
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index ce16cc30a..0e1849df0 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -272,11 +272,10 @@ string readFile(int fd)
if (fstat(fd, &st) == -1)
throw SysError("statting file");
- unsigned char * buf = new unsigned char[st.st_size];
- AutoDeleteArray<unsigned char> d(buf);
- readFull(fd, buf, st.st_size);
+ auto buf = std::make_unique<unsigned char[]>(st.st_size);
+ readFull(fd, buf.get(), st.st_size);
- return string((char *) buf, st.st_size);
+ return string((char *) buf.get(), st.st_size);
}
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 50b96f7ed..d42099781 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -139,18 +139,6 @@ string drainFD(int fd);
/* Automatic cleanup of resources. */
-template <class T>
-struct AutoDeleteArray
-{
- T * p;
- AutoDeleteArray(T * p) : p(p) { }
- ~AutoDeleteArray()
- {
- delete [] p;
- }
-};
-
-
class AutoDelete
{
Path path;