cython-devel
changeset 2658:4208042ceeae 0.12.alpha0
Fix bug #252, mangle illegal optional c argument names.
| author | Robert Bradshaw <robertwb@math.washington.edu> |
|---|---|
| date | Wed Nov 04 21:41:14 2009 -0800 (3 years ago) |
| parents | a87fd9d5750e |
| children | e49f3f25bb9e |
| files | Cython/Compiler/ExprNodes.py Cython/Compiler/Nodes.py Cython/Compiler/PyrexTypes.py tests/bugs.txt tests/run/bad_c_struct_T252.pyx |
line diff
1.1 --- a/Cython/Compiler/ExprNodes.py Wed Nov 04 21:02:09 2009 -0800
1.2 +++ b/Cython/Compiler/ExprNodes.py Wed Nov 04 21:41:14 2009 -0800
1.3 @@ -2572,7 +2572,7 @@
1.4 for formal_arg, actual_arg in args[expected_nargs:actual_nargs]:
1.5 code.putln("%s.%s = %s;" % (
1.6 self.opt_arg_struct,
1.7 - formal_arg.name,
1.8 + func_type.opt_arg_cname(formal_arg.name),
1.9 actual_arg.result_as(formal_arg.type)))
1.10 exc_checks = []
1.11 if self.type.is_pyobject:
2.1 --- a/Cython/Compiler/Nodes.py Wed Nov 04 21:02:09 2009 -0800
2.2 +++ b/Cython/Compiler/Nodes.py Wed Nov 04 21:41:14 2009 -0800
2.3 @@ -1473,13 +1473,11 @@
2.4 code.putln('if (%s) {' % Naming.optional_args_cname)
2.5 for arg in self.args:
2.6 if arg.default:
2.7 - # FIXME: simple name prefixing doesn't work when
2.8 - # argument name mangling is in place
2.9 code.putln('if (%s->%sn > %s) {' % (Naming.optional_args_cname, Naming.pyrex_prefix, i))
2.10 declarator = arg.declarator
2.11 while not hasattr(declarator, 'name'):
2.12 declarator = declarator.base
2.13 - code.putln('%s = %s->%s;' % (arg.cname, Naming.optional_args_cname, declarator.name))
2.14 + code.putln('%s = %s->%s;' % (arg.cname, Naming.optional_args_cname, self.type.opt_arg_cname(declarator.name)))
2.15 i += 1
2.16 for _ in range(self.type.optional_arg_count):
2.17 code.putln('}')
3.1 --- a/Cython/Compiler/PyrexTypes.py Wed Nov 04 21:02:09 2009 -0800
3.2 +++ b/Cython/Compiler/PyrexTypes.py Wed Nov 04 21:41:14 2009 -0800
3.3 @@ -1535,6 +1535,9 @@
3.4 def signature_cast_string(self):
3.5 s = self.declaration_code("(*)", with_calling_convention=False)
3.6 return '(%s)' % s
3.7 +
3.8 + def opt_arg_cname(self, arg_name):
3.9 + return self.op_arg_struct.base_type.scope.lookup(arg_name).cname
3.10
3.11
3.12 class CFuncTypeArg(object):
4.1 --- a/tests/bugs.txt Wed Nov 04 21:02:09 2009 -0800
4.2 +++ b/tests/bugs.txt Wed Nov 04 21:41:14 2009 -0800
4.3 @@ -5,5 +5,4 @@
4.4 class_attribute_init_values_T18
4.5 numpy_ValueError_T172
4.6 unsignedbehaviour_T184
4.7 -bad_c_struct_T252
4.8 missing_baseclass_in_predecl_T262
5.1 --- a/tests/run/bad_c_struct_T252.pyx Wed Nov 04 21:02:09 2009 -0800
5.2 +++ b/tests/run/bad_c_struct_T252.pyx Wed Nov 04 21:41:14 2009 -0800
5.3 @@ -1,10 +1,10 @@
5.4 cdef cf(default=None):
5.5 return default
5.6
5.7 -cpdef cpf(default=None):
5.8 +cpdef cpf(default=100):
5.9 """
5.10 >>> cpf()
5.11 - None
5.12 + 100
5.13 >>> cpf(1)
5.14 1
5.15 >>> cpf(default=2)
5.16 @@ -13,10 +13,10 @@
5.17 default = cf(default)
5.18 return default
5.19
5.20 -def pf(default=None):
5.21 +def pf(default=100):
5.22 """
5.23 >>> pf()
5.24 - None
5.25 + 100
5.26 >>> pf(1)
5.27 1
5.28 >>> pf(default=2)
