aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cppgenerator.cpp38
-rw-r--r--hppgenerator.cpp34
2 files changed, 45 insertions, 27 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index a930bffee..1349ed323 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -243,19 +243,29 @@ QString CppGenerator::writeFunctionCast(QTextStream &s,
QString CppGenerator::verifyDefaultReturnPolicy(const AbstractMetaFunction *cppFunction, const QString& callPolicy)
{
+ //If return type replaced, the return policy need be set manually.
+ if (!cppFunction->typeReplaced(0).isEmpty())
+ return QString();
+
AbstractMetaType *type = cppFunction->type();
QString returnPolicy;
- if (type && type->isReference() && type->isConstant()) {
- returnPolicy = "python::return_value_policy<python::copy_const_reference";
+ if (type && type->isConstant()) {
+ returnPolicy = "python::return_value_policy<";
+
+ if (type->isQObject() || type->isObject() || type->isNativePointer()) {
+ returnPolicy += "PySide::return_const_ptr_object";
+ } else if (type->isReference()) {
+ returnPolicy += "python::copy_const_reference";
+ } else {
+ returnPolicy += "python::return_by_value";
+ }
if (!callPolicy.isEmpty())
returnPolicy += ", " + callPolicy;
returnPolicy += " >()";
} else if (type && (type->isReference() || type->isQObject() || type->isObject())) {
- bool cppOwnership = type->isConstant();
- if (cppFunction->isStatic() || cppOwnership) {
- returnPolicy = "python::return_value_policy<PySide::return_ptr_object< "
- + (cppOwnership ? QString("true") : QString("false")) + "> >()";
+ if (cppFunction->isStatic()) {
+ returnPolicy = "python::return_value_policy<PySide::return_ptr_object<false> >()";
} else if (type->isQObject() || type->isObject()) {
returnPolicy = QString("PySide::return_object<1, 0, %1, %2 %3 %4 >()")
.arg(getArgumentType(cppFunction->ownerClass(), cppFunction, -1))
@@ -624,11 +634,13 @@ void CppGenerator::writeModifiedConstructorImpl ( QTextStream& s, const Abstract
void CppGenerator::writeConstructorImpl(QTextStream& s, const AbstractMetaFunction* func)
{
- s << functionSignature(func, getWrapperName(func->ownerClass()) + "::", "",
- (Option)(OriginalTypeDescription | SkipDefaultValues));
- s << " : ";
+ QString wrapperName = getWrapperName(func->ownerClass());
+ s << wrapperName << "::" << wrapperName << "(PyObject *py_self" << (func->arguments().size() ? ", " : "");
+ writeFunctionArguments(s, func, OriginalTypeDescription | SkipDefaultValues);
+ s << ")" << endl;
+ s << INDENT << " : ";
writeFunctionCall(s, func);
- s << " {" << endl;
+ s << ", wrapper(py_self)" << endl << "{" << endl;
writeCodeSnips(s, getCodeSnips(func), CodeSnip::Beginning, TypeSystem::All, func);
writeCodeSnips(s, getCodeSnips(func), CodeSnip::End, TypeSystem::All, func);
s << '}' << endl << endl;
@@ -644,7 +656,7 @@ void CppGenerator::writeVirtualMethodImplHead(QTextStream& s, const AbstractMeta
CodeSnip::Beginning, TypeSystem::NativeCode, func);
}
- s << INDENT << "python::object method = PySide::detail::get_override(this, \"" << func->implementingClass()->name();
+ s << INDENT << "python::object method = get_override(\"" << func->implementingClass()->name();
if (func->implementingClass()->typeEntry()->isObject() || func->implementingClass()->typeEntry()->isQObject())
s << '*';
@@ -682,9 +694,7 @@ void CppGenerator::writeVirtualMethodImplHead(QTextStream& s, const AbstractMeta
(func->type()->isObject() || func->type()->isQObject())) {
s << INDENT << "PySide::qptr<" << QString(typeName).replace("*", "") << " > __ptr(__result.ptr());" << endl
- << INDENT << "if (__ptr.is_wrapper()) {" << endl
- << INDENT << INDENT << "python::incref(__result.ptr());" << endl
- << INDENT << "}" << endl
+ << INDENT << "python::incref(__result.ptr());" << endl
<< INDENT << "__ptr.release_ownership();" << endl;
}
diff --git a/hppgenerator.cpp b/hppgenerator.cpp
index 4e7da1120..0fd5cab6a 100644
--- a/hppgenerator.cpp
+++ b/hppgenerator.cpp
@@ -38,8 +38,8 @@ QString HppGenerator::fileNameForClass(const AbstractMetaClass *cppClass) const
void HppGenerator::writeCopyCtor(QTextStream &s, const AbstractMetaClass *cppClass)
{
- s << INDENT << getWrapperName(cppClass) << "(const " << cppClass->qualifiedCppName() << "& self)"
- << " : " << cppClass->qualifiedCppName() << "(self)" << endl
+ s << INDENT << getWrapperName(cppClass) << "(PyObject *py_self, const " << cppClass->qualifiedCppName() << "& self)"
+ << " : " << cppClass->qualifiedCppName() << "(self), wrapper(py_self)" << endl
<< INDENT << "{" << endl
<< INDENT << "}" << endl;
}
@@ -67,11 +67,13 @@ void HppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *cppCla
if (!cppClass->isPolymorphic() || cppClass->hasPrivateDestructor() || cppClass->isNamespace())
s << "namespace " << wrapperName << " {" << endl << endl;
+ bool needWriteBackReference = false;
if (cppClass->isNamespace()) {
s << INDENT << "struct Namespace {};" << endl;
} else {
QString className;
bool create_wrapper = canCreateWrapperFor(cppClass);
+ bool is_wrapper = false;
// detect the held type
QString held_type = cppClass->typeEntry()->heldTypeValue();
if (held_type.isEmpty() && create_wrapper)
@@ -81,16 +83,17 @@ void HppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *cppCla
CodeSnip::Declaration, TypeSystem::NativeCode);
if (cppClass->isPolymorphic() && !cppClass->hasPrivateDestructor()) {
+ /*
if (!held_type.isEmpty()) {
s << "// held type forward decalration" << endl;
s << "template<typename T> class " << held_type << ';' << endl;
}
+ */
// Class
s << "class PYSIDE_LOCAL " << wrapperName;
if (create_wrapper) {
- s << " : public " << cppClass->qualifiedCppName() << ", public boost::python::wrapper<";
- s << cppClass->qualifiedCppName() << '>';
+ s << " : public " << cppClass->qualifiedCppName() << ", public PySide::wrapper";
}
s << endl;
s << "{" << endl;
@@ -101,22 +104,20 @@ void HppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *cppCla
if (cppClass->isPolymorphic() && !cppClass->hasPrivateDestructor()) {
s << endl << "private:" << endl;
-
- if (cppClass->hasPrivateDestructor())
- className = cppClass->qualifiedCppName();
- else
- className = wrapperName;
+ className = wrapperName;
+ is_wrapper = true;
} else {
className = cppClass->qualifiedCppName();
}
// print the huge boost::python::class_ typedef
- s << INDENT << "typedef boost::python::class_< " << className;
+ s << INDENT << "typedef boost::python::class_< " << cppClass->qualifiedCppName();
writeBaseClass(s, cppClass);
if (!held_type.isEmpty())
- s << ", PySide::" << held_type << " < " << className << ", PySide::qptr_base::avoid_cache > ";
+ s << ", PySide::" << held_type << " < " << className << ", qptr_base::no_check_cache | qptr_base::"
+ << ( is_wrapper ? "wrapper_pointer" : "no_wrapper_pointer") << "> ";
if (!isCopyable(cppClass))
s << ", boost::noncopyable";
@@ -143,7 +144,6 @@ void HppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *cppCla
writeCodeSnips(s, cppClass->typeEntry()->codeSnips(),
CodeSnip::End, TypeSystem::ShellDeclaration);
-
}
QString staticKeyword = cppClass->isNamespace() ? QLatin1String("") : QLatin1String("static ");
@@ -159,6 +159,7 @@ void HppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *cppCla
s << "};" << endl << endl;
+
s << "#endif // __" << wrapperName.toUpper() << "__" << endl << endl;
}
@@ -179,7 +180,14 @@ void HppGenerator::writeFunction(QTextStream &s, const AbstractMetaFunction* fun
s << INDENT << "static " << signatureForDefaultVirtualMethod(func, "", "_default", Generator::SkipName) << ';' << endl;
}
- s << INDENT << functionSignature(func, "", "", Generator::OriginalTypeDescription | Generator::SkipName);
+ if (func->isConstructor()) {
+ s << INDENT << getWrapperName(func->ownerClass()) << "(PyObject *py_self" << (func->arguments().size() ? "," : "");
+ writeFunctionArguments(s, func, Generator::OriginalTypeDescription | Generator::SkipName);
+ s << ")";
+ } else {
+ s << INDENT << functionSignature(func, "", "", Generator::OriginalTypeDescription | Generator::SkipName);
+ }
+
if (func->isModifiedRemoved() && func->isAbstract())
writeDefaultImplementation(s, func);
else