Merge branch 'gtk-diag-suppress'

Fixes for suppressing bogus GTK diagnostics.

See #23923.
This commit is contained in:
Vadim Zeitlin 2023-10-02 19:34:40 +02:00
commit 9bfd72e7f7
6 changed files with 36 additions and 2 deletions

View file

@ -93,7 +93,7 @@ jobs:
git fetch --depth=1 origin master git fetch --depth=1 origin master
if git diff origin/master \ if git diff origin/master \
':**.h' ':**.cpp' \ ':**.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." echo "::error ::Please use C++11 equivalents of the deprecated macros in the new code."
exit 1 exit 1
fi fi

View file

@ -45,6 +45,12 @@ wxWidgets programs.
This can be helpful when running older programs recompiled with This can be helpful when running older programs recompiled with
wxWidgets 3.1 or later, as these asserts are mostly harmless and can wxWidgets 3.1 or later, as these asserts are mostly harmless and can
be safely ignored if the code works as expected.} 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 @see wxSystemOptions

View file

@ -1042,6 +1042,11 @@ public:
This function can be called to suppress GTK diagnostic messages that This function can be called to suppress GTK diagnostic messages that
are output on the standard error stream by default. 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 The default value of the argument disables all messages, but you
can pass in a mask flag to specifically disable only particular can pass in a mask flag to specifically disable only particular
categories of messages. categories of messages.

View file

@ -282,6 +282,13 @@ bool MyApp::OnInit()
if ( !wxApp::OnInit() ) if ( !wxApp::OnInit() )
return false; 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 // This will be used in the title of the preferences dialog under some
// platforms, don't leave it as default "Preferences" because this would // platforms, don't leave it as default "Preferences" because this would
// result in rather strange "Preferences Preferences" title. // result in rather strange "Preferences Preferences" title.

View file

@ -273,6 +273,9 @@ LogFilterByMessage::~LogFilterByMessage()
/* static */ /* static */
void wxApp::GTKSuppressDiagnostics(int flags) void wxApp::GTKSuppressDiagnostics(int flags)
{ {
// Allow Install() to actually do something.
GTKAllowDiagnosticsControl();
static wxGTKImpl::LogFilterByLevel s_logFilter; static wxGTKImpl::LogFilterByLevel s_logFilter;
s_logFilter.SetLevelToIgnore(flags); s_logFilter.SetLevelToIgnore(flags);
s_logFilter.Install(); s_logFilter.Install();
@ -389,6 +392,19 @@ bool wxApp::OnInitGui()
} }
#endif #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; return true;
} }

View file

@ -431,7 +431,7 @@ wxNotebookPage *wxNotebook::DoRemovePage( size_t page )
// Suppress bogus assertion failures happening deep inside ATK (used by // Suppress bogus assertion failures happening deep inside ATK (used by
// GTK) that can't be avoided in any other way, see #22176. // GTK) that can't be avoided in any other way, see #22176.
wxGTKImpl::LogFilterByMessage filterLog( 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 // we don't need to unparent the client->m_widget; GTK+ will do