Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
before_install:
# install needed deps
- travis_retry sudo apt-get update -qq
- travis_retry sudo apt-get install -qq python-pygments qt5-default qt5-qmake qtbase5-dev qtcreator libxml2-utils libpcre3 gdb unzip wx-common xmlstarlet
- travis_retry sudo apt-get install -qq python-pygments qt5-default qt5-qmake qtbase5-dev qtcreator libxml2-utils libpcre3 gdb unzip wx-common xmlstarlet python3-dev
- travis_retry python2 -m pip install --user pytest==4.6.4
- travis_retry python2 -m pip install --user pylint
- travis_retry python2 -m pip install --user unittest2
Expand Down
2 changes: 1 addition & 1 deletion cfg/python.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</arg>
</function>
<!-- Those are macros, but it's helpful to declare a function here -->
<function name="Py_XINCREF,Py_XDECREF">
<function name="Py_XINCREF,Py_XDECREF,Py_CLEAR">
<leak-ignore/>
<noreturn>false</noreturn>
<returnValue type="void"/>
Expand Down
34 changes: 34 additions & 0 deletions test/cfg/python.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

// Test library configuration for python.cfg
//
// Usage:
// $ cppcheck --check-library --library=python --enable=information --error-exitcode=1 --inline-suppr --suppress=missingIncludeSystem test/cfg/python.c
// =>
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
//

#define PY_SSIZE_T_CLEAN
#include <Python.h> // should be the first include

void validCode(PyObject * pPyObjArg)
{
PyObject * pPyObjNULL = NULL;
Py_Initialize();
Py_INCREF(pPyObjArg);
Py_DECREF(pPyObjArg);
Py_XINCREF(pPyObjArg);
Py_XINCREF(pPyObjNULL);
Py_XDECREF(pPyObjArg);
Py_XDECREF(pPyObjNULL);
Py_CLEAR(pPyObjArg);
Py_CLEAR(pPyObjNULL);
(void)PyErr_NewException("text", NULL, NULL);
}

void nullPointer()
{
// cppcheck-suppress nullPointer
Py_INCREF(NULL);
// cppcheck-suppress nullPointer
Py_DECREF(NULL);
}
27 changes: 27 additions & 0 deletions test/cfg/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,33 @@ ${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=sqlite3 ${DIR}sqlite3.c
${CC} ${CC_OPT} -fopenmp ${DIR}openmp.c
${CPPCHECK} ${CPPCHECK_OPT} --library=openmp ${DIR}openmp.c

# python.c
set +e
pkg-config --version
PKGCONFIG_RETURNCODE=$?
set -e
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then
echo "pkg-config needed to retrieve Python 3 configuration is not available, skipping syntax check."
else
set +e
PYTHON3CONFIG=$(pkg-config --cflags python3)
PYTHON3CONFIG_RETURNCODE=$?
set -e
if [ $PYTHON3CONFIG_RETURNCODE -eq 0 ]; then
set +e
echo -e "#include <Python.h>" | ${CC} ${CC_OPT} ${PYTHON3CONFIG} -x c -
PYTHON3CONFIG_RETURNCODE=$?
set -e
if [ $PYTHON3CONFIG_RETURNCODE -ne 0 ]; then
echo "Python 3 not completely present or not working, skipping syntax check with ${CC}."
else
echo "Python 3 found and working, checking syntax with ${CC} now."
${CC} ${CC_OPT} ${PYTHON3CONFIG} ${DIR}python.c
fi
fi
fi
${CPPCHECK} ${CPPCHECK_OPT} --library=python ${DIR}python.c

# Check the syntax of the defines in the configuration files
set +e
xmlstarlet --version
Expand Down