summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-01-11 10:56:26 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-01-11 14:55:29 +0000
commit0dd022957ddf3a2c92b796895d7bfec6387b9ca3 (patch)
tree9c06b065bb07275abc101f46dd6ecf9d4ede7d6d
parentb33f8708fd1d9aee7e4409a91b96fe96d3730764 (diff)
shiboken: Replace C-style NULL by nullptr
Replace in comments, code and generated code. Rename variable NULL_VALUE to NULL_PTR and make extern for follow-up changes. Rewrite code using NULL in QString::arg() (resulting apparently from some misunderstanding that it requires a terminating nullptr) to use printf-formatting to fix a warning: format not a string literal and no format arguments [-Wformat-security]). Change-Id: I97c111cadc09192132308924136eb6ede7a6bf44 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp2
-rw-r--r--sources/shiboken2/generator/generator.h4
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp25
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.cpp4
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.h12
5 files changed, 25 insertions, 22 deletions
diff --git a/sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp b/sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp
index 9f71b495..c438e0c3 100644
--- a/sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp
+++ b/sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp
@@ -59,7 +59,7 @@ void TestCodeInjections::testReadFile()
const char* cppCode ="struct A {};\n";
int argc = 0;
- char *argv[] = {NULL};
+ char *argv[] = {nullptr};
QCoreApplication app(argc, argv);
QString attribute = QLatin1String("file='") + filePath + QLatin1Char('\'');
diff --git a/sources/shiboken2/generator/generator.h b/sources/shiboken2/generator/generator.h
index 225e7aec..cdf6d89b 100644
--- a/sources/shiboken2/generator/generator.h
+++ b/sources/shiboken2/generator/generator.h
@@ -288,10 +288,10 @@ protected:
/// Returns all container types found by APIExtractor
ContainerTypeEntryList containerTypes() const;
- /// Returns an AbstractMetaEnum for a given TypeEntry that is an EnumTypeEntry, or NULL if not found.
+ /// Returns an AbstractMetaEnum for a given TypeEntry that is an EnumTypeEntry, or nullptr if not found.
const AbstractMetaEnum* findAbstractMetaEnum(const TypeEntry* typeEntry) const;
- /// Returns an AbstractMetaEnum for a given AbstractMetaType that holds an EnumTypeEntry, or NULL if not found.
+ /// Returns an AbstractMetaEnum for a given AbstractMetaType that holds an EnumTypeEntry, or nullptr if not found.
const AbstractMetaEnum* findAbstractMetaEnum(const AbstractMetaType* metaType) const;
/// Generates a file for given AbstractMetaClass or AbstractMetaType (smart pointer case).
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index a62a0ac2..8b9152fd 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -962,7 +962,8 @@ void CppGenerator::writeVirtualMethodNative(QTextStream&s, const AbstractMetaFun
if (!injectedCodeCallsPythonOverride(func)) {
s << INDENT;
- s << "Shiboken::AutoDecRef " << PYTHON_RETURN_VAR << "(PyObject_Call(" << PYTHON_OVERRIDE_VAR << ", " << PYTHON_ARGS << ", NULL));" << endl;
+ s << "Shiboken::AutoDecRef " << PYTHON_RETURN_VAR << "(PyObject_Call("
+ << PYTHON_OVERRIDE_VAR << ", " << PYTHON_ARGS << ", nullptr));" << endl;
s << INDENT << "// An error happened in python code!" << endl;
s << INDENT << "if (" << PYTHON_RETURN_VAR << ".isNull()) {" << endl;
@@ -1090,7 +1091,7 @@ void CppGenerator::writeMetaObjectMethod(QTextStream& s, const AbstractMetaClass
s << INDENT << "if (QObject::d_ptr->metaObject)" << endl
<< INDENT << INDENT << "return QObject::d_ptr->dynamicMetaObject();" << endl;
s << INDENT << "SbkObject* pySelf = Shiboken::BindingManager::instance().retrieveWrapper(this);" << endl;
- s << INDENT << "if (pySelf == NULL)" << endl;
+ s << INDENT << "if (pySelf == nullptr)" << endl;
s << INDENT << INDENT << "return " << metaClass->qualifiedCppName() << "::metaObject();" << endl;
s << INDENT << "return PySide::SignalManager::retrieveMetaObject(reinterpret_cast<PyObject*>(pySelf));" << endl;
s << '}' << endl << endl;
@@ -1099,7 +1100,7 @@ void CppGenerator::writeMetaObjectMethod(QTextStream& s, const AbstractMetaClass
s << "int " << wrapperClassName << "::qt_metacall(QMetaObject::Call call, int id, void** args)" << endl;
s << "{" << endl;
- AbstractMetaFunction *func = NULL;
+ AbstractMetaFunction *func = nullptr;
AbstractMetaFunctionList list = metaClass->queryFunctionsByName(QLatin1String("qt_metacall"));
if (list.size() == 1)
func = list[0];
@@ -2682,7 +2683,7 @@ void CppGenerator::writeSingleFunctionCall(QTextStream &s,
// When an argument is removed from a method signature and no other means of calling
// the method are provided (as with code injection) the generator must abort.
qFatal(qPrintable(QString::fromLatin1("No way to call '%1::%2' with the modifications described in the type system.")
- .arg(func->ownerClass()->name(), func->signature())), NULL);
+ .arg(func->ownerClass()->name(), func->signature())));
}
removedArgs++;
continue;
@@ -2779,9 +2780,9 @@ void CppGenerator::writeCppToPythonFunction(QTextStream& s, const AbstractMetaTy
{
const CustomConversion* customConversion = containerType->typeEntry()->customConversion();
if (!customConversion) {
- qFatal(qPrintable(QString::fromLatin1("Can't write the C++ to Python conversion function for container type '%1' - "\
- "no conversion rule was defined for it in the type system.")
- .arg(containerType->typeEntry()->qualifiedCppName())), NULL);
+ qFatal("Can't write the C++ to Python conversion function for container type '%s' - "\
+ "no conversion rule was defined for it in the type system.",
+ qPrintable(containerType->typeEntry()->qualifiedCppName()));
}
if (!containerType->typeEntry()->isContainer()) {
writeCppToPythonFunction(s, customConversion);
@@ -2906,9 +2907,9 @@ void CppGenerator::writePythonToCppConversionFunctions(QTextStream& s,
}
if (typeCheck.isEmpty()) {
if (!toNative->sourceType() || toNative->sourceType()->isPrimitive()) {
- qFatal(qPrintable(QString::fromLatin1("User added implicit conversion for C++ type '%1' must provide either an input "\
- "type check function or a non primitive type entry.")
- .arg(targetType->qualifiedCppName())), NULL);
+ qFatal("User added implicit conversion for C++ type '%s' must provide either an input "\
+ "type check function or a non primitive type entry.",
+ qPrintable(targetType->qualifiedCppName()));
}
typeCheck = QString::fromLatin1("PyObject_TypeCheck(%in, %1)").arg(cpythonTypeNameExt(toNative->sourceType()));
@@ -5259,7 +5260,7 @@ void CppGenerator::writeGetattroFunction(QTextStream& s, GeneratorContext &conte
s << INDENT << "} else {" << endl;
{
Indentation indent(INDENT);
- s << INDENT << "if (!PyErr_ExceptionMatches(PyExc_AttributeError)) return NULL;" << endl;
+ s << INDENT << "if (!PyErr_ExceptionMatches(PyExc_AttributeError)) return nullptr;" << endl;
s << INDENT << "PyErr_Clear();" << endl;
s << INDENT << "// Try to find the 'name' attribute, by retrieving the PyObject for "
@@ -5286,7 +5287,7 @@ void CppGenerator::writeGetattroFunction(QTextStream& s, GeneratorContext &conte
s << INDENT << "PyErr_Format(PyExc_AttributeError," << endl;
s << INDENT << " \"'%.50s' object has no attribute '%.400s'\"," << endl;
s << INDENT << " tp->tp_name, PyBytes_AS_STRING(name));" << endl;
- s << INDENT << "return NULL;" << endl;
+ s << INDENT << "return nullptr;" << endl;
}
s << INDENT << "} else {" << endl;
{
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
index b9eea752..041c042a 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
@@ -41,7 +41,6 @@
#include <limits>
#include <memory>
-static const char NULL_VALUE[] = "NULL";
static const char AVOID_PROTECTED_HACK[] = "avoid-protected-hack";
static const char PARENT_CTOR_HEURISTIC[] = "enable-parent-ctor-heuristic";
static const char RETURN_VALUE_HEURISTIC[] = "enable-return-value-heuristic";
@@ -53,6 +52,7 @@ const char *CPP_ARG = "cppArg";
const char *CPP_ARG_REMOVED = "removed_cppArg";
const char *CPP_RETURN_VAR = "cppResult";
const char *CPP_SELF_VAR = "cppSelf";
+const char *NULL_PTR = "nullptr";
const char *PYTHON_ARG = "pyArg";
const char *PYTHON_ARGS = "pyArgs";
const char *PYTHON_OVERRIDE_VAR = "pyOverride";
@@ -1396,7 +1396,7 @@ QString ShibokenGenerator::argumentString(const AbstractMetaFunction *func,
{
QString default_value = argument->originalDefaultValueExpression();
if (default_value == QLatin1String("NULL"))
- default_value = QLatin1String(NULL_VALUE);
+ default_value = QLatin1String(NULL_PTR);
//WORKAROUND: fix this please
if (default_value.startsWith(QLatin1String("new ")))
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.h b/sources/shiboken2/generator/shiboken2/shibokengenerator.h
index 60e31a99..d2c4b329 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.h
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.h
@@ -33,6 +33,7 @@ extern const char *CPP_ARG;
extern const char *CPP_ARG_REMOVED;
extern const char *CPP_RETURN_VAR;
extern const char *CPP_SELF_VAR;
+extern const char *NULL_PTR;
extern const char *PYTHON_ARG;
extern const char *PYTHON_ARGS;
extern const char *PYTHON_OVERRIDE_VAR;
@@ -200,7 +201,7 @@ protected:
void writeToCppConversion(QTextStream& s, const AbstractMetaType* type, const AbstractMetaClass* context, const QString& inArgName, const QString& outArgName);
void writeToCppConversion(QTextStream& s, const AbstractMetaClass* metaClass, const QString& inArgName, const QString& outArgName);
- /// Returns true if the argument is a pointer that rejects NULL values.
+ /// Returns true if the argument is a pointer that rejects nullptr values.
bool shouldRejectNullPointerArgument(const AbstractMetaFunction* func, int argIndex);
/// Verifies if the class should have a C++ wrapper generated for it, instead of only a Python wrapper.
@@ -208,7 +209,7 @@ protected:
/// Adds enums eligible for generation from classes/namespaces marked not to be generated.
static void lookForEnumsInClassesNotToBeGenerated(AbstractMetaEnumList& enumList, const AbstractMetaClass* metaClass);
- /// Returns the enclosing class for an enum, or NULL if it should be global.
+ /// Returns the enclosing class for an enum, or nullptr if it should be global.
const AbstractMetaClass* getProperEnclosingClassForEnum(const AbstractMetaEnum* metaEnum);
QString wrapperName(const AbstractMetaClass* metaClass) const;
@@ -299,7 +300,7 @@ protected:
* \param type A string representing the type to be discovered.
* \param metaType A pointer to an AbstractMetaType pointer, to where write a new meta type object
* if one is produced from the \p type string. This object must be deallocated by
- * the caller. It will set the target variable to NULL, is \p type is a Python type.
+ * the caller. It will set the target variable to nullptr, is \p type is a Python type.
* \return A custom check if \p type is a custom type, or an empty string if \p metaType
* receives an existing type object.
*/
@@ -377,9 +378,10 @@ protected:
/**
* Builds an AbstractMetaType object from a QString.
- * Returns NULL if no type could be built from the string.
+ * Returns nullptr if no type could be built from the string.
* \param typeSignature The string describing the type to be built.
- * \return A new AbstractMetaType object that must be deleted by the caller, or a NULL pointer in case of failure.
+ * \return A new AbstractMetaType object that must be deleted by the caller,
+ * or a nullptr pointer in case of failure.
*/
AbstractMetaType *buildAbstractMetaTypeFromString(QString typeSignature,
QString *errorMessage = nullptr);