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

Comparing BDB/BDB.xs (file contents):
Revision 1.58 by root, Tue Sep 30 17:03:07 2008 UTC vs.
Revision 1.73 by root, Tue Dec 8 17:09:06 2009 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
53#if DB_VERSION_MINOR >= 3 55#if DB_VERSION_MINOR >= 3
54typedef DB_SEQUENCE DB_SEQUENCE_ornull; 56typedef DB_SEQUENCE DB_SEQUENCE_ornull;
55typedef DB_SEQUENCE DB_SEQUENCE_ornuked; 57typedef DB_SEQUENCE DB_SEQUENCE_ornuked;
56#endif 58#endif
57 59
58typedef SV SV8; /* byte-sv, used for argument-checking */
59typedef char *bdb_filename; 60typedef char *bdb_filename;
60 61
61static 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;
62 71
63#if DB_VERSION_MINOR >= 6 72#if DB_VERSION_MINOR >= 6
64# define c_close close 73# define c_close close
65# define c_count count 74# define c_count count
66# define c_del del 75# define c_del del
150 159
151enum { 160enum {
152 REQ_QUIT, 161 REQ_QUIT,
153 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,
154 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,
155 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,
156 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,
157 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, 167 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH,
158 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,
159 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,
160}; 170};
245} 255}
246 256
247static volatile unsigned int nreqs, nready, npending; 257static volatile unsigned int nreqs, nready, npending;
248static volatile unsigned int max_idle = 4; 258static volatile unsigned int max_idle = 4;
249static volatile unsigned int max_outstanding = 0xffffffff; 259static volatile unsigned int max_outstanding = 0xffffffff;
250static int respipe_osf [2], respipe [2] = { -1, -1 }; 260static s_epipe respipe;
251 261
252static mutex_t reslock = X_MUTEX_INIT; 262static mutex_t reslock = X_MUTEX_INIT;
253static mutex_t reqlock = X_MUTEX_INIT; 263static mutex_t reqlock = X_MUTEX_INIT;
254static cond_t reqwait = X_COND_INIT; 264static cond_t reqwait = X_COND_INIT;
255 265
378 388
379 av_push (av, newSVnv (req->key_range.less)); 389 av_push (av, newSVnv (req->key_range.less));
380 av_push (av, newSVnv (req->key_range.equal)); 390 av_push (av, newSVnv (req->key_range.equal));
381 av_push (av, newSVnv (req->key_range.greater)); 391 av_push (av, newSVnv (req->key_range.greater));
382 392
393 av = (AV *)newRV_noinc ((SV *)av);
394
383 SvREADONLY_off (req->sv1); 395 SvREADONLY_off (req->sv1);
384 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); 396 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av));
397 SvREFCNT_dec (av);
385 SvREFCNT_dec (req->sv1); 398 SvREFCNT_dec (req->sv1);
386 } 399 }
387 break; 400 break;
388 401
389#if DB_VERSION_MINOR >= 3 402#if DB_VERSION_MINOR >= 3
396 sv_setnv_mg (req->sv1, (NV)req->seq_t); 409 sv_setnv_mg (req->sv1, (NV)req->seq_t);
397 410
398 SvREFCNT_dec (req->sv1); 411 SvREFCNT_dec (req->sv1);
399 break; 412 break;
400#endif 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;
401 } 432 }
402 433
403 errno = req->result; 434 errno = req->result;
404 435
405 if (req->callback) 436 if (req->callback)
435 free (req->buf3); 466 free (req->buf3);
436 467
437 Safefree (req); 468 Safefree (req);
438} 469}
439 470
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 471static void
447create_respipe (void) 472create_respipe (void)
448{ 473{
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)) 474 if (s_epipe_renew (&respipe))
461#endif 475 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} 476}
486 477
487static void bdb_request (bdb_req req); 478static void bdb_request (bdb_req req);
488X_THREAD_PROC (bdb_proc); 479X_THREAD_PROC (bdb_proc);
489 480
625 end_thread (); 616 end_thread ();
626} 617}
627 618
628static void poll_wait (void) 619static void poll_wait (void)
629{ 620{
630 fd_set rfd;
631
632 while (nreqs) 621 while (nreqs)
633 { 622 {
634 int size; 623 int size;
635 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 624 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
636 size = res_queue.size; 625 size = res_queue.size;
639 if (size) 628 if (size)
640 return; 629 return;
641 630
642 maybe_start_thread (); 631 maybe_start_thread ();
643 632
644 FD_ZERO (&rfd); 633 s_epipe_wait (&respipe);
645 FD_SET (respipe [0], &rfd);
646
647 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
648 } 634 }
649} 635}
650 636
651static int poll_cb (void) 637static int poll_cb (void)
652{ 638{
672 if (req) 658 if (req)
673 { 659 {
674 --npending; 660 --npending;
675 661
676 if (!res_queue.size) 662 if (!res_queue.size)
677 {
678 /* read any signals sent by the worker threads */ 663 /* read any signals sent by the worker threads */
679 char buf [4]; 664 s_epipe_drain (&respipe);
680 while (respipe_read (respipe [0], buf, 4) == 4)
681 ;
682 }
683 } 665 }
684 666
685 X_UNLOCK (reslock); 667 X_UNLOCK (reslock);
686 668
687 if (!req) 669 if (!req)
769 req->result = req->db->close (req->db, req->uint1); 751 req->result = req->db->close (req->db, req->uint1);
770 break; 752 break;
771 753
772#if DB_VERSION_MINOR >= 4 754#if DB_VERSION_MINOR >= 4
773 case REQ_DB_COMPACT: 755 case REQ_DB_COMPACT:
774 req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0); 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);
775 break; 757 break;
776#endif 758#endif
777 759
778 case REQ_DB_SYNC: 760 case REQ_DB_SYNC:
779 req->result = req->db->sync (req->db, req->uint1); 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);
780 break; 766 break;
781 767
782 case REQ_DB_UPGRADE: 768 case REQ_DB_UPGRADE:
783 req->result = req->db->upgrade (req->db, req->buf1, req->uint1); 769 req->result = req->db->upgrade (req->db, req->buf1, req->uint1);
784 break; 770 break;
871 case REQ_SEQ_REMOVE: 857 case REQ_SEQ_REMOVE:
872 req->result = req->seq->remove (req->seq, req->txn, req->uint1); 858 req->result = req->seq->remove (req->seq, req->txn, req->uint1);
873 break; 859 break;
874#endif 860#endif
875 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
876 default: 870 default:
877 req->result = ENOSYS; 871 req->result = ENOSYS;
878 break; 872 break;
879 } 873 }
880 874
891 /* try to distribute timeouts somewhat evenly */ 885 /* try to distribute timeouts somewhat evenly */
892 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 886 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
893 887
894 for (;;) 888 for (;;)
895 { 889 {
896 ts.tv_sec = time (0) + IDLE_TIMEOUT; 890 ts.tv_sec = time (0) + IDLE_TIMEOUT;
897 891
898 X_LOCK (reqlock); 892 X_LOCK (reqlock);
899 893
900 for (;;) 894 for (;;)
901 { 895 {
946 X_LOCK (reslock); 940 X_LOCK (reslock);
947 941
948 ++npending; 942 ++npending;
949 943
950 if (!reqq_push (&res_queue, req)) 944 if (!reqq_push (&res_queue, req))
951 /* write a dummy byte to the pipe so fh becomes ready */ 945 s_epipe_signal (&respipe);
952 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
953 946
954 self->req = 0; 947 self->req = 0;
955 worker_clear (self); 948 worker_clear (self);
956 949
957 X_UNLOCK (reslock); 950 X_UNLOCK (reslock);
1033 (void)0; 1026 (void)0;
1034 1027
1035#define REQ_SEND \ 1028#define REQ_SEND \
1036 req_send (req) 1029 req_send (req)
1037 1030
1038#define SvPTR(var, arg, type, class, nullok) \ 1031#define SvPTR(var, arg, type, stash, class, nullok) \
1039 if (!SvOK (arg)) \ 1032 if (!SvOK (arg)) \
1040 { \ 1033 { \
1041 if (nullok != 1) \ 1034 if (nullok != 1) \
1042 croak (# var " must be a " # class " object, not undef"); \ 1035 croak (# var " must be a " # class " object, not undef"); \
1043 \ 1036 \
1044 (var) = 0; \ 1037 (var) = 0; \
1045 } \ 1038 } \
1046 else if (sv_derived_from ((arg), # class)) \ 1039 else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \
1047 { \ 1040 { \
1048 IV tmp = SvIV ((SV*) SvRV (arg)); \ 1041 IV tmp = SvIV ((SV*) SvRV (arg)); \
1049 (var) = INT2PTR (type, tmp); \ 1042 (var) = INT2PTR (type, tmp); \
1050 if (!var && nullok != 2) \ 1043 if (!var && nullok != 2) \
1051 croak (# var " is not a valid " # class " object anymore"); \ 1044 croak (# var " is not a valid " # class " object anymore"); \
1054 croak (# var " is not of type " # class); 1047 croak (# var " is not of type " # class);
1055 1048
1056#define ARG_MUTABLE(name) \ 1049#define ARG_MUTABLE(name) \
1057 if (SvREADONLY (name)) \ 1050 if (SvREADONLY (name)) \
1058 croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); 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}
1059 1062
1060static void 1063static void
1061ptr_nuke (SV *sv) 1064ptr_nuke (SV *sv)
1062{ 1065{
1063 assert (SvROK (sv)); 1066 assert (SvROK (sv));
1134 } 1137 }
1135 1138
1136 return 0; 1139 return 0;
1137} 1140}
1138 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
1139/* stupid windows defines CALLBACK as well */ 1183/* stupid windows defines CALLBACK as well */
1140#undef CALLBACK 1184#undef CALLBACK
1141#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); 1185#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1));
1142 1186
1143MODULE = BDB PACKAGE = BDB 1187MODULE = BDB PACKAGE = BDB
1144 1188
1145PROTOTYPES: ENABLE 1189PROTOTYPES: ENABLE
1146 1190
1147BOOT: 1191BOOT:
1148{ 1192{
1149 HV *stash = gv_stashpv ("BDB", 1);
1150
1151 static const struct { 1193 static const struct {
1152 const char *name; 1194 const char *name;
1153 IV iv; 1195 IV iv;
1154 } *civ, const_iv[] = { 1196 } *civ, const_iv[] = {
1155#define const_iv(name) { # name, (IV)DB_ ## name }, 1197#define const_iv(name) { # name, (IV)DB_ ## name },
1184 const_iv (TXN_NOT_DURABLE) 1226 const_iv (TXN_NOT_DURABLE)
1185 const_iv (TXN_WRITE_NOSYNC) 1227 const_iv (TXN_WRITE_NOSYNC)
1186 const_iv (WRITECURSOR) 1228 const_iv (WRITECURSOR)
1187 const_iv (YIELDCPU) 1229 const_iv (YIELDCPU)
1188 const_iv (ENCRYPT_AES) 1230 const_iv (ENCRYPT_AES)
1231#if DB_VERSION_MINOR < 8
1189 const_iv (XA_CREATE) 1232 const_iv (XA_CREATE)
1233#endif
1190 const_iv (BTREE) 1234 const_iv (BTREE)
1191 const_iv (HASH) 1235 const_iv (HASH)
1192 const_iv (QUEUE) 1236 const_iv (QUEUE)
1193 const_iv (RECNO) 1237 const_iv (RECNO)
1194 const_iv (UNKNOWN) 1238 const_iv (UNKNOWN)
1197 const_iv (NOSYNC) 1241 const_iv (NOSYNC)
1198 const_iv (CHKSUM) 1242 const_iv (CHKSUM)
1199 const_iv (ENCRYPT) 1243 const_iv (ENCRYPT)
1200 const_iv (DUP) 1244 const_iv (DUP)
1201 const_iv (DUPSORT) 1245 const_iv (DUPSORT)
1202 const_iv (RECNUM) 1246 //const_iv (RECNUM)
1203 const_iv (RENUMBER) 1247 const_iv (RENUMBER)
1204 const_iv (REVSPLITOFF) 1248 const_iv (REVSPLITOFF)
1205 const_iv (CONSUME) 1249 const_iv (CONSUME)
1206 const_iv (CONSUME_WAIT) 1250 const_iv (CONSUME_WAIT)
1207 const_iv (GET_BOTH) 1251 const_iv (GET_BOTH)
1258 const_iv (LOCK_OLDEST) 1302 const_iv (LOCK_OLDEST)
1259 const_iv (LOCK_RANDOM) 1303 const_iv (LOCK_RANDOM)
1260 const_iv (LOCK_YOUNGEST) 1304 const_iv (LOCK_YOUNGEST)
1261 1305
1262 const_iv (DONOTINDEX) 1306 const_iv (DONOTINDEX)
1263 const_iv (KEYEMPTY ) 1307 const_iv (KEYEMPTY)
1264 const_iv (KEYEXIST ) 1308 const_iv (KEYEXIST)
1265 const_iv (LOCK_DEADLOCK) 1309 const_iv (LOCK_DEADLOCK)
1266 const_iv (LOCK_NOTGRANTED) 1310 const_iv (LOCK_NOTGRANTED)
1267 const_iv (NOSERVER) 1311 const_iv (NOSERVER)
1268 const_iv (NOSERVER_HOME) 1312 const_iv (NOSERVER_HOME)
1269 const_iv (NOSERVER_ID) 1313 const_iv (NOSERVER_ID)
1279 const_iv (REP_UNAVAIL) 1323 const_iv (REP_UNAVAIL)
1280 const_iv (RUNRECOVERY) 1324 const_iv (RUNRECOVERY)
1281 const_iv (SECONDARY_BAD) 1325 const_iv (SECONDARY_BAD)
1282 const_iv (VERIFY_BAD) 1326 const_iv (VERIFY_BAD)
1283 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
1284 const_iv (VERB_DEADLOCK) 1339 const_iv (VERB_DEADLOCK)
1285 const_iv (VERB_RECOVERY) 1340 const_iv (VERB_RECOVERY)
1286 const_iv (VERB_REPLICATION) 1341 const_iv (VERB_REPLICATION)
1287 const_iv (VERB_WAITSFOR) 1342 const_iv (VERB_WAITSFOR)
1288 1343
1289 const_iv (VERSION_MAJOR) 1344 const_iv (VERSION_MAJOR)
1290 const_iv (VERSION_MINOR) 1345 const_iv (VERSION_MINOR)
1291 const_iv (VERSION_PATCH) 1346 const_iv (VERSION_PATCH)
1347 const_iv (LOGVERSION)
1348 const_iv (LOGOLDVER)
1292#if DB_VERSION_MINOR >= 3 1349#if DB_VERSION_MINOR >= 3
1293 const_iv (INORDER) 1350 const_iv (INORDER)
1294 const_iv (LOCK_MAXWRITE) 1351 const_iv (LOCK_MAXWRITE)
1295 const_iv (SEQ_DEC) 1352 const_iv (SEQ_DEC)
1296 const_iv (SEQ_INC) 1353 const_iv (SEQ_INC)
1321 const_iv (PRIORITY_VERY_LOW) 1378 const_iv (PRIORITY_VERY_LOW)
1322 const_iv (PRIORITY_LOW) 1379 const_iv (PRIORITY_LOW)
1323 const_iv (PRIORITY_DEFAULT) 1380 const_iv (PRIORITY_DEFAULT)
1324 const_iv (PRIORITY_HIGH) 1381 const_iv (PRIORITY_HIGH)
1325 const_iv (PRIORITY_VERY_HIGH) 1382 const_iv (PRIORITY_VERY_HIGH)
1383 const_iv (IGNORE_LEASE)
1326#endif 1384#endif
1327#if DB_VERSION_MINOR >= 7 1385#if DB_VERSION_MINOR >= 7
1386 //const_iv (MULTIPLE_KEY)
1328 const_iv (LOG_DIRECT) 1387 const_iv (LOG_DIRECT)
1329 const_iv (LOG_DSYNC) 1388 const_iv (LOG_DSYNC)
1330 const_iv (LOG_AUTO_REMOVE) 1389 const_iv (LOG_AUTO_REMOVE)
1331 const_iv (LOG_IN_MEMORY) 1390 const_iv (LOG_IN_MEMORY)
1332 const_iv (LOG_ZERO) 1391 const_iv (LOG_ZERO)
1335 const_iv (LOG_AUTOREMOVE) 1394 const_iv (LOG_AUTOREMOVE)
1336# if DB_VERSION_MINOR >= 3 1395# if DB_VERSION_MINOR >= 3
1337 const_iv (DSYNC_LOG) 1396 const_iv (DSYNC_LOG)
1338 const_iv (LOG_INMEMORY) 1397 const_iv (LOG_INMEMORY)
1339# endif 1398# endif
1399#if DB_VERSION_MINOR >= 8
1400 const_iv (LOGVERSION_LATCHING)
1401#endif
1340#endif 1402#endif
1341 }; 1403 };
1342 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
1343 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; )
1344 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1413 newCONSTSUB (bdb_stash, (char *)civ->name, newSViv (civ->iv));
1345 1414
1346 prepare_cb = &PL_sv_undef; 1415 prepare_cb = &PL_sv_undef;
1347 1416
1348 { 1417 {
1349 /* 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 */
1350 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 };
1351 1420
1352 newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); 1421 newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3));
1353 } 1422 }
1354 1423
1355 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1424 newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1356 1425
1357 create_respipe (); 1426 create_respipe ();
1358 1427
1359 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1428 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1360 patch_errno (); 1429 patch_errno ();
1438 1507
1439int 1508int
1440poll_fileno () 1509poll_fileno ()
1441 PROTOTYPE: 1510 PROTOTYPE:
1442 CODE: 1511 CODE:
1443 RETVAL = respipe [0]; 1512 RETVAL = s_epipe_fd (&respipe);
1444 OUTPUT: 1513 OUTPUT:
1445 RETVAL 1514 RETVAL
1446 1515
1447int 1516int
1448poll_cb (...) 1517poll_cb (...)
1632 dREQ (REQ_ENV_DBRENAME, 2); 1701 dREQ (REQ_ENV_DBRENAME, 2);
1633 req->env = env; 1702 req->env = env;
1634 req->buf1 = strdup_ornull (file); 1703 req->buf1 = strdup_ornull (file);
1635 req->buf2 = strdup_ornull (database); 1704 req->buf2 = strdup_ornull (database);
1636 req->buf3 = strdup_ornull (newname); 1705 req->buf3 = strdup_ornull (newname);
1706 req->uint1 = flags;
1707 REQ_SEND;
1708}
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;
1637 req->uint1 = flags; 1719 req->uint1 = flags;
1638 REQ_SEND; 1720 REQ_SEND;
1639} 1721}
1640 1722
1641DB * 1723DB *
1692 CODE: 1774 CODE:
1693{ 1775{
1694 dREQ (REQ_DB_COMPACT, 2); 1776 dREQ (REQ_DB_COMPACT, 2);
1695 req->db = db; 1777 req->db = db;
1696 req->txn = txn; 1778 req->txn = txn;
1697 sv_to_dbt (&req->dbt1, start); 1779 if (start) sv_to_dbt (&req->dbt1, start);
1698 sv_to_dbt (&req->dbt2, stop); 1780 if (stop ) sv_to_dbt (&req->dbt2, stop );
1699 req->uint1 = flags; 1781 req->uint1 = flags;
1700 REQ_SEND; 1782 REQ_SEND;
1701} 1783}
1702 1784
1703#endif 1785#endif
1713 req->uint1 = flags; 1795 req->uint1 = flags;
1714 REQ_SEND; 1796 REQ_SEND;
1715} 1797}
1716 1798
1717void 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
1718db_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)
1719 PREINIT: 1816 PREINIT:
1720 CALLBACK 1817 CALLBACK
1721 CODE: 1818 CODE:
1722{ 1819{
1723 dREQ (REQ_DB_SYNC, 1); 1820 dREQ (REQ_DB_UPGRADE, 1);
1724 req->db = db; 1821 req->db = db;
1725 req->buf1 = strdup (file); 1822 req->buf1 = strdup (file);
1726 req->uint1 = flags; 1823 req->uint1 = flags;
1727 REQ_SEND; 1824 REQ_SEND;
1728} 1825}
1908db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0) 2005db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1909 PREINIT: 2006 PREINIT:
1910 CALLBACK 2007 CALLBACK
1911 CODE: 2008 CODE:
1912{ 2009{
1913 if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) 2010 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"); 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");
1915 2016
1916 { 2017 {
1917 dREQ (REQ_C_GET, 1); 2018 dREQ (REQ_C_GET, 1);
1918 req->dbc = dbc; 2019 req->dbc = dbc;
1919 req->uint1 = flags; 2020 req->uint1 = flags;
1920 if (flags & DB_OPFLAGS_MASK == DB_SET) 2021 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1921 sv_to_dbt (&req->dbt1, key); 2022 sv_to_dbt (&req->dbt1, key);
1922 else 2023 else
1923 { 2024 {
1924 if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) 2025 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
1925 sv_to_dbt (&req->dbt1, key); 2026 sv_to_dbt (&req->dbt1, key);
1926 else 2027 else
1927 req->dbt1.flags = DB_DBT_MALLOC; 2028 req->dbt1.flags = DB_DBT_MALLOC;
1928 2029
1929 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); 2030 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1930 } 2031 }
1931 2032
1932 if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH 2033 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1933 || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) 2034 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1934 sv_to_dbt (&req->dbt3, data); 2035 sv_to_dbt (&req->dbt3, data);
1935 else 2036 else
1936 req->dbt3.flags = DB_DBT_MALLOC; 2037 req->dbt3.flags = DB_DBT_MALLOC;
1937 2038
1938 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2039 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1944db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0) 2045db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1945 PREINIT: 2046 PREINIT:
1946 CALLBACK 2047 CALLBACK
1947 CODE: 2048 CODE:
1948{ 2049{
1949 if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) 2050 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
1950 croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET"); 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");
1951 2056
1952 { 2057 {
1953 dREQ (REQ_C_PGET, 1); 2058 dREQ (REQ_C_PGET, 1);
1954 req->dbc = dbc; 2059 req->dbc = dbc;
1955 req->uint1 = flags; 2060 req->uint1 = flags;
1956 if (flags & DB_OPFLAGS_MASK == DB_SET) 2061 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1957 sv_to_dbt (&req->dbt1, key); 2062 sv_to_dbt (&req->dbt1, key);
1958 else 2063 else
1959 { 2064 {
1960 if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) 2065 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
1961 sv_to_dbt (&req->dbt1, key); 2066 sv_to_dbt (&req->dbt1, key);
1962 else 2067 else
1963 req->dbt1.flags = DB_DBT_MALLOC; 2068 req->dbt1.flags = DB_DBT_MALLOC;
1964 2069
1965 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); 2070 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1966 } 2071 }
1967 2072
1968 req->dbt2.flags = DB_DBT_MALLOC; 2073 req->dbt2.flags = DB_DBT_MALLOC;
1969 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); 2074 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1970 2075
1971 if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH 2076 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1972 || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) 2077 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1973 sv_to_dbt (&req->dbt3, data); 2078 sv_to_dbt (&req->dbt3, data);
1974 else 2079 else
1975 req->dbt3.flags = DB_DBT_MALLOC; 2080 req->dbt3.flags = DB_DBT_MALLOC;
1976 2081
1977 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2082 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
2259 CODE: 2364 CODE:
2260 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); 2365 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache);
2261 OUTPUT: 2366 OUTPUT:
2262 RETVAL 2367 RETVAL
2263 2368
2369int set_pagesize (DB *db, U32 pagesize)
2370 CODE:
2371 RETVAL = db->set_pagesize (db, pagesize);
2372 OUTPUT:
2373 RETVAL
2374
2264int set_flags (DB *db, U32 flags) 2375int set_flags (DB *db, U32 flags)
2265 CODE: 2376 CODE:
2266 RETVAL = db->set_flags (db, flags); 2377 RETVAL = db->set_flags (db, flags);
2267 OUTPUT: 2378 OUTPUT:
2268 RETVAL 2379 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines