summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-09-01 14:40:15 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2010-09-01 16:38:59 -0300
commit7d38f877d69fe44dbe7c36fb15cd477acccb4500 (patch)
tree6a5972b53afc68327047785937a3ed53cf67b79d
parent2a5ad3e48e5a148bc87bd6dbb74c695dd352a79a (diff)
downloadshiboken-7d38f877d69fe44dbe7c36fb15cd477acccb4500.tar.gz
shiboken-7d38f877d69fe44dbe7c36fb15cd477acccb4500.tar.xz
shiboken-7d38f877d69fe44dbe7c36fb15cd477acccb4500.zip
Fix bug#316 - "QAbstractItemModel.createIndex is broken"
Use SbkNumber_Check instead of PyNumber_Check, because PyNumber_Check returns true for all user types. This commit also disable the generation of _Check macros and replaces all entries with Converter<T>::checkType. Those changes are on the same commit because SbkNumber_Check conflicts with a macro generated by "other" binding which binds a type named "Number". Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Renato Ara├║jo <renato.filho@openbossa.org>
-rw-r--r--headergenerator.cpp18
-rw-r--r--headergenerator.h1
-rw-r--r--libshiboken/conversions.h8
-rw-r--r--shibokengenerator.cpp29
-rw-r--r--shibokengenerator.h2
5 files changed, 22 insertions, 36 deletions
diff --git a/headergenerator.cpp b/headergenerator.cpp
index 0d7524cb..59028081 100644
--- a/headergenerator.cpp
+++ b/headergenerator.cpp
@@ -199,14 +199,6 @@ void HeaderGenerator::writeFunction(QTextStream& s, const AbstractMetaFunction*
}
}
-void HeaderGenerator::writeTypeCheckMacro(QTextStream& s, const TypeEntry* type)
-{
- QString pyTypeName = cppApiVariableName() + '[' + getTypeIndexVariableName(type) + ']';
- QString checkFunction = cpythonCheckFunction(type);
- s << "#define " << checkFunction << "(op) PyObject_TypeCheck(op, (PyTypeObject*)";
- s << pyTypeName << ')' << endl;
-}
-
void HeaderGenerator::writeTypeConverterDecl(QTextStream& s, const TypeEntry* type)
{
s << "template<>" << endl;
@@ -328,10 +320,6 @@ void HeaderGenerator::finishGeneration()
macrosStream << "// Macros for type check" << endl;
foreach (const AbstractMetaEnum* cppEnum, globalEnums()) {
includes << cppEnum->typeEntry()->include();
- writeTypeCheckMacro(macrosStream, cppEnum->typeEntry());
- FlagsTypeEntry* flags = cppEnum->typeEntry()->flags();
- if (flags)
- writeTypeCheckMacro(macrosStream, flags);
writeTypeConverterDecl(convDecl, cppEnum->typeEntry());
convDecl << endl;
writeSbkTypeFunction(typeFunctions, cppEnum);
@@ -348,13 +336,10 @@ void HeaderGenerator::finishGeneration()
foreach (const AbstractMetaEnum* cppEnum, metaClass->enums()) {
EnumTypeEntry* enumType = cppEnum->typeEntry();
includes << enumType->include();
- writeTypeCheckMacro(macrosStream, enumType);
writeTypeConverterDecl(convDecl, enumType);
FlagsTypeEntry* flagsEntry = enumType->flags();
- if (flagsEntry) {
- writeTypeCheckMacro(macrosStream, flagsEntry);
+ if (flagsEntry)
writeTypeConverterDecl(convDecl, flagsEntry);
- }
convDecl << endl;
writeSbkTypeFunction(typeFunctions, cppEnum);
}
@@ -362,7 +347,6 @@ void HeaderGenerator::finishGeneration()
if (!metaClass->isNamespace()) {
writeSbkTypeFunction(typeFunctions, metaClass);
writeSbkCopyCppObjectFunction(convDecl, metaClass);
- writeTypeCheckMacro(macrosStream, classType);
writeTypeConverterDecl(convDecl, classType);
writeTypeConverterImpl(convImpl, classType);
convDecl << endl;
diff --git a/headergenerator.h b/headergenerator.h
index 22dced48..c1f56b00 100644
--- a/headergenerator.h
+++ b/headergenerator.h
@@ -42,7 +42,6 @@ private:
void writeFunction(QTextStream& s, const AbstractMetaFunction* func) const;
void writePureVirtualEmptyImpl(QTextStream& , const AbstractMetaFunction* func) const;
void writeDefaultImplementation(QTextStream& s, const AbstractMetaFunction* func) const;
- void writeTypeCheckMacro(QTextStream& s, const TypeEntry* type);
void writeTypeConverterDecl(QTextStream& s, const TypeEntry* type);
void writeSbkTypeFunction(QTextStream& s, const AbstractMetaEnum* cppEnum);
void writeSbkTypeFunction(QTextStream& s, const AbstractMetaClass* cppClass);
diff --git a/libshiboken/conversions.h b/libshiboken/conversions.h
index 8caa56c8..1806d63a 100644
--- a/libshiboken/conversions.h
+++ b/libshiboken/conversions.h
@@ -50,6 +50,8 @@
#define PyObject_Check(X) true
#include "autodecref.h"
+#define SbkNumber_Check(X) (PyInt_Check(X) || PyFloat_Check(X) || PyLong_Check(X))
+
namespace Shiboken
{
/**
@@ -380,7 +382,7 @@ template <typename PyIntEquiv>
struct Converter_PyInt
{
static inline bool checkType(PyObject* pyobj) { return PyInt_Check(pyobj); }
- static inline bool isConvertible(PyObject* pyobj) { return PyNumber_Check(pyobj); }
+ static inline bool isConvertible(PyObject* pyobj) { return SbkNumber_Check(pyobj); }
static inline PyObject* toPython(void* cppobj) { return toPython(*reinterpret_cast<PyIntEquiv*>(cppobj)); }
static inline PyObject* toPython(const PyIntEquiv& cppobj) { return PyInt_FromLong((long) cppobj); }
static PyIntEquiv toCpp(PyObject* pyobj)
@@ -409,7 +411,7 @@ struct Converter_PyULongInt : Converter_PyInt<T>
/// Check if we can treat the pyobj as a char, i.e. it's a number or a string with just one character.
-#define SbkChar_Check(pyobj) (PyNumber_Check(pyobj) || (PyString_Check(pyobj) && PyString_Size(pyobj) == 1))
+#define SbkChar_Check(pyobj) (SbkNumber_Check(pyobj) || (PyString_Check(pyobj) && PyString_Size(pyobj) == 1))
/// Specialization to convert char and unsigned char, it accepts Python numbers and strings with just one character.
template <typename CharType>
@@ -478,7 +480,7 @@ template <typename PyFloatEquiv>
struct Converter_PyFloat
{
static inline bool checkType(PyObject* obj) { return PyFloat_Check(obj); }
- static inline bool isConvertible(PyObject* obj) { return PyNumber_Check(obj); }
+ static inline bool isConvertible(PyObject* obj) { return SbkNumber_Check(obj); }
static inline PyObject* toPython(void* cppobj) { return toPython(*reinterpret_cast<PyFloatEquiv*>(cppobj)); }
static inline PyObject* toPython(PyFloatEquiv cppobj) { return PyFloat_FromDouble((double) cppobj); }
static inline PyFloatEquiv toCpp(PyObject* pyobj)
diff --git a/shibokengenerator.cpp b/shibokengenerator.cpp
index 0f862f52..b6edd6a3 100644
--- a/shibokengenerator.cpp
+++ b/shibokengenerator.cpp
@@ -779,21 +779,13 @@ bool ShibokenGenerator::visibilityModifiedToPrivate(const AbstractMetaFunction*
return false;
}
-static QString checkFunctionName(QString baseName, bool genericNumberType, bool checkExact)
-{
- // TODO: Remove checkExact argument.
- return QString("%1_Check%2")
- .arg((genericNumberType && ShibokenGenerator::isNumber(baseName) ? "PyNumber" : baseName))
- .arg((checkExact && !genericNumberType ? "Exact" : ""));
-}
-
QString ShibokenGenerator::cpythonCheckFunction(const AbstractMetaType* metaType, bool genericNumberType)
{
QString baseName = cpythonBaseName(metaType);
if (metaType->typeEntry()->isCustom()) {
return guessCPythonCheckFunction(metaType->typeEntry()->name());
} else if (isNumber(baseName)) {
- return genericNumberType ? "PyNumber_Check" : baseName+"_Check";
+ return genericNumberType ? "SbkNumber_Check" : baseName+"_Check";
} else {
QString str;
QTextStream s(&str);
@@ -803,11 +795,20 @@ QString ShibokenGenerator::cpythonCheckFunction(const AbstractMetaType* metaType
}
}
-QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry* type, bool genericNumberType, bool checkExact)
+QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry* type, bool genericNumberType)
{
- if (type->isCustom())
+ QString baseName = cpythonBaseName(type);
+ if (type->isCustom()) {
return guessCPythonCheckFunction(type->name());
- return checkFunctionName(cpythonBaseName(type), genericNumberType, checkExact);
+ } else if (isNumber(baseName)) {
+ return genericNumberType ? "SbkNumber_Check" : baseName+"_Check";
+ } else {
+ QString str;
+ QTextStream s(&str);
+ writeBaseConversion(s, type);
+ s.flush();
+ return str + "checkType";
+ }
}
QString ShibokenGenerator::guessCPythonCheckFunction(const QString& type)
@@ -846,7 +847,7 @@ QString ShibokenGenerator::guessCPythonIsConvertible(const QString& type)
QString ShibokenGenerator::cpythonIsConvertibleFunction(const TypeEntry* type, bool genericNumberType, bool checkExact)
{
if (checkExact)
- return cpythonCheckFunction(type, genericNumberType, checkExact);
+ return cpythonCheckFunction(type, genericNumberType);
if (type->isCustom())
return guessCPythonIsConvertible(type->name());
QString baseName;
@@ -864,7 +865,7 @@ QString ShibokenGenerator::cpythonIsConvertibleFunction(const AbstractMetaType*
if (metaType->typeEntry()->isCustom()) {
return guessCPythonCheckFunction(metaType->typeEntry()->name());
} else if (isNumber(baseName)) {
- return genericNumberType ? "PyNumber_Check" : baseName+"_Check";
+ return genericNumberType ? "SbkNumber_Check" : baseName+"_Check";
} else {
QString str;
QTextStream s(&str);
diff --git a/shibokengenerator.h b/shibokengenerator.h
index 8ab6d7c5..37f484a9 100644
--- a/shibokengenerator.h
+++ b/shibokengenerator.h
@@ -243,7 +243,7 @@ public:
QString cpythonTypeName(const AbstractMetaClass* metaClass);
QString cpythonTypeName(const TypeEntry* type);
QString cpythonTypeNameExt(const TypeEntry* type);
- QString cpythonCheckFunction(const TypeEntry* type, bool genericNumberType = false, bool checkExact = false);
+ QString cpythonCheckFunction(const TypeEntry* type, bool genericNumberType = false);
QString cpythonCheckFunction(const AbstractMetaType* metaType, bool genericNumberType = false);
QString guessCPythonCheckFunction(const QString& type);
QString cpythonIsConvertibleFunction(const TypeEntry* type, bool genericNumberType = false, bool checkExact = false);