ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/BDB/BDB.xs
(Generate patch)

Comparing BDB/BDB.xs (file contents):
Revision 1.22 by root, Fri Dec 7 13:14:54 2007 UTC vs.
Revision 1.47 by root, Fri Jul 18 22:39:10 2008 UTC

27# include <unistd.h> 27# include <unistd.h>
28#endif 28#endif
29 29
30#include <db.h> 30#include <db.h>
31 31
32#if DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 4) 32#if DB_VERSION_MAJOR != 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 3)
33# error you need Berkeley DB 4.4 or newer installed 33# error you need Berkeley DB 4.3 or a newer 4.x version installed
34#endif 34#endif
35 35
36/* number of seconds after which idle threads exit */ 36/* number of seconds after which idle threads exit */
37#define IDLE_TIMEOUT 10 37#define IDLE_TIMEOUT 10
38 38
39typedef DB_ENV DB_ENV_ornull; 39typedef DB_ENV DB_ENV_ornull;
40typedef DB_TXN DB_TXN_ornull; 40typedef DB_TXN DB_TXN_ornull;
41typedef DBC DBC_ornull; 41typedef DBC DBC_ornull;
42typedef DB DB_ornull; 42typedef DB DB_ornull;
43
44typedef DB_ENV DB_ENV_ornuked;
45typedef DB_TXN DB_TXN_ornuked;
46typedef DBC DBC_ornuked;
47typedef DB DB_ornuked;
48
49#if DB_VERSION_MINOR >= 3
43typedef DB_SEQUENCE DB_SEQUENCE_ornull; 50typedef DB_SEQUENCE DB_SEQUENCE_ornull;
51typedef DB_SEQUENCE DB_SEQUENCE_ornuked;
52#endif
44 53
45typedef SV SV8; /* byte-sv, used for argument-checking */ 54typedef SV SV8; /* byte-sv, used for argument-checking */
46typedef char *octetstring; 55typedef char *bdb_filename;
47 56
48static SV *prepare_cb; 57static SV *prepare_cb;
49 58
50#if DB_VERSION_MINOR >= 6 59#if DB_VERSION_MINOR >= 6
51# define c_close close 60# define c_close close
55# define c_get get 64# define c_get get
56# define c_pget pget 65# define c_pget pget
57# define c_put put 66# define c_put put
58#endif 67#endif
59 68
69static char *
70get_bdb_filename (SV *sv)
71{
72 if (!SvOK (sv))
73 return 0;
74
75#if _WIN32
76 /* win32 madness + win32 perl absolutely brokenness make for horrible hacks */
77 {
78 STRLEN len;
79 char *src = SvPVbyte (sv, len);
80 SV *t1 = sv_newmortal ();
81 SV *t2 = sv_newmortal ();
82
83 sv_upgrade (t1, SVt_PV); SvPOK_only (t1); SvGROW (t1, len * 16 + 1);
84 sv_upgrade (t2, SVt_PV); SvPOK_only (t2); SvGROW (t2, len * 16 + 1);
85
86 len = MultiByteToWideChar (CP_ACP, 0, src, len, (WCHAR *)SvPVX (t1), SvLEN (t1) / sizeof (WCHAR));
87 len = WideCharToMultiByte (CP_UTF8, 0, (WCHAR *)SvPVX (t1), len, SvPVX (t2), SvLEN (t2), 0, 0);
88 SvPOK_only (t2);
89 SvPVX (t2)[len] = 0;
90 SvCUR_set (t2, len);
91
92 return SvPVX (t2);
93 }
94#else
95 return SvPVbyte_nolen (sv);
96#endif
97}
98
60static void 99static void
61debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) 100debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg)
62{ 101{
63 printf ("err[%s]\n", msg); 102 printf ("err[%s]\n", msg);
64} 103}
101} 140}
102 141
103enum { 142enum {
104 REQ_QUIT, 143 REQ_QUIT,
105 REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, 144 REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT,
106 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, 145 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME,
107 REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, 146 REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE,
108 REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, 147 REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE,
109 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, 148 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH,
110 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, 149 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL,
111 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, 150 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE,
112}; 151};
113 152
114typedef struct aio_cb 153typedef struct bdb_cb
115{ 154{
116 struct aio_cb *volatile next; 155 struct bdb_cb *volatile next;
117 SV *callback; 156 SV *callback;
118 int type, pri, result; 157 int type, pri, result;
119 158
120 DB_ENV *env; 159 DB_ENV *env;
121 DB *db; 160 DB *db;
123 DBC *dbc; 162 DBC *dbc;
124 163
125 UV uv1; 164 UV uv1;
126 int int1, int2; 165 int int1, int2;
127 U32 uint1, uint2; 166 U32 uint1, uint2;
128 char *buf1, *buf2; 167 char *buf1, *buf2, *buf3;
129 SV *sv1, *sv2, *sv3; 168 SV *sv1, *sv2, *sv3;
130 169
131 DBT dbt1, dbt2, dbt3; 170 DBT dbt1, dbt2, dbt3;
132 DB_KEY_RANGE key_range; 171 DB_KEY_RANGE key_range;
172#if DB_VERSION_MINOR >= 3
133 DB_SEQUENCE *seq; 173 DB_SEQUENCE *seq;
134 db_seq_t seq_t; 174 db_seq_t seq_t;
135} aio_cb; 175#endif
176} bdb_cb;
136 177
137typedef aio_cb *aio_req; 178typedef bdb_cb *bdb_req;
138 179
139enum { 180enum {
140 PRI_MIN = -4, 181 PRI_MIN = -4,
141 PRI_MAX = 4, 182 PRI_MAX = 4,
142 183
145 NUM_PRI = PRI_MAX + PRI_BIAS + 1, 186 NUM_PRI = PRI_MAX + PRI_BIAS + 1,
146}; 187};
147 188
148#define AIO_TICKS ((1000000 + 1023) >> 10) 189#define AIO_TICKS ((1000000 + 1023) >> 10)
149 190
191static SV *on_next_submit;
192
150static unsigned int max_poll_time = 0; 193static unsigned int max_poll_time = 0;
151static unsigned int max_poll_reqs = 0; 194static unsigned int max_poll_reqs = 0;
152 195
153/* calculcate time difference in ~1/AIO_TICKS of a second */ 196/* calculcate time difference in ~1/AIO_TICKS of a second */
154static int tvdiff (struct timeval *tv1, struct timeval *tv2) 197static int tvdiff (struct timeval *tv1, struct timeval *tv2)
169 struct worker *prev, *next; 212 struct worker *prev, *next;
170 213
171 thread_t tid; 214 thread_t tid;
172 215
173 /* locked by reslock, reqlock or wrklock */ 216 /* locked by reslock, reqlock or wrklock */
174 aio_req req; /* currently processed request */ 217 bdb_req req; /* currently processed request */
175 void *dbuf; 218 void *dbuf;
176 DIR *dirp; 219 DIR *dirp;
177} worker; 220} worker;
178 221
179static worker wrk_first = { &wrk_first, &wrk_first, 0 }; 222static worker wrk_first = { &wrk_first, &wrk_first, 0 };
199static mutex_t reqlock = X_MUTEX_INIT; 242static mutex_t reqlock = X_MUTEX_INIT;
200static cond_t reqwait = X_COND_INIT; 243static cond_t reqwait = X_COND_INIT;
201 244
202#if WORDACCESS_UNSAFE 245#if WORDACCESS_UNSAFE
203 246
204static unsigned int get_nready () 247static unsigned int get_nready (void)
205{ 248{
206 unsigned int retval; 249 unsigned int retval;
207 250
208 X_LOCK (reqlock); 251 X_LOCK (reqlock);
209 retval = nready; 252 retval = nready;
210 X_UNLOCK (reqlock); 253 X_UNLOCK (reqlock);
211 254
212 return retval; 255 return retval;
213} 256}
214 257
215static unsigned int get_npending () 258static unsigned int get_npending (void)
216{ 259{
217 unsigned int retval; 260 unsigned int retval;
218 261
219 X_LOCK (reslock); 262 X_LOCK (reslock);
220 retval = npending; 263 retval = npending;
221 X_UNLOCK (reslock); 264 X_UNLOCK (reslock);
222 265
223 return retval; 266 return retval;
224} 267}
225 268
226static unsigned int get_nthreads () 269static unsigned int get_nthreads (void)
227{ 270{
228 unsigned int retval; 271 unsigned int retval;
229 272
230 X_LOCK (wrklock); 273 X_LOCK (wrklock);
231 retval = started; 274 retval = started;
246 * a somewhat faster data structure might be nice, but 289 * a somewhat faster data structure might be nice, but
247 * with 8 priorities this actually needs <20 insns 290 * with 8 priorities this actually needs <20 insns
248 * per shift, the most expensive operation. 291 * per shift, the most expensive operation.
249 */ 292 */
250typedef struct { 293typedef struct {
251 aio_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ 294 bdb_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */
252 int size; 295 int size;
253} reqq; 296} reqq;
254 297
255static reqq req_queue; 298static reqq req_queue;
256static reqq res_queue; 299static reqq res_queue;
257 300
258int reqq_push (reqq *q, aio_req req) 301int reqq_push (reqq *q, bdb_req req)
259{ 302{
260 int pri = req->pri; 303 int pri = req->pri;
261 req->next = 0; 304 req->next = 0;
262 305
263 if (q->qe[pri]) 306 if (q->qe[pri])
269 q->qe[pri] = q->qs[pri] = req; 312 q->qe[pri] = q->qs[pri] = req;
270 313
271 return q->size++; 314 return q->size++;
272} 315}
273 316
274aio_req reqq_shift (reqq *q) 317bdb_req reqq_shift (reqq *q)
275{ 318{
276 int pri; 319 int pri;
277 320
278 if (!q->size) 321 if (!q->size)
279 return 0; 322 return 0;
280 323
281 --q->size; 324 --q->size;
282 325
283 for (pri = NUM_PRI; pri--; ) 326 for (pri = NUM_PRI; pri--; )
284 { 327 {
285 aio_req req = q->qs[pri]; 328 bdb_req req = q->qs[pri];
286 329
287 if (req) 330 if (req)
288 { 331 {
289 if (!(q->qs[pri] = req->next)) 332 if (!(q->qs[pri] = req->next))
290 q->qe[pri] = 0; 333 q->qe[pri] = 0;
294 } 337 }
295 338
296 abort (); 339 abort ();
297} 340}
298 341
299static int poll_cb (); 342static int poll_cb (void);
300static void req_free (aio_req req); 343static void req_free (bdb_req req);
301static void req_cancel (aio_req req); 344static void req_cancel (bdb_req req);
302 345
303static int req_invoke (aio_req req) 346static int req_invoke (bdb_req req)
304{ 347{
305 dSP; 348 dSP;
306 349
307 if (SvOK (req->callback)) 350 if (req->callback)
308 { 351 {
309 ENTER; 352 ENTER;
310 SAVETMPS; 353 SAVETMPS;
311 PUSHMARK (SP); 354 PUSHMARK (SP);
312 355
326 dbt_to_sv (req->sv1, &req->dbt1); 369 dbt_to_sv (req->sv1, &req->dbt1);
327 dbt_to_sv (req->sv2, &req->dbt2); 370 dbt_to_sv (req->sv2, &req->dbt2);
328 dbt_to_sv (req->sv3, &req->dbt3); 371 dbt_to_sv (req->sv3, &req->dbt3);
329 break; 372 break;
330 373
374 case REQ_DB_PUT:
375 case REQ_C_PUT:
376 dbt_to_sv (0, &req->dbt1);
377 dbt_to_sv (0, &req->dbt2);
378 break;
379
331 case REQ_DB_KEY_RANGE: 380 case REQ_DB_KEY_RANGE:
332 { 381 {
333 AV *av = newAV (); 382 AV *av = newAV ();
334 383
335 av_push (av, newSVnv (req->key_range.less)); 384 av_push (av, newSVnv (req->key_range.less));
340 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); 389 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av));
341 SvREFCNT_dec (req->sv1); 390 SvREFCNT_dec (req->sv1);
342 } 391 }
343 break; 392 break;
344 393
394#if DB_VERSION_MINOR >= 3
345 case REQ_SEQ_GET: 395 case REQ_SEQ_GET:
346 SvREADONLY_off (req->sv1); 396 SvREADONLY_off (req->sv1);
347 397
348 if (sizeof (IV) > 4) 398 if (sizeof (IV) > 4)
349 sv_setiv_mg (req->sv1, (IV)req->seq_t); 399 sv_setiv_mg (req->sv1, (IV)req->seq_t);
350 else 400 else
351 sv_setnv_mg (req->sv1, (NV)req->seq_t); 401 sv_setnv_mg (req->sv1, (NV)req->seq_t);
352 402
353 SvREFCNT_dec (req->sv1); 403 SvREFCNT_dec (req->sv1);
354 break; 404 break;
405#endif
355 } 406 }
356 407
357 errno = req->result; 408 errno = req->result;
358 409
359 PUTBACK; 410 PUTBACK;
365 } 416 }
366 417
367 return !SvTRUE (ERRSV); 418 return !SvTRUE (ERRSV);
368} 419}
369 420
370static void req_free (aio_req req) 421static void req_free (bdb_req req)
371{ 422{
423 SvREFCNT_dec (req->callback);
424
372 free (req->buf1); 425 free (req->buf1);
373 free (req->buf2); 426 free (req->buf2);
427 free (req->buf3);
428
374 Safefree (req); 429 Safefree (req);
375} 430}
376 431
377#ifdef USE_SOCKETS_AS_HANDLES 432#ifdef USE_SOCKETS_AS_HANDLES
378# define TO_SOCKET(x) (win32_get_osfhandle (x)) 433# define TO_SOCKET(x) (win32_get_osfhandle (x))
379#else 434#else
380# define TO_SOCKET(x) (x) 435# define TO_SOCKET(x) (x)
381#endif 436#endif
382 437
383static void 438static void
384create_respipe () 439create_respipe (void)
385{ 440{
386#ifdef _WIN32 441#ifdef _WIN32
387 int arg; /* argg */ 442 int arg; /* argg */
388#endif 443#endif
389 int old_readfd = respipe [0]; 444 int old_readfd = respipe [0];
443 free (wrk); 498 free (wrk);
444 499
445 X_UNLOCK (wrklock); 500 X_UNLOCK (wrklock);
446} 501}
447 502
448static void maybe_start_thread () 503static void maybe_start_thread (void)
449{ 504{
450 if (get_nthreads () >= wanted) 505 if (get_nthreads () >= wanted)
451 return; 506 return;
452 507
453 /* todo: maybe use idle here, but might be less exact */ 508 /* todo: maybe use idle here, but might be less exact */
455 return; 510 return;
456 511
457 start_thread (); 512 start_thread ();
458} 513}
459 514
460static void req_send (aio_req req) 515static void req_send (bdb_req req)
461{ 516{
462 SV *wait_callback = 0; 517 SV *wait_callback = 0;
463 518
519 if (on_next_submit)
520 {
521 dSP;
522 SV *cb = sv_2mortal (on_next_submit);
523
524 on_next_submit = 0;
525
526 PUSHMARK (SP);
527 PUTBACK;
528 call_sv (cb, G_DISCARD | G_EVAL);
529 }
530
464 // synthesize callback if none given 531 // synthesize callback if none given
465 if (!SvOK (req->callback)) 532 if (!req->callback)
466 { 533 {
467 int count; 534 int count;
468 535
469 dSP; 536 dSP;
470 PUSHMARK (SP); 537 PUSHMARK (SP);
473 SPAGAIN; 540 SPAGAIN;
474 541
475 if (count != 2) 542 if (count != 2)
476 croak ("prepare callback must return exactly two values\n"); 543 croak ("prepare callback must return exactly two values\n");
477 544
478 wait_callback = SvREFCNT_inc (POPs); 545 wait_callback = POPs;
479 SvREFCNT_dec (req->callback); 546 SvREFCNT_dec (req->callback);
480 req->callback = SvREFCNT_inc (POPs); 547 req->callback = SvREFCNT_inc (POPs);
481 } 548 }
482 549
483 ++nreqs; 550 ++nreqs;
494 { 561 {
495 dSP; 562 dSP;
496 PUSHMARK (SP); 563 PUSHMARK (SP);
497 PUTBACK; 564 PUTBACK;
498 call_sv (wait_callback, G_DISCARD); 565 call_sv (wait_callback, G_DISCARD);
499 SvREFCNT_dec (wait_callback);
500 } 566 }
501} 567}
502 568
503static void end_thread (void) 569static void end_thread (void)
504{ 570{
505 aio_req req; 571 bdb_req req;
506 572
507 Newz (0, req, 1, aio_cb); 573 Newz (0, req, 1, bdb_cb);
508 574
509 req->type = REQ_QUIT; 575 req->type = REQ_QUIT;
510 req->pri = PRI_MAX + PRI_BIAS; 576 req->pri = PRI_MAX + PRI_BIAS;
511 577
512 X_LOCK (reqlock); 578 X_LOCK (reqlock);
539 605
540 while (started > wanted) 606 while (started > wanted)
541 end_thread (); 607 end_thread ();
542} 608}
543 609
544static void poll_wait () 610static void poll_wait (void)
545{ 611{
546 fd_set rfd; 612 fd_set rfd;
547 613
548 while (nreqs) 614 while (nreqs)
549 { 615 {
562 628
563 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); 629 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
564 } 630 }
565} 631}
566 632
567static int poll_cb () 633static int poll_cb (void)
568{ 634{
569 dSP; 635 dSP;
570 int count = 0; 636 int count = 0;
571 int maxreqs = max_poll_reqs; 637 int maxreqs = max_poll_reqs;
572 int do_croak = 0; 638 int do_croak = 0;
573 struct timeval tv_start, tv_now; 639 struct timeval tv_start, tv_now;
574 aio_req req; 640 bdb_req req;
575 641
576 if (max_poll_time) 642 if (max_poll_time)
577 gettimeofday (&tv_start, 0); 643 gettimeofday (&tv_start, 0);
578 644
579 for (;;) 645 for (;;)
640 706
641/*****************************************************************************/ 707/*****************************************************************************/
642 708
643X_THREAD_PROC (bdb_proc) 709X_THREAD_PROC (bdb_proc)
644{ 710{
645 aio_req req; 711 bdb_req req;
646 struct timespec ts; 712 struct timespec ts;
647 worker *self = (worker *)thr_arg; 713 worker *self = (worker *)thr_arg;
648 714
649 /* try to distribute timeouts somewhat evenly */ 715 /* try to distribute timeouts somewhat evenly */
650 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 716 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
717 783
718 case REQ_ENV_MEMP_TRICKLE: 784 case REQ_ENV_MEMP_TRICKLE:
719 req->result = req->env->memp_trickle (req->env, req->int1, &req->int2); 785 req->result = req->env->memp_trickle (req->env, req->int1, &req->int2);
720 break; 786 break;
721 787
788 case REQ_ENV_DBREMOVE:
789 req->result = req->env->dbremove (req->env, req->txn, req->buf1, req->buf2, req->uint1);
790 break;
791
792 case REQ_ENV_DBRENAME:
793 req->result = req->env->dbrename (req->env, req->txn, req->buf1, req->buf2, req->buf3, req->uint1);
794 break;
795
722 case REQ_DB_OPEN: 796 case REQ_DB_OPEN:
723 req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2); 797 req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2);
724 break; 798 break;
725 799
726 case REQ_DB_CLOSE: 800 case REQ_DB_CLOSE:
727 req->result = req->db->close (req->db, req->uint1); 801 req->result = req->db->close (req->db, req->uint1);
728 break; 802 break;
729 803
804#if DB_VERSION_MINOR >= 4
730 case REQ_DB_COMPACT: 805 case REQ_DB_COMPACT:
731 req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0); 806 req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0);
732 break; 807 break;
808#endif
733 809
734 case REQ_DB_SYNC: 810 case REQ_DB_SYNC:
735 req->result = req->db->sync (req->db, req->uint1); 811 req->result = req->db->sync (req->db, req->uint1);
736 break; 812 break;
737 813
814 case REQ_DB_UPGRADE:
815 req->result = req->db->upgrade (req->db, req->buf1, req->uint1);
816 break;
817
738 case REQ_DB_PUT: 818 case REQ_DB_PUT:
739 req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); 819 req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1);
740 break; 820 break;
741 821
822#if DB_VERSION_MINOR >= 6
823 case REQ_DB_EXISTS:
824 req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1);
825 break;
826#endif
742 case REQ_DB_GET: 827 case REQ_DB_GET:
743 req->result = req->db->get (req->db, req->txn, &req->dbt1, &req->dbt3, req->uint1); 828 req->result = req->db->get (req->db, req->txn, &req->dbt1, &req->dbt3, req->uint1);
744 break; 829 break;
745 830
746 case REQ_DB_PGET: 831 case REQ_DB_PGET:
800 885
801 case REQ_C_DEL: 886 case REQ_C_DEL:
802 req->result = req->dbc->c_del (req->dbc, req->uint1); 887 req->result = req->dbc->c_del (req->dbc, req->uint1);
803 break; 888 break;
804 889
890#if DB_VERSION_MINOR >= 3
805 case REQ_SEQ_OPEN: 891 case REQ_SEQ_OPEN:
806 req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); 892 req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1);
807 break; 893 break;
808 894
809 case REQ_SEQ_CLOSE: 895 case REQ_SEQ_CLOSE:
815 break; 901 break;
816 902
817 case REQ_SEQ_REMOVE: 903 case REQ_SEQ_REMOVE:
818 req->result = req->seq->remove (req->seq, req->txn, req->uint1); 904 req->result = req->seq->remove (req->seq, req->txn, req->uint1);
819 break; 905 break;
906#endif
820 907
821 default: 908 default:
822 req->result = ENOSYS; 909 req->result = ENOSYS;
823 break; 910 break;
824 } 911 }
864 X_UNLOCK (wrklock); 951 X_UNLOCK (wrklock);
865} 952}
866 953
867static void atfork_child (void) 954static void atfork_child (void)
868{ 955{
869 aio_req prv; 956 bdb_req prv;
870 957
871 while (prv = reqq_shift (&req_queue)) 958 while (prv = reqq_shift (&req_queue))
872 req_free (prv); 959 req_free (prv);
873 960
874 while (prv = reqq_shift (&res_queue)) 961 while (prv = reqq_shift (&res_queue))
895 982
896 atfork_parent (); 983 atfork_parent ();
897} 984}
898 985
899#define dREQ(reqtype) \ 986#define dREQ(reqtype) \
900 aio_req req; \ 987 bdb_req req; \
901 int req_pri = next_pri; \ 988 int req_pri = next_pri; \
902 next_pri = DEFAULT_PRI + PRI_BIAS; \ 989 next_pri = DEFAULT_PRI + PRI_BIAS; \
903 \ 990 \
904 if (SvOK (callback) && !SvROK (callback)) \ 991 if (callback && SvOK (callback)) \
905 croak ("callback must be undef or of reference type"); \ 992 croak ("callback has illegal type or extra arguments"); \
906 \ 993 \
907 Newz (0, req, 1, aio_cb); \ 994 Newz (0, req, 1, bdb_cb); \
908 if (!req) \ 995 if (!req) \
909 croak ("out of memory during aio_req allocation"); \ 996 croak ("out of memory during bdb_req allocation"); \
910 \ 997 \
911 req->callback = newSVsv (callback); \ 998 req->callback = cb ? SvREFCNT_inc (cb) : 0; \
912 req->type = (reqtype); \ 999 req->type = (reqtype); \
913 req->pri = req_pri 1000 req->pri = req_pri
914 1001
915#define REQ_SEND \ 1002#define REQ_SEND \
916 req_send (req) 1003 req_send (req)
917 1004
918#define SvPTR(var, arg, type, class, nullok) \ 1005#define SvPTR(var, arg, type, class, nullok) \
919 if (!SvOK (arg)) \ 1006 if (!SvOK (arg)) \
920 { \ 1007 { \
921 if (!nullok) \ 1008 if (nullok != 1) \
922 croak (# var " must be a " # class " object, not undef"); \ 1009 croak (# var " must be a " # class " object, not undef"); \
923 \ 1010 \
924 (var) = 0; \ 1011 (var) = 0; \
925 } \ 1012 } \
926 else if (sv_derived_from ((arg), # class)) \ 1013 else if (sv_derived_from ((arg), # class)) \
927 { \ 1014 { \
928 IV tmp = SvIV ((SV*) SvRV (arg)); \ 1015 IV tmp = SvIV ((SV*) SvRV (arg)); \
929 (var) = INT2PTR (type, tmp); \ 1016 (var) = INT2PTR (type, tmp); \
930 if (!var) \ 1017 if (!var && nullok != 2) \
931 croak (# var " is not a valid " # class " object anymore"); \ 1018 croak (# var " is not a valid " # class " object anymore"); \
932 } \ 1019 } \
933 else \ 1020 else \
934 croak (# var " is not of type " # class); \ 1021 croak (# var " is not of type " # class);
935 \
936 1022
937static void 1023static void
938ptr_nuke (SV *sv) 1024ptr_nuke (SV *sv)
939{ 1025{
940 assert (SvROK (sv)); 1026 assert (SvROK (sv));
941 sv_setiv (SvRV (sv), 0); 1027 sv_setiv (SvRV (sv), 0);
942} 1028}
1029
1030static int
1031errno_get (pTHX_ SV *sv, MAGIC *mg)
1032{
1033 if (*mg->mg_ptr == '!') // should always be the case
1034 if (-30999 <= errno && errno <= -30800)
1035 {
1036 sv_setnv (sv, (NV)errno);
1037 sv_setpv (sv, db_strerror (errno));
1038 SvNOK_on (sv); /* what a wonderful hack! */
1039 // ^^^ copied from perl sources
1040 return 0;
1041 }
1042
1043 return PL_vtbl_sv.svt_get (aTHX_ sv, mg);
1044}
1045
1046static MGVTBL vtbl_errno;
1047
1048// this wonderful hack :( patches perl's $! variable to support our errno values
1049static void
1050patch_errno (void)
1051{
1052 SV *sv;
1053 MAGIC *mg;
1054
1055 if (!(sv = get_sv ("!", 1)))
1056 return;
1057
1058 if (!(mg = mg_find (sv, PERL_MAGIC_sv)))
1059 return;
1060
1061 if (mg->mg_virtual != &PL_vtbl_sv)
1062 return;
1063
1064 vtbl_errno = PL_vtbl_sv;
1065 vtbl_errno.svt_get = errno_get;
1066 mg->mg_virtual = &vtbl_errno;
1067}
1068
1069#if __GNUC__ >= 4
1070# define noinline __attribute__ ((noinline))
1071#else
1072# define noinline
1073#endif
1074
1075static noinline SV *
1076pop_callback (I32 *ritems, SV *sv)
1077{
1078 if (SvROK (sv))
1079 {
1080 HV *st;
1081 GV *gvp;
1082 CV *cv;
1083 const char *name;
1084
1085 /* forgive me */
1086 if (SvTYPE (SvRV (sv)) == SVt_PVMG
1087 && (st = SvSTASH (SvRV (sv)))
1088 && (name = HvNAME_get (st))
1089 && (name [0] == 'B' && name [1] == 'D' && name [2] == 'B' && name [3] == ':'))
1090 return 0;
1091
1092 if ((cv = sv_2cv (sv, &st, &gvp, 0)))
1093 {
1094 --*ritems;
1095 return (SV *)cv;
1096 }
1097 }
1098
1099 return 0;
1100}
1101
1102/* stupid windoes defined CALLBACK as well */
1103#undef CALLBACK
1104#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1));
943 1105
944MODULE = BDB PACKAGE = BDB 1106MODULE = BDB PACKAGE = BDB
945 1107
946PROTOTYPES: ENABLE 1108PROTOTYPES: ENABLE
947 1109
968 const_iv (RDONLY) 1130 const_iv (RDONLY)
969 const_iv (USE_ENVIRON) 1131 const_iv (USE_ENVIRON)
970 const_iv (USE_ENVIRON_ROOT) 1132 const_iv (USE_ENVIRON_ROOT)
971 const_iv (LOCKDOWN) 1133 const_iv (LOCKDOWN)
972 const_iv (PRIVATE) 1134 const_iv (PRIVATE)
973 const_iv (REGISTER)
974 const_iv (SYSTEM_MEM) 1135 const_iv (SYSTEM_MEM)
975 const_iv (AUTO_COMMIT) 1136 const_iv (AUTO_COMMIT)
976 const_iv (CDB_ALLDB) 1137 const_iv (CDB_ALLDB)
977 const_iv (DIRECT_DB) 1138 const_iv (DIRECT_DB)
978 const_iv (DIRECT_LOG)
979 const_iv (DSYNC_DB)
980 const_iv (DSYNC_LOG)
981 const_iv (LOG_AUTOREMOVE)
982 const_iv (LOG_INMEMORY)
983 const_iv (NOLOCKING) 1139 const_iv (NOLOCKING)
984 const_iv (NOMMAP) 1140 const_iv (NOMMAP)
985 const_iv (NOPANIC) 1141 const_iv (NOPANIC)
986 const_iv (OVERWRITE) 1142 const_iv (OVERWRITE)
987 const_iv (PANIC_ENVIRONMENT) 1143 const_iv (PANIC_ENVIRONMENT)
998 const_iv (HASH) 1154 const_iv (HASH)
999 const_iv (QUEUE) 1155 const_iv (QUEUE)
1000 const_iv (RECNO) 1156 const_iv (RECNO)
1001 const_iv (UNKNOWN) 1157 const_iv (UNKNOWN)
1002 const_iv (EXCL) 1158 const_iv (EXCL)
1003 const_iv (READ_COMMITTED)
1004 const_iv (READ_UNCOMMITTED)
1005 const_iv (TRUNCATE) 1159 const_iv (TRUNCATE)
1006 const_iv (NOSYNC) 1160 const_iv (NOSYNC)
1007 const_iv (CHKSUM) 1161 const_iv (CHKSUM)
1008 const_iv (ENCRYPT) 1162 const_iv (ENCRYPT)
1009 const_iv (DUP) 1163 const_iv (DUP)
1010 const_iv (DUPSORT) 1164 const_iv (DUPSORT)
1011 const_iv (RECNUM) 1165 const_iv (RECNUM)
1012 const_iv (RENUMBER) 1166 const_iv (RENUMBER)
1013 const_iv (REVSPLITOFF) 1167 const_iv (REVSPLITOFF)
1014 const_iv (INORDER)
1015 const_iv (CONSUME) 1168 const_iv (CONSUME)
1016 const_iv (CONSUME_WAIT) 1169 const_iv (CONSUME_WAIT)
1017 const_iv (GET_BOTH) 1170 const_iv (GET_BOTH)
1018 const_iv (GET_BOTH_RANGE) 1171 const_iv (GET_BOTH_RANGE)
1019 //const_iv (SET_RECNO) 1172 //const_iv (SET_RECNO)
1020 //const_iv (MULTIPLE) 1173 //const_iv (MULTIPLE)
1021 const_iv (SNAPSHOT) 1174 const_iv (SNAPSHOT)
1022 const_iv (JOIN_ITEM) 1175 const_iv (JOIN_ITEM)
1176 const_iv (JOIN_NOSORT)
1023 const_iv (RMW) 1177 const_iv (RMW)
1024 1178
1025 const_iv (NOTFOUND) 1179 const_iv (NOTFOUND)
1026 const_iv (KEYEMPTY) 1180 const_iv (KEYEMPTY)
1027 const_iv (LOCK_DEADLOCK) 1181 const_iv (LOCK_DEADLOCK)
1028 const_iv (LOCK_NOTGRANTED) 1182 const_iv (LOCK_NOTGRANTED)
1029 const_iv (RUNRECOVERY) 1183 const_iv (RUNRECOVERY)
1030 const_iv (OLD_VERSION) 1184 const_iv (OLD_VERSION)
1031 const_iv (REP_HANDLE_DEAD) 1185 const_iv (REP_HANDLE_DEAD)
1032 const_iv (REP_LOCKOUT)
1033 const_iv (SECONDARY_BAD) 1186 const_iv (SECONDARY_BAD)
1034
1035 const_iv (FREE_SPACE)
1036 const_iv (FREELIST_ONLY)
1037 1187
1038 const_iv (APPEND) 1188 const_iv (APPEND)
1039 const_iv (NODUPDATA) 1189 const_iv (NODUPDATA)
1040 const_iv (NOOVERWRITE) 1190 const_iv (NOOVERWRITE)
1041 1191
1043 const_iv (TXN_SYNC) 1193 const_iv (TXN_SYNC)
1044 1194
1045 const_iv (SET_LOCK_TIMEOUT) 1195 const_iv (SET_LOCK_TIMEOUT)
1046 const_iv (SET_TXN_TIMEOUT) 1196 const_iv (SET_TXN_TIMEOUT)
1047 1197
1048 const_iv (JOIN_ITEM)
1049 const_iv (FIRST) 1198 const_iv (FIRST)
1050 const_iv (NEXT) 1199 const_iv (NEXT)
1051 const_iv (NEXT_DUP) 1200 const_iv (NEXT_DUP)
1052 const_iv (NEXT_NODUP) 1201 const_iv (NEXT_NODUP)
1053 const_iv (PREV) 1202 const_iv (PREV)
1065 const_iv (FORCE) 1214 const_iv (FORCE)
1066 1215
1067 const_iv (LOCK_DEFAULT) 1216 const_iv (LOCK_DEFAULT)
1068 const_iv (LOCK_EXPIRE) 1217 const_iv (LOCK_EXPIRE)
1069 const_iv (LOCK_MAXLOCKS) 1218 const_iv (LOCK_MAXLOCKS)
1070 const_iv (LOCK_MAXWRITE)
1071 const_iv (LOCK_MINLOCKS) 1219 const_iv (LOCK_MINLOCKS)
1072 const_iv (LOCK_MINWRITE) 1220 const_iv (LOCK_MINWRITE)
1073 const_iv (LOCK_OLDEST) 1221 const_iv (LOCK_OLDEST)
1074 const_iv (LOCK_RANDOM) 1222 const_iv (LOCK_RANDOM)
1075 const_iv (LOCK_YOUNGEST) 1223 const_iv (LOCK_YOUNGEST)
1076 1224
1077 const_iv (SEQ_DEC)
1078 const_iv (SEQ_INC)
1079 const_iv (SEQ_WRAP)
1080
1081 const_iv (BUFFER_SMALL)
1082 const_iv (DONOTINDEX) 1225 const_iv (DONOTINDEX)
1083 const_iv (KEYEMPTY ) 1226 const_iv (KEYEMPTY )
1084 const_iv (KEYEXIST ) 1227 const_iv (KEYEXIST )
1085 const_iv (LOCK_DEADLOCK) 1228 const_iv (LOCK_DEADLOCK)
1086 const_iv (LOCK_NOTGRANTED) 1229 const_iv (LOCK_NOTGRANTED)
1087 const_iv (LOG_BUFFER_FULL)
1088 const_iv (NOSERVER) 1230 const_iv (NOSERVER)
1089 const_iv (NOSERVER_HOME) 1231 const_iv (NOSERVER_HOME)
1090 const_iv (NOSERVER_ID) 1232 const_iv (NOSERVER_ID)
1091 const_iv (NOTFOUND) 1233 const_iv (NOTFOUND)
1092 const_iv (OLD_VERSION)
1093 const_iv (PAGE_NOTFOUND) 1234 const_iv (PAGE_NOTFOUND)
1094 const_iv (REP_DUPMASTER) 1235 const_iv (REP_DUPMASTER)
1095 const_iv (REP_HANDLE_DEAD) 1236 const_iv (REP_HANDLE_DEAD)
1096 const_iv (REP_HOLDELECTION) 1237 const_iv (REP_HOLDELECTION)
1097 const_iv (REP_IGNORE)
1098 const_iv (REP_ISPERM) 1238 const_iv (REP_ISPERM)
1099 const_iv (REP_JOIN_FAILURE)
1100 const_iv (REP_LOCKOUT)
1101 const_iv (REP_NEWMASTER) 1239 const_iv (REP_NEWMASTER)
1102 const_iv (REP_NEWSITE) 1240 const_iv (REP_NEWSITE)
1103 const_iv (REP_NOTPERM) 1241 const_iv (REP_NOTPERM)
1104 const_iv (REP_UNAVAIL) 1242 const_iv (REP_UNAVAIL)
1105 const_iv (RUNRECOVERY) 1243 const_iv (RUNRECOVERY)
1106 const_iv (SECONDARY_BAD) 1244 const_iv (SECONDARY_BAD)
1107 const_iv (VERIFY_BAD) 1245 const_iv (VERIFY_BAD)
1108 const_iv (VERSION_MISMATCH)
1109 1246
1110 const_iv (VERB_DEADLOCK) 1247 const_iv (VERB_DEADLOCK)
1111 const_iv (VERB_RECOVERY) 1248 const_iv (VERB_RECOVERY)
1112 const_iv (VERB_REGISTER)
1113 const_iv (VERB_REPLICATION) 1249 const_iv (VERB_REPLICATION)
1114 const_iv (VERB_WAITSFOR) 1250 const_iv (VERB_WAITSFOR)
1115 1251
1116 const_iv (VERSION_MAJOR) 1252 const_iv (VERSION_MAJOR)
1117 const_iv (VERSION_MINOR) 1253 const_iv (VERSION_MINOR)
1118 const_iv (VERSION_PATCH) 1254 const_iv (VERSION_PATCH)
1255#if DB_VERSION_MINOR >= 3
1256 const_iv (INORDER)
1257 const_iv (LOCK_MAXWRITE)
1258 const_iv (SEQ_DEC)
1259 const_iv (SEQ_INC)
1260 const_iv (SEQ_WRAP)
1261 const_iv (BUFFER_SMALL)
1262 const_iv (LOG_BUFFER_FULL)
1263 const_iv (VERSION_MISMATCH)
1264#endif
1265#if DB_VERSION_MINOR >= 4
1266 const_iv (REGISTER)
1267 const_iv (DSYNC_DB)
1268 const_iv (READ_COMMITTED)
1269 const_iv (READ_UNCOMMITTED)
1270 const_iv (REP_IGNORE)
1271 const_iv (REP_LOCKOUT)
1272 const_iv (REP_JOIN_FAILURE)
1273 const_iv (FREE_SPACE)
1274 const_iv (FREELIST_ONLY)
1275 const_iv (VERB_REGISTER)
1276#endif
1119#if DB_VERSION_MINOR >= 5 1277#if DB_VERSION_MINOR >= 5
1120 const_iv (MULTIVERSION) 1278 const_iv (MULTIVERSION)
1121 const_iv (TXN_SNAPSHOT) 1279 const_iv (TXN_SNAPSHOT)
1122#endif 1280#endif
1123#if DB_VERSION_MINOR >= 6 1281#if DB_VERSION_MINOR >= 6
1124 const_iv (PREV_DUP) 1282 const_iv (PREV_DUP)
1125# if 0
1126 const_iv (PRIORITY_UNCHANGED) 1283 const_iv (PRIORITY_UNCHANGED)
1127 const_iv (PRIORITY_VERY_LOW) 1284 const_iv (PRIORITY_VERY_LOW)
1128 const_iv (PRIORITY_LOW) 1285 const_iv (PRIORITY_LOW)
1129 const_iv (PRIORITY_DEFAULT) 1286 const_iv (PRIORITY_DEFAULT)
1130 const_iv (PRIORITY_HIGH) 1287 const_iv (PRIORITY_HIGH)
1131 const_iv (PRIORITY_VERY_HIGH) 1288 const_iv (PRIORITY_VERY_HIGH)
1289#endif
1290#if DB_VERSION_MINOR >= 7
1291 const_iv (LOG_DIRECT)
1292 const_iv (LOG_DSYNC)
1293 const_iv (LOG_AUTO_REMOVE)
1294 const_iv (LOG_IN_MEMORY)
1295 const_iv (LOG_ZERO)
1296#else
1297 const_iv (DIRECT_LOG)
1298 const_iv (LOG_AUTOREMOVE)
1299# if DB_VERSION_MINOR >= 3
1300 const_iv (DSYNC_LOG)
1301 const_iv (LOG_INMEMORY)
1132# endif 1302# endif
1133#endif 1303#endif
1134 }; 1304 };
1135 1305
1136 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1306 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1137 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1307 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1138 1308
1139 newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); 1309 {
1310 /* we currently only allow version, minor-version and patchlevel to go up to 255 */
1311 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH };
1312
1313 newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3));
1314 }
1315
1140 newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1316 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1141 1317
1142 create_respipe (); 1318 create_respipe ();
1143 1319
1144 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1320 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1145#ifdef _WIN32 1321 patch_errno ();
1146 X_MUTEX_CHECK (wrklock);
1147 X_MUTEX_CHECK (reslock);
1148 X_MUTEX_CHECK (reqlock);
1149
1150 X_COND_CHECK (reqwait);
1151#endif
1152} 1322}
1153 1323
1154void 1324void
1155max_poll_reqs (int nreqs) 1325max_poll_reqs (int nreqs)
1156 PROTOTYPE: $ 1326 PROTOTYPE: $
1296 CODE: 1466 CODE:
1297 RETVAL = db_strerror (errorno); 1467 RETVAL = db_strerror (errorno);
1298 OUTPUT: 1468 OUTPUT:
1299 RETVAL 1469 RETVAL
1300 1470
1471void _on_next_submit (SV *cb)
1472 CODE:
1473 SvREFCNT_dec (on_next_submit);
1474 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1475
1301DB_ENV * 1476DB_ENV *
1302db_env_create (U32 env_flags = 0) 1477db_env_create (U32 env_flags = 0)
1303 CODE: 1478 CODE:
1304{ 1479{
1305 errno = db_env_create (&RETVAL, env_flags); 1480 errno = db_env_create (&RETVAL, env_flags);
1314} 1489}
1315 OUTPUT: 1490 OUTPUT:
1316 RETVAL 1491 RETVAL
1317 1492
1318void 1493void
1319db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) 1494db_env_open (DB_ENV *env, bdb_filename db_home, U32 open_flags, int mode, SV *callback = 0)
1495 PREINIT:
1496 CALLBACK
1320 CODE: 1497 CODE:
1321{ 1498{
1322 dREQ (REQ_ENV_OPEN); 1499 dREQ (REQ_ENV_OPEN);
1323
1324 env->set_thread_count (env, wanted + 2);
1325
1326 req->env = env; 1500 req->env = env;
1327 req->uint1 = open_flags | DB_THREAD; 1501 req->uint1 = open_flags | DB_THREAD;
1328 req->int1 = mode; 1502 req->int1 = mode;
1329 req->buf1 = strdup_ornull (db_home); 1503 req->buf1 = strdup_ornull (db_home);
1330 REQ_SEND; 1504 REQ_SEND;
1331} 1505}
1332 1506
1333void 1507void
1334db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = &PL_sv_undef) 1508db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0)
1509 PREINIT:
1510 CALLBACK
1335 CODE: 1511 CODE:
1336{ 1512{
1337 dREQ (REQ_ENV_CLOSE); 1513 dREQ (REQ_ENV_CLOSE);
1338 req->env = env; 1514 req->env = env;
1339 req->uint1 = flags; 1515 req->uint1 = flags;
1340 REQ_SEND; 1516 REQ_SEND;
1341 ptr_nuke (ST (0)); 1517 ptr_nuke (ST (0));
1342} 1518}
1343 1519
1344void 1520void
1345db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = &PL_sv_undef) 1521db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0)
1522 PREINIT:
1523 CALLBACK
1346 CODE: 1524 CODE:
1347{ 1525{
1348 dREQ (REQ_ENV_TXN_CHECKPOINT); 1526 dREQ (REQ_ENV_TXN_CHECKPOINT);
1349 req->env = env; 1527 req->env = env;
1350 req->uint1 = kbyte; 1528 req->uint1 = kbyte;
1352 req->uint2 = flags; 1530 req->uint2 = flags;
1353 REQ_SEND; 1531 REQ_SEND;
1354} 1532}
1355 1533
1356void 1534void
1357db_env_lock_detect (DB_ENV *env, U32 flags = 0, U32 atype = DB_LOCK_DEFAULT, SV *dummy = 0, SV *callback = &PL_sv_undef) 1535db_env_lock_detect (DB_ENV *env, U32 flags = 0, U32 atype = DB_LOCK_DEFAULT, SV *dummy = 0, SV *callback = 0)
1536 PREINIT:
1537 CALLBACK
1358 CODE: 1538 CODE:
1359{ 1539{
1360 dREQ (REQ_ENV_LOCK_DETECT); 1540 dREQ (REQ_ENV_LOCK_DETECT);
1361 req->env = env; 1541 req->env = env;
1362 req->uint1 = flags; 1542 req->uint1 = flags;
1363 req->uint2 = atype; 1543 req->uint2 = atype;
1544 /* req->int2 = 0; dummy */
1364 REQ_SEND; 1545 REQ_SEND;
1365} 1546}
1366 1547
1367void 1548void
1368db_env_memp_sync (DB_ENV *env, SV *dummy = 0, SV *callback = &PL_sv_undef) 1549db_env_memp_sync (DB_ENV *env, SV *dummy = 0, SV *callback = 0)
1550 PREINIT:
1551 CALLBACK
1369 CODE: 1552 CODE:
1370{ 1553{
1371 dREQ (REQ_ENV_MEMP_SYNC); 1554 dREQ (REQ_ENV_MEMP_SYNC);
1372 req->env = env; 1555 req->env = env;
1373 REQ_SEND; 1556 REQ_SEND;
1374} 1557}
1375 1558
1376void 1559void
1377db_env_memp_trickle (DB_ENV *env, int percent, SV *dummy = 0, SV *callback = &PL_sv_undef) 1560db_env_memp_trickle (DB_ENV *env, int percent, SV *dummy = 0, SV *callback = 0)
1561 PREINIT:
1562 CALLBACK
1378 CODE: 1563 CODE:
1379{ 1564{
1380 dREQ (REQ_ENV_MEMP_TRICKLE); 1565 dREQ (REQ_ENV_MEMP_TRICKLE);
1381 req->env = env; 1566 req->env = env;
1382 req->int1 = percent; 1567 req->int1 = percent;
1383 REQ_SEND; 1568 REQ_SEND;
1384} 1569}
1385 1570
1571void
1572db_env_dbremove (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, U32 flags = 0, SV *callback = 0)
1573 PREINIT:
1574 CALLBACK
1575 CODE:
1576{
1577 dREQ (REQ_ENV_DBREMOVE);
1578 req->env = env;
1579 req->buf1 = strdup_ornull (file);
1580 req->buf2 = strdup_ornull (database);
1581 req->uint1 = flags;
1582 REQ_SEND;
1583}
1584
1585void
1586db_env_dbrename (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, bdb_filename newname, U32 flags = 0, SV *callback = 0)
1587 PREINIT:
1588 CALLBACK
1589 CODE:
1590{
1591 dREQ (REQ_ENV_DBRENAME);
1592 req->env = env;
1593 req->buf1 = strdup_ornull (file);
1594 req->buf2 = strdup_ornull (database);
1595 req->buf3 = strdup_ornull (newname);
1596 req->uint1 = flags;
1597 REQ_SEND;
1598}
1386 1599
1387DB * 1600DB *
1388db_create (DB_ENV *env = 0, U32 flags = 0) 1601db_create (DB_ENV *env = 0, U32 flags = 0)
1389 CODE: 1602 CODE:
1390{ 1603{
1397} 1610}
1398 OUTPUT: 1611 OUTPUT:
1399 RETVAL 1612 RETVAL
1400 1613
1401void 1614void
1402db_open (DB *db, DB_TXN_ornull *txnid, octetstring file, octetstring database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) 1615db_open (DB *db, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, int type, U32 flags, int mode, SV *callback = 0)
1616 PREINIT:
1617 CALLBACK
1403 CODE: 1618 CODE:
1404{ 1619{
1405 dREQ (REQ_DB_OPEN); 1620 dREQ (REQ_DB_OPEN);
1406 req->db = db; 1621 req->db = db;
1407 req->txn = txnid; 1622 req->txn = txnid;
1412 req->int2 = mode; 1627 req->int2 = mode;
1413 REQ_SEND; 1628 REQ_SEND;
1414} 1629}
1415 1630
1416void 1631void
1417db_close (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) 1632db_close (DB *db, U32 flags = 0, SV *callback = 0)
1633 PREINIT:
1634 CALLBACK
1418 CODE: 1635 CODE:
1419{ 1636{
1420 dREQ (REQ_DB_CLOSE); 1637 dREQ (REQ_DB_CLOSE);
1421 req->db = db; 1638 req->db = db;
1422 req->uint1 = flags; 1639 req->uint1 = flags;
1423 req->sv1 = (SV *)db->app_private; 1640 req->sv1 = (SV *)db->app_private;
1424 REQ_SEND; 1641 REQ_SEND;
1425 ptr_nuke (ST (0)); 1642 ptr_nuke (ST (0));
1426} 1643}
1427 1644
1645#if DB_VERSION_MINOR >= 4
1646
1428void 1647void
1429db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = &PL_sv_undef) 1648db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = 0)
1649 PREINIT:
1650 CALLBACK
1430 CODE: 1651 CODE:
1431{ 1652{
1432 dREQ (REQ_DB_COMPACT); 1653 dREQ (REQ_DB_COMPACT);
1433 req->db = db; 1654 req->db = db;
1434 req->txn = txn; 1655 req->txn = txn;
1436 sv_to_dbt (&req->dbt2, stop); 1657 sv_to_dbt (&req->dbt2, stop);
1437 req->uint1 = flags; 1658 req->uint1 = flags;
1438 REQ_SEND; 1659 REQ_SEND;
1439} 1660}
1440 1661
1662#endif
1663
1441void 1664void
1442db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) 1665db_sync (DB *db, U32 flags = 0, SV *callback = 0)
1666 PREINIT:
1667 CALLBACK
1443 CODE: 1668 CODE:
1444{ 1669{
1445 dREQ (REQ_DB_SYNC); 1670 dREQ (REQ_DB_SYNC);
1446 req->db = db; 1671 req->db = db;
1447 req->uint1 = flags; 1672 req->uint1 = flags;
1448 REQ_SEND; 1673 REQ_SEND;
1449} 1674}
1450 1675
1451void 1676void
1677db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0)
1678 PREINIT:
1679 CALLBACK
1680 CODE:
1681{
1682 dREQ (REQ_DB_SYNC);
1683 req->db = db;
1684 req->buf1 = strdup (file);
1685 req->uint1 = flags;
1686 REQ_SEND;
1687}
1688
1689void
1452db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) 1690db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = 0)
1691 PREINIT:
1692 CALLBACK
1453 CODE: 1693 CODE:
1454{ 1694{
1455 dREQ (REQ_DB_KEY_RANGE); 1695 dREQ (REQ_DB_KEY_RANGE);
1456 req->db = db; 1696 req->db = db;
1457 req->txn = txn; 1697 req->txn = txn;
1460 req->sv1 = SvREFCNT_inc (key_range); SvREADONLY_on (key_range); 1700 req->sv1 = SvREFCNT_inc (key_range); SvREADONLY_on (key_range);
1461 REQ_SEND; 1701 REQ_SEND;
1462} 1702}
1463 1703
1464void 1704void
1465db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 1705db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0)
1706 PREINIT:
1707 CALLBACK
1466 CODE: 1708 CODE:
1467{ 1709{
1468 dREQ (REQ_DB_PUT); 1710 dREQ (REQ_DB_PUT);
1469 req->db = db; 1711 req->db = db;
1470 req->txn = txn; 1712 req->txn = txn;
1472 sv_to_dbt (&req->dbt2, data); 1714 sv_to_dbt (&req->dbt2, data);
1473 req->uint1 = flags; 1715 req->uint1 = flags;
1474 REQ_SEND; 1716 REQ_SEND;
1475} 1717}
1476 1718
1719#if DB_VERSION_MINOR >= 6
1720
1477void 1721void
1722db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0)
1723 PREINIT:
1724 CALLBACK
1725 CODE:
1726{
1727 dREQ (REQ_DB_EXISTS);
1728 req->db = db;
1729 req->txn = txn;
1730 req->uint1 = flags;
1731 sv_to_dbt (&req->dbt1, key);
1732 REQ_SEND;
1733}
1734
1735#endif
1736
1737void
1478db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 1738db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0)
1739 PREINIT:
1740 CALLBACK
1479 CODE: 1741 CODE:
1742 if (SvREADONLY (data))
1743 croak ("can't modify read-only data scalar in db_get");
1480{ 1744{
1481 dREQ (REQ_DB_GET); 1745 dREQ (REQ_DB_GET);
1482 req->db = db; 1746 req->db = db;
1483 req->txn = txn; 1747 req->txn = txn;
1484 req->uint1 = flags; 1748 req->uint1 = flags;
1487 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 1751 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1488 REQ_SEND; 1752 REQ_SEND;
1489} 1753}
1490 1754
1491void 1755void
1492db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 1756db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0)
1757 PREINIT:
1758 CALLBACK
1493 CODE: 1759 CODE:
1760 if (SvREADONLY (data))
1761 croak ("can't modify read-only data scalar in db_pget");
1494{ 1762{
1495 dREQ (REQ_DB_PGET); 1763 dREQ (REQ_DB_PGET);
1496 req->db = db; 1764 req->db = db;
1497 req->txn = txn; 1765 req->txn = txn;
1498 req->uint1 = flags; 1766 req->uint1 = flags;
1502 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 1770 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1503 REQ_SEND; 1771 REQ_SEND;
1504} 1772}
1505 1773
1506void 1774void
1507db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) 1775db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0)
1776 PREINIT:
1777 CALLBACK
1508 CODE: 1778 CODE:
1509{ 1779{
1510 dREQ (REQ_DB_DEL); 1780 dREQ (REQ_DB_DEL);
1511 req->db = db; 1781 req->db = db;
1512 req->txn = txn; 1782 req->txn = txn;
1514 sv_to_dbt (&req->dbt1, key); 1784 sv_to_dbt (&req->dbt1, key);
1515 REQ_SEND; 1785 REQ_SEND;
1516} 1786}
1517 1787
1518void 1788void
1519db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) 1789db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1790 PREINIT:
1791 CALLBACK
1520 CODE: 1792 CODE:
1521{ 1793{
1522 dREQ (REQ_TXN_COMMIT); 1794 dREQ (REQ_TXN_COMMIT);
1523 req->txn = txn; 1795 req->txn = txn;
1524 req->uint1 = flags; 1796 req->uint1 = flags;
1525 REQ_SEND; 1797 REQ_SEND;
1526 ptr_nuke (ST (0)); 1798 ptr_nuke (ST (0));
1527} 1799}
1528 1800
1529void 1801void
1530db_txn_abort (DB_TXN *txn, SV *callback = &PL_sv_undef) 1802db_txn_abort (DB_TXN *txn, SV *callback = 0)
1803 PREINIT:
1804 CALLBACK
1531 CODE: 1805 CODE:
1532{ 1806{
1533 dREQ (REQ_TXN_ABORT); 1807 dREQ (REQ_TXN_ABORT);
1534 req->txn = txn; 1808 req->txn = txn;
1535 REQ_SEND; 1809 REQ_SEND;
1536 ptr_nuke (ST (0)); 1810 ptr_nuke (ST (0));
1537} 1811}
1538 1812
1539void 1813void
1540db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) 1814db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1815 PREINIT:
1816 CALLBACK
1541 CODE: 1817 CODE:
1542{ 1818{
1543 dREQ (REQ_TXN_FINISH); 1819 dREQ (REQ_TXN_FINISH);
1544 req->txn = txn; 1820 req->txn = txn;
1545 req->uint1 = flags; 1821 req->uint1 = flags;
1546 REQ_SEND; 1822 REQ_SEND;
1547 ptr_nuke (ST (0)); 1823 ptr_nuke (ST (0));
1548} 1824}
1549 1825
1550void 1826void
1551db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) 1827db_c_close (DBC *dbc, SV *callback = 0)
1828 PREINIT:
1829 CALLBACK
1552 CODE: 1830 CODE:
1553{ 1831{
1554 dREQ (REQ_C_CLOSE); 1832 dREQ (REQ_C_CLOSE);
1555 req->dbc = dbc; 1833 req->dbc = dbc;
1556 REQ_SEND; 1834 REQ_SEND;
1557 ptr_nuke (ST (0)); 1835 ptr_nuke (ST (0));
1558} 1836}
1559 1837
1560void 1838void
1561db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = &PL_sv_undef) 1839db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0)
1840 PREINIT:
1841 CALLBACK
1562 CODE: 1842 CODE:
1563{ 1843{
1564 dREQ (REQ_C_COUNT); 1844 dREQ (REQ_C_COUNT);
1565 req->dbc = dbc; 1845 req->dbc = dbc;
1566 req->sv1 = SvREFCNT_inc (count); 1846 req->sv1 = SvREFCNT_inc (count);
1567 REQ_SEND; 1847 REQ_SEND;
1568} 1848}
1569 1849
1570void 1850void
1571db_c_put (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 1851db_c_put (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0)
1852 PREINIT:
1853 CALLBACK
1572 CODE: 1854 CODE:
1573{ 1855{
1574 dREQ (REQ_C_PUT); 1856 dREQ (REQ_C_PUT);
1575 req->dbc = dbc; 1857 req->dbc = dbc;
1576 sv_to_dbt (&req->dbt1, key); 1858 sv_to_dbt (&req->dbt1, key);
1578 req->uint1 = flags; 1860 req->uint1 = flags;
1579 REQ_SEND; 1861 REQ_SEND;
1580} 1862}
1581 1863
1582void 1864void
1583db_c_get (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 1865db_c_get (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0)
1866 PREINIT:
1867 CALLBACK
1584 CODE: 1868 CODE:
1585{ 1869{
1586 dREQ (REQ_C_GET); 1870 dREQ (REQ_C_GET);
1587 req->dbc = dbc; 1871 req->dbc = dbc;
1588 req->uint1 = flags; 1872 req->uint1 = flags;
1603 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 1887 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1604 REQ_SEND; 1888 REQ_SEND;
1605} 1889}
1606 1890
1607void 1891void
1608db_c_pget (DBC *dbc, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 1892db_c_pget (DBC *dbc, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0)
1893 PREINIT:
1894 CALLBACK
1609 CODE: 1895 CODE:
1610{ 1896{
1611 dREQ (REQ_C_PGET); 1897 dREQ (REQ_C_PGET);
1612 req->dbc = dbc; 1898 req->dbc = dbc;
1613 req->uint1 = flags; 1899 req->uint1 = flags;
1631 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 1917 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1632 REQ_SEND; 1918 REQ_SEND;
1633} 1919}
1634 1920
1635void 1921void
1636db_c_del (DBC *dbc, U32 flags = 0, SV *callback = &PL_sv_undef) 1922db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0)
1923 PREINIT:
1924 CALLBACK
1637 CODE: 1925 CODE:
1638{ 1926{
1639 dREQ (REQ_C_DEL); 1927 dREQ (REQ_C_DEL);
1640 req->dbc = dbc; 1928 req->dbc = dbc;
1641 req->uint1 = flags; 1929 req->uint1 = flags;
1642 REQ_SEND; 1930 REQ_SEND;
1643} 1931}
1644 1932
1645 1933
1934#if DB_VERSION_MINOR >= 3
1935
1646void 1936void
1647db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) 1937db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0)
1938 PREINIT:
1939 CALLBACK
1648 CODE: 1940 CODE:
1649{ 1941{
1650 dREQ (REQ_SEQ_OPEN); 1942 dREQ (REQ_SEQ_OPEN);
1651 req->seq = seq; 1943 req->seq = seq;
1652 req->txn = txnid; 1944 req->txn = txnid;
1654 sv_to_dbt (&req->dbt1, key); 1946 sv_to_dbt (&req->dbt1, key);
1655 REQ_SEND; 1947 REQ_SEND;
1656} 1948}
1657 1949
1658void 1950void
1659db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = &PL_sv_undef) 1951db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0)
1952 PREINIT:
1953 CALLBACK
1660 CODE: 1954 CODE:
1661{ 1955{
1662 dREQ (REQ_SEQ_CLOSE); 1956 dREQ (REQ_SEQ_CLOSE);
1663 req->seq = seq; 1957 req->seq = seq;
1664 req->uint1 = flags; 1958 req->uint1 = flags;
1665 REQ_SEND; 1959 REQ_SEND;
1666 ptr_nuke (ST (0)); 1960 ptr_nuke (ST (0));
1667} 1961}
1668 1962
1669void 1963void
1670db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = &PL_sv_undef) 1964db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0)
1965 PREINIT:
1966 CALLBACK
1671 CODE: 1967 CODE:
1672{ 1968{
1673 dREQ (REQ_SEQ_GET); 1969 dREQ (REQ_SEQ_GET);
1674 req->seq = seq; 1970 req->seq = seq;
1675 req->txn = txnid; 1971 req->txn = txnid;
1678 req->sv1 = SvREFCNT_inc (seq_value); SvREADONLY_on (seq_value); 1974 req->sv1 = SvREFCNT_inc (seq_value); SvREADONLY_on (seq_value);
1679 REQ_SEND; 1975 REQ_SEND;
1680} 1976}
1681 1977
1682void 1978void
1683db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = &PL_sv_undef) 1979db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = 0)
1980 PREINIT:
1981 CALLBACK
1684 CODE: 1982 CODE:
1685{ 1983{
1686 dREQ (REQ_SEQ_REMOVE); 1984 dREQ (REQ_SEQ_REMOVE);
1687 req->seq = seq; 1985 req->seq = seq;
1688 req->txn = txnid; 1986 req->txn = txnid;
1689 req->uint1 = flags; 1987 req->uint1 = flags;
1690 REQ_SEND; 1988 REQ_SEND;
1691} 1989}
1692 1990
1991#endif
1992
1693 1993
1694MODULE = BDB PACKAGE = BDB::Env 1994MODULE = BDB PACKAGE = BDB::Env
1695 1995
1696void 1996void
1697DESTROY (DB_ENV_ornull *env) 1997DESTROY (DB_ENV_ornuked *env)
1698 CODE: 1998 CODE:
1699 if (env) 1999 if (env)
1700 env->close (env, 0); 2000 env->close (env, 0);
1701 2001
1702int set_data_dir (DB_ENV *env, const char *dir) 2002int set_data_dir (DB_ENV *env, const char *dir)
1727 CODE: 2027 CODE:
1728 RETVAL = env->set_cachesize (env, gbytes, bytes, ncache); 2028 RETVAL = env->set_cachesize (env, gbytes, bytes, ncache);
1729 OUTPUT: 2029 OUTPUT:
1730 RETVAL 2030 RETVAL
1731 2031
1732int set_flags (DB_ENV *env, U32 flags, int onoff) 2032int set_flags (DB_ENV *env, U32 flags, int onoff = 1)
1733 CODE: 2033 CODE:
1734 RETVAL = env->set_flags (env, flags, onoff); 2034 RETVAL = env->set_flags (env, flags, onoff);
1735 OUTPUT: 2035 OUTPUT:
1736 RETVAL 2036 RETVAL
1737 2037
2038#if DB_VERSION_MINOR >= 7
2039
2040int set_intermediate_dir_mode (DB_ENV *env, const char *mode)
2041 CODE:
2042 RETVAL = env->set_intermediate_dir_mode (env, mode);
2043 OUTPUT:
2044 RETVAL
2045
2046int log_set_config (DB_ENV *env, U32 flags, int onoff = 1)
2047 CODE:
2048 RETVAL = env->log_set_config (env, flags, onoff);
2049 OUTPUT:
2050 RETVAL
2051
2052#endif
2053
2054
1738void set_errfile (DB_ENV *env, FILE *errfile = 0) 2055void set_errfile (DB_ENV *env, FILE *errfile = 0)
1739 CODE: 2056 CODE:
1740 env->set_errfile (env, errfile); 2057 env->set_errfile (env, errfile);
1741 2058
1742void set_msgfile (DB_ENV *env, FILE *msgfile = 0) 2059void set_msgfile (DB_ENV *env, FILE *msgfile = 0)
1743 CODE: 2060 CODE:
1744 env->set_msgfile (env, msgfile); 2061 env->set_msgfile (env, msgfile);
1745 2062
1746int set_verbose (DB_ENV *env, U32 which, int onoff = 1) 2063int set_verbose (DB_ENV *env, U32 which = -1, int onoff = 1)
1747 CODE: 2064 CODE:
1748 RETVAL = env->set_verbose (env, which, onoff); 2065 RETVAL = env->set_verbose (env, which, onoff);
1749 OUTPUT: 2066 OUTPUT:
1750 RETVAL 2067 RETVAL
1751 2068
1812int set_lg_max (DB_ENV *env, U32 max) 2129int set_lg_max (DB_ENV *env, U32 max)
1813 CODE: 2130 CODE:
1814 RETVAL = env->set_lg_max (env, max); 2131 RETVAL = env->set_lg_max (env, max);
1815 OUTPUT: 2132 OUTPUT:
1816 RETVAL 2133 RETVAL
2134
2135#if DB_VERSION_MINOR >= 4
1817 2136
1818int mutex_set_max (DB_ENV *env, U32 max) 2137int mutex_set_max (DB_ENV *env, U32 max)
1819 CODE: 2138 CODE:
1820 RETVAL = env->mutex_set_max (env, max); 2139 RETVAL = env->mutex_set_max (env, max);
1821 OUTPUT: 2140 OUTPUT:
1837 CODE: 2156 CODE:
1838 RETVAL = env->mutex_set_align (env, align); 2157 RETVAL = env->mutex_set_align (env, align);
1839 OUTPUT: 2158 OUTPUT:
1840 RETVAL 2159 RETVAL
1841 2160
2161#endif
2162
1842DB_TXN * 2163DB_TXN *
1843txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0) 2164txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0)
1844 CODE: 2165 CODE:
1845 errno = env->txn_begin (env, parent, &RETVAL, flags); 2166 errno = env->txn_begin (env, parent, &RETVAL, flags);
1846 if (errno) 2167 if (errno)
1847 croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); 2168 croak ("DB_ENV->txn_begin: %s", db_strerror (errno));
1848 OUTPUT: 2169 OUTPUT:
1849 RETVAL 2170 RETVAL
1850 2171
2172#if DB_VERSION_MINOR >= 5
2173
2174DB_TXN *
2175cdsgroup_begin (DB_ENV *env)
2176 CODE:
2177 errno = env->cdsgroup_begin (env, &RETVAL);
2178 if (errno)
2179 croak ("DB_ENV->cdsgroup_begin: %s", db_strerror (errno));
2180 OUTPUT:
2181 RETVAL
2182
2183#endif
2184
1851MODULE = BDB PACKAGE = BDB::Db 2185MODULE = BDB PACKAGE = BDB::Db
1852 2186
1853void 2187void
1854DESTROY (DB_ornull *db) 2188DESTROY (DB_ornuked *db)
1855 CODE: 2189 CODE:
1856 if (db) 2190 if (db)
1857 { 2191 {
1858 SV *env = (SV *)db->app_private; 2192 SV *env = (SV *)db->app_private;
1859 db->close (db, 0); 2193 db->close (db, 0);
1939 if (errno) 2273 if (errno)
1940 croak ("DB->cursor: %s", db_strerror (errno)); 2274 croak ("DB->cursor: %s", db_strerror (errno));
1941 OUTPUT: 2275 OUTPUT:
1942 RETVAL 2276 RETVAL
1943 2277
2278#if DB_VERSION_MINOR >= 3
2279
1944DB_SEQUENCE * 2280DB_SEQUENCE *
1945sequence (DB *db, U32 flags = 0) 2281sequence (DB *db, U32 flags = 0)
1946 CODE: 2282 CODE:
1947{ 2283{
1948 errno = db_sequence_create (&RETVAL, db, flags); 2284 errno = db_sequence_create (&RETVAL, db, flags);
1950 croak ("db_sequence_create: %s", db_strerror (errno)); 2286 croak ("db_sequence_create: %s", db_strerror (errno));
1951} 2287}
1952 OUTPUT: 2288 OUTPUT:
1953 RETVAL 2289 RETVAL
1954 2290
2291#endif
2292
1955 2293
1956MODULE = BDB PACKAGE = BDB::Txn 2294MODULE = BDB PACKAGE = BDB::Txn
1957 2295
1958void 2296void
1959DESTROY (DB_TXN_ornull *txn) 2297DESTROY (DB_TXN_ornuked *txn)
1960 CODE: 2298 CODE:
1961 if (txn) 2299 if (txn)
1962 txn->abort (txn); 2300 txn->abort (txn);
1963 2301
1964int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) 2302int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT)
1975 2313
1976 2314
1977MODULE = BDB PACKAGE = BDB::Cursor 2315MODULE = BDB PACKAGE = BDB::Cursor
1978 2316
1979void 2317void
1980DESTROY (DBC_ornull *dbc) 2318DESTROY (DBC_ornuked *dbc)
1981 CODE: 2319 CODE:
1982 if (dbc) 2320 if (dbc)
1983 dbc->c_close (dbc); 2321 dbc->c_close (dbc);
1984 2322
2323#if DB_VERSION_MINOR >= 6
2324
2325int set_priority (DBC *dbc, int priority)
2326 CODE:
2327 dbc->set_priority (dbc, priority);
2328
2329#endif
2330
2331#if DB_VERSION_MINOR >= 3
2332
1985MODULE = BDB PACKAGE = BDB::Sequence 2333MODULE = BDB PACKAGE = BDB::Sequence
1986 2334
1987void 2335void
1988DESTROY (DB_SEQUENCE_ornull *seq) 2336DESTROY (DB_SEQUENCE_ornuked *seq)
1989 CODE: 2337 CODE:
1990 if (seq) 2338 if (seq)
1991 seq->close (seq, 0); 2339 seq->close (seq, 0);
1992 2340
1993int initial_value (DB_SEQUENCE *seq, db_seq_t value) 2341int initial_value (DB_SEQUENCE *seq, db_seq_t value)
2012 CODE: 2360 CODE:
2013 RETVAL = seq->set_range (seq, min, max); 2361 RETVAL = seq->set_range (seq, min, max);
2014 OUTPUT: 2362 OUTPUT:
2015 RETVAL 2363 RETVAL
2016 2364
2365#endif
2366
2367

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines