Vitja Makarov, 05.12.2010 08:41:
I've updated patch.
I removed pretty_name, bad idea should use name instead in pydeclare_lambda.
`is_lambda` is now called `is_anonymous`, that means that entry itself
doesn't know how it will be named inside scope, so its anonymous (both
lambda and pyfunctions)
That's ok and the patch looks good to me now.
However, it lacks error tests and the modified code actually fails to
detect redefinitions of cdef functions as Python functions and vice versa,
which is not supported (and IMHO doesn't make sense either). Similarly,
redefinitions in cdef classes aren't currently supported but are not
detected either.
I've attached a patch that currently breaks cpdef functions, but that
handles (and tests) at least some of the error cases. I'm not sure what to
do to fix the cpdef functions, though.
BTW, note that there's a typo in the test name.
Stefan
diff -r 9029c2b62103 Cython/Compiler/Symtab.py
--- a/Cython/Compiler/Symtab.py Sun Dec 05 20:37:19 2010 +0100
+++ b/Cython/Compiler/Symtab.py Sun Dec 05 22:08:33 2010 +0100
@@ -515,8 +515,9 @@
return self.outer_scope.declare_builtin(name, pos)
def _declare_pyfunction(self, name, pos, visibility='extern', entry=None):
- if entry and not entry.type.is_cfunction:
- error(pos, "'%s' already declared" % name)
+ if entry and visibility == 'extern':
+ error(pos, "'%s' redeclared" % name)
+ error(entry.pos, "Previous declaration is here")
entry = self.declare_var(name, py_object_type, pos, visibility=visibility)
entry.signature = pyfunction_signature
self.pyfunc_entries.append(entry)
@@ -530,7 +531,7 @@
if entry:
if entry.type.is_unspecified:
entry.type = py_object_type
- elif not entry.type.is_pyobject:
+ elif entry.type is not py_object_type:
return self._declare_pyfunction(name, pos, visibility=visibility, entry=entry)
else: # declare entry stub
self.declare_var(name, py_object_type, pos, visibility=visibility)
@@ -1537,6 +1538,10 @@
warning(pos, "__new__ method of extension type will change semantics "
"in a future version of Pyrex and Cython. Use __cinit__ instead.")
name = EncodedString("__cinit__")
+ entry = self.lookup_here(name)
+ if entry and not entry.is_cfunction: # currently needed to keep cpdef functions working
+ error(pos, "'%s' redeclared" % name)
+ error(entry.pos, "Previous declaration is here")
entry = self.declare_var(name, py_object_type, pos, visibility='extern')
special_sig = get_special_method_signature(name)
if special_sig:
@@ -1570,7 +1575,7 @@
(args[0].type, name, self.parent_type))
entry = self.lookup_here(name)
if entry:
- if not entry.is_cfunction:
+ if not entry.is_cfunction and not entry.type.is_pyobject:
warning(pos, "'%s' redeclared " % name, 0)
else:
if defining and entry.func_cname:
diff -r 9029c2b62103 tests/errors/pyfunc_redefine_typed.pyx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/errors/pyfunc_redefine_typed.pyx Sun Dec 05 22:08:33 2010 +0100
@@ -0,0 +1,61 @@
+
+def define_object():
+ cdef object x
+ def x(): pass # ok
+
+def define_ctype():
+ cdef int x
+ def x(): pass # not ok
+
+def define_pytype():
+ cdef list x
+ def x(): pass # not ok
+
+def define_functype():
+ cdef int (*x)()
+ def x(): pass # not ok
+
+cdef class RedefExt(object):
+ def x(self): pass
+ def x(self): pass # potentially ok, but not supported
+
+ cdef int x1(self): pass
+ def x1(self): pass # FIXME: not ok!
+
+ def x2(self): pass
+ cdef int x2(self): pass # not ok
+
+ def x3(self): pass
+ cpdef int x3(self): pass # not ok
+
+ cpdef int x4(self): pass
+ def x4(self): pass # FIXME: not ok?
+
+def x(): pass
+cdef x(): pass # not ok
+
+cdef x1(): pass
+def x1(): pass # not ok
+
+_ERRORS = """
+8:4: 'x' redeclared
+12:4: 'x' redeclared
+16:4: 'x' redeclared
+19:4: Previous declaration is here
+20:4: 'x' redeclared
+#22:9: Previous declaration is here
+#23:4: 'x1' redeclared
+25:4: Previous declaration is here
+26:9: 'x2' already defined
+26:9: Signature not compatible with previous declaration
+28:4: Previous declaration is here
+28:4: Previous declaration is here
+29:10: 'x3' already defined
+29:10: Signature not compatible with previous declaration
+29:10: 'x3' redeclared
+#31:10: Previous declaration is here
+#32:4: 'x4' redeclared
+35:5: Function signature does not match previous declaration
+37:5: Previous declaration is here
+38:0: 'x1' redeclared
+"""
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev