summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Turner <jason@emptycrate.com>2014-05-31 14:35:10 -0600
committerOliver Buchtala <oliver.buchtala@gmail.com>2014-06-06 18:24:22 +0200
commitfa36b6228e760e19928a9cccff71114ea46f932b (patch)
tree5822066ba01d54e1d049dd6174bf5d2ddc460232
parentef4cb2f57465025203961a484fd8f7a0a8c9faa7 (diff)
downloadswig-fa36b6228e760e19928a9cccff71114ea46f932b.tar.gz
Fix function naming conflict with class overloads.
This fix takes into account the classname while generating overload handlers. Example: If you have two classes: class A { public: void doSomething(int); void doSomething(double); }; class B { public: void doSomething(int); void doSomething(double); }; Before this patch, the overload handlers for A::doSomething and B::doSomething create conflicting names and function redefinition errors are caused. After the patch, the overload handlers are named classname_doSomething and no longer conflict. This is might not the best way to implement this, but it solves a critical problem on large projects, and specifically can affect operator overloads that are being wrapped.
-rw-r--r--Source/Modules/javascript.cxx15
1 files changed, 12 insertions, 3 deletions
diff --git a/Source/Modules/javascript.cxx b/Source/Modules/javascript.cxx
index 8b7a74037..0c3f02a75 100644
--- a/Source/Modules/javascript.cxx
+++ b/Source/Modules/javascript.cxx
@@ -1231,18 +1231,27 @@ int JSEmitter::emitFunctionDispatcher(Node *n, bool /*is_member */ ) {
// substract the extension "sym:overname",
String *wrap_name = NewString(Getattr(n, "wrap:name"));
String *overname = Getattr(n, "sym:overname");
+
+ Node *methodclass = Swig_methodclass(n);
+ String *class_name = Getattr(methodclass, "sym:name");
+
int l1 = Len(wrap_name);
int l2 = Len(overname);
Delslice(wrap_name, l1 - l2, l1);
- Setattr(n, "wrap:name", wrap_name);
- state.function(WRAPPER_NAME, wrap_name);
+ String *new_string = NewStringf("%s_%s", class_name, wrap_name);
+ String *final_wrap_name = Swig_name_wrapper(new_string);
+
+ Setattr(n, "wrap:name", final_wrap_name);
+ state.function(WRAPPER_NAME, final_wrap_name);
+
+
t_function.replace("$jslocals", wrapper->locals)
.replace("$jscode", wrapper->code);
// call this here, to replace all variables
- t_function.replace("$jswrapper", wrap_name)
+ t_function.replace("$jswrapper", final_wrap_name)
.replace("$jsname", state.function(NAME))
.pretty_print(f_wrappers);