Gtk library: Add configuration to avoid syntax error, add test file (#1109)

Add configuration for G_UNLIKELY and G_LIKELY to avoid syntax errors
when these macros are used as condition without enclosing brackets.
Add test file to verify Gtk library configuration. Syntax check for the
test file is only done when Gtk+2.0 or Gtk+3.0 is found and working.
Tested on Cygwin and on Ubuntu 16.04.
This commit is contained in:
Sebastian 2018-03-10 11:22:10 +01:00 committed by amai2012
parent c63cda4439
commit 7ba9ab7e4c
3 changed files with 57 additions and 0 deletions

View File

@ -5,6 +5,8 @@
<define name="g_return_val_if_fail(expr, val)" value="do{if(!(expr)){return val;}}while(0)"/> <define name="g_return_val_if_fail(expr, val)" value="do{if(!(expr)){return val;}}while(0)"/>
<define name="g_return_if_reached()" value="do{return;}while(0)"/> <define name="g_return_if_reached()" value="do{return;}while(0)"/>
<define name="g_return_val_if_reached(val)" value="do{return val;}while(0)"/> <define name="g_return_val_if_reached(val)" value="do{return val;}while(0)"/>
<define name="G_LIKELY(expr)" value="(expr)"/>
<define name="G_UNLIKELY(expr)" value="(expr)"/>
<memory> <memory>
<alloc init="true">g_thread_new</alloc> <alloc init="true">g_thread_new</alloc>
<alloc init="true">g_thread_try_new</alloc> <alloc init="true">g_thread_try_new</alloc>

22
test/cfg/gtk.c Normal file
View File

@ -0,0 +1,22 @@
// Test library configuration for gtk.cfg
//
// Usage:
// $ cppcheck --check-library --enable=information --inconclusive --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr --library=gtk test/cfg/gtk.cpp
// =>
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
//
#include <gtk/gtk.h>
void validCode(int argInt)
{
// if G_UNLIKELY is not defined this results in a syntax error
if G_UNLIKELY(argInt == 1) {
} else if (G_UNLIKELY(argInt == 2)) {
}
if G_LIKELY(argInt == 0) {
} else if (G_LIKELY(argInt == -1)) {
}
}

View File

@ -64,3 +64,36 @@ else
fi fi
fi fi
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=wxwidgets -f ${DIR}wxwidgets.cpp ${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=wxwidgets -f ${DIR}wxwidgets.cpp
# gtk.c
set +e
pkg-config --version
PKGCONFIG_RETURNCODE=$?
set -e
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then
echo "pkg-config needed to retrieve GTK+ configuration is not available, skipping syntax check."
else
set +e
GTKCONFIG=$(pkg-config --cflags gtk+-3.0)
GTKCONFIG_RETURNCODE=$?
set -e
if [ $GTKCONFIG_RETURNCODE -ne 0 ]; then
set +e
GTKCONFIG=$(pkg-config --cflags gtk+-2.0)
GTKCONFIG_RETURNCODE=$?
set -e
fi
if [ $GTKCONFIG_RETURNCODE -eq 0 ]; then
set +e
echo -e "#include <gtk/gtk.h>" | ${CC} ${CC_OPT} ${GTKCONFIG} -x c -
GTKCHECK_RETURNCODE=$?
set -e
if [ $GTKCHECK_RETURNCODE -ne 0 ]; then
echo "GTK+ not completely present or not working, skipping syntax check with ${CXX}."
else
echo "GTK+ found and working, checking syntax with ${CXX} now."
${CC} ${CC_OPT} ${GTKCONFIG} ${DIR}gtk.c
fi
fi
fi
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=gtk -f ${DIR}gtk.c