From 60525e800d5ddcdbd41a859b23c9c7271b3d3a30 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 3 Jan 2013 14:09:14 -0600 Subject: [PATCH 01/11] Added a test case for SourceForge Bug #1283. This test case exercise directors used in conjunction with smart pointers. --- Examples/test-suite/common.mk | 1 + Examples/test-suite/director_smartptr.i | 63 +++++++++++++++++++ .../java/director_smartptr_runme.java | 48 ++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 Examples/test-suite/director_smartptr.i create mode 100644 Examples/test-suite/java/director_smartptr_runme.java diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 0c790caf6..1cda06140 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -185,6 +185,7 @@ CPP_TEST_CASES += \ director_protected \ director_protected_overloaded \ director_redefined \ + director_smartptr \ director_thread \ director_unroll \ director_using \ diff --git a/Examples/test-suite/director_smartptr.i b/Examples/test-suite/director_smartptr.i new file mode 100644 index 000000000..0d78c2775 --- /dev/null +++ b/Examples/test-suite/director_smartptr.i @@ -0,0 +1,63 @@ +%module(directors="1") director_smartptr + +#ifdef SWIGJAVA +SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) +SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE) +#endif + +%{ +#include +#include + +class FooBar { +public: + FooBar() {} + FooBar(const FooBar&) {} + virtual ~FooBar() {} + + std::string FooBarDo() { return "Bar::Foo2::Foo2Bar()"; } +}; + +class Foo { +public: + virtual ~Foo() {} + virtual std::string ping() { return "Foo::ping()"; } + virtual std::string pong() { return "Foo::pong();" + ping(); } + virtual std::string fooBar(FooBar* fooBarPtr) { return fooBarPtr->FooBarDo(); } + virtual Foo makeFoo() { return Foo(); } + virtual FooBar makeFooBar() { return FooBar(); } + + static Foo* get_self(Foo *self_) {return self_;} +}; + +%} + +%include +%include + +%shared_ptr(Foo) + +%feature("director") Foo; + +class FooBar { +public: + FooBar(); + FooBar(const FooBar&); + virtual ~FooBar(); + + std::string FooBarDo(); + +}; + +class Foo +{ +public: + virtual ~Foo(); + virtual std::string ping(); + virtual std::string pong(); + virtual std::string fooBar(FooBar* fooBarPtr); + virtual Foo makeFoo(); + virtual FooBar makeFooBar(); + + static Foo* get_self(Foo *self_); +}; \ No newline at end of file diff --git a/Examples/test-suite/java/director_smartptr_runme.java b/Examples/test-suite/java/director_smartptr_runme.java new file mode 100644 index 000000000..8c4ddc5d3 --- /dev/null +++ b/Examples/test-suite/java/director_smartptr_runme.java @@ -0,0 +1,48 @@ +// Make sure that directors are connected and disconnected when used inconjunction with +// being a smart pointer + +public class director_smartptr_runme { + + static { + try { + System.loadLibrary("director_smartptr"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + director_smartptr_MyBarFoo myBarFoo = + new director_smartptr_MyBarFoo(); + } + +} + +class director_smartptr_MyBarFoo extends director_smartptr.Foo { + + @Override + public String ping() { + return "director_smartptr_MyBarFoo.ping();"; + } + + @Override + public String pong() { + return "director_smartptr_MyBarFoo.pong();" + ping(); + } + + @Override + public String fooBar(director_smartptr.FooBar fooBar) { + return fooBar.FooBarDo(); + } + + @Override + public director_smartptr.Foo makeFoo() { + return new director_smartptr.Foo(); + } + + @Override + public director_smartptr.FooBar makeFooBar() { + return new director_smartptr.FooBar(); + } +} \ No newline at end of file From 3e70da14c96072618a58a169a4ccb2f7d799d98e Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 3 Jan 2013 14:54:06 -0600 Subject: [PATCH 02/11] Fix for SourceForge Bug #1283. * Change the name of the memory own variable for base java director classes to match that expected by the director code * Add conditional to appropriately dynamically cast director classes wrapped in smart pointers. --- Lib/java/boost_shared_ptr.i | 8 ++++---- Source/Modules/java.cxx | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Lib/java/boost_shared_ptr.i b/Lib/java/boost_shared_ptr.i index 31d7efdf9..e75236993 100644 --- a/Lib/java/boost_shared_ptr.i +++ b/Lib/java/boost_shared_ptr.i @@ -146,10 +146,10 @@ // Base proxy classes %typemap(javabody) TYPE %{ private long swigCPtr; - private boolean swigCMemOwnBase; + private boolean swigCMemOwn; PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { - swigCMemOwnBase = cMemoryOwn; + swigCMemOwn = cMemoryOwn; swigCPtr = cPtr; } @@ -176,8 +176,8 @@ %typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE { if (swigCPtr != 0) { - if (swigCMemOwnBase) { - swigCMemOwnBase = false; + if (swigCMemOwn) { + swigCMemOwn = false; $jnicall; } swigCPtr = 0; diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index cd8cfe543..1f7fa29ce 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3381,6 +3381,7 @@ public: String *swig_director_connect = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); String *swig_director_connect_jni = makeValidJniName(swig_director_connect); String *sym_name = Getattr(n, "sym:name"); + String *smartptr_feature = Getattr(n, "feature:smartptr"); Wrapper *code_wrap; Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean mem_own, boolean weak_global);\n", @@ -3390,9 +3391,24 @@ public: Printf(code_wrap->def, "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jswig_mem_own, " "jboolean jweak_global) {\n", jnipackage, jni_imclass_name, swig_director_connect_jni); - Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); - Printf(code_wrap->code, " (void)jcls;\n"); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); + + if (Len(smartptr_feature)) { + Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", smartptr_feature, smartptr_feature); + Printf(code_wrap->code, " (void)jcls;\n"); + Printf(code_wrap->code, " // NOTE: Pulling the raw pointer out of the smart pointer as the following code does\n"); + Printf(code_wrap->code, " // is generally a bad idea. However, in this case we keep a local instance of the\n"); + Printf(code_wrap->code, " // smart pointer around while we are using the raw pointer, which should keep the\n"); + Printf(code_wrap->code, " // raw pointer alive. This is done instead of using the smart pointer's dynamic cast\n"); + Printf(code_wrap->code, " // feature since different smart pointer implementations have differently named dynamic\n"); + Printf(code_wrap->code, " // cast mechanisms.\n"); + Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast< SwigDirector_%s *>(obj->operator->());\n", sym_name, sym_name); + } + else { + Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); + Printf(code_wrap->code, " (void)jcls;\n"); + Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); + } + Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_connect_director(jenv, jself, jenv->GetObjectClass(jself), " "(jswig_mem_own == JNI_TRUE), (jweak_global == JNI_TRUE));\n"); From f6ce5f089f2f782a0987876737c47c7adb69ab3f Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 3 Jan 2013 21:26:08 -0600 Subject: [PATCH 03/11] Qualify generated SwigDirector class names with namespaces --- Source/Modules/directors.cxx | 9 ++++--- Source/Modules/java.cxx | 50 +++++++++++++----------------------- Source/Modules/lang.cxx | 20 ++++++++++++++- Source/Modules/swigmod.h | 2 ++ Source/Swig/cwrap.c | 12 +++++++-- 5 files changed, 55 insertions(+), 38 deletions(-) diff --git a/Source/Modules/directors.cxx b/Source/Modules/directors.cxx index 7f4c8d9d1..5d88b6306 100644 --- a/Source/Modules/directors.cxx +++ b/Source/Modules/directors.cxx @@ -78,9 +78,10 @@ String *Swig_class_name(Node *n) { String *Swig_director_declaration(Node *n) { String *classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); + String *directorname = Language::instance()->directorClassName(n); String *base = Getattr(n, "classtype"); String *declaration = Swig_class_declaration(n, directorname); + Printf(declaration, " : public %s, public Swig::Director {\n", base); Delete(classname); Delete(directorname); @@ -281,8 +282,10 @@ void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f) { && !Equal(nodeType(n), "constructor"))) { Node *parent = Getattr(n, "parentNode"); String *symname = Getattr(parent, "sym:name"); - String *dirname = NewStringf("SwigDirector_%s", symname); - String *dirdecl = NewStringf("%s *darg = 0", dirname); + String *dirname; + String *dirdecl; + dirname = Language::instance()->directorClassName(parent); + dirdecl = NewStringf("%s *darg = 0", dirname); Wrapper_add_local(f, "darg", dirdecl); Printf(f->code, "darg = dynamic_cast<%s *>(arg1);\n", dirname); Delete(dirname); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 1f7fa29ce..c642387dc 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -204,24 +204,6 @@ public: return valid_jni_name; } - /* ----------------------------------------------------------------------------- - * directorClassName() - * ----------------------------------------------------------------------------- */ - - String *directorClassName(Node *n) { - String *dirclassname; - const char *attrib = "director:classname"; - - if (!(dirclassname = Getattr(n, attrib))) { - String *classname = Getattr(n, "sym:name"); - - dirclassname = NewStringf("SwigDirector_%s", classname); - Setattr(n, attrib, dirclassname); - } - - return dirclassname; - } - /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ @@ -2008,7 +1990,7 @@ public: Printf(dcast_wrap->code, " jobject jresult = (jobject) 0;\n"); Printf(dcast_wrap->code, " %s *obj = *((%s **)&jCPtrBase);\n", norm_name, norm_name); Printf(dcast_wrap->code, " if (obj) director = dynamic_cast(obj);\n"); - Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self(jenv);\n"); + Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self);\n"); Printf(dcast_wrap->code, " return jresult;\n"); Printf(dcast_wrap->code, "}\n"); @@ -3380,8 +3362,8 @@ public: String *norm_name = SwigType_namestr(Getattr(n, "name")); String *swig_director_connect = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); String *swig_director_connect_jni = makeValidJniName(swig_director_connect); - String *sym_name = Getattr(n, "sym:name"); String *smartptr_feature = Getattr(n, "feature:smartptr"); + String *dirClassName = directorClassName(n); Wrapper *code_wrap; Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean mem_own, boolean weak_global);\n", @@ -3401,12 +3383,12 @@ public: Printf(code_wrap->code, " // raw pointer alive. This is done instead of using the smart pointer's dynamic cast\n"); Printf(code_wrap->code, " // feature since different smart pointer implementations have differently named dynamic\n"); Printf(code_wrap->code, " // cast mechanisms.\n"); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast< SwigDirector_%s *>(obj->operator->());\n", sym_name, sym_name); + Printf(code_wrap->code, " %s *director = dynamic_cast< %s *>(obj->operator->());\n", dirClassName, dirClassName); } else { Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); Printf(code_wrap->code, " (void)jcls;\n"); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); } Printf(code_wrap->code, " if (director) {\n"); @@ -3432,7 +3414,7 @@ public: "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jtake_or_release) {\n", jnipackage, jni_imclass_name, changeown_jnimethod_name); Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); Printf(code_wrap->code, " (void)jcls;\n"); Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_java_change_ownership(jenv, jself, jtake_or_release ? true : false);\n"); @@ -3445,6 +3427,7 @@ public: Delete(changeown_method_name); Delete(changeown_jnimethod_name); Delete(norm_name); + Delete(dirClassName); Delete(jni_imclass_name); } @@ -3583,7 +3566,7 @@ public: // we're consistent with the sym:overload name in functionWrapper. (?? when // does the overloaded method name get set?) - imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), classname, overloaded_name)); + imclass_dmethod = NewStringf("%s", Swig_name_member(getNSpace(), dirclassname, overloaded_name)); qualified_return = SwigType_rcaststr(returntype, "c_result"); @@ -4182,16 +4165,18 @@ public: int classDirectorDefaultConstructor(Node *n) { String *classname = Swig_class_name(n); String *classtype = SwigType_namestr(Getattr(n, "name")); + String *dirClassName = directorClassName(n); Wrapper *w = NewWrapper(); - Printf(w->def, "SwigDirector_%s::SwigDirector_%s(JNIEnv *jenv) : %s {", classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "%s::%s(JNIEnv *jenv) : %s {", dirClassName, dirClassName, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); - Printf(f_directors_h, " SwigDirector_%s(JNIEnv *jenv);\n", classname); + Printf(f_directors_h, " %s(JNIEnv *jenv);\n", dirClassName); DelWrapper(w); Delete(classtype); Delete(classname); + Delete(dirClassName); directorPrefixArgs(n); return Language::classDirectorDefaultConstructor(n); } @@ -4228,14 +4213,15 @@ public: Node *current_class = getCurrentClass(); String *full_classname = Getattr(current_class, "name"); String *classname = Swig_class_name(current_class); + String *dirClassName = directorClassName(current_class); Wrapper *w = NewWrapper(); if (Getattr(n, "throw")) { - Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s() throw ();\n", dirClassName); + Printf(w->def, "%s::~%s() throw () {\n", dirClassName, dirClassName); } else { - Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s();\n", dirClassName); + Printf(w->def, "%s::~%s() {\n", dirClassName, dirClassName); } /* Ensure that correct directordisconnect typemap's method name is called @@ -4254,6 +4240,7 @@ public: DelWrapper(w); Delete(disconn_attr); Delete(classname); + Delete(dirClassName); return SWIG_OK; } @@ -4395,8 +4382,7 @@ public: String *base = Getattr(n, "classtype"); String *class_ctor = NewString("Swig::Director(jenv)"); - String *classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); + String *directorname = directorClassName(n); String *declaration = Swig_class_declaration(n, directorname); Printf(declaration, " : public %s, public Swig::Director", base); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 8e5a91dbe..410945592 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -347,6 +347,24 @@ Language::~Language() { this_ = 0; } + /* ----------------------------------------------------------------------------- + * directorClassName() + * ----------------------------------------------------------------------------- */ + + String *Language::directorClassName(Node *n) { + String *dirclassname; + String *nspace = Getattr(n, "sym:nspace"); + const char *attrib = "director:classname"; + String *classname = Getattr(n, "sym:name"); + + Replace(nspace, ".", "_", DOH_REPLACE_ANY); + dirclassname = NewStringf("SwigDirector_%s_%s", nspace, classname); + Setattr(n, attrib, dirclassname); + + Delete(nspace); + return dirclassname; + } + /* ---------------------------------------------------------------------- emit_one() ---------------------------------------------------------------------- */ @@ -2405,7 +2423,7 @@ int Language::classDeclaration(Node *n) { } if (dir) { - DirectorClassName = NewStringf("SwigDirector_%s", symname); + DirectorClassName = directorClassName(n); classDirector(n); } /* check for abstract after resolving directors */ diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 4a65444fc..b3722af40 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -120,6 +120,8 @@ public: virtual ~Language(); virtual int emit_one(Node *n); + String *directorClassName(Node *n); + /* Parse command line options */ virtual void main(int argc, char *argv[]); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 063ab9858..d47f072e7 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -855,6 +855,9 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas String *self = 0; int is_smart_pointer_overload = 0; String *qualifier = Getattr(n, "qualifier"); + String *directorScope = NewString(nspace); + + Replace(directorScope, ".", "_", DOH_REPLACE_ANY); /* If smart pointer without const overload or mutable method, change self dereferencing */ if (flags & CWRAP_SMART_POINTER) { @@ -937,7 +940,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas /* If protected access (can only be if a director method) then call the extra public accessor method (language module must provide this) */ String *explicit_qualifier_tmp = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname")); explicitcall_name = NewStringf("%sSwigPublic", name); - explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp); + explicit_qualifier = NewStringf("SwigDirector_%s_%s", directorScope, explicit_qualifier_tmp); Delete(explicit_qualifier_tmp); } else { explicit_qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname")); @@ -1057,6 +1060,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas Delete(p); Delete(self); Delete(parms); + Delete(directorScope); return SWIG_OK; } @@ -1107,6 +1111,9 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String ParmList *directorparms; SwigType *type; int use_director; + String *directorScope = NewString(nspace); + + Replace(directorScope, ".", "_", DOH_REPLACE_ANY); use_director = Swig_directorclass(n); @@ -1167,7 +1174,7 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String Node *parent = Swig_methodclass(n); int abstract = Getattr(parent, "abstracts") != 0; String *name = Getattr(parent, "sym:name"); - String *directorname = NewStringf("SwigDirector_%s", name); + String *directorname = NewStringf("SwigDirector_%s_%s", directorScope, name); String *action = NewStringEmpty(); String *tmp_none_comparison = Copy(none_comparison); String *director_call; @@ -1233,6 +1240,7 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String if (directorparms != parms) Delete(directorparms); Delete(parms); + Delete(directorScope); return SWIG_OK; } From 00c71edbedc8412c90daec57a59936b79acd626c Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 3 Jan 2013 23:09:29 -0600 Subject: [PATCH 04/11] Change test to reflect new director class naming convention. --- Examples/test-suite/java_director_assumeoverride.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/java_director_assumeoverride.i b/Examples/test-suite/java_director_assumeoverride.i index 7364a3d58..310a20e0c 100644 --- a/Examples/test-suite/java_director_assumeoverride.i +++ b/Examples/test-suite/java_director_assumeoverride.i @@ -10,7 +10,7 @@ public: #include "java_director_assumeoverride_wrap.h" bool isFuncOverridden(OverrideMe* f) { - SwigDirector_OverrideMe* director = dynamic_cast(f); + SwigDirector__OverrideMe* director = dynamic_cast(f); if (!director) { return false; } From 747b50e2d7f43c73214867c9821dccef786b3107 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 3 Jan 2013 23:10:28 -0600 Subject: [PATCH 05/11] Clean up fix for SourceForge Bug #1299. --- Source/Modules/directors.cxx | 1 - Source/Modules/lang.cxx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Modules/directors.cxx b/Source/Modules/directors.cxx index 5d88b6306..4b23a52bb 100644 --- a/Source/Modules/directors.cxx +++ b/Source/Modules/directors.cxx @@ -281,7 +281,6 @@ void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f) { checkAttribute(n, "storage", "static")) && !Equal(nodeType(n), "constructor"))) { Node *parent = Getattr(n, "parentNode"); - String *symname = Getattr(parent, "sym:name"); String *dirname; String *dirdecl; dirname = Language::instance()->directorClassName(parent); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 410945592..b7ce2c4a8 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -353,7 +353,7 @@ Language::~Language() { String *Language::directorClassName(Node *n) { String *dirclassname; - String *nspace = Getattr(n, "sym:nspace"); + String *nspace = NewString(Getattr(n, "sym:nspace")); const char *attrib = "director:classname"; String *classname = Getattr(n, "sym:name"); From c786781e9273f341183fe927c9061cc1979b2769 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 5 Jan 2013 03:14:42 -0600 Subject: [PATCH 06/11] Add test case for SourceForge Bug #1299 --- Examples/test-suite/common.mk | 1 + .../director_nspace_director_name_collision.i | 66 +++++++++++++++++++ Examples/test-suite/java/Makefile.in | 1 + 3 files changed, 68 insertions(+) create mode 100644 Examples/test-suite/director_nspace_director_name_collision.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 1cda06140..09112c316 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -178,6 +178,7 @@ CPP_TEST_CASES += \ director_keywords \ director_namespace_clash \ director_nspace \ + director_nspace_director_name_collision \ director_nested \ director_overload \ director_overload2 \ diff --git a/Examples/test-suite/director_nspace_director_name_collision.i b/Examples/test-suite/director_nspace_director_name_collision.i new file mode 100644 index 000000000..5ef2509f8 --- /dev/null +++ b/Examples/test-suite/director_nspace_director_name_collision.i @@ -0,0 +1,66 @@ +%module(directors="1") director_nspace_director_name_collision + +#ifdef SWIGJAVA +SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) +SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE) +#endif + +%{ +#include + +namespace TopLevel +{ + namespace A + { + class Foo { + public: + virtual ~Foo() {} + virtual std::string ping() { return "TopLevel::A::Foo::ping()"; } + }; + } + + namespace B + { + class Foo { + public: + virtual ~Foo() {} + virtual std::string ping() { return "TopLevel::B:Foo::ping()"; } + }; + } +} + +%} + +%include + +// nspace feature only supported by these languages +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) +%nspace TopLevel::A::Foo; +%nspace TopLevel::B::Foo; +#else +#warning nspace feature not yet supported in this target language +#endif + +%feature("director") TopLevel::A::Foo; +%feature("director") TopLevel::B::Foo; + +namespace TopLevel +{ + namespace A + { + class Foo { + public: + virtual ~Foo(); + virtual std::string ping(); + }; + } + + namespace B + { + class Foo { + public: + virtual ~Foo(); + virtual std::string ping(); + }; + } +} diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 0b3f7babb..f8da8e6cc 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -46,6 +46,7 @@ SWIGOPT += -package $(JAVA_PACKAGE) nspace.%: JAVA_PACKAGE = $*Package nspace_extend.%: JAVA_PACKAGE = $*Package director_nspace.%: JAVA_PACKAGE = $*Package +director_nspace_director_name_collision.%: JAVA_PACKAGE = $*Package # Rules for the different types of tests %.cpptest: From 3c12306b2146a00c27080d43f60e8e29d7b94cd9 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 5 Jan 2013 03:40:06 -0600 Subject: [PATCH 07/11] Remove extra underscore from generated director names to maintain prevent breaking languages that do not support nspace. --- Examples/test-suite/java_director_assumeoverride.i | 2 +- Source/Modules/lang.cxx | 5 ++++- Source/Swig/cwrap.c | 12 ++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/java_director_assumeoverride.i b/Examples/test-suite/java_director_assumeoverride.i index 310a20e0c..7364a3d58 100644 --- a/Examples/test-suite/java_director_assumeoverride.i +++ b/Examples/test-suite/java_director_assumeoverride.i @@ -10,7 +10,7 @@ public: #include "java_director_assumeoverride_wrap.h" bool isFuncOverridden(OverrideMe* f) { - SwigDirector__OverrideMe* director = dynamic_cast(f); + SwigDirector_OverrideMe* director = dynamic_cast(f); if (!director) { return false; } diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index b7ce2c4a8..7468774a3 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -358,7 +358,10 @@ Language::~Language() { String *classname = Getattr(n, "sym:name"); Replace(nspace, ".", "_", DOH_REPLACE_ANY); - dirclassname = NewStringf("SwigDirector_%s_%s", nspace, classname); + if (Len(nspace) > 0) + dirclassname = NewStringf("SwigDirector_%s_%s", nspace, classname); + else + dirclassname = NewStringf("SwigDirector_%s", classname); Setattr(n, attrib, dirclassname); Delete(nspace); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index d47f072e7..c4c4621a1 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -940,7 +940,10 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas /* If protected access (can only be if a director method) then call the extra public accessor method (language module must provide this) */ String *explicit_qualifier_tmp = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname")); explicitcall_name = NewStringf("%sSwigPublic", name); - explicit_qualifier = NewStringf("SwigDirector_%s_%s", directorScope, explicit_qualifier_tmp); + if (Len(directorScope) > 0) + explicit_qualifier = NewStringf("SwigDirector_%s_%s", directorScope, explicit_qualifier_tmp); + else + explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp); Delete(explicit_qualifier_tmp); } else { explicit_qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname")); @@ -1174,12 +1177,17 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String Node *parent = Swig_methodclass(n); int abstract = Getattr(parent, "abstracts") != 0; String *name = Getattr(parent, "sym:name"); - String *directorname = NewStringf("SwigDirector_%s_%s", directorScope, name); + String *directorname; String *action = NewStringEmpty(); String *tmp_none_comparison = Copy(none_comparison); String *director_call; String *nodirector_call; + if (Len(directorScope) > 0) + directorname = NewStringf("SwigDirector_%s_%s", directorScope, name); + else + directorname = NewStringf("SwigDirector_%s", name); + Replaceall(tmp_none_comparison, "$arg", "arg1"); director_call = Swig_cppconstructor_director_call(directorname, directorparms); From b005c68009b51f521f2d469eb557164cb657bc8f Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 5 Jan 2013 04:54:02 -0600 Subject: [PATCH 08/11] Patch for SourceForge Bug #1299 broke D and C#. Update D module to reflect these changes NOTE: There are several test failures in the D test suite, so it is difficult to be entirely sure this does not break something. --- Source/Modules/d.cxx | 71 +++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index b8e30d50c..b66f8d2be 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -1897,7 +1897,7 @@ public: // Write C++ director class declaration, for example: // class SwigDirector_myclass : public myclass, public Swig::Director { String *classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); + String *directorname = directorClassName(n); String *declaration = Swig_class_declaration(n, directorname); const String *base = Getattr(n, "classtype"); @@ -1949,7 +1949,7 @@ public: bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0"))); int status = SWIG_OK; bool output_director = true; - String *dirclassname = getDirectorClassName(parent); + String *dirclassname = directorClassName(parent); String *qualified_name = NewStringf("%s::%s", dirclassname, name); SwigType *c_ret_type = NULL; String *dcallback_call_args = NewString(""); @@ -2373,10 +2373,12 @@ public: Printf(director_callback_pointers, " SWIG_Callback%s_t swig_callback_%s;\n", methid, overloaded_name); // Write the type alias for the callback to the intermediary D module. - String* proxy_callback_type = NewString(""); - Printf(proxy_callback_type, "SwigDirector_%s_Callback%s", classname, methid); + String *proxy_callback_type = NewString(""); + String *dirClassName = directorClassName(parent); + Printf(proxy_callback_type, "%s_Callback%s", dirClassName, methid); Printf(im_dmodule_code, "alias extern(C) %s function(void*%s) %s;\n", proxy_callback_return_type, delegate_parms, proxy_callback_type); Delete(proxy_callback_type); + Delete(dirClassName); } Delete(qualified_return); @@ -2399,7 +2401,7 @@ public: Node *parent = parentNode(n); String *decl = Getattr(n, "decl");; String *supername = Swig_class_name(parent); - String *classname = getDirectorClassName(parent); + String *classname = directorClassName(parent); String *sub = NewString(""); Parm *p; ParmList *superparms = Getattr(n, "parms"); @@ -2454,15 +2456,15 @@ public: * D::classDirectorDefaultConstructor() * --------------------------------------------------------------------------- */ virtual int classDirectorDefaultConstructor(Node *n) { - String *classname = Swig_class_name(n); + String *classname = directorClassName(n); String *classtype = SwigType_namestr(Getattr(n, "name")); Wrapper *w = NewWrapper(); - Printf(w->def, "SwigDirector_%s::SwigDirector_%s() : %s {", classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "%s::%s() : %s {", classname, classname, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); - Printf(f_directors_h, " SwigDirector_%s();\n", classname); + Printf(f_directors_h, " %s();\n", classname); DelWrapper(w); Delete(classtype); Delete(classname); @@ -2474,15 +2476,15 @@ public: * --------------------------------------------------------------------------- */ virtual int classDirectorDestructor(Node *n) { Node *current_class = getCurrentClass(); - String *classname = Swig_class_name(current_class); + String *classname = directorClassName(current_class); Wrapper *w = NewWrapper(); if (Getattr(n, "throw")) { - Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s() throw ();\n", classname); + Printf(w->def, "%s::~%s() throw () {\n", classname, classname); } else { - Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s();\n", classname); + Printf(w->def, "%s::~%s() {\n", classname, classname); } Printv(w->code, "}\n", NIL); @@ -2499,7 +2501,7 @@ public: * --------------------------------------------------------------------------- */ virtual int classDirectorEnd(Node *n) { int i; - String *director_classname = getDirectorClassName(n); + String *director_classname = directorClassName(n); Wrapper *w = NewWrapper(); @@ -3308,7 +3310,7 @@ private: // If directors are enabled for the current class, generate the // director connect helper function which is called from the constructor // and write it to the class body. - writeDirectorConnectProxy(); + writeDirectorConnectProxy(n); } // Write all constants and enumerations first to prevent forward reference @@ -3475,12 +3477,15 @@ private: } /* --------------------------------------------------------------------------- - * D::writeDirectorConnectProxy() + * D::writeDirectorConnectProxy(Node *classNode) * * Writes the helper method which registers the director callbacks by calling * the director connect function from the D side to the proxy class. * --------------------------------------------------------------------------- */ - void writeDirectorConnectProxy() { + void writeDirectorConnectProxy(Node* classNode) { + String *dirClassName = directorClassName(classNode); + String *connect_name = Swig_name_member(getNSpace(), + proxy_class_name, "director_connect"); Printf(proxy_class_body_code, "\nprivate void swigDirectorConnect() {\n"); int i; @@ -3491,12 +3496,12 @@ private: String *return_type = Getattr(udata, "return_type"); String *param_list = Getattr(udata, "param_list"); String *methid = Getattr(udata, "class_methodidx"); - Printf(proxy_class_body_code, " %s.SwigDirector_%s_Callback%s callback%s;\n", im_dmodule_fq_name, proxy_class_name, methid, methid); + Printf(proxy_class_body_code, " %s.%s_Callback%s callback%s;\n", im_dmodule_fq_name, dirClassName, methid, methid); Printf(proxy_class_body_code, " if (swigIsMethodOverridden!(%s delegate(%s), %s function(%s), %s)()) {\n", return_type, param_list, return_type, param_list, method); Printf(proxy_class_body_code, " callback%s = &swigDirectorCallback_%s_%s;\n", methid, proxy_class_name, overloaded_name); Printf(proxy_class_body_code, " }\n\n"); } - Printf(proxy_class_body_code, " %s.%s_director_connect(cast(void*)swigCPtr, cast(void*)this", im_dmodule_fq_name, proxy_class_name); + Printf(proxy_class_body_code, " %s.%s(cast(void*)swigCPtr, cast(void*)this", im_dmodule_fq_name, connect_name); for (i = first_class_dmethod; i < curr_class_dmethod; ++i) { UpcallData *udata = Getitem(dmethods_seq, i); String *methid = Getattr(udata, "class_methodidx"); @@ -3532,6 +3537,8 @@ private: director_callback_pointers = NULL; Delete(director_dcallbacks_code); director_dcallbacks_code = NULL; + Delete(dirClassName); + Delete(connect_name); } /* --------------------------------------------------------------------------- @@ -3548,7 +3555,7 @@ private: String *norm_name = SwigType_namestr(Getattr(n, "name")); String *connect_name = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); - String *sym_name = Getattr(n, "sym:name"); + String *dirClassName = directorClassName(n); Wrapper *code_wrap; Printv(wrapper_loader_bind_code, wrapper_loader_bind_command, NIL); @@ -3561,7 +3568,7 @@ private: Printf(code_wrap->def, "SWIGEXPORT void D_%s(void *objarg, void *dobj", connect_name); Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_connect_director(dobj"); @@ -3570,9 +3577,9 @@ private: UpcallData *udata = Getitem(dmethods_seq, i); String *methid = Getattr(udata, "class_methodidx"); - Printf(code_wrap->def, ", SwigDirector_%s::SWIG_Callback%s_t callback%s", sym_name, methid, methid); + Printf(code_wrap->def, ", %s::SWIG_Callback%s_t callback%s", dirClassName, methid, methid); Printf(code_wrap->code, ", callback%s", methid); - Printf(im_dmodule_code, ", SwigDirector_%s_Callback%s callback%s", sym_name, methid, methid); + Printf(im_dmodule_code, ", %s_Callback%s callback%s", dirClassName, methid, methid); } Printf(code_wrap->def, ") {\n"); @@ -3585,6 +3592,7 @@ private: DelWrapper(code_wrap); Delete(connect_name); + Delete(dirClassName); } /* --------------------------------------------------------------------------- @@ -4298,23 +4306,6 @@ private: return proxyname; } - /* --------------------------------------------------------------------------- - * D::directorClassName() - * --------------------------------------------------------------------------- */ - String *getDirectorClassName(Node *n) const { - String *dirclassname; - const char *attrib = "director:classname"; - - if (!(dirclassname = Getattr(n, attrib))) { - String *classname = Getattr(n, "sym:name"); - - dirclassname = NewStringf("SwigDirector_%s", classname); - Setattr(n, attrib, dirclassname); - } - - return dirclassname; - } - /* --------------------------------------------------------------------------- * D::makeParameterName() * From c62cd63f713aeeda9dd938a3dc1311f8d2f14e06 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 5 Jan 2013 05:25:33 -0600 Subject: [PATCH 09/11] Patch for SourceForge Bug #1299 broke D and C#. Update C# module to reflect these changes. --- Source/Modules/csharp.cxx | 45 +++++++++++++-------------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index c54475029..d78253f1a 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -198,24 +198,6 @@ public: return proxyname; } - /* ----------------------------------------------------------------------------- - * directorClassName() - * ----------------------------------------------------------------------------- */ - - String *directorClassName(Node *n) { - String *dirclassname; - const char *attrib = "director:classname"; - - if (!(dirclassname = Getattr(n, attrib))) { - String *classname = Getattr(n, "sym:name"); - - dirclassname = NewStringf("SwigDirector_%s", classname); - Setattr(n, attrib, dirclassname); - } - - return dirclassname; - } - /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ @@ -3407,6 +3389,7 @@ public: String *sym_name = Getattr(n, "sym:name"); String *qualified_classname = Copy(sym_name); String *nspace = getNSpace(); + String *dirClassName = directorClassName(n); if (nspace) Insert(qualified_classname, 0, NewStringf("%s.", nspace)); @@ -3418,7 +3401,7 @@ public: Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL %s(void *objarg", wname); Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); // TODO: if statement not needed?? - Java too Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_connect_director("); @@ -3430,7 +3413,7 @@ public: Printf(code_wrap->def, ", "); if (i != first_class_dmethod) Printf(code_wrap->code, ", "); - Printf(code_wrap->def, "SwigDirector_%s::SWIG_Callback%s_t callback%s", sym_name, methid, methid); + Printf(code_wrap->def, "%s::SWIG_Callback%s_t callback%s", dirClassName, methid, methid); Printf(code_wrap->code, "callback%s", methid); Printf(imclass_class_code, ", %s.SwigDelegate%s_%s delegate%s", qualified_classname, sym_name, methid, methid); } @@ -3447,6 +3430,7 @@ public: Delete(wname); Delete(swig_director_connect); Delete(qualified_classname); + Delete(dirClassName); } /* --------------------------------------------------------------- @@ -3962,15 +3946,15 @@ public: * ------------------------------------------------------------ */ int classDirectorDefaultConstructor(Node *n) { - String *classname = Swig_class_name(n); + String *classname = directorClassName(n); String *classtype = SwigType_namestr(Getattr(n, "name")); Wrapper *w = NewWrapper(); - Printf(w->def, "SwigDirector_%s::SwigDirector_%s() : %s {", classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "%s::%s() : %s {", classname, classname, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); - Printf(f_directors_h, " SwigDirector_%s();\n", classname); + Printf(f_directors_h, " %s();\n", classname); DelWrapper(w); Delete(classtype); Delete(classname); @@ -4014,15 +3998,15 @@ public: int classDirectorDestructor(Node *n) { Node *current_class = getCurrentClass(); - String *classname = Swig_class_name(current_class); + String *classname = directorClassName(current_class); Wrapper *w = NewWrapper(); if (Getattr(n, "throw")) { - Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s() throw ();\n", classname); + Printf(w->def, "%s::~%s() throw () {\n", classname, classname); } else { - Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s();\n", classname); + Printf(w->def, "%s::~%s() {\n", classname, classname); } Printv(w->code, "}\n", NIL); @@ -4120,8 +4104,7 @@ public: String *base = Getattr(n, "classtype"); String *class_ctor = NewString("Swig::Director()"); - String *classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); + String *directorname = directorClassName(n); String *declaration = Swig_class_declaration(n, directorname); Printf(declaration, " : public %s, public Swig::Director", base); @@ -4129,6 +4112,8 @@ public: // Stash stuff for later. Setattr(n, "director:decl", declaration); Setattr(n, "director:ctor", class_ctor); + + Delete(directorname); } }; /* class CSHARP */ From 6cb5b5487f414fb20524e557210669fbb0609a4b Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Tue, 8 Jan 2013 21:28:13 -0600 Subject: [PATCH 10/11] Use NSPACE_SEPARATOR rather than liter string for package seperator. --- Source/Modules/lang.cxx | 2 +- Source/Swig/cwrap.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 7468774a3..dc21d7f96 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -357,7 +357,7 @@ Language::~Language() { const char *attrib = "director:classname"; String *classname = Getattr(n, "sym:name"); - Replace(nspace, ".", "_", DOH_REPLACE_ANY); + Replace(nspace, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY); if (Len(nspace) > 0) dirclassname = NewStringf("SwigDirector_%s_%s", nspace, classname); else diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index c4c4621a1..38787fc63 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -857,7 +857,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas String *qualifier = Getattr(n, "qualifier"); String *directorScope = NewString(nspace); - Replace(directorScope, ".", "_", DOH_REPLACE_ANY); + Replace(directorScope, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY); /* If smart pointer without const overload or mutable method, change self dereferencing */ if (flags & CWRAP_SMART_POINTER) { @@ -1116,7 +1116,7 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String int use_director; String *directorScope = NewString(nspace); - Replace(directorScope, ".", "_", DOH_REPLACE_ANY); + Replace(directorScope, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY); use_director = Swig_directorclass(n); From e1a59ae2c78e46d2593cdbe965da3330e3914494 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Tue, 8 Jan 2013 21:38:57 -0600 Subject: [PATCH 11/11] Clean up local variable name that store the director class's name to prevent confusion with the class name. --- Source/Modules/csharp.cxx | 29 +++++++++++++++-------------- Source/Modules/d.cxx | 29 +++++++++++++++-------------- Source/Modules/java.cxx | 9 +++++---- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index d78253f1a..5010c6cee 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3890,7 +3890,7 @@ public: Node *parent = parentNode(n); String *decl = Getattr(n, "decl"); String *supername = Swig_class_name(parent); - String *classname = directorClassName(parent); + String *dirclassname = directorClassName(parent); String *sub = NewString(""); Parm *p; ParmList *superparms = Getattr(n, "parms"); @@ -3914,11 +3914,11 @@ public: /* constructor */ { String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); + String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0); String *call = Swig_csuperclass_call(0, basetype, superparms); String *classtype = SwigType_namestr(Getattr(n, "name")); - Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor")); + Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor")); Printf(f_directors, " swig_init_callbacks();\n"); Printf(f_directors, "}\n\n"); @@ -3929,7 +3929,7 @@ public: /* constructor header */ { - String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); + String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } @@ -3938,6 +3938,7 @@ public: Delete(sub); Delete(supername); Delete(parms); + Delete(dirclassname); return Language::classDirectorConstructor(n); } @@ -3946,18 +3947,18 @@ public: * ------------------------------------------------------------ */ int classDirectorDefaultConstructor(Node *n) { - String *classname = directorClassName(n); + String *dirclassname = directorClassName(n); String *classtype = SwigType_namestr(Getattr(n, "name")); Wrapper *w = NewWrapper(); - Printf(w->def, "%s::%s() : %s {", classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "%s::%s() : %s {", dirclassname, dirclassname, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); - Printf(f_directors_h, " %s();\n", classname); + Printf(f_directors_h, " %s();\n", dirclassname); DelWrapper(w); Delete(classtype); - Delete(classname); + Delete(dirclassname); return Language::classDirectorDefaultConstructor(n); } @@ -3998,15 +3999,15 @@ public: int classDirectorDestructor(Node *n) { Node *current_class = getCurrentClass(); - String *classname = directorClassName(current_class); + String *dirclassname = directorClassName(current_class); Wrapper *w = NewWrapper(); if (Getattr(n, "throw")) { - Printf(f_directors_h, " virtual ~%s() throw ();\n", classname); - Printf(w->def, "%s::~%s() throw () {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s() throw ();\n", dirclassname); + Printf(w->def, "%s::~%s() throw () {\n", dirclassname, dirclassname); } else { - Printf(f_directors_h, " virtual ~%s();\n", classname); - Printf(w->def, "%s::~%s() {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s();\n", dirclassname); + Printf(w->def, "%s::~%s() {\n", dirclassname, dirclassname); } Printv(w->code, "}\n", NIL); @@ -4014,7 +4015,7 @@ public: Wrapper_print(w, f_directors); DelWrapper(w); - Delete(classname); + Delete(dirclassname); return SWIG_OK; } diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index b66f8d2be..46a6a2b07 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -2401,7 +2401,7 @@ public: Node *parent = parentNode(n); String *decl = Getattr(n, "decl");; String *supername = Swig_class_name(parent); - String *classname = directorClassName(parent); + String *dirclassname = directorClassName(parent); String *sub = NewString(""); Parm *p; ParmList *superparms = Getattr(n, "parms"); @@ -2425,11 +2425,11 @@ public: /* constructor */ { String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); + String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0); String *call = Swig_csuperclass_call(0, basetype, superparms); String *classtype = SwigType_namestr(Getattr(n, "name")); - Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor")); + Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor")); Printf(f_directors, " swig_init_callbacks();\n"); Printf(f_directors, "}\n\n"); @@ -2440,7 +2440,7 @@ public: /* constructor header */ { - String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); + String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } @@ -2449,6 +2449,7 @@ public: Delete(sub); Delete(supername); Delete(parms); + Delete(dirclassname); return Language::classDirectorConstructor(n); } @@ -2456,18 +2457,18 @@ public: * D::classDirectorDefaultConstructor() * --------------------------------------------------------------------------- */ virtual int classDirectorDefaultConstructor(Node *n) { - String *classname = directorClassName(n); + String *dirclassname = directorClassName(n); String *classtype = SwigType_namestr(Getattr(n, "name")); Wrapper *w = NewWrapper(); - Printf(w->def, "%s::%s() : %s {", classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "%s::%s() : %s {", dirclassname, dirclassname, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); - Printf(f_directors_h, " %s();\n", classname); + Printf(f_directors_h, " %s();\n", dirclassname); DelWrapper(w); Delete(classtype); - Delete(classname); + Delete(dirclassname); return Language::classDirectorDefaultConstructor(n); } @@ -2476,15 +2477,15 @@ public: * --------------------------------------------------------------------------- */ virtual int classDirectorDestructor(Node *n) { Node *current_class = getCurrentClass(); - String *classname = directorClassName(current_class); + String *dirclassname = directorClassName(current_class); Wrapper *w = NewWrapper(); if (Getattr(n, "throw")) { - Printf(f_directors_h, " virtual ~%s() throw ();\n", classname); - Printf(w->def, "%s::~%s() throw () {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s() throw ();\n", dirclassname); + Printf(w->def, "%s::~%s() throw () {\n", dirclassname, dirclassname); } else { - Printf(f_directors_h, " virtual ~%s();\n", classname); - Printf(w->def, "%s::~%s() {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s();\n", dirclassname); + Printf(w->def, "%s::~%s() {\n", dirclassname, dirclassname); } Printv(w->code, "}\n", NIL); @@ -2492,7 +2493,7 @@ public: Wrapper_print(w, f_directors); DelWrapper(w); - Delete(classname); + Delete(dirclassname); return SWIG_OK; } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 28d8b88aa..b4703bd3e 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -4099,7 +4099,7 @@ public: Node *parent = parentNode(n); String *decl = Getattr(n, "decl"); String *supername = Swig_class_name(parent); - String *classname = directorClassName(parent); + String *dirclassname = directorClassName(parent); String *sub = NewString(""); Parm *p; ParmList *superparms = Getattr(n, "parms"); @@ -4131,11 +4131,11 @@ public: /* constructor */ { String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); + String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0); String *call = Swig_csuperclass_call(0, basetype, superparms); String *classtype = SwigType_namestr(Getattr(n, "name")); - Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor")); + Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor")); Printf(f_directors, "}\n\n"); Delete(classtype); @@ -4145,7 +4145,7 @@ public: /* constructor header */ { - String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); + String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } @@ -4155,6 +4155,7 @@ public: Delete(supername); Delete(jenv_type); Delete(parms); + Delete(dirclassname); return Language::classDirectorConstructor(n); }