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.
This commit is contained in:
William S Fulton 2022-07-10 19:08:32 +01:00
commit bf761998ed
7 changed files with 150 additions and 18 deletions

View file

@ -192,10 +192,25 @@ try {
}
}
%}
%typemap(javarelease) SWIGTYPE %{
%typemap(javabody) SWIGTYPE %{
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
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;
try {
@ -208,6 +223,7 @@ try {
}
%}
%inline %{
struct NoExceptTest {
unsigned int noExceptionPlease() { return 123; }