File: java.swg

package info (click to toggle)
swig1.3 1.3.11-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,852 kB
  • ctags: 4,764
  • sloc: ansic: 20,489; cpp: 10,052; sh: 7,256; yacc: 2,669; makefile: 2,381; python: 873; java: 762; tcl: 686; perl: 474; lisp: 444; ruby: 370; php: 367
file content (520 lines) | stat: -rw-r--r-- 18,985 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520

%insert(runtime) "javahead.swg"

/* Java typemaps.
 *
 * The jni, jtype and jstype typemaps work together and so there should be one of each. 
 * The jni typemap contains the JNI type used in the JNI (C/C++) code. 
 * The jtype typemap contains the Java type used in the Java module class. 
 * The jstype typemap contains the Java type used in the Java shadow class. */

/* Primitive types */
%typemap(jni) char               "jbyte"
%typemap(jni) signed char        "jbyte"
%typemap(jni) unsigned char      "jshort"
%typemap(jni) short              "jshort"
%typemap(jni) unsigned short     "jint"
%typemap(jni) int                "jint"
%typemap(jni) unsigned int       "jlong"
%typemap(jni) long               "jint"
%typemap(jni) unsigned long      "jlong"
%typemap(jni) long long          "jlong"
%typemap(jni) unsigned long long "jobject"
%typemap(jni) float              "jfloat"
%typemap(jni) double             "jdouble"
%typemap(jni) bool               "jboolean"
%typemap(jni) char *             "jstring"
%typemap(jni) void               "void"

%typemap(jtype) char               "byte"
%typemap(jtype) signed char        "byte"
%typemap(jtype) unsigned char      "short"
%typemap(jtype) short              "short"
%typemap(jtype) unsigned short     "int"
%typemap(jtype) int                "int"
%typemap(jtype) unsigned int       "long"
%typemap(jtype) long               "int"
%typemap(jtype) unsigned long      "long"
%typemap(jtype) long long          "long"
%typemap(jtype) unsigned long long "java.math.BigInteger"
%typemap(jtype) float              "float"
%typemap(jtype) double             "double"
%typemap(jtype) bool               "boolean"
%typemap(jtype) char *             "String"
%typemap(jtype) void               "void"

%typemap(jstype) char               "byte"
%typemap(jstype) signed char        "byte"
%typemap(jstype) unsigned char      "short"
%typemap(jstype) short              "short"
%typemap(jstype) unsigned short     "int"
%typemap(jstype) int                "int"
%typemap(jstype) unsigned int       "long"
%typemap(jstype) long               "int"
%typemap(jstype) unsigned long      "long"
%typemap(jstype) long long          "long"
%typemap(jstype) unsigned long long "java.math.BigInteger"
%typemap(jstype) float              "float"
%typemap(jstype) double             "double"
%typemap(jstype) bool               "boolean"
%typemap(jstype) char *             "String"
%typemap(jstype) void               "void"

/* Arrays of primtive types */                     
%typemap(jni) char[ANY]               "jstring"
%typemap(jni) signed char[ANY]        "jbyteArray"
%typemap(jni) unsigned char[ANY]      "jshortArray"
%typemap(jni) short[ANY]              "jshortArray"
%typemap(jni) unsigned short[ANY]     "jintArray"
%typemap(jni) int[ANY]                "jintArray"
%typemap(jni) unsigned int[ANY]       "jlongArray"
%typemap(jni) long[ANY]               "jintArray"
%typemap(jni) unsigned long[ANY]      "jlongArray"
%typemap(jni) long long[ANY]          "jlongArray"
/*%typemap(jni) unsigned long long[ANY] "jobjectArray"*/
%typemap(jni) float[ANY]              "jfloatArray"
%typemap(jni) double[ANY]             "jdoubleArray"
%typemap(jni) bool[ANY]               "jbooleanArray"

