Skip to content

Commit

Permalink
boost 1.86 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
malbit committed Sep 23, 2024
1 parent 2d24362 commit 9de6659
Show file tree
Hide file tree
Showing 26 changed files with 94 additions and 174 deletions.
24 changes: 15 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ statusinfo("CMake version ${CMAKE_VERSION}")
project(arqma
LANGUAGES CXX C)

if(POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()

cmake_host_system_information(RESULT freememsys QUERY AVAILABLE_PHYSICAL_MEMORY)
cmake_host_system_information(RESULT freememvirt QUERY AVAILABLE_VIRTUAL_MEMORY)
statusinfo("${Green}Total available physical memory:${ColourReset}${BoldBlue} ${freememsys} Mib ${ColourReset}")
Expand Down Expand Up @@ -1011,10 +1015,10 @@ else()
endif()

if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.15 -fvisibility=hidden -DGTEST_HAS_TR1_TUPLE=0")
if(NOT DEPENDS)
set(CMAKE_OSX_DEPLOYMENT_TARGET 13.0)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -DGTEST_HAS_TR1_TUPLE=0")
# if(NOT DEPENDS)
# set(CMAKE_OSX_DEPLOYMENT_TARGET 14.0)
# endif()
endif()

set(DEBUG_FLAGS "-g3")
Expand Down Expand Up @@ -1081,8 +1085,10 @@ if(STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
if(NOT APPLE)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
endif()
endif()

if(DEPENDS)
Expand All @@ -1093,15 +1099,15 @@ if(DEPENDS)
endif()
endif()

set(BOOST_LIBRARIES system filesystem thread date_time chrono regex serialization program_options)
if(WIN32)
set(BOOST_LIBRARIES system filesystem thread date_time chrono regex serialization program_options locale)
else()
set(BOOST_LIBRARIES system filesystem thread date_time chrono regex serialization program_options)
list(APPEND BOOST_LIBRARIES locale)
endif()

find_package(Boost 1.62.0 QUIET REQUIRED COMPONENTS ${BOOST_LIBRARIES})
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
add_definitions(-DBOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION)
add_definitions(-DBOOST_UUID_DISABLE_ALIGNMENT)

set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_LIB_SUFFIXES})
if(NOT Boost_FOUND)
Expand Down
43 changes: 0 additions & 43 deletions contrib/epee/include/file_io_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,6 @@ namespace file_io_utils
#endif
}

inline
bool get_file_time(const std::string& path_to_file, time_t& ft)
{
boost::system::error_code ec;
ft = boost::filesystem::last_write_time(boost::filesystem::path(path_to_file), ec);
if(!ec)
return true;
else
return false;
}

inline
bool set_file_time(const std::string& path_to_file, const time_t& ft)
{
boost::system::error_code ec;
boost::filesystem::last_write_time(boost::filesystem::path(path_to_file), ft, ec);
if(!ec)
return true;
else
return false;
}


inline
bool load_file_to_string(const std::string& path_to_file, std::string& target_str, size_t max_size = 1000000000)
{
Expand Down Expand Up @@ -175,26 +152,6 @@ namespace file_io_utils
#endif
}

inline
bool append_string_to_file(const std::string& path_to_file, const std::string& str)
{
// No special Windows implementation because so far not used in Monero code
try
{
std::ofstream fstream;
fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
fstream.open(path_to_file.c_str(), std::ios_base::binary | std::ios_base::out | std::ios_base::app);
fstream << str;
fstream.close();
return true;
}

catch(...)
{
return false;
}
}

