Commit 69fdc363 authored by Xavier Thompson's avatar Xavier Thompson

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

parent cc937270
...@@ -1652,7 +1652,8 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode): ...@@ -1652,7 +1652,8 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
if not skipped_self: if not skipped_self:
return # if this ever happens (?), skip non-static methods without a self argument 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 (?) # we pass the global scope as argument, should not affect the result (?)
if not cfunc_return_type.can_coerce_to_pyobject(env.global_scope()): if not cfunc_return_type.can_coerce_to_pyobject(env.global_scope()):
...@@ -1714,11 +1715,22 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode): ...@@ -1714,11 +1715,22 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
# > return the result of the call if the underlying return type is not void # > return the result of the call if the underlying return type is not void
if cfunc_return_type.is_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: 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]) 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 # > the wrapper method
return DefNode( return DefNode(
cfunc_method.pos, cfunc_method.pos,
......
...@@ -4027,6 +4027,9 @@ class CypClassType(CppClassType): ...@@ -4027,6 +4027,9 @@ class CypClassType(CppClassType):
return path return path
# allow conversion to Python only when there is a wrapper type # 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): def create_to_py_utility_code(self, env):
if not self.wrapper_type: if not self.wrapper_type:
return False 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