Fix crash Java directors

Further crash fixes when using OUTPUT and INOUT typemaps in typemaps.i and
passing NULL pointers in C++ to director method overloaded and implemented
in Java.

Don't create the one element array in these directorin typemaps if the
input is a NULL pointer, that is, translate a NULL C++ pointer into a
null Java object.

Also add some missing JNI error checks in these typemaps.
This commit is contained in:
William S Fulton 2018-08-12 13:45:43 +01:00
commit 61d9dd40a0
4 changed files with 208 additions and 68 deletions

View file

@ -16,8 +16,11 @@ public class java_director_typemaps_ptr_runme {
public static void main(String argv[]) {
Quux quux = new java_director_typemaps_ptr_MyQuux();
java_director_typemaps_ptr_MyQuux myquux = new java_director_typemaps_ptr_MyQuux();
Quux quux = myquux;
quux.etest();
myquux.testing_nulls = true;
quux.nulltest();
}
}
@ -25,6 +28,7 @@ class java_director_typemaps_ptr_MyQuux extends Quux {
public java_director_typemaps_ptr_MyQuux() {
super();
}
public boolean testing_nulls = false;
public void director_method_output(
boolean[] bool_arg,
@ -47,19 +51,34 @@ class java_director_typemaps_ptr_MyQuux extends Quux {
float[] float_arg,
double[] double_arg)
{
bool_arg[0] = true;
signed_char_arg[0] = 1;
unsigned_char_arg[0] = 2;
short_arg[0] = 3;
unsigned_short_arg[0] = 4;
int_arg[0] = 5;
unsigned_int_arg[0] = 6;
long_arg[0] = 7;
unsigned_long_arg[0] = 8;
long_long_arg[0] = 9;
// unsigned_long_long_arg[0] = 10;
float_arg[0] = 11;
double_arg[0] = 12;
if (testing_nulls) {
if (bool_arg != null) throw new RuntimeException("not null bool_arg");
if (signed_char_arg != null) throw new RuntimeException("not null signed_char_arg");
if (unsigned_char_arg != null) throw new RuntimeException("not null unsigned_char_arg");
if (short_arg != null) throw new RuntimeException("not null short_arg");
if (unsigned_short_arg != null) throw new RuntimeException("not null unsigned_short_arg");
if (int_arg != null) throw new RuntimeException("not null int_arg");
if (unsigned_int_arg != null) throw new RuntimeException("not null unsigned_int_arg");
if (long_arg != null) throw new RuntimeException("not null long_arg");
if (unsigned_long_arg != null) throw new RuntimeException("not null unsigned_long_arg");
if (long_long_arg != null) throw new RuntimeException("not null long_long_arg");
// if (unsigned_long_long_arg != null) throw new RuntimeException("not null unsigned_long_long_arg");
if (float_arg != null) throw new RuntimeException("not null float_arg");
if (double_arg != null) throw new RuntimeException("not null double_arg");
}
if (bool_arg != null) bool_arg[0] = true;
if (signed_char_arg != null) signed_char_arg[0] = 1;
if (unsigned_char_arg != null) unsigned_char_arg[0] = 2;
if (short_arg != null) short_arg[0] = 3;
if (unsigned_short_arg != null) unsigned_short_arg[0] = 4;
if (int_arg != null) int_arg[0] = 5;
if (unsigned_int_arg != null) unsigned_int_arg[0] = 6;
if (long_arg != null) long_arg[0] = 7;
if (unsigned_long_arg != null) unsigned_long_arg[0] = 8;
if (long_long_arg != null) long_long_arg[0] = 9;
// if (unsigned_long_long_arg != null) unsigned_long_long_arg[0] = 10;
if (float_arg != null) float_arg[0] = 11;
if (double_arg != null) double_arg[0] = 12;
}
public void director_method_inout(
@ -83,34 +102,49 @@ class java_director_typemaps_ptr_MyQuux extends Quux {
float[] float_arg,
double[] double_arg)
{
if (bool_arg[0]) throw new RuntimeException("unexpected value for bool_arg");
if (testing_nulls) {
if (bool_arg != null) throw new RuntimeException("not null bool_arg");
if (signed_char_arg != null) throw new RuntimeException("not null signed_char_arg");
if (unsigned_char_arg != null) throw new RuntimeException("not null unsigned_char_arg");
if (short_arg != null) throw new RuntimeException("not null short_arg");
if (unsigned_short_arg != null) throw new RuntimeException("not null unsigned_short_arg");
if (int_arg != null) throw new RuntimeException("not null int_arg");
if (unsigned_int_arg != null) throw new RuntimeException("not null unsigned_int_arg");
if (long_arg != null) throw new RuntimeException("not null long_arg");
if (unsigned_long_arg != null) throw new RuntimeException("not null unsigned_long_arg");
if (long_long_arg != null) throw new RuntimeException("not null long_long_arg");
// if (unsigned_long_long_arg != null) throw new RuntimeException("not null unsigned_long_long_arg");
if (float_arg != null) throw new RuntimeException("not null float_arg");
if (double_arg != null) throw new RuntimeException("not null double_arg");
} else {
if (bool_arg[0]) throw new RuntimeException("unexpected value for bool_arg");
if (signed_char_arg[0] != 101) throw new RuntimeException("unexpected value for signed_char_arg");
if (unsigned_char_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_char_arg");
if (short_arg[0] != 101) throw new RuntimeException("unexpected value for short_arg");
if (unsigned_short_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_short_arg");
if (int_arg[0] != 101) throw new RuntimeException("unexpected value for int_arg");
if (unsigned_int_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_int_arg");
if (long_arg[0] != 101) throw new RuntimeException("unexpected value for long_arg");
if (unsigned_long_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_long_arg");
if (long_long_arg[0] != 101) throw new RuntimeException("unexpected value for long_long_arg");
// if (unsigned_long_long_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_long_long_arg");
if (float_arg[0] != 101) throw new RuntimeException("unexpected value for float_arg");
if (double_arg[0] != 101) throw new RuntimeException("unexpected value for double_arg");
}
if (signed_char_arg[0] != 101) throw new RuntimeException("unexpected value for signed_char_arg");
if (unsigned_char_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_char_arg");
if (short_arg[0] != 101) throw new RuntimeException("unexpected value for short_arg");
if (unsigned_short_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_short_arg");
if (int_arg[0] != 101) throw new RuntimeException("unexpected value for int_arg");
if (unsigned_int_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_int_arg");
if (long_arg[0] != 101) throw new RuntimeException("unexpected value for long_arg");
if (unsigned_long_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_long_arg");
if (long_long_arg[0] != 101) throw new RuntimeException("unexpected value for long_long_arg");
// if (unsigned_long_long_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_long_long_arg");
if (float_arg[0] != 101) throw new RuntimeException("unexpected value for float_arg");
if (double_arg[0] != 101) throw new RuntimeException("unexpected value for double_arg");
bool_arg[0] = false;
signed_char_arg[0] = 11;
unsigned_char_arg[0] = 12;
short_arg[0] = 13;
unsigned_short_arg[0] = 14;
int_arg[0] = 15;
unsigned_int_arg[0] = 16;
long_arg[0] = 17;
unsigned_long_arg[0] = 18;
long_long_arg[0] = 19;
// unsigned_long_long_arg[0] = 110;
float_arg[0] = 111;
double_arg[0] = 112;
if (bool_arg != null) bool_arg[0] = false;
if (signed_char_arg != null) signed_char_arg[0] = 11;
if (unsigned_char_arg != null) unsigned_char_arg[0] = 12;
if (short_arg != null) short_arg[0] = 13;
if (unsigned_short_arg != null) unsigned_short_arg[0] = 14;
if (int_arg != null) int_arg[0] = 15;
if (unsigned_int_arg != null) unsigned_int_arg[0] = 16;
if (long_arg != null) long_arg[0] = 17;
if (unsigned_long_arg != null) unsigned_long_arg[0] = 18;
if (long_long_arg != null) long_long_arg[0] = 19;
// if (unsigned_long_long_arg != null) unsigned_long_long_arg[0] = 110;
if (float_arg != null) float_arg[0] = 111;
if (double_arg != null) double_arg[0] = 112;
}
public void director_method_nameless_args(
@ -134,18 +168,33 @@ class java_director_typemaps_ptr_MyQuux extends Quux {
float[] float_arg,
double[] double_arg)
{
bool_arg[0] = true;
signed_char_arg[0] = 12;
unsigned_char_arg[0] = 13;
short_arg[0] = 14;
unsigned_short_arg[0] = 15;
int_arg[0] = 16;
unsigned_int_arg[0] = 17;
long_arg[0] = 18;
unsigned_long_arg[0] = 19;
long_long_arg[0] = 20;
// unsigned_long_long_arg[0] = 111;
float_arg[0] = 112;
double_arg[0] = 113;
if (testing_nulls) {
if (bool_arg != null) throw new RuntimeException("not null bool_arg");
if (signed_char_arg != null) throw new RuntimeException("not null signed_char_arg");
if (unsigned_char_arg != null) throw new RuntimeException("not null unsigned_char_arg");
if (short_arg != null) throw new RuntimeException("not null short_arg");
if (unsigned_short_arg != null) throw new RuntimeException("not null unsigned_short_arg");
if (int_arg != null) throw new RuntimeException("not null int_arg");
if (unsigned_int_arg != null) throw new RuntimeException("not null unsigned_int_arg");
if (long_arg != null) throw new RuntimeException("not null long_arg");
if (unsigned_long_arg != null) throw new RuntimeException("not null unsigned_long_arg");
if (long_long_arg != null) throw new RuntimeException("not null long_long_arg");
// if (unsigned_long_long_arg != null) throw new RuntimeException("not null unsigned_long_long_arg");
if (float_arg != null) throw new RuntimeException("not null float_arg");
if (double_arg != null) throw new RuntimeException("not null double_arg");
}
if (bool_arg != null) bool_arg[0] = true;
if (signed_char_arg != null) signed_char_arg[0] = 12;
if (unsigned_char_arg != null) unsigned_char_arg[0] = 13;
if (short_arg != null) short_arg[0] = 14;
if (unsigned_short_arg != null) unsigned_short_arg[0] = 15;
if (int_arg != null) int_arg[0] = 16;
if (unsigned_int_arg != null) unsigned_int_arg[0] = 17;
if (long_arg != null) long_arg[0] = 18;
if (unsigned_long_arg != null) unsigned_long_arg[0] = 19;
if (long_long_arg != null) long_long_arg[0] = 20;
// if (unsigned_long_long_arg != null) unsigned_long_long_arg[0] = 111;
if (float_arg != null) float_arg[0] = 112;
if (double_arg != null) double_arg[0] = 113;
}
}

View file

@ -344,6 +344,71 @@ public:
verify(floatarg_inout == 112);
verify(doublearg_inout == 113);
}
void nulltest() {
director_method_output(
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
// NULL,
NULL,
NULL);
director_method_inout(
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
// NULL,
NULL,
NULL);
director_method_nameless_args(
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
// NULL,
NULL,
NULL);
}
};
%}