%typemap(jtype) char[ANY]               "String"
%typemap(jtype) signed char[ANY]        "byte[]"
%typemap(jtype) unsigned char[ANY]      "short[]"
%typemap(jtype) short[ANY]              "short[]"
%typemap(jtype) unsigned short[ANY]     "int[]"
%typemap(jtype) int[ANY]                "int[]"
%typemap(jtype) unsigned int[ANY]       "long[]"
%typemap(jtype) long[ANY]               "int[]"
%typemap(jtype) unsigned long[ANY]      "long[]"
%typemap(jtype) long long[ANY]          "long[]"
/*%typemap(jtype) unsigned long long[ANY] "java.math.BigInteger[]"*/
%typemap(jtype) float[ANY]              "float[]"
%typemap(jtype) double[ANY]             "double[]"
%typemap(jtype) bool[ANY]               "boolean[]"

%typemap(jstype) char[ANY]               "String"
%typemap(jstype) signed char[ANY]        "byte[]"
%typemap(jstype) unsigned char[ANY]      "short[]"
%typemap(jstype) short[ANY]              "short[]"
%typemap(jstype) unsigned short[ANY]     "int[]"
%typemap(jstype) int[ANY]                "int[]"
%typemap(jstype) unsigned int[ANY]       "long[]"
%typemap(jstype) long[ANY]               "int[]"
%typemap(jstype) unsigned long[ANY]      "long[]"
%typemap(jstype) long long[ANY]          "long[]"
/*%typemap(jstype) unsigned long long[ANY] "java.math.BigInteger[]"*/
%typemap(jstype) float[ANY]              "float[]"
%typemap(jstype) double[ANY]             "double[]"
%typemap(jstype) bool[ANY]               "boolean[]"

/* Non primitive types */
%typemap(jni) SWIGTYPE "jlong"
%typemap(jtype) SWIGTYPE "long"
%typemap(jstype) SWIGTYPE "$javaclassname"

%typemap(jni) SWIGTYPE [] "jlongArray"
%typemap(jtype) SWIGTYPE [] "long[]"
%typemap(jstype) SWIGTYPE [] "$javaclassname[]"

%typemap(jni) SWIGTYPE * "jlong"
%typemap(jtype) SWIGTYPE * "long"
%typemap(jstype) SWIGTYPE * "long"

%typemap(jni) SWIGTYPE & "jlong"
%typemap(jtype) SWIGTYPE & "long"
%typemap(jstype) SWIGTYPE & "long"

%typemap(jni) enum SWIGTYPE "jint"
%typemap(jtype) enum SWIGTYPE "int"
%typemap(jstype) enum SWIGTYPE "int"

/* Arrays of pointers. SWIG doesn't have a default for pointers to arrays, 
 * eg SWIGTYPE *[]. The typemap SWIGTYPE [] is used for all arrays. The
 * typemaps below give some support for arrays of pointers to primitive types. */
%typemap(jni) SWIGTYPE *ARRAYSOFPRIMITIVEPOINTERS[ANY] "jlongArray"
%typemap(jtype) SWIGTYPE *ARRAYSOFPRIMITIVEPOINTERS[ANY] "long[]"
%typemap(jstype) SWIGTYPE *ARRAYSOFPRIMITIVEPOINTERS[ANY] "long[]"

/* Arrays of enum pointers. These typemaps are applied in the source
 * code for all enum declarations, that is the equivalent of:
 * %apply enum SWIGTYPE *[ANY] { name *[ANY] }; */
%typemap(jni) enum SWIGTYPE *[ANY] "jlongArray"
%typemap(jtype) enum SWIGTYPE *[ANY] "long[]"
%typemap(jstype) enum SWIGTYPE *[ANY] "long[]"

/* Arrays of pointers. These typemaps makes it possible to treat an array of c pointers to 
 * class/struct/union as an array of Java classes. These typemaps are applied in the source
 * code for all class/struct/union declarations, that is the equivalent of:
 * %apply SWIGTYPE *ARRAYSOFCLASSPOINTERS[ANY] { name *[ANY] }; */
%typemap(jni) SWIGTYPE *ARRAYSOFCLASSPOINTERS[ANY] "jlongArray"
%typemap(jtype) SWIGTYPE *ARRAYSOFCLASSPOINTERS[ANY] "long[]"
%typemap(jstype) SWIGTYPE *ARRAYSOFCLASSPOINTERS[ANY] "$javaclassname[]"

