Skip to content

Commit

Permalink
Test c++17
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Jun 4, 2023
1 parent 84523d9 commit 3dfde3b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ endif()
set_target_properties(
LIB_LIEF
PROPERTIES POSITION_INDEPENDENT_CODE ON
CXX_STANDARD 11
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_VISIBILITY_PRESET hidden
C_VISIBILITY_PRESET hidden)
Expand Down
2 changes: 1 addition & 1 deletion api/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ target_compile_features(pyLIEF PRIVATE cxx_attribute_deprecated)

set_target_properties(pyLIEF PROPERTIES
POSITION_INDEPENDENT_CODE ON
CXX_STANDARD 14
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_VISIBILITY_PRESET hidden
C_VISIBILITY_PRESET hidden
Expand Down
3 changes: 2 additions & 1 deletion src/MachO/Builder.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ ok_error_t Builder::build_segments() {
header.flags = static_cast<uint32_t>(section.raw_flags());
header.reserved1 = static_cast<uint32_t>(section.reserved1());
header.reserved2 = static_cast<uint32_t>(section.reserved2());
if (std::is_same<section_t, details::section_64>::value) { // TODO: Move to if constexpr when LIEF will use C++17

if constexpr (std::is_same_v<section_t, details::section_64>) {
reinterpret_cast<details::section_64*>(&header)->reserved3 = static_cast<uint32_t>(section.reserved3());
}

Expand Down
2 changes: 1 addition & 1 deletion src/PE/Parser.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ ok_error_t Parser::parse_load_config() {
size_t current_size = 0;
WIN_VERSION version_found = WIN_VERSION::WIN_UNKNOWN;

if /* constexpr */(std::is_same<PE_T, details::PE32>::value) {
if (std::is_same<PE_T, details::PE32>::value) {
for (const auto& p : PE32_LOAD_CONFIGURATION_SIZES) {
if (current_size < p.second && p.second <= size) {
std::tie(version_found, current_size) = p;
Expand Down
16 changes: 15 additions & 1 deletion src/hash_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include <string>
#include <array>
#include <memory>
#include <type_traits>

#include "LIEF/span.hpp"

namespace LIEF {
class hashstream {
Expand Down Expand Up @@ -48,20 +51,31 @@ class hashstream {

hashstream& align(size_t size, uint8_t val = 0);

template<class Integer, typename = typename std::enable_if<std::is_integral<Integer>::value>>
template<typename T>
hashstream& write(span<const T> s) {
static_assert(std::is_same_v<T, uint8_t> || std::is_same_v<T, char>, "Require an integer");
write(reinterpret_cast<const uint8_t*>(s.data()), s.size());
return *this;
}

template<class Integer>
hashstream& write(Integer integer) {
static_assert(std::is_integral<Integer>::value, "Require an integer");
const auto* int_p = reinterpret_cast<const uint8_t*>(&integer);
return write(int_p, sizeof(Integer));
}

template<typename T, size_t size, typename = typename std::enable_if<std::is_integral<T>::value>>
hashstream& write(const std::array<T, size>& t) {
static_assert(std::is_integral<T>::value, "Require an integer");
for (T val : t) {
write<T>(val);
}
return *this;
}



hashstream& get(std::vector<uint8_t>& c);
hashstream& flush();

Expand Down
10 changes: 5 additions & 5 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Logger& Logger::operator=(Logger&&) = default;
Logger::~Logger() = default;

Logger::Logger() {
if /* constexpr */ (lief_logging_support) {
if /* constexpr */ (current_platform() == PLATFORMS::ANDROID_PLAT) {
if constexpr (lief_logging_support) {
if constexpr (current_platform() == PLATFORMS::ANDROID_PLAT) {
#if defined(__ANDROID__)
sink_ = spdlog::android_logger_mt("LIEF", "lief");
#else
Expand Down Expand Up @@ -109,19 +109,19 @@ const char* to_string(LOGGING_LEVEL e) {


void Logger::disable() {
if /* constexpr */ (lief_logging_support) {
if constexpr (lief_logging_support) {
Logger::instance().sink_->set_level(spdlog::level::off);
}
}

void Logger::enable() {
if /* constexpr */ (lief_logging_support) {
if constexpr (lief_logging_support) {
Logger::instance().sink_->set_level(spdlog::level::warn);
}
}

void Logger::set_level(LOGGING_LEVEL level) {
if /* constexpr */ (!lief_logging_support) {
if constexpr (!lief_logging_support) {
return;
}
switch (level) {
Expand Down

0 comments on commit 3dfde3b

Please sign in to comment.