Merge remote-tracking branch 'td/master'

This commit is contained in:
Andrea Cavalli 2021-12-10 16:59:45 +01:00
commit c037048ec3
33 changed files with 192 additions and 124 deletions

View File

@ -3,17 +3,20 @@ Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Left
AlignOperands: true
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: None # All
AllowShortIfStatementsOnASingleLine: Never # WithoutElse
AllowShortLambdasOnASingleLine: Inline # All
@ -24,10 +27,11 @@ AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
@ -37,12 +41,15 @@ BraceWrapping:
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeConceptDeclarations: true
BreakBeforeInheritanceComma: true # false
BreakInheritanceList: BeforeComma # BeforeColon
BreakBeforeTernaryOperators: true
@ -60,21 +67,30 @@ Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- Q_FOREACH_THIS_LIST_MUST_BE_NON_EMPTY
IncludeBlocks: Preserve
#IndentCaseBlocks: false
IncludeCategories:
- Regex: '.*'
Priority: 0
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequires: false
IndentWidth: 2
IndentWrappedFunctionNames: false
# InsertTrailingCommas: None
# JavaScriptQuotes: Leave
# JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
@ -91,15 +107,22 @@ PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: false # true
SortIncludes: false # disabled, because we need case insensitive sort
ShortNamespaceLines: 0 # 1
SortIncludes: CaseInsensitive # CaseSensitive
# SortJavaStaticImport: Before
SortUsingDeclarations: false # true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
@ -109,10 +132,13 @@ SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: 1 # -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto

View File

