/usr/share/swig/3.0.12/java
Edit: /usr/share/swig/3.0.12/java/arrays_java.i (13701B)
/* -----------------------------------------------------------------------------
* arrays_java.i
*
* These typemaps give more natural support for arrays. The typemaps are not efficient
* as there is a lot of copying of the array values whenever the array is passed to C/C++
* from Java and vice versa. The Java array is expected to be the same size as the C array.
* An exception is thrown if they are not.
*
* Example usage:
* Wrapping:
*
* %include
* %inline %{
* short FiddleSticks[3];
* %}
*
* Use from Java like this:
*
* short[] fs = new short[] {10, 11, 12};
* example.setFiddleSticks(fs);
* fs = example.getFiddleSticks();
* ----------------------------------------------------------------------------- */
/* Primitive array support is a combination of SWIG macros and functions in order to reduce
* code bloat and aid maintainability. The SWIG preprocessor expands the macros into functions
* for inclusion in the generated code. */
/* Array support functions declarations macro */
%define JAVA_ARRAYS_DECL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME)
%{
static int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input);
static void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input);
static JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz);
%}
%enddef
/* Array support functions macro */
%define JAVA_ARRAYS_IMPL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME)
%{
/* CTYPE[] support */
static int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input) {
int i;
jsize sz;
if (!input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array");
return 0;
}
sz = JCALL1(GetArrayLength, jenv, input);
*jarr = JCALL2(Get##JAVATYPE##ArrayElements, jenv, input, 0);
if (!*jarr)
return 0; %}
#ifdef __cplusplus
%{ *carr = new CTYPE[sz]; %}
#else
%{ *carr = (CTYPE*) malloc(sz * sizeof(CTYPE)); %}
#endif
%{ if (!*carr) {
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed");
return 0;
}
for (i=0; i