Commit e7d1eb15 authored by Lisandro Dalcin's avatar Lisandro Dalcin

make GCC happy when string literals and const char* pointers are passed to...

make GCC happy when string literals and const char* pointers are passed to many C-API calls or set in struct slots for Python 2.3/2.4
parent d95405ff
...@@ -235,22 +235,22 @@ proto = """ ...@@ -235,22 +235,22 @@ proto = """
PySequence_Contains((anyset), (key)) PySequence_Contains((anyset), (key))
#define PySet_Pop(set) \\ #define PySet_Pop(set) \\
PyObject_CallMethod(set, "pop", NULL) PyObject_CallMethod(set, (char *)"pop", NULL)
static INLINE int PySet_Clear(PyObject *set) { static INLINE int PySet_Clear(PyObject *set) {
PyObject *ret = PyObject_CallMethod(set, "clear", NULL); PyObject *ret = PyObject_CallMethod(set, (char *)"clear", NULL);
if (!ret) return -1; if (!ret) return -1;
Py_DECREF(ret); return 0; Py_DECREF(ret); return 0;
} }
static INLINE int PySet_Discard(PyObject *set, PyObject *key) { static INLINE int PySet_Discard(PyObject *set, PyObject *key) {
PyObject *ret = PyObject_CallMethod(set, "discard", "O", key); PyObject *ret = PyObject_CallMethod(set, (char *)"discard", (char *)"O", key);
if (!ret) return -1; if (!ret) return -1;
Py_DECREF(ret); return 0; Py_DECREF(ret); return 0;
} }
static INLINE int PySet_Add(PyObject *set, PyObject *key) { static INLINE int PySet_Add(PyObject *set, PyObject *key) {
PyObject *ret = PyObject_CallMethod(set, "add", "O", key); PyObject *ret = PyObject_CallMethod(set, (char *)"add", (char *)"O", key);
if (!ret) return -1; if (!ret) return -1;
Py_DECREF(ret); return 0; Py_DECREF(ret); return 0;
} }
...@@ -277,11 +277,11 @@ static PyTypeObject *__Pyx_PyFrozenSet_Type = NULL; ...@@ -277,11 +277,11 @@ static PyTypeObject *__Pyx_PyFrozenSet_Type = NULL;
static int __Pyx_Py23SetsImport(void) { static int __Pyx_Py23SetsImport(void) {
PyObject *sets=0, *Set=0, *ImmutableSet=0; PyObject *sets=0, *Set=0, *ImmutableSet=0;
sets = PyImport_ImportModule("sets"); sets = PyImport_ImportModule((char *)"sets");
if (!sets) goto bad; if (!sets) goto bad;
Set = PyObject_GetAttrString(sets, "Set"); Set = PyObject_GetAttrString(sets, (char *)"Set");
if (!Set) goto bad; if (!Set) goto bad;
ImmutableSet = PyObject_GetAttrString(sets, "ImmutableSet"); ImmutableSet = PyObject_GetAttrString(sets, (char *)"ImmutableSet");
if (!ImmutableSet) goto bad; if (!ImmutableSet) goto bad;
Py_DECREF(sets); Py_DECREF(sets);
......
...@@ -805,7 +805,7 @@ class CCodeWriter(object): ...@@ -805,7 +805,7 @@ class CCodeWriter(object):
if entry.is_special: if entry.is_special:
method_flags += [method_coexist] method_flags += [method_coexist]
self.putln( self.putln(
'{"%s", (PyCFunction)%s, %s, %s}%s' % ( '{__Pyx_NAMESTR("%s"), (PyCFunction)%s, %s, __Pyx_DOCSTR(%s)}%s' % (
entry.name, entry.name,
entry.func_cname, entry.func_cname,
"|".join(method_flags), "|".join(method_flags),
......
...@@ -1369,7 +1369,7 @@ class NameNode(AtomicExprNode): ...@@ -1369,7 +1369,7 @@ class NameNode(AtomicExprNode):
error(self.pos, "Deletion of local or C global name not supported") error(self.pos, "Deletion of local or C global name not supported")
return return
code.put_error_if_neg(self.pos, code.put_error_if_neg(self.pos,
'PyObject_DelAttrString(%s, "%s")' % ( '__Pyx_DelAttrString(%s, "%s")' % (
Naming.module_cname, Naming.module_cname,
self.entry.name)) self.entry.name))
...@@ -5106,7 +5106,7 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) { ...@@ -5106,7 +5106,7 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
PyObject *global_dict = 0; PyObject *global_dict = 0;
PyObject *empty_dict = 0; PyObject *empty_dict = 0;
PyObject *list; PyObject *list;
__import__ = PyObject_GetAttrString(%(BUILTINS)s, "__import__"); __import__ = __Pyx_GetAttrString(%(BUILTINS)s, "__import__");
if (!__import__) if (!__import__)
goto bad; goto bad;
if (from_list) if (from_list)
...@@ -5309,7 +5309,7 @@ static INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { ...@@ -5309,7 +5309,7 @@ static INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
} }
else { else {
PyObject *r, *m; PyObject *r, *m;
m = PyObject_GetAttrString(L, "append"); m = __Pyx_GetAttrString(L, "append");
if (!m) return NULL; if (!m) return NULL;
r = PyObject_CallFunctionObjArgs(m, x, NULL); r = PyObject_CallFunctionObjArgs(m, x, NULL);
Py_DECREF(m); Py_DECREF(m);
......
...@@ -509,6 +509,24 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -509,6 +509,24 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln(" #define _USE_MATH_DEFINES") code.putln(" #define _USE_MATH_DEFINES")
code.putln("#endif") code.putln("#endif")
code.putln("#if PY_VERSION_HEX < 0x02050000")
code.putln(" #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n)))")
code.putln(" #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))")
code.putln(" #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n)))")
code.putln("#else")
code.putln(" #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n))")
code.putln(" #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))")
code.putln(" #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n))")
code.putln("#endif")
code.putln("#if PY_VERSION_HEX < 0x02050000")
code.putln(" #define __Pyx_NAMESTR(n) ((char *)(n))")
code.putln(" #define __Pyx_DOCSTR(n) ((char *)(n))")
code.putln("#else")
code.putln(" #define __Pyx_NAMESTR(n) (n)")
code.putln(" #define __Pyx_DOCSTR(n) (n)")
code.putln("#endif")
self.generate_extern_c_macro_definition(code) self.generate_extern_c_macro_definition(code)
code.putln("#include <math.h>") code.putln("#include <math.h>")
code.putln("#define %s" % Naming.api_guard_prefix + self.api_name(env)) code.putln("#define %s" % Naming.api_guard_prefix + self.api_name(env))
...@@ -1410,7 +1428,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1410,7 +1428,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln( code.putln(
"PyVarObject_HEAD_INIT(0, 0)") "PyVarObject_HEAD_INIT(0, 0)")
code.putln( code.putln(
'"%s.%s", /*tp_name*/' % ( '__Pyx_NAMESTR("%s.%s"), /*tp_name*/' % (
self.full_module_name, scope.class_name)) self.full_module_name, scope.class_name))
if type.typedef_flag: if type.typedef_flag:
objstruct = type.objstruct_cname objstruct = type.objstruct_cname
...@@ -1702,7 +1720,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1702,7 +1720,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
doc = "0" doc = "0"
code.putln("#if PY_MAJOR_VERSION < 3") code.putln("#if PY_MAJOR_VERSION < 3")
code.putln( code.putln(
'%s = Py_InitModule4("%s", %s, %s, 0, PYTHON_API_VERSION);' % ( '%s = Py_InitModule4(__Pyx_NAMESTR("%s"), %s, %s, 0, PYTHON_API_VERSION);' % (
env.module_cname, env.module_cname,
env.module_name, env.module_name,
env.method_table_cname, env.method_table_cname,
...@@ -1723,20 +1741,20 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1723,20 +1741,20 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
env.module_cname) env.module_cname)
code.putln("#endif") code.putln("#endif")
code.putln( code.putln(
'%s = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME);' % '%s = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));' %
Naming.builtins_cname) Naming.builtins_cname)
code.putln( code.putln(
"if (!%s) %s;" % ( "if (!%s) %s;" % (
Naming.builtins_cname, Naming.builtins_cname,
code.error_goto(self.pos))); code.error_goto(self.pos)));
code.putln( code.putln(
'if (PyObject_SetAttrString(%s, "__builtins__", %s) < 0) %s;' % ( 'if (__Pyx_SetAttrString(%s, "__builtins__", %s) < 0) %s;' % (
env.module_cname, env.module_cname,
Naming.builtins_cname, Naming.builtins_cname,
code.error_goto(self.pos))) code.error_goto(self.pos)))
if Options.pre_import is not None: if Options.pre_import is not None:
code.putln( code.putln(
'%s = PyImport_AddModule("%s");' % ( '%s = PyImport_AddModule(__Pyx_NAMESTR("%s"));' % (
Naming.preimport_cname, Naming.preimport_cname,
Options.pre_import)) Options.pre_import))
code.putln( code.putln(
...@@ -1893,7 +1911,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1893,7 +1911,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.error_goto(entry.pos))) code.error_goto(entry.pos)))
env.use_utility_code(Nodes.set_vtable_utility_code) env.use_utility_code(Nodes.set_vtable_utility_code)
code.putln( code.putln(
'if (PyObject_SetAttrString(%s, "%s", (PyObject *)&%s) < 0) %s' % ( 'if (__Pyx_SetAttrString(%s, "%s", (PyObject *)&%s) < 0) %s' % (
Naming.module_cname, Naming.module_cname,
scope.class_name, scope.class_name,
typeobj_cname, typeobj_cname,
...@@ -2063,16 +2081,22 @@ static int __Pyx_ExportFunction(const char *name, void *f, const char *sig); /*p ...@@ -2063,16 +2081,22 @@ static int __Pyx_ExportFunction(const char *name, void *f, const char *sig); /*p
""", """,
impl = r""" impl = r"""
static int __Pyx_ExportFunction(const char *name, void *f, const char *sig) { static int __Pyx_ExportFunction(const char *name, void *f, const char *sig) {
#if PY_VERSION_HEX < 0x02050000
char *api = (char *)"%(API)s";
#else
const char *api = "%(API)s";
#endif
PyObject *d = 0; PyObject *d = 0;
PyObject *p = 0; PyObject *p = 0;
d = PyObject_GetAttrString(%(MODULE)s, "%(API)s");
d = PyObject_GetAttrString(%(MODULE)s, api);
if (!d) { if (!d) {
PyErr_Clear(); PyErr_Clear();
d = PyDict_New(); d = PyDict_New();
if (!d) if (!d)
goto bad; goto bad;
Py_INCREF(d); Py_INCREF(d);
if (PyModule_AddObject(%(MODULE)s, "%(API)s", d) < 0) if (PyModule_AddObject(%(MODULE)s, api, d) < 0)
goto bad; goto bad;
} }
p = PyCObject_FromVoidPtrAndDesc(f, (void *)sig, 0); p = PyCObject_FromVoidPtrAndDesc(f, (void *)sig, 0);
...@@ -2100,11 +2124,16 @@ impl = """ ...@@ -2100,11 +2124,16 @@ impl = """
#ifndef __PYX_HAVE_RT_ImportFunction #ifndef __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction #define __PYX_HAVE_RT_ImportFunction
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void **f, const char *sig) { static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void **f, const char *sig) {
#if PY_VERSION_HEX < 0x02050000
char *api = (char *)"%(API)s";
#else
const char *api = "%(API)s";
#endif
PyObject *d = 0; PyObject *d = 0;
PyObject *cobj = 0; PyObject *cobj = 0;
char *desc; char *desc;
d = PyObject_GetAttrString(module, "%(API)s"); d = PyObject_GetAttrString(module, api);
if (!d) if (!d)
goto bad; goto bad;
cobj = PyDict_GetItemString(d, funcname); cobj = PyDict_GetItemString(d, funcname);
...@@ -2138,7 +2167,7 @@ register_cleanup_utility_code = UtilityCode( ...@@ -2138,7 +2167,7 @@ register_cleanup_utility_code = UtilityCode(
proto = """ proto = """
static int __Pyx_RegisterCleanup(void); /*proto*/ static int __Pyx_RegisterCleanup(void); /*proto*/
static PyObject* __pyx_module_cleanup(PyObject *self, PyObject *unused); /*proto*/ static PyObject* __pyx_module_cleanup(PyObject *self, PyObject *unused); /*proto*/
static PyMethodDef cleanup_def = {"__cleanup", (PyCFunction)&__pyx_module_cleanup, METH_NOARGS, 0}; static PyMethodDef cleanup_def = {__Pyx_NAMESTR("__cleanup"), (PyCFunction)&__pyx_module_cleanup, METH_NOARGS, 0};
""", """,
impl = """ impl = """
static int __Pyx_RegisterCleanup(void) { static int __Pyx_RegisterCleanup(void) {
...@@ -2163,7 +2192,7 @@ static int __Pyx_RegisterCleanup(void) { ...@@ -2163,7 +2192,7 @@ static int __Pyx_RegisterCleanup(void) {
atexit = __Pyx_ImportModule("atexit"); atexit = __Pyx_ImportModule("atexit");
if (!atexit) if (!atexit)
goto bad; goto bad;
reg = PyObject_GetAttrString(atexit, "register"); reg = __Pyx_GetAttrString(atexit, "register");
if (!reg) if (!reg)
goto bad; goto bad;
res = PyObject_CallObject(reg, args); res = PyObject_CallObject(reg, args);
...@@ -2187,7 +2216,7 @@ import_star_utility_code = """ ...@@ -2187,7 +2216,7 @@ import_star_utility_code = """
static int static int
__Pyx_import_all_from(PyObject *locals, PyObject *v) __Pyx_import_all_from(PyObject *locals, PyObject *v)
{ {
PyObject *all = PyObject_GetAttrString(v, "__all__"); PyObject *all = __Pyx_GetAttrString(v, "__all__");
PyObject *dict, *name, *value; PyObject *dict, *name, *value;
int skip_leading_underscores = 0; int skip_leading_underscores = 0;
int pos, err; int pos, err;
...@@ -2196,7 +2225,7 @@ __Pyx_import_all_from(PyObject *locals, PyObject *v) ...@@ -2196,7 +2225,7 @@ __Pyx_import_all_from(PyObject *locals, PyObject *v)
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) if (!PyErr_ExceptionMatches(PyExc_AttributeError))
return -1; /* Unexpected error */ return -1; /* Unexpected error */
PyErr_Clear(); PyErr_Clear();
dict = PyObject_GetAttrString(v, "__dict__"); dict = __Pyx_GetAttrString(v, "__dict__");
if (dict == NULL) { if (dict == NULL) {
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) if (!PyErr_ExceptionMatches(PyExc_AttributeError))
return -1; return -1;
......
...@@ -861,7 +861,7 @@ class CEnumDefNode(StatNode): ...@@ -861,7 +861,7 @@ class CEnumDefNode(StatNode):
self.temp, self.temp,
item.cname, item.cname,
code.error_goto_if_null(self.temp, item.pos))) code.error_goto_if_null(self.temp, item.pos)))
code.putln('if (PyObject_SetAttrString(%s, "%s", %s) < 0) %s' % ( code.putln('if (__Pyx_SetAttrString(%s, "%s", %s) < 0) %s' % (
Naming.module_cname, Naming.module_cname,
item.name, item.name,
self.temp, self.temp,
...@@ -4641,7 +4641,7 @@ static int __Pyx_Print(PyObject *arg_tuple, int newline) { ...@@ -4641,7 +4641,7 @@ static int __Pyx_Print(PyObject *arg_tuple, int newline) {
PyObject* result = 0; PyObject* result = 0;
PyObject* end_string; PyObject* end_string;
if (!%(PRINT_FUNCTION)s) { if (!%(PRINT_FUNCTION)s) {
%(PRINT_FUNCTION)s = PyObject_GetAttrString(%(BUILTINS)s, "print"); %(PRINT_FUNCTION)s = __Pyx_GetAttrString(%(BUILTINS)s, "print");
if (!%(PRINT_FUNCTION)s) if (!%(PRINT_FUNCTION)s)
return -1; return -1;
} }
......
...@@ -314,7 +314,7 @@ class DocStringSlot(SlotDescriptor): ...@@ -314,7 +314,7 @@ class DocStringSlot(SlotDescriptor):
doc = scope.doc.utf8encode() doc = scope.doc.utf8encode()
else: else:
doc = scope.doc.byteencode() doc = scope.doc.byteencode()
return '"%s"' % StringEncoding.escape_byte_string(doc) return '__Pyx_DOCSTR("%s")' % StringEncoding.escape_byte_string(doc)
else: else:
return "0" return "0"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment