Skip to content

Commit c780d89

Browse files
iakovjcfr
authored andcommitted
[Backport] Several fixes and patches (commontk#89)
(cherry-picked and adapted from MeVisLab/pythonqt@1e794e5) * minor improvements in code and unit tests * disable warnings for deprecated declarations * add -Wpedantic and even -Werror for src, but relax some warnings * fix undefined behavior * fix memory leaks * use QT_NO_CAST_TO_ASCII to prevent incorrect behavior on non-Latin1 input * Improvements in build and CI: ** add parallel build ** add `make check` support ** fix `debug`/`release` builds ** force C++11 ** introduce UBSan into CI ** fixes for macOS build with clang ** add pkg-config support: if PKGCONFIG is set, skip old-style lookup (useful on Linux and macOS GHA, when `python-config` returns incorrect linkage options with missing `-Ldirs`) ** add macOS GHA CI
1 parent 87f362c commit c780d89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+294
-185
lines changed

PythonQt.pro

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
TEMPLATE = subdirs
22

3-
CONFIG += ordered
43
SUBDIRS = generator src extensions tests examples
4+
tests.depends += src extensions
5+
extensions.depends += src
6+
examples.depends += src extensions

build/common.prf

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,5 @@ PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp
6969
VERSION = 3.2.0
7070

7171
win32: CONFIG += skip_target_version_ext
72-
unix: QMAKE_CXXFLAGS += -std=c++11
72+
unix: CONFIG += c++11
73+
gcc: QMAKE_CXXFLAGS += -Wno-deprecated-declarations

build/python.prf

+30-10
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,27 @@ isEmpty( PYTHON_DIR ) {
1717
PYTHON_DIR=$${PYTHON_DIR}/
1818
}
1919

20-
message(Using Python version $${PYTHON_VERSION})
20+
PYTHON_VERSION_MAJOR=$$section(PYTHON_VERSION, ., 0, 0)
21+
PYTHON_VERSION_MINOR=$$section(PYTHON_VERSION, ., 1, 1)
2122

22-
macx {
23+
!equals(PYTHON_VERSION, $${PYTHON_VERSION_MAJOR}.$${PYTHON_VERSION_MINOR}) {
24+
error("Failed to parse PYTHON_VERSION:\"$$PYTHON_VERSION\"")
25+
} else {
26+
message(Using Python version $${PYTHON_VERSION})
27+
}
28+
29+
30+
# Python 2.x has problems:
31+
# 1) https://wiki.gentoo.org/wiki/Project:Python/Strict_aliasing
32+
# 2) deprecated implicit cast of string literals to char*
33+
equals(PYTHON_VERSION_MAJOR, 2):gcc:QMAKE_CXXFLAGS *= -fno-strict-aliasing -Wno-error=write-strings
34+
contains(PKGCONFIG, "python.*"){
35+
CONFIG += link_pkgconfig
36+
PYTHON_PKGCONFIG = $$member($$unique($$find(PKGCONFIG, "python.*")), 1, 1)
37+
# add rpath
38+
PYTHON_LIBDIR = $$system($$pkgConfigExecutable() --libs-only-L $$PYTHON_PKGCONFIG)
39+
QMAKE_RPATHDIR += $$replace(PYTHON_LIBDIR,-L,)
40+
} else:macx:isEmpty(PYTHON_DIR){
2341
# for macx you need to have the Python development kit installed as framework
2442
INCLUDEPATH += /System/Library/Frameworks/Python.framework/Headers
2543
LIBS += -F/System/Library/Frameworks -framework Python
@@ -52,15 +70,17 @@ macx {
5270
# make sure that you have installed a matching python-dev package.
5371

5472
PYTHON_CONFIG = $${PYTHON_DIR}/bin/python$${PYTHON_VERSION}-config
55-
system($${PYTHON_CONFIG} --embed --libs) {
56-
unix:LIBS += $$system($${PYTHON_CONFIG} --embed --libs)
57-
} else: unix:LIBS += $$system($${PYTHON_CONFIG} --libs)
58-
unix:QMAKE_CXXFLAGS += $$system($${PYTHON_CONFIG} --includes)
73+
PYTHON_CONFIG_OPTIONS_LIBS = --libs
74+
equals(PYTHON_VERSION_MAJOR, 3):!lessThan(PYTHON_VERSION_MINOR, 8) {
75+
# Since 3.8 `--embed` is needed
76+
PYTHON_CONFIG_OPTIONS_LIBS += --embed
77+
}
78+
LIBS += $$system($${PYTHON_CONFIG} $${PYTHON_CONFIG_OPTIONS_LIBS})
79+
QMAKE_CXXFLAGS += $$system($${PYTHON_CONFIG} --includes)
5980
PYTHON_LFLAGS = $$system($${PYTHON_CONFIG} --ldflags)
60-
unix:QMAKE_LFLAGS += $${PYTHON_LFLAGS}
81+
QMAKE_LFLAGS += $${PYTHON_LFLAGS}
6182
# add rpath
6283
PYTHON_LIBDIR = $$find(PYTHON_LFLAGS,-L.*)
63-
RPATH = -Wl,-rpath,
64-
PYTHON_RPATH = $$replace(PYTHON_LIBDIR,-L,$${RPATH})
65-
unix:QMAKE_LFLAGS += $${PYTHON_RPATH}
84+
PYTHON_RPATH = $$replace(PYTHON_LIBDIR,-L,)
85+
QMAKE_RPATHDIR += $$PYTHON_RPATH
6686
}

extensions/PythonQt_QtAll/PythonQt_QtAll.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,5 @@ namespace PythonQt_QtAll
117117
#ifdef PYTHONQT_WITH_UITOOLS
118118
PythonQt_init_QtUiTools(0);
119119
#endif
120-
};
121-
};
122-
123-
120+
}
121+
}

