1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

fix compilation errors of different platforms and move to c++20

This commit is contained in:
birydrad 2024-09-12 16:37:25 +02:00
parent 0780a6a1b5
commit 1c66852842
10 changed files with 67 additions and 25 deletions

View file

@ -79,7 +79,7 @@ else()
set(HAVE_SSE42 FALSE)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS FALSE)

View file

@ -18,7 +18,6 @@
*/
#pragma once
#include "absl/strings/internal/str_format/parser.h"
#include "td/actor/actor.h"
namespace ton {

View file

@ -62,6 +62,7 @@
#include "vm/dict.h"
#include <numeric>
#include <optional>
namespace vm {
@ -2010,7 +2011,7 @@ TEST(TonDb, CompactArrayOld) {
SCOPE_EXIT {
ton_db->commit_transaction(std::move(txn));
};
auto smart = txn->begin_smartcontract("");
auto smart = txn->begin_smartcontract();
SCOPE_EXIT {
txn->commit_smartcontract(std::move(smart));
};
@ -2037,7 +2038,7 @@ TEST(TonDb, CompactArrayOld) {
SCOPE_EXIT {
ton_db->commit_transaction(std::move(txn));
};
auto smart = txn->begin_smartcontract("");
auto smart = txn->begin_smartcontract();
//smart->validate_meta();
SCOPE_EXIT {
txn->commit_smartcontract(std::move(smart));
@ -2058,7 +2059,7 @@ TEST(TonDb, CompactArrayOld) {
SCOPE_EXIT {
ton_db->abort_transaction(std::move(txn));
};
auto smart = txn->begin_smartcontract("");
auto smart = txn->begin_smartcontract();
SCOPE_EXIT {
txn->abort_smartcontract(std::move(smart));
};
@ -2219,7 +2220,7 @@ TEST(TonDb, CellStat) {
ASSERT_EQ(stat.cells, new_stat.get_stat().cells);
ASSERT_EQ(stat.bits, new_stat.get_stat().bits);
CHECK(usage_tree.unique());
CHECK(usage_tree.use_count() == 1);
usage_tree.reset();
td::Ref<vm::Cell> C, BC, C_proof;
std::shared_ptr<vm::CellUsageTree> usage_tree_B;

View file

@ -76,7 +76,7 @@ struct CellHash {
inline size_t cell_hash_slice_hash(td::Slice hash) {
// use offset 8, because in db keys are grouped by first bytes.
return td::as<size_t>(hash.ubegin() + 8);
return td::as<size_t>(hash.substr(8, 8).ubegin());
}
namespace std {
template <>

View file

@ -14,6 +14,8 @@
#include "td/utils/HashMap.h"
#include "td/utils/HashSet.h"
#include <optional>
#if TD_PORT_POSIX
#include <sys/mman.h>
#include <unistd.h>
@ -98,7 +100,7 @@ class ArenaPrunnedCellCreator : public ExtCellCreator {
}
#else
static std::unique_ptr<char, Deleter> alloc() {
auto ptr = reinterpret_cast<char *>(malloc(batch_size)));
auto ptr = reinterpret_cast<char *>(malloc(batch_size));
CHECK(ptr != nullptr);
return std::unique_ptr<char, Deleter>(ptr);
}
@ -292,7 +294,7 @@ struct CellInfoHashTableDense {
}
template <class Iterator>
void init_from(Iterator begin, Iterator end) {
auto size = std::distance(begin, end);
auto size = td::narrow_cast<size_t>(std::distance(begin, end));
dense_ht_buckets_ = std::max(size_t(1), size_t(size / 8));
std::vector<size_t> offsets(dense_ht_buckets_ + 2);
@ -438,16 +440,16 @@ class CellStorage {
add_stat("ht.size", size);
add_stat("ht.load", double(size) / std::max(1.0, double(capacity)));
}
CHECK(stats.roots_total_count == local_roots_.size());
CHECK(td::narrow_cast<size_t>(stats.roots_total_count) == local_roots_.size());
return stats;
}
void apply_stats_diff(DynamicBagOfCellsDb::Stats diff) {
auto unique_access = local_access_.lock();
stats_.apply_diff(diff);
CHECK(stats_.roots_total_count == local_roots_.size());
CHECK(td::narrow_cast<size_t>(stats_.roots_total_count) == local_roots_.size());
size_t cells_count{0};
for_each_bucket(0, [&](size_t bucket_id, auto &bucket) { cells_count += bucket.infos_.size(); });
CHECK(stats_.cells_total_count == cells_count);
CHECK(td::narrow_cast<size_t>(stats_.cells_total_count) == cells_count);
}
td::Result<Ref<DataCell>> load_cell(const CellHash &hash) const {
@ -541,8 +543,8 @@ class CellStorage {
DefaultPrunnedCellCreator default_pc_creator;
auto timer = td::Timer();
size_t cell_count{0};
size_t desc_count{0};
td::int64 cell_count{0};
td::int64 desc_count{0};
if (options.use_less_memory_during_creation) {
auto [new_cell_count, new_desc_count] = parallel_scan_cells(
default_pc_creator, options.use_arena,

View file

@ -113,7 +113,8 @@ class TonDbTransactionImpl;
using TonDbTransaction = std::unique_ptr<TonDbTransactionImpl>;
class TonDbTransactionImpl {
public:
SmartContractDb begin_smartcontract(td::Slice hash = {});
SmartContractDb begin_smartcontract(td::Slice hash = std::string(32, '\0'));
void commit_smartcontract(SmartContractDb txn);
void commit_smartcontract(SmartContractDiff txn);

View file

@ -2,12 +2,24 @@
#include "td/actor/core/ActorTypeStat.h"
#include "td/actor/core/Scheduler.h"
#include "td/utils/port/thread_local.h"
#include <cxxabi.h>
#include <set>
#include <map>
#include <mutex>
#include <typeindex>
#include <typeinfo>
#include <optional>
#include "td/utils/port/platform.h"
#ifdef __has_include
#if __has_include(<cxxabi.h>)
#include <cxxabi.h>
#define CXXABI_AVAILABLE 1
#else
#define CXXABI_AVAILABLE 0
#endif
#else
#define CXXABI_AVAILABLE 0
#endif
namespace td {
namespace actor {
@ -82,6 +94,7 @@ ActorTypeStatRef ActorTypeStatManager::get_actor_type_stat(td::uint32 id, Actor
}
std::string ActorTypeStatManager::get_class_name(const char *name) {
#if CXXABI_AVAILABLE
int status;
char *real_name = abi::__cxa_demangle(name, nullptr, nullptr, &status);
if (status < 0) {
@ -91,6 +104,9 @@ std::string ActorTypeStatManager::get_class_name(const char *name) {
std::string result = real_name;
std::free(real_name);
return result;
#else
return name;
#endif
}
ActorTypeStats ActorTypeStatManager::get_stats(double inv_ticks_per_second) {

View file

@ -22,6 +22,10 @@
#include <ctime>
namespace td {
int64 Clocks::monotonic_nano() {
auto duration = std::chrono::steady_clock::now().time_since_epoch();
return std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count();
}
double Clocks::monotonic() {
// TODO write system specific functions, because std::chrono::steady_clock is steady only under Windows

View file

@ -22,20 +22,22 @@
namespace td {
struct Clocks {
static int64 monotonic_nano();
static double monotonic();
static double system();
static int tz_offset();
#if defined(__i386__)
static __inline__ td::uint64 rdtsc(void) {
#if defined(__i386__) or defined(__M_IX86)
static uint64 rdtsc() {
unsigned long long int x;
__asm__ volatile("rdtsc" : "=A"(x));
return x;
}
static constexpr td::uint64 rdtsc_frequency(void) {
static constexpr uint64 rdtsc_frequency() {
return 2000'000'000;
}
@ -46,13 +48,13 @@ struct Clocks {
static constexpr double inv_ticks_per_second() {
return 0.5e-9;
}
#elif defined(__x86_64__)
static __inline__ td::uint64 rdtsc(void) {
#elif defined(__x86_64__) or defined(__M_X64)
static uint64 rdtsc() {
unsigned hi, lo;
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
return ((unsigned long long)lo) | (((unsigned long long)hi) << 32);
}
static constexpr td::uint64 rdtsc_frequency(void) {
static constexpr uint64 rdtsc_frequency() {
return 2000'000'000;
}
@ -63,13 +65,13 @@ struct Clocks {
static constexpr double inv_ticks_per_second() {
return 0.5e-9;
}
#elif defined(__aarch64__)
static __inline__ td::uint64 rdtsc(void) {
#elif defined(__aarch64__) or defined(_M_ARM64)
static uint64 rdtsc() {
unsigned long long val;
asm volatile("mrs %0, cntvct_el0" : "=r"(val));
return val;
}
static __inline__ td::uint64 rdtsc_frequency(void) {
static uint64 rdtsc_frequency() {
unsigned long long val;
asm volatile("mrs %0, cntfrq_el0" : "=r"(val));
return val;
@ -79,6 +81,21 @@ struct Clocks {
return static_cast<double>(rdtsc_frequency());
}
static double inv_ticks_per_second() {
return 1.0 / static_cast<double>(rdtsc_frequency());
}
#else
static uint64 rdtsc() {
return monotonic_nano();
}
static uint64 rdtsc_frequency() {
return 1000'000'000;
}
static double ticks_per_second() {
return static_cast<double>(rdtsc_frequency());
}
static double inv_ticks_per_second() {
return 1.0 / static_cast<double>(rdtsc_frequency());
}

View file

@ -29,6 +29,8 @@
#include "db-utils.h"
#include "td/db/RocksDb.h"
#include <optional>
namespace rocksdb {
class Statistics;
class DB;