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

Comparing BDB/BDB.xs (file contents):
Revision 1.20 by root, Tue Dec 4 10:13:50 2007 UTC vs.
Revision 1.50 by root, Thu Sep 25 13:22:32 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines