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

Comparing BDB/BDB.xs (file contents):
Revision 1.54 by root, Fri Sep 26 02:03:48 2008 UTC vs.
Revision 1.76 by root, Fri Jul 29 09:30:20 2011 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
137dbt_to_sv (SV *sv, DBT *dbt) 145dbt_to_sv (SV *sv, DBT *dbt)
138{ 146{
139 if (sv) 147 if (sv)
140 { 148 {
141 SvREADONLY_off (sv); 149 SvREADONLY_off (sv);
142 sv_setsv_mg (sv, dbt->data ? newSVpvn (dbt->data, dbt->size) : &PL_sv_undef); 150
151 if (dbt->data)
152 sv_setpvn_mg (sv, dbt->data, dbt->size);
153 else
154 sv_setsv_mg (sv, &PL_sv_undef);
155
143 SvREFCNT_dec (sv); 156 SvREFCNT_dec (sv);
144 } 157 }
145 158
146 if (dbt->flags & DB_DBT_MALLOC)
147 free (dbt->data); 159 free (dbt->data);
148} 160}
149 161
150enum { 162enum {
151 REQ_QUIT, 163 REQ_QUIT,
152 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,
153 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,
154 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,
155 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,
156 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, 169 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH,
157 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,
158 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,
159}; 172};
175 char *buf1, *buf2, *buf3; 188 char *buf1, *buf2, *buf3;
176 SV *sv1, *sv2, *sv3; 189 SV *sv1, *sv2, *sv3;
177 190
178 DBT dbt1, dbt2, dbt3; 191 DBT dbt1, dbt2, dbt3;
179 DB_KEY_RANGE key_range; 192 DB_KEY_RANGE key_range;
180#if DB_VERSION_MINOR >= 3 193#if DBVER >= 403
181 DB_SEQUENCE *seq; 194 DB_SEQUENCE *seq;
182 db_seq_t seq_t; 195 db_seq_t seq_t;
183#endif 196#endif
184 197
185 SV *rsv1, *rsv2; // keep some request objects alive 198 SV *rsv1, *rsv2; // keep some request objects alive
213static int next_pri = DEFAULT_PRI + PRI_BIAS; 226static int next_pri = DEFAULT_PRI + PRI_BIAS;
214 227
215static unsigned int started, idle, wanted; 228static unsigned int started, idle, wanted;
216 229
217/* worker threads management */ 230/* worker threads management */
218static mutex_t wrklock = X_MUTEX_INIT; 231static xmutex_t wrklock = X_MUTEX_INIT;
219 232
220typedef struct worker { 233typedef struct worker {
221 /* locked by wrklock */ 234 /* locked by wrklock */
222 struct worker *prev, *next; 235 struct worker *prev, *next;
223 236
224 thread_t tid; 237 xthread_t tid;
225 238
226 /* locked by reslock, reqlock or wrklock */ 239 /* locked by reslock, reqlock or wrklock */
227 bdb_req req; /* currently processed request */ 240 bdb_req req; /* currently processed request */
228 void *dbuf; 241 void *dbuf;
229 DIR *dirp; 242 DIR *dirp;
244} 257}
245 258
246static volatile unsigned int nreqs, nready, npending; 259static volatile unsigned int nreqs, nready, npending;
247static volatile unsigned int max_idle = 4; 260static volatile unsigned int max_idle = 4;
248static volatile unsigned int max_outstanding = 0xffffffff; 261static volatile unsigned int max_outstanding = 0xffffffff;
249static int respipe_osf [2], respipe [2] = { -1, -1 }; 262static s_epipe respipe;
250 263
251static mutex_t reslock = X_MUTEX_INIT; 264static xmutex_t reslock = X_MUTEX_INIT;
252static mutex_t reqlock = X_MUTEX_INIT; 265static xmutex_t reqlock = X_MUTEX_INIT;
253static cond_t reqwait = X_COND_INIT; 266static xcond_t reqwait = X_COND_INIT;
254 267
255#if WORDACCESS_UNSAFE 268#if WORDACCESS_UNSAFE
256 269
257static unsigned int get_nready (void) 270static unsigned int get_nready (void)
258{ 271{
349 abort (); 362 abort ();
350} 363}
351 364
352static int poll_cb (void); 365static int poll_cb (void);
353static void req_free (bdb_req req); 366static void req_free (bdb_req req);
354static void req_cancel (bdb_req req);
355 367
356static int req_invoke (bdb_req req) 368static int req_invoke (bdb_req req)
357{ 369{
358 switch (req->type) 370 switch (req->type)
359 { 371 {
378 390
379 av_push (av, newSVnv (req->key_range.less)); 391 av_push (av, newSVnv (req->key_range.less));
380 av_push (av, newSVnv (req->key_range.equal)); 392 av_push (av, newSVnv (req->key_range.equal));
381 av_push (av, newSVnv (req->key_range.greater)); 393 av_push (av, newSVnv (req->key_range.greater));
382 394
395 av = (AV *)newRV_noinc ((SV *)av);
396
383 SvREADONLY_off (req->sv1); 397 SvREADONLY_off (req->sv1);
384 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); 398 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av));
399 SvREFCNT_dec (av);
385 SvREFCNT_dec (req->sv1); 400 SvREFCNT_dec (req->sv1);
386 } 401 }
387 break; 402 break;
388 403
389#if DB_VERSION_MINOR >= 3 404#if DBVER >= 403
390 case REQ_SEQ_GET: 405 case REQ_SEQ_GET:
391 SvREADONLY_off (req->sv1); 406 SvREADONLY_off (req->sv1);
392 407
393 if (sizeof (IV) > 4) 408 if (sizeof (IV) > 4)
394 sv_setiv_mg (req->sv1, (IV)req->seq_t); 409 sv_setiv_mg (req->sv1, (IV)req->seq_t);
396 sv_setnv_mg (req->sv1, (NV)req->seq_t); 411 sv_setnv_mg (req->sv1, (NV)req->seq_t);
397 412
398 SvREFCNT_dec (req->sv1); 413 SvREFCNT_dec (req->sv1);
399 break; 414 break;
400#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;
401 } 434 }
402 435
403 errno = req->result; 436 errno = req->result;
404 437
405 if (req->callback) 438 if (req->callback)
435 free (req->buf3); 468 free (req->buf3);
436 469
437 Safefree (req); 470 Safefree (req);
438} 471}
439 472
440#ifdef USE_SOCKETS_AS_HANDLES
441# define TO_SOCKET(x) (win32_get_osfhandle (x))
442#else
443# define TO_SOCKET(x) (x)
444#endif
445
446static void 473static void
447create_respipe (void) 474create_respipe (void)
448{ 475{
449#ifdef _WIN32
450 int arg; /* argg */
451#endif
452 int old_readfd = respipe [0];
453
454 if (respipe [1] >= 0)
455 respipe_close (TO_SOCKET (respipe [1]));
456
457#ifdef _WIN32
458 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe))
459#else
460 if (pipe (respipe)) 476 if (s_epipe_renew (&respipe))
461#endif 477 croak ("BDB: unable to create event pipe");
462 croak ("unable to initialize result pipe");
463
464 if (old_readfd >= 0)
465 {
466 if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0)
467 croak ("unable to initialize result pipe(2)");
468
469 respipe_close (respipe [0]);
470 respipe [0] = old_readfd;
471 }
472
473#ifdef _WIN32
474 arg = 1;
475 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg)
476 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg))
477#else
478 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
479 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
480#endif
481 croak ("unable to initialize result pipe(3)");
482
483 respipe_osf [0] = TO_SOCKET (respipe [0]);
484 respipe_osf [1] = TO_SOCKET (respipe [1]);
485} 478}
486 479
487static void bdb_request (bdb_req req); 480static void bdb_request (bdb_req req);
488X_THREAD_PROC (bdb_proc); 481X_THREAD_PROC (bdb_proc);
489 482
625 end_thread (); 618 end_thread ();
626} 619}
627 620
628static void poll_wait (void) 621static void poll_wait (void)
629{ 622{
630 fd_set rfd;
631
632 while (nreqs) 623 while (nreqs)
633 { 624 {
634 int size; 625 int size;
635 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 626 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
636 size = res_queue.size; 627 size = res_queue.size;
639 if (size) 630 if (size)
640 return; 631 return;
641 632
642 maybe_start_thread (); 633 maybe_start_thread ();
643 634
644 FD_ZERO (&rfd); 635 s_epipe_wait (&respipe);
645 FD_SET (respipe [0], &rfd);
646
647 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
648 } 636 }
649} 637}
650 638
651static int poll_cb (void) 639static int poll_cb (void)
652{ 640{
672 if (req) 660 if (req)
673 { 661 {
674 --npending; 662 --npending;
675 663
676 if (!res_queue.size) 664 if (!res_queue.size)
677 {
678 /* read any signals sent by the worker threads */ 665 /* read any signals sent by the worker threads */
679 char buf [4]; 666 s_epipe_drain (&respipe);
680 while (respipe_read (respipe [0], buf, 4) == 4)
681 ;
682 }
683 } 667 }
684 668
685 X_UNLOCK (reslock); 669 X_UNLOCK (reslock);
686 670
687 if (!req) 671 if (!req)
767 751
768 case REQ_DB_CLOSE: 752 case REQ_DB_CLOSE:
769 req->result = req->db->close (req->db, req->uint1); 753 req->result = req->db->close (req->db, req->uint1);
770 break; 754 break;
771 755
772#if DB_VERSION_MINOR >= 4 756#if DBVER >= 404
773 case REQ_DB_COMPACT: 757 case REQ_DB_COMPACT:
774 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);
775 break; 759 break;
776#endif 760#endif
777 761
778 case REQ_DB_SYNC: 762 case REQ_DB_SYNC:
779 req->result = req->db->sync (req->db, req->uint1); 763 req->result = req->db->sync (req->db, req->uint1);
780 break; 764 break;
781 765
766 case REQ_DB_VERIFY:
767 req->result = req->db->verify (req->db, req->buf1, req->buf2, 0, req->uint1);
768 break;
769
782 case REQ_DB_UPGRADE: 770 case REQ_DB_UPGRADE:
783 req->result = req->db->upgrade (req->db, req->buf1, req->uint1); 771 req->result = req->db->upgrade (req->db, req->buf1, req->uint1);
784 break; 772 break;
785 773
786 case REQ_DB_PUT: 774 case REQ_DB_PUT:
787 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);
788 break; 776 break;
789 777
790#if DB_VERSION_MINOR >= 6 778#if DBVER >= 406
791 case REQ_DB_EXISTS: 779 case REQ_DB_EXISTS:
792 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);
793 break; 781 break;
794#endif 782#endif
795 case REQ_DB_GET: 783 case REQ_DB_GET:
853 841
854 case REQ_C_DEL: 842 case REQ_C_DEL:
855 req->result = req->dbc->c_del (req->dbc, req->uint1); 843 req->result = req->dbc->c_del (req->dbc, req->uint1);
856 break; 844 break;
857 845
858#if DB_VERSION_MINOR >= 3 846#if DBVER >= 403
859 case REQ_SEQ_OPEN: 847 case REQ_SEQ_OPEN:
860 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);
861 break; 849 break;
862 850
863 case REQ_SEQ_CLOSE: 851 case REQ_SEQ_CLOSE:
870 858
871 case REQ_SEQ_REMOVE: 859 case REQ_SEQ_REMOVE:
872 req->result = req->seq->remove (req->seq, req->txn, req->uint1); 860 req->result = req->seq->remove (req->seq, req->txn, req->uint1);
873 break; 861 break;
874#endif 862#endif
863
864 case REQ_ENV_LOG_ARCHIVE:
865 {
866 char **listp = 0; /* DB_ARCH_REMOVE does not touch listp, contrary to docs */
867 req->result = req->env->log_archive (req->env, &listp, req->uint1);
868 req->buf1 = (char *)listp;
869 }
870 break;
875 871
876 default: 872 default:
877 req->result = ENOSYS; 873 req->result = ENOSYS;
878 break; 874 break;
879 } 875 }
891 /* try to distribute timeouts somewhat evenly */ 887 /* try to distribute timeouts somewhat evenly */
892 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 888 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
893 889
894 for (;;) 890 for (;;)
895 { 891 {
896 ts.tv_sec = time (0) + IDLE_TIMEOUT; 892 ts.tv_sec = time (0) + IDLE_TIMEOUT;
897 893
898 X_LOCK (reqlock); 894 X_LOCK (reqlock);
899 895
900 for (;;) 896 for (;;)
901 { 897 {
946 X_LOCK (reslock); 942 X_LOCK (reslock);
947 943
948 ++npending; 944 ++npending;
949 945
950 if (!reqq_push (&res_queue, req)) 946 if (!reqq_push (&res_queue, req))
951 /* write a dummy byte to the pipe so fh becomes ready */ 947 s_epipe_signal (&respipe);
952 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
953 948
954 self->req = 0; 949 self->req = 0;
955 worker_clear (self); 950 worker_clear (self);
956 951
957 X_UNLOCK (reslock); 952 X_UNLOCK (reslock);
1033 (void)0; 1028 (void)0;
1034 1029
1035#define REQ_SEND \ 1030#define REQ_SEND \
1036 req_send (req) 1031 req_send (req)
1037 1032
1038#define SvPTR(var, arg, type, class, nullok) \ 1033#define SvPTR(var, arg, type, stash, class, nullok) \
1039 if (!SvOK (arg)) \ 1034 if (!SvOK (arg)) \
1040 { \ 1035 { \
1041 if (nullok != 1) \ 1036 if (nullok != 1) \
1042 croak (# var " must be a " # class " object, not undef"); \ 1037 croak (# var " must be a " # class " object, not undef"); \
1043 \ 1038 \
1044 (var) = 0; \ 1039 (var) = 0; \
1045 } \ 1040 } \
1046 else if (sv_derived_from ((arg), # class)) \ 1041 else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \
1047 { \ 1042 { \
1048 IV tmp = SvIV ((SV*) SvRV (arg)); \ 1043 IV tmp = SvIV ((SV*) SvRV (arg)); \
1049 (var) = INT2PTR (type, tmp); \ 1044 (var) = INT2PTR (type, tmp); \
1050 if (!var && nullok != 2) \ 1045 if (!var && nullok != 2) \
1051 croak (# var " is not a valid " # class " object anymore"); \ 1046 croak (# var " is not a valid " # class " object anymore"); \
1054 croak (# var " is not of type " # class); 1049 croak (# var " is not of type " # class);
1055 1050
1056#define ARG_MUTABLE(name) \ 1051#define ARG_MUTABLE(name) \
1057 if (SvREADONLY (name)) \ 1052 if (SvREADONLY (name)) \
1058 croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); 1053 croak ("argument " #name " is read-only/constant, but the request requires it to be mutable");
1054
1055static SV *
1056newSVptr (void *ptr, HV *stash)
1057{
1058 SV *rv = NEWSV (0, 0);
1059 sv_upgrade (rv, SVt_PVMG);
1060 sv_setiv (rv, PTR2IV (ptr));
1061
1062 return sv_bless (newRV_noinc (rv), stash);
1063}
1059 1064
1060static void 1065static void
1061ptr_nuke (SV *sv) 1066ptr_nuke (SV *sv)
1062{ 1067{
1063 assert (SvROK (sv)); 1068 assert (SvROK (sv));
1134 } 1139 }
1135 1140
1136 return 0; 1141 return 0;
1137} 1142}
1138 1143
1144/*****************************************************************************/
1145
1146#if 0
1147static int
1148bt_pfxc_compare (DB *db, const DBT *dbt1, const DBT *dbt2)
1149{
1150 ssize_t size1 = dbt1->size;
1151 ssize_t size2 = dbt2->size;
1152 int res = memcmp ((void *)dbt1->data, (void *)dbt2->data,
1153 size1 <= size2 ? size1 : size2);
1154
1155 if (res)
1156 return res;
1157 else if (size1 - size2)
1158 return size1 - size2;
1159 else
1160 return 0;
1161}
1162
1163static size_t
1164bt_pfxc_prefix_x (DB *db, const DBT *dbt1, const DBT *dbt2)
1165{
1166 ssize_t size1 = dbt1->size;
1167 ssize_t size2 = dbt2->size;
1168 u_int8_t *p1 = (u_int8_t *)dbt1->data;
1169 u_int8_t *p2 = (u_int8_t *)dbt2->data;
1170 u_int8_t *pe = p1 + (size1 <= size2 ? size1 : size2);
1171
1172 while (p1 < pe)
1173 if (*p1++ != *p2++)
1174 return p1 - (u_int8_t *)dbt1->data - 1;
1175
1176 if (size1 < size2) return size1 + 1;
1177 if (size1 > size2) return size2 + 1;
1178
1179 return size1;
1180}
1181#endif
1182
1183/*****************************************************************************/
1184
1139/* stupid windoes defined CALLBACK as well */ 1185/* stupid windows defines CALLBACK as well */
1140#undef CALLBACK 1186#undef CALLBACK
1141#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); 1187#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1));
1142 1188
1143MODULE = BDB PACKAGE = BDB 1189MODULE = BDB PACKAGE = BDB
1144 1190
1145PROTOTYPES: ENABLE 1191PROTOTYPES: ENABLE
1146 1192
1147BOOT: 1193BOOT:
1148{ 1194{
1149 HV *stash = gv_stashpv ("BDB", 1);
1150
1151 static const struct { 1195 static const struct {
1152 const char *name; 1196 const char *name;
1153 IV iv; 1197 IV iv;
1154 } *civ, const_iv[] = { 1198 } *civ, const_iv[] = {
1155#define const_iv(name) { # name, (IV)DB_ ## name }, 1199#define const_iv(name) { # name, (IV)DB_ ## name },
1200#if DBVER <= 408
1156 const_iv (RPCCLIENT) 1201 const_iv (RPCCLIENT)
1202#endif
1157 const_iv (INIT_CDB) 1203 const_iv (INIT_CDB)
1158 const_iv (INIT_LOCK) 1204 const_iv (INIT_LOCK)
1159 const_iv (INIT_LOG) 1205 const_iv (INIT_LOG)
1160 const_iv (INIT_MPOOL) 1206 const_iv (INIT_MPOOL)
1161 const_iv (INIT_REP) 1207 const_iv (INIT_REP)
1184 const_iv (TXN_NOT_DURABLE) 1230 const_iv (TXN_NOT_DURABLE)
1185 const_iv (TXN_WRITE_NOSYNC) 1231 const_iv (TXN_WRITE_NOSYNC)
1186 const_iv (WRITECURSOR) 1232 const_iv (WRITECURSOR)
1187 const_iv (YIELDCPU) 1233 const_iv (YIELDCPU)
1188 const_iv (ENCRYPT_AES) 1234 const_iv (ENCRYPT_AES)
1235#if DBVER < 408
1189 const_iv (XA_CREATE) 1236 const_iv (XA_CREATE)
1237#endif
1190 const_iv (BTREE) 1238 const_iv (BTREE)
1191 const_iv (HASH) 1239 const_iv (HASH)
1192 const_iv (QUEUE) 1240 const_iv (QUEUE)
1193 const_iv (RECNO) 1241 const_iv (RECNO)
1194 const_iv (UNKNOWN) 1242 const_iv (UNKNOWN)
1197 const_iv (NOSYNC) 1245 const_iv (NOSYNC)
1198 const_iv (CHKSUM) 1246 const_iv (CHKSUM)
1199 const_iv (ENCRYPT) 1247 const_iv (ENCRYPT)
1200 const_iv (DUP) 1248 const_iv (DUP)
1201 const_iv (DUPSORT) 1249 const_iv (DUPSORT)
1202 const_iv (RECNUM) 1250 //const_iv (RECNUM)
1203 const_iv (RENUMBER) 1251 const_iv (RENUMBER)
1204 const_iv (REVSPLITOFF) 1252 const_iv (REVSPLITOFF)
1205 const_iv (CONSUME) 1253 const_iv (CONSUME)
1206 const_iv (CONSUME_WAIT) 1254 const_iv (CONSUME_WAIT)
1207 const_iv (GET_BOTH) 1255 const_iv (GET_BOTH)
1258 const_iv (LOCK_OLDEST) 1306 const_iv (LOCK_OLDEST)
1259 const_iv (LOCK_RANDOM) 1307 const_iv (LOCK_RANDOM)
1260 const_iv (LOCK_YOUNGEST) 1308 const_iv (LOCK_YOUNGEST)
1261 1309
1262 const_iv (DONOTINDEX) 1310 const_iv (DONOTINDEX)
1263 const_iv (KEYEMPTY ) 1311 const_iv (KEYEMPTY)
1264 const_iv (KEYEXIST ) 1312 const_iv (KEYEXIST)
1265 const_iv (LOCK_DEADLOCK) 1313 const_iv (LOCK_DEADLOCK)
1266 const_iv (LOCK_NOTGRANTED) 1314 const_iv (LOCK_NOTGRANTED)
1267 const_iv (NOSERVER) 1315 const_iv (NOSERVER)
1268 const_iv (NOSERVER_HOME) 1316 const_iv (NOSERVER_HOME)
1269 const_iv (NOSERVER_ID) 1317 const_iv (NOSERVER_ID)
1279 const_iv (REP_UNAVAIL) 1327 const_iv (REP_UNAVAIL)
1280 const_iv (RUNRECOVERY) 1328 const_iv (RUNRECOVERY)
1281 const_iv (SECONDARY_BAD) 1329 const_iv (SECONDARY_BAD)
1282 const_iv (VERIFY_BAD) 1330 const_iv (VERIFY_BAD)
1283 1331
1332 const_iv (SALVAGE)
1333 const_iv (AGGRESSIVE)
1334 const_iv (PRINTABLE)
1335 const_iv (NOORDERCHK)
1336 const_iv (ORDERCHKONLY)
1337
1338 const_iv (ARCH_ABS)
1339 const_iv (ARCH_DATA)
1340 const_iv (ARCH_LOG)
1341 const_iv (ARCH_REMOVE)
1342
1284 const_iv (VERB_DEADLOCK) 1343 const_iv (VERB_DEADLOCK)
1285 const_iv (VERB_RECOVERY) 1344 const_iv (VERB_RECOVERY)
1286 const_iv (VERB_REPLICATION) 1345 const_iv (VERB_REPLICATION)
1287 const_iv (VERB_WAITSFOR) 1346 const_iv (VERB_WAITSFOR)
1288 1347
1289 const_iv (VERSION_MAJOR) 1348 const_iv (VERSION_MAJOR)
1290 const_iv (VERSION_MINOR) 1349 const_iv (VERSION_MINOR)
1291 const_iv (VERSION_PATCH) 1350 const_iv (VERSION_PATCH)
1292#if DB_VERSION_MINOR >= 3 1351 const_iv (LOGVERSION)
1352 const_iv (LOGOLDVER)
1353#if DBVER >= 403
1293 const_iv (INORDER) 1354 const_iv (INORDER)
1294 const_iv (LOCK_MAXWRITE) 1355 const_iv (LOCK_MAXWRITE)
1295 const_iv (SEQ_DEC) 1356 const_iv (SEQ_DEC)
1296 const_iv (SEQ_INC) 1357 const_iv (SEQ_INC)
1297 const_iv (SEQ_WRAP) 1358 const_iv (SEQ_WRAP)
1298 const_iv (BUFFER_SMALL) 1359 const_iv (BUFFER_SMALL)
1299 const_iv (LOG_BUFFER_FULL) 1360 const_iv (LOG_BUFFER_FULL)
1300 const_iv (VERSION_MISMATCH) 1361 const_iv (VERSION_MISMATCH)
1301#endif 1362#endif
1302#if DB_VERSION_MINOR >= 4 1363#if DBVER >= 404
1303 const_iv (REGISTER) 1364 const_iv (REGISTER)
1304 const_iv (DSYNC_DB) 1365 const_iv (DSYNC_DB)
1305 const_iv (READ_COMMITTED) 1366 const_iv (READ_COMMITTED)
1306 const_iv (READ_UNCOMMITTED) 1367 const_iv (READ_UNCOMMITTED)
1307 const_iv (REP_IGNORE) 1368 const_iv (REP_IGNORE)
1309 const_iv (REP_JOIN_FAILURE) 1370 const_iv (REP_JOIN_FAILURE)
1310 const_iv (FREE_SPACE) 1371 const_iv (FREE_SPACE)
1311 const_iv (FREELIST_ONLY) 1372 const_iv (FREELIST_ONLY)
1312 const_iv (VERB_REGISTER) 1373 const_iv (VERB_REGISTER)
1313#endif 1374#endif
1314#if DB_VERSION_MINOR >= 5 1375#if DBVER >= 405
1315 const_iv (MULTIVERSION) 1376 const_iv (MULTIVERSION)
1316 const_iv (TXN_SNAPSHOT) 1377 const_iv (TXN_SNAPSHOT)
1317#endif 1378#endif
1318#if DB_VERSION_MINOR >= 6 1379#if DBVER >= 406
1319 const_iv (PREV_DUP) 1380 const_iv (PREV_DUP)
1320 const_iv (PRIORITY_UNCHANGED) 1381 const_iv (PRIORITY_UNCHANGED)
1321 const_iv (PRIORITY_VERY_LOW) 1382 const_iv (PRIORITY_VERY_LOW)
1322 const_iv (PRIORITY_LOW) 1383 const_iv (PRIORITY_LOW)
1323 const_iv (PRIORITY_DEFAULT) 1384 const_iv (PRIORITY_DEFAULT)
1324 const_iv (PRIORITY_HIGH) 1385 const_iv (PRIORITY_HIGH)
1325 const_iv (PRIORITY_VERY_HIGH) 1386 const_iv (PRIORITY_VERY_HIGH)
1387 const_iv (IGNORE_LEASE)
1326#endif 1388#endif
1327#if DB_VERSION_MINOR >= 7 1389#if DBVER >= 407
1390 //const_iv (MULTIPLE_KEY)
1328 const_iv (LOG_DIRECT) 1391 const_iv (LOG_DIRECT)
1329 const_iv (LOG_DSYNC) 1392 const_iv (LOG_DSYNC)
1330 const_iv (LOG_AUTO_REMOVE) 1393 const_iv (LOG_AUTO_REMOVE)
1331 const_iv (LOG_IN_MEMORY) 1394 const_iv (LOG_IN_MEMORY)
1332 const_iv (LOG_ZERO) 1395 const_iv (LOG_ZERO)
1333#else 1396#else
1334 const_iv (DIRECT_LOG) 1397 const_iv (DIRECT_LOG)
1335 const_iv (LOG_AUTOREMOVE) 1398 const_iv (LOG_AUTOREMOVE)
1336# if DB_VERSION_MINOR >= 3 1399# if DBVER >= 403
1337 const_iv (DSYNC_LOG) 1400 const_iv (DSYNC_LOG)
1338 const_iv (LOG_INMEMORY) 1401 const_iv (LOG_INMEMORY)
1339# endif 1402# endif
1403#if DBVER >= 408
1404 const_iv (LOGVERSION_LATCHING)
1405#endif
1340#endif 1406#endif
1341 }; 1407 };
1342 1408
1409 bdb_stash = gv_stashpv ("BDB" , 1);
1410 bdb_env_stash = gv_stashpv ("BDB::Env" , 1);
1411 bdb_txn_stash = gv_stashpv ("BDB::Txn" , 1);
1412 bdb_cursor_stash = gv_stashpv ("BDB::Cursor" , 1);
1413 bdb_db_stash = gv_stashpv ("BDB::Db" , 1);
1414 bdb_sequence_stash = gv_stashpv ("BDB::Sequence", 1);
1415
1343 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1416 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
1344 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1417 newCONSTSUB (bdb_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
1345 1418
1346 prepare_cb = &PL_sv_undef; 1419 prepare_cb = &PL_sv_undef;
1347 1420
1348 { 1421 {
1349 /* we currently only allow version, minor-version and patchlevel to go up to 255 */ 1422 /* we currently only allow version, minor-version and patchlevel to go up to 255 */
1350 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; 1423 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH };
1351 1424
1352 newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); 1425 newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3));
1353 } 1426 }
1354 1427
1355 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1428 newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1356 1429
1357 create_respipe (); 1430 create_respipe ();
1358 1431
1359 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1432 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1360 patch_errno (); 1433 patch_errno ();
1438 1511
1439int 1512int
1440poll_fileno () 1513poll_fileno ()
1441 PROTOTYPE: 1514 PROTOTYPE:
1442 CODE: 1515 CODE:
1443 RETVAL = respipe [0]; 1516 RETVAL = s_epipe_fd (&respipe);
1444 OUTPUT: 1517 OUTPUT:
1445 RETVAL 1518 RETVAL
1446 1519
1447int 1520int
1448poll_cb (...) 1521poll_cb (...)
1549db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) 1622db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0)
1550 PREINIT: 1623 PREINIT:
1551 CALLBACK 1624 CALLBACK
1552 CODE: 1625 CODE:
1553{ 1626{
1627 dREQ (REQ_ENV_CLOSE, 0);
1554 ptr_nuke (ST (0)); 1628 ptr_nuke (ST (0));
1555 dREQ (REQ_ENV_CLOSE, 0);
1556 req->env = env; 1629 req->env = env;
1557 req->uint1 = flags; 1630 req->uint1 = flags;
1558 REQ_SEND; 1631 REQ_SEND;
1559} 1632}
1560 1633
1632 dREQ (REQ_ENV_DBRENAME, 2); 1705 dREQ (REQ_ENV_DBRENAME, 2);
1633 req->env = env; 1706 req->env = env;
1634 req->buf1 = strdup_ornull (file); 1707 req->buf1 = strdup_ornull (file);
1635 req->buf2 = strdup_ornull (database); 1708 req->buf2 = strdup_ornull (database);
1636 req->buf3 = strdup_ornull (newname); 1709 req->buf3 = strdup_ornull (newname);
1710 req->uint1 = flags;
1711 REQ_SEND;
1712}
1713
1714void
1715db_env_log_archive (DB_ENV *env, SV_mutable *listp, U32 flags = 0, SV *callback = 0)
1716 PREINIT:
1717 CALLBACK
1718 CODE:
1719{
1720 dREQ (REQ_ENV_LOG_ARCHIVE, 1);
1721 req->sv1 = SvREFCNT_inc (listp);
1722 req->env = env;
1637 req->uint1 = flags; 1723 req->uint1 = flags;
1638 REQ_SEND; 1724 REQ_SEND;
1639} 1725}
1640 1726
1641DB * 1727DB *
1673db_close (DB *db, U32 flags = 0, SV *callback = 0) 1759db_close (DB *db, U32 flags = 0, SV *callback = 0)
1674 PREINIT: 1760 PREINIT:
1675 CALLBACK 1761 CALLBACK
1676 CODE: 1762 CODE:
1677{ 1763{
1764 dREQ (REQ_DB_CLOSE, 0);
1678 ptr_nuke (ST (0)); 1765 ptr_nuke (ST (0));
1679 dREQ (REQ_DB_CLOSE, 0);
1680 req->db = db; 1766 req->db = db;
1681 req->uint1 = flags; 1767 req->uint1 = flags;
1682 req->sv1 = (SV *)db->app_private; 1768 req->sv1 = (SV *)db->app_private;
1683 REQ_SEND; 1769 REQ_SEND;
1684} 1770}
1685 1771
1686#if DB_VERSION_MINOR >= 4 1772#if DBVER >= 404
1687 1773
1688void 1774void
1689db_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) 1775db_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)
1690 PREINIT: 1776 PREINIT:
1691 CALLBACK 1777 CALLBACK
1692 CODE: 1778 CODE:
1693{ 1779{
1694 dREQ (REQ_DB_COMPACT, 2); 1780 dREQ (REQ_DB_COMPACT, 2);
1695 req->db = db; 1781 req->db = db;
1696 req->txn = txn; 1782 req->txn = txn;
1697 sv_to_dbt (&req->dbt1, start); 1783 if (start) sv_to_dbt (&req->dbt1, start);
1698 sv_to_dbt (&req->dbt2, stop); 1784 if (stop ) sv_to_dbt (&req->dbt2, stop );
1699 req->uint1 = flags; 1785 req->uint1 = flags;
1700 REQ_SEND; 1786 REQ_SEND;
1701} 1787}
1702 1788
1703#endif 1789#endif
1713 req->uint1 = flags; 1799 req->uint1 = flags;
1714 REQ_SEND; 1800 REQ_SEND;
1715} 1801}
1716 1802
1717void 1803void
1804db_verify (DB *db, bdb_filename file, bdb_filename database = 0, SV *dummy = 0, U32 flags = 0, SV *callback = 0)
1805 PREINIT:
1806 CALLBACK
1807 CODE:
1808{
1809 dREQ (REQ_DB_VERIFY, 1);
1810 ptr_nuke (ST (0)); /* verify destroys the database handle, hopefully it is freed as well */
1811 req->db = db;
1812 req->buf1 = strdup (file);
1813 req->buf2 = strdup_ornull (database);
1814 req->uint1 = flags;
1815 REQ_SEND;
1816}
1817
1818void
1718db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) 1819db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0)
1719 PREINIT: 1820 PREINIT:
1720 CALLBACK 1821 CALLBACK
1721 CODE: 1822 CODE:
1722{ 1823{
1723 dREQ (REQ_DB_SYNC, 1); 1824 dREQ (REQ_DB_UPGRADE, 1);
1724 req->db = db; 1825 req->db = db;
1725 req->buf1 = strdup (file); 1826 req->buf1 = strdup (file);
1726 req->uint1 = flags; 1827 req->uint1 = flags;
1727 REQ_SEND; 1828 REQ_SEND;
1728} 1829}
1755 sv_to_dbt (&req->dbt2, data); 1856 sv_to_dbt (&req->dbt2, data);
1756 req->uint1 = flags; 1857 req->uint1 = flags;
1757 REQ_SEND; 1858 REQ_SEND;
1758} 1859}
1759 1860
1760#if DB_VERSION_MINOR >= 6 1861#if DBVER >= 406
1761 1862
1762void 1863void
1763db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) 1864db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0)
1764 PREINIT: 1865 PREINIT:
1765 CALLBACK 1866 CALLBACK
1832db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) 1933db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1833 PREINIT: 1934 PREINIT:
1834 CALLBACK 1935 CALLBACK
1835 CODE: 1936 CODE:
1836{ 1937{
1938 dREQ (REQ_TXN_COMMIT, 0);
1837 ptr_nuke (ST (0)); 1939 ptr_nuke (ST (0));
1838 dREQ (REQ_TXN_COMMIT, 0);
1839 req->txn = txn; 1940 req->txn = txn;
1840 req->uint1 = flags; 1941 req->uint1 = flags;
1841 REQ_SEND; 1942 REQ_SEND;
1842} 1943}
1843 1944
1845db_txn_abort (DB_TXN *txn, SV *callback = 0) 1946db_txn_abort (DB_TXN *txn, SV *callback = 0)
1846 PREINIT: 1947 PREINIT:
1847 CALLBACK 1948 CALLBACK
1848 CODE: 1949 CODE:
1849{ 1950{
1951 dREQ (REQ_TXN_ABORT, 0);
1850 ptr_nuke (ST (0)); 1952 ptr_nuke (ST (0));
1851 dREQ (REQ_TXN_ABORT, 0);
1852 req->txn = txn; 1953 req->txn = txn;
1853 REQ_SEND; 1954 REQ_SEND;
1854} 1955}
1855 1956
1856void 1957void
1857db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0) 1958db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1858 PREINIT: 1959 PREINIT:
1859 CALLBACK 1960 CALLBACK
1860 CODE: 1961 CODE:
1861{ 1962{
1963 dREQ (REQ_TXN_FINISH, 0);
1862 ptr_nuke (ST (0)); 1964 ptr_nuke (ST (0));
1863 dREQ (REQ_TXN_FINISH, 0);
1864 req->txn = txn; 1965 req->txn = txn;
1865 req->uint1 = flags; 1966 req->uint1 = flags;
1866 REQ_SEND; 1967 REQ_SEND;
1867} 1968}
1868 1969
1870db_c_close (DBC *dbc, SV *callback = 0) 1971db_c_close (DBC *dbc, SV *callback = 0)
1871 PREINIT: 1972 PREINIT:
1872 CALLBACK 1973 CALLBACK
1873 CODE: 1974 CODE:
1874{ 1975{
1976 dREQ (REQ_C_CLOSE, 0);
1875 ptr_nuke (ST (0)); 1977 ptr_nuke (ST (0));
1876 dREQ (REQ_C_CLOSE, 0);
1877 req->dbc = dbc; 1978 req->dbc = dbc;
1878 REQ_SEND; 1979 REQ_SEND;
1879} 1980}
1880 1981
1881void 1982void
1908db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0) 2009db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1909 PREINIT: 2010 PREINIT:
1910 CALLBACK 2011 CALLBACK
1911 CODE: 2012 CODE:
1912{ 2013{
1913 if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) 2014 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
1914 croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET"); 2015 croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET");
2016 if (SvPOKp (key) && !sv_utf8_downgrade (key, 1))
2017 croak ("argument \"%s\" must be byte/octet-encoded in %s",
2018 "key",
2019 "BDB::db_c_get");
1915 2020
2021 {
1916 dREQ (REQ_C_GET, 1); 2022 dREQ (REQ_C_GET, 1);
1917 req->dbc = dbc; 2023 req->dbc = dbc;
1918 req->uint1 = flags; 2024 req->uint1 = flags;
1919 if (flags & DB_OPFLAGS_MASK == DB_SET) 2025 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1920 sv_to_dbt (&req->dbt1, key); 2026 sv_to_dbt (&req->dbt1, key);
1921 else 2027 else
1922 { 2028 {
1923 if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) 2029 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
1924 sv_to_dbt (&req->dbt1, key); 2030 sv_to_dbt (&req->dbt1, key);
1925 else 2031 else
1926 req->dbt1.flags = DB_DBT_MALLOC; 2032 req->dbt1.flags = DB_DBT_MALLOC;
1927 2033
1928 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); 2034 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1929 } 2035 }
1930 2036
1931 if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH 2037 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1932 || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) 2038 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1933 sv_to_dbt (&req->dbt3, data); 2039 sv_to_dbt (&req->dbt3, data);
1934 else 2040 else
1935 req->dbt3.flags = DB_DBT_MALLOC; 2041 req->dbt3.flags = DB_DBT_MALLOC;
1936 2042
1937 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2043 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1938 REQ_SEND; 2044 REQ_SEND;
2045 }
1939} 2046}
1940 2047
1941void 2048void
1942db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0) 2049db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1943 PREINIT: 2050 PREINIT:
1944 CALLBACK 2051 CALLBACK
1945 CODE: 2052 CODE:
1946{ 2053{
1947 if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) 2054 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
1948 croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET"); 2055 croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET");
2056 if (SvPOKp (key) && !sv_utf8_downgrade (key, 1))
2057 croak ("argument \"%s\" must be byte/octet-encoded in %s",
2058 "key",
2059 "BDB::db_c_pget");
1949 2060
2061 {
1950 dREQ (REQ_C_PGET, 1); 2062 dREQ (REQ_C_PGET, 1);
1951 req->dbc = dbc; 2063 req->dbc = dbc;
1952 req->uint1 = flags; 2064 req->uint1 = flags;
1953 if (flags & DB_OPFLAGS_MASK == DB_SET) 2065 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1954 sv_to_dbt (&req->dbt1, key); 2066 sv_to_dbt (&req->dbt1, key);
1955 else 2067 else
1956 { 2068 {
1957 if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) 2069 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
1958 sv_to_dbt (&req->dbt1, key); 2070 sv_to_dbt (&req->dbt1, key);
1959 else 2071 else
1960 req->dbt1.flags = DB_DBT_MALLOC; 2072 req->dbt1.flags = DB_DBT_MALLOC;
1961 2073
1962 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); 2074 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1963 } 2075 }
1964 2076
1965 req->dbt2.flags = DB_DBT_MALLOC; 2077 req->dbt2.flags = DB_DBT_MALLOC;
1966 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); 2078 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1967 2079
1968 if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH 2080 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1969 || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) 2081 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1970 sv_to_dbt (&req->dbt3, data); 2082 sv_to_dbt (&req->dbt3, data);
1971 else 2083 else
1972 req->dbt3.flags = DB_DBT_MALLOC; 2084 req->dbt3.flags = DB_DBT_MALLOC;
1973 2085
1974 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2086 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1975 REQ_SEND; 2087 REQ_SEND;
2088 }
1976} 2089}
1977 2090
1978void 2091void
1979db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) 2092db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0)
1980 PREINIT: 2093 PREINIT:
1986 req->uint1 = flags; 2099 req->uint1 = flags;
1987 REQ_SEND; 2100 REQ_SEND;
1988} 2101}
1989 2102
1990 2103
1991#if DB_VERSION_MINOR >= 3 2104#if DBVER >= 403
1992 2105
1993void 2106void
1994db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) 2107db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0)
1995 PREINIT: 2108 PREINIT:
1996 CALLBACK 2109 CALLBACK
2008db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) 2121db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0)
2009 PREINIT: 2122 PREINIT:
2010 CALLBACK 2123 CALLBACK
2011 CODE: 2124 CODE:
2012{ 2125{
2126 dREQ (REQ_SEQ_CLOSE, 0);
2013 ptr_nuke (ST (0)); 2127 ptr_nuke (ST (0));
2014 dREQ (REQ_SEQ_CLOSE, 0);
2015 req->seq = seq; 2128 req->seq = seq;
2016 req->uint1 = flags; 2129 req->uint1 = flags;
2017 REQ_SEND; 2130 REQ_SEND;
2018} 2131}
2019 2132
2090 CODE: 2203 CODE:
2091 RETVAL = env->set_flags (env, flags, onoff); 2204 RETVAL = env->set_flags (env, flags, onoff);
2092 OUTPUT: 2205 OUTPUT:
2093 RETVAL 2206 RETVAL
2094 2207
2095#if DB_VERSION_MINOR >= 7 2208#if DBVER >= 407
2096 2209
2097int set_intermediate_dir_mode (DB_ENV *env, const char *mode) 2210int set_intermediate_dir_mode (DB_ENV *env, const char *mode)
2098 CODE: 2211 CODE:
2099 RETVAL = env->set_intermediate_dir_mode (env, mode); 2212 RETVAL = env->set_intermediate_dir_mode (env, mode);
2100 OUTPUT: 2213 OUTPUT:
2187 CODE: 2300 CODE:
2188 RETVAL = env->set_lg_max (env, max); 2301 RETVAL = env->set_lg_max (env, max);
2189 OUTPUT: 2302 OUTPUT:
2190 RETVAL 2303 RETVAL
2191 2304
2192#if DB_VERSION_MINOR >= 4 2305#if DBVER >= 404
2193 2306
2194int mutex_set_max (DB_ENV *env, U32 max) 2307int mutex_set_max (DB_ENV *env, U32 max)
2195 CODE: 2308 CODE:
2196 RETVAL = env->mutex_set_max (env, max); 2309 RETVAL = env->mutex_set_max (env, max);
2197 OUTPUT: 2310 OUTPUT:
2224 if (errno) 2337 if (errno)
2225 croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); 2338 croak ("DB_ENV->txn_begin: %s", db_strerror (errno));
2226 OUTPUT: 2339 OUTPUT:
2227 RETVAL 2340 RETVAL
2228 2341
2229#if DB_VERSION_MINOR >= 5 2342#if DBVER >= 405
2230 2343
2231DB_TXN * 2344DB_TXN *
2232cdsgroup_begin (DB_ENV *env) 2345cdsgroup_begin (DB_ENV *env)
2233 CODE: 2346 CODE:
2234 errno = env->cdsgroup_begin (env, &RETVAL); 2347 errno = env->cdsgroup_begin (env, &RETVAL);
2255 CODE: 2368 CODE:
2256 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); 2369 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache);
2257 OUTPUT: 2370 OUTPUT:
2258 RETVAL 2371 RETVAL
2259 2372
2373int set_pagesize (DB *db, U32 pagesize)
2374 CODE:
2375 RETVAL = db->set_pagesize (db, pagesize);
2376 OUTPUT:
2377 RETVAL
2378
2260int set_flags (DB *db, U32 flags) 2379int set_flags (DB *db, U32 flags)
2261 CODE: 2380 CODE:
2262 RETVAL = db->set_flags (db, flags); 2381 RETVAL = db->set_flags (db, flags);
2263 OUTPUT: 2382 OUTPUT:
2264 RETVAL 2383 RETVAL
2330 if (errno) 2449 if (errno)
2331 croak ("DB->cursor: %s", db_strerror (errno)); 2450 croak ("DB->cursor: %s", db_strerror (errno));
2332 OUTPUT: 2451 OUTPUT:
2333 RETVAL 2452 RETVAL
2334 2453
2335#if DB_VERSION_MINOR >= 3 2454#if DBVER >= 403
2336 2455
2337DB_SEQUENCE * 2456DB_SEQUENCE *
2338sequence (DB *db, U32 flags = 0) 2457sequence (DB *db, U32 flags = 0)
2339 CODE: 2458 CODE:
2340{ 2459{
2375DESTROY (DBC_ornuked *dbc) 2494DESTROY (DBC_ornuked *dbc)
2376 CODE: 2495 CODE:
2377 if (dbc) 2496 if (dbc)
2378 dbc->c_close (dbc); 2497 dbc->c_close (dbc);
2379 2498
2380#if DB_VERSION_MINOR >= 6 2499#if DBVER >= 406
2381 2500
2382int set_priority (DBC *dbc, int priority) 2501int set_priority (DBC *dbc, int priority)
2383 CODE: 2502 CODE:
2384 dbc->set_priority (dbc, priority); 2503 dbc->set_priority (dbc, priority);
2385 2504
2386#endif 2505#endif
2387 2506
2388#if DB_VERSION_MINOR >= 3 2507#if DBVER >= 403
2389 2508
2390MODULE = BDB PACKAGE = BDB::Sequence 2509MODULE = BDB PACKAGE = BDB::Sequence
2391 2510
2392void 2511void
2393DESTROY (DB_SEQUENCE_ornuked *seq) 2512DESTROY (DB_SEQUENCE_ornuked *seq)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines