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

Comparing BDB/BDB.xs (file contents):
Revision 1.48 by root, Tue Jul 29 03:33:16 2008 UTC vs.
Revision 1.75 by root, Fri Jul 29 08:35:35 2011 UTC

6 6
7#include "EXTERN.h" 7#include "EXTERN.h"
8#include "perl.h" 8#include "perl.h"
9#include "XSUB.h" 9#include "XSUB.h"
10 10
11#include "schmorp.h"
12
11// perl stupidly defines these as macros, breaking 13// perl stupidly defines these as argument-less macros, breaking
12// lots and lots of code. 14// lots and lots of code.
13#undef open 15#undef open
14#undef close 16#undef close
15#undef abort 17#undef abort
16#undef malloc 18#undef malloc
36#endif 38#endif
37 39
38/* number of seconds after which idle threads exit */ 40/* number of seconds after which idle threads exit */
39#define IDLE_TIMEOUT 10 41#define IDLE_TIMEOUT 10
40 42
43typedef SV SV_mutable;
44
41typedef DB_ENV DB_ENV_ornull; 45typedef DB_ENV DB_ENV_ornull;
42typedef DB_TXN DB_TXN_ornull; 46typedef DB_TXN DB_TXN_ornull;
43typedef DBC DBC_ornull; 47typedef DBC DBC_ornull;
44typedef DB DB_ornull; 48typedef DB DB_ornull;
45 49
51#if DB_VERSION_MINOR >= 3 55#if DB_VERSION_MINOR >= 3
52typedef DB_SEQUENCE DB_SEQUENCE_ornull; 56typedef DB_SEQUENCE DB_SEQUENCE_ornull;
53typedef DB_SEQUENCE DB_SEQUENCE_ornuked; 57typedef DB_SEQUENCE DB_SEQUENCE_ornuked;
54#endif 58#endif
55 59
56typedef SV SV8; /* byte-sv, used for argument-checking */
57typedef char *bdb_filename; 60typedef char *bdb_filename;
58 61
59static SV *prepare_cb; 62static SV *prepare_cb;
63
64static HV
65 *bdb_stash,
66 *bdb_env_stash,
67 *bdb_txn_stash,
68 *bdb_cursor_stash,
69 *bdb_db_stash,
70 *bdb_sequence_stash;
60 71
61#if DB_VERSION_MINOR >= 6 72#if DB_VERSION_MINOR >= 6
62# define c_close close 73# define c_close close
63# define c_count count 74# define c_count count
64# define c_del del 75# define c_del del
132dbt_to_sv (SV *sv, DBT *dbt) 143dbt_to_sv (SV *sv, DBT *dbt)
133{ 144{
134 if (sv) 145 if (sv)
135 { 146 {
136 SvREADONLY_off (sv); 147 SvREADONLY_off (sv);
148
149 if (dbt->data)
137 sv_setpvn_mg (sv, dbt->data, dbt->size); 150 sv_setpvn_mg (sv, dbt->data, dbt->size);
151 else
152 sv_setsv_mg (sv, &PL_sv_undef);
153
138 SvREFCNT_dec (sv); 154 SvREFCNT_dec (sv);
139 } 155 }
140 156
141 free (dbt->data); 157 free (dbt->data);
142} 158}
143 159
144enum { 160enum {
145 REQ_QUIT, 161 REQ_QUIT,
146 REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, 162 REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT,
147 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, 163 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME,
164 REQ_ENV_LOG_ARCHIVE,
148 REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, 165 REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_VERIFY, REQ_DB_UPGRADE,
149 REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, 166 REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE,
150 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, 167 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH,
151 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, 168 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL,
152 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, 169 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE,
153}; 170};
173 DB_KEY_RANGE key_range; 190 DB_KEY_RANGE key_range;
174#if DB_VERSION_MINOR >= 3 191#if DB_VERSION_MINOR >= 3
175 DB_SEQUENCE *seq; 192 DB_SEQUENCE *seq;
176 db_seq_t seq_t; 193 db_seq_t seq_t;
177#endif 194#endif
195
196 SV *rsv1, *rsv2; // keep some request objects alive
178} bdb_cb; 197} bdb_cb;
179 198
180typedef bdb_cb *bdb_req; 199typedef bdb_cb *bdb_req;
181 200
182enum { 201enum {
205static int next_pri = DEFAULT_PRI + PRI_BIAS; 224static int next_pri = DEFAULT_PRI + PRI_BIAS;
206 225
207static unsigned int started, idle, wanted; 226static unsigned int started, idle, wanted;
208 227
209/* worker threads management */ 228/* worker threads management */
210static mutex_t wrklock = X_MUTEX_INIT; 229static xmutex_t wrklock = X_MUTEX_INIT;
211 230
212typedef struct worker { 231typedef struct worker {
213 /* locked by wrklock */ 232 /* locked by wrklock */
214 struct worker *prev, *next; 233 struct worker *prev, *next;
215 234
216 thread_t tid; 235 xthread_t tid;
217 236
218 /* locked by reslock, reqlock or wrklock */ 237 /* locked by reslock, reqlock or wrklock */
219 bdb_req req; /* currently processed request */ 238 bdb_req req; /* currently processed request */
220 void *dbuf; 239 void *dbuf;
221 DIR *dirp; 240 DIR *dirp;
236} 255}
237 256
238static volatile unsigned int nreqs, nready, npending; 257static volatile unsigned int nreqs, nready, npending;
239static volatile unsigned int max_idle = 4; 258static volatile unsigned int max_idle = 4;
240static volatile unsigned int max_outstanding = 0xffffffff; 259static volatile unsigned int max_outstanding = 0xffffffff;
241static int respipe_osf [2], respipe [2] = { -1, -1 }; 260static s_epipe respipe;
242 261
243static mutex_t reslock = X_MUTEX_INIT; 262static xmutex_t reslock = X_MUTEX_INIT;
244static mutex_t reqlock = X_MUTEX_INIT; 263static xmutex_t reqlock = X_MUTEX_INIT;
245static cond_t reqwait = X_COND_INIT; 264static xcond_t reqwait = X_COND_INIT;
246 265
247#if WORDACCESS_UNSAFE 266#if WORDACCESS_UNSAFE
248 267
249static unsigned int get_nready (void) 268static unsigned int get_nready (void)
250{ 269{
341 abort (); 360 abort ();
342} 361}
343 362
344static int poll_cb (void); 363static int poll_cb (void);
345static void req_free (bdb_req req); 364static void req_free (bdb_req req);
346static void req_cancel (bdb_req req);
347 365
348static int req_invoke (bdb_req req) 366static int req_invoke (bdb_req req)
349{ 367{
350 dSP; 368 switch (req->type)
369 {
370 case REQ_DB_CLOSE:
371 SvREFCNT_dec (req->sv1);
372 break;
373
374 case REQ_DB_GET:
375 case REQ_DB_PGET:
376 case REQ_C_GET:
377 case REQ_C_PGET:
378 case REQ_DB_PUT:
379 case REQ_C_PUT:
380 dbt_to_sv (req->sv1, &req->dbt1);
381 dbt_to_sv (req->sv2, &req->dbt2);
382 dbt_to_sv (req->sv3, &req->dbt3);
383 break;
384
385 case REQ_DB_KEY_RANGE:
386 {
387 AV *av = newAV ();
388
389 av_push (av, newSVnv (req->key_range.less));
390 av_push (av, newSVnv (req->key_range.equal));
391 av_push (av, newSVnv (req->key_range.greater));
392
393 av = (AV *)newRV_noinc ((SV *)av);
394
395 SvREADONLY_off (req->sv1);
396 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av));
397 SvREFCNT_dec (av);
398 SvREFCNT_dec (req->sv1);
399 }
400 break;
401
402#if DB_VERSION_MINOR >= 3
403 case REQ_SEQ_GET:
404 SvREADONLY_off (req->sv1);
405
406 if (sizeof (IV) > 4)
407 sv_setiv_mg (req->sv1, (IV)req->seq_t);
408 else
409 sv_setnv_mg (req->sv1, (NV)req->seq_t);
410
411 SvREFCNT_dec (req->sv1);
412 break;
413#endif
414
415 case REQ_ENV_LOG_ARCHIVE:
416 {
417 AV *av = newAV ();
418 char **listp = (char **)req->buf1;
419
420 if (listp)
421 while (*listp)
422 av_push (av, newSVpv (*listp, 0)), ++listp;
423
424 av = (AV *)newRV_noinc ((SV *)av);
425
426 SvREADONLY_off (req->sv1);
427 sv_setsv_mg (req->sv1, (SV *)av);
428 SvREFCNT_dec (av);
429 SvREFCNT_dec (req->sv1);
430 }
431 break;
432 }
433
434 errno = req->result;
351 435
352 if (req->callback) 436 if (req->callback)
353 { 437 {
438 dSP;
439
354 ENTER; 440 ENTER;
355 SAVETMPS; 441 SAVETMPS;
356 PUSHMARK (SP); 442 PUSHMARK (SP);
357 443
358 switch (req->type)
359 {
360 case REQ_DB_CLOSE:
361 SvREFCNT_dec (req->sv1);
362 break;
363
364 case REQ_DB_GET:
365 case REQ_DB_PGET:
366 dbt_to_sv (req->sv3, &req->dbt3);
367 break;
368
369 case REQ_C_GET:
370 case REQ_C_PGET:
371 dbt_to_sv (req->sv1, &req->dbt1);
372 dbt_to_sv (req->sv2, &req->dbt2);
373 dbt_to_sv (req->sv3, &req->dbt3);
374 break;
375
376 case REQ_DB_PUT:
377 case REQ_C_PUT:
378 dbt_to_sv (0, &req->dbt1);
379 dbt_to_sv (0, &req->dbt2);
380 break;
381
382 case REQ_DB_KEY_RANGE:
383 {
384 AV *av = newAV ();
385
386 av_push (av, newSVnv (req->key_range.less));
387 av_push (av, newSVnv (req->key_range.equal));
388 av_push (av, newSVnv (req->key_range.greater));
389
390 SvREADONLY_off (req->sv1);
391 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av));
392 SvREFCNT_dec (req->sv1);
393 }
394 break;
395
396#if DB_VERSION_MINOR >= 3
397 case REQ_SEQ_GET:
398 SvREADONLY_off (req->sv1);
399
400 if (sizeof (IV) > 4)
401 sv_setiv_mg (req->sv1, (IV)req->seq_t);
402 else
403 sv_setnv_mg (req->sv1, (NV)req->seq_t);
404
405 SvREFCNT_dec (req->sv1);
406 break;
407#endif
408 }
409
410 errno = req->result;
411
412 PUTBACK; 444 PUTBACK;
413 call_sv (req->callback, G_VOID | G_EVAL); 445 call_sv (req->callback, G_VOID | G_EVAL);
414 SPAGAIN; 446 SPAGAIN;
415 447
416 FREETMPS; 448 FREETMPS;
417 LEAVE; 449 LEAVE;
450
451 return !SvTRUE (ERRSV);
418 } 452 }
419 453
420 return !SvTRUE (ERRSV); 454 return 1;
421} 455}
422 456
423static void req_free (bdb_req req) 457static void req_free (bdb_req req)
424{ 458{
425 SvREFCNT_dec (req->callback); 459 SvREFCNT_dec (req->callback);
460
461 SvREFCNT_dec (req->rsv1);
462 SvREFCNT_dec (req->rsv2);
426 463
427 free (req->buf1); 464 free (req->buf1);
428 free (req->buf2); 465 free (req->buf2);
429 free (req->buf3); 466 free (req->buf3);
430 467
431 Safefree (req); 468 Safefree (req);
432} 469}
433 470
434#ifdef USE_SOCKETS_AS_HANDLES
435# define TO_SOCKET(x) (win32_get_osfhandle (x))
436#else
437# define TO_SOCKET(x) (x)
438#endif
439
440static void 471static void
441create_respipe (void) 472create_respipe (void)
442{ 473{
443#ifdef _WIN32
444 int arg; /* argg */
445#endif
446 int old_readfd = respipe [0];
447
448 if (respipe [1] >= 0)
449 respipe_close (TO_SOCKET (respipe [1]));
450
451#ifdef _WIN32
452 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe))
453#else
454 if (pipe (respipe)) 474 if (s_epipe_renew (&respipe))
455#endif 475 croak ("BDB: unable to create event pipe");
456 croak ("unable to initialize result pipe");
457
458 if (old_readfd >= 0)
459 {
460 if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0)
461 croak ("unable to initialize result pipe(2)");
462
463 respipe_close (respipe [0]);
464 respipe [0] = old_readfd;
465 }
466
467#ifdef _WIN32
468 arg = 1;
469 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg)
470 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg))
471#else
472 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
473 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
474#endif
475 croak ("unable to initialize result pipe(3)");
476
477 respipe_osf [0] = TO_SOCKET (respipe [0]);
478 respipe_osf [1] = TO_SOCKET (respipe [1]);
479} 476}
480 477
478static void bdb_request (bdb_req req);
481X_THREAD_PROC (bdb_proc); 479X_THREAD_PROC (bdb_proc);
482 480
483static void start_thread (void) 481static void start_thread (void)
484{ 482{
485 worker *wrk = calloc (1, sizeof (worker)); 483 worker *wrk = calloc (1, sizeof (worker));
526 on_next_submit = 0; 524 on_next_submit = 0;
527 525
528 PUSHMARK (SP); 526 PUSHMARK (SP);
529 PUTBACK; 527 PUTBACK;
530 call_sv (cb, G_DISCARD | G_EVAL); 528 call_sv (cb, G_DISCARD | G_EVAL);
529 SPAGAIN;
531 } 530 }
532 531
533 // synthesize callback if none given 532 // synthesize callback if none given
534 if (!req->callback) 533 if (!req->callback)
535 { 534 {
535 if (SvOK (prepare_cb))
536 {
536 int count; 537 int count;
537 538
538 dSP; 539 dSP;
539 PUSHMARK (SP); 540 PUSHMARK (SP);
540 PUTBACK; 541 PUTBACK;
541 count = call_sv (prepare_cb, G_ARRAY); 542 count = call_sv (prepare_cb, G_ARRAY);
542 SPAGAIN; 543 SPAGAIN;
543 544
544 if (count != 2) 545 if (count != 2)
545 croak ("prepare callback must return exactly two values\n"); 546 croak ("sync prepare callback must return exactly two values\n");
546 547
547 wait_callback = POPs; 548 wait_callback = POPs;
548 SvREFCNT_dec (req->callback);
549 req->callback = SvREFCNT_inc (POPs); 549 req->callback = SvREFCNT_inc (POPs);
550 }
551 else
552 {
553 // execute request synchronously
554 bdb_request (req);
555 req_invoke (req);
556 req_free (req);
557 return;
558 }
550 } 559 }
551 560
552 ++nreqs; 561 ++nreqs;
553 562
554 X_LOCK (reqlock); 563 X_LOCK (reqlock);
568 } 577 }
569} 578}
570 579
571static void end_thread (void) 580static void end_thread (void)
572{ 581{
573 bdb_req req; 582 bdb_req req = calloc (1, sizeof (bdb_cb));
574
575 Newz (0, req, 1, bdb_cb);
576 583
577 req->type = REQ_QUIT; 584 req->type = REQ_QUIT;
578 req->pri = PRI_MAX + PRI_BIAS; 585 req->pri = PRI_MAX + PRI_BIAS;
579 586
580 X_LOCK (reqlock); 587 X_LOCK (reqlock);
609 end_thread (); 616 end_thread ();
610} 617}
611 618
612static void poll_wait (void) 619static void poll_wait (void)
613{ 620{
614 fd_set rfd;
615
616 while (nreqs) 621 while (nreqs)
617 { 622 {
618 int size; 623 int size;
619 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 624 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
620 size = res_queue.size; 625 size = res_queue.size;
623 if (size) 628 if (size)
624 return; 629 return;
625 630
626 maybe_start_thread (); 631 maybe_start_thread ();
627 632
628 FD_ZERO (&rfd); 633 s_epipe_wait (&respipe);
629 FD_SET (respipe [0], &rfd);
630
631 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
632 } 634 }
633} 635}
634 636
635static int poll_cb (void) 637static int poll_cb (void)
636{ 638{
656 if (req) 658 if (req)
657 { 659 {
658 --npending; 660 --npending;
659 661
660 if (!res_queue.size) 662 if (!res_queue.size)
661 {
662 /* read any signals sent by the worker threads */ 663 /* read any signals sent by the worker threads */
663 char buf [4]; 664 s_epipe_drain (&respipe);
664 while (respipe_read (respipe [0], buf, 4) == 4)
665 ;
666 }
667 } 665 }
668 666
669 X_UNLOCK (reslock); 667 X_UNLOCK (reslock);
670 668
671 if (!req) 669 if (!req)
706 return count; 704 return count;
707} 705}
708 706
709/*****************************************************************************/ 707/*****************************************************************************/
710 708
709static void
710bdb_request (bdb_req req)
711{
712 switch (req->type)
713 {
714 case REQ_ENV_OPEN:
715 req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1);
716 break;
717
718 case REQ_ENV_CLOSE:
719 req->result = req->env->close (req->env, req->uint1);
720 break;
721
722 case REQ_ENV_TXN_CHECKPOINT:
723 req->result = req->env->txn_checkpoint (req->env, req->uint1, req->int1, req->uint2);
724 break;
725
726 case REQ_ENV_LOCK_DETECT:
727 req->result = req->env->lock_detect (req->env, req->uint1, req->uint2, &req->int1);
728 break;
729
730 case REQ_ENV_MEMP_SYNC:
731 req->result = req->env->memp_sync (req->env, 0);
732 break;
733
734 case REQ_ENV_MEMP_TRICKLE:
735 req->result = req->env->memp_trickle (req->env, req->int1, &req->int2);
736 break;
737
738 case REQ_ENV_DBREMOVE:
739 req->result = req->env->dbremove (req->env, req->txn, req->buf1, req->buf2, req->uint1);
740 break;
741
742 case REQ_ENV_DBRENAME:
743 req->result = req->env->dbrename (req->env, req->txn, req->buf1, req->buf2, req->buf3, req->uint1);
744 break;
745
746 case REQ_DB_OPEN:
747 req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2);
748 break;
749
750 case REQ_DB_CLOSE:
751 req->result = req->db->close (req->db, req->uint1);
752 break;
753
754#if DB_VERSION_MINOR >= 4
755 case REQ_DB_COMPACT:
756 req->result = req->db->compact (req->db, req->txn, req->dbt1.data ? &req->dbt1 : 0, req->dbt2.data ? &req->dbt2 : 0, 0, req->uint1, 0);
757 break;
758#endif
759
760 case REQ_DB_SYNC:
761 req->result = req->db->sync (req->db, req->uint1);
762 break;
763
764 case REQ_DB_VERIFY:
765 req->result = req->db->verify (req->db, req->buf1, req->buf2, 0, req->uint1);
766 break;
767
768 case REQ_DB_UPGRADE:
769 req->result = req->db->upgrade (req->db, req->buf1, req->uint1);
770 break;
771
772 case REQ_DB_PUT:
773 req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1);
774 break;
775
776#if DB_VERSION_MINOR >= 6
777 case REQ_DB_EXISTS:
778 req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1);
779 break;
780#endif
781 case REQ_DB_GET:
782 req->result = req->db->get (req->db, req->txn, &req->dbt1, &req->dbt3, req->uint1);
783 break;
784
785 case REQ_DB_PGET:
786 req->result = req->db->pget (req->db, req->txn, &req->dbt1, &req->dbt2, &req->dbt3, req->uint1);
787 break;
788
789 case REQ_DB_DEL:
790 req->result = req->db->del (req->db, req->txn, &req->dbt1, req->uint1);
791 break;
792
793 case REQ_DB_KEY_RANGE:
794 req->result = req->db->key_range (req->db, req->txn, &req->dbt1, &req->key_range, req->uint1);
795 break;
796
797 case REQ_TXN_COMMIT:
798 req->result = req->txn->commit (req->txn, req->uint1);
799 break;
800
801 case REQ_TXN_ABORT:
802 req->result = req->txn->abort (req->txn);
803 break;
804
805 case REQ_TXN_FINISH:
806 if (req->txn->flags & TXN_DEADLOCK)
807 {
808 req->result = req->txn->abort (req->txn);
809 if (!req->result)
810 req->result = DB_LOCK_DEADLOCK;
811 }
812 else
813 req->result = req->txn->commit (req->txn, req->uint1);
814 break;
815
816 case REQ_C_CLOSE:
817 req->result = req->dbc->c_close (req->dbc);
818 break;
819
820 case REQ_C_COUNT:
821 {
822 db_recno_t recno;
823 req->result = req->dbc->c_count (req->dbc, &recno, req->uint1);
824 req->uv1 = recno;
825 }
826 break;
827
828 case REQ_C_PUT:
829 req->result = req->dbc->c_put (req->dbc, &req->dbt1, &req->dbt2, req->uint1);
830 break;
831
832 case REQ_C_GET:
833 req->result = req->dbc->c_get (req->dbc, &req->dbt1, &req->dbt3, req->uint1);
834 break;
835
836 case REQ_C_PGET:
837 req->result = req->dbc->c_pget (req->dbc, &req->dbt1, &req->dbt2, &req->dbt3, req->uint1);
838 break;
839
840 case REQ_C_DEL:
841 req->result = req->dbc->c_del (req->dbc, req->uint1);
842 break;
843
844#if DB_VERSION_MINOR >= 3
845 case REQ_SEQ_OPEN:
846 req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1);
847 break;
848
849 case REQ_SEQ_CLOSE:
850 req->result = req->seq->close (req->seq, req->uint1);
851 break;
852
853 case REQ_SEQ_GET:
854 req->result = req->seq->get (req->seq, req->txn, req->int1, &req->seq_t, req->uint1);
855 break;
856
857 case REQ_SEQ_REMOVE:
858 req->result = req->seq->remove (req->seq, req->txn, req->uint1);
859 break;
860#endif
861
862 case REQ_ENV_LOG_ARCHIVE:
863 {
864 char **listp = 0; /* DB_ARCH_REMOVE does not touch listp, contrary to docs */
865 req->result = req->env->log_archive (req->env, &listp, req->uint1);
866 req->buf1 = (char *)listp;
867 }
868 break;
869
870 default:
871 req->result = ENOSYS;
872 break;
873 }
874
875 if (req->txn && (req->result > 0 || req->result == DB_LOCK_NOTGRANTED))
876 req->txn->flags |= TXN_DEADLOCK;
877}
878
711X_THREAD_PROC (bdb_proc) 879X_THREAD_PROC (bdb_proc)
712{ 880{
713 bdb_req req; 881 bdb_req req;
714 struct timespec ts; 882 struct timespec ts;
715 worker *self = (worker *)thr_arg; 883 worker *self = (worker *)thr_arg;
717 /* try to distribute timeouts somewhat evenly */ 885 /* try to distribute timeouts somewhat evenly */
718 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 886 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
719 887
720 for (;;) 888 for (;;)
721 { 889 {
722 ts.tv_sec = time (0) + IDLE_TIMEOUT; 890 ts.tv_sec = time (0) + IDLE_TIMEOUT;
723 891
724 X_LOCK (reqlock); 892 X_LOCK (reqlock);
725 893
726 for (;;) 894 for (;;)
727 { 895 {
754 } 922 }
755 923
756 --nready; 924 --nready;
757 925
758 X_UNLOCK (reqlock); 926 X_UNLOCK (reqlock);
759 927
760 switch (req->type) 928 if (req->type == REQ_QUIT)
761 { 929 {
762 case REQ_QUIT: 930 X_LOCK (reslock);
763 req->result = ENOSYS; 931 free (req);
932 self->req = 0;
933 X_UNLOCK (reslock);
934
764 goto quit; 935 goto quit;
765
766 case REQ_ENV_OPEN:
767 req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1);
768 break;
769
770 case REQ_ENV_CLOSE:
771 req->result = req->env->close (req->env, req->uint1);
772 break;
773
774 case REQ_ENV_TXN_CHECKPOINT:
775 req->result = req->env->txn_checkpoint (req->env, req->uint1, req->int1, req->uint2);
776 break;
777
778 case REQ_ENV_LOCK_DETECT:
779 req->result = req->env->lock_detect (req->env, req->uint1, req->uint2, &req->int1);
780 break;
781
782 case REQ_ENV_MEMP_SYNC:
783 req->result = req->env->memp_sync (req->env, 0);
784 break;
785
786 case REQ_ENV_MEMP_TRICKLE:
787 req->result = req->env->memp_trickle (req->env, req->int1, &req->int2);
788 break;
789
790 case REQ_ENV_DBREMOVE:
791 req->result = req->env->dbremove (req->env, req->txn, req->buf1, req->buf2, req->uint1);
792 break;
793
794 case REQ_ENV_DBRENAME:
795 req->result = req->env->dbrename (req->env, req->txn, req->buf1, req->buf2, req->buf3, req->uint1);
796 break;
797
798 case REQ_DB_OPEN:
799 req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2);
800 break;
801
802 case REQ_DB_CLOSE:
803 req->result = req->db->close (req->db, req->uint1);
804 break;
805
806#if DB_VERSION_MINOR >= 4
807 case REQ_DB_COMPACT:
808 req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0);
809 break;
810#endif
811
812 case REQ_DB_SYNC:
813 req->result = req->db->sync (req->db, req->uint1);
814 break;
815
816 case REQ_DB_UPGRADE:
817 req->result = req->db->upgrade (req->db, req->buf1, req->uint1);
818 break;
819
820 case REQ_DB_PUT:
821 req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1);
822 break;
823
824#if DB_VERSION_MINOR >= 6
825 case REQ_DB_EXISTS:
826 req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1);
827 break;
828#endif
829 case REQ_DB_GET:
830 req->result = req->db->get (req->db, req->txn, &req->dbt1, &req->dbt3, req->uint1);
831 break;
832
833 case REQ_DB_PGET:
834 req->result = req->db->pget (req->db, req->txn, &req->dbt1, &req->dbt2, &req->dbt3, req->uint1);
835 break;
836
837 case REQ_DB_DEL:
838 req->result = req->db->del (req->db, req->txn, &req->dbt1, req->uint1);
839 break;
840
841 case REQ_DB_KEY_RANGE:
842 req->result = req->db->key_range (req->db, req->txn, &req->dbt1, &req->key_range, req->uint1);
843 break;
844
845 case REQ_TXN_COMMIT:
846 req->result = req->txn->commit (req->txn, req->uint1);
847 break;
848
849 case REQ_TXN_ABORT:
850 req->result = req->txn->abort (req->txn);
851 break;
852
853 case REQ_TXN_FINISH:
854 if (req->txn->flags & TXN_DEADLOCK)
855 {
856 req->result = req->txn->abort (req->txn);
857 if (!req->result)
858 req->result = DB_LOCK_DEADLOCK;
859 }
860 else
861 req->result = req->txn->commit (req->txn, req->uint1);
862 break;
863
864 case REQ_C_CLOSE:
865 req->result = req->dbc->c_close (req->dbc);
866 break;
867
868 case REQ_C_COUNT:
869 {
870 db_recno_t recno;
871 req->result = req->dbc->c_count (req->dbc, &recno, req->uint1);
872 req->uv1 = recno;
873 }
874 break;
875
876 case REQ_C_PUT:
877 req->result = req->dbc->c_put (req->dbc, &req->dbt1, &req->dbt2, req->uint1);
878 break;
879
880 case REQ_C_GET:
881 req->result = req->dbc->c_get (req->dbc, &req->dbt1, &req->dbt3, req->uint1);
882 break;
883
884 case REQ_C_PGET:
885 req->result = req->dbc->c_pget (req->dbc, &req->dbt1, &req->dbt2, &req->dbt3, req->uint1);
886 break;
887
888 case REQ_C_DEL:
889 req->result = req->dbc->c_del (req->dbc, req->uint1);
890 break;
891
892#if DB_VERSION_MINOR >= 3
893 case REQ_SEQ_OPEN:
894 req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1);
895 break;
896
897 case REQ_SEQ_CLOSE:
898 req->result = req->seq->close (req->seq, req->uint1);
899 break;
900
901 case REQ_SEQ_GET:
902 req->result = req->seq->get (req->seq, req->txn, req->int1, &req->seq_t, req->uint1);
903 break;
904
905 case REQ_SEQ_REMOVE:
906 req->result = req->seq->remove (req->seq, req->txn, req->uint1);
907 break;
908#endif
909
910 default:
911 req->result = ENOSYS;
912 break;
913 } 936 }
914 937
915 if (req->txn && (req->result > 0 || req->result == DB_LOCK_NOTGRANTED)) 938 bdb_request (req);
916 req->txn->flags |= TXN_DEADLOCK;
917 939
918 X_LOCK (reslock); 940 X_LOCK (reslock);
919 941
920 ++npending; 942 ++npending;
921 943
922 if (!reqq_push (&res_queue, req)) 944 if (!reqq_push (&res_queue, req))
923 /* write a dummy byte to the pipe so fh becomes ready */ 945 s_epipe_signal (&respipe);
924 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
925 946
926 self->req = 0; 947 self->req = 0;
927 worker_clear (self); 948 worker_clear (self);
928 949
929 X_UNLOCK (reslock); 950 X_UNLOCK (reslock);
983 create_respipe (); 1004 create_respipe ();
984 1005
985 atfork_parent (); 1006 atfork_parent ();
986} 1007}
987 1008
988#define dREQ(reqtype) \ 1009#define dREQ(reqtype,rsvcnt) \
989 bdb_req req; \ 1010 bdb_req req; \
990 int req_pri = next_pri; \ 1011 int req_pri = next_pri; \
991 next_pri = DEFAULT_PRI + PRI_BIAS; \ 1012 next_pri = DEFAULT_PRI + PRI_BIAS; \
992 \ 1013 \
993 if (callback && SvOK (callback)) \ 1014 if (callback && SvOK (callback)) \
995 \ 1016 \
996 Newz (0, req, 1, bdb_cb); \ 1017 Newz (0, req, 1, bdb_cb); \
997 if (!req) \ 1018 if (!req) \
998 croak ("out of memory during bdb_req allocation"); \ 1019 croak ("out of memory during bdb_req allocation"); \
999 \ 1020 \
1000 req->callback = cb ? SvREFCNT_inc (cb) : 0; \ 1021 req->callback = SvREFCNT_inc (cb); \
1001 req->type = (reqtype); \ 1022 req->type = (reqtype); \
1002 req->pri = req_pri 1023 req->pri = req_pri; \
1024 if (rsvcnt >= 1) req->rsv1 = SvREFCNT_inc (ST (0)); \
1025 if (rsvcnt >= 2) req->rsv2 = SvREFCNT_inc (ST (1)); \
1026 (void)0;
1003 1027
1004#define REQ_SEND \ 1028#define REQ_SEND \
1005 req_send (req) 1029 req_send (req)
1006 1030
1007#define SvPTR(var, arg, type, class, nullok) \ 1031#define SvPTR(var, arg, type, stash, class, nullok) \
1008 if (!SvOK (arg)) \ 1032 if (!SvOK (arg)) \
1009 { \ 1033 { \
1010 if (nullok != 1) \ 1034 if (nullok != 1) \
1011 croak (# var " must be a " # class " object, not undef"); \ 1035 croak (# var " must be a " # class " object, not undef"); \
1012 \ 1036 \
1013 (var) = 0; \ 1037 (var) = 0; \
1014 } \ 1038 } \
1015 else if (sv_derived_from ((arg), # class)) \ 1039 else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \
1016 { \ 1040 { \
1017 IV tmp = SvIV ((SV*) SvRV (arg)); \ 1041 IV tmp = SvIV ((SV*) SvRV (arg)); \
1018 (var) = INT2PTR (type, tmp); \ 1042 (var) = INT2PTR (type, tmp); \
1019 if (!var && nullok != 2) \ 1043 if (!var && nullok != 2) \
1020 croak (# var " is not a valid " # class " object anymore"); \ 1044 croak (# var " is not a valid " # class " object anymore"); \
1021 } \ 1045 } \
1022 else \ 1046 else \
1023 croak (# var " is not of type " # class); 1047 croak (# var " is not of type " # class);
1048
1049#define ARG_MUTABLE(name) \
1050 if (SvREADONLY (name)) \
1051 croak ("argument " #name " is read-only/constant, but the request requires it to be mutable");
1052
1053static SV *
1054newSVptr (void *ptr, HV *stash)
1055{
1056 SV *rv = NEWSV (0, 0);
1057 sv_upgrade (rv, SVt_PVMG);
1058 sv_setiv (rv, PTR2IV (ptr));
1059
1060 return sv_bless (newRV_noinc (rv), stash);
1061}
1024 1062
1025static void 1063static void
1026ptr_nuke (SV *sv) 1064ptr_nuke (SV *sv)
1027{ 1065{
1028 assert (SvROK (sv)); 1066 assert (SvROK (sv));
1099 } 1137 }
1100 1138
1101 return 0; 1139 return 0;
1102} 1140}
1103 1141
1142/*****************************************************************************/
1143
1144#if 0
1145static int
1146bt_pfxc_compare (DB *db, const DBT *dbt1, const DBT *dbt2)
1147{
1148 ssize_t size1 = dbt1->size;
1149 ssize_t size2 = dbt2->size;
1150 int res = memcmp ((void *)dbt1->data, (void *)dbt2->data,
1151 size1 <= size2 ? size1 : size2);
1152
1153 if (res)
1154 return res;
1155 else if (size1 - size2)
1156 return size1 - size2;
1157 else
1158 return 0;
1159}
1160
1161static size_t
1162bt_pfxc_prefix_x (DB *db, const DBT *dbt1, const DBT *dbt2)
1163{
1164 ssize_t size1 = dbt1->size;
1165 ssize_t size2 = dbt2->size;
1166 u_int8_t *p1 = (u_int8_t *)dbt1->data;
1167 u_int8_t *p2 = (u_int8_t *)dbt2->data;
1168 u_int8_t *pe = p1 + (size1 <= size2 ? size1 : size2);
1169
1170 while (p1 < pe)
1171 if (*p1++ != *p2++)
1172 return p1 - (u_int8_t *)dbt1->data - 1;
1173
1174 if (size1 < size2) return size1 + 1;
1175 if (size1 > size2) return size2 + 1;
1176
1177 return size1;
1178}
1179#endif
1180
1181/*****************************************************************************/
1182
1104/* stupid windoes defined CALLBACK as well */ 1183/* stupid windows defines CALLBACK as well */
1105#undef CALLBACK 1184#undef CALLBACK
1106#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); 1185#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1));
1107 1186
1108MODULE = BDB PACKAGE = BDB 1187MODULE = BDB PACKAGE = BDB
1109 1188
1110PROTOTYPES: ENABLE 1189PROTOTYPES: ENABLE
1111 1190
1112BOOT: 1191BOOT:
1113{ 1192{
1114 HV *stash = gv_stashpv ("BDB", 1);
1115
1116 static const struct { 1193 static const struct {
1117 const char *name; 1194 const char *name;
1118 IV iv; 1195 IV iv;
1119 } *civ, const_iv[] = { 1196 } *civ, const_iv[] = {
1120#define const_iv(name) { # name, (IV)DB_ ## name }, 1197#define const_iv(name) { # name, (IV)DB_ ## name },
1149 const_iv (TXN_NOT_DURABLE) 1226 const_iv (TXN_NOT_DURABLE)
1150 const_iv (TXN_WRITE_NOSYNC) 1227 const_iv (TXN_WRITE_NOSYNC)
1151 const_iv (WRITECURSOR) 1228 const_iv (WRITECURSOR)
1152 const_iv (YIELDCPU) 1229 const_iv (YIELDCPU)
1153 const_iv (ENCRYPT_AES) 1230 const_iv (ENCRYPT_AES)
1231#if DB_VERSION_MINOR < 8
1154 const_iv (XA_CREATE) 1232 const_iv (XA_CREATE)
1233#endif
1155 const_iv (BTREE) 1234 const_iv (BTREE)
1156 const_iv (HASH) 1235 const_iv (HASH)
1157 const_iv (QUEUE) 1236 const_iv (QUEUE)
1158 const_iv (RECNO) 1237 const_iv (RECNO)
1159 const_iv (UNKNOWN) 1238 const_iv (UNKNOWN)
1162 const_iv (NOSYNC) 1241 const_iv (NOSYNC)
1163 const_iv (CHKSUM) 1242 const_iv (CHKSUM)
1164 const_iv (ENCRYPT) 1243 const_iv (ENCRYPT)
1165 const_iv (DUP) 1244 const_iv (DUP)
1166 const_iv (DUPSORT) 1245 const_iv (DUPSORT)
1167 const_iv (RECNUM) 1246 //const_iv (RECNUM)
1168 const_iv (RENUMBER) 1247 const_iv (RENUMBER)
1169 const_iv (REVSPLITOFF) 1248 const_iv (REVSPLITOFF)
1170 const_iv (CONSUME) 1249 const_iv (CONSUME)
1171 const_iv (CONSUME_WAIT) 1250 const_iv (CONSUME_WAIT)
1172 const_iv (GET_BOTH) 1251 const_iv (GET_BOTH)
1223 const_iv (LOCK_OLDEST) 1302 const_iv (LOCK_OLDEST)
1224 const_iv (LOCK_RANDOM) 1303 const_iv (LOCK_RANDOM)
1225 const_iv (LOCK_YOUNGEST) 1304 const_iv (LOCK_YOUNGEST)
1226 1305
1227 const_iv (DONOTINDEX) 1306 const_iv (DONOTINDEX)
1228 const_iv (KEYEMPTY ) 1307 const_iv (KEYEMPTY)
1229 const_iv (KEYEXIST ) 1308 const_iv (KEYEXIST)
1230 const_iv (LOCK_DEADLOCK) 1309 const_iv (LOCK_DEADLOCK)
1231 const_iv (LOCK_NOTGRANTED) 1310 const_iv (LOCK_NOTGRANTED)
1232 const_iv (NOSERVER) 1311 const_iv (NOSERVER)
1233 const_iv (NOSERVER_HOME) 1312 const_iv (NOSERVER_HOME)
1234 const_iv (NOSERVER_ID) 1313 const_iv (NOSERVER_ID)
1244 const_iv (REP_UNAVAIL) 1323 const_iv (REP_UNAVAIL)
1245 const_iv (RUNRECOVERY) 1324 const_iv (RUNRECOVERY)
1246 const_iv (SECONDARY_BAD) 1325 const_iv (SECONDARY_BAD)
1247 const_iv (VERIFY_BAD) 1326 const_iv (VERIFY_BAD)
1248 1327
1328 const_iv (SALVAGE)
1329 const_iv (AGGRESSIVE)
1330 const_iv (PRINTABLE)
1331 const_iv (NOORDERCHK)
1332 const_iv (ORDERCHKONLY)
1333
1334 const_iv (ARCH_ABS)
1335 const_iv (ARCH_DATA)
1336 const_iv (ARCH_LOG)
1337 const_iv (ARCH_REMOVE)
1338
1249 const_iv (VERB_DEADLOCK) 1339 const_iv (VERB_DEADLOCK)
1250 const_iv (VERB_RECOVERY) 1340 const_iv (VERB_RECOVERY)
1251 const_iv (VERB_REPLICATION) 1341 const_iv (VERB_REPLICATION)
1252 const_iv (VERB_WAITSFOR) 1342 const_iv (VERB_WAITSFOR)
1253 1343
1254 const_iv (VERSION_MAJOR) 1344 const_iv (VERSION_MAJOR)
1255 const_iv (VERSION_MINOR) 1345 const_iv (VERSION_MINOR)
1256 const_iv (VERSION_PATCH) 1346 const_iv (VERSION_PATCH)
1347 const_iv (LOGVERSION)
1348 const_iv (LOGOLDVER)
1257#if DB_VERSION_MINOR >= 3 1349#if DB_VERSION_MINOR >= 3
1258 const_iv (INORDER) 1350 const_iv (INORDER)
1259 const_iv (LOCK_MAXWRITE) 1351 const_iv (LOCK_MAXWRITE)
1260 const_iv (SEQ_DEC) 1352 const_iv (SEQ_DEC)
1261 const_iv (SEQ_INC) 1353 const_iv (SEQ_INC)
1286 const_iv (PRIORITY_VERY_LOW) 1378 const_iv (PRIORITY_VERY_LOW)
1287 const_iv (PRIORITY_LOW) 1379 const_iv (PRIORITY_LOW)
1288 const_iv (PRIORITY_DEFAULT) 1380 const_iv (PRIORITY_DEFAULT)
1289 const_iv (PRIORITY_HIGH) 1381 const_iv (PRIORITY_HIGH)
1290 const_iv (PRIORITY_VERY_HIGH) 1382 const_iv (PRIORITY_VERY_HIGH)
1383 const_iv (IGNORE_LEASE)
1291#endif 1384#endif
1292#if DB_VERSION_MINOR >= 7 1385#if DB_VERSION_MINOR >= 7
1386 //const_iv (MULTIPLE_KEY)
1293 const_iv (LOG_DIRECT) 1387 const_iv (LOG_DIRECT)
1294 const_iv (LOG_DSYNC) 1388 const_iv (LOG_DSYNC)
1295 const_iv (LOG_AUTO_REMOVE) 1389 const_iv (LOG_AUTO_REMOVE)
1296 const_iv (LOG_IN_MEMORY) 1390 const_iv (LOG_IN_MEMORY)
1297 const_iv (LOG_ZERO) 1391 const_iv (LOG_ZERO)
1300 const_iv (LOG_AUTOREMOVE) 1394 const_iv (LOG_AUTOREMOVE)
1301# if DB_VERSION_MINOR >= 3 1395# if DB_VERSION_MINOR >= 3
1302 const_iv (DSYNC_LOG) 1396 const_iv (DSYNC_LOG)
1303 const_iv (LOG_INMEMORY) 1397 const_iv (LOG_INMEMORY)
1304# endif 1398# endif
1399#if DB_VERSION_MINOR >= 8
1400 const_iv (LOGVERSION_LATCHING)
1401#endif
1305#endif 1402#endif
1306 }; 1403 };
1307 1404
1405 bdb_stash = gv_stashpv ("BDB" , 1);
1406 bdb_env_stash = gv_stashpv ("BDB::Env" , 1);
1407 bdb_txn_stash = gv_stashpv ("BDB::Txn" , 1);
1408 bdb_cursor_stash = gv_stashpv ("BDB::Cursor" , 1);
1409 bdb_db_stash = gv_stashpv ("BDB::Db" , 1);
1410 bdb_sequence_stash = gv_stashpv ("BDB::Sequence", 1);
1411
1308 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1412 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
1309 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1413 newCONSTSUB (bdb_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
1414
1415 prepare_cb = &PL_sv_undef;
1310 1416
1311 { 1417 {
1312 /* we currently only allow version, minor-version and patchlevel to go up to 255 */ 1418 /* we currently only allow version, minor-version and patchlevel to go up to 255 */
1313 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; 1419 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH };
1314 1420
1315 newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); 1421 newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3));
1316 } 1422 }
1317 1423
1318 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1424 newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1319 1425
1320 create_respipe (); 1426 create_respipe ();
1321 1427
1322 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1428 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1323 patch_errno (); 1429 patch_errno ();
1401 1507
1402int 1508int
1403poll_fileno () 1509poll_fileno ()
1404 PROTOTYPE: 1510 PROTOTYPE:
1405 CODE: 1511 CODE:
1406 RETVAL = respipe [0]; 1512 RETVAL = s_epipe_fd (&respipe);
1407 OUTPUT: 1513 OUTPUT:
1408 RETVAL 1514 RETVAL
1409 1515
1410int 1516int
1411poll_cb (...) 1517poll_cb (...)
1453 RETVAL = started; 1559 RETVAL = started;
1454 if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); 1560 if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock);
1455 OUTPUT: 1561 OUTPUT:
1456 RETVAL 1562 RETVAL
1457 1563
1458void 1564SV *
1459set_sync_prepare (SV *cb) 1565set_sync_prepare (SV *cb)
1460 PROTOTYPE: & 1566 PROTOTYPE: &
1461 CODE: 1567 CODE:
1462 SvREFCNT_dec (prepare_cb); 1568 RETVAL = prepare_cb;
1463 prepare_cb = newSVsv (cb); 1569 prepare_cb = newSVsv (cb);
1570 OUTPUT:
1571 RETVAL
1464 1572
1465char * 1573char *
1466strerror (int errorno = errno) 1574strerror (int errorno = errno)
1467 PROTOTYPE: ;$ 1575 PROTOTYPE: ;$
1468 CODE: 1576 CODE:
1496db_env_open (DB_ENV *env, bdb_filename db_home, U32 open_flags, int mode, SV *callback = 0) 1604db_env_open (DB_ENV *env, bdb_filename db_home, U32 open_flags, int mode, SV *callback = 0)
1497 PREINIT: 1605 PREINIT:
1498 CALLBACK 1606 CALLBACK
1499 CODE: 1607 CODE:
1500{ 1608{
1501 dREQ (REQ_ENV_OPEN); 1609 dREQ (REQ_ENV_OPEN, 1);
1502 req->env = env; 1610 req->env = env;
1503 req->uint1 = open_flags | DB_THREAD; 1611 req->uint1 = open_flags | DB_THREAD;
1504 req->int1 = mode; 1612 req->int1 = mode;
1505 req->buf1 = strdup_ornull (db_home); 1613 req->buf1 = strdup_ornull (db_home);
1506 REQ_SEND; 1614 REQ_SEND;
1510db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) 1618db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0)
1511 PREINIT: 1619 PREINIT:
1512 CALLBACK 1620 CALLBACK
1513 CODE: 1621 CODE:
1514{ 1622{
1515 dREQ (REQ_ENV_CLOSE); 1623 dREQ (REQ_ENV_CLOSE, 0);
1624 ptr_nuke (ST (0));
1516 req->env = env; 1625 req->env = env;
1517 req->uint1 = flags; 1626 req->uint1 = flags;
1518 REQ_SEND; 1627 REQ_SEND;
1519 ptr_nuke (ST (0));
1520} 1628}
1521 1629
1522void 1630void
1523db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0) 1631db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0)
1524 PREINIT: 1632 PREINIT:
1525 CALLBACK 1633 CALLBACK
1526 CODE: 1634 CODE:
1527{ 1635{
1528 dREQ (REQ_ENV_TXN_CHECKPOINT); 1636 dREQ (REQ_ENV_TXN_CHECKPOINT, 1);
1529 req->env = env; 1637 req->env = env;
1530 req->uint1 = kbyte; 1638 req->uint1 = kbyte;
1531 req->int1 = min; 1639 req->int1 = min;
1532 req->uint2 = flags; 1640 req->uint2 = flags;
1533 REQ_SEND; 1641 REQ_SEND;
1537db_env_lock_detect (DB_ENV *env, U32 flags = 0, U32 atype = DB_LOCK_DEFAULT, SV *dummy = 0, SV *callback = 0) 1645db_env_lock_detect (DB_ENV *env, U32 flags = 0, U32 atype = DB_LOCK_DEFAULT, SV *dummy = 0, SV *callback = 0)
1538 PREINIT: 1646 PREINIT:
1539 CALLBACK 1647 CALLBACK
1540 CODE: 1648 CODE:
1541{ 1649{
1542 dREQ (REQ_ENV_LOCK_DETECT); 1650 dREQ (REQ_ENV_LOCK_DETECT, 1);
1543 req->env = env; 1651 req->env = env;
1544 req->uint1 = flags; 1652 req->uint1 = flags;
1545 req->uint2 = atype; 1653 req->uint2 = atype;
1546 /* req->int2 = 0; dummy */ 1654 /* req->int2 = 0; dummy */
1547 REQ_SEND; 1655 REQ_SEND;
1551db_env_memp_sync (DB_ENV *env, SV *dummy = 0, SV *callback = 0) 1659db_env_memp_sync (DB_ENV *env, SV *dummy = 0, SV *callback = 0)
1552 PREINIT: 1660 PREINIT:
1553 CALLBACK 1661 CALLBACK
1554 CODE: 1662 CODE:
1555{ 1663{
1556 dREQ (REQ_ENV_MEMP_SYNC); 1664 dREQ (REQ_ENV_MEMP_SYNC, 1);
1557 req->env = env; 1665 req->env = env;
1558 REQ_SEND; 1666 REQ_SEND;
1559} 1667}
1560 1668
1561void 1669void
1562db_env_memp_trickle (DB_ENV *env, int percent, SV *dummy = 0, SV *callback = 0) 1670db_env_memp_trickle (DB_ENV *env, int percent, SV *dummy = 0, SV *callback = 0)
1563 PREINIT: 1671 PREINIT:
1564 CALLBACK 1672 CALLBACK
1565 CODE: 1673 CODE:
1566{ 1674{
1567 dREQ (REQ_ENV_MEMP_TRICKLE); 1675 dREQ (REQ_ENV_MEMP_TRICKLE, 1);
1568 req->env = env; 1676 req->env = env;
1569 req->int1 = percent; 1677 req->int1 = percent;
1570 REQ_SEND; 1678 REQ_SEND;
1571} 1679}
1572 1680
1574db_env_dbremove (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, U32 flags = 0, SV *callback = 0) 1682db_env_dbremove (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, U32 flags = 0, SV *callback = 0)
1575 PREINIT: 1683 PREINIT:
1576 CALLBACK 1684 CALLBACK
1577 CODE: 1685 CODE:
1578{ 1686{
1579 dREQ (REQ_ENV_DBREMOVE); 1687 dREQ (REQ_ENV_DBREMOVE, 2);
1580 req->env = env; 1688 req->env = env;
1581 req->buf1 = strdup_ornull (file); 1689 req->buf1 = strdup_ornull (file);
1582 req->buf2 = strdup_ornull (database); 1690 req->buf2 = strdup_ornull (database);
1583 req->uint1 = flags; 1691 req->uint1 = flags;
1584 REQ_SEND; 1692 REQ_SEND;
1588db_env_dbrename (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, bdb_filename newname, U32 flags = 0, SV *callback = 0) 1696db_env_dbrename (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, bdb_filename newname, U32 flags = 0, SV *callback = 0)
1589 PREINIT: 1697 PREINIT:
1590 CALLBACK 1698 CALLBACK
1591 CODE: 1699 CODE:
1592{ 1700{
1593 dREQ (REQ_ENV_DBRENAME); 1701 dREQ (REQ_ENV_DBRENAME, 2);
1594 req->env = env; 1702 req->env = env;
1595 req->buf1 = strdup_ornull (file); 1703 req->buf1 = strdup_ornull (file);
1596 req->buf2 = strdup_ornull (database); 1704 req->buf2 = strdup_ornull (database);
1597 req->buf3 = strdup_ornull (newname); 1705 req->buf3 = strdup_ornull (newname);
1598 req->uint1 = flags; 1706 req->uint1 = flags;
1599 REQ_SEND; 1707 REQ_SEND;
1600} 1708}
1601 1709
1710void
1711db_env_log_archive (DB_ENV *env, SV_mutable *listp, U32 flags = 0, SV *callback = 0)
1712 PREINIT:
1713 CALLBACK
1714 CODE:
1715{
1716 dREQ (REQ_ENV_LOG_ARCHIVE, 1);
1717 req->sv1 = SvREFCNT_inc (listp);
1718 req->env = env;
1719 req->uint1 = flags;
1720 REQ_SEND;
1721}
1722
1602DB * 1723DB *
1603db_create (DB_ENV *env = 0, U32 flags = 0) 1724db_create (DB_ENV *env = 0, U32 flags = 0)
1604 CODE: 1725 CODE:
1605{ 1726{
1606 errno = db_create (&RETVAL, env, flags); 1727 errno = db_create (&RETVAL, env, flags);
1617db_open (DB *db, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, int type, U32 flags, int mode, SV *callback = 0) 1738db_open (DB *db, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, int type, U32 flags, int mode, SV *callback = 0)
1618 PREINIT: 1739 PREINIT:
1619 CALLBACK 1740 CALLBACK
1620 CODE: 1741 CODE:
1621{ 1742{
1622 dREQ (REQ_DB_OPEN); 1743 dREQ (REQ_DB_OPEN, 2);
1623 req->db = db; 1744 req->db = db;
1624 req->txn = txnid; 1745 req->txn = txnid;
1625 req->buf1 = strdup_ornull (file); 1746 req->buf1 = strdup_ornull (file);
1626 req->buf2 = strdup_ornull (database); 1747 req->buf2 = strdup_ornull (database);
1627 req->int1 = type; 1748 req->int1 = type;
1634db_close (DB *db, U32 flags = 0, SV *callback = 0) 1755db_close (DB *db, U32 flags = 0, SV *callback = 0)
1635 PREINIT: 1756 PREINIT:
1636 CALLBACK 1757 CALLBACK
1637 CODE: 1758 CODE:
1638{ 1759{
1639 dREQ (REQ_DB_CLOSE); 1760 dREQ (REQ_DB_CLOSE, 0);
1761 ptr_nuke (ST (0));
1640 req->db = db; 1762 req->db = db;
1641 req->uint1 = flags; 1763 req->uint1 = flags;
1642 req->sv1 = (SV *)db->app_private; 1764 req->sv1 = (SV *)db->app_private;
1643 REQ_SEND; 1765 REQ_SEND;
1644 ptr_nuke (ST (0));
1645} 1766}
1646 1767
1647#if DB_VERSION_MINOR >= 4 1768#if DB_VERSION_MINOR >= 4
1648 1769
1649void 1770void
1650db_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) 1771db_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)
1651 PREINIT: 1772 PREINIT:
1652 CALLBACK 1773 CALLBACK
1653 CODE: 1774 CODE:
1654{ 1775{
1655 dREQ (REQ_DB_COMPACT); 1776 dREQ (REQ_DB_COMPACT, 2);
1656 req->db = db; 1777 req->db = db;
1657 req->txn = txn; 1778 req->txn = txn;
1658 sv_to_dbt (&req->dbt1, start); 1779 if (start) sv_to_dbt (&req->dbt1, start);
1659 sv_to_dbt (&req->dbt2, stop); 1780 if (stop ) sv_to_dbt (&req->dbt2, stop );
1660 req->uint1 = flags; 1781 req->uint1 = flags;
1661 REQ_SEND; 1782 REQ_SEND;
1662} 1783}
1663 1784
1664#endif 1785#endif
1667db_sync (DB *db, U32 flags = 0, SV *callback = 0) 1788db_sync (DB *db, U32 flags = 0, SV *callback = 0)
1668 PREINIT: 1789 PREINIT:
1669 CALLBACK 1790 CALLBACK
1670 CODE: 1791 CODE:
1671{ 1792{
1672 dREQ (REQ_DB_SYNC); 1793 dREQ (REQ_DB_SYNC, 1);
1673 req->db = db; 1794 req->db = db;
1674 req->uint1 = flags; 1795 req->uint1 = flags;
1675 REQ_SEND; 1796 REQ_SEND;
1676} 1797}
1677 1798
1678void 1799void
1800db_verify (DB *db, bdb_filename file, bdb_filename database = 0, SV *dummy = 0, U32 flags = 0, SV *callback = 0)
1801 PREINIT:
1802 CALLBACK
1803 CODE:
1804{
1805 dREQ (REQ_DB_VERIFY, 1);
1806 ptr_nuke (ST (0)); /* verify destroys the database handle, hopefully it is freed as well */
1807 req->db = db;
1808 req->buf1 = strdup (file);
1809 req->buf2 = strdup_ornull (database);
1810 req->uint1 = flags;
1811 REQ_SEND;
1812}
1813
1814void
1679db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) 1815db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0)
1680 PREINIT: 1816 PREINIT:
1681 CALLBACK 1817 CALLBACK
1682 CODE: 1818 CODE:
1683{ 1819{
1684 dREQ (REQ_DB_SYNC); 1820 dREQ (REQ_DB_UPGRADE, 1);
1685 req->db = db; 1821 req->db = db;
1686 req->buf1 = strdup (file); 1822 req->buf1 = strdup (file);
1687 req->uint1 = flags; 1823 req->uint1 = flags;
1688 REQ_SEND; 1824 REQ_SEND;
1689} 1825}
1690 1826
1691void 1827void
1692db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = 0) 1828db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *key_range, U32 flags = 0, SV *callback = 0)
1693 PREINIT: 1829 PREINIT:
1694 CALLBACK 1830 CALLBACK
1695 CODE: 1831 CODE:
1696{ 1832{
1697 dREQ (REQ_DB_KEY_RANGE); 1833 dREQ (REQ_DB_KEY_RANGE, 2);
1698 req->db = db; 1834 req->db = db;
1699 req->txn = txn; 1835 req->txn = txn;
1700 sv_to_dbt (&req->dbt1, key); 1836 sv_to_dbt (&req->dbt1, key);
1701 req->uint1 = flags; 1837 req->uint1 = flags;
1702 req->sv1 = SvREFCNT_inc (key_range); SvREADONLY_on (key_range); 1838 req->sv1 = SvREFCNT_inc (key_range); SvREADONLY_on (key_range);
1707db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0) 1843db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0)
1708 PREINIT: 1844 PREINIT:
1709 CALLBACK 1845 CALLBACK
1710 CODE: 1846 CODE:
1711{ 1847{
1712 dREQ (REQ_DB_PUT); 1848 dREQ (REQ_DB_PUT, 2);
1713 req->db = db; 1849 req->db = db;
1714 req->txn = txn; 1850 req->txn = txn;
1715 sv_to_dbt (&req->dbt1, key); 1851 sv_to_dbt (&req->dbt1, key);
1716 sv_to_dbt (&req->dbt2, data); 1852 sv_to_dbt (&req->dbt2, data);
1717 req->uint1 = flags; 1853 req->uint1 = flags;
1724db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) 1860db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0)
1725 PREINIT: 1861 PREINIT:
1726 CALLBACK 1862 CALLBACK
1727 CODE: 1863 CODE:
1728{ 1864{
1729 dREQ (REQ_DB_EXISTS); 1865 dREQ (REQ_DB_EXISTS, 2);
1730 req->db = db; 1866 req->db = db;
1731 req->txn = txn; 1867 req->txn = txn;
1732 req->uint1 = flags; 1868 req->uint1 = flags;
1733 sv_to_dbt (&req->dbt1, key); 1869 sv_to_dbt (&req->dbt1, key);
1734 REQ_SEND; 1870 REQ_SEND;
1735} 1871}
1736 1872
1737#endif 1873#endif
1738 1874
1739void 1875void
1740db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0) 1876db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1741 PREINIT: 1877 PREINIT:
1742 CALLBACK 1878 CALLBACK
1743 CODE: 1879 CODE:
1744 if (SvREADONLY (data))
1745 croak ("can't modify read-only data scalar in db_get");
1746{ 1880{
1881 //TODO: key is somtimesmutable
1747 dREQ (REQ_DB_GET); 1882 dREQ (REQ_DB_GET, 2);
1748 req->db = db; 1883 req->db = db;
1749 req->txn = txn; 1884 req->txn = txn;
1750 req->uint1 = flags; 1885 req->uint1 = flags;
1751 sv_to_dbt (&req->dbt1, key); 1886 sv_to_dbt (&req->dbt1, key);
1752 req->dbt3.flags = DB_DBT_MALLOC; 1887 req->dbt3.flags = DB_DBT_MALLOC;
1753 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 1888 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1754 REQ_SEND; 1889 REQ_SEND;
1755} 1890}
1756 1891
1757void 1892void
1758db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) 1893db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1759 PREINIT: 1894 PREINIT:
1760 CALLBACK 1895 CALLBACK
1761 CODE: 1896 CODE:
1762 if (SvREADONLY (data))
1763 croak ("can't modify read-only data scalar in db_pget");
1764{ 1897{
1898 //TODO: key is somtimesmutable
1765 dREQ (REQ_DB_PGET); 1899 dREQ (REQ_DB_PGET, 2);
1900 req->db = db;
1901 req->txn = txn;
1902 req->uint1 = flags;
1903
1904 sv_to_dbt (&req->dbt1, key);
1905
1906 req->dbt2.flags = DB_DBT_MALLOC;
1907 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1908
1909 req->dbt3.flags = DB_DBT_MALLOC;
1910 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1911 REQ_SEND;
1912}
1913
1914void
1915db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0)
1916 PREINIT:
1917 CALLBACK
1918 CODE:
1919{
1920 dREQ (REQ_DB_DEL, 2);
1766 req->db = db; 1921 req->db = db;
1767 req->txn = txn; 1922 req->txn = txn;
1768 req->uint1 = flags; 1923 req->uint1 = flags;
1769 sv_to_dbt (&req->dbt1, key); 1924 sv_to_dbt (&req->dbt1, key);
1770 sv_to_dbt (&req->dbt2, pkey);
1771 req->dbt3.flags = DB_DBT_MALLOC;
1772 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1773 REQ_SEND; 1925 REQ_SEND;
1774} 1926}
1775 1927
1776void 1928void
1777db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) 1929db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1778 PREINIT: 1930 PREINIT:
1779 CALLBACK 1931 CALLBACK
1780 CODE: 1932 CODE:
1781{ 1933{
1782 dREQ (REQ_DB_DEL); 1934 dREQ (REQ_TXN_COMMIT, 0);
1783 req->db = db; 1935 ptr_nuke (ST (0));
1784 req->txn = txn; 1936 req->txn = txn;
1785 req->uint1 = flags; 1937 req->uint1 = flags;
1786 sv_to_dbt (&req->dbt1, key);
1787 REQ_SEND; 1938 REQ_SEND;
1788} 1939}
1789 1940
1790void 1941void
1942db_txn_abort (DB_TXN *txn, SV *callback = 0)
1943 PREINIT:
1944 CALLBACK
1945 CODE:
1946{
1947 dREQ (REQ_TXN_ABORT, 0);
1948 ptr_nuke (ST (0));
1949 req->txn = txn;
1950 REQ_SEND;
1951}
1952
1953void
1791db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) 1954db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1792 PREINIT: 1955 PREINIT:
1793 CALLBACK 1956 CALLBACK
1794 CODE: 1957 CODE:
1795{ 1958{
1796 dREQ (REQ_TXN_COMMIT); 1959 dREQ (REQ_TXN_FINISH, 0);
1960 ptr_nuke (ST (0));
1797 req->txn = txn; 1961 req->txn = txn;
1798 req->uint1 = flags; 1962 req->uint1 = flags;
1799 REQ_SEND; 1963 REQ_SEND;
1964}
1965
1966void
1967db_c_close (DBC *dbc, SV *callback = 0)
1968 PREINIT:
1969 CALLBACK
1970 CODE:
1971{
1972 dREQ (REQ_C_CLOSE, 0);
1800 ptr_nuke (ST (0)); 1973 ptr_nuke (ST (0));
1801}
1802
1803void
1804db_txn_abort (DB_TXN *txn, SV *callback = 0)
1805 PREINIT:
1806 CALLBACK
1807 CODE:
1808{
1809 dREQ (REQ_TXN_ABORT);
1810 req->txn = txn;
1811 REQ_SEND;
1812 ptr_nuke (ST (0));
1813}
1814
1815void
1816db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1817 PREINIT:
1818 CALLBACK
1819 CODE:
1820{
1821 dREQ (REQ_TXN_FINISH);
1822 req->txn = txn;
1823 req->uint1 = flags;
1824 REQ_SEND;
1825 ptr_nuke (ST (0));
1826}
1827
1828void
1829db_c_close (DBC *dbc, SV *callback = 0)
1830 PREINIT:
1831 CALLBACK
1832 CODE:
1833{
1834 dREQ (REQ_C_CLOSE);
1835 req->dbc = dbc; 1974 req->dbc = dbc;
1836 REQ_SEND; 1975 REQ_SEND;
1837 ptr_nuke (ST (0));
1838} 1976}
1839 1977
1840void 1978void
1841db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0) 1979db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0)
1842 PREINIT: 1980 PREINIT:
1843 CALLBACK 1981 CALLBACK
1844 CODE: 1982 CODE:
1845{ 1983{
1846 dREQ (REQ_C_COUNT); 1984 dREQ (REQ_C_COUNT, 1);
1847 req->dbc = dbc; 1985 req->dbc = dbc;
1848 req->sv1 = SvREFCNT_inc (count); 1986 req->sv1 = SvREFCNT_inc (count);
1849 REQ_SEND; 1987 REQ_SEND;
1850} 1988}
1851 1989
1853db_c_put (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0) 1991db_c_put (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0)
1854 PREINIT: 1992 PREINIT:
1855 CALLBACK 1993 CALLBACK
1856 CODE: 1994 CODE:
1857{ 1995{
1858 dREQ (REQ_C_PUT); 1996 dREQ (REQ_C_PUT, 1);
1859 req->dbc = dbc; 1997 req->dbc = dbc;
1860 sv_to_dbt (&req->dbt1, key); 1998 sv_to_dbt (&req->dbt1, key);
1861 sv_to_dbt (&req->dbt2, data); 1999 sv_to_dbt (&req->dbt2, data);
1862 req->uint1 = flags; 2000 req->uint1 = flags;
1863 REQ_SEND; 2001 REQ_SEND;
1864} 2002}
1865 2003
1866void 2004void
1867db_c_get (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0) 2005db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1868 PREINIT: 2006 PREINIT:
1869 CALLBACK 2007 CALLBACK
1870 CODE: 2008 CODE:
1871{ 2009{
2010 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
2011 croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET");
2012 if (SvPOKp (key) && !sv_utf8_downgrade (key, 1))
2013 croak ("argument \"%s\" must be byte/octet-encoded in %s",
2014 "key",
2015 "BDB::db_c_get");
2016
2017 {
1872 dREQ (REQ_C_GET); 2018 dREQ (REQ_C_GET, 1);
2019 req->dbc = dbc;
2020 req->uint1 = flags;
2021 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
2022 sv_to_dbt (&req->dbt1, key);
2023 else
2024 {
2025 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
2026 sv_to_dbt (&req->dbt1, key);
2027 else
2028 req->dbt1.flags = DB_DBT_MALLOC;
2029
2030 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
2031 }
2032
2033 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
2034 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
2035 sv_to_dbt (&req->dbt3, data);
2036 else
2037 req->dbt3.flags = DB_DBT_MALLOC;
2038
2039 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
2040 REQ_SEND;
2041 }
2042}
2043
2044void
2045db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0)
2046 PREINIT:
2047 CALLBACK
2048 CODE:
2049{
2050 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
2051 croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET");
2052 if (SvPOKp (key) && !sv_utf8_downgrade (key, 1))
2053 croak ("argument \"%s\" must be byte/octet-encoded in %s",
2054 "key",
2055 "BDB::db_c_pget");
2056
2057 {
2058 dREQ (REQ_C_PGET, 1);
2059 req->dbc = dbc;
2060 req->uint1 = flags;
2061 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
2062 sv_to_dbt (&req->dbt1, key);
2063 else
2064 {
2065 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
2066 sv_to_dbt (&req->dbt1, key);
2067 else
2068 req->dbt1.flags = DB_DBT_MALLOC;
2069
2070 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
2071 }
2072
2073 req->dbt2.flags = DB_DBT_MALLOC;
2074 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
2075
2076 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
2077 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
2078 sv_to_dbt (&req->dbt3, data);
2079 else
2080 req->dbt3.flags = DB_DBT_MALLOC;
2081
2082 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
2083 REQ_SEND;
2084 }
2085}
2086
2087void
2088db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0)
2089 PREINIT:
2090 CALLBACK
2091 CODE:
2092{
2093 dREQ (REQ_C_DEL, 1);
1873 req->dbc = dbc; 2094 req->dbc = dbc;
1874 req->uint1 = flags; 2095 req->uint1 = flags;
1875 if ((flags & DB_SET) == DB_SET
1876 || (flags & DB_SET_RANGE) == DB_SET_RANGE)
1877 sv_to_dbt (&req->dbt1, key);
1878 else
1879 req->dbt1.flags = DB_DBT_MALLOC;
1880
1881 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1882
1883 if ((flags & DB_GET_BOTH) == DB_GET_BOTH
1884 || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE)
1885 sv_to_dbt (&req->dbt3, data);
1886 else
1887 req->dbt3.flags = DB_DBT_MALLOC;
1888
1889 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1890 REQ_SEND;
1891}
1892
1893void
1894db_c_pget (DBC *dbc, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0)
1895 PREINIT:
1896 CALLBACK
1897 CODE:
1898{
1899 dREQ (REQ_C_PGET);
1900 req->dbc = dbc;
1901 req->uint1 = flags;
1902 if ((flags & DB_SET) == DB_SET
1903 || (flags & DB_SET_RANGE) == DB_SET_RANGE)
1904 sv_to_dbt (&req->dbt1, key);
1905 else
1906 req->dbt1.flags = DB_DBT_MALLOC;
1907
1908 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1909
1910 req->dbt2.flags = DB_DBT_MALLOC;
1911 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1912
1913 if ((flags & DB_GET_BOTH) == DB_GET_BOTH
1914 || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE)
1915 sv_to_dbt (&req->dbt3, data);
1916 else
1917 req->dbt3.flags = DB_DBT_MALLOC;
1918
1919 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1920 REQ_SEND;
1921}
1922
1923void
1924db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0)
1925 PREINIT:
1926 CALLBACK
1927 CODE:
1928{
1929 dREQ (REQ_C_DEL);
1930 req->dbc = dbc;
1931 req->uint1 = flags;
1932 REQ_SEND; 2096 REQ_SEND;
1933} 2097}
1934 2098
1935 2099
1936#if DB_VERSION_MINOR >= 3 2100#if DB_VERSION_MINOR >= 3
1939db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) 2103db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0)
1940 PREINIT: 2104 PREINIT:
1941 CALLBACK 2105 CALLBACK
1942 CODE: 2106 CODE:
1943{ 2107{
1944 dREQ (REQ_SEQ_OPEN); 2108 dREQ (REQ_SEQ_OPEN, 2);
1945 req->seq = seq; 2109 req->seq = seq;
1946 req->txn = txnid; 2110 req->txn = txnid;
1947 req->uint1 = flags | DB_THREAD; 2111 req->uint1 = flags | DB_THREAD;
1948 sv_to_dbt (&req->dbt1, key); 2112 sv_to_dbt (&req->dbt1, key);
1949 REQ_SEND; 2113 REQ_SEND;
1953db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) 2117db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0)
1954 PREINIT: 2118 PREINIT:
1955 CALLBACK 2119 CALLBACK
1956 CODE: 2120 CODE:
1957{ 2121{
1958 dREQ (REQ_SEQ_CLOSE); 2122 dREQ (REQ_SEQ_CLOSE, 0);
2123 ptr_nuke (ST (0));
1959 req->seq = seq; 2124 req->seq = seq;
1960 req->uint1 = flags; 2125 req->uint1 = flags;
1961 REQ_SEND; 2126 REQ_SEND;
1962 ptr_nuke (ST (0));
1963} 2127}
1964 2128
1965void 2129void
1966db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0) 2130db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV_mutable *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0)
1967 PREINIT: 2131 PREINIT:
1968 CALLBACK 2132 CALLBACK
1969 CODE: 2133 CODE:
1970{ 2134{
1971 dREQ (REQ_SEQ_GET); 2135 dREQ (REQ_SEQ_GET, 2);
1972 req->seq = seq; 2136 req->seq = seq;
1973 req->txn = txnid; 2137 req->txn = txnid;
1974 req->int1 = delta; 2138 req->int1 = delta;
1975 req->uint1 = flags; 2139 req->uint1 = flags;
1976 req->sv1 = SvREFCNT_inc (seq_value); SvREADONLY_on (seq_value); 2140 req->sv1 = SvREFCNT_inc (seq_value); SvREADONLY_on (seq_value);
1981db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = 0) 2145db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = 0)
1982 PREINIT: 2146 PREINIT:
1983 CALLBACK 2147 CALLBACK
1984 CODE: 2148 CODE:
1985{ 2149{
1986 dREQ (REQ_SEQ_REMOVE); 2150 dREQ (REQ_SEQ_REMOVE, 2);
1987 req->seq = seq; 2151 req->seq = seq;
1988 req->txn = txnid; 2152 req->txn = txnid;
1989 req->uint1 = flags; 2153 req->uint1 = flags;
1990 REQ_SEND; 2154 REQ_SEND;
1991} 2155}
2200 CODE: 2364 CODE:
2201 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); 2365 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache);
2202 OUTPUT: 2366 OUTPUT:
2203 RETVAL 2367 RETVAL
2204 2368
2369int set_pagesize (DB *db, U32 pagesize)
2370 CODE:
2371 RETVAL = db->set_pagesize (db, pagesize);
2372 OUTPUT:
2373 RETVAL
2374
2205int set_flags (DB *db, U32 flags) 2375int set_flags (DB *db, U32 flags)
2206 CODE: 2376 CODE:
2207 RETVAL = db->set_flags (db, flags); 2377 RETVAL = db->set_flags (db, flags);
2208 OUTPUT: 2378 OUTPUT:
2209 RETVAL 2379 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines