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

Comparing BDB/BDB.xs (file contents):
Revision 1.57 by root, Mon Sep 29 03:01:54 2008 UTC vs.
Revision 1.72 by root, Fri Dec 4 15:04: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
350 abort (); 360 abort ();
351} 361}
352 362
353static int poll_cb (void); 363static int poll_cb (void);
354static void req_free (bdb_req req); 364static void req_free (bdb_req req);
355static void req_cancel (bdb_req req);
356 365
357static int req_invoke (bdb_req req) 366static int req_invoke (bdb_req req)
358{ 367{
359 switch (req->type) 368 switch (req->type)
360 { 369 {
379 388
380 av_push (av, newSVnv (req->key_range.less)); 389 av_push (av, newSVnv (req->key_range.less));
381 av_push (av, newSVnv (req->key_range.equal)); 390 av_push (av, newSVnv (req->key_range.equal));
382 av_push (av, newSVnv (req->key_range.greater)); 391 av_push (av, newSVnv (req->key_range.greater));
383 392
393 av = (AV *)newRV_noinc ((SV *)av);
394
384 SvREADONLY_off (req->sv1); 395 SvREADONLY_off (req->sv1);
385 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); 396 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av));
397 SvREFCNT_dec (av);
386 SvREFCNT_dec (req->sv1); 398 SvREFCNT_dec (req->sv1);
387 } 399 }
388 break; 400 break;
389 401
390#if DB_VERSION_MINOR >= 3 402#if DB_VERSION_MINOR >= 3
397 sv_setnv_mg (req->sv1, (NV)req->seq_t); 409 sv_setnv_mg (req->sv1, (NV)req->seq_t);
398 410
399 SvREFCNT_dec (req->sv1); 411 SvREFCNT_dec (req->sv1);
400 break; 412 break;
401#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;
402 } 432 }
403 433
404 errno = req->result; 434 errno = req->result;
405 435
406 if (req->callback) 436 if (req->callback)
436 free (req->buf3); 466 free (req->buf3);
437 467
438 Safefree (req); 468 Safefree (req);
439} 469}
440 470
441#ifdef USE_SOCKETS_AS_HANDLES
442# define TO_SOCKET(x) (win32_get_osfhandle (x))
443#else
444# define TO_SOCKET(x) (x)
445#endif
446
447static void 471static void
448create_respipe (void) 472create_respipe (void)
449{ 473{
450#ifdef _WIN32
451 int arg; /* argg */
452#endif
453 int old_readfd = respipe [0];
454
455 if (respipe [1] >= 0)
456 respipe_close (TO_SOCKET (respipe [1]));
457
458#ifdef _WIN32
459 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe))
460#else
461 if (pipe (respipe)) 474 if (s_epipe_renew (&respipe))
462#endif 475 croak ("BDB: unable to create event pipe");
463 croak ("unable to initialize result pipe");
464
465 if (old_readfd >= 0)
466 {
467 if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0)
468 croak ("unable to initialize result pipe(2)");
469
470 respipe_close (respipe [0]);
471 respipe [0] = old_readfd;
472 }
473
474#ifdef _WIN32
475 arg = 1;
476 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg)
477 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg))
478#else
479 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
480 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
481#endif
482 croak ("unable to initialize result pipe(3)");
483
484 respipe_osf [0] = TO_SOCKET (respipe [0]);
485 respipe_osf [1] = TO_SOCKET (respipe [1]);
486} 476}
487 477
488static void bdb_request (bdb_req req); 478static void bdb_request (bdb_req req);
489X_THREAD_PROC (bdb_proc); 479X_THREAD_PROC (bdb_proc);
490 480
626 end_thread (); 616 end_thread ();
627} 617}
628 618
629static void poll_wait (void) 619static void poll_wait (void)
630{ 620{
631 fd_set rfd;
632
633 while (nreqs) 621 while (nreqs)
634 { 622 {
635 int size; 623 int size;
636 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 624 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
637 size = res_queue.size; 625 size = res_queue.size;
640 if (size) 628 if (size)
641 return; 629 return;
642 630
643 maybe_start_thread (); 631 maybe_start_thread ();
644 632
645 FD_ZERO (&rfd); 633 s_epipe_wait (&respipe);
646 FD_SET (respipe [0], &rfd);
647
648 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
649 } 634 }
650} 635}
651 636
652static int poll_cb (void) 637static int poll_cb (void)
653{ 638{
673 if (req) 658 if (req)
674 { 659 {
675 --npending; 660 --npending;
676 661
677 if (!res_queue.size) 662 if (!res_queue.size)
678 {
679 /* read any signals sent by the worker threads */ 663 /* read any signals sent by the worker threads */
680 char buf [4]; 664 s_epipe_drain (&respipe);
681 while (respipe_read (respipe [0], buf, 4) == 4)
682 ;
683 }
684 } 665 }
685 666
686 X_UNLOCK (reslock); 667 X_UNLOCK (reslock);
687 668
688 if (!req) 669 if (!req)
770 req->result = req->db->close (req->db, req->uint1); 751 req->result = req->db->close (req->db, req->uint1);
771 break; 752 break;
772 753
773#if DB_VERSION_MINOR >= 4 754#if DB_VERSION_MINOR >= 4
774 case REQ_DB_COMPACT: 755 case REQ_DB_COMPACT:
775 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);
776 break; 757 break;
777#endif 758#endif
778 759
779 case REQ_DB_SYNC: 760 case REQ_DB_SYNC:
780 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);
781 break; 766 break;
782 767
783 case REQ_DB_UPGRADE: 768 case REQ_DB_UPGRADE:
784 req->result = req->db->upgrade (req->db, req->buf1, req->uint1); 769 req->result = req->db->upgrade (req->db, req->buf1, req->uint1);
785 break; 770 break;
872 case REQ_SEQ_REMOVE: 857 case REQ_SEQ_REMOVE:
873 req->result = req->seq->remove (req->seq, req->txn, req->uint1); 858 req->result = req->seq->remove (req->seq, req->txn, req->uint1);
874 break; 859 break;
875#endif 860#endif
876 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
877 default: 870 default:
878 req->result = ENOSYS; 871 req->result = ENOSYS;
879 break; 872 break;
880 } 873 }
881 874
892 /* try to distribute timeouts somewhat evenly */ 885 /* try to distribute timeouts somewhat evenly */
893 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 886 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
894 887
895 for (;;) 888 for (;;)
896 { 889 {
897 ts.tv_sec = time (0) + IDLE_TIMEOUT; 890 ts.tv_sec = time (0) + IDLE_TIMEOUT;
898 891
899 X_LOCK (reqlock); 892 X_LOCK (reqlock);
900 893
901 for (;;) 894 for (;;)
902 { 895 {
947 X_LOCK (reslock); 940 X_LOCK (reslock);
948 941
949 ++npending; 942 ++npending;
950 943
951 if (!reqq_push (&res_queue, req)) 944 if (!reqq_push (&res_queue, req))
952 /* write a dummy byte to the pipe so fh becomes ready */ 945 s_epipe_signal (&respipe);
953 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
954 946
955 self->req = 0; 947 self->req = 0;
956 worker_clear (self); 948 worker_clear (self);
957 949
958 X_UNLOCK (reslock); 950 X_UNLOCK (reslock);
1034 (void)0; 1026 (void)0;
1035 1027
1036#define REQ_SEND \ 1028#define REQ_SEND \
1037 req_send (req) 1029 req_send (req)
1038 1030
1039#define SvPTR(var, arg, type, class, nullok) \ 1031#define SvPTR(var, arg, type, stash, class, nullok) \
1040 if (!SvOK (arg)) \ 1032 if (!SvOK (arg)) \
1041 { \ 1033 { \
1042 if (nullok != 1) \ 1034 if (nullok != 1) \
1043 croak (# var " must be a " # class " object, not undef"); \ 1035 croak (# var " must be a " # class " object, not undef"); \
1044 \ 1036 \
1045 (var) = 0; \ 1037 (var) = 0; \
1046 } \ 1038 } \
1047 else if (sv_derived_from ((arg), # class)) \ 1039 else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \
1048 { \ 1040 { \
1049 IV tmp = SvIV ((SV*) SvRV (arg)); \ 1041 IV tmp = SvIV ((SV*) SvRV (arg)); \
1050 (var) = INT2PTR (type, tmp); \ 1042 (var) = INT2PTR (type, tmp); \
1051 if (!var && nullok != 2) \ 1043 if (!var && nullok != 2) \
1052 croak (# var " is not a valid " # class " object anymore"); \ 1044 croak (# var " is not a valid " # class " object anymore"); \
1055 croak (# var " is not of type " # class); 1047 croak (# var " is not of type " # class);
1056 1048
1057#define ARG_MUTABLE(name) \ 1049#define ARG_MUTABLE(name) \
1058 if (SvREADONLY (name)) \ 1050 if (SvREADONLY (name)) \
1059 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}
1060 1062
1061static void 1063static void
1062ptr_nuke (SV *sv) 1064ptr_nuke (SV *sv)
1063{ 1065{
1064 assert (SvROK (sv)); 1066 assert (SvROK (sv));
1135 } 1137 }
1136 1138
1137 return 0; 1139 return 0;
1138} 1140}
1139 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
1140/* stupid windoes defined CALLBACK as well */ 1183/* stupid windows defines CALLBACK as well */
1141#undef CALLBACK 1184#undef CALLBACK
1142#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); 1185#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1));
1143 1186
1144MODULE = BDB PACKAGE = BDB 1187MODULE = BDB PACKAGE = BDB
1145 1188
1146PROTOTYPES: ENABLE 1189PROTOTYPES: ENABLE
1147 1190
1148BOOT: 1191BOOT:
1149{ 1192{
1150 HV *stash = gv_stashpv ("BDB", 1);
1151
1152 static const struct { 1193 static const struct {
1153 const char *name; 1194 const char *name;
1154 IV iv; 1195 IV iv;
1155 } *civ, const_iv[] = { 1196 } *civ, const_iv[] = {
1156#define const_iv(name) { # name, (IV)DB_ ## name }, 1197#define const_iv(name) { # name, (IV)DB_ ## name },
1198 const_iv (NOSYNC) 1239 const_iv (NOSYNC)
1199 const_iv (CHKSUM) 1240 const_iv (CHKSUM)
1200 const_iv (ENCRYPT) 1241 const_iv (ENCRYPT)
1201 const_iv (DUP) 1242 const_iv (DUP)
1202 const_iv (DUPSORT) 1243 const_iv (DUPSORT)
1203 const_iv (RECNUM) 1244 //const_iv (RECNUM)
1204 const_iv (RENUMBER) 1245 const_iv (RENUMBER)
1205 const_iv (REVSPLITOFF) 1246 const_iv (REVSPLITOFF)
1206 const_iv (CONSUME) 1247 const_iv (CONSUME)
1207 const_iv (CONSUME_WAIT) 1248 const_iv (CONSUME_WAIT)
1208 const_iv (GET_BOTH) 1249 const_iv (GET_BOTH)
1280 const_iv (REP_UNAVAIL) 1321 const_iv (REP_UNAVAIL)
1281 const_iv (RUNRECOVERY) 1322 const_iv (RUNRECOVERY)
1282 const_iv (SECONDARY_BAD) 1323 const_iv (SECONDARY_BAD)
1283 const_iv (VERIFY_BAD) 1324 const_iv (VERIFY_BAD)
1284 1325
1326 const_iv (SALVAGE)
1327 const_iv (AGGRESSIVE)
1328 const_iv (PRINTABLE)
1329 const_iv (NOORDERCHK)
1330 const_iv (ORDERCHKONLY)
1331
1332 const_iv (ARCH_ABS)
1333 const_iv (ARCH_DATA)
1334 const_iv (ARCH_LOG)
1335 const_iv (ARCH_REMOVE)
1336
1285 const_iv (VERB_DEADLOCK) 1337 const_iv (VERB_DEADLOCK)
1286 const_iv (VERB_RECOVERY) 1338 const_iv (VERB_RECOVERY)
1287 const_iv (VERB_REPLICATION) 1339 const_iv (VERB_REPLICATION)
1288 const_iv (VERB_WAITSFOR) 1340 const_iv (VERB_WAITSFOR)
1289 1341
1322 const_iv (PRIORITY_VERY_LOW) 1374 const_iv (PRIORITY_VERY_LOW)
1323 const_iv (PRIORITY_LOW) 1375 const_iv (PRIORITY_LOW)
1324 const_iv (PRIORITY_DEFAULT) 1376 const_iv (PRIORITY_DEFAULT)
1325 const_iv (PRIORITY_HIGH) 1377 const_iv (PRIORITY_HIGH)
1326 const_iv (PRIORITY_VERY_HIGH) 1378 const_iv (PRIORITY_VERY_HIGH)
1379 const_iv (IGNORE_LEASE)
1327#endif 1380#endif
1328#if DB_VERSION_MINOR >= 7 1381#if DB_VERSION_MINOR >= 7
1382 //const_iv (MULTIPLE_KEY)
1329 const_iv (LOG_DIRECT) 1383 const_iv (LOG_DIRECT)
1330 const_iv (LOG_DSYNC) 1384 const_iv (LOG_DSYNC)
1331 const_iv (LOG_AUTO_REMOVE) 1385 const_iv (LOG_AUTO_REMOVE)
1332 const_iv (LOG_IN_MEMORY) 1386 const_iv (LOG_IN_MEMORY)
1333 const_iv (LOG_ZERO) 1387 const_iv (LOG_ZERO)
1339 const_iv (LOG_INMEMORY) 1393 const_iv (LOG_INMEMORY)
1340# endif 1394# endif
1341#endif 1395#endif
1342 }; 1396 };
1343 1397
1398 bdb_stash = gv_stashpv ("BDB" , 1);
1399 bdb_env_stash = gv_stashpv ("BDB::Env" , 1);
1400 bdb_txn_stash = gv_stashpv ("BDB::Txn" , 1);
1401 bdb_cursor_stash = gv_stashpv ("BDB::Cursor" , 1);
1402 bdb_db_stash = gv_stashpv ("BDB::Db" , 1);
1403 bdb_sequence_stash = gv_stashpv ("BDB::Sequence", 1);
1404
1344 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1405 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1345 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1406 newCONSTSUB (bdb_stash, (char *)civ->name, newSViv (civ->iv));
1346 1407
1347 prepare_cb = &PL_sv_undef; 1408 prepare_cb = &PL_sv_undef;
1348 1409
1349 { 1410 {
1350 /* we currently only allow version, minor-version and patchlevel to go up to 255 */ 1411 /* we currently only allow version, minor-version and patchlevel to go up to 255 */
1351 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; 1412 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH };
1352 1413
1353 newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); 1414 newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3));
1354 } 1415 }
1355 1416
1356 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1417 newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1357 1418
1358 create_respipe (); 1419 create_respipe ();
1359 1420
1360 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1421 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1361 patch_errno (); 1422 patch_errno ();
1439 1500
1440int 1501int
1441poll_fileno () 1502poll_fileno ()
1442 PROTOTYPE: 1503 PROTOTYPE:
1443 CODE: 1504 CODE:
1444 RETVAL = respipe [0]; 1505 RETVAL = s_epipe_fd (&respipe);
1445 OUTPUT: 1506 OUTPUT:
1446 RETVAL 1507 RETVAL
1447 1508
1448int 1509int
1449poll_cb (...) 1510poll_cb (...)
1633 dREQ (REQ_ENV_DBRENAME, 2); 1694 dREQ (REQ_ENV_DBRENAME, 2);
1634 req->env = env; 1695 req->env = env;
1635 req->buf1 = strdup_ornull (file); 1696 req->buf1 = strdup_ornull (file);
1636 req->buf2 = strdup_ornull (database); 1697 req->buf2 = strdup_ornull (database);
1637 req->buf3 = strdup_ornull (newname); 1698 req->buf3 = strdup_ornull (newname);
1699 req->uint1 = flags;
1700 REQ_SEND;
1701}
1702
1703void
1704db_env_log_archive (DB_ENV *env, SV_mutable *listp, U32 flags = 0, SV *callback = 0)
1705 PREINIT:
1706 CALLBACK
1707 CODE:
1708{
1709 dREQ (REQ_ENV_LOG_ARCHIVE, 1);
1710 req->sv1 = SvREFCNT_inc (listp);
1711 req->env = env;
1638 req->uint1 = flags; 1712 req->uint1 = flags;
1639 REQ_SEND; 1713 REQ_SEND;
1640} 1714}
1641 1715
1642DB * 1716DB *
1693 CODE: 1767 CODE:
1694{ 1768{
1695 dREQ (REQ_DB_COMPACT, 2); 1769 dREQ (REQ_DB_COMPACT, 2);
1696 req->db = db; 1770 req->db = db;
1697 req->txn = txn; 1771 req->txn = txn;
1698 sv_to_dbt (&req->dbt1, start); 1772 if (start) sv_to_dbt (&req->dbt1, start);
1699 sv_to_dbt (&req->dbt2, stop); 1773 if (stop ) sv_to_dbt (&req->dbt2, stop );
1700 req->uint1 = flags; 1774 req->uint1 = flags;
1701 REQ_SEND; 1775 REQ_SEND;
1702} 1776}
1703 1777
1704#endif 1778#endif
1714 req->uint1 = flags; 1788 req->uint1 = flags;
1715 REQ_SEND; 1789 REQ_SEND;
1716} 1790}
1717 1791
1718void 1792void
1793db_verify (DB *db, bdb_filename file, bdb_filename database = 0, SV *dummy = 0, U32 flags = 0, SV *callback = 0)
1794 PREINIT:
1795 CALLBACK
1796 CODE:
1797{
1798 dREQ (REQ_DB_VERIFY, 1);
1799 ptr_nuke (ST (0)); /* verify destroys the database handle, hopefully it is freed as well */
1800 req->db = db;
1801 req->buf1 = strdup (file);
1802 req->buf2 = strdup_ornull (database);
1803 req->uint1 = flags;
1804 REQ_SEND;
1805}
1806
1807void
1719db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) 1808db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0)
1720 PREINIT: 1809 PREINIT:
1721 CALLBACK 1810 CALLBACK
1722 CODE: 1811 CODE:
1723{ 1812{
1724 dREQ (REQ_DB_SYNC, 1); 1813 dREQ (REQ_DB_UPGRADE, 1);
1725 req->db = db; 1814 req->db = db;
1726 req->buf1 = strdup (file); 1815 req->buf1 = strdup (file);
1727 req->uint1 = flags; 1816 req->uint1 = flags;
1728 REQ_SEND; 1817 REQ_SEND;
1729} 1818}
1909db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0) 1998db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1910 PREINIT: 1999 PREINIT:
1911 CALLBACK 2000 CALLBACK
1912 CODE: 2001 CODE:
1913{ 2002{
1914 if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) 2003 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
1915 croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET"); 2004 croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET");
2005 if (SvPOKp (key) && !sv_utf8_downgrade (key, 1))
2006 croak ("argument \"%s\" must be byte/octet-encoded in %s",
2007 "key",
2008 "BDB::db_c_get");
1916 2009
1917 { 2010 {
1918 dREQ (REQ_C_GET, 1); 2011 dREQ (REQ_C_GET, 1);
1919 req->dbc = dbc; 2012 req->dbc = dbc;
1920 req->uint1 = flags; 2013 req->uint1 = flags;
1921 if (flags & DB_OPFLAGS_MASK == DB_SET) 2014 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1922 sv_to_dbt (&req->dbt1, key); 2015 sv_to_dbt (&req->dbt1, key);
1923 else 2016 else
1924 { 2017 {
1925 if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) 2018 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
1926 sv_to_dbt (&req->dbt1, key); 2019 sv_to_dbt (&req->dbt1, key);
1927 else 2020 else
1928 req->dbt1.flags = DB_DBT_MALLOC; 2021 req->dbt1.flags = DB_DBT_MALLOC;
1929 2022
1930 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); 2023 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1931 } 2024 }
1932 2025
1933 if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH 2026 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1934 || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) 2027 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1935 sv_to_dbt (&req->dbt3, data); 2028 sv_to_dbt (&req->dbt3, data);
1936 else 2029 else
1937 req->dbt3.flags = DB_DBT_MALLOC; 2030 req->dbt3.flags = DB_DBT_MALLOC;
1938 2031
1939 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2032 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1945db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0) 2038db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1946 PREINIT: 2039 PREINIT:
1947 CALLBACK 2040 CALLBACK
1948 CODE: 2041 CODE:
1949{ 2042{
1950 if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) 2043 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
1951 croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET"); 2044 croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET");
2045 if (SvPOKp (key) && !sv_utf8_downgrade (key, 1))
2046 croak ("argument \"%s\" must be byte/octet-encoded in %s",
2047 "key",
2048 "BDB::db_c_pget");
1952 2049
1953 { 2050 {
1954 dREQ (REQ_C_PGET, 1); 2051 dREQ (REQ_C_PGET, 1);
1955 req->dbc = dbc; 2052 req->dbc = dbc;
1956 req->uint1 = flags; 2053 req->uint1 = flags;
1957 if (flags & DB_OPFLAGS_MASK == DB_SET) 2054 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1958 sv_to_dbt (&req->dbt1, key); 2055 sv_to_dbt (&req->dbt1, key);
1959 else 2056 else
1960 { 2057 {
1961 if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) 2058 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
1962 sv_to_dbt (&req->dbt1, key); 2059 sv_to_dbt (&req->dbt1, key);
1963 else 2060 else
1964 req->dbt1.flags = DB_DBT_MALLOC; 2061 req->dbt1.flags = DB_DBT_MALLOC;
1965 2062
1966 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); 2063 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1967 } 2064 }
1968 2065
1969 req->dbt2.flags = DB_DBT_MALLOC; 2066 req->dbt2.flags = DB_DBT_MALLOC;
1970 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); 2067 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1971 2068
1972 if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH 2069 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1973 || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) 2070 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1974 sv_to_dbt (&req->dbt3, data); 2071 sv_to_dbt (&req->dbt3, data);
1975 else 2072 else
1976 req->dbt3.flags = DB_DBT_MALLOC; 2073 req->dbt3.flags = DB_DBT_MALLOC;
1977 2074
1978 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2075 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
2260 CODE: 2357 CODE:
2261 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); 2358 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache);
2262 OUTPUT: 2359 OUTPUT:
2263 RETVAL 2360 RETVAL
2264 2361
2362int set_pagesize (DB *db, U32 pagesize)
2363 CODE:
2364 RETVAL = db->set_pagesize (db, pagesize);
2365 OUTPUT:
2366 RETVAL
2367
2265int set_flags (DB *db, U32 flags) 2368int set_flags (DB *db, U32 flags)
2266 CODE: 2369 CODE:
2267 RETVAL = db->set_flags (db, flags); 2370 RETVAL = db->set_flags (db, flags);
2268 OUTPUT: 2371 OUTPUT:
2269 RETVAL 2372 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines