Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RPCS3 compile in C++2a mode #7394

Merged
merged 1 commit into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 14 additions & 10 deletions Utilities/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,13 @@ logs::file_writer::file_writer(const std::string& name)
m_fout.open(log_name, fs::rewrite);

// Compressed log, make it inaccessible (foolproof)
if (!m_fout2.open(log_name + ".gz", fs::rewrite + fs::unread) || deflateInit2(&m_zs, 9, Z_DEFLATED, 16 + 15, 9, Z_DEFAULT_STRATEGY) != Z_OK)
if (m_fout2.open(log_name + ".gz", fs::rewrite + fs::unread))
{
m_fout2.close();
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
if (deflateInit2(&m_zs, 9, Z_DEFLATED, 16 + 15, 9, Z_DEFAULT_STRATEGY) != Z_OK)
#pragma GCC diagnostic pop
m_fout2.close();
}

#ifdef _WIN32
Expand Down Expand Up @@ -666,14 +670,14 @@ void logs::file_listener::log(u64 stamp, const logs::message& msg, const std::st
// Used character: U+00B7 (Middle Dot)
switch (msg.sev)
{
case level::always: text = u8"·A "; break;
case level::fatal: text = u8"·F "; break;
case level::error: text = u8"·E "; break;
case level::todo: text = u8"·U "; break;
case level::success: text = u8"·S "; break;
case level::warning: text = u8"·W "; break;
case level::notice: text = u8"·! "; break;
case level::trace: text = u8"·T "; break;
case level::always: text = reinterpret_cast<const char*>(u8"·A "); break;
case level::fatal: text = reinterpret_cast<const char*>(u8"·F "); break;
case level::error: text = reinterpret_cast<const char*>(u8"·E "); break;
case level::todo: text = reinterpret_cast<const char*>(u8"·U "); break;
case level::success: text = reinterpret_cast<const char*>(u8"·S "); break;
case level::warning: text = reinterpret_cast<const char*>(u8"·W "); break;
case level::notice: text = reinterpret_cast<const char*>(u8"·! "); break;
case level::trace: text = reinterpret_cast<const char*>(u8"·T "); break;
}

// Print µs timestamp
Expand Down
19 changes: 18 additions & 1 deletion Utilities/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ namespace logs
{
}

private:
#if __cpp_char8_t >= 201811
using char2 = char8_t;
#else
using char2 = uchar;
#endif

#define GEN_LOG_METHOD(_sev)\
const message msg_##_sev{this, level::_sev};\
template <std::size_t N, typename... Args>\
Expand All @@ -78,8 +85,18 @@ namespace logs
static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make<fmt_unveil_t<Args>>()...};\
msg_##_sev.broadcast(fmt, type_list, u64{fmt_unveil<Args>::get(args)}...);\
}\
}
}\
template <std::size_t N, typename... Args>\
void _sev(const char2(&fmt)[N], const Args&... args)\
{\
if (UNLIKELY(level::_sev <= enabled.load(std::memory_order_relaxed)))\
{\
static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make<fmt_unveil_t<Args>>()...};\
msg_##_sev.broadcast(reinterpret_cast<const char*>(+fmt), type_list, u64{fmt_unveil<Args>::get(args)}...);\
}\
}\

public:
GEN_LOG_METHOD(fatal)
GEN_LOG_METHOD(error)
GEN_LOG_METHOD(todo)
Expand Down
16 changes: 8 additions & 8 deletions Utilities/StrFmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace fmt
{
template <typename... Args>
static std::string format(const char*, const Args&...);
template <typename CharT, std::size_t N, typename... Args>
static std::string format(const CharT(&)[N], const Args&...);
}

template <typename T, typename>
Expand Down Expand Up @@ -274,19 +274,19 @@ namespace fmt
void raw_append(std::string& out, const char*, const fmt_type_info*, const u64*) noexcept;

// Formatting function
template <typename... Args>
SAFE_BUFFERS FORCE_INLINE void append(std::string& out, const char* fmt, const Args&... args)
template <typename CharT, std::size_t N, typename... Args>
SAFE_BUFFERS FORCE_INLINE void append(std::string& out, const CharT(&fmt)[N], const Args&... args)
{
static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make<fmt_unveil_t<Args>>()...};
raw_append(out, fmt, type_list, fmt_args_t<Args...>{fmt_unveil<Args>::get(args)...});
raw_append(out, reinterpret_cast<const char*>(fmt), type_list, fmt_args_t<Args...>{fmt_unveil<Args>::get(args)...});
}

