aboutsummaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-04-06 22:50:56 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:15:20 -0300
commit6ea5f0caa16f783d50221f817431d2cadc22f947 (patch)
tree8620c3da1dcc7695c689b874d8e5559420330797 /generator
parentf107f41c2b99517133ac4d2d624e8ee61cac2bb2 (diff)
Added the type system variables %BEGIN_ALLOW_THREADS and %END_ALLOW_THREADS.
Also moved the save and restore thread state lines to a macro in ShibokenGenerator header file. The type system variables documentation was updated accordingly. Reviewed by Lauro Moura <lauro.neto@openbossa.org> Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'generator')
-rw-r--r--generator/cppgenerator.cpp8
-rw-r--r--generator/shibokengenerator.cpp9
-rw-r--r--generator/shibokengenerator.h2
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>