Merge pull request #1886 from MaddTheSane/morePrintfLike

More printflike macros
This commit is contained in:
Connor McLaughlin 2021-04-01 02:29:05 +10:00 committed by GitHub
commit c825292a93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 27 additions and 26 deletions

View file

@ -61,7 +61,7 @@ bool CDImageMemory::CopyImage(CDImage* image, ProgressCallback* progress)
static_cast<u8*>(std::malloc(static_cast<size_t>(RAW_SECTOR_SIZE) * static_cast<size_t>(m_memory_sectors)));
if (!m_memory)
{
progress->DisplayFormattedModalError("Failed to allocate memory for %llu sectors", m_memory_sectors);
progress->DisplayFormattedModalError("Failed to allocate memory for %u sectors", m_memory_sectors);
return false;
}

View file

@ -23,7 +23,7 @@ public:
virtual void SetProgressValue(u32 value) = 0;
virtual void IncrementProgressValue() = 0;
void SetFormattedStatusText(const char* Format, ...);
void SetFormattedStatusText(const char* Format, ...) printflike(2, 3);
virtual void DisplayError(const char* message) = 0;
virtual void DisplayWarning(const char* message) = 0;
@ -34,13 +34,13 @@ public:
virtual bool ModalConfirmation(const char* message) = 0;
virtual void ModalInformation(const char* message) = 0;
void DisplayFormattedError(const char* format, ...);
void DisplayFormattedWarning(const char* format, ...);
void DisplayFormattedInformation(const char* format, ...);
void DisplayFormattedDebugMessage(const char* format, ...);
void DisplayFormattedModalError(const char* format, ...);
bool DisplayFormattedModalConfirmation(const char* format, ...);
void DisplayFormattedModalInformation(const char* format, ...);
void DisplayFormattedError(const char* format, ...) printflike(2, 3);
void DisplayFormattedWarning(const char* format, ...) printflike(2, 3);
void DisplayFormattedInformation(const char* format, ...) printflike(2, 3);
void DisplayFormattedDebugMessage(const char* format, ...) printflike(2, 3);
void DisplayFormattedModalError(const char* format, ...) printflike(2, 3);
bool DisplayFormattedModalConfirmation(const char* format, ...) printflike(2, 3);
void DisplayFormattedModalInformation(const char* format, ...) printflike(2, 3);
void UpdateProgressFromStream(ByteStream* stream);

View file

