diff options
Diffstat (limited to 'generator')
-rw-r--r-- | generator/cppgenerator.cpp | 8 | ||||
-rw-r--r-- | generator/shibokengenerator.cpp | 9 | ||||
-rw-r--r-- | generator/shibokengenerator.h | 2 |
3 files changed, 15 insertions, 4 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp index f208241b8..cef8523be 100644 --- a/generator/cppgenerator.cpp +++ b/generator/cppgenerator.cpp @@ -417,9 +417,9 @@ void CppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *metaCl s << INDENT << "const ::" << metaClass->qualifiedCppName() << "* cppSelf = "; s << "Shiboken::Converter< ::" << metaClass->qualifiedCppName() << "*>::toCpp(pyObj);" << endl; s << INDENT << "int result;" << endl; - s << INDENT << "Py_BEGIN_ALLOW_THREADS" << endl; + s << INDENT << BEGIN_ALLOW_THREADS << endl; s << INDENT << "result = !cppSelf->isNull();" << endl; - s << INDENT << "Py_END_ALLOW_THREADS" << endl; + s << INDENT << END_ALLOW_THREADS << endl; s << INDENT << "return result;" << endl; s << '}' << endl << endl; } @@ -2161,7 +2161,7 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f } if (!injectedCodeCallsCppFunction(func)) { - s << INDENT << "PyThreadState* _save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS" << endl << INDENT; + s << INDENT << BEGIN_ALLOW_THREADS << endl << INDENT; if (isCtor) { s << "cptr = "; } else if (func->type() && !func->isInplaceOperator()) { @@ -2185,7 +2185,7 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f s << " " CPP_RETURN_VAR " = "; } s << methodCall << ';' << endl; - s << INDENT << "PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS" << endl; + s << INDENT << END_ALLOW_THREADS << endl; if (!isCtor && !func->isInplaceOperator() && func->type() && !injectedCodeHasReturnValueAttribution(func, TypeSystem::TargetLangCode)) { diff --git a/generator/shibokengenerator.cpp b/generator/shibokengenerator.cpp index 8d8cd4230..43f4192d2 100644 --- a/generator/shibokengenerator.cpp +++ b/generator/shibokengenerator.cpp @@ -1221,6 +1221,15 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s, code.replace("%CPPSELF.", replacement.arg(cppSelf)); code.replace("%CPPSELF", cppSelf); + if (code.indexOf("%BEGIN_ALLOW_THREADS") > -1) { + if (code.count("%BEGIN_ALLOW_THREADS") == code.count("%END_ALLOW_THREADS")) { + code.replace("%BEGIN_ALLOW_THREADS", BEGIN_ALLOW_THREADS); + code.replace("%END_ALLOW_THREADS", END_ALLOW_THREADS); + } else { + ReportHandler::warning("%BEGIN_ALLOW_THREADS and %END_ALLOW_THREADS mismatch"); + } + } + // replace template variable for the Python Type object for the // class implementing the method in which the code snip is written if (func->isStatic()) { diff --git a/generator/shibokengenerator.h b/generator/shibokengenerator.h index c660f2efd..abf74c5fe 100644 --- a/generator/shibokengenerator.h +++ b/generator/shibokengenerator.h @@ -30,6 +30,8 @@ #define CPP_SELF_VAR "cppSelf" #define CPP_ARG "cppArg" #define CPP_ARG0 (CPP_ARG "0") +#define BEGIN_ALLOW_THREADS "PyThreadState* _save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS" +#define END_ALLOW_THREADS "PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS" #include <generator.h> #include <QtCore/QTextStream> |