Commit fa2d65b8 authored by gsamain's avatar gsamain

Correct code to avoid useless optarg presence when doing message (un)locking

parent e9367c94
......@@ -1227,7 +1227,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("%s(this->%s);" % (op_lbda(narg), narg.cname))
if opt_arg_count:
code.putln("if (this->%s != NULL) {" % opt_arg_name)
opt_arg_guard = code.insertion_point()
code.increase_indent()
num_if = 0
for opt_idx, optarg in enumerate(func_type.args[narg_count:]):
if optarg.type.is_cyp_class:
......@@ -1244,6 +1245,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
num_if += 1
for _ in range(num_if):
code.putln("}")
if num_if:
opt_arg_guard.putln("if (this->%s != NULL) {" % opt_arg_name)
code.putln("}")
code.putln("}")
for reifying_class_entry in entry.type.scope.reifying_entries:
......@@ -1347,10 +1351,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("++%s;" % trylock_result)
num_trylock += 1
if opt_arg_count:
num_optional_if = 0
code.putln("if (this->%s != NULL) {" % opt_arg_name)
if opt_arg_count:
opt_arg_guard = code.insertion_point()
code.increase_indent()
for opt_idx, optarg in enumerate(func_type.args[narg_count:]):
if optarg.type.is_cyp_class:
try_op = "Cy_TRYRLOCK" if optarg.type.is_const else "Cy_TRYWLOCK"
......@@ -1371,6 +1375,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
num_trylock += 1
for _ in range(num_optional_if):
code.putln("}")
if num_optional_if > 0:
opt_arg_guard.putln("if (this->%s != NULL) {" % opt_arg_name)
code.putln("}") # The check for optional_args != NULL
for _ in range(num_trylock):
code.putln("}")
......@@ -1388,15 +1394,18 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("if (%s > %s) {" % (trylock_result, num_unlock))
code.putln("Cy_UNLOCK(this->%s);" % narg.cname)
num_unlock += 1
if opt_arg_count:
if opt_arg_count and num_optional_if:
code.putln("if (this->%s != NULL) {" % opt_arg_name)
for opt_idx, optarg in enumerate(func_type.args[narg_count:]):
if optarg.type.is_cyp_class:
code.putln("if (%s > %s) {" % (trylock_result, num_unlock))
code.putln("Cy_UNLOCK(this->%s->%s);" % (opt_arg_name, func_type.opt_arg_cname(optarg.name)))
num_unlock += 1
for _ in range(num_unlock):
# Note: we do not respect the semantic order of end-blocks here for simplification purpose.
# This one is for the "not NULL opt arg" check
code.putln("}")
# These ones are all the checks for mandatory and optional arguments
for _ in range(num_unlock):
code.putln("}")
code.putln("return 0;")
code.putln("}")
......
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