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

Comparing BDB/BDB.xs (file contents):
Revision 1.55 by root, Fri Sep 26 02:37:33 2008 UTC vs.
Revision 1.72 by root, Fri Dec 4 15:04:06 2009 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
56#if DB_VERSION_MINOR >= 3 55#if DB_VERSION_MINOR >= 3
57typedef DB_SEQUENCE DB_SEQUENCE_ornull; 56typedef DB_SEQUENCE DB_SEQUENCE_ornull;
58typedef DB_SEQUENCE DB_SEQUENCE_ornuked; 57typedef DB_SEQUENCE DB_SEQUENCE_ornuked;
59#endif 58#endif
60 59
61typedef SV SV8; /* byte-sv, used for argument-checking */
62typedef char *bdb_filename; 60typedef char *bdb_filename;
63 61
64static 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;
65 71
66#if DB_VERSION_MINOR >= 6 72#if DB_VERSION_MINOR >= 6
67# define c_close close 73# define c_close close
68# define c_count count 74# define c_count count
69# define c_del del 75# define c_del del
153 159
154enum { 160enum {
155 REQ_QUIT, 161 REQ_QUIT,
156 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,
157 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,
158 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,
159 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,
160 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, 167 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH,
161 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, 168 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL,
162 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, 169 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE,
163}; 170};
248} 255}
249 256
250static volatile unsigned int nreqs, nready, npending; 257static volatile unsigned int nreqs, nready, npending;
251static volatile unsigned int max_idle = 4; 258static volatile unsigned int max_idle = 4;
252static volatile unsigned int max_outstanding = 0xffffffff; 259static volatile unsigned int max_outstanding = 0xffffffff;
253static int respipe_osf [2], respipe [2] = { -1, -1 }; 260static s_epipe respipe;
254 261
255static mutex_t reslock = X_MUTEX_INIT; 262static mutex_t reslock = X_MUTEX_INIT;
256static mutex_t reqlock = X_MUTEX_INIT; 263static mutex_t reqlock = X_MUTEX_INIT;
257static cond_t reqwait = X_COND_INIT; 264static cond_t reqwait = X_COND_INIT;
258 265
353 abort (); 360 abort ();
354} 361}
355 362
356static int poll_cb (void); 363static int poll_cb (void);
357static void req_free (bdb_req req); 364static void req_free (bdb_req req);
358static void req_cancel (bdb_req req);
359 365
360static int req_invoke (bdb_req req) 366static int req_invoke (bdb_req req)
361{ 367{
362 switch (req->type) 368 switch (req->type)
363 { 369 {
382 388
383 av_push (av, newSVnv (req->key_range.less)); 389 av_push (av, newSVnv (req->key_range.less));
384 av_push (av, newSVnv (req->key_range.equal)); 390 av_push (av, newSVnv (req->key_range.equal));
385 av_push (av, newSVnv (req->key_range.greater)); 391 av_push (av, newSVnv (req->key_range.greater));
386 392
393 av = (AV *)newRV_noinc ((SV *)av);
394
387 SvREADONLY_off (req->sv1); 395 SvREADONLY_off (req->sv1);
388 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); 396 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av));
397 SvREFCNT_dec (av);
389 SvREFCNT_dec (req->sv1); 398 SvREFCNT_dec (req->sv1);
390 } 399 }
391 break; 400 break;
392 401
393#if DB_VERSION_MINOR >= 3 402#if DB_VERSION_MINOR >= 3
400 sv_setnv_mg (req->sv1, (NV)req->seq_t); 409 sv_setnv_mg (req->sv1, (NV)req->seq_t);
401 410
402 SvREFCNT_dec (req->sv1); 411 SvREFCNT_dec (req->sv1);
403 break; 412 break;
404#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;
405 } 432 }
406 433
407 errno = req->result; 434 errno = req->result;
408 435
409 if (req->callback) 436 if (req->callback)
439 free (req->buf3); 466 free (req->buf3);
440 467
441 Safefree (req); 468 Safefree (req);
442} 469}
443 470
444#ifdef USE_SOCKETS_AS_HANDLES
445# define TO_SOCKET(x) (win32_get_osfhandle (x))
446#else
447# define TO_SOCKET(x) (x)
448#endif
449
450static void 471static void
451create_respipe (void) 472create_respipe (void)
452{ 473{
453#ifdef _WIN32
454 int arg; /* argg */
455#endif
456 int old_readfd = respipe [0];
457
458 if (respipe [1] >= 0)
459 respipe_close (TO_SOCKET (respipe [1]));
460
461#ifdef _WIN32
462 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe))
463#else
464 if (pipe (respipe)) 474 if (s_epipe_renew (&respipe))
465#endif 475 croak ("BDB: unable to create event pipe");
466 croak ("unable to initialize result pipe");
467
468 if (old_readfd >= 0)
469 {
470 if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0)
471 croak ("unable to initialize result pipe(2)");
472
473 respipe_close (respipe [0]);
474 respipe [0] = old_readfd;
475 }
476
477#ifdef _WIN32
478 arg = 1;
479 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg)
480 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg))
481#else
482 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
483 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
484#endif
485 croak ("unable to initialize result pipe(3)");
486
487 respipe_osf [0] = TO_SOCKET (respipe [0]);
488 respipe_osf [1] = TO_SOCKET (respipe [1]);
489} 476}
490 477
491static void bdb_request (bdb_req req); 478static void bdb_request (bdb_req req);
492X_THREAD_PROC (bdb_proc); 479X_THREAD_PROC (bdb_proc);
493 480
629 end_thread (); 616 end_thread ();
630} 617}
631 618
632static void poll_wait (void) 619static void poll_wait (void)
633{ 620{
634 fd_set rfd;
635
636 while (nreqs) 621 while (nreqs)
637 { 622 {
638 int size; 623 int size;
639 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 624 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
640 size = res_queue.size; 625 size = res_queue.size;
643 if (size) 628 if (size)
644 return; 629 return;
645 630
646 maybe_start_thread (); 631 maybe_start_thread ();
647 632
648 FD_ZERO (&rfd); 633 s_epipe_wait (&respipe);
649 FD_SET (respipe [0], &rfd);
650
651 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
652 } 634 }
653} 635}
654 636
655static int poll_cb (void) 637static int poll_cb (void)
656{ 638{
676 if (req) 658 if (req)
677 { 659 {
678 --npending; 660 --npending;
679 661
680 if (!res_queue.size) 662 if (!res_queue.size)
681 {
682 /* read any signals sent by the worker threads */ 663 /* read any signals sent by the worker threads */
683 char buf [4]; 664 s_epipe_drain (&respipe);
684 while (respipe_read (respipe [0], buf, 4) == 4)
685 ;
686 }
687 } 665 }
688 666
689 X_UNLOCK (reslock); 667 X_UNLOCK (reslock);
690 668
691 if (!req) 669 if (!req)
773 req->result = req->db->close (req->db, req->uint1); 751 req->result = req->db->close (req->db, req->uint1);
774 break; 752 break;
775 753
776#if DB_VERSION_MINOR >= 4 754#if DB_VERSION_MINOR >= 4
777 case REQ_DB_COMPACT: 755 case REQ_DB_COMPACT:
778 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);
779 break; 757 break;
780#endif 758#endif
781 759
782 case REQ_DB_SYNC: 760 case REQ_DB_SYNC:
783 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);
784 break; 766 break;
785 767
786 case REQ_DB_UPGRADE: 768 case REQ_DB_UPGRADE:
787 req->result = req->db->upgrade (req->db, req->buf1, req->uint1); 769 req->result = req->db->upgrade (req->db, req->buf1, req->uint1);
788 break; 770 break;
875 case REQ_SEQ_REMOVE: 857 case REQ_SEQ_REMOVE:
876 req->result = req->seq->remove (req->seq, req->txn, req->uint1); 858 req->result = req->seq->remove (req->seq, req->txn, req->uint1);
877 break; 859 break;
878#endif 860#endif
879 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
880 default: 870 default:
881 req->result = ENOSYS; 871 req->result = ENOSYS;
882 break; 872 break;
883 } 873 }
884 874
895 /* try to distribute timeouts somewhat evenly */ 885 /* try to distribute timeouts somewhat evenly */
896 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 886 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
897 887
898 for (;;) 888 for (;;)
899 { 889 {
900 ts.tv_sec = time (0) + IDLE_TIMEOUT; 890 ts.tv_sec = time (0) + IDLE_TIMEOUT;
901 891
902 X_LOCK (reqlock); 892 X_LOCK (reqlock);
903 893
904 for (;;) 894 for (;;)
905 { 895 {
950 X_LOCK (reslock); 940 X_LOCK (reslock);
951 941
952 ++npending; 942 ++npending;
953 943
954 if (!reqq_push (&res_queue, req)) 944 if (!reqq_push (&res_queue, req))
955 /* write a dummy byte to the pipe so fh becomes ready */ 945 s_epipe_signal (&respipe);
956 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
957 946
958 self->req = 0; 947 self->req = 0;
959 worker_clear (self); 948 worker_clear (self);
960 949
961 X_UNLOCK (reslock); 950 X_UNLOCK (reslock);
1037 (void)0; 1026 (void)0;
1038 1027
1039#define REQ_SEND \ 1028#define REQ_SEND \
1040 req_send (req) 1029 req_send (req)
1041 1030
1042#define SvPTR(var, arg, type, class, nullok) \ 1031#define SvPTR(var, arg, type, stash, class, nullok) \
1043 if (!SvOK (arg)) \ 1032 if (!SvOK (arg)) \
1044 { \ 1033 { \
1045 if (nullok != 1) \ 1034 if (nullok != 1) \
1046 croak (# var " must be a " # class " object, not undef"); \ 1035 croak (# var " must be a " # class " object, not undef"); \
1047 \ 1036 \
1048 (var) = 0; \ 1037 (var) = 0; \
1049 } \ 1038 } \
1050 else if (sv_derived_from ((arg), # class)) \ 1039 else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \
1051 { \ 1040 { \
1052 IV tmp = SvIV ((SV*) SvRV (arg)); \ 1041 IV tmp = SvIV ((SV*) SvRV (arg)); \
1053 (var) = INT2PTR (type, tmp); \ 1042 (var) = INT2PTR (type, tmp); \
1054 if (!var && nullok != 2) \ 1043 if (!var && nullok != 2) \
1055 croak (# var " is not a valid " # class " object anymore"); \ 1044 croak (# var " is not a valid " # class " object anymore"); \
1058 croak (# var " is not of type " # class); 1047 croak (# var " is not of type " # class);
1059 1048
1060#define ARG_MUTABLE(name) \ 1049#define ARG_MUTABLE(name) \
1061 if (SvREADONLY (name)) \ 1050 if (SvREADONLY (name)) \
1062 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}
1063 1062
1064static void 1063static void
1065ptr_nuke (SV *sv) 1064ptr_nuke (SV *sv)
1066{ 1065{
1067 assert (SvROK (sv)); 1066 assert (SvROK (sv));
1138 } 1137 }
1139 1138
1140 return 0; 1139 return 0;
1141} 1140}
1142 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
1143/* stupid windoes defined CALLBACK as well */ 1183/* stupid windows defines CALLBACK as well */
1144#undef CALLBACK 1184#undef CALLBACK
1145#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); 1185#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1));
1146 1186
1147MODULE = BDB PACKAGE = BDB 1187MODULE = BDB PACKAGE = BDB
1148 1188
1149PROTOTYPES: ENABLE 1189PROTOTYPES: ENABLE
1150 1190
1151BOOT: 1191BOOT:
1152{ 1192{
1153 HV *stash = gv_stashpv ("BDB", 1);
1154
1155 static const struct { 1193 static const struct {
1156 const char *name; 1194 const char *name;
1157 IV iv; 1195 IV iv;
1158 } *civ, const_iv[] = { 1196 } *civ, const_iv[] = {
1159#define const_iv(name) { # name, (IV)DB_ ## name }, 1197#define const_iv(name) { # name, (IV)DB_ ## name },
1201 const_iv (NOSYNC) 1239 const_iv (NOSYNC)
1202 const_iv (CHKSUM) 1240 const_iv (CHKSUM)
1203 const_iv (ENCRYPT) 1241 const_iv (ENCRYPT)
1204 const_iv (DUP) 1242 const_iv (DUP)
1205 const_iv (DUPSORT) 1243 const_iv (DUPSORT)
1206 const_iv (RECNUM) 1244 //const_iv (RECNUM)
1207 const_iv (RENUMBER) 1245 const_iv (RENUMBER)
1208 const_iv (REVSPLITOFF) 1246 const_iv (REVSPLITOFF)
1209 const_iv (CONSUME) 1247 const_iv (CONSUME)
1210 const_iv (CONSUME_WAIT) 1248 const_iv (CONSUME_WAIT)
1211 const_iv (GET_BOTH) 1249 const_iv (GET_BOTH)
1283 const_iv (REP_UNAVAIL) 1321 const_iv (REP_UNAVAIL)
1284 const_iv (RUNRECOVERY) 1322 const_iv (RUNRECOVERY)
1285 const_iv (SECONDARY_BAD) 1323 const_iv (SECONDARY_BAD)
1286 const_iv (VERIFY_BAD) 1324 const_iv (VERIFY_BAD)
1287 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
1288 const_iv (VERB_DEADLOCK) 1337 const_iv (VERB_DEADLOCK)
1289 const_iv (VERB_RECOVERY) 1338 const_iv (VERB_RECOVERY)
1290 const_iv (VERB_REPLICATION) 1339 const_iv (VERB_REPLICATION)
1291 const_iv (VERB_WAITSFOR) 1340 const_iv (VERB_WAITSFOR)
1292 1341
1325 const_iv (PRIORITY_VERY_LOW) 1374 const_iv (PRIORITY_VERY_LOW)
1326 const_iv (PRIORITY_LOW) 1375 const_iv (PRIORITY_LOW)
1327 const_iv (PRIORITY_DEFAULT) 1376 const_iv (PRIORITY_DEFAULT)
1328 const_iv (PRIORITY_HIGH) 1377 const_iv (PRIORITY_HIGH)
1329 const_iv (PRIORITY_VERY_HIGH) 1378 const_iv (PRIORITY_VERY_HIGH)
1379 const_iv (IGNORE_LEASE)
1330#endif 1380#endif
1331#if DB_VERSION_MINOR >= 7 1381#if DB_VERSION_MINOR >= 7
1382 //const_iv (MULTIPLE_KEY)
1332 const_iv (LOG_DIRECT) 1383 const_iv (LOG_DIRECT)
1333 const_iv (LOG_DSYNC) 1384 const_iv (LOG_DSYNC)
1334 const_iv (LOG_AUTO_REMOVE) 1385 const_iv (LOG_AUTO_REMOVE)
1335 const_iv (LOG_IN_MEMORY) 1386 const_iv (LOG_IN_MEMORY)
1336 const_iv (LOG_ZERO) 1387 const_iv (LOG_ZERO)
1342 const_iv (LOG_INMEMORY) 1393 const_iv (LOG_INMEMORY)
1343# endif 1394# endif
1344#endif 1395#endif
1345 }; 1396 };
1346 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
1347 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; )
1348 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1406 newCONSTSUB (bdb_stash, (char *)civ->name, newSViv (civ->iv));
1349 1407
1350 prepare_cb = &PL_sv_undef; 1408 prepare_cb = &PL_sv_undef;
1351 1409
1352 { 1410 {
1353 /* 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 */
1354 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 };
1355 1413
1356 newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); 1414 newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3));
1357 } 1415 }
1358 1416
1359 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1417 newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1360 1418
1361 create_respipe (); 1419 create_respipe ();
1362 1420
1363 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1421 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1364 patch_errno (); 1422 patch_errno ();
1442 1500
1443int 1501int
1444poll_fileno () 1502poll_fileno ()
1445 PROTOTYPE: 1503 PROTOTYPE:
1446 CODE: 1504 CODE:
1447 RETVAL = respipe [0]; 1505 RETVAL = s_epipe_fd (&respipe);
1448 OUTPUT: 1506 OUTPUT:
1449 RETVAL 1507 RETVAL
1450 1508
1451int 1509int
1452poll_cb (...) 1510poll_cb (...)
1553db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) 1611db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0)
1554 PREINIT: 1612 PREINIT:
1555 CALLBACK 1613 CALLBACK
1556 CODE: 1614 CODE:
1557{ 1615{
1616 dREQ (REQ_ENV_CLOSE, 0);
1558 ptr_nuke (ST (0)); 1617 ptr_nuke (ST (0));
1559 dREQ (REQ_ENV_CLOSE, 0);
1560 req->env = env; 1618 req->env = env;
1561 req->uint1 = flags; 1619 req->uint1 = flags;
1562 REQ_SEND; 1620 REQ_SEND;
1563} 1621}
1564 1622
1636 dREQ (REQ_ENV_DBRENAME, 2); 1694 dREQ (REQ_ENV_DBRENAME, 2);
1637 req->env = env; 1695 req->env = env;
1638 req->buf1 = strdup_ornull (file); 1696 req->buf1 = strdup_ornull (file);
1639 req->buf2 = strdup_ornull (database); 1697 req->buf2 = strdup_ornull (database);
1640 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;
1641 req->uint1 = flags; 1712 req->uint1 = flags;
1642 REQ_SEND; 1713 REQ_SEND;
1643} 1714}
1644 1715
1645DB * 1716DB *
1677db_close (DB *db, U32 flags = 0, SV *callback = 0) 1748db_close (DB *db, U32 flags = 0, SV *callback = 0)
1678 PREINIT: 1749 PREINIT:
1679 CALLBACK 1750 CALLBACK
1680 CODE: 1751 CODE:
1681{ 1752{
1753 dREQ (REQ_DB_CLOSE, 0);
1682 ptr_nuke (ST (0)); 1754 ptr_nuke (ST (0));
1683 dREQ (REQ_DB_CLOSE, 0);
1684 req->db = db; 1755 req->db = db;
1685 req->uint1 = flags; 1756 req->uint1 = flags;
1686 req->sv1 = (SV *)db->app_private; 1757 req->sv1 = (SV *)db->app_private;
1687 REQ_SEND; 1758 REQ_SEND;
1688} 1759}
1696 CODE: 1767 CODE:
1697{ 1768{
1698 dREQ (REQ_DB_COMPACT, 2); 1769 dREQ (REQ_DB_COMPACT, 2);
1699 req->db = db; 1770 req->db = db;
1700 req->txn = txn; 1771 req->txn = txn;
1701 sv_to_dbt (&req->dbt1, start); 1772 if (start) sv_to_dbt (&req->dbt1, start);
1702 sv_to_dbt (&req->dbt2, stop); 1773 if (stop ) sv_to_dbt (&req->dbt2, stop );
1703 req->uint1 = flags; 1774 req->uint1 = flags;
1704 REQ_SEND; 1775 REQ_SEND;
1705} 1776}
1706 1777
1707#endif 1778#endif
1717 req->uint1 = flags; 1788 req->uint1 = flags;
1718 REQ_SEND; 1789 REQ_SEND;
1719} 1790}
1720 1791
1721void 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
1722db_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)
1723 PREINIT: 1809 PREINIT:
1724 CALLBACK 1810 CALLBACK
1725 CODE: 1811 CODE:
1726{ 1812{
1727 dREQ (REQ_DB_SYNC, 1); 1813 dREQ (REQ_DB_UPGRADE, 1);
1728 req->db = db; 1814 req->db = db;
1729 req->buf1 = strdup (file); 1815 req->buf1 = strdup (file);
1730 req->uint1 = flags; 1816 req->uint1 = flags;
1731 REQ_SEND; 1817 REQ_SEND;
1732} 1818}
1836db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) 1922db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1837 PREINIT: 1923 PREINIT:
1838 CALLBACK 1924 CALLBACK
1839 CODE: 1925 CODE:
1840{ 1926{
1927 dREQ (REQ_TXN_COMMIT, 0);
1841 ptr_nuke (ST (0)); 1928 ptr_nuke (ST (0));
1842 dREQ (REQ_TXN_COMMIT, 0);
1843 req->txn = txn; 1929 req->txn = txn;
1844 req->uint1 = flags; 1930 req->uint1 = flags;
1845 REQ_SEND; 1931 REQ_SEND;
1846} 1932}
1847 1933
1849db_txn_abort (DB_TXN *txn, SV *callback = 0) 1935db_txn_abort (DB_TXN *txn, SV *callback = 0)
1850 PREINIT: 1936 PREINIT:
1851 CALLBACK 1937 CALLBACK
1852 CODE: 1938 CODE:
1853{ 1939{
1940 dREQ (REQ_TXN_ABORT, 0);
1854 ptr_nuke (ST (0)); 1941 ptr_nuke (ST (0));
1855 dREQ (REQ_TXN_ABORT, 0);
1856 req->txn = txn; 1942 req->txn = txn;
1857 REQ_SEND; 1943 REQ_SEND;
1858} 1944}
1859 1945
1860void 1946void
1861db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0) 1947db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1862 PREINIT: 1948 PREINIT:
1863 CALLBACK 1949 CALLBACK
1864 CODE: 1950 CODE:
1865{ 1951{
1952 dREQ (REQ_TXN_FINISH, 0);
1866 ptr_nuke (ST (0)); 1953 ptr_nuke (ST (0));
1867 dREQ (REQ_TXN_FINISH, 0);
1868 req->txn = txn; 1954 req->txn = txn;
1869 req->uint1 = flags; 1955 req->uint1 = flags;
1870 REQ_SEND; 1956 REQ_SEND;
1871} 1957}
1872 1958
1874db_c_close (DBC *dbc, SV *callback = 0) 1960db_c_close (DBC *dbc, SV *callback = 0)
1875 PREINIT: 1961 PREINIT:
1876 CALLBACK 1962 CALLBACK
1877 CODE: 1963 CODE:
1878{ 1964{
1965 dREQ (REQ_C_CLOSE, 0);
1879 ptr_nuke (ST (0)); 1966 ptr_nuke (ST (0));
1880 dREQ (REQ_C_CLOSE, 0);
1881 req->dbc = dbc; 1967 req->dbc = dbc;
1882 REQ_SEND; 1968 REQ_SEND;
1883} 1969}
1884 1970
1885void 1971void
1912db_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)
1913 PREINIT: 1999 PREINIT:
1914 CALLBACK 2000 CALLBACK
1915 CODE: 2001 CODE:
1916{ 2002{
1917 if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) 2003 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
1918 croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET"); 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");
1919 2009
2010 {
1920 dREQ (REQ_C_GET, 1); 2011 dREQ (REQ_C_GET, 1);
1921 req->dbc = dbc; 2012 req->dbc = dbc;
1922 req->uint1 = flags; 2013 req->uint1 = flags;
1923 if (flags & DB_OPFLAGS_MASK == DB_SET) 2014 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1924 sv_to_dbt (&req->dbt1, key); 2015 sv_to_dbt (&req->dbt1, key);
1925 else 2016 else
1926 { 2017 {
1927 if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) 2018 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
1928 sv_to_dbt (&req->dbt1, key); 2019 sv_to_dbt (&req->dbt1, key);
1929 else 2020 else
1930 req->dbt1.flags = DB_DBT_MALLOC; 2021 req->dbt1.flags = DB_DBT_MALLOC;
1931 2022
1932 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); 2023 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1933 } 2024 }
1934 2025
1935 if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH 2026 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1936 || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) 2027 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1937 sv_to_dbt (&req->dbt3, data); 2028 sv_to_dbt (&req->dbt3, data);
1938 else 2029 else
1939 req->dbt3.flags = DB_DBT_MALLOC; 2030 req->dbt3.flags = DB_DBT_MALLOC;
1940 2031
1941 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2032 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1942 REQ_SEND; 2033 REQ_SEND;
2034 }
1943} 2035}
1944 2036
1945void 2037void
1946db_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)
1947 PREINIT: 2039 PREINIT:
1948 CALLBACK 2040 CALLBACK
1949 CODE: 2041 CODE:
1950{ 2042{
1951 if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) 2043 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
1952 croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET"); 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");
1953 2049
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);
1979 REQ_SEND; 2076 REQ_SEND;
2077 }
1980} 2078}
1981 2079
1982void 2080void
1983db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) 2081db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0)
1984 PREINIT: 2082 PREINIT:
2012db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) 2110db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0)
2013 PREINIT: 2111 PREINIT:
2014 CALLBACK 2112 CALLBACK
2015 CODE: 2113 CODE:
2016{ 2114{
2115 dREQ (REQ_SEQ_CLOSE, 0);
2017 ptr_nuke (ST (0)); 2116 ptr_nuke (ST (0));
2018 dREQ (REQ_SEQ_CLOSE, 0);
2019 req->seq = seq; 2117 req->seq = seq;
2020 req->uint1 = flags; 2118 req->uint1 = flags;
2021 REQ_SEND; 2119 REQ_SEND;
2022} 2120}
2023 2121
2259 CODE: 2357 CODE:
2260 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); 2358 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache);
2261 OUTPUT: 2359 OUTPUT:
2262 RETVAL 2360 RETVAL
2263 2361
2362int set_pagesize (DB *db, U32 pagesize)
2363 CODE:
2364 RETVAL = db->set_pagesize (db, pagesize);
2365 OUTPUT:
2366 RETVAL
2367
2264int set_flags (DB *db, U32 flags) 2368int set_flags (DB *db, U32 flags)
2265 CODE: 2369 CODE:
2266 RETVAL = db->set_flags (db, flags); 2370 RETVAL = db->set_flags (db, flags);
2267 OUTPUT: 2371 OUTPUT:
2268 RETVAL 2372 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines