summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-12-13 18:36:53 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2010-12-13 19:03:22 -0200
commit66bb59f9be9f7f38af48b1c4dc1108017c06ef72 (patch)
tree80fd1f69416ba3aa7891475791056f67dc62e1e6 /generator
parent701b31ef3ddae7c43380d1513f9938f70f46eb7e (diff)
downloadshiboken-66bb59f9be9f7f38af48b1c4dc1108017c06ef72.tar.gz
shiboken-66bb59f9be9f7f38af48b1c4dc1108017c06ef72.tar.xz
shiboken-66bb59f9be9f7f38af48b1c4dc1108017c06ef72.zip
Fix bug#513 - "Hardcoded bool return type for operator overloads"
Reviewer: Renato Ara├║jo <renato.filho@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'generator')
-rw-r--r--generator/cppgenerator.cpp34
1 files changed, 10 insertions, 24 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index 0c99b09c..55747d37 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -29,7 +29,7 @@
#include <QtCore/QTextStream>
#include <QtCore/QDebug>
-// utiliy functions
+// utility functions
inline CodeSnipList getConversionRule(TypeSystem::Language lang, const AbstractMetaFunction *function)
{
CodeSnipList list;
@@ -2731,7 +2731,7 @@ void CppGenerator::writeRichCompareFunction(QTextStream& s, const AbstractMetaCl
s << baseName << "_richcompare(PyObject* self, PyObject* other, int op)" << endl;
s << '{' << endl;
QList<AbstractMetaFunctionList> cmpOverloads = filterGroupedOperatorFunctions(metaClass, AbstractMetaClass::ComparisonOp);
- s << INDENT << "bool result = false;" << endl;
+ s << INDENT << "PyObject* result = 0;" << endl;
s << INDENT << metaClass->qualifiedCppName() << "& " CPP_SELF_VAR " = *" << cpythonWrapperCPtr(metaClass) << ';' << endl;
s << endl;
@@ -2784,24 +2784,10 @@ void CppGenerator::writeRichCompareFunction(QTextStream& s, const AbstractMetaCl
s << " cppOther = ";
writeToCppConversion(s, type, metaClass, "other", ExcludeReference | ExcludeConst);
s << ';' << endl;
- s << INDENT << "result = (" CPP_SELF_VAR " " << op << " cppOther);" << endl;
- }
- s << INDENT << '}';
- }
- // Compares with implicit conversions
- if (comparesWithSameType && !metaClass->implicitConversions().isEmpty()) {
- AbstractMetaType temporaryType;
- temporaryType.setTypeEntry(metaClass->typeEntry());
- temporaryType.setConstant(false);
- temporaryType.setReference(false);
- temporaryType.setTypeUsagePattern(AbstractMetaType::ValuePattern);
- s << " else if (" << cpythonIsConvertibleFunction(metaClass->typeEntry());
- s << "(other)) {" << endl;
- {
- Indentation indent(INDENT);
- writeArgumentConversion(s, &temporaryType, "cppOther", "other", metaClass);
- s << INDENT << "result = (" CPP_SELF_VAR " " << op << " cppOther);" << endl;
+ s << INDENT << "result = ";
+ writeToPythonConversion(s, func->type(), metaClass, CPP_SELF_VAR " " + op + " cppOther");
+ s << ';' << endl;
}
s << INDENT << '}';
}
@@ -2814,19 +2800,19 @@ void CppGenerator::writeRichCompareFunction(QTextStream& s, const AbstractMetaCl
s << INDENT << "default:" << endl;
{
Indentation indent(INDENT);
- s << INDENT << "PyErr_SetString(PyExc_NotImplementedError, \"operator not implemented.\");" << endl;
- s << INDENT << "return " << m_currentErrorCode << ';' << endl;
+ s << INDENT << "goto " << baseName << "_RichComparison_TypeError;" << endl;
}
}
s << INDENT << '}' << endl << endl;
- s << INDENT << "if (result)" << endl;
+ s << INDENT << "if (result && !PyErr_Occurred())" << endl;
{
Indentation indent(INDENT);
- s << INDENT << "Py_RETURN_TRUE;" << endl;
+ s << INDENT << "return result;" << endl;
}
s << INDENT << baseName << "_RichComparison_TypeError:" << endl;
- s << INDENT << "Py_RETURN_FALSE;" << endl << endl;
+ s << INDENT << "PyErr_SetString(PyExc_NotImplementedError, \"operator not implemented.\");" << endl;
+ s << INDENT << "return " << m_currentErrorCode << ';' << endl << endl;
s << '}' << endl << endl;
}