From: Lisandro Dalcin Date: Thu, 6 Nov 2008 20:35:11 +0000 (-0300) Subject: For Py>=2.5, make GCC happy when passing -Wwrite-strings X-Git-Tag: 0.11-beta~272^2~2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2a463b67b36770c3894dbd0baa5371fbee8232de;p=cython.git For Py>=2.5, make GCC happy when passing -Wwrite-strings --- diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 761bd967..13bf3145 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -293,7 +293,7 @@ class GlobalState(object): def add_interned_num_decl(self, entry): if self.should_declare(entry.cname, entry): if entry.init[-1] == "L": - self.initwriter.putln('%s = PyLong_FromString("%s", 0, 0); %s;' % ( + self.initwriter.putln('%s = PyLong_FromString((char *)"%s", 0, 0); %s;' % ( entry.cname, entry.init, self.initwriter.error_goto_if_null(entry.cname, self.module_pos))) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 9603776e..86bdec15 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -899,7 +899,7 @@ class LongNode(AtomicExprNode): def generate_evaluation_code(self, code): code.putln( - '%s = PyLong_FromString("%s", 0, 0); %s' % ( + '%s = PyLong_FromString((char *)"%s", 0, 0); %s' % ( self.result(), self.value, code.error_goto_if_null(self.result(), self.pos))) @@ -4692,8 +4692,8 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) { empty_dict = PyDict_New(); if (!empty_dict) goto bad; - module = PyObject_CallFunction(__import__, "OOOO", - name, global_dict, empty_dict, list); + module = PyObject_CallFunctionObjArgs(__import__, + name, global_dict, empty_dict, list, NULL); bad: Py_XDECREF(empty_list); Py_XDECREF(__import__); @@ -4810,11 +4810,11 @@ static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { create_class_utility_code = UtilityCode( proto = """ -static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/ +static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, const char *modname); /*proto*/ """, impl = """ static PyObject *__Pyx_CreateClass( - PyObject *bases, PyObject *dict, PyObject *name, char *modname) + PyObject *bases, PyObject *dict, PyObject *name, const char *modname) { PyObject *py_modname; PyObject *result = 0; @@ -4877,7 +4877,12 @@ static INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { return Py_None; // this is just to have an accurate signature } else { - return PyObject_CallMethod(L, "append", "(O)", x); + PyObject *r, *m; + m = PyObject_GetAttrString(L, "append"); + if (!m) return NULL; + r = PyObject_CallFunctionObjArgs(m, x, NULL); + Py_DECREF(m); + return r; } } """, @@ -4968,10 +4973,10 @@ impl = """ raise_noneattr_error_utility_code = UtilityCode( proto = """ -static INLINE void __Pyx_RaiseNoneAttributeError(char* attrname); +static INLINE void __Pyx_RaiseNoneAttributeError(const char* attrname); """, impl = """ -static INLINE void __Pyx_RaiseNoneAttributeError(char* attrname) { +static INLINE void __Pyx_RaiseNoneAttributeError(const char* attrname) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", attrname); } """) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 36c8b020..e2866249 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -1448,7 +1448,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): flags = "READONLY" else: flags = "0" - code.putln('{"%s", %s, %s, %s, 0},' % ( + code.putln('{(char *)"%s", %s, %s, %s, 0},' % ( entry.name, type_code, "offsetof(%s, %s)" % (objstruct, entry.cname), @@ -1466,7 +1466,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): env.getset_table_cname) for entry in env.property_entries: code.putln( - '{"%s", %s, %s, %s, 0},' % ( + '{(char *)"%s", %s, %s, %s, 0},' % ( entry.name, entry.getter_cname or "0", entry.setter_cname or "0", @@ -2050,10 +2050,10 @@ bad: function_export_utility_code = UtilityCode( proto = """ -static int __Pyx_ExportFunction(char *name, void *f, char *sig); /*proto*/ +static int __Pyx_ExportFunction(const char *name, void *f, const char *sig); /*proto*/ """, impl = r""" -static int __Pyx_ExportFunction(char *name, void *f, char *sig) { +static int __Pyx_ExportFunction(const char *name, void *f, const char *sig) { PyObject *d = 0; PyObject *p = 0; d = PyObject_GetAttrString(%(MODULE)s, "%(API)s"); @@ -2066,7 +2066,7 @@ static int __Pyx_ExportFunction(char *name, void *f, char *sig) { if (PyModule_AddObject(%(MODULE)s, "%(API)s", d) < 0) goto bad; } - p = PyCObject_FromVoidPtrAndDesc(f, sig, 0); + p = PyCObject_FromVoidPtrAndDesc(f, (void *)sig, 0); if (!p) goto bad; if (PyDict_SetItemString(d, name, p) < 0) @@ -2085,16 +2085,16 @@ bad: function_import_utility_code = UtilityCode( proto = """ -static int __Pyx_ImportFunction(PyObject *module, char *funcname, void **f, char *sig); /*proto*/ +static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void **f, const char *sig); /*proto*/ """, impl = """ #ifndef __PYX_HAVE_RT_ImportFunction #define __PYX_HAVE_RT_ImportFunction -static int __Pyx_ImportFunction(PyObject *module, char *funcname, void **f, char *sig) { +static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void **f, const char *sig) { PyObject *d = 0; PyObject *cobj = 0; char *desc; - + d = PyObject_GetAttrString(module, "%(API)s"); if (!d) goto bad; diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 5c985202..e82ae755 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -4493,7 +4493,7 @@ static PyObject* %s = 0; impl = r""" #if PY_MAJOR_VERSION < 3 static PyObject *__Pyx_GetStdout(void) { - PyObject *f = PySys_GetObject("stdout"); + PyObject *f = PySys_GetObject((char *)"stdout"); if (!f) { PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); } @@ -4504,7 +4504,7 @@ static int __Pyx_Print(PyObject *arg_tuple, int newline) { PyObject *f; PyObject* v; int i; - + if (!(f = __Pyx_GetStdout())) return -1; for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {