From a7fa8d86cc75d0e47040215d65454400a40d7e97 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 29 Jun 2003 21:52:26 +0000 Subject: [PATCH] New typemap attribute which specifies the destructor wrapper method name thus making the wrapper method name configurable. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4933 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/csharp/csharp.swg | 4 ++-- Lib/java/java.swg | 4 ++-- Source/Modules/csharp.cxx | 43 +++++++++++++++++++++++++-------------- Source/Modules/java.cxx | 25 +++++++++++++++++------ 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 5a602bdb1..5e4fa12cb 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -434,7 +434,7 @@ $1 = &temp; %} } %} -%typemap(csdestruct) SWIGTYPE { +%typemap(csdestruct, methodname="Dispose") SWIGTYPE { if(swigCPtr != IntPtr.Zero && swigCMemOwn) { $imcall; swigCMemOwn = false; @@ -443,7 +443,7 @@ $1 = &temp; %} GC.SuppressFinalize(this); } -%typemap(csdestruct_derived) SWIGTYPE { +%typemap(csdestruct_derived, methodname="Dispose") SWIGTYPE { if(swigCPtr != IntPtr.Zero && swigCMemOwn) { $imcall; swigCMemOwn = false; diff --git a/Lib/java/java.swg b/Lib/java/java.swg index b896f171d..33b4b2d8f 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -685,7 +685,7 @@ } %} -%typemap(javadestruct) SWIGTYPE { +%typemap(javadestruct, methodname="delete") SWIGTYPE { if(swigCPtr != 0 && swigCMemOwn) { $jnicall; swigCMemOwn = false; @@ -693,7 +693,7 @@ swigCPtr = 0; } -%typemap(javadestruct_derived) SWIGTYPE { +%typemap(javadestruct_derived, methodname="delete") SWIGTYPE { if(swigCPtr != 0 && swigCMemOwn) { $jnicall; swigCMemOwn = false; diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index e6f6f803d..a7d87cc6c 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -749,7 +749,7 @@ class CSHARP : public Language { if ((tm = Swig_typemap_lookup_new("cstype",n,"",0))) { substituteClassname(t, tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_JSWTYPE_UNDEF, input_file, line_number, + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(t,0)); } @@ -800,7 +800,7 @@ class CSHARP : public Language { classname_substituted_flag = substituteClassname(t, tm); Printf(return_type, "%s", tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_JSWTYPE_UNDEF, input_file, line_number, + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(t,0)); } @@ -1016,12 +1016,22 @@ class CSHARP : public Language { } // C++ destructor is wrapped by the Dispose method + // Note that the method name is specified in a typemap attribute called methodname String *destruct = NewString(""); const String *tm = NULL; - if (derived) - tm = typemapLookup("csdestruct_derived", classDeclarationName, WARN_NONE); - else - tm = typemapLookup("csdestruct", classDeclarationName, WARN_NONE); + Node *attributes = NewHash(); + String *destruct_methodname = NULL; + if (derived) { + tm = typemapLookup("csdestruct_derived", classDeclarationName, WARN_NONE, attributes); + destruct_methodname = Getattr(attributes, "tmap:csdestruct_derived:methodname"); + } else { + tm = typemapLookup("csdestruct", classDeclarationName, WARN_NONE, attributes); + destruct_methodname = Getattr(attributes, "tmap:csdestruct:methodname"); + } + if (!destruct_methodname) { + Swig_error(input_file, line_number, + "No methodname attribute defined in csdestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); + } // Emit the Finalize and Dispose methods if (tm) { @@ -1038,8 +1048,9 @@ class CSHARP : public Language { else Replaceall(destruct, "$imcall", "throw new MethodAccessException(\"C++ destructor does not have public access\")"); if (*Char(destruct)) - Printv(proxy_class_def, "\n public ", derived ? "override" : "virtual", " void Dispose() ", destruct, "\n", NIL); + Printv(proxy_class_def, "\n public ", derived ? "override" : "virtual", " void ", destruct_methodname, "() ", destruct, "\n", NIL); } + Delete(attributes); Delete(destruct); // Emit various other methods @@ -1235,7 +1246,7 @@ class CSHARP : public Language { substituteClassname(t, tm); Printf(return_type, "%s", tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_JSWTYPE_UNDEF, input_file, line_number, + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(t,0)); } @@ -1289,7 +1300,7 @@ class CSHARP : public Language { substituteClassname(pt, tm); Printf(param_type, "%s", tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_JSWTYPE_UNDEF, input_file, line_number, + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(pt,0)); } @@ -1434,7 +1445,7 @@ class CSHARP : public Language { substituteClassname(pt, tm); Printf(param_type, "%s", tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_JSWTYPE_UNDEF, input_file, line_number, + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(pt,0)); } @@ -1509,7 +1520,7 @@ class CSHARP : public Language { if ((tm = Swig_typemap_lookup_new("cstype",n,"",0))) { substituteClassname(t, tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_JSWTYPE_UNDEF, input_file, line_number, + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(t,0)); } @@ -1543,7 +1554,7 @@ class CSHARP : public Language { if ((tm = Swig_typemap_lookup_new("cstype",n,"",0))) { substituteClassname(t, tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_JSWTYPE_UNDEF, input_file, line_number, + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(t,0)); } @@ -1627,7 +1638,7 @@ class CSHARP : public Language { substituteClassname(t, tm); Printf(return_type, "%s", tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_JSWTYPE_UNDEF, input_file, line_number, + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(t,0)); } @@ -1672,7 +1683,7 @@ class CSHARP : public Language { substituteClassname(pt, tm); Printf(param_type, "%s", tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_JSWTYPE_UNDEF, input_file, line_number, + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(pt,0)); } @@ -1901,12 +1912,14 @@ class CSHARP : public Language { * typemapLookup() * ----------------------------------------------------------------------------- */ - const String *typemapLookup(const String *op, String *type, int warning) { + const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes=NULL) { String *tm = NULL; const String *code = NULL; if((tm = Swig_typemap_search(op, type, NULL, NULL))) { code = Getattr(tm,"code"); + if (typemap_attributes) + Swig_typemap_attach_kwargs(tm,op,typemap_attributes); } if (!code) { diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index df08e2f01..680719f26 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1117,12 +1117,22 @@ class JAVA : public Language { } // C++ destructor is wrapped by the delete method + // Note that the method name is specified in a typemap attribute called methodname String *destruct = NewString(""); const String *tm = NULL; - if (derived) - tm = typemapLookup("javadestruct_derived", classDeclarationName, WARN_NONE); - else - tm = typemapLookup("javadestruct", classDeclarationName, WARN_NONE); + Node *attributes = NewHash(); + String *destruct_methodname = NULL; + if (derived) { + tm = typemapLookup("javadestruct_derived", classDeclarationName, WARN_NONE, attributes); + destruct_methodname = Getattr(attributes, "tmap:javadestruct_derived:methodname"); + } else { + tm = typemapLookup("javadestruct", classDeclarationName, WARN_NONE, attributes); + destruct_methodname = Getattr(attributes, "tmap:javadestruct:methodname"); + } + if (!destruct_methodname) { + Swig_error(input_file, line_number, + "No methodname attribute defined in javadestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); + } // Emit the finalize and delete methods if (tm) { @@ -1139,8 +1149,9 @@ class JAVA : public Language { else Replaceall(destruct, "$jnicall", ""); if (*Char(destruct)) - Printv(proxy_class_def, "\n ", *Char(destructor_call) ? "public": "protected", " void delete() ", destruct, "\n", NIL); + Printv(proxy_class_def, "\n ", *Char(destructor_call) ? "public": "protected", " void ", destruct_methodname, "() ", destruct, "\n", NIL); } + Delete(attributes); Delete(destruct); // Emit various other methods @@ -1891,12 +1902,14 @@ class JAVA : public Language { * typemapLookup() * ----------------------------------------------------------------------------- */ - const String *typemapLookup(const String *op, String *type, int warning) { + const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes=NULL) { String *tm = NULL; const String *code = NULL; if((tm = Swig_typemap_search(op, type, NULL, NULL))) { code = Getattr(tm,"code"); + if (typemap_attributes) + Swig_typemap_attach_kwargs(tm,op,typemap_attributes); } if (!code) {