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

Comparing BDB/BDB.xs (file contents):
Revision 1.55 by root, Fri Sep 26 02:37:33 2008 UTC vs.
Revision 1.81 by root, Tue Feb 2 04:28:06 2016 UTC

1#include <sys/user.h>
2#include <sys/ptrace.h>
3
4#define X_STACKSIZE 1024 * 128 + sizeof (long) * 64 * 1024 / 4 1#define X_STACKSIZE 1024 * 128 + sizeof (long) * 64 * 1024 / 4
5 2
6#include "xthread.h" 3#include "xthread.h"
7 4
8#include <errno.h> 5#include <errno.h>
9 6
10#include "EXTERN.h" 7#include "EXTERN.h"
11#include "perl.h" 8#include "perl.h"
12#include "XSUB.h" 9#include "XSUB.h"
13 10
11#include "schmorp.h"
12
14// perl stupidly defines these as macros, breaking 13// perl stupidly defines these as argument-less macros, breaking
15// lots and lots of code. 14// lots and lots of code.
16#undef open 15#undef open
17#undef close 16#undef close
18#undef abort 17#undef abort
19#undef malloc 18#undef malloc
32# include <unistd.h> 31# include <unistd.h>
33#endif 32#endif
34 33
35#include <db.h> 34#include <db.h>
36 35
37#if DB_VERSION_MAJOR != 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 3) 36#define DBVER DB_VERSION_MAJOR * 100 + DB_VERSION_MINOR
37
38#if DBVER < 403
38# error you need Berkeley DB 4.3 or a newer 4.x version installed 39# error you need Berkeley DB 4.3 or a newer version installed
39#endif 40#endif
40 41
41/* number of seconds after which idle threads exit */ 42/* number of seconds after which idle threads exit */
42#define IDLE_TIMEOUT 10 43#define IDLE_TIMEOUT 10
43 44
51typedef DB_ENV DB_ENV_ornuked; 52typedef DB_ENV DB_ENV_ornuked;
52typedef DB_TXN DB_TXN_ornuked; 53typedef DB_TXN DB_TXN_ornuked;
53typedef DBC DBC_ornuked; 54typedef DBC DBC_ornuked;
54typedef DB DB_ornuked; 55typedef DB DB_ornuked;
55 56
56#if DB_VERSION_MINOR >= 3 57#if DBVER >= 403
57typedef DB_SEQUENCE DB_SEQUENCE_ornull; 58typedef DB_SEQUENCE DB_SEQUENCE_ornull;
58typedef DB_SEQUENCE DB_SEQUENCE_ornuked; 59typedef DB_SEQUENCE DB_SEQUENCE_ornuked;
59#endif 60#endif
60 61
61typedef SV SV8; /* byte-sv, used for argument-checking */
62typedef char *bdb_filename; 62typedef char *bdb_filename;
63 63
64static SV *prepare_cb; 64static SV *prepare_cb;
65 65
66#if DB_VERSION_MINOR >= 6 66static HV
67 *bdb_stash,
68 *bdb_env_stash,
69 *bdb_txn_stash,
70 *bdb_cursor_stash,
71 *bdb_db_stash,
72 *bdb_sequence_stash;
73
74#if DBVER >= 406
67# define c_close close 75# define c_close close
68# define c_count count 76# define c_count count
69# define c_del del 77# define c_del del
70# define c_dup dup 78# define c_dup dup
71# define c_get get 79# define c_get get
153 161
154enum { 162enum {
155 REQ_QUIT, 163 REQ_QUIT,
156 REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, 164 REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT,
157 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, 165 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME,
166 REQ_ENV_LOG_ARCHIVE, REQ_ENV_LSN_RESET, REQ_ENV_FILEID_RESET,
158 REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, 167 REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_VERIFY, REQ_DB_UPGRADE,
159 REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, 168 REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE,
160 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, 169 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH,
161 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, 170 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL,
162 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, 171 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE,
163}; 172};
179 char *buf1, *buf2, *buf3; 188 char *buf1, *buf2, *buf3;
180 SV *sv1, *sv2, *sv3; 189 SV *sv1, *sv2, *sv3;
181 190
182 DBT dbt1, dbt2, dbt3; 191 DBT dbt1, dbt2, dbt3;
183 DB_KEY_RANGE key_range; 192 DB_KEY_RANGE key_range;
184#if DB_VERSION_MINOR >= 3 193#if DBVER >= 403
185 DB_SEQUENCE *seq; 194 DB_SEQUENCE *seq;
186 db_seq_t seq_t; 195 db_seq_t seq_t;
187#endif 196#endif
188 197
189 SV *rsv1, *rsv2; // keep some request objects alive 198 SV *rsv1, *rsv2; // keep some request objects alive
217static int next_pri = DEFAULT_PRI + PRI_BIAS; 226static int next_pri = DEFAULT_PRI + PRI_BIAS;
218 227
219static unsigned int started, idle, wanted; 228static unsigned int started, idle, wanted;
220 229
221/* worker threads management */ 230/* worker threads management */
222static mutex_t wrklock = X_MUTEX_INIT; 231static xmutex_t wrklock = X_MUTEX_INIT;
223 232
224typedef struct worker { 233typedef struct worker {
225 /* locked by wrklock */ 234 /* locked by wrklock */
226 struct worker *prev, *next; 235 struct worker *prev, *next;
227 236
228 thread_t tid; 237 xthread_t tid;
229 238
230 /* locked by reslock, reqlock or wrklock */ 239 /* locked by reslock, reqlock or wrklock */
231 bdb_req req; /* currently processed request */ 240 bdb_req req; /* currently processed request */
232 void *dbuf; 241 void *dbuf;
233 DIR *dirp; 242 DIR *dirp;
248} 257}
249 258
250static volatile unsigned int nreqs, nready, npending; 259static volatile unsigned int nreqs, nready, npending;
251static volatile unsigned int max_idle = 4; 260static volatile unsigned int max_idle = 4;
252static volatile unsigned int max_outstanding = 0xffffffff; 261static volatile unsigned int max_outstanding = 0xffffffff;
253static int respipe_osf [2], respipe [2] = { -1, -1 }; 262static s_epipe respipe;
254 263
255static mutex_t reslock = X_MUTEX_INIT; 264static xmutex_t reslock = X_MUTEX_INIT;
256static mutex_t reqlock = X_MUTEX_INIT; 265static xmutex_t reqlock = X_MUTEX_INIT;
257static cond_t reqwait = X_COND_INIT; 266static xcond_t reqwait = X_COND_INIT;
258 267
259#if WORDACCESS_UNSAFE 268#if WORDACCESS_UNSAFE
260 269
261static unsigned int get_nready (void) 270static unsigned int get_nready (void)
262{ 271{
353 abort (); 362 abort ();
354} 363}
355 364
356static int poll_cb (void); 365static int poll_cb (void);
357static void req_free (bdb_req req); 366static void req_free (bdb_req req);
358static void req_cancel (bdb_req req);
359 367
360static int req_invoke (bdb_req req) 368static int req_invoke (bdb_req req)
361{ 369{
362 switch (req->type) 370 switch (req->type)
363 { 371 {
382 390
383 av_push (av, newSVnv (req->key_range.less)); 391 av_push (av, newSVnv (req->key_range.less));
384 av_push (av, newSVnv (req->key_range.equal)); 392 av_push (av, newSVnv (req->key_range.equal));
385 av_push (av, newSVnv (req->key_range.greater)); 393 av_push (av, newSVnv (req->key_range.greater));
386 394
395 av = (AV *)newRV_noinc ((SV *)av);
396
387 SvREADONLY_off (req->sv1); 397 SvREADONLY_off (req->sv1);
388 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); 398 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av));
399 SvREFCNT_dec (av);
389 SvREFCNT_dec (req->sv1); 400 SvREFCNT_dec (req->sv1);
390 } 401 }
391 break; 402 break;
392 403
393#if DB_VERSION_MINOR >= 3 404#if DBVER >= 403
394 case REQ_SEQ_GET: 405 case REQ_SEQ_GET:
395 SvREADONLY_off (req->sv1); 406 SvREADONLY_off (req->sv1);
396 407
397 if (sizeof (IV) > 4) 408 if (sizeof (IV) > 4)
398 sv_setiv_mg (req->sv1, (IV)req->seq_t); 409 sv_setiv_mg (req->sv1, (IV)req->seq_t);
400 sv_setnv_mg (req->sv1, (NV)req->seq_t); 411 sv_setnv_mg (req->sv1, (NV)req->seq_t);
401 412
402 SvREFCNT_dec (req->sv1); 413 SvREFCNT_dec (req->sv1);
403 break; 414 break;
404#endif 415#endif
416
417 case REQ_ENV_LOG_ARCHIVE:
418 {
419 AV *av = newAV ();
420 char **listp = (char **)req->buf1;
421
422 if (listp)
423 while (*listp)
424 av_push (av, newSVpv (*listp, 0)), ++listp;
425
426 av = (AV *)newRV_noinc ((SV *)av);
427
428 SvREADONLY_off (req->sv1);
429 sv_setsv_mg (req->sv1, (SV *)av);
430 SvREFCNT_dec (av);
431 SvREFCNT_dec (req->sv1);
432 }
433 break;
405 } 434 }
406 435
407 errno = req->result; 436 errno = req->result;
408 437
409 if (req->callback) 438 if (req->callback)
439 free (req->buf3); 468 free (req->buf3);
440 469
441 Safefree (req); 470 Safefree (req);
442} 471}
443 472
444#ifdef USE_SOCKETS_AS_HANDLES
445# define TO_SOCKET(x) (win32_get_osfhandle (x))
446#else
447# define TO_SOCKET(x) (x)
448#endif
449
450static void 473static void
451create_respipe (void) 474create_respipe (void)
452{ 475{
453#ifdef _WIN32
454 int arg; /* argg */
455#endif
456 int old_readfd = respipe [0];
457
458 if (respipe [1] >= 0)
459 respipe_close (TO_SOCKET (respipe [1]));
460
461#ifdef _WIN32
462 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe))
463#else
464 if (pipe (respipe)) 476 if (s_epipe_renew (&respipe))
465#endif 477 croak ("BDB: unable to create event pipe");
466 croak ("unable to initialize result pipe");
467
468 if (old_readfd >= 0)
469 {
470 if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0)
471 croak ("unable to initialize result pipe(2)");
472
473 respipe_close (respipe [0]);
474 respipe [0] = old_readfd;
475 }
476
477#ifdef _WIN32
478 arg = 1;
479 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg)
480 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg))
481#else
482 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
483 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
484#endif
485 croak ("unable to initialize result pipe(3)");
486
487 respipe_osf [0] = TO_SOCKET (respipe [0]);
488 respipe_osf [1] = TO_SOCKET (respipe [1]);
489} 478}
490 479
491static void bdb_request (bdb_req req); 480static void bdb_request (bdb_req req);
492X_THREAD_PROC (bdb_proc); 481X_THREAD_PROC (bdb_proc);
493 482
497 486
498 if (!wrk) 487 if (!wrk)
499 croak ("unable to allocate worker thread data"); 488 croak ("unable to allocate worker thread data");
500 489
501 X_LOCK (wrklock); 490 X_LOCK (wrklock);
502 if (thread_create (&wrk->tid, bdb_proc, (void *)wrk)) 491 if (xthread_create (&wrk->tid, bdb_proc, (void *)wrk))
503 { 492 {
504 wrk->prev = &wrk_first; 493 wrk->prev = &wrk_first;
505 wrk->next = wrk_first.next; 494 wrk->next = wrk_first.next;
506 wrk_first.next->prev = wrk; 495 wrk_first.next->prev = wrk;
507 wrk_first.next = wrk; 496 wrk_first.next = wrk;
629 end_thread (); 618 end_thread ();
630} 619}
631 620
632static void poll_wait (void) 621static void poll_wait (void)
633{ 622{
634 fd_set rfd;
635
636 while (nreqs) 623 while (nreqs)
637 { 624 {
638 int size; 625 int size;
639 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 626 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
640 size = res_queue.size; 627 size = res_queue.size;
643 if (size) 630 if (size)
644 return; 631 return;
645 632
646 maybe_start_thread (); 633 maybe_start_thread ();
647 634
648 FD_ZERO (&rfd); 635 s_epipe_wait (&respipe);
649 FD_SET (respipe [0], &rfd);
650
651 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
652 } 636 }
653} 637}
654 638
655static int poll_cb (void) 639static int poll_cb (void)
656{ 640{
676 if (req) 660 if (req)
677 { 661 {
678 --npending; 662 --npending;
679 663
680 if (!res_queue.size) 664 if (!res_queue.size)
681 {
682 /* read any signals sent by the worker threads */ 665 /* read any signals sent by the worker threads */
683 char buf [4]; 666 s_epipe_drain (&respipe);
684 while (respipe_read (respipe [0], buf, 4) == 4)
685 ;
686 }
687 } 667 }
688 668
689 X_UNLOCK (reslock); 669 X_UNLOCK (reslock);
690 670
691 if (!req) 671 if (!req)
771 751
772 case REQ_DB_CLOSE: 752 case REQ_DB_CLOSE:
773 req->result = req->db->close (req->db, req->uint1); 753 req->result = req->db->close (req->db, req->uint1);
774 break; 754 break;
775 755
776#if DB_VERSION_MINOR >= 4 756#if DBVER >= 404
777 case REQ_DB_COMPACT: 757 case REQ_DB_COMPACT:
778 req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0); 758 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);
779 break; 759 break;
780#endif 760#endif
781 761
782 case REQ_DB_SYNC: 762 case REQ_DB_SYNC:
783 req->result = req->db->sync (req->db, req->uint1); 763 req->result = req->db->sync (req->db, req->uint1);
784 break; 764 break;
785 765
766 case REQ_DB_VERIFY:
767 req->result = req->db->verify (req->db, req->buf1, req->buf2, 0, req->uint1);
768 break;
769
786 case REQ_DB_UPGRADE: 770 case REQ_DB_UPGRADE:
787 req->result = req->db->upgrade (req->db, req->buf1, req->uint1); 771 req->result = req->db->upgrade (req->db, req->buf1, req->uint1);
788 break; 772 break;
789 773
790 case REQ_DB_PUT: 774 case REQ_DB_PUT:
791 req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); 775 req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1);
792 break; 776 break;
793 777
794#if DB_VERSION_MINOR >= 6 778#if DBVER >= 406
795 case REQ_DB_EXISTS: 779 case REQ_DB_EXISTS:
796 req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1); 780 req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1);
797 break; 781 break;
798#endif 782#endif
799 case REQ_DB_GET: 783 case REQ_DB_GET:
857 841
858 case REQ_C_DEL: 842 case REQ_C_DEL:
859 req->result = req->dbc->c_del (req->dbc, req->uint1); 843 req->result = req->dbc->c_del (req->dbc, req->uint1);
860 break; 844 break;
861 845
862#if DB_VERSION_MINOR >= 3 846#if DBVER >= 403
863 case REQ_SEQ_OPEN: 847 case REQ_SEQ_OPEN:
864 req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); 848 req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1);
865 break; 849 break;
866 850
867 case REQ_SEQ_CLOSE: 851 case REQ_SEQ_CLOSE:
874 858
875 case REQ_SEQ_REMOVE: 859 case REQ_SEQ_REMOVE:
876 req->result = req->seq->remove (req->seq, req->txn, req->uint1); 860 req->result = req->seq->remove (req->seq, req->txn, req->uint1);
877 break; 861 break;
878#endif 862#endif
863
864#if DBVER >= 407
865 case REQ_ENV_LSN_RESET:
866 req->result = req->env->lsn_reset (req->env, req->buf1, req->uint1);
867 break;
868
869 case REQ_ENV_FILEID_RESET:
870 req->result = req->env->fileid_reset (req->env, req->buf1, req->uint1);
871 break;
872#endif
873
874 case REQ_ENV_LOG_ARCHIVE:
875 {
876 char **listp = 0; /* DB_ARCH_REMOVE does not touch listp, contrary to docs */
877 req->result = req->env->log_archive (req->env, &listp, req->uint1);
878 req->buf1 = (char *)listp;
879 }
880 break;
879 881
880 default: 882 default:
881 req->result = ENOSYS; 883 req->result = ENOSYS;
882 break; 884 break;
883 } 885 }
895 /* try to distribute timeouts somewhat evenly */ 897 /* try to distribute timeouts somewhat evenly */
896 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 898 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
897 899
898 for (;;) 900 for (;;)
899 { 901 {
900 ts.tv_sec = time (0) + IDLE_TIMEOUT; 902 ts.tv_sec = time (0) + IDLE_TIMEOUT;
901 903
902 X_LOCK (reqlock); 904 X_LOCK (reqlock);
903 905
904 for (;;) 906 for (;;)
905 { 907 {
950 X_LOCK (reslock); 952 X_LOCK (reslock);
951 953
952 ++npending; 954 ++npending;
953 955
954 if (!reqq_push (&res_queue, req)) 956 if (!reqq_push (&res_queue, req))
955 /* write a dummy byte to the pipe so fh becomes ready */ 957 s_epipe_signal (&respipe);
956 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
957 958
958 self->req = 0; 959 self->req = 0;
959 worker_clear (self); 960 worker_clear (self);
960 961
961 X_UNLOCK (reslock); 962 X_UNLOCK (reslock);
1023 next_pri = DEFAULT_PRI + PRI_BIAS; \ 1024 next_pri = DEFAULT_PRI + PRI_BIAS; \
1024 \ 1025 \
1025 if (callback && SvOK (callback)) \ 1026 if (callback && SvOK (callback)) \
1026 croak ("callback has illegal type or extra arguments"); \ 1027 croak ("callback has illegal type or extra arguments"); \
1027 \ 1028 \
1028 Newz (0, req, 1, bdb_cb); \ 1029 Newz (0, req, 1, bdb_cb); \
1029 if (!req) \ 1030 if (!req) \
1030 croak ("out of memory during bdb_req allocation"); \ 1031 croak ("out of memory during bdb_req allocation"); \
1031 \ 1032 \
1032 req->callback = SvREFCNT_inc (cb); \ 1033 req->callback = SvREFCNT_inc (cb); \
1033 req->type = (reqtype); \ 1034 req->type = (reqtype); \
1034 req->pri = req_pri; \ 1035 req->pri = req_pri; \
1035 if (rsvcnt >= 1) req->rsv1 = SvREFCNT_inc (ST (0)); \ 1036 if (rsvcnt >= 1) req->rsv1 = SvREFCNT_inc (ST (0)); \
1036 if (rsvcnt >= 2) req->rsv2 = SvREFCNT_inc (ST (1)); \ 1037 if (rsvcnt >= 2) req->rsv2 = SvREFCNT_inc (ST (1)); \
1037 (void)0; 1038 (void)0;
1038 1039
1039#define REQ_SEND \ 1040#define REQ_SEND \
1040 req_send (req) 1041 req_send (req)
1041 1042
1042#define SvPTR(var, arg, type, class, nullok) \ 1043#define SvPTR(var, arg, type, stash, class, nullok) \
1043 if (!SvOK (arg)) \ 1044 if (!SvOK (arg)) \
1044 { \ 1045 { \
1045 if (nullok != 1) \ 1046 if (nullok != 1) \
1046 croak (# var " must be a " # class " object, not undef"); \ 1047 croak (# var " must be a " # class " object, not undef"); \
1047 \ 1048 \
1048 (var) = 0; \ 1049 (var) = 0; \
1049 } \ 1050 } \
1050 else if (sv_derived_from ((arg), # class)) \ 1051 else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \
1051 { \ 1052 { \
1052 IV tmp = SvIV ((SV*) SvRV (arg)); \ 1053 IV tmp = SvIV ((SV*) SvRV (arg)); \
1053 (var) = INT2PTR (type, tmp); \ 1054 (var) = INT2PTR (type, tmp); \
1054 if (!var && nullok != 2) \ 1055 if (!var && nullok != 2) \
1055 croak (# var " is not a valid " # class " object anymore"); \ 1056 croak (# var " is not a valid " # class " object anymore"); \
1058 croak (# var " is not of type " # class); 1059 croak (# var " is not of type " # class);
1059 1060
1060#define ARG_MUTABLE(name) \ 1061#define ARG_MUTABLE(name) \
1061 if (SvREADONLY (name)) \ 1062 if (SvREADONLY (name)) \
1062 croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); 1063 croak ("argument " #name " is read-only/constant, but the request requires it to be mutable");
1064
1065static SV *
1066newSVptr (void *ptr, HV *stash)
1067{
1068 SV *rv = NEWSV (0, 0);
1069 sv_upgrade (rv, SVt_PVMG);
1070 sv_setiv (rv, PTR2IV (ptr));
1071
1072 return sv_bless (newRV_noinc (rv), stash);
1073}
1063 1074
1064static void 1075static void
1065ptr_nuke (SV *sv) 1076ptr_nuke (SV *sv)
1066{ 1077{
1067 assert (SvROK (sv)); 1078 assert (SvROK (sv));
1138 } 1149 }
1139 1150
1140 return 0; 1151 return 0;
1141} 1152}
1142 1153
1154/*****************************************************************************/
1155
1156#if 0
1157static int
1158bt_pfxc_compare (DB *db, const DBT *dbt1, const DBT *dbt2)
1159{
1160 ssize_t size1 = dbt1->size;
1161 ssize_t size2 = dbt2->size;
1162 int res = memcmp ((void *)dbt1->data, (void *)dbt2->data,
1163 size1 <= size2 ? size1 : size2);
1164
1165 if (res)
1166 return res;
1167 else if (size1 - size2)
1168 return size1 - size2;
1169 else
1170 return 0;
1171}
1172
1173static size_t
1174bt_pfxc_prefix_x (DB *db, const DBT *dbt1, const DBT *dbt2)
1175{
1176 ssize_t size1 = dbt1->size;
1177 ssize_t size2 = dbt2->size;
1178 u_int8_t *p1 = (u_int8_t *)dbt1->data;
1179 u_int8_t *p2 = (u_int8_t *)dbt2->data;
1180 u_int8_t *pe = p1 + (size1 <= size2 ? size1 : size2);
1181
1182 while (p1 < pe)
1183 if (*p1++ != *p2++)
1184 return p1 - (u_int8_t *)dbt1->data - 1;
1185
1186 if (size1 < size2) return size1 + 1;
1187 if (size1 > size2) return size2 + 1;
1188
1189 return size1;
1190}
1191#endif
1192
1193/*****************************************************************************/
1194
1143/* stupid windoes defined CALLBACK as well */ 1195/* stupid windows defines CALLBACK as well */
1144#undef CALLBACK 1196#undef CALLBACK
1145#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); 1197#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1));
1146 1198
1147MODULE = BDB PACKAGE = BDB 1199MODULE = BDB PACKAGE = BDB
1148 1200
1149PROTOTYPES: ENABLE 1201PROTOTYPES: ENABLE
1150 1202
1151BOOT: 1203BOOT:
1152{ 1204{
1153 HV *stash = gv_stashpv ("BDB", 1);
1154
1155 static const struct { 1205 static const struct {
1156 const char *name; 1206 const char *name;
1157 IV iv; 1207 IV iv;
1158 } *civ, const_iv[] = { 1208 } *civ, const_iv[] = {
1159#define const_iv(name) { # name, (IV)DB_ ## name }, 1209#define const_iv(name) { # name, (IV)DB_ ## name },
1210#if DBVER <= 408
1160 const_iv (RPCCLIENT) 1211 const_iv (RPCCLIENT)
1212#endif
1161 const_iv (INIT_CDB) 1213 const_iv (INIT_CDB)
1162 const_iv (INIT_LOCK) 1214 const_iv (INIT_LOCK)
1163 const_iv (INIT_LOG) 1215 const_iv (INIT_LOG)
1164 const_iv (INIT_MPOOL) 1216 const_iv (INIT_MPOOL)
1165 const_iv (INIT_REP) 1217 const_iv (INIT_REP)
1188 const_iv (TXN_NOT_DURABLE) 1240 const_iv (TXN_NOT_DURABLE)
1189 const_iv (TXN_WRITE_NOSYNC) 1241 const_iv (TXN_WRITE_NOSYNC)
1190 const_iv (WRITECURSOR) 1242 const_iv (WRITECURSOR)
1191 const_iv (YIELDCPU) 1243 const_iv (YIELDCPU)
1192 const_iv (ENCRYPT_AES) 1244 const_iv (ENCRYPT_AES)
1245#if DBVER < 408
1193 const_iv (XA_CREATE) 1246 const_iv (XA_CREATE)
1247#endif
1194 const_iv (BTREE) 1248 const_iv (BTREE)
1195 const_iv (HASH) 1249 const_iv (HASH)
1196 const_iv (QUEUE) 1250 const_iv (QUEUE)
1197 const_iv (RECNO) 1251 const_iv (RECNO)
1198 const_iv (UNKNOWN) 1252 const_iv (UNKNOWN)
1201 const_iv (NOSYNC) 1255 const_iv (NOSYNC)
1202 const_iv (CHKSUM) 1256 const_iv (CHKSUM)
1203 const_iv (ENCRYPT) 1257 const_iv (ENCRYPT)
1204 const_iv (DUP) 1258 const_iv (DUP)
1205 const_iv (DUPSORT) 1259 const_iv (DUPSORT)
1206 const_iv (RECNUM) 1260 //const_iv (RECNUM)
1207 const_iv (RENUMBER) 1261 const_iv (RENUMBER)
1208 const_iv (REVSPLITOFF) 1262 const_iv (REVSPLITOFF)
1209 const_iv (CONSUME) 1263 const_iv (CONSUME)
1210 const_iv (CONSUME_WAIT) 1264 const_iv (CONSUME_WAIT)
1211 const_iv (GET_BOTH) 1265 const_iv (GET_BOTH)
1262 const_iv (LOCK_OLDEST) 1316 const_iv (LOCK_OLDEST)
1263 const_iv (LOCK_RANDOM) 1317 const_iv (LOCK_RANDOM)
1264 const_iv (LOCK_YOUNGEST) 1318 const_iv (LOCK_YOUNGEST)
1265 1319
1266 const_iv (DONOTINDEX) 1320 const_iv (DONOTINDEX)
1267 const_iv (KEYEMPTY ) 1321 const_iv (KEYEMPTY)
1268 const_iv (KEYEXIST ) 1322 const_iv (KEYEXIST)
1269 const_iv (LOCK_DEADLOCK) 1323 const_iv (LOCK_DEADLOCK)
1270 const_iv (LOCK_NOTGRANTED) 1324 const_iv (LOCK_NOTGRANTED)
1271 const_iv (NOSERVER) 1325 const_iv (NOSERVER)
1326#if DBVER < 502
1272 const_iv (NOSERVER_HOME) 1327 const_iv (NOSERVER_HOME)
1273 const_iv (NOSERVER_ID) 1328 const_iv (NOSERVER_ID)
1329#endif
1274 const_iv (NOTFOUND) 1330 const_iv (NOTFOUND)
1275 const_iv (PAGE_NOTFOUND) 1331 const_iv (PAGE_NOTFOUND)
1276 const_iv (REP_DUPMASTER) 1332 const_iv (REP_DUPMASTER)
1277 const_iv (REP_HANDLE_DEAD) 1333 const_iv (REP_HANDLE_DEAD)
1278 const_iv (REP_HOLDELECTION) 1334 const_iv (REP_HOLDELECTION)
1283 const_iv (REP_UNAVAIL) 1339 const_iv (REP_UNAVAIL)
1284 const_iv (RUNRECOVERY) 1340 const_iv (RUNRECOVERY)
1285 const_iv (SECONDARY_BAD) 1341 const_iv (SECONDARY_BAD)
1286 const_iv (VERIFY_BAD) 1342 const_iv (VERIFY_BAD)
1287 1343
1344 const_iv (SALVAGE)
1345 const_iv (AGGRESSIVE)
1346 const_iv (PRINTABLE)
1347 const_iv (NOORDERCHK)
1348 const_iv (ORDERCHKONLY)
1349
1350 const_iv (ARCH_ABS)
1351 const_iv (ARCH_DATA)
1352 const_iv (ARCH_LOG)
1353 const_iv (ARCH_REMOVE)
1354
1288 const_iv (VERB_DEADLOCK) 1355 const_iv (VERB_DEADLOCK)
1289 const_iv (VERB_RECOVERY) 1356 const_iv (VERB_RECOVERY)
1290 const_iv (VERB_REPLICATION) 1357 const_iv (VERB_REPLICATION)
1291 const_iv (VERB_WAITSFOR) 1358 const_iv (VERB_WAITSFOR)
1292 1359
1293 const_iv (VERSION_MAJOR) 1360 const_iv (VERSION_MAJOR)
1294 const_iv (VERSION_MINOR) 1361 const_iv (VERSION_MINOR)
1295 const_iv (VERSION_PATCH) 1362 const_iv (VERSION_PATCH)
1296#if DB_VERSION_MINOR >= 3 1363 const_iv (LOGVERSION)
1364 const_iv (LOGOLDVER)
1365#if DBVER >= 403
1297 const_iv (INORDER) 1366 const_iv (INORDER)
1298 const_iv (LOCK_MAXWRITE) 1367 const_iv (LOCK_MAXWRITE)
1299 const_iv (SEQ_DEC) 1368 const_iv (SEQ_DEC)
1300 const_iv (SEQ_INC) 1369 const_iv (SEQ_INC)
1301 const_iv (SEQ_WRAP) 1370 const_iv (SEQ_WRAP)
1302 const_iv (BUFFER_SMALL) 1371 const_iv (BUFFER_SMALL)
1303 const_iv (LOG_BUFFER_FULL) 1372 const_iv (LOG_BUFFER_FULL)
1304 const_iv (VERSION_MISMATCH) 1373 const_iv (VERSION_MISMATCH)
1305#endif 1374#endif
1306#if DB_VERSION_MINOR >= 4 1375#if DBVER >= 404
1307 const_iv (REGISTER) 1376 const_iv (REGISTER)
1308 const_iv (DSYNC_DB) 1377 const_iv (DSYNC_DB)
1309 const_iv (READ_COMMITTED) 1378 const_iv (READ_COMMITTED)
1310 const_iv (READ_UNCOMMITTED) 1379 const_iv (READ_UNCOMMITTED)
1311 const_iv (REP_IGNORE) 1380 const_iv (REP_IGNORE)
1313 const_iv (REP_JOIN_FAILURE) 1382 const_iv (REP_JOIN_FAILURE)
1314 const_iv (FREE_SPACE) 1383 const_iv (FREE_SPACE)
1315 const_iv (FREELIST_ONLY) 1384 const_iv (FREELIST_ONLY)
1316 const_iv (VERB_REGISTER) 1385 const_iv (VERB_REGISTER)
1317#endif 1386#endif
1318#if DB_VERSION_MINOR >= 5 1387#if DBVER >= 405
1319 const_iv (MULTIVERSION) 1388 const_iv (MULTIVERSION)
1320 const_iv (TXN_SNAPSHOT) 1389 const_iv (TXN_SNAPSHOT)
1321#endif 1390#endif
1322#if DB_VERSION_MINOR >= 6 1391#if DBVER >= 406
1323 const_iv (PREV_DUP) 1392 const_iv (PREV_DUP)
1324 const_iv (PRIORITY_UNCHANGED) 1393 const_iv (PRIORITY_UNCHANGED)
1325 const_iv (PRIORITY_VERY_LOW) 1394 const_iv (PRIORITY_VERY_LOW)
1326 const_iv (PRIORITY_LOW) 1395 const_iv (PRIORITY_LOW)
1327 const_iv (PRIORITY_DEFAULT) 1396 const_iv (PRIORITY_DEFAULT)
1328 const_iv (PRIORITY_HIGH) 1397 const_iv (PRIORITY_HIGH)
1329 const_iv (PRIORITY_VERY_HIGH) 1398 const_iv (PRIORITY_VERY_HIGH)
1399 const_iv (IGNORE_LEASE)
1330#endif 1400#endif
1331#if DB_VERSION_MINOR >= 7 1401#if DBVER >= 407
1402 //const_iv (MULTIPLE_KEY)
1332 const_iv (LOG_DIRECT) 1403 const_iv (LOG_DIRECT)
1333 const_iv (LOG_DSYNC) 1404 const_iv (LOG_DSYNC)
1334 const_iv (LOG_AUTO_REMOVE) 1405 const_iv (LOG_AUTO_REMOVE)
1335 const_iv (LOG_IN_MEMORY) 1406 const_iv (LOG_IN_MEMORY)
1336 const_iv (LOG_ZERO) 1407 const_iv (LOG_ZERO)
1337#else 1408#else
1338 const_iv (DIRECT_LOG) 1409 const_iv (DIRECT_LOG)
1339 const_iv (LOG_AUTOREMOVE) 1410 const_iv (LOG_AUTOREMOVE)
1340# if DB_VERSION_MINOR >= 3 1411# if DBVER >= 403
1341 const_iv (DSYNC_LOG) 1412 const_iv (DSYNC_LOG)
1342 const_iv (LOG_INMEMORY) 1413 const_iv (LOG_INMEMORY)
1343# endif 1414# endif
1415#if DBVER >= 408
1416 const_iv (LOGVERSION_LATCHING)
1417#endif
1344#endif 1418#endif
1345 }; 1419 };
1346 1420
1421 bdb_stash = gv_stashpv ("BDB" , 1);
1422 bdb_env_stash = gv_stashpv ("BDB::Env" , 1);
1423 bdb_txn_stash = gv_stashpv ("BDB::Txn" , 1);
1424 bdb_cursor_stash = gv_stashpv ("BDB::Cursor" , 1);
1425 bdb_db_stash = gv_stashpv ("BDB::Db" , 1);
1426 bdb_sequence_stash = gv_stashpv ("BDB::Sequence", 1);
1427
1347 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1428 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
1348 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1429 newCONSTSUB (bdb_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
1349 1430
1350 prepare_cb = &PL_sv_undef; 1431 prepare_cb = &PL_sv_undef;
1351 1432
1352 { 1433 {
1353 /* we currently only allow version, minor-version and patchlevel to go up to 255 */ 1434 /* we currently only allow version, minor-version and patchlevel to go up to 255 */
1354 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; 1435 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH };
1355 1436
1356 newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); 1437 newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3));
1357 } 1438 }
1358 1439
1359 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1440 newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1360 1441
1361 create_respipe (); 1442 create_respipe ();
1362 1443
1363 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1444 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1364 patch_errno (); 1445 patch_errno ();
1442 1523
1443int 1524int
1444poll_fileno () 1525poll_fileno ()
1445 PROTOTYPE: 1526 PROTOTYPE:
1446 CODE: 1527 CODE:
1447 RETVAL = respipe [0]; 1528 RETVAL = s_epipe_fd (&respipe);
1448 OUTPUT: 1529 OUTPUT:
1449 RETVAL 1530 RETVAL
1450 1531
1451int 1532int
1452poll_cb (...) 1533poll_cb (...)
1553db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) 1634db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0)
1554 PREINIT: 1635 PREINIT:
1555 CALLBACK 1636 CALLBACK
1556 CODE: 1637 CODE:
1557{ 1638{
1639 dREQ (REQ_ENV_CLOSE, 0);
1558 ptr_nuke (ST (0)); 1640 ptr_nuke (ST (0));
1559 dREQ (REQ_ENV_CLOSE, 0);
1560 req->env = env; 1641 req->env = env;
1561 req->uint1 = flags; 1642 req->uint1 = flags;
1562 REQ_SEND; 1643 REQ_SEND;
1563} 1644}
1564 1645
1636 dREQ (REQ_ENV_DBRENAME, 2); 1717 dREQ (REQ_ENV_DBRENAME, 2);
1637 req->env = env; 1718 req->env = env;
1638 req->buf1 = strdup_ornull (file); 1719 req->buf1 = strdup_ornull (file);
1639 req->buf2 = strdup_ornull (database); 1720 req->buf2 = strdup_ornull (database);
1640 req->buf3 = strdup_ornull (newname); 1721 req->buf3 = strdup_ornull (newname);
1722 req->uint1 = flags;
1723 REQ_SEND;
1724}
1725
1726void
1727db_env_lsn_reset (DB_ENV *env, bdb_filename db, U32 flags = 0, SV *callback = 0)
1728 ALIAS:
1729 db_env_fileid_reset = 1
1730 PREINIT:
1731 CALLBACK
1732 CODE:
1733{
1734 dREQ (ix ? REQ_ENV_FILEID_RESET : REQ_ENV_LSN_RESET, 1);
1735 req->env = env;
1736 req->uint1 = flags;
1737 req->buf1 = strdup_ornull (db);
1738 REQ_SEND;
1739}
1740
1741void
1742db_env_log_archive (DB_ENV *env, SV_mutable *listp, U32 flags = 0, SV *callback = 0)
1743 PREINIT:
1744 CALLBACK
1745 CODE:
1746{
1747 dREQ (REQ_ENV_LOG_ARCHIVE, 1);
1748 req->sv1 = SvREFCNT_inc (listp);
1749 req->env = env;
1641 req->uint1 = flags; 1750 req->uint1 = flags;
1642 REQ_SEND; 1751 REQ_SEND;
1643} 1752}
1644 1753
1645DB * 1754DB *
1677db_close (DB *db, U32 flags = 0, SV *callback = 0) 1786db_close (DB *db, U32 flags = 0, SV *callback = 0)
1678 PREINIT: 1787 PREINIT:
1679 CALLBACK 1788 CALLBACK
1680 CODE: 1789 CODE:
1681{ 1790{
1791 dREQ (REQ_DB_CLOSE, 0);
1682 ptr_nuke (ST (0)); 1792 ptr_nuke (ST (0));
1683 dREQ (REQ_DB_CLOSE, 0);
1684 req->db = db; 1793 req->db = db;
1685 req->uint1 = flags; 1794 req->uint1 = flags;
1686 req->sv1 = (SV *)db->app_private; 1795 req->sv1 = (SV *)db->app_private;
1687 REQ_SEND; 1796 REQ_SEND;
1688} 1797}
1689 1798
1690#if DB_VERSION_MINOR >= 4 1799#if DBVER >= 404
1691 1800
1692void 1801void
1693db_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) 1802db_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)
1694 PREINIT: 1803 PREINIT:
1695 CALLBACK 1804 CALLBACK
1696 CODE: 1805 CODE:
1697{ 1806{
1698 dREQ (REQ_DB_COMPACT, 2); 1807 dREQ (REQ_DB_COMPACT, 2);
1699 req->db = db; 1808 req->db = db;
1700 req->txn = txn; 1809 req->txn = txn;
1701 sv_to_dbt (&req->dbt1, start); 1810 if (start) sv_to_dbt (&req->dbt1, start);
1702 sv_to_dbt (&req->dbt2, stop); 1811 if (stop ) sv_to_dbt (&req->dbt2, stop );
1703 req->uint1 = flags; 1812 req->uint1 = flags;
1704 REQ_SEND; 1813 REQ_SEND;
1705} 1814}
1706 1815
1707#endif 1816#endif
1717 req->uint1 = flags; 1826 req->uint1 = flags;
1718 REQ_SEND; 1827 REQ_SEND;
1719} 1828}
1720 1829
1721void 1830void
1831db_verify (DB *db, bdb_filename file, bdb_filename database = 0, SV *dummy = 0, U32 flags = 0, SV *callback = 0)
1832 PREINIT:
1833 CALLBACK
1834 CODE:
1835{
1836 dREQ (REQ_DB_VERIFY, 1);
1837 ptr_nuke (ST (0)); /* verify destroys the database handle, hopefully it is freed as well */
1838 req->db = db;
1839 req->buf1 = strdup (file);
1840 req->buf2 = strdup_ornull (database);
1841 req->uint1 = flags;
1842 REQ_SEND;
1843}
1844
1845void
1722db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) 1846db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0)
1723 PREINIT: 1847 PREINIT:
1724 CALLBACK 1848 CALLBACK
1725 CODE: 1849 CODE:
1726{ 1850{
1727 dREQ (REQ_DB_SYNC, 1); 1851 dREQ (REQ_DB_UPGRADE, 1);
1728 req->db = db; 1852 req->db = db;
1729 req->buf1 = strdup (file); 1853 req->buf1 = strdup (file);
1730 req->uint1 = flags; 1854 req->uint1 = flags;
1731 REQ_SEND; 1855 REQ_SEND;
1732} 1856}
1759 sv_to_dbt (&req->dbt2, data); 1883 sv_to_dbt (&req->dbt2, data);
1760 req->uint1 = flags; 1884 req->uint1 = flags;
1761 REQ_SEND; 1885 REQ_SEND;
1762} 1886}
1763 1887
1764#if DB_VERSION_MINOR >= 6 1888#if DBVER >= 406
1765 1889
1766void 1890void
1767db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) 1891db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0)
1768 PREINIT: 1892 PREINIT:
1769 CALLBACK 1893 CALLBACK
1836db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) 1960db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1837 PREINIT: 1961 PREINIT:
1838 CALLBACK 1962 CALLBACK
1839 CODE: 1963 CODE:
1840{ 1964{
1965 dREQ (REQ_TXN_COMMIT, 0);
1841 ptr_nuke (ST (0)); 1966 ptr_nuke (ST (0));
1842 dREQ (REQ_TXN_COMMIT, 0);
1843 req->txn = txn; 1967 req->txn = txn;
1844 req->uint1 = flags; 1968 req->uint1 = flags;
1845 REQ_SEND; 1969 REQ_SEND;
1846} 1970}
1847 1971
1849db_txn_abort (DB_TXN *txn, SV *callback = 0) 1973db_txn_abort (DB_TXN *txn, SV *callback = 0)
1850 PREINIT: 1974 PREINIT:
1851 CALLBACK 1975 CALLBACK
1852 CODE: 1976 CODE:
1853{ 1977{
1978 dREQ (REQ_TXN_ABORT, 0);
1854 ptr_nuke (ST (0)); 1979 ptr_nuke (ST (0));
1855 dREQ (REQ_TXN_ABORT, 0);
1856 req->txn = txn; 1980 req->txn = txn;
1857 REQ_SEND; 1981 REQ_SEND;
1858} 1982}
1859 1983
1860void 1984void
1861db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0) 1985db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1862 PREINIT: 1986 PREINIT:
1863 CALLBACK 1987 CALLBACK
1864 CODE: 1988 CODE:
1865{ 1989{
1990 dREQ (REQ_TXN_FINISH, 0);
1866 ptr_nuke (ST (0)); 1991 ptr_nuke (ST (0));
1867 dREQ (REQ_TXN_FINISH, 0);
1868 req->txn = txn; 1992 req->txn = txn;
1869 req->uint1 = flags; 1993 req->uint1 = flags;
1870 REQ_SEND; 1994 REQ_SEND;
1871} 1995}
1872 1996
1874db_c_close (DBC *dbc, SV *callback = 0) 1998db_c_close (DBC *dbc, SV *callback = 0)
1875 PREINIT: 1999 PREINIT:
1876 CALLBACK 2000 CALLBACK
1877 CODE: 2001 CODE:
1878{ 2002{
2003 dREQ (REQ_C_CLOSE, 0);
1879 ptr_nuke (ST (0)); 2004 ptr_nuke (ST (0));
1880 dREQ (REQ_C_CLOSE, 0);
1881 req->dbc = dbc; 2005 req->dbc = dbc;
1882 REQ_SEND; 2006 REQ_SEND;
1883} 2007}
1884 2008
1885void 2009void
1912db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0) 2036db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1913 PREINIT: 2037 PREINIT:
1914 CALLBACK 2038 CALLBACK
1915 CODE: 2039 CODE:
1916{ 2040{
1917 if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) 2041 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
1918 croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET"); 2042 croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET");
2043 if (SvPOKp (key) && !sv_utf8_downgrade (key, 1))
2044 croak ("argument \"%s\" must be byte/octet-encoded in %s",
2045 "key",
2046 "BDB::db_c_get");
1919 2047
2048 {
1920 dREQ (REQ_C_GET, 1); 2049 dREQ (REQ_C_GET, 1);
1921 req->dbc = dbc; 2050 req->dbc = dbc;
1922 req->uint1 = flags; 2051 req->uint1 = flags;
1923 if (flags & DB_OPFLAGS_MASK == DB_SET) 2052 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1924 sv_to_dbt (&req->dbt1, key); 2053 sv_to_dbt (&req->dbt1, key);
1925 else 2054 else
1926 { 2055 {
1927 if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) 2056 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
1928 sv_to_dbt (&req->dbt1, key); 2057 sv_to_dbt (&req->dbt1, key);
1929 else 2058 else
1930 req->dbt1.flags = DB_DBT_MALLOC; 2059 req->dbt1.flags = DB_DBT_MALLOC;
1931 2060
1932 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); 2061 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1933 } 2062 }
1934 2063
1935 if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH 2064 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1936 || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) 2065 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1937 sv_to_dbt (&req->dbt3, data); 2066 sv_to_dbt (&req->dbt3, data);
1938 else 2067 else
1939 req->dbt3.flags = DB_DBT_MALLOC; 2068 req->dbt3.flags = DB_DBT_MALLOC;
1940 2069
1941 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2070 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1942 REQ_SEND; 2071 REQ_SEND;
2072 }
1943} 2073}
1944 2074
1945void 2075void
1946db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0) 2076db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1947 PREINIT: 2077 PREINIT:
1948 CALLBACK 2078 CALLBACK
1949 CODE: 2079 CODE:
1950{ 2080{
1951 if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) 2081 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
1952 croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET"); 2082 croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET");
2083 if (SvPOKp (key) && !sv_utf8_downgrade (key, 1))
2084 croak ("argument \"%s\" must be byte/octet-encoded in %s",
2085 "key",
2086 "BDB::db_c_pget");
1953 2087
2088 {
1954 dREQ (REQ_C_PGET, 1); 2089 dREQ (REQ_C_PGET, 1);
1955 req->dbc = dbc; 2090 req->dbc = dbc;
1956 req->uint1 = flags; 2091 req->uint1 = flags;
1957 if (flags & DB_OPFLAGS_MASK == DB_SET) 2092 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1958 sv_to_dbt (&req->dbt1, key); 2093 sv_to_dbt (&req->dbt1, key);
1959 else 2094 else
1960 { 2095 {
1961 if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) 2096 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
1962 sv_to_dbt (&req->dbt1, key); 2097 sv_to_dbt (&req->dbt1, key);
1963 else 2098 else
1964 req->dbt1.flags = DB_DBT_MALLOC; 2099 req->dbt1.flags = DB_DBT_MALLOC;
1965 2100
1966 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); 2101 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1967 } 2102 }
1968 2103
1969 req->dbt2.flags = DB_DBT_MALLOC; 2104 req->dbt2.flags = DB_DBT_MALLOC;
1970 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); 2105 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1971 2106
1972 if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH 2107 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1973 || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) 2108 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1974 sv_to_dbt (&req->dbt3, data); 2109 sv_to_dbt (&req->dbt3, data);
1975 else 2110 else
1976 req->dbt3.flags = DB_DBT_MALLOC; 2111 req->dbt3.flags = DB_DBT_MALLOC;
1977 2112
1978 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2113 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1979 REQ_SEND; 2114 REQ_SEND;
2115 }
1980} 2116}
1981 2117
1982void 2118void
1983db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) 2119db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0)
1984 PREINIT: 2120 PREINIT:
1990 req->uint1 = flags; 2126 req->uint1 = flags;
1991 REQ_SEND; 2127 REQ_SEND;
1992} 2128}
1993 2129
1994 2130
1995#if DB_VERSION_MINOR >= 3 2131#if DBVER >= 403
1996 2132
1997void 2133void
1998db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) 2134db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0)
1999 PREINIT: 2135 PREINIT:
2000 CALLBACK 2136 CALLBACK
2012db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) 2148db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0)
2013 PREINIT: 2149 PREINIT:
2014 CALLBACK 2150 CALLBACK
2015 CODE: 2151 CODE:
2016{ 2152{
2153 dREQ (REQ_SEQ_CLOSE, 0);
2017 ptr_nuke (ST (0)); 2154 ptr_nuke (ST (0));
2018 dREQ (REQ_SEQ_CLOSE, 0);
2019 req->seq = seq; 2155 req->seq = seq;
2020 req->uint1 = flags; 2156 req->uint1 = flags;
2021 REQ_SEND; 2157 REQ_SEND;
2022} 2158}
2023 2159
2094 CODE: 2230 CODE:
2095 RETVAL = env->set_flags (env, flags, onoff); 2231 RETVAL = env->set_flags (env, flags, onoff);
2096 OUTPUT: 2232 OUTPUT:
2097 RETVAL 2233 RETVAL
2098 2234
2099#if DB_VERSION_MINOR >= 7 2235#if DBVER >= 407
2100 2236
2101int set_intermediate_dir_mode (DB_ENV *env, const char *mode) 2237int set_intermediate_dir_mode (DB_ENV *env, const char *mode)
2102 CODE: 2238 CODE:
2103 RETVAL = env->set_intermediate_dir_mode (env, mode); 2239 RETVAL = env->set_intermediate_dir_mode (env, mode);
2104 OUTPUT: 2240 OUTPUT:
2191 CODE: 2327 CODE:
2192 RETVAL = env->set_lg_max (env, max); 2328 RETVAL = env->set_lg_max (env, max);
2193 OUTPUT: 2329 OUTPUT:
2194 RETVAL 2330 RETVAL
2195 2331
2196#if DB_VERSION_MINOR >= 4 2332#if DBVER >= 404
2197 2333
2198int mutex_set_max (DB_ENV *env, U32 max) 2334int mutex_set_max (DB_ENV *env, U32 max)
2199 CODE: 2335 CODE:
2200 RETVAL = env->mutex_set_max (env, max); 2336 RETVAL = env->mutex_set_max (env, max);
2201 OUTPUT: 2337 OUTPUT:
2228 if (errno) 2364 if (errno)
2229 croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); 2365 croak ("DB_ENV->txn_begin: %s", db_strerror (errno));
2230 OUTPUT: 2366 OUTPUT:
2231 RETVAL 2367 RETVAL
2232 2368
2233#if DB_VERSION_MINOR >= 5 2369#if DBVER >= 405
2234 2370
2235DB_TXN * 2371DB_TXN *
2236cdsgroup_begin (DB_ENV *env) 2372cdsgroup_begin (DB_ENV *env)
2237 CODE: 2373 CODE:
2238 errno = env->cdsgroup_begin (env, &RETVAL); 2374 errno = env->cdsgroup_begin (env, &RETVAL);
2259 CODE: 2395 CODE:
2260 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); 2396 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache);
2261 OUTPUT: 2397 OUTPUT:
2262 RETVAL 2398 RETVAL
2263 2399
2400int set_pagesize (DB *db, U32 pagesize)
2401 CODE:
2402 RETVAL = db->set_pagesize (db, pagesize);
2403 OUTPUT:
2404 RETVAL
2405
2264int set_flags (DB *db, U32 flags) 2406int set_flags (DB *db, U32 flags)
2265 CODE: 2407 CODE:
2266 RETVAL = db->set_flags (db, flags); 2408 RETVAL = db->set_flags (db, flags);
2267 OUTPUT: 2409 OUTPUT:
2268 RETVAL 2410 RETVAL
2334 if (errno) 2476 if (errno)
2335 croak ("DB->cursor: %s", db_strerror (errno)); 2477 croak ("DB->cursor: %s", db_strerror (errno));
2336 OUTPUT: 2478 OUTPUT:
2337 RETVAL 2479 RETVAL
2338 2480
2339#if DB_VERSION_MINOR >= 3 2481#if DBVER >= 403
2340 2482
2341DB_SEQUENCE * 2483DB_SEQUENCE *
2342sequence (DB *db, U32 flags = 0) 2484sequence (DB *db, U32 flags = 0)
2343 CODE: 2485 CODE:
2344{ 2486{
2379DESTROY (DBC_ornuked *dbc) 2521DESTROY (DBC_ornuked *dbc)
2380 CODE: 2522 CODE:
2381 if (dbc) 2523 if (dbc)
2382 dbc->c_close (dbc); 2524 dbc->c_close (dbc);
2383 2525
2384#if DB_VERSION_MINOR >= 6 2526#if DBVER >= 406
2385 2527
2386int set_priority (DBC *dbc, int priority) 2528int set_priority (DBC *dbc, int priority)
2387 CODE: 2529 CODE:
2388 dbc->set_priority (dbc, priority); 2530 dbc->set_priority (dbc, priority);
2389 2531
2390#endif 2532#endif
2391 2533
2392#if DB_VERSION_MINOR >= 3 2534#if DBVER >= 403
2393 2535
2394MODULE = BDB PACKAGE = BDB::Sequence 2536MODULE = BDB PACKAGE = BDB::Sequence
2395 2537
2396void 2538void
2397DESTROY (DB_SEQUENCE_ornuked *seq) 2539DESTROY (DB_SEQUENCE_ornuked *seq)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines