[Pyrex] Unused variables

Elias Pschernig elias at users.sourceforge.net
Sun Dec 18 13:57:51 CET 2005


Improved version attached.

-- 
Elias Pschernig
-------------- next part --------------
diff -ru Pyrex/Compiler/Code.py /usr/lib/python2.3/site-packages/Pyrex/Compiler/Code.py
--- Pyrex/Compiler/Code.py	2005-09-13 09:49:53.000000000 +0000
+++ Pyrex/Compiler/Code.py	2005-12-16 23:57:16.000000000 +0000
@@ -2,7 +2,7 @@
 #   Pyrex - Code output module
 #
 
-import Naming
+import Naming, StringIO
 from Pyrex.Utils import open_new_file
 
 class CCodeWriter:
@@ -22,7 +22,10 @@
     in_try_finally = 0
 
     def __init__(self, outfile_name):
-        self.f = open_new_file(outfile_name)
+        if outfile_name:
+            self.f = open_new_file(outfile_name)
+        else:
+            self.f = StringIO.StringIO()
         self.level = 0
         self.bol = 1
         self.marker = None
@@ -31,6 +34,9 @@
         self.filename_table = {}
         self.filename_list = []
 
+    def append(self, code):
+        self.f.write(code.f.getvalue())
+
     def putln(self, code = ""):
         if self.marker and self.bol:
             self.emit_marker()
diff -ru Pyrex/Compiler/Nodes.py /usr/lib/python2.3/site-packages/Pyrex/Compiler/Nodes.py
--- Pyrex/Compiler/Nodes.py	2005-09-13 09:35:22.000000000 +0000
+++ Pyrex/Compiler/Nodes.py	2005-12-17 00:36:24.000000000 +0000
@@ -164,9 +164,8 @@
     def generate_c_code(self, env, result):
         modules = []
         self.find_referenced_modules(env, modules, {})
-        code = Code.CCodeWriter(result.c_file)
+        code = Code.CCodeWriter(None)
         code.init_labels()
-        self.generate_module_preamble(env, modules, code)
         for module in modules:
             self.generate_declarations_for_module(module, code)
         code.putln("")
@@ -182,6 +181,11 @@
         self.generate_module_init_func(modules[:-1], env, code)
         self.generate_filename_table(code)
         self.generate_utility_functions(env, code)
+
+        final_code = Code.CCodeWriter(result.c_file)
+        self.generate_module_preamble(env, modules, final_code)
+        final_code.append(code)
+
         result.c_file_generated = 1
     
     def find_referenced_modules(self, env, module_list, modules_seen):
@@ -204,7 +208,21 @@
         #for filename in env.include_files:
         #	code.putln('#include "%s"' % filename)
         code.putln('')
+
         code.put(utility_function_predeclarations)
+        # Auto-generate predeclaration for all the used utility functions
+        for utility in env.utility_code_used:
+            continuation = 0
+            for declaration in utility.splitlines():
+                if declaration: # skip leading empty lines
+                    if continuation or declaration.startswith("static"):
+                        if declaration.endswith("{"):
+                            code.putln(declaration[:-1] + "; /* prototype */")
+                            continuation = 0
+                        else:
+                            code.putln(declaration)
+                            continuation = 1
+
         if Options.intern_names:
             code.putln(get_name_interned_predeclaration)
         else:
@@ -3507,28 +3523,31 @@
 """
 typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
 typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
-static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/
-static int __Pyx_EndUnpack(PyObject *, int); /*proto*/
-static int __Pyx_PrintItem(PyObject *); /*proto*/
-static int __Pyx_PrintNewline(void); /*proto*/
-static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
-static void __Pyx_ReRaise(void); /*proto*/
-static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
-static PyObject *__Pyx_GetExcValue(void); /*proto*/
-static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
-static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
-static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds,\
- char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/
-static void __Pyx_WriteUnraisable(char *name); /*proto*/
 static void __Pyx_AddTraceback(char *funcname); /*proto*/
-static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size);  /*proto*/
-static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
-static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/
-static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
-static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
-static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
 """
 
+#"""
+#static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/
+#static int __Pyx_EndUnpack(PyObject *, int); /*proto*/
+#static int __Pyx_PrintItem(PyObject *); /*proto*/
+#static int __Pyx_PrintNewline(void); /*proto*/
+#static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+#static void __Pyx_ReRaise(void); /*proto*/
+#static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
+#static PyObject *__Pyx_GetExcValue(void); /*proto*/
+#static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
+#static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
+#static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds,\
+# char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/
+#static void __Pyx_WriteUnraisable(char *name); /*proto*/
+#static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size);  /*proto*/
+#static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
+#static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/
+#static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
+#static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
+#static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+#"""
+
 get_name_predeclaration = \
 "static PyObject *__Pyx_GetName(PyObject *dict, char *name); /*proto*/"
 


More information about the Pyrex mailing list