From 0efd803f309a68dd41dd1a2642edd2caab0485e3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 1 Oct 2023 16:49:13 +0200 Subject: [PATCH 1/5] Make GTKSuppressDiagnostics() work again This got broken by the addition of GTKAllowDiagnosticsControl() in 8af645ed22 (Fix crash when using wxNotebook with glib 2.73 or later, 2022-08-29) as not calling it resulted not only in preventing wx code from installing its own log function implicitly, but also prevented explicit calls to GTKSuppressDiagnostics() from working neither. Fix this by calling GTKAllowDiagnosticsControl() automatically from GTKSuppressDiagnostics() itself. --- src/gtk/app.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index f72d777867..8c092e7bba 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -273,6 +273,9 @@ LogFilterByMessage::~LogFilterByMessage() /* static */ void wxApp::GTKSuppressDiagnostics(int flags) { + // Allow Install() to actually do something. + GTKAllowDiagnosticsControl(); + static wxGTKImpl::LogFilterByLevel s_logFilter; s_logFilter.SetLevelToIgnore(flags); s_logFilter.Install(); From 2a875156609c41801f837daeaee100bf4cf67598 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 1 Oct 2023 16:57:08 +0200 Subject: [PATCH 2/5] Fix filtering out of bogus GTK critical errors in wxNotebook Restore the correct message which was erroneously modified by the changes of 4f4c5fcfdf (Use nullptr instead of NULL in the code and documentation, 2022-10-16). --- src/gtk/notebook.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 8ffa481b0e..eae490c0fe 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -431,7 +431,7 @@ wxNotebookPage *wxNotebook::DoRemovePage( size_t page ) // Suppress bogus assertion failures happening deep inside ATK (used by // GTK) that can't be avoided in any other way, see #22176. wxGTKImpl::LogFilterByMessage filterLog( - "gtk_notebook_get_tab_label: assertion 'list != nullptr' failed" + "gtk_notebook_get_tab_label: assertion 'list != NULL' failed" ); // we don't need to unparent the client->m_widget; GTK+ will do From 6a41d8a48667cc72222ab4e1e8692f856b82a7db Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 1 Oct 2023 17:02:25 +0200 Subject: [PATCH 3/5] Relax code style check for NULL This is fine tuned to allow the string in the last commit to pass this check, but still generally makes sense too. --- .github/workflows/code_checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml index 3538f280b1..c916973cf0 100644 --- a/.github/workflows/code_checks.yml +++ b/.github/workflows/code_checks.yml @@ -93,7 +93,7 @@ jobs: git fetch --depth=1 origin master if git diff origin/master \ ':**.h' ':**.cpp' \ - | grep -E '^\+.*(wxOVERRIDE|wxNOEXCEPT|[^"_@A-Za-z0-9]NULL[^"_A-Za-z0-9])'; then + | grep -E '^\+.*(wxOVERRIDE|wxNOEXCEPT|[^"_@A-Za-z0-9]NULL([- ,;()+*/%&=!?]|$))'; then echo "::error ::Please use C++11 equivalents of the deprecated macros in the new code." exit 1 fi From 95bd6d4cfa97c9fbdd974c534d472444abf83bad Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 1 Oct 2023 17:13:01 +0200 Subject: [PATCH 4/5] Suppress bogus GTK errors from wxNotebook in preferences sample Call GTKAllowDiagnosticsControl() to let the code in wxNotebook suppressing them have an effect. --- samples/preferences/preferences.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/samples/preferences/preferences.cpp b/samples/preferences/preferences.cpp index c3b736ae4b..2ab9d35dd5 100644 --- a/samples/preferences/preferences.cpp +++ b/samples/preferences/preferences.cpp @@ -282,6 +282,13 @@ bool MyApp::OnInit() if ( !wxApp::OnInit() ) return false; +#ifdef __WXGTK__ + // Many version of wxGTK generate spurious diagnostic messages when + // destroying wxNotebook (or removing pages from it), allow wxWidgets to + // suppress them. + GTKAllowDiagnosticsControl(); +#endif // __WXGTK__ + // This will be used in the title of the preferences dialog under some // platforms, don't leave it as default "Preferences" because this would // result in rather strange "Preferences Preferences" title. From 4ffad5074f744bfe38c5c5ed728da591162b90a5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 1 Oct 2023 17:36:54 +0200 Subject: [PATCH 5/5] Add WXSUPPRESS_GTK_DIAGNOSTICS environment variable This allows to suppress some or all GTK diagnostics even for the programs not calling GTKSuppressDiagnostics() nor even GTKAllowDiagnosticsControl() themselves. --- docs/doxygen/overviews/envvars.h | 6 ++++++ interface/wx/app.h | 5 +++++ src/gtk/app.cpp | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/docs/doxygen/overviews/envvars.h b/docs/doxygen/overviews/envvars.h index 051f1dfec3..7b6386d8e4 100644 --- a/docs/doxygen/overviews/envvars.h +++ b/docs/doxygen/overviews/envvars.h @@ -45,6 +45,12 @@ wxWidgets programs. This can be helpful when running older programs recompiled with wxWidgets 3.1 or later, as these asserts are mostly harmless and can be safely ignored if the code works as expected.} +@itemdef{WXSUPPRESS_GTK_DIAGNOSTICS, + If set to a non-zero value, wxApp::GTKSuppressDiagnostics() is called + on program startup using the numeric value of this variable or the + default value if it's not a number, so that e.g. setting it to "yes" + suppresses all GTK diagnostics while setting it to 16 only suppresses + GTK warning messages.} */ @see wxSystemOptions diff --git a/interface/wx/app.h b/interface/wx/app.h index da2a863b9b..b27e504fcb 100644 --- a/interface/wx/app.h +++ b/interface/wx/app.h @@ -1042,6 +1042,11 @@ public: This function can be called to suppress GTK diagnostic messages that are output on the standard error stream by default. + If @c WXSUPPRESS_GTK_DIAGNOSTICS environment variable is set to a + non-zero value, wxWidgets automatically calls this function on program + startup with the value of this variable as @a flags if it's a number or + with the default flags value otherwise. + The default value of the argument disables all messages, but you can pass in a mask flag to specifically disable only particular categories of messages. diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 8c092e7bba..8537b4f8cf 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -392,6 +392,19 @@ bool wxApp::OnInitGui() } #endif + // Suppress GTK diagnostics if requested: this is convenient if the program + // doesn't use GTKAllowDiagnosticsControl() itself. + wxString suppress; + if ( wxGetEnv("WXSUPPRESS_GTK_DIAGNOSTICS", &suppress) ) + { + long flags; + if ( !suppress.ToLong(&flags) ) + flags = -1; // Suppress everything by default. + + if ( flags != 0 ) + GTKSuppressDiagnostics(flags); + } + return true; }