extensions/PythonQt_QtAll/PythonQt_QtAll.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ namespace PythonQt_QtAll
4747
{
4848
//! initialize the Qt binding
4949
PYTHONQT_QTALL_EXPORT void init();
50-
};
50+
}
5151

5252
#endif
+37-31
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# get external pythonqtall config or enable all by default
22

3+
isEmpty( PYTHONQTALL_CONFIG ) {
4+
PYTHONQTALL_CONFIG = $$(PYTHONQTALL_CONFIG)
5+
}
6+
37
isEmpty( PYTHONQTALL_CONFIG ) {
48
message("using default PythonQt_QtAll Configuration")
59
CONFIG += PythonQtCore
6-
CONFIG += PythonQtGui
7-
CONFIG += PythonQtSvg
8-
CONFIG += PythonQtSql
9-
CONFIG += PythonQtNetwork
10-
CONFIG += PythonQtOpengl
11-
CONFIG += PythonQtXml
12-
CONFIG += PythonQtXmlpatterns
13-
CONFIG += PythonQtMultimedia
14-
CONFIG += PythonQtQml
15-
CONFIG += PythonQtQuick
16-
CONFIG += PythonQtUiTools
10+
qtHaveModule(gui):qtHaveModule(widgets):CONFIG += PythonQtGui
11+
qtHaveModule(svg):CONFIG += PythonQtSvg
12+
qtHaveModule(sql):CONFIG += PythonQtSql
13+
qtHaveModule(network):CONFIG += PythonQtNetwork
14+
qtHaveModule(opengl):CONFIG += PythonQtOpengl
15+
qtHaveModule(xml):CONFIG += PythonQtXml
16+
qtHaveModule(xmlpatterns):CONFIG += PythonQtXmlpatterns
17+
qtHaveModule(multimedia):CONFIG += PythonQtMultimedia
18+
qtHaveModule(qml):CONFIG += PythonQtQml
19+
qtHaveModule(quick):CONFIG += PythonQtQuick
20+
qtHaveModule(uitools):CONFIG += PythonQtUiTools
1721

1822
qtHaveModule(webkit):CONFIG += PythonQtWebKit
1923
} else {
@@ -36,10 +40,10 @@ CONFIG += dll qt
3640
DEFINES += PYTHONQT_QTALL_EXPORTS
3741

3842
HEADERS += \
39-
PythonQt_QtAll.h
43+
$$PWD/PythonQt_QtAll.h
4044

4145
SOURCES += \
42-
PythonQt_QtAll.cpp
46+
$$PWD/PythonQt_QtAll.cpp
4347

4448
unix {
4549
CONFIG += create_pc create_prl no_install_prl
@@ -60,79 +64,81 @@ headers.path = /include
6064

6165
INSTALLS += target headers
6266

67+
defineTest(Xinclude) {
68+
f=$$PYTHONQT_GENERATED_PATH/$$1/$${1}.pri
69+
exists($$f):include($$f):export(HEADERS):export(SOURCES):export(DEFINES)
70+
71+
}
72+
73+
6374
PythonQtCore {
6475
DEFINES += PYTHONQT_WITH_CORE
65-
include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_core/com_trolltech_qt_core.pri)
76+
Xinclude (com_trolltech_qt_core)
6677
}
6778

6879
PythonQtGui {
6980
DEFINES += PYTHONQT_WITH_GUI
70-
include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_gui/com_trolltech_qt_gui.pri)
81+
Xinclude (com_trolltech_qt_gui)
7182
QT += gui widgets printsupport
7283
}
7384

