From: Kirill Smelkov Date: Wed, 14 May 2008 17:16:01 +0000 (+0400) Subject: RFC: constify Cython output all over the place (newbie approach) X-Git-Tag: 0.9.8rc1~23 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=28e39a8ce0fe1ec32da7feff1caff2dbf2d46a8a;p=cython.git RFC: constify Cython output all over the place (newbie approach) 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. --- diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 1fb70945..3f873d4c 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -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()) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 39755885..c71722e8 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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;