Commit f871cad3 authored by Vitja Makarov's avatar Vitja Makarov

Don't initialize unused cdef-function optional args

parent 594e3bad
...@@ -523,11 +523,10 @@ def check_definitions(flow, compiler_directives): ...@@ -523,11 +523,10 @@ 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)
entry.cf_used = False entry.cf_used = False
messages.report() messages.report()
......
...@@ -1828,28 +1828,40 @@ class CFuncDefNode(FuncDefNode): ...@@ -1828,28 +1828,40 @@ 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:
result = arg.calculate_default_value_code(code) entry = scope.lookup(arg.name)
code.putln('%s = %s;' % ( if entry.cf_used:
arg.type.declaration_code(arg.cname), result)) result = arg.calculate_default_value_code(code)
code.putln('%s = %s;' % (
arg.type.declaration_code(arg.cname), result))
def generate_keyword_list(self, code): def generate_keyword_list(self, code):
pass pass
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)
declarator = arg.declarator if entry.cf_used:
while not hasattr(declarator, 'name'): code.putln('if (%s->%sn > %s) {' %
declarator = declarator.base (Naming.optional_args_cname,
code.putln('%s = %s->%s;' % (arg.cname, Naming.optional_args_cname, self.type.opt_arg_cname(declarator.name))) Naming.pyrex_prefix, i))
declarator = arg.declarator
while not hasattr(declarator, 'name'):
declarator = declarator.base
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