From 8397a44bedf542b53284674c87268819f4911d31 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 22 Feb 2012 16:17:30 +0100 Subject: QByteArray: deprecate QT_NO_CAST_FROM_BYTEARRAY-protected operators The QByteArray::operator const {char,void}*() implicit conversions are a source of subtle bugs, so they right- fully can be disabled with QT_NO_CAST_FROM_BYTEARRAY. const char *d = qstring.toLatin1(); // implicit conversion while ( d ) // oops: d points to freed memory // ... But almost no-one ever enabled this macros in the wild and many were bitten by these implicit conversions, so this patch deprecates them. I would have liked to remove them completely, but there are just too many occurrences even in Qt itself to hope to find all conditionally-compiled code that uses these. Also fixes all code that needs to compile under QT_NO_DEPRECATED (in qmake/, src/tools/). I984706452db7d0841620a0f64e179906123f3849 separately deals with the bulk of changes in src/ and examples/. Depends on I5ea1ad3c96d9e64167be53c0c418c7b7dba51f68. Change-Id: I8d47e6c293c80f61c6288c9f8d42fda41afe2267 Reviewed-by: David Faure Reviewed-by: Lars Knoll --- src/tools/rcc/rcc.cpp | 2 +- src/tools/uic/cpp/cppwriteicondata.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/tools') diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp index 5fbda35fc6..bfb3206778 100644 --- a/src/tools/rcc/rcc.cpp +++ b/src/tools/rcc/rcc.cpp @@ -681,7 +681,7 @@ bool RCCResourceLibrary::output(QIODevice &outDevice, QIODevice &errorDevice) m_errorDevice->write("Could not write footer\n"); return false; } - outDevice.write(m_out, m_out.size()); + outDevice.write(m_out.constData(), m_out.size()); return true; } diff --git a/src/tools/uic/cpp/cppwriteicondata.cpp b/src/tools/uic/cpp/cppwriteicondata.cpp index 39ce52f4b3..082961cfe6 100644 --- a/src/tools/uic/cpp/cppwriteicondata.cpp +++ b/src/tools/uic/cpp/cppwriteicondata.cpp @@ -176,8 +176,8 @@ void WriteIconData::writeImage(QTextStream &output, const QString &indent, void WriteIconData::writeImage(QIODevice &output, DomImage *image) { - QByteArray array = transformImageData(image->elementData()->text()); - output.write(array, array.size()); + const QByteArray array = transformImageData(image->elementData()->text()); + output.write(array.constData(), array.size()); } } // namespace CPP -- cgit v1.2.3 From 5bb1408927b4eb5a03e8ab9f7cbc68f80d8a3962 Mon Sep 17 00:00:00 2001 From: Matthew Vogt Date: Thu, 23 Feb 2012 11:12:58 +1000 Subject: Allow moc to handle symbols that have been redefined. Allow moc to produce the desired identifiers when used with C++ symbol names that have been redefined, for example by -Dfoo=bar. Two changes are required: firstly, when encoding a type name, the components of the name must be checked for substitutions that have been defined for that token (note that this is not done here by correct pre-processing, but only by processing the resultant table of definitions). Secondly, the arguments to the SIGNAL, SLOT and METHOD macros must be allowed to be substituted during macro expansion rather than stringized directly. This is a temporary change to prevent breaking existing projects that depend on the declarative module. After clients have had an opportunity to update their code to the use the new interfaces, it can be removed. Task-number: QTBUG-23737 Change-Id: I39e6844cebf6ca7984af6028160b8a3797ac44a5 Reviewed-by: Martin Jones --- src/tools/moc/main.cpp | 2 +- src/tools/moc/moc.cpp | 110 ++++++++++++++++++++++++++++++++++++++++++++++++- src/tools/moc/moc.h | 13 +++++- 3 files changed, 120 insertions(+), 5 deletions(-) (limited to 'src/tools') diff --git a/src/tools/moc/main.cpp b/src/tools/moc/main.cpp index 772df1feec..6f67a7dddf 100644 --- a/src/tools/moc/main.cpp +++ b/src/tools/moc/main.cpp @@ -159,7 +159,7 @@ int runMoc(int _argc, char **_argv) bool autoInclude = true; bool defaultInclude = true; Preprocessor pp; - Moc moc; + Moc moc(pp); pp.macros["Q_MOC_RUN"]; pp.macros["__cplusplus"]; QByteArray filename; diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 7b358c1ae8..4189c29de1 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -304,7 +304,9 @@ void Moc::parseFunctionArguments(FunctionDef *def) arg.rightType += lexem(); } arg.normalizedType = normalizeType(QByteArray(arg.type.name + ' ' + arg.rightType)); + arg.normalizedType = getTypeSubstitution(arg.normalizedType); arg.typeNameForCast = normalizeType(QByteArray(noRef(arg.type.name) + "(*)" + arg.rightType)); + arg.typeNameForCast = getTypeSubstitution(arg.typeNameForCast); if (test(EQ)) arg.isDefault = true; def->arguments += arg; @@ -414,6 +416,7 @@ bool Moc::parseFunction(FunctionDef *def, bool inMacro) } def->normalizedType = normalizeType(def->type.name); + def->normalizedType = getTypeSubstitution(def->normalizedType); if (!test(RPAREN)) { parseFunctionArguments(def); @@ -512,6 +515,7 @@ bool Moc::parseMaybeFunction(const ClassDef *cdef, FunctionDef *def) } def->normalizedType = normalizeType(def->type.name); + def->normalizedType = getTypeSubstitution(def->normalizedType); if (!test(RPAREN)) { parseFunctionArguments(def); @@ -968,6 +972,7 @@ void Moc::createPropertyDef(PropertyDef &propDef) QVariant. */ type = normalizeType(type); + type = getTypeSubstitution(type); if (type == "QMap") type = "QMap"; else if (type == "QValueList") @@ -1081,7 +1086,6 @@ void Moc::parseProperty(ClassDef *def) createPropertyDef(propDef); next(RPAREN); - if(!propDef.notify.isEmpty()) def->notifyableProperties++; if (propDef.revision > 0) @@ -1244,7 +1248,8 @@ void Moc::parseInterfaces(ClassDef *def) } // resolve from classnames to interface ids for (int i = 0; i < iface.count(); ++i) { - const QByteArray iid = interface2IdMap.value(iface.at(i).className); + QByteArray className = getTypeSubstitution(iface.at(i).className); + QByteArray iid = interface2IdMap.value(className); if (iid.isEmpty()) error("Undefined interface"); @@ -1502,6 +1507,107 @@ void Moc::checkProperties(ClassDef *cdef) } } +QByteArray Moc::getSubstitution(const QByteArray &token) const +{ + Macros::ConstIterator it = preprocessor.macros.find(token); + if (it != preprocessor.macros.end() && it->symbols.count() == 1) { + // We can only handle substitutions that result in a single symbol + return it->symbols.at(0).lexem(); + } + + return QByteArray(); +} + +QByteArray Moc::getTokenSubstitution(const QByteArray &token) const +{ + QByteArray result = token; + + QSet used; + + // Process substitution chain until no replacement exists + QByteArray substitution = getSubstitution(result); + while (!substitution.isEmpty()) { + used.insert(result); + result = substitution; + + if (used.contains(result)) { + break; + } + + substitution = getSubstitution(result); + } + + return result; +} + +QByteArray Moc::getWordSubstitution(const QByteArray &word) const +{ + QByteArray result; + + // A word can contain multiple components separated by '*' + int startIndex = 0; + do { + int index = word.indexOf('*', startIndex); + if (index == -1) { + result.append(getTokenSubstitution(word.mid(startIndex))); + } else { + result.append(getTokenSubstitution(word.mid(startIndex, (index - startIndex)))); + result.append('*'); + } + + startIndex = index + 1; + } while (startIndex != 0); + + return result; +} + +QByteArray Moc::getNameSubstitution(const QByteArray &name) const +{ + QByteArray result; + + // Parse multiple tokens in this name independently + int startIndex = 0; + do { + int index = name.indexOf(' ', startIndex); + if (index == -1) { + result.append(getWordSubstitution(name.mid(startIndex))); + } else { + result.append(getWordSubstitution(name.mid(startIndex, (index - startIndex)))); + result.append(' '); + } + + startIndex = index + 1; + } while (startIndex != 0); + + return result; +} + +QByteArray Moc::getTypeSubstitution(const QByteArray &typeName) const +{ + int index = typeName.indexOf('<'); + if (index != -1) { + QByteArray templateName = typeName.left(index); + + int lastIndex = typeName.lastIndexOf('>'); + if (lastIndex > index) { + QByteArray result = getNameSubstitution(templateName); + + // Parse the interior type independently + QByteArray parameter = typeName.mid(index + 1, (lastIndex - index - 1)); + QByteArray interior = getTypeSubstitution(parameter); + if (interior.endsWith('>')) { + interior.append(' '); + } + result.append('<').append(interior).append(typeName.mid(lastIndex)); + return result; + } else { + // Something is broken; return the input unmodified + return typeName; + } + } + + return getNameSubstitution(typeName); +} QT_END_NAMESPACE diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h index aedb97b234..9e9225da0a 100644 --- a/src/tools/moc/moc.h +++ b/src/tools/moc/moc.h @@ -43,6 +43,7 @@ #define MOC_H #include "parser.h" +#include "preprocessor.h" #include #include #include @@ -197,12 +198,14 @@ struct NamespaceDef { class Moc : public Parser { public: - Moc() - : noInclude(false), generatedCode(false), mustIncludeQMetaTypeH(false), mustIncludeQPluginH(false) + Moc(Preprocessor &p) + : preprocessor(p), noInclude(false), generatedCode(false), + mustIncludeQMetaTypeH(false), mustIncludeQPluginH(false) {} QByteArray filename; + Preprocessor &preprocessor; bool noInclude; bool generatedCode; bool mustIncludeQMetaTypeH; @@ -260,6 +263,12 @@ public: void checkSuperClasses(ClassDef *def); void checkProperties(ClassDef* cdef); + + QByteArray getSubstitution(const QByteArray &token) const; + QByteArray getTokenSubstitution(const QByteArray &token) const; + QByteArray getWordSubstitution(const QByteArray &word) const; + QByteArray getNameSubstitution(const QByteArray &name) const; + QByteArray getTypeSubstitution(const QByteArray &typeName) const; }; inline QByteArray noRef(const QByteArray &type) -- cgit v1.2.3 From 012f799254eedc610e2e33842e62d2a184b14fcc Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 28 Feb 2012 20:57:38 +0100 Subject: revamp -sysroot and -hostprefix handling instead of being a variable added to the makespec (via qconfig.pri), QT_SYSROOT is now a property. the QT_INSTALL_... properties are now automatically prefixed with the sysroot; the raw values are available as QT_RAW_INSTALL_... - this is expected to cause the least migration effort for existing projects. -hostprefix and the new -hostbindir & -hostdatadir now feed the new QT_HOST_... properties. adapted the qmake feature files and the qtbase build system accordingly. Change-Id: Iaa9b65bc10d9fe9c4988d620c70a8ce72177f8d4 Reviewed-by: Marius Storm-Olsen --- src/tools/moc/moc.pro | 2 +- src/tools/rcc/rcc.pro | 2 +- src/tools/uic/uic.pro | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/tools') diff --git a/src/tools/moc/moc.pro b/src/tools/moc/moc.pro index 3ee507855c..5c96c96a4c 100644 --- a/src/tools/moc/moc.pro +++ b/src/tools/moc/moc.pro @@ -13,6 +13,6 @@ HEADERS += qdatetime_p.h SOURCES += main.cpp include(../bootstrap/bootstrap.pri) -target.path=$$[QT_INSTALL_BINS] +target.path = $$[QT_HOST_BINS] INSTALLS += target load(qt_targets) diff --git a/src/tools/rcc/rcc.pro b/src/tools/rcc/rcc.pro index 6c78642406..e87ef605b9 100644 --- a/src/tools/rcc/rcc.pro +++ b/src/tools/rcc/rcc.pro @@ -11,6 +11,6 @@ HEADERS += ../../corelib/kernel/qcorecmdlineargs_p.h SOURCES += main.cpp include(../bootstrap/bootstrap.pri) -target.path=$$[QT_INSTALL_BINS] +target.path = $$[QT_HOST_BINS] INSTALLS += target load(qt_targets) diff --git a/src/tools/uic/uic.pro b/src/tools/uic/uic.pro index 7a95db861f..0acc6e77c8 100644 --- a/src/tools/uic/uic.pro +++ b/src/tools/uic/uic.pro @@ -22,6 +22,6 @@ linux-g++-maemo { include(../bootstrap/bootstrap.pri) -target.path=$$[QT_INSTALL_BINS] +target.path = $$[QT_HOST_BINS] INSTALLS += target load(qt_targets) -- cgit v1.2.3