A lot of various fixes.

GitOrigin-RevId: 64963bfb55e5ffe8b099c1953143158b44a540c6
This commit is contained in:
levlam 2018-12-11 23:18:58 +03:00
parent 70ad4eb366
commit 6445cf645b
17 changed files with 67 additions and 44 deletions

1
.gitattributes vendored
View File

@ -14,6 +14,7 @@
*.md text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.md text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
*.in text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.in text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
*.sky text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.sky text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
*.html text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
*.java text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.java text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
*.py text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.py text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent

View File

@ -9,9 +9,12 @@
#include "td/telegram/misc.h" #include "td/telegram/misc.h"
#include "td/utils/JsonBuilder.h" #include "td/utils/JsonBuilder.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h" #include "td/utils/misc.h"
#include "td/utils/utf8.h" #include "td/utils/utf8.h"
#include <utility>
namespace td { namespace td {
static td_api::object_ptr<td_api::JsonValue> get_json_value_object(const JsonValue &json_value); static td_api::object_ptr<td_api::JsonValue> get_json_value_object(const JsonValue &json_value);

View File

@ -21,8 +21,8 @@
#include "td/utils/logging.h" #include "td/utils/logging.h"
#include "td/utils/misc.h" #include "td/utils/misc.h"
#include <map>
#include <mutex> #include <mutex>
#include <unordered_map>
namespace td { namespace td {

View File

@ -535,7 +535,7 @@ class MessagesDbImpl : public MessagesDbSyncInterface {
} }
Result<vector<BufferSlice>> get_messages_from_notification_id(DialogId dialog_id, NotificationId from_notification_id, Result<vector<BufferSlice>> get_messages_from_notification_id(DialogId dialog_id, NotificationId from_notification_id,
int32 limit) { int32 limit) override {
auto &stmt = get_messages_from_notification_id_stmt_; auto &stmt = get_messages_from_notification_id_stmt_;
SCOPE_EXIT { SCOPE_EXIT {
stmt.reset(); stmt.reset();

View File

@ -14,11 +14,13 @@
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/telegram/TdDb.h" #include "td/telegram/TdDb.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h" #include "td/utils/misc.h"
#include "td/utils/Time.h"
#include <algorithm> #include <algorithm>
#include <iterator>
#include <limits> #include <limits>
#include <tuple>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>

View File

@ -20,11 +20,14 @@
#include "td/actor/Timeout.h" #include "td/actor/Timeout.h"
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/logging.h"
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h" #include "td/utils/StringBuilder.h"
#include <functional> #include <functional>
#include <map> #include <map>
#include <unordered_map> #include <unordered_map>
#include <unordered_set>
namespace td { namespace td {

View File

@ -32,7 +32,7 @@ class NotificationTypeMessage : public NotificationType {
return string_builder << "NewMessageNotification[" << message_id_ << ']'; return string_builder << "NewMessageNotification[" << message_id_ << ']';
} }
Type get_type() const { Type get_type() const override {
return Type::Message; return Type::Message;
} }
@ -60,7 +60,7 @@ class NotificationTypeSecretChat : public NotificationType {
return string_builder << "NewSecretChatNotification[]"; return string_builder << "NewSecretChatNotification[]";
} }
Type get_type() const { Type get_type() const override {
return Type::SecretChat; return Type::SecretChat;
} }
@ -86,7 +86,7 @@ class NotificationTypeCall : public NotificationType {
return string_builder << "NewCallNotification[" << call_id_ << ']'; return string_builder << "NewCallNotification[" << call_id_ << ']';
} }
Type get_type() const { Type get_type() const override {
return Type::Call; return Type::Call;
} }

View File

@ -7,6 +7,7 @@
#pragma once #pragma once
#include "td/telegram/CallId.h" #include "td/telegram/CallId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/MessageId.h" #include "td/telegram/MessageId.h"
#include "td/telegram/td_api.h" #include "td/telegram/td_api.h"

View File

@ -17,6 +17,7 @@
#include "td/actor/Timeout.h" #include "td/actor/Timeout.h"
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/logging.h"
#include <map> #include <map>
#include <unordered_set> #include <unordered_set>

View File

@ -13,6 +13,8 @@
#include "td/telegram/files/FileLocation.h" #include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileStats.h" #include "td/telegram/files/FileStats.h"
#include "td/utils/logging.h"
namespace td { namespace td {
extern int VERBOSITY_NAME(file_gc); extern int VERBOSITY_NAME(file_gc);

View File

@ -18,10 +18,12 @@
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/format.h"
#include "td/utils/logging.h" #include "td/utils/logging.h"
#include "td/utils/misc.h" #include "td/utils/misc.h"
#include "td/utils/Parser.h" #include "td/utils/Parser.h"
#include "td/utils/port/path.h" #include "td/utils/port/path.h"
#include "td/utils/port/Stat.h"
#include "td/utils/Slice.h" #include "td/utils/Slice.h"
#include <cmath> #include <cmath>

View File

@ -675,7 +675,6 @@ class FullRemoteFileLocation {
#define as_input_web_file_location() as_input_web_file_location_impl(__FILE__, __LINE__) #define as_input_web_file_location() as_input_web_file_location_impl(__FILE__, __LINE__)
tl_object_ptr<telegram_api::inputWebFileLocation> as_input_web_file_location_impl(const char *file, int line) const { tl_object_ptr<telegram_api::inputWebFileLocation> as_input_web_file_location_impl(const char *file, int line) const {
CHECK(is_web()) << file << ' ' << line; CHECK(is_web()) << file << ' ' << line;
;
return make_tl_object<telegram_api::inputWebFileLocation>(web().url_, web().access_hash_); return make_tl_object<telegram_api::inputWebFileLocation>(web().url_, web().access_hash_);
} }

View File

@ -12,6 +12,7 @@
#include "td/telegram/net/NetQuery.h" #include "td/telegram/net/NetQuery.h"
#include "td/actor/actor.h" #include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h" #include "td/utils/buffer.h"
#include "td/utils/common.h" #include "td/utils/common.h"

View File

@ -13,7 +13,7 @@
#include <openssl/rand.h> #include <openssl/rand.h>
#endif #endif
#include <array> #include <atomic>
#include <cstring> #include <cstring>
#include <limits> #include <limits>
#include <random> #include <random>
@ -21,18 +21,17 @@
namespace td { namespace td {
#if TD_HAVE_OPENSSL #if TD_HAVE_OPENSSL
namespace { namespace {
constexpr size_t secure_bytes_buffer_size = 512; std::atomic<int64> random_seed_generation{0};
} } // namespace
void Random::secure_bytes(MutableSlice dest) { void Random::secure_bytes(MutableSlice dest) {
Random::secure_bytes(dest.ubegin(), dest.size()); Random::secure_bytes(dest.ubegin(), dest.size());
} }
namespace {
std::atomic<int64> random_seed_generation{0};
}
void Random::secure_bytes(unsigned char *ptr, size_t size) { void Random::secure_bytes(unsigned char *ptr, size_t size) {
constexpr size_t buf_size = secure_bytes_buffer_size; constexpr size_t buf_size = 512;
static TD_THREAD_LOCAL unsigned char *buf; // static zero-initialized static TD_THREAD_LOCAL unsigned char *buf; // static zero-initialized
static TD_THREAD_LOCAL size_t buf_pos; static TD_THREAD_LOCAL size_t buf_pos;
static TD_THREAD_LOCAL int64 generation; static TD_THREAD_LOCAL int64 generation;

View File

@ -6,17 +6,52 @@
// //
#include "td/utils/StringBuilder.h" #include "td/utils/StringBuilder.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h" #include "td/utils/misc.h"
#include "td/utils/port/thread_local.h" #include "td/utils/port/thread_local.h"
#include "td/utils/Slice.h"
#include <cstdio> #include <cstdio>
#include <cstring>
#include <limits> #include <limits>
#include <locale> #include <locale>
#include <memory>
#include <sstream> #include <sstream>
#include <utility> #include <utility>
namespace td { namespace td {
StringBuilder::StringBuilder(MutableSlice slice, bool use_buffer)
: begin_ptr_(slice.begin()), current_ptr_(begin_ptr_), use_buffer_(use_buffer) {
if (slice.size() <= reserved_size) {
auto buffer_size = reserved_size + 100;
buffer_ = std::make_unique<char[]>(buffer_size);
begin_ptr_ = buffer_.get();
current_ptr_ = begin_ptr_;
end_ptr_ = begin_ptr_ + buffer_size - reserved_size;
} else {
end_ptr_ = slice.end() - reserved_size;
}
}
StringBuilder &StringBuilder::operator<<(Slice slice) {
size_t size = slice.size();
if (unlikely(!reserve(size))) {
if (end_ptr_ < current_ptr_) {
return on_error();
}
auto available_size = static_cast<size_t>(end_ptr_ + reserved_size - 1 - current_ptr_);
if (size > available_size) {
error_flag_ = true;
size = available_size;
}
}
std::memcpy(current_ptr_, slice.begin(), size);
current_ptr_ += size;
return *this;
}
template <class T> template <class T>
static char *print_uint(char *current_ptr, T x) { static char *print_uint(char *current_ptr, T x) {
if (x < 100) { if (x < 100) {

View File

@ -11,25 +11,14 @@
#include "td/utils/StackAllocator.h" #include "td/utils/StackAllocator.h"
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <memory>
#include <type_traits> #include <type_traits>
namespace td { namespace td {
class StringBuilder { class StringBuilder {
public: public:
explicit StringBuilder(MutableSlice slice, bool use_buffer = false) explicit StringBuilder(MutableSlice slice, bool use_buffer = false);
: begin_ptr_(slice.begin()), current_ptr_(begin_ptr_), use_buffer_(use_buffer) {
if (slice.size() <= reserved_size) {
auto buffer_size = reserved_size + 100;
buffer_ = std::make_unique<char[]>(buffer_size);
begin_ptr_ = buffer_.get();
current_ptr_ = begin_ptr_;
end_ptr_ = begin_ptr_ + buffer_size - reserved_size;
} else {
end_ptr_ = slice.end() - reserved_size;
}
}
void clear() { void clear() {
current_ptr_ = begin_ptr_; current_ptr_ = begin_ptr_;
@ -54,23 +43,7 @@ class StringBuilder {
StringBuilder &operator<<(const wchar_t *str) = delete; StringBuilder &operator<<(const wchar_t *str) = delete;
StringBuilder &operator<<(Slice slice) { StringBuilder &operator<<(Slice slice);
size_t size = slice.size();
if (unlikely(!reserve(size))) {
if (end_ptr_ < current_ptr_) {
return on_error();
}
auto available_size = static_cast<size_t>(end_ptr_ + reserved_size - 1 - current_ptr_);
if (size > available_size) {
error_flag_ = true;
size = available_size;
}
}
std::memcpy(current_ptr_, slice.begin(), size);
current_ptr_ += size;
return *this;
}
StringBuilder &operator<<(bool b) { StringBuilder &operator<<(bool b) {
return *this << (b ? Slice("true") : Slice("false")); return *this << (b ? Slice("true") : Slice("false"));

View File

@ -8,6 +8,7 @@
#include "td/utils/JsonBuilder.h" #include "td/utils/JsonBuilder.h"
#include "td/utils/logging.h" #include "td/utils/logging.h"
#include "td/utils/Slice.h"
#include "td/utils/StringBuilder.h" #include "td/utils/StringBuilder.h"
#include <tuple> #include <tuple>