From 0634883089550070c55e53a9f788a6794f3efaf2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 24 Aug 2022 17:52:20 +0100 Subject: [PATCH] SWIGTYPE && input typemaps now assume object has been moved - Java Implementation tweak - better RAII. SWIGTYPE && null pointer check. --- .../cpp11_rvalue_reference_move_input_runme.java | 16 ++++++++++++++++ Lib/java/java.swg | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/java/cpp11_rvalue_reference_move_input_runme.java b/Examples/test-suite/java/cpp11_rvalue_reference_move_input_runme.java index dfc09f217..121c93075 100644 --- a/Examples/test-suite/java/cpp11_rvalue_reference_move_input_runme.java +++ b/Examples/test-suite/java/cpp11_rvalue_reference_move_input_runme.java @@ -56,5 +56,21 @@ public class cpp11_rvalue_reference_move_input_runme { mo111.delete(); Counter.check_counts(2, 0, 0, 0, 1, 2); } + + { + // null check + Counter.reset_counts(); + boolean exception_thrown = false; + try { + MovableCopyable.movein(null); + } catch (NullPointerException e) { + if (!e.getMessage().contains("MovableCopyable && is null")) + throw new RuntimeException("incorrect exception message"); + exception_thrown = true; + } + if (!exception_thrown) + throw new RuntimeException("Should have thrown null error"); + Counter.check_counts(0, 0, 0, 0, 0, 0); + } } } diff --git a/Lib/java/java.swg b/Lib/java/java.swg index 4e65e7c17..821b5cdf6 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -695,12 +695,12 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); } SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); return $null; } %} -%typemap(in) SWIGTYPE && %{ $1 = *($&1_ltype)&$input; +%typemap(in, fragment="") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter) %{ $1 = *($&1_ltype)&$input; if (!$1) { SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); return $null; - } %} -%typemap(freearg) SWIGTYPE && %{ delete $1; %} + } + rvrdeleter.reset($1); %} %typemap(out) SWIGTYPE * %{ *($&1_ltype)&$result = $1; %} %typemap(out, fragment="SWIG_PackData", noblock=1) SWIGTYPE (CLASS::*) {