/* Arrays of enums. SWIG does not have a default for arrays of enums, eg enum SWIGTYPE []. The following 
 * typemaps are applied in the source code for all enum declarations that is the equivalent of:
 * %apply enum SWIGTYPE[ANY] {name[ANY]}; */
%typemap(jni) enum SWIGTYPE[ANY] "jintArray"
%typemap(jtype) enum SWIGTYPE[ANY] "int[]"
%typemap(jstype) enum SWIGTYPE[ANY] "int[]"

/* Pointers and references to classes. SWIG does not have a default for pointers to classes, eg SWIGTYPE *CLASS. 
 * The following typemaps are applied in the source code for all class/struct/union declarations, that is the equivalent of:
 * %apply SWIGTYPE *CLASS { name * }; 
 * %apply SWIGTYPE &CLASS { name & }; */
%typemap(jni) SWIGTYPE *CLASS "jlong"
%typemap(jtype) SWIGTYPE *CLASS "long"
%typemap(jstype) SWIGTYPE *CLASS "$javaclassname"

%typemap(jni) SWIGTYPE &CLASS "jlong"
%typemap(jtype) SWIGTYPE &CLASS "long"
%typemap(jstype) SWIGTYPE &CLASS "$javaclassname"

/* The following are the in, out, freearg, argout typemaps. These are the JNI code generating typemaps for converting from Java to C and visa versa. */

/* primitive types */
%typemap(in) bool,
             char, 
             signed char, 
             unsigned char, 
             short, 
             unsigned short, 
             int, 
             unsigned int, 
             long, 
             unsigned long, 
             long long, 
             float, 
             double, 
             enum SWIGTYPE
%{ $1 = ($1_ltype)$input; %}

%typemap(out) bool           %{ $result = (jboolean)$1; %}
%typemap(out) char           %{ $result = (jbyte)$1; %}
%typemap(out) signed char    %{ $result = (jbyte)$1; %}
%typemap(out) unsigned char  %{ $result = (jshort)$1; %}
%typemap(out) short          %{ $result = (jshort)$1; %}
%typemap(out) unsigned short %{ $result = (jint)$1; %}
%typemap(out) int            %{ $result = (jint)$1; %}
%typemap(out) unsigned int   %{ $result = (jlong)$1; %}
%typemap(out) long           %{ $result = (jint)$1; %}
%typemap(out) unsigned long  %{ $result = (jlong)$1; %}
%typemap(out) long long      %{ $result = (jlong)$1; %}
%typemap(out) float          %{ $result = (jfloat)$1; %}
%typemap(out) double         %{ $result = (jdouble)$1; %}
%typemap(out) enum SWIGTYPE  %{ $result = (jint)$1; %}


/* unsigned long long */
/* Convert from BigInteger using the toByteArray member function */
%typemap(in) unsigned long long { 
  jclass clazz;
  jmethodID mid;
  jbyteArray ba;
  jbyte* bae;
  jsize sz;
  int i;

  if (!$input) {
    SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
    return $null;
  }
  clazz = JCALL1(GetObjectClass, jenv, $input);
  mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B");
  ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid);
  bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
  sz = JCALL1(GetArrayLength, jenv, ba);
  $1 = 0;
  if (bae[0] == 0) {
    for(i=sz-1; i>0; i-- ) {
      $1 = ($1 << 8) | (unsigned char)bae[sz-i];
    }
  } 
  else {
    for(i=sz; i>=0; i-- ) {
      $1 = ($1 << 8) | (unsigned char)bae[sz-1-i];
    }
  }
  JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
}

/* Convert to BigInteger - byte array holds number in 2's complement big endian format */
%typemap(out) unsigned long long { 
  jbyteArray ba = JCALL1(NewByteArray, jenv, 9);
  jbyte* bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
  jclass clazz = JCALL1(FindClass, jenv, "java/math/BigInteger");
  jmethodID mid = JCALL3(GetMethodID, jenv, clazz, "<init>", "([B)V");
  jobject bigint;
  int i;

  bae[0] = 0;
  for(i=1; i<9; i++ ) {
    bae[i] = (jbyte)($1>>8*(8-i));
  }

  JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
  bigint = JCALL3(NewObject, jenv, clazz, mid, ba);
  $result = bigint;
}