@ -219,7 +219,7 @@ function split_file($file, $chunks, $undo) {
$new_content = $common.$namespace_begin.$f.$namespace_end;
$std_methods = array();
preg_match_all('/std::[a-z_0-9]*/', $new_content, $std_methods);
preg_match_all('/std::[a-z_0-9]*|td::unique(?!_)/', $new_content, $std_methods);
$std_methods = array_unique($std_methods[0]);
$needed_std_headers = array();
@ -230,6 +230,7 @@ function split_file($file, $chunks, $undo) {
'std::uint32_t' => '',
'std::int32_t' => '',
'std::int64_t' => '',
'td::unique' => 'algorithm',
'std::fill' => 'algorithm',
'std::find' => 'algorithm',
'std::max' => 'algorithm',

View File

@ -1079,6 +1079,7 @@ class ToggleSlowModeQuery final : public Td::ResultHandler {
class ReportChannelSpamQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
DialogId sender_dialog_id_;
public:
explicit ReportChannelSpamQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
@ -1086,6 +1087,7 @@ class ReportChannelSpamQuery final : public Td::ResultHandler {
void send(ChannelId channel_id, DialogId sender_dialog_id, const vector<MessageId> &message_ids) {
channel_id_ = channel_id;
sender_dialog_id_ = sender_dialog_id;
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
CHECK(input_channel != nullptr);
@ -1110,7 +1112,9 @@ class ReportChannelSpamQuery final : public Td::ResultHandler {
}
void on_error(Status status) final {
// td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ReportChannelSpamQuery");
if (sender_dialog_id_.get_type() != DialogType::Channel) {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ReportChannelSpamQuery");
}
promise_.set_error(std::move(status));
}
};
@ -2127,14 +2131,16 @@ class EditChannelAdminQuery final : public Td::ResultHandler {
class EditChannelBannedQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
DialogId participant_dialog_id_;
public:
explicit EditChannelBannedQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId channel_id, tl_object_ptr<telegram_api::InputPeer> &&input_peer,
void send(ChannelId channel_id, DialogId participant_dialog_id, tl_object_ptr<telegram_api::InputPeer> &&input_peer,
const DialogParticipantStatus &status) {
channel_id_ = channel_id;
participant_dialog_id_ = participant_dialog_id;
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
CHECK(input_channel != nullptr);
send_query(G()->net_query_creator().create(telegram_api::channels_editBanned(
@ -2154,7 +2160,9 @@ class EditChannelBannedQuery final : public Td::ResultHandler {
}
void on_error(Status status) final {
if (participant_dialog_id_.get_type() != DialogType::Channel) {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "EditChannelBannedQuery");
}
promise_.set_error(std::move(status));
td_->updates_manager_->get_difference("EditChannelBannedQuery");
}
@ -2737,7 +2745,9 @@ class GetChannelParticipantQuery final : public Td::ResultHandler {
return;
}
// td_->contacts_manager_->on_get_channel_error(channel_id_, status, "GetChannelParticipantQuery");
if (participant_dialog_id_.get_type() != DialogType::Channel) {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "GetChannelParticipantQuery");
}
promise_.set_error(std::move(status));
}
};
@ -7573,7 +7583,8 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogI
if (participant_dialog_id.get_type() == DialogType::User) {
speculative_add_channel_user(channel_id, participant_dialog_id.get_user_id(), status, old_status);
}
td_->create_handler<EditChannelBannedQuery>(std::move(promise))->send(channel_id, std::move(input_peer), status);
td_->create_handler<EditChannelBannedQuery>(std::move(promise))
->send(channel_id, participant_dialog_id, std::move(input_peer), status);
}
ChannelId ContactsManager::migrate_chat_to_megagroup(ChatId chat_id, Promise<Unit> &promise) {

View File

@ -2873,12 +2873,17 @@ class BlockFromRepliesQuery final : public Td::ResultHandler {
class DeleteParticipantHistoryQuery final : public Td::ResultHandler {
Promise<AffectedHistory> promise_;
ChannelId channel_id_;
DialogId sender_dialog_id_;
public:
explicit DeleteParticipantHistoryQuery(Promise<AffectedHistory> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId channel_id, DialogId sender_dialog_id) {
channel_id_ = channel_id;
sender_dialog_id_ = sender_dialog_id;
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
if (input_channel == nullptr) {
return promise_.set_error(Status::Error(400, "Chat is not accessible"));
@ -2902,7 +2907,9 @@ class DeleteParticipantHistoryQuery final : public Td::ResultHandler {
}
void on_error(Status status) final {
// td_->contacts_manager_->on_get_channel_error(channel_id_, status, "DeleteParticipantHistoryQuery");
if (sender_dialog_id_.get_type() != DialogType::Channel) {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "DeleteParticipantHistoryQuery");
}
promise_.set_error(std::move(status));
}
};
@ -12178,6 +12185,30 @@ void MessagesManager::set_dialog_online_member_count(DialogId dialog_id, int32 o
return;
}
if (online_member_count < 0) {
LOG(ERROR) << "Receive online_member_count = " << online_member_count << " in " << dialog_id;
online_member_count = 0;
}
switch (dialog_id.get_type()) {
case DialogType::Chat: {
auto participant_count = td_->contacts_manager_->get_chat_participant_count(dialog_id.get_chat_id());
if (online_member_count > participant_count) {
online_member_count = participant_count;
}
break;
}
case DialogType::Channel: {
auto participant_count = td_->contacts_manager_->get_channel_participant_count(dialog_id.get_channel_id());
if (participant_count != 0 && online_member_count > participant_count) {
online_member_count = participant_count;
}
break;
}
default:
break;
}
auto &info = dialog_online_member_counts_[dialog_id];
LOG(INFO) << "Change number of online members from " << info.online_member_count << " to " << online_member_count
<< " in " << dialog_id << " from " << source;

View File

@ -8,7 +8,6 @@
#include "td/utils/logging.h"
#include "td/utils/port/thread_local.h"
#include "td/utils/ThreadSafeCounter.h"
#include <cstddef>
#include <new>
@ -26,20 +25,14 @@ TD_THREAD_LOCAL BufferAllocator::BufferRawTls *BufferAllocator::buffer_raw_tls;
std::atomic<size_t> BufferAllocator::buffer_mem;
static ThreadSafeCounter buffer_slice_size_;
int64 BufferAllocator::get_buffer_slice_size() {
return buffer_slice_size_.sum();
return 0;
}
void BufferAllocator::track_buffer_slice(int64 size) {
if (size == 0) {
return;
}
buffer_slice_size_.add(size);
}
size_t BufferAllocator::get_buffer_mem() {
return buffer_mem;
}

View File

@ -30,8 +30,8 @@
#define REF_NEW ref new
#define CLRCALL
#define DEPRECATED_ATTRIBUTE(message) ::Windows::Foundation::Metadata::Deprecated(message,\
::Windows::Foundation::Metadata::DeprecationType::Deprecate, 0x0)
#define DEPRECATED_ATTRIBUTE(message) \
::Windows::Foundation::Metadata::Deprecated(message, ::Windows::Foundation::Metadata::DeprecationType::Deprecate, 0x0)
namespace CxCli {
@ -73,6 +73,7 @@ public:
std::lock_guard<std::mutex> guard(mutex_);
return impl_[key];
}
private:
std::mutex mutex_;
std::map<Key, Value> impl_;

View File

@ -103,7 +103,7 @@ StringBuilder &operator<<(StringBuilder &sb, const PrintFlags &print_flags) {
namespace detail {
class FileFdImpl {
public:
PollableFdInfo info;
PollableFdInfo info_;
};
} // namespace detail
@ -242,8 +242,8 @@ Result<FileFd> FileFd::open(CSlice filepath, int32 flags, int32 mode) {
FileFd FileFd::from_native_fd(NativeFd native_fd) {
auto impl = make_unique<detail::FileFdImpl>();
impl->info.set_native_fd(std::move(native_fd));
impl->info.add_flags(PollFlags::Write());
impl->info_.set_native_fd(std::move(native_fd));
impl->info_.add_flags(PollFlags::Write());
return FileFd(std::move(impl));
}
@ -648,11 +648,11 @@ Status FileFd::truncate_to_current_position(int64 current_position) {
}
PollableFdInfo &FileFd::get_poll_info() {
CHECK(!empty());
return impl_->info;
return impl_->info_;
}
const PollableFdInfo &FileFd::get_poll_info() const {
CHECK(!empty());
return impl_->info;
return impl_->info_;
}
} // namespace td

View File

@ -43,7 +43,7 @@ namespace detail {
#if TD_PORT_WINDOWS
class SocketFdImpl final : private Iocp::Callback {
public:
explicit SocketFdImpl(NativeFd native_fd) : info(std::move(native_fd)) {
explicit SocketFdImpl(NativeFd native_fd) : info_(std::move(native_fd)) {
VLOG(fd) << get_native_fd() << " create from native_fd";
get_poll_info().add_flags(PollFlags::Write());
Iocp::get()->subscribe(get_native_fd(), this);
@ -51,7 +51,7 @@ class SocketFdImpl final : private Iocp::Callback {
notify_iocp_connected();
}
SocketFdImpl(NativeFd native_fd, const IPAddress &addr) : info(std::move(native_fd)) {
SocketFdImpl(NativeFd native_fd, const IPAddress &addr) : info_(std::move(native_fd)) {
VLOG(fd) << get_native_fd() << " create from native_fd and connect";
get_poll_info().add_flags(PollFlags::Write());
Iocp::get()->subscribe(get_native_fd(), this);
@ -88,14 +88,14 @@ class SocketFdImpl final : private Iocp::Callback {
}
PollableFdInfo &get_poll_info() {
return info;
return info_;
}
const PollableFdInfo &get_poll_info() const {
return info;
return info_;
}
const NativeFd &get_native_fd() const {
return info.native_fd();
return info_.native_fd();
}
Result<size_t> write(Slice data) {
@ -161,7 +161,7 @@ class SocketFdImpl final : private Iocp::Callback {
}
private:
PollableFdInfo info;
PollableFdInfo info_;
SpinLock lock_;
std::atomic<int> refcnt_{1};
@ -283,7 +283,12 @@ class SocketFdImpl final : private Iocp::Callback {
if (overlapped == reinterpret_cast<WSAOVERLAPPED *>(&close_overlapped_)) {
return on_close();
}
UNREACHABLE();
LOG(ERROR) << this << ' ' << overlapped << ' ' << &read_overlapped_ << ' ' << &write_overlapped_ << ' '
<< reinterpret_cast<WSAOVERLAPPED *>(&close_overlapped_) << ' ' << size;
LOG(FATAL) << get_native_fd() << ' ' << info_.get_flags_local() << ' ' << refcnt_.load() << ' ' << close_flag_
<< ' ' << need_close_after_write_ << ' ' << is_connected_ << ' ' << is_read_active_ << ' '
<< is_write_active_ << ' ' << is_write_waiting_.load() << ' ' << input_reader_.size() << ' '
<< output_reader_.size();
}
void on_error(Status status) {
@ -335,7 +340,7 @@ class SocketFdImpl final : private Iocp::Callback {
void on_close() {
VLOG(fd) << get_native_fd() << " on close";
close_flag_ = true;
info.set_native_fd({});
info_.set_native_fd({});
}
bool dec_refcnt() {
VLOG(fd) << get_native_fd() << " dec_refcnt from " << refcnt_;
@ -386,18 +391,18 @@ static InitWSA init_wsa;
#else
class SocketFdImpl {
public:
PollableFdInfo info;
explicit SocketFdImpl(NativeFd fd) : info(std::move(fd)) {
PollableFdInfo info_;
explicit SocketFdImpl(NativeFd fd) : info_(std::move(fd)) {
}
PollableFdInfo &get_poll_info() {
return info;
return info_;
}
const PollableFdInfo &get_poll_info() const {
return info;
return info_;
}
const NativeFd &get_native_fd() const {
return info.native_fd();
return info_.native_fd();
}
Result<size_t> writev(Span<IoSlice> slices) {

View File

@ -29,7 +29,7 @@ namespace td {
namespace detail {
class EventFdLinuxImpl {
public:
PollableFdInfo info;
PollableFdInfo info_;
};
EventFdLinux::EventFdLinux() = default;
@ -42,7 +42,7 @@ void EventFdLinux::init() {
auto eventfd_errno = errno;
LOG_IF(FATAL, !fd) << Status::PosixError(eventfd_errno, "eventfd call failed");
impl_ = make_unique<EventFdLinuxImpl>();
impl_->info.set_native_fd(std::move(fd));
impl_->info_.set_native_fd(std::move(fd));
}
bool EventFdLinux::empty() {
@ -58,14 +58,14 @@ Status EventFdLinux::get_pending_error() {
}
PollableFdInfo &EventFdLinux::get_poll_info() {
return impl_->info;
return impl_->info_;
}
// NB: will be called from multiple threads
void EventFdLinux::release() {
const uint64 value = 1;
auto slice = Slice(reinterpret_cast<const char *>(&value), sizeof(value));
auto native_fd = impl_->info.native_fd().fd();
auto native_fd = impl_->info_.native_fd().fd();
auto result = [&]() -> Result<size_t> {
auto write_res = detail::skip_eintr([&] { return write(native_fd, slice.begin(), slice.size()); });
@ -86,7 +86,7 @@ void EventFdLinux::release() {
}
void EventFdLinux::acquire() {
impl_->info.sync_with_poll();
impl_->info_.sync_with_poll();
SCOPE_EXIT {
// Clear flags without EAGAIN and EWOULDBLOCK
// Looks like it is safe thing to do with eventfd
@ -94,7 +94,7 @@ void EventFdLinux::acquire() {
};
uint64 res;
auto slice = MutableSlice(reinterpret_cast<char *>(&res), sizeof(res));
auto native_fd = impl_->info.native_fd().fd();
auto native_fd = impl_->info_.native_fd().fd();
auto result = [&]() -> Result<size_t> {
CHECK(!slice.empty());
auto read_res = detail::skip_eintr([&] { return ::read(native_fd, slice.begin(), slice.size()); });