File: jvilla.c

package info (click to toggle)
qdbm 1.8.78-6.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,952 kB
  • ctags: 5,454
  • sloc: ansic: 31,454; cpp: 3,623; perl: 2,167; java: 2,079; ruby: 1,690; makefile: 1,318; sh: 396
file content (759 lines) | stat: -rw-r--r-- 19,330 bytes parent folder | download | duplicates (10)
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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
/*************************************************************************************************
 * Implementation of Villa for Java
 *                                                      Copyright (C) 2000-2006 Mikio Hirabayashi
 * This file is part of QDBM, Quick Database Manager.
 * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU
 * Lesser General Public License as published by the Free Software Foundation; either version
 * 2.1 of the License or any later version.  QDBM is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 * details.
 * You should have received a copy of the GNU Lesser General Public License along with QDBM; if
 * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307 USA.
 *************************************************************************************************/


#include "qdbm_Villa.h"
#include "qdbm_VillaCursor.h"
#include <depot.h>
#include <cabin.h>
#include <villa.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

#if SIZEOF_VOID_P == SIZEOF_INT
#define PTRNUM         jint
#else
#define PTRNUM         jlong
#endif

#define MAXOPEN 1024


JNIEnv *vljnienv;
jclass vlmyclass;
VILLA *vltable[MAXOPEN];

static int getnewindex(void);
static int checkdup(const char *name);
static int getvlomode(jint omode);
static VLCFUNC getvlcmp(jint cmode);
static int getvldmode(jint dmode);
static int getvljmode(jint jmode);
static int getvlcpmode(jint cpmode);
static int objcompare(const char *aptr, int asiz, const char *bptr, int bsiz);



/*************************************************************************************************
 * public objects
 *************************************************************************************************/


JNIEXPORT void JNICALL
Java_qdbm_Villa_vlinit(JNIEnv *env, jclass myclass)
{
  int i;
  for(i = 0; i < MAXOPEN; i++){
    vltable[i] = NULL;
  }
}