/* char * - treat as String */
%typemap(in) char * %{ $1 = ($input) ? ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0) : NULL; %}
%typemap(freearg) char * %{ if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, $1); %}
%typemap(out) char * %{ if($1) $result = JCALL1(NewStringUTF, jenv, $1); %}

/* Default handling */
%typemap(in) SWIGTYPE ($&1_type argp)
%{ argp = ($&1_ltype)*(void**)&$input; 
   $1 = *argp; %}

%typemap(out) SWIGTYPE 
#ifdef __cplusplus
%{$&1_type $1ptr = new $1_ltype($1);
  *($&1_ltype*)&$result = $1ptr; %}
#else
{
  $&1_type $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
  memmove($1ptr, &$1, sizeof($1_type));
  *($&1_ltype*)&$result = $1ptr;
}
#endif

/* Generic pointers and references */
%typemap(in) SWIGTYPE * , SWIGTYPE & %{ $1 = ($1_ltype)*(void**)&$input; %}
%typemap(out) SWIGTYPE * , SWIGTYPE & %{ *($&1_ltype)&$result = $1; %} 

/* Arrays */
/* bool[ANY] */
%typemap(in) bool[ANY] (jboolean *jarr)
%{ if (!SWIG_JavaArrayInBool(jenv, &jarr, &$1, $input)) return $null; %}
%typemap(argout) bool[ANY] 
%{ SWIG_JavaArrayArgoutBool(jenv, jarr$argnum, $1, $input); %}
%typemap(out) bool[ANY] 
%{$result = SWIG_JavaArrayOutBool(jenv, $1, $dim0); %}

/* char[ANY] - treat as String */
%typemap(in) char[ANY] %{ $1 = ($input) ? ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0) : NULL; %}
%typemap(argout) char[ANY] ""
%typemap(freearg) char[ANY] %{ if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, $1); %}
%typemap(out) char[ANY] %{ if($1) $result = JCALL1(NewStringUTF, jenv, $1); %}

/* signed char[ANY] */
%typemap(in) signed char[ANY] (jbyte *jarr)
%{ if (!SWIG_JavaArrayInSchar(jenv, &jarr, &$1, $input)) return $null; %}
%typemap(argout) signed char[ANY] 
%{ SWIG_JavaArrayArgoutSchar(jenv, jarr$argnum, $1, $input); %}
%typemap(out) signed char[ANY] 
%{$result = SWIG_JavaArrayOutSchar(jenv, $1, $dim0); %}

/* unsigned char[ANY] */
%typemap(in) unsigned char[ANY] (jshort *jarr)
%{ if (!SWIG_JavaArrayInUchar(jenv, &jarr, &$1, $input)) return $null; %}
%typemap(argout) unsigned char[ANY] 
%{ SWIG_JavaArrayArgoutUchar(jenv, jarr$argnum, $1, $input); %}
%typemap(out) unsigned char[ANY] 
%{$result = SWIG_JavaArrayOutUchar(jenv, $1, $dim0); %}

/* short[ANY] */
%typemap(in) short[ANY] (jshort *jarr)
%{ if (!SWIG_JavaArrayInShort(jenv, &jarr, &$1, $input)) return $null; %}
%typemap(argout) short[ANY] 
%{ SWIG_JavaArrayArgoutShort(jenv, jarr$argnum, $1, $input); %}
%typemap(out) short[ANY] 
%{$result = SWIG_JavaArrayOutShort(jenv, $1, $dim0); %}

/* unsigned short[ANY] */
%typemap(in) unsigned short[ANY] (jint *jarr)
%{ if (!SWIG_JavaArrayInUshort(jenv, &jarr, &$1, $input)) return $null; %}
%typemap(argout) unsigned short[ANY] 
%{ SWIG_JavaArrayArgoutUshort(jenv, jarr$argnum, $1, $input); %}
%typemap(out) unsigned short[ANY] 
%{$result = SWIG_JavaArrayOutUshort(jenv, $1, $dim0); %}

