From f948956bf789926e8a1f0456d93c8786d78eb2d7 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 27 Sep 2018 04:19:03 +0300 Subject: [PATCH] Use td::unique_ptr instead of std::unique_ptr whenever possible. GitOrigin-RevId: 424beb72dc62efdefdbffb75f1036ba9417f84cb --- benchmark/bench_actor.cpp | 4 +- benchmark/bench_db.cpp | 6 +- benchmark/bench_tddb.cpp | 4 +- benchmark/wget.cpp | 2 +- example/cpp/td_example.cpp | 1 + td/mtproto/HandshakeActor.cpp | 13 ++- td/mtproto/HandshakeActor.h | 18 ++-- td/mtproto/HandshakeConnection.h | 10 +-- td/mtproto/IStreamTransport.cpp | 8 +- td/mtproto/IStreamTransport.h | 2 +- td/mtproto/PingConnection.h | 6 +- td/mtproto/RawConnection.h | 4 +- td/mtproto/SessionConnection.cpp | 2 +- td/mtproto/SessionConnection.h | 5 +- td/telegram/AnimationsManager.cpp | 4 +- td/telegram/AnimationsManager.h | 2 +- td/telegram/AudiosManager.cpp | 6 +- td/telegram/AudiosManager.h | 2 +- td/telegram/Client.cpp | 8 +- td/telegram/ConfigManager.cpp | 8 +- td/telegram/ContactsManager.cpp | 3 +- td/telegram/ContactsManager.h | 2 +- td/telegram/DialogDb.cpp | 4 +- td/telegram/DocumentsManager.cpp | 4 +- td/telegram/DocumentsManager.h | 2 +- td/telegram/Global.cpp | 8 +- td/telegram/Global.h | 16 ++-- td/telegram/LanguagePackManager.cpp | 7 +- td/telegram/LanguagePackManager.h | 2 +- td/telegram/MessagesDb.cpp | 4 +- td/telegram/MessagesManager.cpp | 48 +++++----- td/telegram/Payments.cpp | 11 +-- td/telegram/SecretChatActor.cpp | 33 ++++--- td/telegram/SecretChatActor.h | 32 +++---- td/telegram/SecretChatsManager.cpp | 32 +++---- td/telegram/SecretChatsManager.h | 12 +-- td/telegram/StickersManager.cpp | 4 +- td/telegram/StickersManager.h | 2 +- td/telegram/Td.cpp | 26 +++--- td/telegram/Td.h | 18 ++-- td/telegram/TdDb.cpp | 11 ++- td/telegram/TdDb.h | 5 +- td/telegram/VideoNotesManager.cpp | 4 +- td/telegram/VideoNotesManager.h | 2 +- td/telegram/VideosManager.cpp | 4 +- td/telegram/VideosManager.h | 2 +- td/telegram/VoiceNotesManager.cpp | 6 +- td/telegram/VoiceNotesManager.h | 2 +- td/telegram/WebPagesManager.cpp | 40 ++++----- td/telegram/files/FileDownloader.cpp | 2 +- td/telegram/files/FileDownloader.h | 4 +- td/telegram/files/FileFromBytes.cpp | 2 +- td/telegram/files/FileFromBytes.h | 4 +- td/telegram/files/FileGenerateManager.cpp | 16 ++-- td/telegram/files/FileGenerateManager.h | 3 +- td/telegram/files/FileHashUploader.h | 2 +- td/telegram/files/FileLocation.h | 2 +- td/telegram/files/FileManager.cpp | 19 ++-- td/telegram/files/FileManager.h | 6 +- td/telegram/files/FileUploader.cpp | 2 +- td/telegram/files/FileUploader.h | 4 +- td/telegram/files/ResourceManager.cpp | 2 +- td/telegram/files/ResourceManager.h | 2 +- td/telegram/logevent/LogEvent.h | 8 +- td/telegram/net/ConnectionCreator.cpp | 88 +++++++++---------- td/telegram/net/ConnectionCreator.h | 20 ++--- td/telegram/net/DcAuthManager.cpp | 2 +- td/telegram/net/DcOptionsSet.cpp | 4 +- td/telegram/net/DcOptionsSet.h | 4 +- td/telegram/net/NetStatsManager.cpp | 2 +- td/telegram/net/PublicRsaKeyShared.cpp | 2 +- td/telegram/net/PublicRsaKeyShared.h | 4 +- td/telegram/net/PublicRsaKeyWatchdog.cpp | 2 +- td/telegram/net/Session.cpp | 36 ++++---- td/telegram/net/Session.h | 12 +-- td/telegram/net/SessionProxy.cpp | 4 +- td/telegram/net/TempAuthKeyWatchdog.h | 4 +- tdactor/td/actor/MultiPromise.h | 8 +- tdactor/td/actor/PromiseFuture.h | 22 ++--- tdactor/td/actor/impl/ActorInfo-decl.h | 2 +- tdactor/td/actor/impl/ActorInfo.h | 2 +- tdactor/td/actor/impl/ConcurrentScheduler.cpp | 2 +- tdactor/td/actor/impl/ConcurrentScheduler.h | 2 +- tdactor/td/actor/impl/Scheduler-decl.h | 2 +- tdactor/td/actor/impl/Scheduler.h | 2 +- tdactor/test/actors_bugs.cpp | 4 +- tdactor/test/actors_main.cpp | 6 +- tdactor/test/actors_workers.cpp | 2 +- tddb/td/db/BinlogKeyValue.h | 2 +- tddb/td/db/SqliteKeyValueAsync.cpp | 6 +- tddb/td/db/SqliteKeyValueAsync.h | 4 +- tddb/td/db/binlog/Binlog.cpp | 4 +- tddb/td/db/binlog/Binlog.h | 4 +- tddb/td/db/binlog/ConcurrentBinlog.cpp | 10 +-- tddb/td/db/binlog/ConcurrentBinlog.h | 4 +- tdnet/td/net/HttpQuery.h | 2 +- tdnet/td/net/NetStats.h | 6 +- tdnet/td/net/SslStream.cpp | 4 +- tdnet/td/net/SslStream.h | 4 +- tdnet/td/net/TransparentProxy.cpp | 2 +- tdnet/td/net/TransparentProxy.h | 4 +- tdutils/td/utils/DecTree.h | 24 ++--- tdutils/td/utils/Destructor.h | 2 +- tdutils/td/utils/HazardPointers.h | 6 +- tdutils/td/utils/MpmcQueue.h | 4 +- tdutils/td/utils/MpscLinkQueue.h | 6 +- tdutils/td/utils/ScopeGuard.h | 4 +- tdutils/td/utils/SharedObjectPool.h | 8 +- tdutils/td/utils/SpinLock.h | 1 + tdutils/td/utils/StackAllocator.h | 1 + tdutils/td/utils/Status.h | 1 + tdutils/td/utils/buffer.h | 1 + tdutils/td/utils/crypto.cpp | 4 +- tdutils/td/utils/crypto.h | 4 +- tdutils/td/utils/port/FileFd.cpp | 4 +- tdutils/td/utils/port/FileFd.h | 4 +- tdutils/td/utils/port/RwMutex.h | 2 + tdutils/td/utils/port/ServerSocketFd.cpp | 6 +- tdutils/td/utils/port/ServerSocketFd.h | 4 +- tdutils/td/utils/port/SocketFd.cpp | 8 +- tdutils/td/utils/port/SocketFd.h | 4 +- tdutils/td/utils/port/StdStreams.cpp | 2 +- tdutils/td/utils/port/StdStreams.h | 1 + tdutils/td/utils/port/UdpSocketFd.cpp | 4 +- tdutils/td/utils/port/UdpSocketFd.h | 4 +- tdutils/td/utils/port/detail/EventFdLinux.cpp | 2 +- tdutils/td/utils/port/detail/EventFdLinux.h | 2 +- tdutils/td/utils/port/detail/PollableFd.h | 1 + tdutils/td/utils/port/detail/ThreadPthread.h | 2 +- tdutils/td/utils/port/thread_local.cpp | 6 +- tdutils/td/utils/port/thread_local.h | 2 +- tdutils/td/utils/tl_parsers.h | 5 +- tdutils/test/MpmcWaiter.cpp | 8 +- tdutils/test/MpscLinkQueue.cpp | 2 +- tdutils/test/misc.cpp | 3 +- tdutils/test/variant.cpp | 18 ++-- test/mtproto.cpp | 37 ++++---- test/secret.cpp | 14 +-- test/tdclient.cpp | 38 ++++---- 139 files changed, 541 insertions(+), 541 deletions(-) diff --git a/benchmark/bench_actor.cpp b/benchmark/bench_actor.cpp index adc57d05..9e88999a 100644 --- a/benchmark/bench_actor.cpp +++ b/benchmark/bench_actor.cpp @@ -136,7 +136,7 @@ class QueryBench : public td::Benchmark { virtual ~Callback() = default; virtual void on_result(int x) = 0; }; - explicit ClientActor(std::unique_ptr callback) : callback_(std::move(callback)) { + explicit ClientActor(td::unique_ptr callback) : callback_(std::move(callback)) { } void f(int x) { callback_->on_result(x * x); @@ -152,7 +152,7 @@ class QueryBench : public td::Benchmark { } private: - std::unique_ptr callback_; + td::unique_ptr callback_; }; class ServerActor : public td::Actor { diff --git a/benchmark/bench_db.cpp b/benchmark/bench_db.cpp index e43ab917..954222ed 100644 --- a/benchmark/bench_db.cpp +++ b/benchmark/bench_db.cpp @@ -167,13 +167,13 @@ class SqliteKeyValueAsyncBench : public td::Benchmark { } private: - std::unique_ptr scheduler_; + td::unique_ptr scheduler_; std::shared_ptr sql_connection_; std::shared_ptr sqlite_kv_safe_; - std::unique_ptr sqlite_kv_async_; + td::unique_ptr sqlite_kv_async_; td::Status do_start_up() { - scheduler_ = std::make_unique(); + scheduler_ = td::make_unique(); scheduler_->init(1); auto guard = scheduler_->get_main_guard(); diff --git a/benchmark/bench_tddb.cpp b/benchmark/bench_tddb.cpp index 3a776934..2b110126 100644 --- a/benchmark/bench_tddb.cpp +++ b/benchmark/bench_tddb.cpp @@ -76,13 +76,13 @@ class MessagesDbBench : public Benchmark { } private: - std::unique_ptr scheduler_; + td::unique_ptr scheduler_; std::shared_ptr sql_connection_; std::shared_ptr messages_db_sync_safe_; std::shared_ptr messages_db_async_; Status do_start_up() { - scheduler_ = std::make_unique(); + scheduler_ = make_unique(); scheduler_->init(1); auto guard = scheduler_->get_main_guard(); diff --git a/benchmark/wget.cpp b/benchmark/wget.cpp index 850c5b64..0103d7f1 100644 --- a/benchmark/wget.cpp +++ b/benchmark/wget.cpp @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) { auto timeout = 10; auto ttl = 3; auto prefer_ipv6 = (argc > 2 && std::string(argv[2]) == "-6"); - auto scheduler = std::make_unique(); + auto scheduler = td::make_unique(); scheduler->init(0); scheduler ->create_actor_unsafe(0, "Client", td::PromiseCreator::lambda([](td::Result res) { diff --git a/example/cpp/td_example.cpp b/example/cpp/td_example.cpp index e155226d..14a5f3c4 100644 --- a/example/cpp/td_example.cpp +++ b/example/cpp/td_example.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/td/mtproto/HandshakeActor.cpp b/td/mtproto/HandshakeActor.cpp index a3ea97e4..1ca40bd2 100644 --- a/td/mtproto/HandshakeActor.cpp +++ b/td/mtproto/HandshakeActor.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/mtproto/HandshakeActor.h" + #include "td/mtproto/HandshakeConnection.h" #include "td/utils/common.h" @@ -13,14 +14,12 @@ namespace td { namespace mtproto { -HandshakeActor::HandshakeActor(std::unique_ptr handshake, - std::unique_ptr raw_connection, - std::unique_ptr context, double timeout, - Promise> raw_connection_promise, - Promise> handshake_promise) +HandshakeActor::HandshakeActor(unique_ptr handshake, unique_ptr raw_connection, + unique_ptr context, double timeout, + Promise> raw_connection_promise, + Promise> handshake_promise) : handshake_(std::move(handshake)) - , connection_( - std::make_unique(std::move(raw_connection), handshake_.get(), std::move(context))) + , connection_(make_unique(std::move(raw_connection), handshake_.get(), std::move(context))) , timeout_(timeout) , raw_connection_promise_(std::move(raw_connection_promise)) , handshake_promise_(std::move(handshake_promise)) { diff --git a/td/mtproto/HandshakeActor.h b/td/mtproto/HandshakeActor.h index b5a02490..af53cf82 100644 --- a/td/mtproto/HandshakeActor.h +++ b/td/mtproto/HandshakeActor.h @@ -13,26 +13,28 @@ namespace td { namespace mtproto { + class AuthKeyHandshake; class AuthKeyHandshakeContext; class RawConnection; class HandshakeConnection; + // Has Raw connection. Generates new auth key. And returns it and raw_connection. Or error... class HandshakeActor : public Actor { public: - HandshakeActor(std::unique_ptr handshake, std::unique_ptr raw_connection, - std::unique_ptr context, double timeout, - Promise> raw_connection_promise, - Promise> handshake_promise); + HandshakeActor(unique_ptr handshake, unique_ptr raw_connection, + unique_ptr context, double timeout, + Promise> raw_connection_promise, + Promise> handshake_promise); void close(); private: - std::unique_ptr handshake_; - std::unique_ptr connection_; + unique_ptr handshake_; + unique_ptr connection_; double timeout_; - Promise> raw_connection_promise_; - Promise> handshake_promise_; + Promise> raw_connection_promise_; + Promise> handshake_promise_; void start_up() override; void tear_down() override { diff --git a/td/mtproto/HandshakeConnection.h b/td/mtproto/HandshakeConnection.h index f01f52e3..c5e3bf8e 100644 --- a/td/mtproto/HandshakeConnection.h +++ b/td/mtproto/HandshakeConnection.h @@ -26,8 +26,8 @@ class HandshakeConnection : private RawConnection::Callback , private AuthKeyHandshake::Callback { public: - HandshakeConnection(std::unique_ptr raw_connection, AuthKeyHandshake *handshake, - std::unique_ptr context) + HandshakeConnection(unique_ptr raw_connection, AuthKeyHandshake *handshake, + unique_ptr context) : raw_connection_(std::move(raw_connection)), handshake_(handshake), context_(std::move(context)) { handshake_->resume(this); } @@ -36,7 +36,7 @@ class HandshakeConnection return raw_connection_->get_poll_info(); } - std::unique_ptr move_as_raw_connection() { + unique_ptr move_as_raw_connection() { return std::move(raw_connection_); } @@ -54,9 +54,9 @@ class HandshakeConnection } private: - std::unique_ptr raw_connection_; + unique_ptr raw_connection_; AuthKeyHandshake *handshake_; - std::unique_ptr context_; + unique_ptr context_; void send_no_crypto(const Storer &storer) override { raw_connection_->send_no_crypto(PacketStorer(0, storer)); diff --git a/td/mtproto/IStreamTransport.cpp b/td/mtproto/IStreamTransport.cpp index 71bafc8b..f4a5cd74 100644 --- a/td/mtproto/IStreamTransport.cpp +++ b/td/mtproto/IStreamTransport.cpp @@ -13,14 +13,14 @@ namespace td { namespace mtproto { -std::unique_ptr create_transport(TransportType type) { +unique_ptr create_transport(TransportType type) { switch (type.type) { case TransportType::ObfuscatedTcp: - return std::make_unique(type.dc_id, std::move(type.secret)); + return td::make_unique(type.dc_id, std::move(type.secret)); case TransportType::Tcp: - return std::make_unique(); + return td::make_unique(); case TransportType::Http: - return std::make_unique(type.secret); + return td::make_unique(type.secret); } UNREACHABLE(); } diff --git a/td/mtproto/IStreamTransport.h b/td/mtproto/IStreamTransport.h index c38ab4e0..9b262030 100644 --- a/td/mtproto/IStreamTransport.h +++ b/td/mtproto/IStreamTransport.h @@ -34,6 +34,6 @@ class IStreamTransport { virtual TransportType get_type() const = 0; }; -std::unique_ptr create_transport(TransportType type); +unique_ptr create_transport(TransportType type); } // namespace mtproto } // namespace td diff --git a/td/mtproto/PingConnection.h b/td/mtproto/PingConnection.h index c880066f..68bbfb05 100644 --- a/td/mtproto/PingConnection.h +++ b/td/mtproto/PingConnection.h @@ -24,7 +24,7 @@ namespace mtproto { class PingConnection : private RawConnection::Callback { public: - PingConnection(std::unique_ptr raw_connection, size_t ping_count) + PingConnection(unique_ptr raw_connection, size_t ping_count) : raw_connection_(std::move(raw_connection)), ping_count_(ping_count) { } @@ -32,7 +32,7 @@ class PingConnection : private RawConnection::Callback { return raw_connection_->get_poll_info(); } - std::unique_ptr move_as_raw_connection() { + unique_ptr move_as_raw_connection() { return std::move(raw_connection_); } @@ -76,7 +76,7 @@ class PingConnection : private RawConnection::Callback { } private: - std::unique_ptr raw_connection_; + unique_ptr raw_connection_; size_t ping_count_ = 1; double start_time_ = 0.0; double finish_time_ = 0.0; diff --git a/td/mtproto/RawConnection.h b/td/mtproto/RawConnection.h index 39ba72ca..1e4572c2 100644 --- a/td/mtproto/RawConnection.h +++ b/td/mtproto/RawConnection.h @@ -42,7 +42,7 @@ class RawConnection { virtual void on_mtproto_error() = 0; }; RawConnection() = default; - RawConnection(SocketFd socket_fd, TransportType transport_type, std::unique_ptr stats_callback) + RawConnection(SocketFd socket_fd, TransportType transport_type, unique_ptr stats_callback) : socket_fd_(std::move(socket_fd)) , transport_(create_transport(transport_type)) , stats_callback_(std::move(stats_callback)) { @@ -116,7 +116,7 @@ class RawConnection { std::map quick_ack_to_token_; bool has_error_{false}; - std::unique_ptr stats_callback_; + unique_ptr stats_callback_; StateManager::ConnectionToken connection_token_; diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index 432f7688..a12b924e 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -659,7 +659,7 @@ Status SessionConnection::on_quick_ack(uint64 quick_ack_token) { callback_->on_message_ack(quick_ack_token); return Status::OK(); } -SessionConnection::SessionConnection(Mode mode, std::unique_ptr raw_connection, AuthData *auth_data, +SessionConnection::SessionConnection(Mode mode, unique_ptr raw_connection, AuthData *auth_data, DhCallback *dh_callback) : raw_connection_(std::move(raw_connection)), auth_data_(auth_data), dh_callback_(dh_callback) { state_ = Init; diff --git a/td/mtproto/SessionConnection.h b/td/mtproto/SessionConnection.h index 07bfa351..b5c965b0 100644 --- a/td/mtproto/SessionConnection.h +++ b/td/mtproto/SessionConnection.h @@ -66,8 +66,7 @@ class SessionConnection , private RawConnection::Callback { public: enum class Mode { Tcp, Http, HttpLongPoll }; - SessionConnection(Mode mode, std::unique_ptr raw_connection, AuthData *auth_data, - DhCallback *dh_callback); + SessionConnection(Mode mode, unique_ptr raw_connection, AuthData *auth_data, DhCallback *dh_callback); PollableFdInfo &get_poll_info(); @@ -181,7 +180,7 @@ class SessionConnection int64 main_message_id_ = 0; double created_at_ = 0; - std::unique_ptr raw_connection_; + unique_ptr raw_connection_; AuthData *auth_data_; SessionConnection::Callback *callback_ = nullptr; DhCallback *dh_callback_; diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index 66107372..6c7cd307 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -129,7 +129,7 @@ tl_object_ptr AnimationsManager::get_animation_object(FileId td_->file_manager_->get_file_object(file_id)); } -FileId AnimationsManager::on_get_animation(std::unique_ptr new_animation, bool replace) { +FileId AnimationsManager::on_get_animation(unique_ptr new_animation, bool replace) { auto file_id = new_animation->file_id; LOG(INFO) << (replace ? "Replace" : "Add") << " animation " << file_id << " of size " << new_animation->dimensions; auto &a = animations_[file_id]; @@ -200,7 +200,7 @@ FileId AnimationsManager::dup_animation(FileId new_id, FileId old_id) { CHECK(old_animation != nullptr); auto &new_animation = animations_[new_id]; CHECK(!new_animation); - new_animation = std::make_unique(*old_animation); + new_animation = make_unique(*old_animation); new_animation->file_id = new_id; new_animation->thumbnail.file_id = td_->file_manager_->dup_file_id(new_animation->thumbnail.file_id); return new_id; diff --git a/td/telegram/AnimationsManager.h b/td/telegram/AnimationsManager.h index 64657c14..8f43f833 100644 --- a/td/telegram/AnimationsManager.h +++ b/td/telegram/AnimationsManager.h @@ -99,7 +99,7 @@ class AnimationsManager : public Actor { const Animation *get_animation(FileId file_id) const; - FileId on_get_animation(std::unique_ptr new_animation, bool replace); + FileId on_get_animation(unique_ptr new_animation, bool replace); int32 get_saved_animations_hash(const char *source) const; diff --git a/td/telegram/AudiosManager.cpp b/td/telegram/AudiosManager.cpp index 37536d5d..e8fbd09d 100644 --- a/td/telegram/AudiosManager.cpp +++ b/td/telegram/AudiosManager.cpp @@ -43,7 +43,7 @@ tl_object_ptr AudiosManager::get_audio_object(FileId file_id) { get_photo_size_object(td_->file_manager_.get(), &audio->thumbnail), td_->file_manager_->get_file_object(file_id)); } -FileId AudiosManager::on_get_audio(std::unique_ptr