inline
bool get_file_size(const std::string& path_to_file, uint64_t &size)
{
Expand Down
53 changes: 1 addition & 52 deletions contrib/epee/include/misc_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,12 @@

#pragma once

#include <limits>
#include <vector>
#include <boost/thread.hpp>
namespace epee
{
#define STD_TRY_BEGIN() try {

#define STD_TRY_CATCH(where_, ret_val) \
} \
catch (const std::exception &e) \
{ \
LOG_ERROR("EXCEPTION: " << where_ << ", mes: "<< e.what()); \
return ret_val; \
} \
catch (...) \
{ \
LOG_ERROR("EXCEPTION: " << where_ ); \
return ret_val; \
}



namespace misc_utils
{
template<typename t_type>
t_type get_max_t_val(t_type t)
{
return (std::numeric_limits<t_type>::max)();
}


template<typename t_iterator>
t_iterator move_it_forward(t_iterator it, size_t count)
{
while(count--)
it++;
return it;
}

template<typename t_iterator>
t_iterator move_it_backward(t_iterator it, size_t count)
{
Expand All @@ -74,25 +42,6 @@ namespace misc_utils
return it;
}


// TEMPLATE STRUCT less
template<class _Ty>
struct less_as_pod
: public std::binary_function<_Ty, _Ty, bool>
{ // functor for operator<
bool operator()(const _Ty& _Left, const _Ty& _Right) const
{ // apply operator< to operands
return memcmp(&_Left, &_Right, sizeof(_Left)) < 0;
}
};

template<class _Ty>
bool is_less_as_pod(const _Ty& _Left, const _Ty& _Right)
{ // apply operator< to operands
return memcmp(&_Left, &_Right, sizeof(_Left)) < 0;
}


inline
bool sleep_no_w(long ms )
{
Expand Down
8 changes: 5 additions & 3 deletions contrib/epee/include/serialization/keyvalue_serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ do { \
epee::serialization::selector<is_store>::serialize_t_val_as_blob(this_ref.variable, stg, hparent_section, val_name);

#define KV_SERIALIZE_VAL_POD_AS_BLOB_N(variable, val_name) \
static_assert(std::is_pod<decltype(this_ref.variable)>::value, "t_type must be a POD type."); \
static_assert(std::is_trivially_copyable_v<decltype(this_ref.variable)>, "t_type must be a trivially copyable type."); \
static_assert(std::is_standard_layout_v<decltype(this_ref.variable)>, "t_type must be a standard layout type."); \
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(variable, val_name)

#define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(variable, val_name, default_value) \
do { \
static_assert(std::is_pod<decltype(this_ref.variable)>::value, "t_type must be a POD type."); \
static_assert(std::is_trivially_copyable_v<decltype(this_ref.variable)>, "t_type must be a trivially copyable type."); \
static_assert(std::is_standard_layout_v<decltype(this_ref.variable)>, "t_type must be a standard layout type."); \
bool ret = KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(variable, val_name); \
if (!ret) \
epee::serialize_default(this_ref.variable, default_value); \
Expand All @@ -114,7 +116,7 @@ do { \
#define KV_SERIALIZE(variable) KV_SERIALIZE_N(variable, #variable)
#define KV_SERIALIZE_VAL_POD_AS_BLOB(variable) KV_SERIALIZE_VAL_POD_AS_BLOB_N(variable, #variable)
#define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(variable, def) KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(variable, #variable, def)
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(variable) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(variable, #variable) //skip is_pod compile time check
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(variable) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(variable, #variable) //skip is_trivially_copyable and is_standard_layout compile time check
#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB(variable) KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(variable, #variable)
#define KV_SERIALIZE_OPT(variable,default_value) KV_SERIALIZE_OPT_N(variable, #variable, default_value)
#define KV_SERIALIZE_OPT2(variable,default_value) KV_SERIALIZE_OPT_N2(variable, #variable, default_value)
Expand Down
16 changes: 7 additions & 9 deletions contrib/epee/include/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,13 @@ namespace epee
return {src.data(), src.size()};
}

template<typename T>
constexpr bool has_padding() noexcept
{
return !std::is_standard_layout<T>() || alignof(T) != 1;
}

//! \return Cast data from `src` as `span<const std::uint8_t>`.
template<typename T>
span<const std::uint8_t> to_byte_span(const span<const T> src) noexcept
{
static_assert(!has_padding<T>(), "source type may have padding");
static_assert(!std::is_empty<T>(), "empty value types will not work -> sizeof == 1");
static_assert(std::is_standard_layout_v<T>, "type must have standard layout");
static_assert(std::has_unique_object_representations_v<T>, "type must be trivially copyable with no padding");
return {reinterpret_cast<const std::uint8_t*>(src.data()), src.size_bytes()};
}

Expand All @@ -151,7 +147,8 @@ namespace epee
span<const std::uint8_t> as_byte_span(const T& src) noexcept
{
static_assert(!std::is_empty<T>(), "empty types will not work -> sizeof == 1");
static_assert(!has_padding<T>(), "source type may have padding");
static_assert(std::is_standard_layout_v<T>, "type must have standard layout");
static_assert(std::has_unique_object_representations_v<T>, "type must be trivially copyable with no padding");
return {reinterpret_cast<const std::uint8_t*>(std::addressof(src)), sizeof(T)};
}

Expand All @@ -160,7 +157,8 @@ namespace epee
span<std::uint8_t> as_mut_byte_span(T& src) noexcept
{
static_assert(!std::is_empty<T>(), "empty types will not work -> sizeof == 1");
static_assert(!has_padding<T>(), "source type may have padding");
static_assert(std::is_standard_layout_v<T>, "type must have standard layout");
static_assert(std::has_unique_object_representations_v<T>, "type must be trivially copyable with no padding");
return {reinterpret_cast<std::uint8_t*>(std::addressof(src)), sizeof(T)};
}

Expand Down
2 changes: 2 additions & 0 deletions contrib/epee/include/string_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ POP_WARNINGS
std::string pod_to_hex(const t_pod_type& s)
{
static_assert(std::is_standard_layout<t_pod_type>(), "expected standard layout type");
static_assert(std::has_unique_object_representations_v<t_pod_type>, "type may have padding");
return to_hex::string(as_byte_span(s));
}
//----------------------------------------------------------------------------
Expand All @@ -309,6 +310,7 @@ POP_WARNINGS
epee::span<char> rspan((char*)&s, sizeof(s));
return parse_hexstr_to_binbuff(epee::to_span(hex_str), rspan);*/
static_assert(std::is_standard_layout<t_pod_type>(), "expected standard layout type");
static_assert(std::has_unique_object_representations_v<t_pod_type>, "type may have padding");
return from_hex::to_buffer(as_mut_byte_span(s), hex_str);
}
//----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/checkpoints/checkpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

namespace cryptonote
{
struct Blockchain;
class Blockchain;
enum struct checkpoint_type
{
hardcoded,
Expand Down
3 changes: 2 additions & 1 deletion src/common/boost_serialization_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <boost/archive/portable_binary_oarchive.hpp>
#include <boost/archive/portable_binary_iarchive.hpp>
#include <boost/filesystem/operations.hpp>
#include "common/util.h"


namespace tools
Expand Down Expand Up @@ -111,7 +112,7 @@ namespace tools
catch(...)
{
// if failed, try reading in unportable mode
boost::filesystem::copy_file(file_path, file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
tools::copy_file(file_path, file_path + ".unportable");
data_file.close();
data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
if(data_file.fail())
Expand Down
1 change: 1 addition & 0 deletions src/common/threadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <cstddef>
#include <functional>
#include <utility>
#include <deque>
#include <vector>
#include <stdexcept>

Expand Down
16 changes: 16 additions & 0 deletions src/common/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ static int flock_exnb(int fd)

namespace tools
{
void copy_file(const std::string& from, const std::string& to)
{
using boost::filesystem::path;
#if BOOST_VERSION < 107400
boost::filesystem::copy_file(
path(from),
path(to),
boost::filesystem::copy_option::overwrite_if_exists);
#else
boost::filesystem::copy_file(
path(from),
path(to),
boost::filesystem::copy_options::overwrite_existing);
#endif
}

std::function<void(int)> signal_handler::m_handler;

private_file::private_file() noexcept : m_handle(), m_filename() {}
Expand Down
2 changes: 2 additions & 0 deletions src/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ namespace tools
}
};

void copy_file(const std::string& from, const std::string& to);

//! A file restricted to process owner AND process. Deletes file on destruction.
class private_file {
std::unique_ptr<std::FILE, close_file> m_handle;
Expand Down
9 changes: 6 additions & 3 deletions src/crypto/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ namespace crypto {
/* Generate a value filled with random bytes.
*/
template<typename T>
typename std::enable_if<std::is_pod<T>::value, T>::type rand() {
T rand() {
static_assert(std::is_standard_layout_v<T>, "cannot write random bytes into non-standard layout type");
static_assert(std::is_trivially_copyable_v<T>, "cannot write random bytes into non-trivially copyable type");
typename std::remove_cv<T>::type res;
generate_random_bytes_thread_safe(sizeof(T), (uint8_t*)&res);
return res;
Expand Down Expand Up @@ -229,8 +231,9 @@ namespace crypto {
inline std::ostream &operator <<(std::ostream &o, const crypto::public_key &v) {
epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
}
inline std::ostream &operator <<(std::ostream &o, const crypto::secret_key &v) {
epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
struct secret_key_explicit_print_ref { const crypto::secret_key &sk; };
inline std::ostream &operator <<(std::ostream &o, const secret_key_explicit_print_ref v) {
epee::to_hex::formatted(o, epee::as_byte_span(unwrap(unwrap(v.sk)))); return o;
}
inline std::ostream &operator <<(std::ostream &o, const crypto::key_derivation &v) {
epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
Expand Down
10 changes: 0 additions & 10 deletions src/cryptonote_basic/cryptonote_basic_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ namespace cryptonote {
/************************************************************************/
/* */
/************************************************************************/
template<class t_array>
struct array_hasher: std::unary_function<t_array&, std::size_t>
{
std::size_t operator()(const t_array& val) const
{
return boost::hash_range(&val.data[0], &val.data[sizeof(val.data)]);
}
};


#pragma pack(push, 1)
struct public_address_outer_blob
{
Expand Down
4 changes: 2 additions & 2 deletions src/cryptonote_basic/cryptonote_format_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ namespace cryptonote
bool r = hwdev.generate_key_derivation(tx_public_key, ack.m_view_secret_key, recv_derivation);
if (!r)
{
MWARNING("key image helper: failed to generate_key_derivation(" << tx_public_key << ", " << ack.m_view_secret_key << ")");
MWARNING("key image helper: failed to generate_key_derivation(" << tx_public_key << ", <viewkey>)");
memcpy(&recv_derivation, rct::identity().bytes, sizeof(recv_derivation));
}

Expand All @@ -313,7 +313,7 @@ namespace cryptonote
r = hwdev.generate_key_derivation(additional_tx_public_keys[i], ack.m_view_secret_key, additional_recv_derivation);
if (!r)
{
MWARNING("key image helper: failed to generate_key_derivation(" << additional_tx_public_keys[i] << ", " << ack.m_view_secret_key << ")");
MWARNING("key image helper: failed to generate_key_derivation(" << additional_tx_public_keys[i] << ", <viewkey>)");
}
else
{
Expand Down
Loading

0 comments on commit 9de6659

Please sign in to comment.