Fix #3184549 - vararg functions and function overloading when using the -fastdispatch option.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12474 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
049e51c282
commit
873d07d1e5
5 changed files with 67 additions and 24 deletions
|
|
@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
Version 2.0.2 (in progress)
|
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
|
2011-02-18: olly
|
||||||
[PHP] An overloaded method which can return an object or a
|
[PHP] An overloaded method which can return an object or a
|
||||||
primitive type no longer causes SWIG to segfault. Reported by Paul
|
primitive type no longer causes SWIG to segfault. Reported by Paul
|
||||||
|
|
|
||||||
|
|
@ -430,6 +430,7 @@ CPP_TEST_CASES += \
|
||||||
valuewrapper_const \
|
valuewrapper_const \
|
||||||
valuewrapper_opaque \
|
valuewrapper_opaque \
|
||||||
varargs \
|
varargs \
|
||||||
|
varargs_overload \
|
||||||
virtual_destructor \
|
virtual_destructor \
|
||||||
virtual_poly \
|
virtual_poly \
|
||||||
voidtest \
|
voidtest \
|
||||||
|
|
|
||||||
22
Examples/test-suite/python/varargs_overload_runme.py
Normal file
22
Examples/test-suite/python/varargs_overload_runme.py
Normal file
|
|
@ -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"
|
||||||
|
|
||||||
32
Examples/test-suite/varargs_overload.i
Normal file
32
Examples/test-suite/varargs_overload.i
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
@ -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);
|
int num_arguments = emit_num_arguments(pi);
|
||||||
if (num_arguments > *maxargs)
|
if (num_arguments > *maxargs)
|
||||||
*maxargs = num_arguments;
|
*maxargs = num_arguments;
|
||||||
int varargs = emit_isvarargs(pi);
|
|
||||||
|
|
||||||
if (!varargs) {
|
if (num_required == num_arguments) {
|
||||||
if (num_required == num_arguments) {
|
Printf(f, "if (%s == %d) {\n", argc_template_string, num_required);
|
||||||
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);
|
|
||||||
}
|
|
||||||
} else {
|
} 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 _ranki = 0;\n");
|
||||||
Printf(f, "SWIG_TypeRank _rankm = 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);
|
int num_arguments = emit_num_arguments(pi);
|
||||||
if (num_arguments > *maxargs)
|
if (num_arguments > *maxargs)
|
||||||
*maxargs = num_arguments;
|
*maxargs = num_arguments;
|
||||||
int varargs = emit_isvarargs(pi);
|
|
||||||
|
|
||||||
if (!varargs) {
|
if (num_required == num_arguments) {
|
||||||
if (num_required == num_arguments) {
|
Printf(f, "if (%s == %d) {\n", argc_template_string, num_required);
|
||||||
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);
|
|
||||||
}
|
|
||||||
} else {
|
} 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
|
/* 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)
|
if (num_arguments > *maxargs)
|
||||||
*maxargs = num_arguments;
|
*maxargs = num_arguments;
|
||||||
int varargs = emit_isvarargs(pi);
|
|
||||||
|
|
||||||
if (!varargs) {
|
if (num_required == num_arguments) {
|
||||||
if (num_required == num_arguments) {
|
Printf(f, "if (%s == %d) {\n", argc_template_string, num_required);
|
||||||
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);
|
|
||||||
}
|
|
||||||
} else {
|
} 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) {
|
if (num_arguments) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue