Revision: 564
http://svn.sourceforge.net/pygccxml/?rev=564&view=rev
Author: mbaas
Date: 2006-09-20 09:52:11 -0700 (Wed, 20 Sep 2006)
Log Message:
-----------
Modified the thread_safe code. This code can be enabled by setting an attribute thread_safe to True on the decl_wrapper.
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py
Modified: pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py 2006-09-20 16:50:09 UTC (rev 563)
+++ pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py 2006-09-20 16:52:11 UTC (rev 564)
@@ -229,6 +229,8 @@
# Stores the name of the variable that holds the override
self._override_var = None
+ # Stores the name of the 'gstate' variable
+ self._gstate_var = None
def default_name(self):
"""Return the name of the 'default' function.
@@ -317,28 +319,31 @@
def create_virtual_body(self):
- thread_safe = False
+ thread_safe = getattr(self.declaration, "thread_safe", False)
if thread_safe:
- # Todo: Properly allocate "gstate"
body = """
-PyGILState_STATE gstate;
-gstate = PyGILState_Ensure();
+pyplusplus::gil_state_t %(gstate_var)s;
-$DECLARATIONS
+%(gstate_var)s.ensure();
+boost::python::override %(override_var)s = this->get_override( "%(alias)s" );
+%(gstate_var)s.release();
-PyGILState_Release(gstate);
-
if( %(override_var)s )
{
- gstate = PyGILState_Ensure();
+ // The corresponding release() is done in the destructor of %(gstate_var)s
+ %(gstate_var)s.ensure();
- try {
+ $DECLARATIONS
+
+ try {
$PRE_CALL
${RESULT_VAR_ASSIGNMENT}boost::python::call<$RESULT_TYPE>($INPUT_PARAMS);
$POST_CALL
+
+ $RETURN_STMT
}
catch(...)
{
@@ -346,11 +351,11 @@
{
PyErr_Print();
}
- PyGILState_Release(gstate);
- throw;
+
+ $CLEANUP
+
+ $EXCEPTION_HANDLER_EXIT
}
- PyGILState_Release(gstate);
- $RETURN_STMT
}
else
{
@@ -360,10 +365,12 @@
if not thread_safe:
body = """
-$DECLARATIONS
+boost::python::override %(override_var)s = this->get_override( "%(alias)s" );
if( %(override_var)s )
{
+ $DECLARATIONS
+
$PRE_CALL
${RESULT_VAR_ASSIGNMENT}boost::python::call<$RESULT_TYPE>($INPUT_PARAMS);
@@ -398,6 +405,7 @@
return body % {
# 'override' : self.override_identifier()
'override_var' : self._override_var
+ , 'gstate_var' : self._gstate_var
, 'alias' : self.declaration.alias
# , 'func_var' : "func_"+self.declaration.alias
, 'inherited' : self.create_base_body()
@@ -476,7 +484,8 @@
# Create the substitution manager
decl = self.declaration
sm = function_transformers.substitution_manager_t(decl, transformers=decl.function_transformers)
- self._override_var = sm.virtual_func.declare_local(decl.alias+"_callable", "boost::python::override", default='this->get_override( "%s" )'%decl.alias)
+ self._override_var = sm.virtual_func.allocate_local(decl.alias+"_callable")
+ self._gstate_var = sm.virtual_func.allocate_local("gstate")
self._subst_manager = sm
answer = [ self.create_function() ]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|