diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2010-09-06 14:22:11 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2010-09-08 18:27:02 -0300 |
commit | b9b777ec9f1be48d4b1e8f217c5eb7cc60bb773c (patch) | |
tree | 05bcf26705660f824558fdcb14eae110b97327e6 | |
parent | 5d23ed3a8801b7152e2c3a601e3bb64595d79046 (diff) |
Retore thread state in the first line before the C++ call to avoid any other
Python call.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Renato Araújo <renato.filho@openbossa.org>
-rw-r--r-- | cppgenerator.cpp | 72 |
1 files changed, 40 insertions, 32 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp index cf162ede7..507ef7f21 100644 --- a/cppgenerator.cpp +++ b/cppgenerator.cpp @@ -1901,9 +1901,13 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f if (convRules.size()) writeCodeSnips(s, convRules, CodeSnip::Beginning, TypeSystem::TargetLangCode, func); + // Code to restore the threadSaver has been written? + bool threadRestored = false; + if (!func->isUserAdded()) { bool badModifications = false; QStringList userArgs; + if (!func->isCopyConstructor()) { int removedArgs = 0; for (int i = 0; i < maxArgs + removedArgs; i++) { @@ -1979,9 +1983,9 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f // means of calling the method is provided (as with code injection) // the generator must write a compiler error line stating the situation. if (func->injectedCodeSnips(CodeSnip::Any, TypeSystem::TargetLangCode).isEmpty()) { - s << INDENT << "#error No way to call \"" << func->ownerClass()->name(); - s << "::" << func->minimalSignature(); - s << "\" with the modifications described in the type system file" << endl; + qFatal(qPrintable("No way to call \"" + func->ownerClass()->name() + + "::" + func->minimalSignature() + +"\" with the modifications described in the type system file")); } } else if (func->isOperatorOverload()) { QString firstArg("(*" CPP_SELF_VAR ")"); @@ -2044,38 +2048,45 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f } } - if (!badModifications) { - if (!injectedCodeCallsCppFunction(func)) { - s << INDENT; - if (isCtor) { - s << "cptr = "; - } else if (func->type() && !func->isInplaceOperator()) { + if (!injectedCodeCallsCppFunction(func)) { + s << INDENT; + if (isCtor) { + s << "cptr = "; + } else if (func->type() && !func->isInplaceOperator()) { #ifdef AVOID_PROTECTED_HACK - QString enumName; - const AbstractMetaEnum* metaEnum = findAbstractMetaEnum(func->type()); - if (metaEnum) { - if (metaEnum->isProtected()) - enumName = protectedEnumSurrogateName(metaEnum); - else - enumName = func->type()->cppSignature(); - methodCall.prepend(enumName + '('); - methodCall.append(')'); - s << enumName; - } else + QString enumName; + const AbstractMetaEnum* metaEnum = findAbstractMetaEnum(func->type()); + if (metaEnum) { + if (metaEnum->isProtected()) + enumName = protectedEnumSurrogateName(metaEnum); + else + enumName = func->type()->cppSignature(); + methodCall.prepend(enumName + '('); + methodCall.append(')'); + s << enumName; + } else #endif - s << func->type()->cppSignature(); - s << " " CPP_RETURN_VAR " = "; - } - s << methodCall << ';' << endl; - if (!isCtor && !func->isInplaceOperator() && func->type()) { - s << INDENT << PYTHON_RETURN_VAR " = "; - writeToPythonConversion(s, func->type(), func->ownerClass(), CPP_RETURN_VAR); - s << ';' << endl; - } + s << func->type()->cppSignature(); + s << " " CPP_RETURN_VAR " = "; + } + s << methodCall << ';' << endl; + + if (func->allowThread()) { + s << INDENT << THREAD_STATE_SAVER_VAR ".restore();" << endl; + threadRestored = true; + } + + if (!isCtor && !func->isInplaceOperator() && func->type()) { + s << INDENT << PYTHON_RETURN_VAR " = "; + writeToPythonConversion(s, func->type(), func->ownerClass(), CPP_RETURN_VAR); + s << ';' << endl; } } } + if (!threadRestored && func->allowThread()) + s << INDENT << THREAD_STATE_SAVER_VAR ".restore();" << endl; + if (func->hasInjectedCode() && !func->isConstructor()) { s << endl; writeCodeSnips(s, snips, CodeSnip::End, TypeSystem::TargetLangCode, func, lastArg); @@ -2152,9 +2163,6 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f } } writeParentChildManagement(s, func, !hasReturnPolicy); - - if (func->allowThread()) - s << INDENT << THREAD_STATE_SAVER_VAR ".restore();" << endl; } QStringList CppGenerator::getAncestorMultipleInheritance(const AbstractMetaClass* metaClass) |