RFC: constify Cython output all over the place (newbie approach)
authorKirill Smelkov <kirr@mns.spb.ru>
Wed, 14 May 2008 17:16:01 +0000 (21:16 +0400)
committerKirill Smelkov <kirr@mns.spb.ru>
Wed, 14 May 2008 17:16:01 +0000 (21:16 +0400)
You know, when developing code, it is very tedious to look for meaningful
errors and warnings in presence of tons of noise like

    warning: deprecated conversion from string constant to ‘char*’

And you know what? It seems in the next version of gcc, this deprecation
warnings will be turned into errors.

----

Python sources already use 'const' keyword freely, so I think it's time to add
constify bits all over the place.

Cython/Compiler/ModuleNode.py
Cython/Compiler/Nodes.py

index 1fb70945a403a6ab869aa8bc5cac1e00881f9d24..3f873d4cf2cd3a2125e186657c3318f692a7bdd9 100644 (file)
@@ -487,9 +487,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
             code.putln('static PyObject *%s;' % Naming.preimport_cname)
         code.putln('static int %s;' % Naming.lineno_cname)
         code.putln('static int %s = 0;' % Naming.clineno_cname)
-        code.putln('static char * %s= %s;' % (Naming.cfilenm_cname, Naming.file_c_macro))
-        code.putln('static char *%s;' % Naming.filename_cname)
-        code.putln('static char **%s;' % Naming.filetable_cname)
+        code.putln('static const char * %s= %s;' % (Naming.cfilenm_cname, Naming.file_c_macro))
+        code.putln('static const char *%s;' % Naming.filename_cname)
+        code.putln('static const char **%s;' % Naming.filetable_cname)
         if env.doc:
             code.putln('')
             code.putln('static char %s[] = "%s";' % (env.doc_cname, env.doc))
@@ -513,7 +513,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
     
     def generate_filename_table(self, code):
         code.putln("")
-        code.putln("static char *%s[] = {" % Naming.filenames_cname)
+        code.putln("static const char *%s[] = {" % Naming.filenames_cname)
         if code.filename_list:
             for source_desc in code.filename_list:
                 filename = os.path.basename(source_desc.get_filenametable_entry())
index 3975588595b4d6abc1ecff6a2bcf11f1b97b9457..c71722e8ff2a5c88821bed0d1392fd3a72cdec3f 100644 (file)
@@ -1466,7 +1466,7 @@ class DefNode(FuncDefNode):
             reqd_kw_flags = []
             has_reqd_kwds = False
             code.put(
-                "static char *%s[] = {" %
+                "static const char *%s[] = {" %
                     Naming.kwdlist_cname)
             for arg in self.args:
                 if arg.is_generic:
@@ -1619,7 +1619,7 @@ class DefNode(FuncDefNode):
 
         argformat = '"%s"' % string.join(arg_formats, "")
         pt_arglist = [Naming.args_cname, Naming.kwds_cname, argformat,
-                      Naming.kwdlist_cname] + arg_addrs
+                      '(char **)/*temp.hack*/'+Naming.kwdlist_cname] + arg_addrs
         pt_argstring = string.join(pt_arglist, ", ")
         code.putln(
             'if (unlikely(!PyArg_ParseTupleAndKeywords(%s))) %s' % (
@@ -4219,9 +4219,9 @@ missing_kwarg:
 
 unraisable_exception_utility_code = [
 """
-static void __Pyx_WriteUnraisable(char *name); /*proto*/
+static void __Pyx_WriteUnraisable(const char *name); /*proto*/
 ""","""
-static void __Pyx_WriteUnraisable(char *name) {
+static void __Pyx_WriteUnraisable(const char *name) {
     PyObject *old_exc, *old_val, *old_tb;
     PyObject *ctx;
     PyErr_Fetch(&old_exc, &old_val, &old_tb);
@@ -4241,13 +4241,13 @@ static void __Pyx_WriteUnraisable(char *name) {
 
 traceback_utility_code = [
 """
-static void __Pyx_AddTraceback(char *funcname); /*proto*/
+static void __Pyx_AddTraceback(const char *funcname); /*proto*/
 ""","""
 #include "compile.h"
 #include "frameobject.h"
 #include "traceback.h"
 
-static void __Pyx_AddTraceback(char *funcname) {
+static void __Pyx_AddTraceback(const char *funcname) {
     PyObject *py_srcfile = 0;
     PyObject *py_funcname = 0;
     PyObject *py_globals = 0;