// Formatting function
template <typename... Args>
SAFE_BUFFERS FORCE_INLINE std::string format(const char* fmt, const Args&... args)
template <typename CharT, std::size_t N, typename... Args>
SAFE_BUFFERS FORCE_INLINE std::string format(const CharT(&fmt)[N], const Args&... args)
{
std::string result;
append<Args...>(result, fmt, args...);
append(result, fmt, args...);
return result;
}

Expand Down
3 changes: 3 additions & 0 deletions Utilities/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2203,7 +2203,10 @@ void thread_ctrl::set_thread_affinity_mask(u64 mask)

if (shifted & 1)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
CPU_SET(core, &cs);
#pragma GCC diagnostic pop
}

if (shifted <= 1)
Expand Down
3 changes: 3 additions & 0 deletions rpcs3/Crypto/unself.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,10 @@ std::vector<fs::file> SCEDecrypter::MakeFile()
strm.avail_out = BUFSIZE;
strm.next_in = data_buf.get()+data_buf_offset;
strm.next_out = tempbuf;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
int ret = inflateInit(&strm);
#pragma GCC diagnostic pop

while (strm.avail_in)
{
Expand Down
14 changes: 7 additions & 7 deletions rpcs3/Emu/Memory/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,32 +1159,32 @@ void fmt_class_string<vm::_ptr_base<const char, u32>>::format(std::string& out,
// Special case (may be allowed for some arguments)
if (arg == 0)
{
out += u8"«NULL»";
out += reinterpret_cast<const char*>(u8"«NULL»");
return;
}

// Filter certainly invalid addresses (TODO)
if (arg < 0x10000 || arg >= 0xf0000000)
{
out += u8"«INVALID_ADDRESS:";
out += reinterpret_cast<const char*>(u8"«INVALID_ADDRESS:");
fmt_class_string<u32>::format(out, arg);
out += u8"»";
out += reinterpret_cast<const char*>(u8"»");
return;
}

const auto start = out.size();

out += u8"“";
out += reinterpret_cast<const char*>(u8"“");

for (vm::_ptr_base<const volatile char, u32> ptr = vm::cast(arg);; ptr++)
{
if (!vm::check_addr(ptr.addr()))
{
// TODO: optimize checks
out.resize(start);
out += u8"«INVALID_ADDRESS:";
out += reinterpret_cast<const char*>(u8"«INVALID_ADDRESS:");
fmt_class_string<u32>::format(out, arg);
out += u8"»";
out += reinterpret_cast<const char*>(u8"»");
return;
}

Expand All @@ -1198,5 +1198,5 @@ void fmt_class_string<vm::_ptr_base<const char, u32>>::format(std::string& out,
}
}

out += u8"”";
out += reinterpret_cast<const char*>(u8"”");
}
12 changes: 6 additions & 6 deletions rpcs3/Emu/RSX/Common/texture_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ namespace rsx
m_cache_update_tag = rsx::get_shared_tag();
}

template <typename... Args>
void emit_once(bool error, const char* fmt, const Args&... params)
template <typename CharT, std::size_t N, typename... Args>
void emit_once(bool error, const CharT(&fmt)[N], const Args&... params)
{
const auto result = m_once_only_messages_set.emplace(fmt::format(fmt, params...));
if (!result.second)
Expand All @@ -359,14 +359,14 @@ namespace rsx
rsx_log.warning("%s", *result.first);
}

template <typename... Args>
void err_once(const char* fmt, const Args&... params)
template <typename CharT, std::size_t N, typename... Args>
void err_once(const CharT(&fmt)[N], const Args&... params)
{
emit_once(true, fmt, params...);
}

template <typename... Args>
void warn_once(const char* fmt, const Args&... params)
template <typename CharT, std::size_t N, typename... Args>
void warn_once(const CharT(&fmt)[N], const Args&... params)
{
emit_once(false, fmt, params...);
}
Expand Down
3 changes: 1 addition & 2 deletions rpcs3/Emu/RSX/rsx_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ namespace rsx

std::string get_message(u32 index, u32 processed, u32 entry_count)
{
const char* text = index == 0 ? "Loading pipeline object %u of %u" : "Compiling pipeline object %u of %u";
return fmt::format(text, processed, entry_count);
return fmt::format("%s pipeline object %u of %u", index == 0 ? "Loading" : "Compiling", processed, entry_count);
};

void load_shaders(uint nb_workers, unpacked_type& unpacked, std::string& directory_path, std::vector<fs::dir_entry>& entries, u32 entry_count,
Expand Down