Commit f871cad3 authored by Vitja Makarov's avatar Vitja Makarov

Don't initialize unused cdef-function optional args

parent 594e3bad
...@@ -523,7 +523,6 @@ def check_definitions(flow, compiler_directives): ...@@ -523,7 +523,6 @@ def check_definitions(flow, compiler_directives):
if is_arg: if is_arg:
if warn_unused_arg: if warn_unused_arg:
messages.warning(entry.pos, "Unused argument '%s'" % entry.name) messages.warning(entry.pos, "Unused argument '%s'" % entry.name)
entry.cf_used = False
else: else:
if warn_unused: if warn_unused:
messages.warning(entry.pos, "Unused entry '%s'" % entry.name) messages.warning(entry.pos, "Unused entry '%s'" % entry.name)
......
...@@ -1828,8 +1828,11 @@ class CFuncDefNode(FuncDefNode): ...@@ -1828,8 +1828,11 @@ class CFuncDefNode(FuncDefNode):
code.putln("%s%s%s {" % (storage_class, modifiers, header)) code.putln("%s%s%s {" % (storage_class, modifiers, header))
def generate_argument_declarations(self, env, code): def generate_argument_declarations(self, env, code):
scope = self.local_scope
for arg in self.args: for arg in self.args:
if arg.default: if arg.default:
entry = scope.lookup(arg.name)
if entry.cf_used:
result = arg.calculate_default_value_code(code) result = arg.calculate_default_value_code(code)
code.putln('%s = %s;' % ( code.putln('%s = %s;' % (
arg.type.declaration_code(arg.cname), result)) arg.type.declaration_code(arg.cname), result))
...@@ -1839,17 +1842,26 @@ class CFuncDefNode(FuncDefNode): ...@@ -1839,17 +1842,26 @@ class CFuncDefNode(FuncDefNode):
def generate_argument_parsing_code(self, env, code): def generate_argument_parsing_code(self, env, code):
i = 0 i = 0
used = 0
if self.type.optional_arg_count: if self.type.optional_arg_count:
scope = self.local_scope
code.putln('if (%s) {' % Naming.optional_args_cname) code.putln('if (%s) {' % Naming.optional_args_cname)
for arg in self.args: for arg in self.args:
if arg.default: if arg.default:
code.putln('if (%s->%sn > %s) {' % (Naming.optional_args_cname, Naming.pyrex_prefix, i)) entry = scope.lookup(arg.name)
if entry.cf_used:
code.putln('if (%s->%sn > %s) {' %
(Naming.optional_args_cname,
Naming.pyrex_prefix, i))
declarator = arg.declarator declarator = arg.declarator
while not hasattr(declarator, 'name'): while not hasattr(declarator, 'name'):
declarator = declarator.base declarator = declarator.base
code.putln('%s = %s->%s;' % (arg.cname, Naming.optional_args_cname, self.type.opt_arg_cname(declarator.name))) code.putln('%s = %s->%s;' %
(arg.cname, Naming.optional_args_cname,
self.type.opt_arg_cname(declarator.name)))
used += 1
i += 1 i += 1
for _ in range(self.type.optional_arg_count): for _ in range(used):
code.putln('}') code.putln('}')
code.putln('}') 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