diff --git a/Examples/test-suite/extend_template_method.i b/Examples/test-suite/extend_template_method.i index e1253606a..1ba6de80a 100644 --- a/Examples/test-suite/extend_template_method.i +++ b/Examples/test-suite/extend_template_method.i @@ -3,6 +3,7 @@ %include %inline %{ +namespace Space { class ExtendMe { public: template @@ -10,9 +11,10 @@ public: return b; } }; +} %} -%extend ExtendMe { +%extend Space::ExtendMe { template T do_stuff(int a, T b) { return $self->do_stuff_impl(a, b, 4.0); @@ -21,15 +23,19 @@ public: T do_overloaded_stuff(T b) { return $self->do_stuff_impl(0, b, 4.0); } + template + static T static_method(T t) { return t; } } -%template(do_stuff_double) ExtendMe::do_stuff; -%template(do_stuff_string) ExtendMe::do_stuff; +%template(do_stuff_double) Space::ExtendMe::do_stuff; +%template(do_stuff_string) Space::ExtendMe::do_stuff; -%template(do_overloaded_stuff) ExtendMe::do_overloaded_stuff; -%template(do_overloaded_stuff) ExtendMe::do_overloaded_stuff; +%template(do_overloaded_stuff) Space::ExtendMe::do_overloaded_stuff; +%template(do_overloaded_stuff) Space::ExtendMe::do_overloaded_stuff; +%template(static_method) Space::ExtendMe::static_method; %inline %{ +namespace Space { template class TemplateExtendMe { public: @@ -38,9 +44,10 @@ public: return b; } }; +} %} -%extend TemplateExtendMe { +%extend Space::TemplateExtendMe { template T do_template_stuff(int a, T b) { return $self->template_stuff_impl(a, b, 4.0); @@ -49,6 +56,8 @@ public: T do_template_overloaded_stuff(T b) { return $self->template_stuff_impl(0, b, 4.0); } + template + static T static_template_method(T t) { return t; } %template(do_template_stuff_double) do_template_stuff; %template(do_template_stuff_string) do_template_stuff; @@ -56,7 +65,8 @@ public: %template(do_template_overloaded_stuff) do_template_overloaded_stuff; %template(do_template_overloaded_stuff) do_template_overloaded_stuff; +%template(static_template_method) static_template_method; } -%template(TemplateExtend) TemplateExtendMe; +%template(TemplateExtend) Space::TemplateExtendMe; diff --git a/Examples/test-suite/java/extend_template_method_runme.java b/Examples/test-suite/java/extend_template_method_runme.java index cf21cd7b1..d6cdc88df 100644 --- a/Examples/test-suite/java/extend_template_method_runme.java +++ b/Examples/test-suite/java/extend_template_method_runme.java @@ -32,6 +32,8 @@ public class extend_template_method_runme { if (!ret_string.equals("hello there")) throw new RuntimeException("string failed " + ret_string); } + if (ExtendMe.static_method(123) != 123) + throw new RuntimeException("static_method failed"); } { TemplateExtend em = new TemplateExtend(); @@ -52,6 +54,8 @@ public class extend_template_method_runme { if (!ret_string.equals("hello there")) throw new RuntimeException("string failed " + ret_string); } + if (TemplateExtend.static_template_method(123) != 123) + throw new RuntimeException("static_template_method failed"); } } } diff --git a/Examples/test-suite/python/extend_template_method_runme.py b/Examples/test-suite/python/extend_template_method_runme.py index eb7a6d654..32bd7b070 100644 --- a/Examples/test-suite/python/extend_template_method_runme.py +++ b/Examples/test-suite/python/extend_template_method_runme.py @@ -17,6 +17,8 @@ ret_string = em.do_overloaded_stuff("hello there") if ret_string != "hello there": raise RuntimeError("string failed " + ret_string) +if ExtendMe.static_method(123) != 123: + raise RuntimeError("static_method failed"); em = TemplateExtend() @@ -34,3 +36,6 @@ if ret_double != 1.1: ret_string = em.do_template_overloaded_stuff("hello there") if ret_string != "hello there": raise RuntimeError("string failed " + ret_string) + +if TemplateExtend.static_template_method(123) != 123: + raise RuntimeError("static_template_method failed"); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index ab4fa2b9e..07077e446 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1145,7 +1145,9 @@ int Language::globalfunctionHandler(Node *n) { Delete(cbname); } Setattr(n, "parms", nonvoid_parms(parms)); - String *call = Swig_cfunction_call(name, parms); + + String *extendname = Getattr(n, "extendname"); + String *call = Swig_cfunction_call(extendname ? extendname : name, parms); String *cres = Swig_cresult(type, Swig_cresult_name(), call); Setattr(n, "wrap:action", cres); Delete(cres); @@ -1322,7 +1324,10 @@ int Language::staticmemberfunctionHandler(Node *n) { if (!defaultargs && code) { /* Hmmm. An added static member. We have to create a little wrapper for this */ - Swig_add_extension_code(n, cname, parms, type, code, CPlusPlus, 0); + String *mangled_cname = Swig_name_mangle(cname); + Swig_add_extension_code(n, mangled_cname, parms, type, code, CPlusPlus, 0); + Setattr(n, "extendname", mangled_cname); + Delete(mangled_cname); } }