diff --git a/CHANGES.current b/CHANGES.current index 759a7eea6..f7c649632 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.2 (in progress) =========================== +2011-02-18: wsfulton + Fix #3184549 - vararg functions and function overloading when using the -fastdispatch option. + 2011-02-18: olly [PHP] An overloaded method which can return an object or a primitive type no longer causes SWIG to segfault. Reported by Paul diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index ce221b4ff..65f18c002 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -430,6 +430,7 @@ CPP_TEST_CASES += \ valuewrapper_const \ valuewrapper_opaque \ varargs \ + varargs_overload \ virtual_destructor \ virtual_poly \ voidtest \ diff --git a/Examples/test-suite/python/varargs_overload_runme.py b/Examples/test-suite/python/varargs_overload_runme.py new file mode 100644 index 000000000..583de8eef --- /dev/null +++ b/Examples/test-suite/python/varargs_overload_runme.py @@ -0,0 +1,22 @@ +import varargs_overload + +if varargs_overload.vararg_over1("Hello") != "Hello": + raise RuntimeError, "Failed" + +if varargs_overload.vararg_over1(2) != "2": + raise RuntimeError, "Failed" + + +if varargs_overload.vararg_over2("Hello") != "Hello": + raise RuntimeError, "Failed" + +if varargs_overload.vararg_over2(2, 2.2) != "2 2.2": + raise RuntimeError, "Failed" + + +if varargs_overload.vararg_over3("Hello") != "Hello": + raise RuntimeError, "Failed" + +if varargs_overload.vararg_over3(2, 2.2, "hey") != "2 2.2 hey": + raise RuntimeError, "Failed" + diff --git a/Examples/test-suite/varargs_overload.i b/Examples/test-suite/varargs_overload.i new file mode 100644 index 000000000..e916da9d3 --- /dev/null +++ b/Examples/test-suite/varargs_overload.i @@ -0,0 +1,32 @@ +// Tests SWIG's *default* handling of overloading varargs (function varargs, not preprocessor varargs). +// The default behavior is to simply ignore the varargs. +%module varargs_overload + +%inline %{ +const char *vararg_over1(const char *fmt, ...) { + return fmt; +} +const char *vararg_over1(int i) { + static char buffer[256]; + sprintf(buffer, "%d", i); + return buffer; +} + +const char *vararg_over2(const char *fmt, ...) { + return fmt; +} +const char *vararg_over2(int i, double j) { + static char buffer[256]; + sprintf(buffer, "%d %g", i, j); + return buffer; +} + +const char *vararg_over3(const char *fmt, ...) { + return fmt; +} +const char *vararg_over3(int i, double j, const char *s) { + static char buffer[256]; + sprintf(buffer, "%d %g %s", i, j, s); + return buffer; +} +%} diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx index a62bdc1bf..bf4bcd797 100644 --- a/Source/Modules/overload.cxx +++ b/Source/Modules/overload.cxx @@ -386,16 +386,11 @@ String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int * int num_arguments = emit_num_arguments(pi); if (num_arguments > *maxargs) *maxargs = num_arguments; - int varargs = emit_isvarargs(pi); - if (!varargs) { - if (num_required == num_arguments) { - Printf(f, "if (%s == %d) {\n", argc_template_string, num_required); - } else { - Printf(f, "if ((%s >= %d) && (%s <= %d)) {\n", argc_template_string, num_required, argc_template_string, num_arguments); - } + if (num_required == num_arguments) { + Printf(f, "if (%s == %d) {\n", argc_template_string, num_required); } else { - Printf(f, "if (%s >= %d) {\n", argc_template_string, num_required); + Printf(f, "if ((%s >= %d) && (%s <= %d)) {\n", argc_template_string, num_required, argc_template_string, num_arguments); } Printf(f, "SWIG_TypeRank _ranki = 0;\n"); Printf(f, "SWIG_TypeRank _rankm = 0;\n"); @@ -565,16 +560,11 @@ String *Swig_overload_dispatch_fast(Node *n, const_String_or_char_ptr fmt, int * int num_arguments = emit_num_arguments(pi); if (num_arguments > *maxargs) *maxargs = num_arguments; - int varargs = emit_isvarargs(pi); - if (!varargs) { - if (num_required == num_arguments) { - Printf(f, "if (%s == %d) {\n", argc_template_string, num_required); - } else { - Printf(f, "if ((%s >= %d) && (%s <= %d)) {\n", argc_template_string, num_required, argc_template_string, num_arguments); - } + if (num_required == num_arguments) { + Printf(f, "if (%s == %d) {\n", argc_template_string, num_required); } else { - Printf(f, "if (%s >= %d) {\n", argc_template_string, num_required); + Printf(f, "if ((%s >= %d) && (%s <= %d)) {\n", argc_template_string, num_required, argc_template_string, num_arguments); } /* create a list with the wrappers that collide with the @@ -732,16 +722,11 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar } if (num_arguments > *maxargs) *maxargs = num_arguments; - int varargs = emit_isvarargs(pi); - if (!varargs) { - if (num_required == num_arguments) { - Printf(f, "if (%s == %d) {\n", argc_template_string, num_required); - } else { - Printf(f, "if ((%s >= %d) && (%s <= %d)) {\n", argc_template_string, num_required, argc_template_string, num_arguments); - } + if (num_required == num_arguments) { + Printf(f, "if (%s == %d) {\n", argc_template_string, num_required); } else { - Printf(f, "if (%s >= %d) {\n", argc_template_string, num_required); + Printf(f, "if ((%s >= %d) && (%s <= %d)) {\n", argc_template_string, num_required, argc_template_string, num_arguments); } if (num_arguments) {