/* int[ANY] */
%typemap(in) int[ANY] (jint *jarr)
%{ if (!SWIG_JavaArrayInInt(jenv, &jarr, &$1, $input)) return $null; %}
%typemap(argout) int[ANY] 
%{ SWIG_JavaArrayArgoutInt(jenv, jarr$argnum, $1, $input); %}
%typemap(out) int[ANY] 
%{$result = SWIG_JavaArrayOutInt(jenv, $1, $dim0); %}

/* unsigned int[ANY] */
%typemap(in) unsigned int[ANY] (jlong *jarr)
%{ if (!SWIG_JavaArrayInUint(jenv, &jarr, &$1, $input)) return $null; %}
%typemap(argout) unsigned int[ANY] 
%{ SWIG_JavaArrayArgoutUint(jenv, jarr$argnum, $1, $input); %}
%typemap(out) unsigned int[ANY] 
%{$result = SWIG_JavaArrayOutUint(jenv, $1, $dim0); %}

/* long[ANY] */
%typemap(in) long[ANY] (jint *jarr)
%{ if (!SWIG_JavaArrayInLong(jenv, &jarr, &$1, $input)) return $null; %}
%typemap(argout) long[ANY] 
%{ SWIG_JavaArrayArgoutLong(jenv, jarr$argnum, $1, $input); %}
%typemap(out) long[ANY] 
%{$result = SWIG_JavaArrayOutLong(jenv, $1, $dim0); %}

/* unsigned long[ANY] */
%typemap(in) unsigned long[ANY] (jlong *jarr)
%{ if (!SWIG_JavaArrayInUlong(jenv, &jarr, &$1, $input)) return $null; %}
%typemap(argout) unsigned long[ANY] 
%{ SWIG_JavaArrayArgoutUlong(jenv, jarr$argnum, $1, $input); %}
%typemap(out) unsigned long[ANY] 
%{$result = SWIG_JavaArrayOutUlong(jenv, $1, $dim0); %}

/* long long[ANY] */
%typemap(in) long long[ANY] (jlong *jarr)
%{ if (!SWIG_JavaArrayInLonglong(jenv, &jarr, &$1, $input)) return $null; %}
%typemap(argout) long long[ANY] 
%{ SWIG_JavaArrayArgoutLonglong(jenv, jarr$argnum, $1, $input); %}
%typemap(out) long long[ANY] 
%{$result = SWIG_JavaArrayOutLonglong(jenv, $1, $dim0); %}

/* float[ANY] */
%typemap(in) float[ANY] (jfloat *jarr)
%{ if (!SWIG_JavaArrayInFloat(jenv, &jarr, &$1, $input)) return $null; %}
%typemap(argout) float[ANY] 
%{ SWIG_JavaArrayArgoutFloat(jenv, jarr$argnum, $1, $input); %}
%typemap(out) float[ANY] 
%{$result = SWIG_JavaArrayOutFloat(jenv, $1, $dim0); %}

/* double[ANY] */
%typemap(in) double[ANY] (jdouble *jarr)
%{ if (!SWIG_JavaArrayInDouble(jenv, &jarr, &$1, $input)) return $null; %}
%typemap(argout) double[ANY] 
%{ SWIG_JavaArrayArgoutDouble(jenv, jarr$argnum, $1, $input); %}
%typemap(out) double[ANY] 
%{$result = SWIG_JavaArrayOutDouble(jenv, $1, $dim0); %}

/* enum SWIGTYPE[ANY] */
%typemap(in) enum SWIGTYPE[ANY] (jint *jarr)
%{ if (!SWIG_JavaArrayInInt(jenv, &jarr, (int**)&$1, $input)) return $null; %}
%typemap(argout) enum SWIGTYPE[ANY] 
%{ SWIG_JavaArrayArgoutInt(jenv, jarr$argnum, (int*)$1, $input); %}
%typemap(out) enum SWIGTYPE[ANY] 
%{$result = SWIG_JavaArrayOutInt(jenv, (int*)$1, $dim0); %}

