summaryrefslogtreecommitdiff
path: root/Lib/java
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2022-07-10 19:08:32 +0100
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2022-07-17 15:15:24 +0100
commitbf761998ed481821997e7c65f5d3e6acdf2eaf03 (patch)
tree6d27c2d23693f5941c27cfef272bd23f2c3c5e23 /Lib/java
parent6b361bf05004181a118235df37c6c9bac099022a (diff)
downloadswig-bf761998ed481821997e7c65f5d3e6acdf2eaf03.tar.gz
SWIGTYPE && input typemaps now assume object has been moved
Change these typemaps to assume that after a function call, the parameter has been moved. The parameter's proxy class that owns the C++ object thus has the underlying pointer set to null so the object cannot be used again and the object is deleted. Scrap new javarelease typemap and move contents into javabody typemap.
Diffstat (limited to 'Lib/java')
-rw-r--r--Lib/java/java.swg32
-rw-r--r--Lib/java/std_unique_ptr.i14
2 files changed, 31 insertions, 15 deletions
diff --git a/Lib/java/java.swg b/Lib/java/java.swg
index 23744aeb3..19198b7b4 100644
--- a/Lib/java/java.swg
+++ b/Lib/java/java.swg
@@ -700,6 +700,7 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
return $null;
} %}
+%typemap(freearg) SWIGTYPE && %{ delete $1; %};
%typemap(out) SWIGTYPE *
%{ *($&1_ltype)&$result = $1; %}
%typemap(out, fragment="SWIG_PackData", noblock=1) SWIGTYPE (CLASS::*) {
@@ -1101,7 +1102,8 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
jobjectArray
"$javainput"
%typemap(javain) SWIGTYPE "$&javaclassname.getCPtr($javainput)"
-%typemap(javain) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "$javaclassname.getCPtr($javainput)"
+%typemap(javain) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$javaclassname.getCPtr($javainput)"
+%typemap(javain) SWIGTYPE && "$javaclassname.swigRelease($javainput)"
%typemap(javain) SWIGTYPE (CLASS::*) "$javaclassname.getCMemberPtr($javainput)"
/* The javaout typemap is used for converting function return types from the return type
@@ -1216,6 +1218,18 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
+
+ CPTR_VISIBILITY static long swigRelease($javaclassname obj) {
+ long ptr = 0;
+ if (obj != null) {
+ if (!obj.swigCMemOwn)
+ throw new RuntimeException("Cannot release ownership as memory is not owned");
+ ptr = obj.swigCPtr;
+ obj.swigCMemOwn = false;
+ obj.delete();
+ }
+ return ptr;
+ }
%}
// Derived proxy classes
@@ -1230,6 +1244,18 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
+
+ CPTR_VISIBILITY static long swigRelease($javaclassname obj) {
+ long ptr = 0;
+ if (obj != null) {
+ if (!obj.swigCMemOwn)
+ throw new RuntimeException("Cannot release ownership as memory is not owned");
+ ptr = obj.swigCPtr;
+ obj.swigCMemOwn = false;
+ obj.delete();
+ }
+ return ptr;
+ }
%}
%enddef
@@ -1249,6 +1275,10 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
+
+ CPTR_VISIBILITY static long swigRelease($javaclassname obj) {
+ return (obj == null) ? 0 : obj.swigCPtr;
+ }
%}
%typemap(javabody) TYPE (CLASS::*) %{
diff --git a/Lib/java/std_unique_ptr.i b/Lib/java/std_unique_ptr.i
index 7a647f616..5f4a0c5a2 100644
--- a/Lib/java/std_unique_ptr.i
+++ b/Lib/java/std_unique_ptr.i
@@ -30,20 +30,6 @@
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
-%typemap(javarelease) TYPE %{
- protected static long swigRelease($javaclassname obj) {
- long ptr = 0;
- if (obj != null) {
- if (!obj.swigCMemOwn)
- throw new RuntimeException("Cannot release ownership as memory is not owned");
- ptr = obj.swigCPtr;
- obj.swigCMemOwn = false;
- obj.delete();
- }
- return ptr;
- }
-%}
-
%template() std::unique_ptr< TYPE >;
%enddef