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
This commit is contained in:
parent
6c72fdcceb
commit
a7fa8d86cc
4 changed files with 51 additions and 25 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue