diff options
Diffstat (limited to 'Examples/test-suite/java_throws.i')
-rw-r--r-- | Examples/test-suite/java_throws.i | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/Examples/test-suite/java_throws.i b/Examples/test-suite/java_throws.i index 6cd47b448..7463fee83 100644 --- a/Examples/test-suite/java_throws.i +++ b/Examples/test-suite/java_throws.i @@ -88,7 +88,7 @@ int ioTest() { return 0; } %} // except feature (%javaexception) specifying a checked exception class for the throws clause -%typemap(javabase) MyException "Throwable"; +%typemap(javabase) MyException "Throwable" %typemap(javacode) MyException %{ public static final long serialVersionUID = 0x52151000; // Suppress ecj warning %} @@ -183,7 +183,7 @@ try { // Need to handle the checked exception in NoExceptTest.delete() %typemap(javafinalize) SWIGTYPE %{ - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "removal"}) protected void finalize() { try { delete(); @@ -193,6 +193,37 @@ try { } %} +%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 { + obj.delete(); + } catch (MyException e) { + throw new RuntimeException(e); + } + } + return ptr; + } +%} + + %inline %{ struct NoExceptTest { unsigned int noExceptionPlease() { return 123; } |