aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-03-16 23:48:30 +1100
committerNeil <nyamatongwe@gmail.com>2021-03-16 23:48:30 +1100
commit99d16b51f142281f7d81cf3f704aff0e97bd1feb (patch)
tree4c650b9eb3c9299ab303fc918a1c263b3fa4637f
parent4ac2ffc2fe88b80ad44fe495ff71912bceb4375a (diff)
downloadscintilla-mirror-99d16b51f142281f7d81cf3f704aff0e97bd1feb.tar.gz
Convert Platform from a class to a namespace. Does not change callers.
Make Assert, DebugPrintf, and similar noexcept so they can be used in noexcept methods and they don't throw.
-rw-r--r--cocoa/PlatCocoa.mm12
-rwxr-xr-xgtk/PlatGTK.cxx10
-rw-r--r--qt/ScintillaEditBase/PlatQt.cpp8
-rw-r--r--src/Platform.h43
-rw-r--r--test/unit/unitTest.cxx4
-rw-r--r--win32/PlatWin.cxx10
6 files changed, 41 insertions, 46 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index 5eb5bf018..3939147c2 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -2089,13 +2089,13 @@ unsigned int Platform::DoubleClickTime() {
//#define TRACE
#ifdef TRACE
-void Platform::DebugDisplay(const char *s) {
+void Platform::DebugDisplay(const char *s) noexcept {
fprintf(stderr, "%s", s);
}
//--------------------------------------------------------------------------------------------------
-void Platform::DebugPrintf(const char *format, ...) {
+void Platform::DebugPrintf(const char *format, ...) noexcept {
const int BUF_SIZE = 2000;
char buffer[BUF_SIZE];
@@ -2108,9 +2108,9 @@ void Platform::DebugPrintf(const char *format, ...) {
#else
-void Platform::DebugDisplay(const char *) {}
+void Platform::DebugDisplay(const char *) noexcept {}
-void Platform::DebugPrintf(const char *, ...) {}
+void Platform::DebugPrintf(const char *, ...) noexcept {}
#endif
@@ -2118,7 +2118,7 @@ void Platform::DebugPrintf(const char *, ...) {}
static bool assertionPopUps = true;
-bool Platform::ShowAssertionPopUps(bool assertionPopUps_) {
+bool Platform::ShowAssertionPopUps(bool assertionPopUps_) noexcept {
bool ret = assertionPopUps;
assertionPopUps = assertionPopUps_;
return ret;
@@ -2126,7 +2126,7 @@ bool Platform::ShowAssertionPopUps(bool assertionPopUps_) {
//--------------------------------------------------------------------------------------------------
-void Platform::Assert(const char *c, const char *file, int line) {
+void Platform::Assert(const char *c, const char *file, int line) noexcept {
char buffer[2000];
snprintf(buffer, sizeof(buffer), "Assertion [%s] failed at %s %d\r\n", c, file, line);
Platform::DebugDisplay(buffer);
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index 1a1907e69..d055ac241 100755
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -2023,14 +2023,14 @@ unsigned int Platform::DoubleClickTime() {
return 500; // Half a second
}
-void Platform::DebugDisplay(const char *s) {
+void Platform::DebugDisplay(const char *s) noexcept {
fprintf(stderr, "%s", s);
}
//#define TRACE
#ifdef TRACE
-void Platform::DebugPrintf(const char *format, ...) {
+void Platform::DebugPrintf(const char *format, ...) noexcept {
char buffer[2000];
va_list pArguments;
va_start(pArguments, format);
@@ -2039,20 +2039,20 @@ void Platform::DebugPrintf(const char *format, ...) {
Platform::DebugDisplay(buffer);
}
#else
-void Platform::DebugPrintf(const char *, ...) {}
+void Platform::DebugPrintf(const char *, ...) noexcept {}
#endif
// Not supported for GTK+
static bool assertionPopUps = true;
-bool Platform::ShowAssertionPopUps(bool assertionPopUps_) {
+bool Platform::ShowAssertionPopUps(bool assertionPopUps_) noexcept {
const bool ret = assertionPopUps;
assertionPopUps = assertionPopUps_;
return ret;
}
-void Platform::Assert(const char *c, const char *file, int line) {
+void Platform::Assert(const char *c, const char *file, int line) noexcept {
char buffer[2000];
g_snprintf(buffer, sizeof(buffer), "Assertion [%s] failed at %s %d\r\n", c, file, line);
Platform::DebugDisplay(buffer);
diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp
index b09812236..72f2b8d5f 100644
--- a/qt/ScintillaEditBase/PlatQt.cpp
+++ b/qt/ScintillaEditBase/PlatQt.cpp
@@ -1211,12 +1211,12 @@ unsigned int Platform::DoubleClickTime()
return QApplication::doubleClickInterval();
}
-void Platform::DebugDisplay(const char *s)
+void Platform::DebugDisplay(const char *s) noexcept
{
qWarning("Scintilla: %s", s);
}
-void Platform::DebugPrintf(const char *format, ...)
+void Platform::DebugPrintf(const char *format, ...) noexcept
{
char buffer[2000];
va_list pArguments;
@@ -1226,12 +1226,12 @@ void Platform::DebugPrintf(const char *format, ...)
Platform::DebugDisplay(buffer);
}
-bool Platform::ShowAssertionPopUps(bool /*assertionPopUps*/)
+bool Platform::ShowAssertionPopUps(bool /*assertionPopUps*/) noexcept
{
return false;
}
-void Platform::Assert(const char *c, const char *file, int line)
+void Platform::Assert(const char *c, const char *file, int line) noexcept
{
char buffer[2000];
sprintf(buffer, "Assertion [%s] failed at %s %d", c, file, line);
diff --git a/src/Platform.h b/src/Platform.h
index 628611132..346e057b1 100644
--- a/src/Platform.h
+++ b/src/Platform.h
@@ -542,31 +542,26 @@ public:
#endif
/**
- * Platform class used to retrieve system wide parameters such as double click speed
- * and chrome colour. Not a creatable object, more of a module with several functions.
+ * Platform namespace used to retrieve system wide parameters such as double click speed
+ * and chrome colour.
*/
-class Platform {
-public:
- Platform() = default;
- Platform(const Platform &) = delete;
- Platform(Platform &&) = delete;
- Platform &operator=(const Platform &) = delete;
- Platform &operator=(Platform &&) = delete;
- ~Platform() = default;
- static ColourDesired Chrome();
- static ColourDesired ChromeHighlight();
- static const char *DefaultFont();
- static int DefaultFontSize();
- static unsigned int DoubleClickTime();
- static void DebugDisplay(const char *s);
- static constexpr long LongFromTwoShorts(short a,short b) noexcept {
- return (a) | ((b) << 16);
- }
-
- static void DebugPrintf(const char *format, ...);
- static bool ShowAssertionPopUps(bool assertionPopUps_);
- static void Assert(const char *c, const char *file, int line) CLANG_ANALYZER_NORETURN;
-};
+namespace Platform {
+
+ColourDesired Chrome();
+ColourDesired ChromeHighlight();
+const char *DefaultFont();
+int DefaultFontSize();
+unsigned int DoubleClickTime();
+constexpr long LongFromTwoShorts(short a,short b) noexcept {
+ return (a) | ((b) << 16);
+}
+
+void DebugDisplay(const char *s) noexcept;
+void DebugPrintf(const char *format, ...) noexcept;
+bool ShowAssertionPopUps(bool assertionPopUps_) noexcept;
+void Assert(const char *c, const char *file, int line) noexcept CLANG_ANALYZER_NORETURN;
+
+}
#ifdef NDEBUG
#define PLATFORM_ASSERT(c) ((void)0)
diff --git a/test/unit/unitTest.cxx b/test/unit/unitTest.cxx
index bff1f9e56..de09fa67e 100644
--- a/test/unit/unitTest.cxx
+++ b/test/unit/unitTest.cxx
@@ -57,12 +57,12 @@ using namespace Scintilla;
// Needed for PLATFORM_ASSERT in code being tested
-void Platform::Assert(const char *c, const char *file, int line) {
+void Platform::Assert(const char *c, const char *file, int line) noexcept {
fprintf(stderr, "Assertion [%s] failed at %s %d\n", c, file, line);
abort();
}
-void Platform::DebugPrintf(const char *format, ...) {
+void Platform::DebugPrintf(const char *format, ...) noexcept {
char buffer[2000];
va_list pArguments;
va_start(pArguments, format);
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 1cae686a2..6fbd05cea 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -3466,14 +3466,14 @@ unsigned int Platform::DoubleClickTime() {
return ::GetDoubleClickTime();
}
-void Platform::DebugDisplay(const char *s) {
+void Platform::DebugDisplay(const char *s) noexcept {
::OutputDebugStringA(s);
}
//#define TRACE
#ifdef TRACE
-void Platform::DebugPrintf(const char *format, ...) {
+void Platform::DebugPrintf(const char *format, ...) noexcept {
char buffer[2000];
va_list pArguments;
va_start(pArguments, format);
@@ -3482,19 +3482,19 @@ void Platform::DebugPrintf(const char *format, ...) {
Platform::DebugDisplay(buffer);
}
#else
-void Platform::DebugPrintf(const char *, ...) {
+void Platform::DebugPrintf(const char *, ...) noexcept {
}
#endif
static bool assertionPopUps = true;
-bool Platform::ShowAssertionPopUps(bool assertionPopUps_) {
+bool Platform::ShowAssertionPopUps(bool assertionPopUps_) noexcept {
const bool ret = assertionPopUps;
assertionPopUps = assertionPopUps_;
return ret;
}
-void Platform::Assert(const char *c, const char *file, int line) {
+void Platform::Assert(const char *c, const char *file, int line) noexcept {
char buffer[2000] {};
sprintf(buffer, "Assertion [%s] failed at %s %d%s", c, file, line, assertionPopUps ? "" : "\r\n");
if (assertionPopUps) {