Python builtin - warning suppression/fixes for 'gcc -Wall' and cosmetic changes in generated code.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12609 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2011-04-05 20:39:44 +00:00
parent 5f6389ab31
commit b2b9e2eb91
4 changed files with 59 additions and 24 deletions

View File

@ -12,7 +12,7 @@
%inline %{ %inline %{
template <typename ImageT> int convolve1() { return 0; } template <typename ImageT> int convolve1() { return 0; }
template <typename ImageT> void convolve1(ImageT a) { ImageT t = a; } template <typename ImageT> void convolve1(ImageT a) { ImageT t = a; (void)t; }
%} %}
%template() convolve1<float>; %template() convolve1<float>;
@ -24,7 +24,7 @@ template <typename ImageT> void convolve1(ImageT a) { ImageT t = a; }
%inline %{ %inline %{
template <typename ImageT> int convolve2() { return 0; } template <typename ImageT> int convolve2() { return 0; }
template <typename ImageT> void convolve2(ImageT a) { ImageT t = a; } template <typename ImageT> void convolve2(ImageT a) { ImageT t = a; (void)t; }
%} %}
%template(convolve2Float) convolve2<float>; %template(convolve2Float) convolve2<float>;
@ -34,7 +34,7 @@ template <typename ImageT> void convolve2(ImageT a) { ImageT t = a; }
%inline %{ %inline %{
template <typename ImageT> int convolve3() { return 0; } template <typename ImageT> int convolve3() { return 0; }
template <typename ImageT> void convolve3(ImageT a) { ImageT t = a; } template <typename ImageT> void convolve3(ImageT a) { ImageT t = a; (void)t; }
%} %}
%template() convolve3<float>; %template() convolve3<float>;
@ -44,7 +44,7 @@ template <typename ImageT> void convolve3(ImageT a) { ImageT t = a; }
%inline %{ %inline %{
template <typename ImageT> int convolve4() { return 0; } template <typename ImageT> int convolve4() { return 0; }
template <typename ImageT> void convolve4(ImageT a) { ImageT t = a; } template <typename ImageT> void convolve4(ImageT a) { ImageT t = a; (void)t; }
%} %}
%template(convolve4Float) convolve4<float>; %template(convolve4Float) convolve4<float>;
@ -56,7 +56,7 @@ template <typename ImageT> void convolve4(ImageT a) { ImageT t = a; }
%inline %{ %inline %{
template <typename ImageT> int convolve5() { return 0; } template <typename ImageT> int convolve5() { return 0; }
template <typename ImageT> void convolve5(ImageT a) { ImageT t = a; } template <typename ImageT> void convolve5(ImageT a) { ImageT t = a; (void)t; }
%} %}
%template() convolve5<float>; %template() convolve5<float>;

View File

@ -338,6 +338,26 @@ SWIGINTERN PyTypeObject SwigPyStaticVar_Type = {
0, /* tp_dict */ 0, /* tp_dict */
(descrgetfunc)SwigPyStaticVar_get, /* tp_descr_get */ (descrgetfunc)SwigPyStaticVar_get, /* tp_descr_get */
(descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */ (descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
#if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */
#endif
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version */
#endif
#ifdef COUNT_ALLOCS
0,0,0,0 /* tp_alloc -> tp_next */
#endif
}; };
SWIGINTERN int SWIGINTERN int

View File

@ -344,9 +344,14 @@ SWIG_init(void) {
swig_type_info *builtin_basetype = 0; swig_type_info *builtin_basetype = 0;
PyObject *tuple = NULL; PyObject *tuple = NULL;
PyGetSetDescrObject *static_getset = NULL; PyGetSetDescrObject *static_getset = NULL;
int i; int i;
(void)builtin_pytype;
(void)builtin_base_count;
(void)builtin_basetype;
(void)tuple;
(void)static_getset;
/* metatype is used to implement static member variables. */ /* metatype is used to implement static member variables. */
PyObject *metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type); PyObject *metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type);
assert(metatype_args); assert(metatype_args);
@ -391,6 +396,7 @@ SWIG_init(void) {
(char *)"this", SwigPyBuiltin_ThisClosure, NULL, NULL, NULL (char *)"this", SwigPyBuiltin_ThisClosure, NULL, NULL, NULL
}; };
PyObject *this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); PyObject *this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def);
(void)this_descr;
/* All objects have a 'thisown' attribute */ /* All objects have a 'thisown' attribute */
static SwigPyGetSet thisown_getset_closure = { static SwigPyGetSet thisown_getset_closure = {
@ -401,9 +407,12 @@ SWIG_init(void) {
(char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure
}; };
PyObject *thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); PyObject *thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def);
(void)thisown_descr;
PyObject *public_interface = PyList_New(0); PyObject *public_interface = PyList_New(0);
PyObject *public_symbol = 0; PyObject *public_symbol = 0;
(void)public_symbol;
PyDict_SetItemString(md, "__all__", public_interface); PyDict_SetItemString(md, "__all__", public_interface);
Py_DECREF(public_interface); Py_DECREF(public_interface);
for (i = 0; SwigMethods[i].ml_name != NULL; ++i) for (i = 0; SwigMethods[i].ml_name != NULL; ++i)