@ -104,7 +104,7 @@ public:
void AppendSubString(const char* appendText, s32 Offset = 0, s32 Count = std::numeric_limits<s32>::max());
// append formatted string to this string
void AppendFormattedString(const char* FormatString, ...);
void AppendFormattedString(const char* FormatString, ...) printflike(2, 3);
void AppendFormattedStringVA(const char* FormatString, va_list ArgPtr);
// append a single character to this string
@ -122,7 +122,7 @@ public:
void PrependSubString(const char* appendText, s32 Offset = 0, s32 Count = std::numeric_limits<s32>::max());
// append formatted string to this string
void PrependFormattedString(const char* FormatString, ...);
void PrependFormattedString(const char* FormatString, ...) printflike(2, 3);
void PrependFormattedStringVA(const char* FormatString, va_list ArgPtr);
// insert a string at the specified offset
@ -133,7 +133,7 @@ public:
void InsertString(s32 offset, const std::string_view& appendStr);
// set to formatted string
void Format(const char* FormatString, ...);
void Format(const char* FormatString, ...) printflike(2, 3);
void FormatVA(const char* FormatString, va_list ArgPtr);
// compare one string to another
@ -229,7 +229,7 @@ public:
}
// creates a new string from the specified format
static String FromFormat(const char* FormatString, ...);
static String FromFormat(const char* FormatString, ...) printflike(1, 2);
// accessor operators
// const char &operator[](u32 i) const { DebugAssert(i < m_pStringData->StringLength); return
@ -345,7 +345,7 @@ public:
}
// Override the fromstring method
static StackString FromFormat(const char* FormatString, ...)
static StackString FromFormat(const char* FormatString, ...) printflike(1, 2)
{
va_list argPtr;
va_start(argPtr, FormatString);

View file

@ -21,7 +21,7 @@
namespace StringUtil {
/// Constructs a std::string from a format string.
std::string StdStringFromFormat(const char* format, ...);
std::string StdStringFromFormat(const char* format, ...) printflike(1, 2);
std::string StdStringFromFormatV(const char* format, std::va_list ap);
/// Checks if a wildcard matches a search string.

View file

@ -74,7 +74,7 @@ VkShaderModule CompileAndCreateFragmentShader(std::string_view source_code);
VkShaderModule CompileAndCreateComputeShader(std::string_view source_code);
const char* VkResultToString(VkResult res);
void LogVulkanResult(int level, const char* func_name, VkResult res, const char* msg, ...);
void LogVulkanResult(int level, const char* func_name, VkResult res, const char* msg, ...) printflike(4, 5);
#define LOG_VULKAN_ERROR(res, ...) ::Vulkan::Util::LogVulkanResult(1, __func__, res, __VA_ARGS__)

View file

@ -148,7 +148,7 @@ void DisassembleAndLog(u32 addr);
void DisassembleAndPrint(u32 addr, u32 instructions_before, u32 instructions_after);
// Write to CPU execution log file.
void WriteToExecutionLog(const char* format, ...);
void WriteToExecutionLog(const char* format, ...) printflike(1, 2);
// Trace Routines
bool IsTraceEnabled();

View file

@ -101,7 +101,7 @@ bool HostInterface::BootSystem(const SystemBootParameters& parameters)
if (!AcquireHostDisplay())
{
ReportFormattedError(g_host_interface->TranslateString("System", "Failed to acquire host display."));
ReportError(g_host_interface->TranslateString("System", "Failed to acquire host display."));
OnSystemDestroyed();
return false;
}
@ -118,7 +118,7 @@ bool HostInterface::BootSystem(const SystemBootParameters& parameters)
{
if (!System::IsStartupCancelled())
{
ReportFormattedError(
ReportError(
g_host_interface->TranslateString("System", "System failed to boot. The log may contain more information."));
}

View file

@ -64,23 +64,23 @@ public:
virtual void ReportDebuggerMessage(const char* message);
virtual bool ConfirmMessage(const char* message);
void ReportFormattedError(const char* format, ...);
void ReportFormattedMessage(const char* format, ...);
void ReportFormattedDebuggerMessage(const char* format, ...);
bool ConfirmFormattedMessage(const char* format, ...);
void ReportFormattedError(const char* format, ...) printflike(2, 3);
void ReportFormattedMessage(const char* format, ...) printflike(2, 3);
void ReportFormattedDebuggerMessage(const char* format, ...) printflike(2, 3);
bool ConfirmFormattedMessage(const char* format, ...) printflike(2, 3);
/// Adds OSD messages, duration is in seconds.
virtual void AddOSDMessage(std::string message, float duration = 2.0f);
void AddFormattedOSDMessage(float duration, const char* format, ...);
void AddFormattedOSDMessage(float duration, const char* format, ...) printflike(3, 4);
/// Returns the base user directory path.
ALWAYS_INLINE const std::string& GetUserDirectory() const { return m_user_directory; }
/// Returns a path relative to the user directory.
std::string GetUserDirectoryRelativePath(const char* format, ...) const;
std::string GetUserDirectoryRelativePath(const char* format, ...) const printflike(2, 3);
/// Returns a path relative to the application directory (for system files).
std::string GetProgramDirectoryRelativePath(const char* format, ...) const;
std::string GetProgramDirectoryRelativePath(const char* format, ...) const printflike(2, 3);
/// Returns a string which can be used as part of a filename, based on the current date/time.
static TinyString GetTimestampStringForFileName();

View file

@ -85,6 +85,7 @@ static ALWAYS_INLINE CommonHostInterface* GetHostInterface()
return static_cast<CommonHostInterface*>(g_host_interface);
}
static void FormattedError(const char* format, ...) printflike(1, 2);
static void FormattedError(const char* format, ...)
{
std::va_list ap;