JNIEXPORT jstring JNICALL
Java_qdbm_Villa_vlversion(JNIEnv *env, jclass myclass)
{
  return (*env)->NewStringUTF(env, dpversion);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlecode(JNIEnv *env, jclass myclass)
{
  switch(dpecode){
  case DP_ENOERR: return qdbm_Villa_ENOERR;
  case DP_EFATAL: return qdbm_Villa_EFATAL;
  case DP_EMODE: return qdbm_Villa_EMODE;
  case DP_EBROKEN: return qdbm_Villa_EBROKEN;
  case DP_EKEEP: return qdbm_Villa_EKEEP;
  case DP_ENOITEM: return qdbm_Villa_ENOITEM;
  case DP_EALLOC: return qdbm_Villa_EALLOC;
  case DP_EMAP: return qdbm_Villa_EMAP;
  case DP_EOPEN: return qdbm_Villa_EOPEN;
  case DP_ECLOSE: return qdbm_Villa_ECLOSE;
  case DP_ETRUNC: return qdbm_Villa_ETRUNC;
  case DP_ESYNC: return qdbm_Villa_ESYNC;
  case DP_ESTAT: return qdbm_Villa_ESTAT;
  case DP_ESEEK: return qdbm_Villa_ESEEK;
  case DP_EREAD: return qdbm_Villa_EREAD;
  case DP_EWRITE: return qdbm_Villa_EWRITE;
  case DP_ELOCK: return qdbm_Villa_ELOCK;
  case DP_EUNLINK: return qdbm_Villa_EUNLINK;
  case DP_EMKDIR: return qdbm_Villa_EMKDIR;
  case DP_ERMDIR: return qdbm_Villa_ERMDIR;
  case DP_EMISC: return qdbm_Villa_EMISC;
  }
  return -1;
}


JNIEXPORT jstring JNICALL
Java_qdbm_Villa_vlerrmsg(JNIEnv *env, jclass myclass, jint ecode)
{
  return (*env)->NewStringUTF(env, dperrmsg(ecode));
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlopen(JNIEnv *env, jclass myclass, jstring name, jint omode, jint cmode)
{
  VILLA *villa;
  const char *tname;
  jboolean ic;
  int index;
  VLCFUNC cmp;
  vljnienv = env;
  vlmyclass = myclass;
  if((index = getnewindex()) == -1) return -1;
  tname = (*env)->GetStringUTFChars(env, name, &ic);
  cmp = NULL;
  if(checkdup(tname) == -1 || !(cmp = getvlcmp(cmode))){
    if(ic == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, name, tname);
    dpecode = DP_EMISC;
    return -1;
  }
  villa = vlopen(tname, getvlomode(omode), cmp);
  if(ic == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, name, tname);
  if(!villa) return -1;
  vltable[index] = villa;
  return index;
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlclose(JNIEnv *env, jclass myclass, jint index)
{
  VILLA *villa;
  vljnienv = env;
  vlmyclass = myclass;
  villa = vltable[index];
  vltable[index] = NULL;
  return vlclose(villa);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlput(JNIEnv *env, jclass myclass, jint index, jbyteArray key, jint ksiz,
                      jbyteArray val, jint vsiz, jint dmode)
{
  jbyte *kbuf, *vbuf;
  jboolean ick, icv;
  int rv;
  vljnienv = env;
  vlmyclass = myclass;
  kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  vbuf = (*env)->GetByteArrayElements(env, val, &icv);
  rv = vlput(vltable[index], (char *)kbuf, ksiz, (char *)vbuf, vsiz, getvldmode(dmode));
  if(ick == JNI_TRUE) (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  if(icv == JNI_TRUE) (*env)->ReleaseByteArrayElements(env, val, vbuf, JNI_ABORT);
  return rv;
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlout(JNIEnv *env, jclass myclass, jint index, jbyteArray key, jint ksiz)
{
  jbyte *kbuf;
  jboolean ick;
  int rv;
  vljnienv = env;
  vlmyclass = myclass;
  kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  rv = vlout(vltable[index], (char *)kbuf, ksiz);
  if(ick == JNI_TRUE) (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return rv;
}


JNIEXPORT jbyteArray JNICALL
Java_qdbm_Villa_vlget(JNIEnv *env, jclass myclass, jint index, jbyteArray key, jint ksiz)
{
  jbyte *kbuf;
  jboolean ick;
  const char *val;
  int vsiz;
  jbyteArray vbuf;
  vljnienv = env;
  vlmyclass = myclass;
  kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  val = vlgetcache(vltable[index], (char *)kbuf, ksiz, &vsiz);
  if(ick == JNI_TRUE) (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  if(val){
    vbuf = (*env)->NewByteArray(env, vsiz);
    (*env)->SetByteArrayRegion(env, vbuf, 0, vsiz, (jbyte *)val);
  } else {
    vbuf = NULL;
  }
  return vbuf;
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlvsiz(JNIEnv *env, jclass myclass, jint index, jbyteArray key, jint ksiz)
{
  jbyte *kbuf;
  jboolean ick;
  int rv;
  vljnienv = env;
  vlmyclass = myclass;
  kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  rv = vlvsiz(vltable[index], (char *)kbuf, ksiz);
  if(ick == JNI_TRUE) (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return rv;
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlvnum(JNIEnv *env, jclass myclass, jint index, jbyteArray key, jint ksiz)
{
  jbyte *kbuf;
  jboolean ick;
  int rv;
  vljnienv = env;
  vlmyclass = myclass;
  kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  rv = vlvnum(vltable[index], (char *)kbuf, ksiz);
  if(ick == JNI_TRUE) (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return rv;
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlcurfirst(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vlcurfirst(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlcurlast(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vlcurlast(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlcurprev(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vlcurprev(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlcurnext(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vlcurnext(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlcurjump(JNIEnv *env, jclass myclass, jint index,
                          jbyteArray key, jint ksiz, jint jmode)
{
  jbyte *kbuf;
  jboolean ick;
  int rv;
  vljnienv = env;
  vlmyclass = myclass;
  kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  rv = vlcurjump(vltable[index], (char *)kbuf, ksiz, getvljmode(jmode));
  if(ick == JNI_TRUE) (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return rv;
}


JNIEXPORT jbyteArray JNICALL
Java_qdbm_Villa_vlcurkey(JNIEnv *env, jclass myclass, jint index)
{
  const char *key;
  int ksiz;
  jbyteArray kbuf;
  vljnienv = env;
  vlmyclass = myclass;
  key = vlcurkeycache(vltable[index], &ksiz);
  if(key){
    kbuf = (*env)->NewByteArray(env, ksiz);
    (*env)->SetByteArrayRegion(env, kbuf, 0, ksiz, (jbyte *)key);
  } else {
    kbuf = NULL;
  }
  return kbuf;
}


JNIEXPORT jbyteArray JNICALL
Java_qdbm_Villa_vlcurval(JNIEnv *env, jclass myclass, jint index)
{
  const char *val;
  int vsiz;
  jbyteArray vbuf;
  vljnienv = env;
  vlmyclass = myclass;
  val = vlcurvalcache(vltable[index], &vsiz);
  if(val){
    vbuf = (*env)->NewByteArray(env, vsiz);
    (*env)->SetByteArrayRegion(env, vbuf, 0, vsiz, (jbyte *)val);
  } else {
    vbuf = NULL;
  }
  return vbuf;
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlcurput(JNIEnv *env, jclass myclass, jint index,
                         jbyteArray val, jint vsiz, jint cpmode){
  jbyte *vbuf;
  jboolean icv;
  int rv;
  vljnienv = env;
  vlmyclass = myclass;
  vbuf = (*env)->GetByteArrayElements(env, val, &icv);
  rv = vlcurput(vltable[index], (char *)vbuf, vsiz, getvlcpmode(cpmode));
  if(icv == JNI_TRUE) (*env)->ReleaseByteArrayElements(env, val, vbuf, JNI_ABORT);
  return rv;
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlcurout(JNIEnv *env, jclass myclass, jint index){
  vljnienv = env;
  vlmyclass = myclass;
  return vlcurout(vltable[index]);
}


JNIEXPORT void JNICALL
Java_qdbm_Villa_vlsettuning(JNIEnv *env, jclass myclass, jint index,
                            jint lrecmax, jint nidxmax, jint lcnum, jint ncnum)
{
  vljnienv = env;
  vlmyclass = myclass;
  vlsettuning(vltable[index], lrecmax, nidxmax, lcnum, ncnum);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlsync(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vlsync(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vloptimize(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vloptimize(vltable[index]);
}


JNIEXPORT jstring JNICALL
Java_qdbm_Villa_vlname(JNIEnv *env, jclass myclass, jint index)
{
  char *name;
  jstring nbuf;
  vljnienv = env;
  vlmyclass = myclass;
  name = vlname(vltable[index]);
  if(name){
    nbuf = (*env)->NewStringUTF(env, name);
    free(name);
  } else {
    nbuf = NULL;
  }
  return nbuf;
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlfsiz(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vlfsiz(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vllnum(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vllnum(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlnnum(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vlnnum(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlrnum(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vlrnum(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlwritable(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vlwritable(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlfatalerror(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vlfatalerror(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlinode(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vlinode(vltable[index]);
}


JNIEXPORT jlong JNICALL
Java_qdbm_Villa_vlmtime(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vlmtime(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vltranbegin(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vltranbegin(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vltrancommit(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vltrancommit(vltable[index]);
}


JNIEXPORT jint JNICALL Java_qdbm_Villa_vltranabort(JNIEnv *env, jclass myclass, jint index)
{
  vljnienv = env;
  vlmyclass = myclass;
  return vltranabort(vltable[index]);
}


JNIEXPORT jint JNICALL
Java_qdbm_Villa_vlremove(JNIEnv *env, jclass myclass, jstring name)
{
  const char *tname;
  jboolean ic;
  int rv;
  tname = (*env)->GetStringUTFChars(env, name, &ic);
  rv = vlremove(tname);
  if(ic == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, name, tname);
  return rv;
}


JNIEXPORT jint JNICALL
Java_qdbm_VillaCursor_vlmulcurecode(JNIEnv *env, jclass myclass)
{
  return Java_qdbm_Villa_vlecode(env, myclass);
}


JNIEXPORT jint
JNICALL Java_qdbm_VillaCursor_vlmulcurnew(JNIEnv *env, jobject obj, jint index)
{
  jclass cls;
  jfieldID fid;
  VLMULCUR *mulcur;
  if(!(mulcur = vlmulcuropen(vltable[index]))) return 0;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  (*env)->SetLongField(env, obj, fid, (PTRNUM)mulcur);
  return 1;
}


JNIEXPORT void JNICALL
Java_qdbm_VillaCursor_vlmulcurdelete(JNIEnv *env, jobject obj)
{
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);


  printf("hoge\n");

  vlmulcurclose((VLMULCUR *)(PTRNUM)coreptr);
}


JNIEXPORT jint JNICALL
Java_qdbm_VillaCursor_vlmulcurfirst(JNIEnv *env, jobject obj, jint index)
{
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  return vlmulcurfirst((VLMULCUR *)(PTRNUM)coreptr);
}


JNIEXPORT jint JNICALL
Java_qdbm_VillaCursor_vlmulcurlast(JNIEnv *env, jobject obj, jint index)
{
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  return vlmulcurlast((VLMULCUR *)(PTRNUM)coreptr);
}


JNIEXPORT jint JNICALL
Java_qdbm_VillaCursor_vlmulcurprev(JNIEnv *env, jobject obj, jint index)
{
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  return vlmulcurprev((VLMULCUR *)(PTRNUM)coreptr);
}


JNIEXPORT jint JNICALL
Java_qdbm_VillaCursor_vlmulcurnext(JNIEnv *env, jobject obj, jint index)
{
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  return vlmulcurnext((VLMULCUR *)(PTRNUM)coreptr);
}


JNIEXPORT jint JNICALL
Java_qdbm_VillaCursor_vlmulcurjump(JNIEnv *env, jobject obj, jint index,
                                   jbyteArray key, jint ksiz, jint jmode)
{
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  jbyte *kbuf;
  jboolean ick;
  int rv;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  rv = vlmulcurjump((VLMULCUR *)(PTRNUM)coreptr, (char *)kbuf, ksiz, getvljmode(jmode));
  if(ick == JNI_TRUE) (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return rv;
}


JNIEXPORT jbyteArray JNICALL
Java_qdbm_VillaCursor_vlmulcurkey(JNIEnv *env, jobject obj, jint index)
{
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  const char *key;
  int ksiz;
  jbyteArray kbuf;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  key = vlmulcurkeycache((VLMULCUR *)(PTRNUM)coreptr, &ksiz);
  if(key){
    kbuf = (*env)->NewByteArray(env, ksiz);
    (*env)->SetByteArrayRegion(env, kbuf, 0, ksiz, (jbyte *)key);
  } else {
    kbuf = NULL;
  }
  return kbuf;
}


JNIEXPORT jbyteArray JNICALL
Java_qdbm_VillaCursor_vlmulcurval(JNIEnv *env, jobject obj, jint index)
{
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  const char *key;
  int ksiz;
  jbyteArray kbuf;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  key = vlmulcurvalcache((VLMULCUR *)(PTRNUM)coreptr, &ksiz);
  if(key){
    kbuf = (*env)->NewByteArray(env, ksiz);
    (*env)->SetByteArrayRegion(env, kbuf, 0, ksiz, (jbyte *)key);
  } else {
    kbuf = NULL;
  }
  return kbuf;
}



/*************************************************************************************************
 * private objects
 *************************************************************************************************/


static int getnewindex(void){
  int i;
  for(i = 0; i < MAXOPEN; i++){
    if(vltable[i] == NULL) return i;
  }
  return -1;
}


static int checkdup(const char *name){
  struct stat sbuf;
  int i, inode;
  if(stat(name, &sbuf) == -1) return 0;
  inode = sbuf.st_ino;
  for(i = 0; i < MAXOPEN; i++){
    if(vltable[i] != NULL && vlinode(vltable[i]) == inode) return -1;
  }
  return 0;
}


static int getvlomode(jint omode){
  int vlomode;
  vlomode = VL_OREADER;
  if(omode & qdbm_Villa_OWRITER){
    vlomode = VL_OWRITER;
    if(omode & qdbm_Villa_OCREAT) vlomode |= VL_OCREAT;
    if(omode & qdbm_Villa_OTRUNC) vlomode |= VL_OTRUNC;
  }
  if(omode & qdbm_Villa_ONOLCK) vlomode |= VL_ONOLCK;
  if(omode & qdbm_Villa_OLCKNB) vlomode |= VL_OLCKNB;
  if(omode & qdbm_Villa_OZCOMP) vlomode |= VL_OZCOMP;
  if(omode & qdbm_Villa_OYCOMP) vlomode |= VL_OYCOMP;
  if(omode & qdbm_Villa_OXCOMP) vlomode |= VL_OXCOMP;
  return vlomode;
}


static VLCFUNC getvlcmp(jint cmode){
  switch(cmode){
  case qdbm_Villa_CMPLEX: return VL_CMPLEX;
  case qdbm_Villa_CMPNUM: return VL_CMPNUM;
  case qdbm_Villa_CMPDEC: return VL_CMPDEC;
  case qdbm_Villa_CMPOBJ: return objcompare;
  }
  return NULL;
}


static int getvldmode(jint dmode){
  switch(dmode){
  case qdbm_Villa_DOVER: return VL_DOVER;
  case qdbm_Villa_DKEEP: return VL_DKEEP;
  case qdbm_Villa_DCAT: return VL_DCAT;
  case qdbm_Villa_DDUP: return VL_DDUP;
  case qdbm_Villa_DDUPR: return VL_DDUPR;
  }
  return -1;
}


static int getvljmode(jint jmode){
  switch(jmode){
  case qdbm_Villa_JFORWARD: return VL_JFORWARD;
  case qdbm_Villa_JBACKWARD: return VL_JBACKWARD;
  }
  return -1;
}


static int getvlcpmode(jint cpmode){
  switch(cpmode){
  case qdbm_Villa_CPCURRENT: return VL_CPCURRENT;
  case qdbm_Villa_CPBEFORE: return VL_CPBEFORE;
  case qdbm_Villa_CPAFTER: return VL_CPAFTER;
  }
  return -1;
}


static int objcompare(const char *aptr, int asiz, const char *bptr, int bsiz){
  jmethodID mid;
  jbyteArray abuf, bbuf;
  mid = (*vljnienv)->GetStaticMethodID(vljnienv, vlmyclass, "objcompare", "([B[B)I");
  abuf = (*vljnienv)->NewByteArray(vljnienv, asiz);
  (*vljnienv)->SetByteArrayRegion(vljnienv, abuf, 0, asiz, (jbyte *)aptr);
  bbuf = (*vljnienv)->NewByteArray(vljnienv, bsiz);
  (*vljnienv)->SetByteArrayRegion(vljnienv, bbuf, 0, bsiz, (jbyte *)bptr);
  return (*vljnienv)->CallStaticIntMethod(vljnienv, vlmyclass, mid, abuf, bbuf);
}



/* END OF FILE */