aboutsummaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-12-28 15:24:11 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:12:51 -0300
commit2f5d90404ace8e5bf00b7976d18624e71ebebe2b (patch)
tree1cf942f6bc77e0b7315c9c9b9b29f2a29cb79124 /generator
parent334024a4797350f75d34ba1842ea702e702080cb (diff)
Fix bug#495 - "Broken rich compare operators if they use an object-type as parameter"
Diffstat (limited to 'generator')
-rw-r--r--generator/cppgenerator.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index 2b46f6909..de1c93009 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -531,6 +531,8 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
const TypeEntry* type = func->type() ? func->type()->typeEntry() : 0;
+ const QString funcName = func->isOperatorOverload() ? pythonOperatorFunctionName(func) : func->name();
+
QString prefix = wrapperName(func->ownerClass()) + "::";
s << functionSignature(func, prefix, "", Generator::SkipDefaultValues|Generator::OriginalTypeDescription) << endl;
s << "{" << endl;
@@ -582,7 +584,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
s << INDENT << "Shiboken::GilState gil;" << endl;
s << INDENT << "Shiboken::AutoDecRef py_override(Shiboken::BindingManager::instance().getOverride(this, \"";
- s << func->name() << "\"));" << endl;
+ s << funcName << "\"));" << endl;
s << INDENT << "if (py_override.isNull()) {" << endl;
{
@@ -597,7 +599,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
if (func->isAbstract()) {
s << INDENT << "PyErr_SetString(PyExc_NotImplementedError, \"pure virtual method '";
- s << func->ownerClass()->name() << '.' << func->name();
+ s << func->ownerClass()->name() << '.' << funcName;
s << "()' not implemented.\");" << endl;
s << INDENT << "return ";
if (func->type()) {
@@ -751,7 +753,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
{
Indentation indent(INDENT);
s << INDENT << "PyErr_Format(PyExc_TypeError, \"Invalid return value in function %s, expected %s, got %s.\", \""
- << func->ownerClass()->name() << '.' << func->name() << "\", " << desiredType
+ << func->ownerClass()->name() << '.' << funcName << "\", " << desiredType
<< ", " PYTHON_RETURN_VAR "->ob_type->tp_name);" << endl;
s << INDENT << "return " << defaultReturnExpr << ';' << endl;
}
@@ -2840,14 +2842,22 @@ void CppGenerator::writeRichCompareFunction(QTextStream& s, const AbstractMetaCl
Indentation indent(INDENT);
s << INDENT << "// " << func->signature() << endl;
s << INDENT;
- s << translateTypeForWrapperMethod(type, metaClass, ExcludeReference | ExcludeConst);
+ s << translateTypeForWrapperMethod(type, 0, ExcludeReference | ExcludeConst);
+ if (type->isObject() || type->isQObject())
+ s << '&';
s << " cppOther = ";
- writeToCppConversion(s, type, metaClass, "other", ExcludeReference | ExcludeConst);
+ writeToCppConversion(s, type, 0, "other", ExcludeReference | ExcludeConst);
s << ';' << endl;
s << INDENT << "result = ";
- writeToPythonConversion(s, func->type(), metaClass, CPP_SELF_VAR " " + op + " cppOther");
- s << ';' << endl;
+ if (!func->type()) {
+ s << "Py_None;" << endl;
+ s << INDENT << "Py_INCREF(Py_None);" << endl;
+ s << INDENT << CPP_SELF_VAR " " << op << " cppOther; // this op return void" << endl;
+ } else {
+ writeToPythonConversion(s, func->type(), metaClass, CPP_SELF_VAR " " + op + " cppOther");
+ s << ';' << endl;
+ }
}
s << INDENT << '}';
}