7485
PythonQtSvg {
7586
DEFINES += PYTHONQT_WITH_SVG
76-
include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_svg/com_trolltech_qt_svg.pri)
87+
Xinclude (com_trolltech_qt_svg)
7788
QT +=svg
7889
}
7990

8091
PythonQtSql {
8192
DEFINES += PYTHONQT_WITH_SQL
82-
include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_sql/com_trolltech_qt_sql.pri)
93+
Xinclude (com_trolltech_qt_sql)
8394
QT += sql
8495
}
8596

8697
PythonQtNetwork {
8798
DEFINES += PYTHONQT_WITH_NETWORK
88-
include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_network/com_trolltech_qt_network.pri)
99+
Xinclude (com_trolltech_qt_network)
89100
QT += network
90101
}
91102

92103
PythonQtOpengl {
93104
DEFINES += PYTHONQT_WITH_OPENGL
94-
PythonQtCore: include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_opengl/com_trolltech_qt_opengl.pri)
95105
QT += opengl
96-
}
97-
98-
PythonQtXml {
99-
DEFINES += PYTHONQT_WITH_XML
100-
include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_xml/com_trolltech_qt_xml.pri)
106+
PythonQtCore: Xinclude (com_trolltech_qt_opengl)
101107
QT += xml
102108
}
103109

104110
PythonQtXmlpatterns {
105111
DEFINES += PYTHONQT_WITH_XMLPATTERNS
106-
include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_xmlpatterns/com_trolltech_qt_xmlpatterns.pri)
112+
Xinclude (com_trolltech_qt_xmlpatterns)
107113
QT += xmlpatterns
108114
}
109115

110116
PythonQtMultimedia {
111117
DEFINES += PYTHONQT_WITH_MULTIMEDIA
112-
include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_multimedia/com_trolltech_qt_multimedia.pri)
113-
QT += multimedia multimediawidgets
118+
Xinclude (com_trolltech_qt_multimedia)
119+
QT += multimedia multimediawidgets
114120
}
115121

116122
PythonQtQml {
117123
DEFINES += PYTHONQT_WITH_QML
118-
include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_qml/com_trolltech_qt_qml.pri)
124+
Xinclude (com_trolltech_qt_qml)
119125
QT += qml
120126
}
121127

122128
PythonQtQuick {
123129
DEFINES += PYTHONQT_WITH_QUICK
124-
include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_quick/com_trolltech_qt_quick.pri)
130+
Xinclude (com_trolltech_qt_quick)
125131
QT += quick quickwidgets
126132
}
127133

128134
PythonQtUiTools {
129135
DEFINES += PYTHONQT_WITH_UITOOLS
130-
include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_uitools/com_trolltech_qt_uitools.pri)
136+
Xinclude (com_trolltech_qt_uitools)
131137
QT += uitools
132138
}
133139

134140
PythonQtWebKit {
135141
DEFINES += PYTHONQT_WITH_WEBKIT
136-
include ($$PYTHONQT_GENERATED_PATH/com_trolltech_qt_webkit/com_trolltech_qt_webkit.pri)
142+
Xinclude (com_trolltech_qt_webkit)
137143
QT += webkit webkitwidgets
138144
}

