summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Alcantara <pcacjr@gmail.com>2012-01-18 14:21:29 -0300
committerPaulo Alcantara <pcacjr@gmail.com>2012-01-18 18:36:21 -0300
commitf79304bb37a5a5ef4b7e6ca4ecba2d5f07b9361c (patch)
treedb23bd523f31bd9b6ce615bec07691f4e8afd14f
parent7ae059fbb6882174c4da3aeb2017390afffa11fe (diff)
downloadshiboken-f79304bb37a5a5ef4b7e6ca4ecba2d5f07b9361c.tar.gz
shiboken-f79304bb37a5a5ef4b7e6ca4ecba2d5f07b9361c.tar.xz
shiboken-f79304bb37a5a5ef4b7e6ca4ecba2d5f07b9361c.zip
Fix BUG #1113 - "Instantiating QObject in user-defined QML element's
constructor crashes if instantiated from QML" Signed-off-by: Paulo Alcantara <pcacjr@gmail.com> Reviewed-by: Marcelo Lira <marcelo.lira@openbossa.org> Reviewed-by: Hugo Parente Lima <hugo.pl@gmail.com>
-rw-r--r--generator/cppgenerator.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index e0b3148c..fa19f7a3 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -1,7 +1,7 @@
/*
* This file is part of the Shiboken Python Bindings Generator project.
*
- * Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2009-2012 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: PySide team <contact@pyside.org>
*
@@ -16,9 +16,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <memory>
@@ -2786,6 +2784,8 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f
bool isCtor = false;
QString methodCall;
QTextStream mc(&methodCall);
+ QString useVAddr;
+ QTextStream uva(&useVAddr);
if (func->isOperatorOverload() && !func->isCallOperator()) {
QString firstArg("(*" CPP_SELF_VAR ")");
if (func->isPointerOperator())
@@ -2827,12 +2827,28 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f
QString ctorCall = className + '(' + userArgs.join(", ") + ')';
if (usePySideExtensions() && func->ownerClass()->isQObject()) {
s << INDENT << "void* addr = PySide::nextQObjectMemoryAddr();" << endl;
- mc << "addr ? new (addr) ::" << ctorCall << " : new ::" << ctorCall;
+ uva << "if (addr) {" << endl;
+ {
+ Indentation indent(INDENT);
+
+ uva << INDENT << "cptr = " << "new (addr) ::"
+ << ctorCall << ';' << endl
+ << INDENT
+ << "PySide::setNextQObjectMemoryAddr(0);"
+ << endl;
+ }
+ uva << INDENT << "} else {" << endl;
+ {
+ Indentation indent(INDENT);
+
+ uva << INDENT << "cptr = " << "new ::"
+ << ctorCall << ';' << endl;
+ }
+ uva << INDENT << "}" << endl;
} else {
mc << "new ::" << ctorCall;
}
}
-
} else {
if (func->ownerClass()) {
if (!avoidProtectedHack() || !func->isProtected()) {
@@ -2890,7 +2906,8 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f
if (!injectedCodeCallsCppFunction(func)) {
s << INDENT << BEGIN_ALLOW_THREADS << endl << INDENT;
if (isCtor) {
- s << "cptr = ";
+ s << (useVAddr.isEmpty() ?
+ QString("cptr = %1;").arg(methodCall) : useVAddr) << endl;
} else if (func->type() && !func->isInplaceOperator()) {
bool writeReturnType = true;
if (avoidProtectedHack()) {
@@ -2916,8 +2933,10 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f
}
}
s << " " CPP_RETURN_VAR " = ";
+ s << methodCall << ';' << endl;
+ } else {
+ s << methodCall << ';' << endl;
}
- s << methodCall << ';' << endl;
s << INDENT << END_ALLOW_THREADS << endl;
if (!func->conversionRule(TypeSystem::TargetLangCode, 0).isEmpty()) {