SWIGTYPE && input typemaps now assume object has been moved - Java

Implementation tweak - better RAII.
SWIGTYPE && null pointer check.
This commit is contained in:
William S Fulton 2022-08-24 17:52:20 +01:00
commit 0634883089
2 changed files with 19 additions and 3 deletions

View file

@ -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);
}
}
}

View file

@ -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="<memory>") 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::*) {