generator/abstractmetabuilder.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ int AbstractMetaBuilder::figureOutEnumValue(const QString &stringValue,
746746
AbstractMetaEnum *meta_enum,
747747
AbstractMetaFunction *meta_function)
748748
{
749+
Q_UNUSED(meta_function)
749750
if (stringValue.isEmpty())
750751
return oldValuevalue;
751752

@@ -1619,12 +1620,15 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(FunctionModelItem fu
16191620

16201621
// If we where not able to translate the default argument make it
16211622
// reset all default arguments before this one too.
1622-
for (int i=0; i<first_default_argument; ++i)
1623+
for (int i=0; i<first_default_argument; ++i) {
16231624
meta_arguments[i]->setDefaultValueExpression(QString());
1625+
}
16241626

1625-
if (ReportHandler::debugLevel() == ReportHandler::FullDebug)
1626-
foreach(AbstractMetaArgument *arg, meta_arguments)
1627+
if (ReportHandler::debugLevel() == ReportHandler::FullDebug) {
1628+
foreach(AbstractMetaArgument *arg, meta_arguments) {
16271629
ReportHandler::debugFull(" - " + arg->toString());
1630+
}
1631+
}
16281632

16291633
return meta_function;
16301634
}
@@ -1944,6 +1948,7 @@ QString AbstractMetaBuilder::translateDefaultValue(ArgumentModelItem item, Abstr
19441948
AbstractMetaFunction *fnc, AbstractMetaClass *implementing_class,
19451949
int argument_index)
19461950
{
1951+
Q_UNUSED(type)
19471952
QString function_name = fnc->name();
19481953
QString class_name = implementing_class->name();
19491954

generator/abstractmetalang.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1205,13 +1205,13 @@ AbstractMetaField *AbstractMetaField::copy() const
12051205

12061206
return returned;
12071207
}
1208-
1208+
/* UNUSED
12091209
static QString upCaseFirst(const QString &str) {
12101210
Q_ASSERT(!str.isEmpty());
12111211
QString s = str;
12121212
s[0] = s.at(0).toUpper();
12131213
return s;
1214-
}
1214+
} */
12151215

12161216
static AbstractMetaFunction *createXetter(const AbstractMetaField *g, const QString &name, uint type) {
12171217
AbstractMetaFunction *f = new AbstractMetaFunction;

generator/generator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Generator : public QObject
5454
{
5555
Q_OBJECT
5656

57-
Q_PROPERTY(QString outputDirectory READ outputDirectory WRITE setOutputDirectory);
57+
Q_PROPERTY(QString outputDirectory READ outputDirectory WRITE setOutputDirectory)
5858

5959
public:
6060
enum Option {

generator/generator.pri

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ isEmpty(GENERATORPATH):GENERATORPATH = $$PWD
22
INCLUDEPATH += $$GENERATORPATH
33

44
TEMPLATE = app
5+
#CONFIG += cmdline -- does not work as expected with old Qt versions, f.e. is missing in 5.9
6+
CONFIG += console
7+
CONFIG -= app_bundle
8+
59
TARGET +=
610
DEPENDPATH += $$GENERATORPATH tests parser
7-
mac:CONFIG -= app_bundle
811
INCLUDEPATH += $$GENERATORPATH/.
912
INCLUDEPATH += $$GENERATORPATH/../common
1013

11-
unix:CONFIG += debug_and_release
12-
13-
CONFIG += console
1414
RESOURCES += generator.qrc
1515

1616
include($$GENERATORPATH/parser/rxx.pri)
@@ -21,6 +21,8 @@ win32-msvc2005:{
2121
QMAKE_CXXFLAGS += -wd4996
2222
QMAKE_CFLAGS += -wd4996
2323
}
24+
gcc:QMAKE_CXXFLAGS += -Wno-deprecated-declarations -Wpedantic
25+
clang: QMAKE_CXXFLAGS += -Wno-nested-anon-types -Wno-gnu-anonymous-struct -Wno-unused-private-field
2426

2527
# Input
2628
HEADERS += \
@@ -58,7 +60,7 @@ SOURCES += \
5860

5961

6062

61-
QT = core xml
63+
QT += core xml
6264

6365
win32-msvc.net {
6466
QMAKE_CXXFLAGS += /Zm500

generator/generator.pro

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
TARGET = pythonqt_generator
2-
CONFIG -= debug
3-
CONFIG += release
42
DESTDIR = .
53

64
include(generator.pri)
7-
5+
DEFINES += QT_NO_CAST_TO_ASCII
86

97
# Input
108
HEADERS += \

generator/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void displayHelp(GeneratorSet *generatorSet);
5353
#include <QDebug>
5454
int main(int argc, char *argv[])
5555
{
56-
GeneratorSet *gs = GeneratorSet::getInstance();
56+
QScopedPointer<GeneratorSet> gs(GeneratorSet::getInstance());
5757

5858
QString default_file = ":/trolltech/generator/qtscript_masterinclude.h";
5959
QString default_system = ":/trolltech/generator/build_all.txt";
@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
118118

119119
typesystemFileName = args.value("arg-2");
120120
if (args.contains("arg-3"))
121-
displayHelp(gs);
121+
displayHelp(&*gs);
122122

123123
if (fileName.isEmpty())
124124
fileName = default_file;
@@ -127,10 +127,10 @@ int main(int argc, char *argv[])
127127
typesystemFileName = default_system;
128128

129129
if (fileName.isEmpty() || typesystemFileName.isEmpty() )
130-
displayHelp(gs);
130+
displayHelp(&*gs);
131131

132132
if (!gs->readParameters(args))
133-
displayHelp(gs);
133+
displayHelp(&*gs);
134134

135135
printf("Please wait while source files are being generated...\n");
136136

generator/parser/codemodel.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ bool TypeInfo::operator==(const TypeInfo &other)
232232
}
233233
#endif
234234

235-
return flags == other.flags
235+
return m_flags.equals(other.m_flags)
236236
&& m_qualifiedName == other.m_qualifiedName
237-
&& (!m_functionPointer || m_arguments == other.m_arguments);
237+
&& (!m_flags.m_functionPointer || m_arguments == other.m_arguments);
238238
}
239239

240240
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)