/* Arrays of pointers */
%typemap(in) SWIGTYPE *ARRAYSOFPRIMITIVEPOINTERS[ANY] (jlong *jarr, jsize sz),
             SWIGTYPE *ARRAYSOFCLASSPOINTERS[ANY] (jlong *jarr, jsize sz),
             enum SWIGTYPE *[ANY] (jlong *jarr, jsize sz)
{
  int i;
  if (!$input) {
    SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array");
    return $null;
  }
  sz = JCALL1(GetArrayLength, jenv, $input);
  jarr = JCALL2(GetLongArrayElements, jenv, $input, 0);
  if (!jarr) {
    return $null;
  }
  $1 = ($1_basetype**) calloc(sz, sizeof($1_basetype*));
  if (!$1) {
    SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "calloc failed");
    return $null;
  }
  for (i=0; i<sz; i++) {
    $1[i] = *($1_basetype**)&jarr[i];
  }
}

%typemap(argout) SWIGTYPE *ARRAYSOFPRIMITIVEPOINTERS[ANY], 
                  SWIGTYPE *ARRAYSOFCLASSPOINTERS[ANY],
                  enum SWIGTYPE *[ANY]
{
  int i;
  for (i=0; i<sz$argnum; i++) {
    jarr$argnum[i] = 0;
    *($1_basetype**)&jarr$argnum[i] = $1[i];
  }
  JCALL3(ReleaseLongArrayElements, jenv, $input, jarr$argnum, 0);
}

%typemap(out) SWIGTYPE *ARRAYSOFPRIMITIVEPOINTERS[ANY],
              SWIGTYPE *ARRAYSOFCLASSPOINTERS[ANY],
              enum SWIGTYPE *[ANY]
{
  jlong *arr;
  int i;
  $result = JCALL1(NewLongArray, jenv, $dim0);
  if (!$result) {
    return $null;
  }
  arr = JCALL2(GetLongArrayElements, jenv, $result, 0);
  if (!arr) {
    return $null;
  }
  for (i=0; i<$dim0; i++) {
    arr[i] = 0;
    *($1_ltype)&arr[i] = $1[i];
  }
  JCALL3(ReleaseLongArrayElements, jenv, $result, arr, 0);
}

%apply SWIGTYPE *ARRAYSOFPRIMITIVEPOINTERS[ANY] { 
    bool *[ANY], char *[ANY], unsigned char *[ANY], short *[ANY], unsigned short *[ANY], int *[ANY], unsigned int *[ANY], long *[ANY], unsigned long *[ANY], long long *[ANY], /*unsigned long long *[ANY],*/ float *[ANY], double *[ANY], void *[ANY] };


/* Default array handling. Used for arrays of non primitive types. */
%typemap(in) SWIGTYPE [] (jlong *jarr, jsize sz)
{
  int i;
  if (!$input) {
    SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array");
    return $null;
  }
  sz = JCALL1(GetArrayLength, jenv, $input);
  jarr = JCALL2(GetLongArrayElements, jenv, $input, 0);
  if (!jarr) {
    return $null;
  }
  $1 = ($1_basetype*) calloc(sz, sizeof($1_basetype));
  if (!$1) {
    SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "calloc failed");
    return $null;
  }
  for (i=0; i<sz; i++) {
    $1[i] = **($1_basetype**)&jarr[i];
  }
}

%typemap(argout) SWIGTYPE []
{
  int i;
  for (i=0; i<sz$argnum; i++) {
    jarr$argnum[i] = 0;
    *($1_basetype**)&jarr$argnum[i] = &$1[i];
  }
  JCALL3(ReleaseLongArrayElements, jenv, $input, jarr$argnum, 0);
}

%typemap(out) SWIGTYPE []
{
  jlong *arr;
  int i;
  $result = JCALL1(NewLongArray, jenv, $dim0);
  if (!$result) {
    return $null;
  }
  arr = JCALL2(GetLongArrayElements, jenv, $result, 0);
  if (!arr) {
    return $null;
  }
  for (i=0; i<$dim0; i++) {
    arr[i] = 0;
    *($1_basetype**)&arr[i] = &$1[i];
  }
  JCALL3(ReleaseLongArrayElements, jenv, $result, arr, 0);
}

/* free memory - required by all the array typemaps */
%typemap(freearg) SWIGTYPE []
%{ free($1); %}


%include "java_arrays.i"


/* Some ANSI C typemaps */

%apply long { size_t };