aboutsummaryrefslogtreecommitdiffstats
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>2012-03-08 16:12:48 -0300
commit97ea178de9327c8620943dd9101e45d18e6d185e (patch)
tree43751fdcc2681d4577eef63d9e643a959bc70cf5 /generator
parentdb40f3e234f466e595ed618891aa2f50e403cd03 (diff)
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 565718c35..fda0bcf35 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;
@@ -2733,7 +2733,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;
@@ -2786,24 +2786,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 << '}';
}
@@ -2816,19 +2802,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;
}