diff --git a/adb/adb_listeners.cpp b/adb/adb_listeners.cpp index a142384be..fecf452c1 100644 --- a/adb/adb_listeners.cpp +++ b/adb/adb_listeners.cpp @@ -29,6 +29,7 @@ #include "socket_spec.h" #include "sysdeps.h" +#include "sysdeps/memory.h" #include "transport.h" // A listener is an entity which binds to a local port and, upon receiving a connection on that @@ -203,7 +204,7 @@ InstallStatus install_listener(const std::string& local_name, const char* connec } } - std::unique_ptr listener(new alistener(local_name, connect_to)); + auto listener = std::make_unique(local_name, connect_to); int resolved = 0; listener->fd = socket_spec_listen(listener->local_name, error, &resolved); diff --git a/adb/commandline.cpp b/adb/commandline.cpp index 6a80bcd36..546321e9c 100644 --- a/adb/commandline.cpp +++ b/adb/commandline.cpp @@ -61,6 +61,7 @@ #include "services.h" #include "shell_service.h" #include "sysdeps/chrono.h" +#include "sysdeps/memory.h" static int install_app(int argc, const char** argv); static int install_multiple_app(int argc, const char** argv); @@ -263,7 +264,7 @@ int read_and_dump(int fd, bool use_shell_protocol = false, char raw_buffer[BUFSIZ]; char* buffer_ptr = raw_buffer; if (use_shell_protocol) { - protocol.reset(new ShellProtocol(fd)); + protocol = std::make_unique(fd); if (!protocol) { LOG(ERROR) << "failed to allocate memory for ShellProtocol object"; return 1; @@ -630,7 +631,7 @@ static int RemoteShell(bool use_shell_protocol, const std::string& type_arg, args->raw_stdin = raw_stdin; args->escape_char = escape_char; if (use_shell_protocol) { - args->protocol.reset(new ShellProtocol(args->write_fd)); + args->protocol = std::make_unique(args->write_fd); } if (raw_stdin) stdin_raw_init(); diff --git a/adb/fdevent_test.cpp b/adb/fdevent_test.cpp index 63cc4d176..dadae5ab7 100644 --- a/adb/fdevent_test.cpp +++ b/adb/fdevent_test.cpp @@ -99,7 +99,7 @@ static void FdEventThreadFunc(ThreadArg* arg) { std::vector> fd_handlers; for (size_t i = 0; i < read_fds.size(); ++i) { - fd_handlers.push_back(std::unique_ptr(new FdHandler(read_fds[i], write_fds[i]))); + fd_handlers.push_back(std::make_unique(read_fds[i], write_fds[i])); } fdevent_loop(); diff --git a/adb/shell_service.cpp b/adb/shell_service.cpp index f9f80c03d..c04ceafa7 100644 --- a/adb/shell_service.cpp +++ b/adb/shell_service.cpp @@ -372,8 +372,8 @@ bool Subprocess::ForkAndExec(std::string* error) { } D("protocol FD = %d", protocol_sfd_.get()); - input_.reset(new ShellProtocol(protocol_sfd_)); - output_.reset(new ShellProtocol(protocol_sfd_)); + input_ = std::make_unique(protocol_sfd_); + output_ = std::make_unique(protocol_sfd_); if (!input_ || !output_) { *error = "failed to allocate shell protocol objects"; kill(pid_, SIGKILL); diff --git a/adb/sysdeps/memory.h b/adb/sysdeps/memory.h new file mode 100644 index 000000000..0e4c509f6 --- /dev/null +++ b/adb/sysdeps/memory.h @@ -0,0 +1,36 @@ +#pragma once + +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#if defined(_WIN32) +// We don't have C++14 on Windows yet. +// Reimplement std::make_unique ourselves until we do. + +namespace std { + +template +typename std::enable_if::value, std::unique_ptr>::type make_unique( + Args&&... args) { + return std::unique_ptr(new T(std::forward(args)...)); +} + +} // namespace std + +#endif