Trac #80, error on unimplemented pxd cdef functions
authorRobert Bradshaw <robertwb@math.washington.edu>
Wed, 29 Oct 2008 01:09:19 +0000 (18:09 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Wed, 29 Oct 2008 01:09:19 +0000 (18:09 -0700)
Cython/Compiler/Main.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/Symtab.py

index 015146d29ac2c84cb1385b17958e227655dc649b..54b70a15324d08a4799300b1252fedd6cc55cd52 100644 (file)
@@ -84,13 +84,13 @@ class Context:
         from AutoDocTransforms import EmbedSignature
         from Optimize import FlattenInListTransform, SwitchTransform, FinalOptimizePhase
         from Buffer import IntroduceBufferAuxiliaryVars
-        from ModuleNode import check_c_classes
+        from ModuleNode import check_c_declarations
 
         if pxd:
-            _check_c_classes = None
+            _check_c_declarations = None
             _specific_post_parse = PxdPostParse(self)
         else:
-            _check_c_classes = check_c_classes
+            _check_c_declarations = check_c_declarations
             _specific_post_parse = None
             
         if py and not pxd:
@@ -111,7 +111,7 @@ class Context:
             EmbedSignature(self),
             TransformBuiltinMethods(self),
             IntroduceBufferAuxiliaryVars(self),
-            _check_c_classes,
+            _check_c_declarations,
             AnalyseExpressionsTransform(self),
             SwitchTransform(),
             FinalOptimizePhase(self),
index a5dd578d10220db82b5a7371ee04d4981dd75225..df264f9f31187f210cd684ed75b49101c19e6c66 100644 (file)
@@ -26,8 +26,9 @@ from Cython.Utils import open_new_file, replace_suffix, UtilityCode
 from StringEncoding import escape_byte_string, EncodedString
 
 
-def check_c_classes(module_node):
+def check_c_declarations(module_node):
     module_node.scope.check_c_classes()
+    module_node.scope.check_c_functions()
     return module_node
 
 class ModuleNode(Nodes.Node, Nodes.BlockNode):
index a7f585600fb09b56bad2a36766b115517785185a..6c906c5e3a0c8c6c7f392ce133041ce88d357499 100644 (file)
@@ -135,6 +135,7 @@ class Entry:
     used = 0
     is_special = 0
     defined_in_pxd = 0
+    is_implemented = 0
     api = 0
     utility_code = None
     is_overridable = 0
@@ -445,6 +446,8 @@ class Scope:
             entry.api = 1
         if not defining and not in_pxd and visibility != 'extern':
             error(pos, "Non-extern C function '%s' declared but not defined" % name)
+        if defining:
+            entry.is_implemented = True
         return entry
     
     def add_cfunction(self, name, type, pos, cname, visibility):
@@ -1093,8 +1096,8 @@ class ModuleScope(Scope):
         for entry in self.c_class_entries:
             if debug_check_c_classes:
                 print("...entry %s %s" % (entry.name, entry))
-                print("......type = " + entry.type)
-                print("......visibility = " + entry.visibility)
+                print("......type = " entry.type)
+                print("......visibility = ", entry.visibility)
             type = entry.type
             name = entry.name
             visibility = entry.visibility
@@ -1116,6 +1119,17 @@ class ModuleScope(Scope):
             if type.vtabslot_cname:
                 #print "ModuleScope.check_c_classes: allocating vtable cname for", self ###
                 type.vtable_cname = self.mangle(Naming.vtable_prefix, entry.name)
+                
+    def check_c_functions(self):
+        # Performs post-analysis checking making sure all 
+        # defined c functions are actually implemented.
+        for name, entry in self.entries.items():
+            if entry.is_cfunction:
+                if (entry.defined_in_pxd 
+                        and entry.visibility != 'extern'
+                        and not entry.in_cinclude 
+                        and not entry.is_implemented):
+                    error(entry.pos, "Non-extern C function '%s' declared but not defined" % name)
     
     def attach_var_entry_to_c_class(self, entry):
         # The name of an extension class has to serve as both a type