Commit 4a3eefc1 authored by Xavier Thompson's avatar Xavier Thompson

Lock inside wrapper methods when the underlying cypclass is in checklock mode

parent 858c5b12
......@@ -1651,7 +1651,8 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
if not skipped_self:
return # if this ever happens (?), skip non-static methods without a self argument
cfunc_return_type = cfunc_method.type.return_type
cfunc_type = cfunc_method.type
cfunc_return_type = cfunc_type.return_type
# we pass the global scope as argument, should not affect the result (?)
if not cfunc_return_type.can_coerce_to_pyobject(env.global_scope()):
......@@ -1713,11 +1714,22 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
# > return the result of the call if the underlying return type is not void
if cfunc_return_type.is_void:
py_stat = ExprStatNode(pos=cfunc_method.pos, expr=c_call)
py_stat = ExprStatNode(cfunc_method.pos, expr=c_call)
else:
py_stat = ReturnStatNode(pos=cfunc_method.pos, return_type=PyrexTypes.py_object_type, value=c_call)
py_stat = ReturnStatNode(cfunc_method.pos, return_type=PyrexTypes.py_object_type, value=c_call)
py_body = StatListNode(cfunc_method.pos, stats=[py_stat])
# > lock around the call in checklock mode
if self.lock_mode == 'checklock':
need_wlock = not cfunc_type.is_const_method
lock_node = LockCypclassNode(
cfunc_method.pos,
state = 'wlocked' if need_wlock else 'rlocked',
obj = underlying_obj,
body = py_body
)
py_body = lock_node
# > the wrapper method
return DefNode(
cfunc_method.pos,
......
......@@ -4208,6 +4208,9 @@ class CypClassType(CppClassType):
return self._mro
# allow conversion to Python only when there is a wrapper type
def can_coerce_to_pyobject(self, env):
return self.wrapper_type is not None
def create_to_py_utility_code(self, env):
if not self.wrapper_type:
return False
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment