diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index bd6b2ff88dd2cae9abbc4bd0526cdc88770b21ca..bc05047b66e653f41ae49e72b2ba3a6b6b5ca53d 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -2572,7 +2572,7 @@ class SimpleCallNode(CallNode): for formal_arg, actual_arg in args[expected_nargs:actual_nargs]: code.putln("%s.%s = %s;" % ( self.opt_arg_struct, - formal_arg.name, + func_type.opt_arg_cname(formal_arg.name), actual_arg.result_as(formal_arg.type))) exc_checks = [] if self.type.is_pyobject: diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 386e58eb015b34ddcc32c17086d7def7d88ef75b..dd9036566306045fb37c8551470edf8d3884aac8 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1473,13 +1473,11 @@ class CFuncDefNode(FuncDefNode): code.putln('if (%s) {' % Naming.optional_args_cname) for arg in self.args: if arg.default: - # FIXME: simple name prefixing doesn't work when - # argument name mangling is in place code.putln('if (%s->%sn > %s) {' % (Naming.optional_args_cname, 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, declarator.name)) + code.putln('%s = %s->%s;' % (arg.cname, Naming.optional_args_cname, self.type.opt_arg_cname(declarator.name))) i += 1 for _ in range(self.type.optional_arg_count): code.putln('}') diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 05ee6380423db6129a21da27f615d42a88b1b3fd..a50760a4e1072bba4001a4fef533bc428bb5abf1 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -1535,6 +1535,9 @@ class CFuncType(CType): def signature_cast_string(self): s = self.declaration_code("(*)", with_calling_convention=False) return '(%s)' % s + + def opt_arg_cname(self, arg_name): + return self.op_arg_struct.base_type.scope.lookup(arg_name).cname class CFuncTypeArg(object): diff --git a/tests/bugs.txt b/tests/bugs.txt index 31d6ff3a85e7a844e75046f3a61098b3c86cf220..23dca0c7b4b73e717d6a2e9fbd763bd074fc219f 100644 --- a/tests/bugs.txt +++ b/tests/bugs.txt @@ -5,5 +5,4 @@ methodmangling_T5 class_attribute_init_values_T18 numpy_ValueError_T172 unsignedbehaviour_T184 -bad_c_struct_T252 missing_baseclass_in_predecl_T262 diff --git a/tests/run/bad_c_struct_T252.pyx b/tests/run/bad_c_struct_T252.pyx index e011ec2d3c43d79067af9283a6708ab6f6d061b4..2b457f235d16615d3c2aa867ffcc59525cd9a158 100644 --- a/tests/run/bad_c_struct_T252.pyx +++ b/tests/run/bad_c_struct_T252.pyx @@ -1,10 +1,10 @@ cdef cf(default=None): return default -cpdef cpf(default=None): +cpdef cpf(default=100): """ >>> cpf() - None + 100 >>> cpf(1) 1 >>> cpf(default=2) @@ -13,10 +13,10 @@ cpdef cpf(default=None): default = cf(default) return default -def pf(default=None): +def pf(default=100): """ >>> pf() - None + 100 >>> pf(1) 1 >>> pf(default=2)