diff --git a/Examples/test-suite/default_args.i b/Examples/test-suite/default_args.i index 579d1592e..b08d51749 100644 --- a/Examples/test-suite/default_args.i +++ b/Examples/test-suite/default_args.i @@ -74,7 +74,9 @@ // Rename a class member %rename(bar2) Foo::bar; -%rename(newname) Foo::oldname; +%rename(newname) Foo::oldname(int x); +%ignore Foo::Foo(int x, int y = 0, int z = 0); + %inline %{ // Define a class @@ -83,6 +85,10 @@ static int bar; static int spam; + Foo(){} + + Foo(int x, int y = 0, int z = 0){} + // Use a renamed member as a default argument. SWIG has to resolve // bar to Foo::bar and not Foo::spam. SWIG-1.3.11 got this wrong. // (Different default parameter wrapping in SWIG-1.3.23 ensures SWIG doesn't have to resolve these symbols). diff --git a/Examples/test-suite/python/default_args_runme.py b/Examples/test-suite/python/default_args_runme.py index 6844e03bb..ad3adc1d2 100644 --- a/Examples/test-suite/python/default_args_runme.py +++ b/Examples/test-suite/python/default_args_runme.py @@ -14,4 +14,30 @@ if default_args.cfunc3(1) != 4: raise RuntimeError +f = default_args.Foo() + +f.newname() +f.newname(1) + + +try: + f = default_args.Foo(1) + error = 1 +except: + error = 0 +if error: raise RuntimeError,"ignore is not working" + +try: + f = default_args.Foo(1,2) + error = 1 +except: + error = 0 +if error: raise RuntimeError,"ignore is not working" + +try: + f = default_args.Foo(1,2,3) + error = 1 +except: + error = 0 +if error: raise RuntimeError,"ignore is not working" diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index aa9117526..f3397a283 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1088,12 +1088,7 @@ static int is_cfunction(Node *n) { * The additional functions form a linked list of nodes with the head being the original Node n. */ static void default_arguments(Node *n) { Node *function = n; -#ifdef MARCELO - String *fname = 0; - String *oname = 0; - SwigType *fdecl = 0; - int ignore = 0; -#endif + SwigType *fdecl = Getattr(function,"decl"); /* Do not add in functions if kwargs is being used or if user wants old default argument wrapping (one wrapped method per function irrespective of number of default arguments) */ @@ -1109,20 +1104,17 @@ static void default_arguments(Node *n) { } } -#ifdef MARCELO - if (function) { - fdecl = Getattr(function,"decl"); - /* try to see if we need to ignore this method */ - fname = Getattr(function,"name"); - oname = make_name(fname,fdecl); - if (strncmp(Char(oname),"$ignore",7) == 0) { - ignore = 1; - } - } -#endif - while (function) { ParmList *parms = Getattr(function,"parms"); + + /* try to see if we need to ignore this method */ + int ignore = 0; + String *oname = make_name(Getattr(function,"name"), fdecl); + if (strncmp(Char(oname),"$ignore",7) == 0) { + ignore = 1; + oname = 0; + } + if (ParmList_has_defaultargs(parms)) { /* Create a parameter list for the new function by copying all @@ -1132,11 +1124,7 @@ static void default_arguments(Node *n) { /* Create new function and add to symbol table */ { Node *new_function = new_node(Copy(nodeType(function))); -#ifdef MARCELO - SwigType *decl = Copy(fdecl); -#else SwigType *decl = Copy(Getattr(function,"decl")); -#endif int constqualifier = SwigType_isconst(decl); Delete(SwigType_pop_function(decl)); /* remove the old parameter list from decl */ @@ -1144,11 +1132,7 @@ static void default_arguments(Node *n) { if (constqualifier) SwigType_add_qualifier(decl,"const"); -#ifdef MARCELO - Setattr(new_function,"name",fname); -#else Setattr(new_function,"name",Getattr(function,"name")); -#endif Setattr(new_function,"code",Copy(Getattr(function,"code"))); Setattr(new_function,"decl", decl); Setattr(new_function,"parms",newparms); @@ -1171,13 +1155,12 @@ static void default_arguments(Node *n) { if (templateparms) Setattr(new_function,"templateparms",CopyParmList(templateparms)); } -#ifdef MARCELO - /* apply the original function features */ - Swig_features_get(Swig_cparse_features(),Namespaceprefix,fname,fdecl,new_function); if (ignore) Setattr(new_function,"feature:ignore","1"); -#endif - add_symbols(new_function); + yyrename = oname; + add_symbols(new_function); + yyrename = 0; + /* mark added functions as ones with overloaded parameters and point to the parsed method */ Setattr(new_function,"defaultargs", n);