Fix e_declarations.pyx, e_nogilfunctype.pyx, e_tempcast.pyx. All tests pass. 0.9.8rc1
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 12 Jun 2008 00:21:38 +0000 (17:21 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 12 Jun 2008 00:21:38 +0000 (17:21 -0700)
Cython/Compiler/ExprNodes.py
Cython/Compiler/PyrexTypes.py
Cython/Compiler/Symtab.py
tests/errors/e_declarations.pyx
tests/errors/e_nogilfunctype.pyx
tests/errors/e_tempcast.pyx

index 976af1ce67094ea48bdf1dd75a7a1ed75e60b125..758de510a9e6adfecc08aa9cd303968b5664769c 100644 (file)
@@ -2791,6 +2791,10 @@ class TypecastNode(ExprNode):
     def analyse_types(self, env):
         base_type = self.base_type.analyse(env)
         _, self.type = self.declarator.analyse(base_type, env)
+        if self.type.is_cfunction:
+            error(self.pos,
+                "Cannot cast to a function type")
+            self.type = PyrexTypes.error_type
         self.operand.analyse_types(env)
         to_py = self.type.is_pyobject
         from_py = self.operand.type.is_pyobject
index a8ff7980e3ad4eef5ad5732858372f7a344deaab..320331d434b2953ba760f1ac64941c76544a9276 100644 (file)
@@ -699,8 +699,6 @@ class CFuncType(CType):
             return 0
         if not self.same_calling_convention_as(other_type):
             return 0
-        if self.nogil != other_type.nogil:
-            return 0
         return 1
 
     def compatible_signature_with(self, other_type, as_cmethod = 0):
index 141c7c838f722b381799d9b488e7614277e06ae8..b74798d2d1ce6e6a98b87085523413a173875f10 100644 (file)
@@ -374,6 +374,10 @@ class Scope:
     
     def declare_pyfunction(self, name, pos):
         # Add an entry for a Python function.
+        entry = self.lookup_here(name)
+        if entry:
+            # This is legal Python, but for now will produce invalid C.
+            error(pos, "'%s' already declared" % name)
         entry = self.declare_var(name, py_object_type, pos)
         entry.signature = pyfunction_signature
         self.pyfunc_entries.append(entry)
@@ -1340,9 +1344,9 @@ class CClassScope(ClassScope):
                 if defining and entry.func_cname:
                     error(pos, "'%s' already defined" % name)
                 #print "CClassScope.declare_cfunction: checking signature" ###
-                if type.same_c_signature_as(entry.type, as_cmethod = 1):
+                if type.same_c_signature_as(entry.type, as_cmethod = 1) and type.nogil == entry.type.nogil:
                     pass
-                elif type.compatible_signature_with(entry.type, as_cmethod = 1):
+                elif type.compatible_signature_with(entry.type, as_cmethod = 1) and type.nogil == entry.type.nogil:
                     if type.optional_arg_count and not type.original_sig.optional_arg_count:
                         # Need to put a wrapper taking no optional arguments 
                         # into the method table.
index 333275b9de6cba4ece5a7236216fabcfe610d241..cd19eb3297a4bf23c64a3fc46ac27c6d0250058e 100644 (file)
@@ -5,7 +5,8 @@ cdef extern int ff()()
 cdef void f():
        cdef void *p
        cdef int (*h)()
-       h = <int ()()>f
+       h = <int ()()>f # this is an error
+       h = <int (*)()>f # this is OK
 _ERRORS = u"""
 /Local/Projects/D/Pyrex/Source/Tests/Errors3/e_declarations.pyx:1:19: Array element cannot be a function
 /Local/Projects/D/Pyrex/Source/Tests/Errors3/e_declarations.pyx:2:18: Function cannot return an array
index 048f65225335d8716bc1429ae7eeb7c87155d9c6..57c8de3fa55f8faad3621cda49b5674f1931f7e9 100644 (file)
@@ -1,8 +1,8 @@
 cdef extern from *:
-       cdef void f() nogil
-       cdef void (*fp)()
+       cdef void f()
+       cdef void (*fp)() nogil
 
 fp = f
 _ERRORS = u"""
-/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_nogilfunctype.pyx:5:6: Cannot assign type 'void (void) nogil' to 'void (*)(void)'
+/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_nogilfunctype.pyx:5:6: Cannot assign type 'void (void)' to 'void (*)(void) nogil'
 """
index dd6b2c9ccc4360597bb3c4771b61788d0f71777e..0a0f8b3abb4a1d2e7a19cd2bd823f7a6a5024bb6 100644 (file)
@@ -1,4 +1,4 @@
-cdef object foo, blarg
+cdef object blarg
 
 def foo(obj):
        cdef int *p