View File

@ -63,6 +63,7 @@ static int modern = 0;
static int new_repr = 1; static int new_repr = 1;
static int no_header_file = 0; static int no_header_file = 0;
static int max_bases = 0; static int max_bases = 0;
static int builtin_bases_needed = 0;
static int py3 = 0; static int py3 = 0;
@ -996,7 +997,7 @@ public:
} }
Dump(f_wrappers, f_begin); Dump(f_wrappers, f_begin);
if (builtin) if (builtin && builtin_bases_needed)
Printf(f_begin, "static PyTypeObject *builtin_bases[%d];\n\n", max_bases + 2); Printf(f_begin, "static PyTypeObject *builtin_bases[%d];\n\n", max_bases + 2);
Wrapper_pretty_print(f_init, f_begin); Wrapper_pretty_print(f_init, f_begin);
@ -2806,8 +2807,10 @@ public:
int addfail = 0; int addfail = 0;
Printf(getf->def, "SWIGINTERN PyObject *%s(void) {", vargetname); Printf(getf->def, "SWIGINTERN PyObject *%s(void) {", vargetname);
Wrapper_add_local(getf, "pyobj", "PyObject *pyobj = 0"); Wrapper_add_local(getf, "pyobj", "PyObject *pyobj = 0");
if (builtin) if (builtin) {
Wrapper_add_local(getf, "self", "PyObject *self = 0"); Wrapper_add_local(getf, "self", "PyObject *self = 0");
Append(getf->code, " (void)self;\n");
}
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) { if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name); Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "pyobj"); Replaceall(tm, "$target", "pyobj");
@ -3116,7 +3119,7 @@ public:
if (shadow) { if (shadow) {
if (builtin) { if (builtin) {
String *rname = SwigType_namestr(real_classname); String *rname = SwigType_namestr(real_classname);
Printf(builtin_methods, tab4 "{ \"__disown__\", (PyCFunction) Swig::Director::swig_pyobj_disown< %s >, METH_NOARGS, \"\" },\n", rname); Printf(builtin_methods, " { \"__disown__\", (PyCFunction) Swig::Director::swig_pyobj_disown< %s >, METH_NOARGS, \"\" },\n", rname);
Delete(rname); Delete(rname);
} else { } else {
String *symname = Getattr(n, "sym:name"); String *symname = Getattr(n, "sym:name");
@ -3230,6 +3233,7 @@ public:
} }
Printv(f_init, " builtin_bases[builtin_base_count] = NULL;\n", NIL); Printv(f_init, " builtin_bases[builtin_base_count] = NULL;\n", NIL);
Printv(f_init, " SwigPyBuiltin_InitBases(builtin_pytype, builtin_bases);\n", NIL); Printv(f_init, " SwigPyBuiltin_InitBases(builtin_pytype, builtin_bases);\n", NIL);
builtin_bases_needed = 1;
// Check for non-public destructor, in which case tp_dealloc will issue // Check for non-public destructor, in which case tp_dealloc will issue
// a warning and allow the memory to leak. Any class that doesn't explicitly // a warning and allow the memory to leak. Any class that doesn't explicitly
@ -3275,7 +3279,7 @@ public:
Delete(gspair); Delete(gspair);
Delete(entry); Delete(entry);
} }
Printv(f, getset_def, " {NULL} /* Sentinel */\n", "};\n\n", NIL); Printv(f, getset_def, " {NULL, NULL, NULL, NULL, NULL} /* Sentinel */\n", "};\n\n", NIL);
// Rich compare function // Rich compare function
Hash *richcompare = Getattr(n, "python:richcompare"); Hash *richcompare = Getattr(n, "python:richcompare");
@ -3314,7 +3318,7 @@ public:
// Methods // Methods
Printf(f, "SWIGINTERN PyMethodDef %s_methods[] = {\n", templ); Printf(f, "SWIGINTERN PyMethodDef %s_methods[] = {\n", templ);
Dump(builtin_methods, f); Dump(builtin_methods, f);
Printf(f, " {NULL} // Sentinel\n};\n\n"); Printf(f, " { NULL, NULL, 0, NULL } /* Sentinel */\n};\n\n");
// No instance dict for nondynamic objects // No instance dict for nondynamic objects
if (GetFlag(n, "feature:python:nondynamic")) if (GetFlag(n, "feature:python:nondynamic"))
@ -3350,15 +3354,15 @@ public:
printSlot(f, getSlot(n, "feature:python:tp_compare"), "tp_compare", "cmpfunc"); printSlot(f, getSlot(n, "feature:python:tp_compare"), "tp_compare", "cmpfunc");
Printv(f, "#endif\n", NIL); Printv(f, "#endif\n", NIL);
printSlot(f, getSlot(n, "feature:python:tp_repr"), "tp_repr", "reprfunc"); printSlot(f, getSlot(n, "feature:python:tp_repr"), "tp_repr", "reprfunc");
Printf(f, " &%s_type.as_number, /*tp_as_number*/\n", templ); Printf(f, " &%s_type.as_number, /* tp_as_number */\n", templ);
Printf(f, " &%s_type.as_sequence, /*tp_as_sequence*/\n", templ); Printf(f, " &%s_type.as_sequence, /* tp_as_sequence */\n", templ);
Printf(f, " &%s_type.as_mapping, /*tp_as_mapping*/\n", templ); Printf(f, " &%s_type.as_mapping, /* tp_as_mapping */\n", templ);
printSlot(f, getSlot(n, "feature:python:tp_hash"), "tp_hash", "hashfunc"); printSlot(f, getSlot(n, "feature:python:tp_hash"), "tp_hash", "hashfunc");
printSlot(f, getSlot(n, "feature:python:tp_call"), "tp_call", "ternaryfunc"); printSlot(f, getSlot(n, "feature:python:tp_call"), "tp_call", "ternaryfunc");
printSlot(f, getSlot(n, "feature:python:tp_str"), "tp_str", "reprfunc"); printSlot(f, getSlot(n, "feature:python:tp_str"), "tp_str", "reprfunc");
printSlot(f, getSlot(n, "feature:python:tp_getattro"), "tp_getattro", "getattrofunc"); printSlot(f, getSlot(n, "feature:python:tp_getattro"), "tp_getattro", "getattrofunc");
printSlot(f, getSlot(n, "feature:python:tp_setattro"), "tp_setattro", "setattrofunc"); printSlot(f, getSlot(n, "feature:python:tp_setattro"), "tp_setattro", "setattrofunc");
Printf(f, " &%s_type.as_buffer, /*tp_as_buffer*/\n", templ); Printf(f, " &%s_type.as_buffer, /* tp_as_buffer */\n", templ);
Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL);
printSlot(f, py3_tp_flags, "tp_flags"); printSlot(f, py3_tp_flags, "tp_flags");
Printv(f, "#else\n", NIL); Printv(f, "#else\n", NIL);
@ -3373,7 +3377,7 @@ public:
printSlot(f, getSlot(n, "feature:python:tp_iternext"), "tp_iternext", "iternextfunc"); printSlot(f, getSlot(n, "feature:python:tp_iternext"), "tp_iternext", "iternextfunc");
printSlot(f, methods_name, "tp_methods"); printSlot(f, methods_name, "tp_methods");
printSlot(f, getSlot(n, "feature:python:tp_members"), "tp_members"); printSlot(f, getSlot(n, "feature:python:tp_members"), "tp_members");
printSlot(f, getset_name, " tp_getset"); printSlot(f, getset_name, "tp_getset");
printSlot(f, getSlot(n, "feature:python:tp_base"), "tp_base"); printSlot(f, getSlot(n, "feature:python:tp_base"), "tp_base");
printSlot(f, getSlot(n, "feature:python:tp_dict"), "tp_dict"); printSlot(f, getSlot(n, "feature:python:tp_dict"), "tp_dict");
printSlot(f, getSlot(n, "feature:python:tp_descr_get"), "tp_descr_get", "descrgetfunc"); printSlot(f, getSlot(n, "feature:python:tp_descr_get"), "tp_descr_get", "descrgetfunc");
@ -3446,7 +3450,7 @@ public:
Printf(f, " {\n"); Printf(f, " {\n");
printSlot(f, getSlot(n, "feature:python:mp_length"), "mp_length", "lenfunc"); printSlot(f, getSlot(n, "feature:python:mp_length"), "mp_length", "lenfunc");
printSlot(f, getSlot(n, "feature:python:mp_subscript"), "mp_subscript", "binaryfunc"); printSlot(f, getSlot(n, "feature:python:mp_subscript"), "mp_subscript", "binaryfunc");
printSlot(f, getSlot(n, "feature:python:mp_ass_subscript"), " mp_ass_subscript", "objobjargproc"); printSlot(f, getSlot(n, "feature:python:mp_ass_subscript"), "mp_ass_subscript", "objobjargproc");
Printf(f, " },\n"); Printf(f, " },\n");
// PySequenceMethods as_sequence; // PySequenceMethods as_sequence;
@ -3889,13 +3893,13 @@ public:
int argcount = Getattr(n, "python:argcount") ? atoi(Char(Getattr(n, "python:argcount"))) : 2; int argcount = Getattr(n, "python:argcount") ? atoi(Char(Getattr(n, "python:argcount"))) : 2;
String *ds = have_docstring(n) ? cdocstring(n, AUTODOC_FUNC) : NewString(""); String *ds = have_docstring(n) ? cdocstring(n, AUTODOC_FUNC) : NewString("");
if (check_kwargs(n)) { if (check_kwargs(n)) {
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS|METH_KEYWORDS, (char*) \"%s\" },\n", symname, wname, ds); Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS|METH_KEYWORDS, (char*) \"%s\" },\n", symname, wname, ds);
} else if (argcount == 0) { } else if (argcount == 0) {
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_NOARGS, (char*) \"%s\" },\n", symname, wname, ds); Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_NOARGS, (char*) \"%s\" },\n", symname, wname, ds);
} else if (argcount == 1) { } else if (argcount == 1) {
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_O, (char*) \"%s\" },\n", symname, wname, ds); Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_O, (char*) \"%s\" },\n", symname, wname, ds);
} else { } else {
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS, (char*) \"%s\" },\n", symname, wname, ds); Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS, (char*) \"%s\" },\n", symname, wname, ds);
} }
Delete(fullname); Delete(fullname);
Delete(wname); Delete(wname);
@ -3995,10 +3999,10 @@ public:
Append(pyflags, "METH_VARARGS"); Append(pyflags, "METH_VARARGS");
if (have_docstring(n)) { if (have_docstring(n)) {
String *ds = cdocstring(n, AUTODOC_STATICFUNC); String *ds = cdocstring(n, AUTODOC_STATICFUNC);
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, %s, (char*) \"%s\" },\n", symname, wname, pyflags, ds); Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, %s, (char*) \"%s\" },\n", symname, wname, pyflags, ds);
Delete(ds); Delete(ds);
} else { } else {
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", symname, wname, pyflags); Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", symname, wname, pyflags);
} }
Delete(fullname); Delete(fullname);
Delete(wname); Delete(wname);
@ -4599,8 +4603,10 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
} }
} }
if (builtin) if (builtin) {
Printv(w->code, "PyObject *self = NULL;\n", NIL); Printv(w->code, "PyObject *self = NULL;\n", NIL);
Printv(w->code, "(void)self;\n", NIL);
}
if (ignored_method) { if (ignored_method) {
if (!pure_virtual) { if (!pure_virtual) {