1%define JAVA_CRITICAL_ARRAYS_TYPEMAPS(CTYPE, JTYPE, JNITYPE, JFUNCNAME, JNIDESC)
2
3%typemap(jni) CTYPE[ANY], CTYPE[]               %{JNITYPE##Array%}
4%typemap(jtype) CTYPE[ANY], CTYPE[]             %{JTYPE[]%}
5%typemap(jstype) CTYPE[ANY], CTYPE[]            %{JTYPE[]%}
6
7%typemap(in) CTYPE[]
8%{ $1 = (CTYPE *)jenv->GetPrimitiveArrayCritical($input, 0); %}
9%typemap(in) CTYPE[ANY]
10%{  if ($input && JCALL1(GetArrayLength, jenv, $input) != $1_size) {
11    SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "incorrect array size");
12    return $null;
13  }
14  $1 = (CTYPE *)jenv->GetPrimitiveArrayCritical($input, 0); %}
15%typemap(argout) CTYPE[ANY], CTYPE[];
16%{ /*SWIG_JavaArrayArgout##JFUNCNAME(jenv, jarr$argnum, (CTYPE *)$1, $input);*/ %}
17%typemap(out) CTYPE[ANY]
18%{ /*$result = SWIG_JavaArrayOut##JFUNCNAME(jenv, (CTYPE *)$1, $1_dim0);*/ %}
19%typemap(out) CTYPE[]
20%{ /*$result = SWIG_JavaArrayOut##JFUNCNAME(jenv, (CTYPE *)$1, FillMeInAsSizeCannotBeDeterminedAutomatically);*/ %}
21%typemap(freearg) CTYPE[ANY], CTYPE[]
22%{ jenv->ReleasePrimitiveArrayCritical($input, (CTYPE *)$1, 0); %}
23
24%typemap(javain) CTYPE[ANY], CTYPE[] "$javainput"
25%typemap(javaout) CTYPE[ANY], CTYPE[] {
26    return $jnicall;
27}
28
29%typemap(memberin) CTYPE[ANY], CTYPE[];
30%typemap(globalin) CTYPE[ANY], CTYPE[];
31%enddef