From b9b777ec9f1be48d4b1e8f217c5eb7cc60bb773c Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Mon, 6 Sep 2010 14:22:11 -0300 Subject: Retore thread state in the first line before the C++ call to avoid any other Python call. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewer: Luciano Wolf Renato Araújo --- cppgenerator.cpp | 72 +++++++++++++++++++++++++++++++------------------------- 1 file 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) -- cgit v1.2.3