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 |
57 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
56 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
58 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
57 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
59 | #endif |
58 | #endif |
60 | |
59 | |
61 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
|
|
62 | typedef char *bdb_filename; |
60 | typedef char *bdb_filename; |
63 | |
61 | |
64 | static SV *prepare_cb; |
62 | static SV *prepare_cb; |
65 | |
63 | |
66 | #if DB_VERSION_MINOR >= 6 |
64 | #if DB_VERSION_MINOR >= 6 |
… | |
… | |
153 | |
151 | |
154 | enum { |
152 | enum { |
155 | REQ_QUIT, |
153 | REQ_QUIT, |
156 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
154 | 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, |
155 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
|
|
156 | REQ_ENV_LOG_ARCHIVE, |
158 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
157 | 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, |
158 | 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, |
159 | 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, |
160 | 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, |
161 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
163 | }; |
162 | }; |
… | |
… | |
248 | } |
247 | } |
249 | |
248 | |
250 | static volatile unsigned int nreqs, nready, npending; |
249 | static volatile unsigned int nreqs, nready, npending; |
251 | static volatile unsigned int max_idle = 4; |
250 | static volatile unsigned int max_idle = 4; |
252 | static volatile unsigned int max_outstanding = 0xffffffff; |
251 | static volatile unsigned int max_outstanding = 0xffffffff; |
253 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
252 | static s_epipe respipe; |
254 | |
253 | |
255 | static mutex_t reslock = X_MUTEX_INIT; |
254 | static mutex_t reslock = X_MUTEX_INIT; |
256 | static mutex_t reqlock = X_MUTEX_INIT; |
255 | static mutex_t reqlock = X_MUTEX_INIT; |
257 | static cond_t reqwait = X_COND_INIT; |
256 | static cond_t reqwait = X_COND_INIT; |
258 | |
257 | |
… | |
… | |
353 | abort (); |
352 | abort (); |
354 | } |
353 | } |
355 | |
354 | |
356 | static int poll_cb (void); |
355 | static int poll_cb (void); |
357 | static void req_free (bdb_req req); |
356 | static void req_free (bdb_req req); |
358 | static void req_cancel (bdb_req req); |
|
|
359 | |
357 | |
360 | static int req_invoke (bdb_req req) |
358 | static int req_invoke (bdb_req req) |
361 | { |
359 | { |
362 | switch (req->type) |
360 | switch (req->type) |
363 | { |
361 | { |
… | |
… | |
382 | |
380 | |
383 | av_push (av, newSVnv (req->key_range.less)); |
381 | av_push (av, newSVnv (req->key_range.less)); |
384 | av_push (av, newSVnv (req->key_range.equal)); |
382 | av_push (av, newSVnv (req->key_range.equal)); |
385 | av_push (av, newSVnv (req->key_range.greater)); |
383 | av_push (av, newSVnv (req->key_range.greater)); |
386 | |
384 | |
|
|
385 | av = (AV *)newRV_noinc ((SV *)av); |
|
|
386 | |
387 | SvREADONLY_off (req->sv1); |
387 | SvREADONLY_off (req->sv1); |
388 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
388 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
|
|
389 | SvREFCNT_dec (av); |
389 | SvREFCNT_dec (req->sv1); |
390 | SvREFCNT_dec (req->sv1); |
390 | } |
391 | } |
391 | break; |
392 | break; |
392 | |
393 | |
393 | #if DB_VERSION_MINOR >= 3 |
394 | #if DB_VERSION_MINOR >= 3 |
… | |
… | |
400 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
401 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
401 | |
402 | |
402 | SvREFCNT_dec (req->sv1); |
403 | SvREFCNT_dec (req->sv1); |
403 | break; |
404 | break; |
404 | #endif |
405 | #endif |
|
|
406 | |
|
|
407 | case REQ_ENV_LOG_ARCHIVE: |
|
|
408 | { |
|
|
409 | AV *av = newAV (); |
|
|
410 | char **listp = (char **)req->buf1; |
|
|
411 | |
|
|
412 | if (listp) |
|
|
413 | while (*listp) |
|
|
414 | av_push (av, newSVpv (*listp, 0)), ++listp; |
|
|
415 | |
|
|
416 | av = (AV *)newRV_noinc ((SV *)av); |
|
|
417 | |
|
|
418 | SvREADONLY_off (req->sv1); |
|
|
419 | sv_setsv_mg (req->sv1, (SV *)av); |
|
|
420 | SvREFCNT_dec (av); |
|
|
421 | SvREFCNT_dec (req->sv1); |
|
|
422 | } |
|
|
423 | break; |
405 | } |
424 | } |
406 | |
425 | |
407 | errno = req->result; |
426 | errno = req->result; |
408 | |
427 | |
409 | if (req->callback) |
428 | if (req->callback) |
… | |
… | |
439 | free (req->buf3); |
458 | free (req->buf3); |
440 | |
459 | |
441 | Safefree (req); |
460 | Safefree (req); |
442 | } |
461 | } |
443 | |
462 | |
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 | |
|
|
450 | static void |
463 | static void |
451 | create_respipe (void) |
464 | create_respipe (void) |
452 | { |
465 | { |
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)) |
466 | if (s_epipe_renew (&respipe)) |
465 | #endif |
467 | 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 | } |
468 | } |
490 | |
469 | |
491 | static void bdb_request (bdb_req req); |
470 | static void bdb_request (bdb_req req); |
492 | X_THREAD_PROC (bdb_proc); |
471 | X_THREAD_PROC (bdb_proc); |
493 | |
472 | |
… | |
… | |
629 | end_thread (); |
608 | end_thread (); |
630 | } |
609 | } |
631 | |
610 | |
632 | static void poll_wait (void) |
611 | static void poll_wait (void) |
633 | { |
612 | { |
634 | fd_set rfd; |
|
|
635 | |
|
|
636 | while (nreqs) |
613 | while (nreqs) |
637 | { |
614 | { |
638 | int size; |
615 | int size; |
639 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
616 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
640 | size = res_queue.size; |
617 | size = res_queue.size; |
… | |
… | |
643 | if (size) |
620 | if (size) |
644 | return; |
621 | return; |
645 | |
622 | |
646 | maybe_start_thread (); |
623 | maybe_start_thread (); |
647 | |
624 | |
648 | FD_ZERO (&rfd); |
625 | s_epipe_wait (&respipe); |
649 | FD_SET (respipe [0], &rfd); |
|
|
650 | |
|
|
651 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
652 | } |
626 | } |
653 | } |
627 | } |
654 | |
628 | |
655 | static int poll_cb (void) |
629 | static int poll_cb (void) |
656 | { |
630 | { |
… | |
… | |
676 | if (req) |
650 | if (req) |
677 | { |
651 | { |
678 | --npending; |
652 | --npending; |
679 | |
653 | |
680 | if (!res_queue.size) |
654 | if (!res_queue.size) |
681 | { |
|
|
682 | /* read any signals sent by the worker threads */ |
655 | /* read any signals sent by the worker threads */ |
683 | char buf [4]; |
656 | s_epipe_drain (&respipe); |
684 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
685 | ; |
|
|
686 | } |
|
|
687 | } |
657 | } |
688 | |
658 | |
689 | X_UNLOCK (reslock); |
659 | X_UNLOCK (reslock); |
690 | |
660 | |
691 | if (!req) |
661 | if (!req) |
… | |
… | |
773 | req->result = req->db->close (req->db, req->uint1); |
743 | req->result = req->db->close (req->db, req->uint1); |
774 | break; |
744 | break; |
775 | |
745 | |
776 | #if DB_VERSION_MINOR >= 4 |
746 | #if DB_VERSION_MINOR >= 4 |
777 | case REQ_DB_COMPACT: |
747 | case REQ_DB_COMPACT: |
778 | req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0); |
748 | 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; |
749 | break; |
780 | #endif |
750 | #endif |
781 | |
751 | |
782 | case REQ_DB_SYNC: |
752 | case REQ_DB_SYNC: |
783 | req->result = req->db->sync (req->db, req->uint1); |
753 | req->result = req->db->sync (req->db, req->uint1); |
|
|
754 | break; |
|
|
755 | |
|
|
756 | case REQ_DB_VERIFY: |
|
|
757 | req->result = req->db->verify (req->db, req->buf1, req->buf2, 0, req->uint1); |
784 | break; |
758 | break; |
785 | |
759 | |
786 | case REQ_DB_UPGRADE: |
760 | case REQ_DB_UPGRADE: |
787 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
761 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
788 | break; |
762 | break; |
… | |
… | |
875 | case REQ_SEQ_REMOVE: |
849 | case REQ_SEQ_REMOVE: |
876 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
850 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
877 | break; |
851 | break; |
878 | #endif |
852 | #endif |
879 | |
853 | |
|
|
854 | case REQ_ENV_LOG_ARCHIVE: |
|
|
855 | { |
|
|
856 | char **listp = 0; /* DB_ARCH_REMOVE does not touch listp, contrary to docs */ |
|
|
857 | req->result = req->env->log_archive (req->env, &listp, req->uint1); |
|
|
858 | req->buf1 = (char *)listp; |
|
|
859 | } |
|
|
860 | break; |
|
|
861 | |
880 | default: |
862 | default: |
881 | req->result = ENOSYS; |
863 | req->result = ENOSYS; |
882 | break; |
864 | break; |
883 | } |
865 | } |
884 | |
866 | |
… | |
… | |
895 | /* try to distribute timeouts somewhat evenly */ |
877 | /* try to distribute timeouts somewhat evenly */ |
896 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
878 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
897 | |
879 | |
898 | for (;;) |
880 | for (;;) |
899 | { |
881 | { |
900 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
882 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
901 | |
883 | |
902 | X_LOCK (reqlock); |
884 | X_LOCK (reqlock); |
903 | |
885 | |
904 | for (;;) |
886 | for (;;) |
905 | { |
887 | { |
… | |
… | |
950 | X_LOCK (reslock); |
932 | X_LOCK (reslock); |
951 | |
933 | |
952 | ++npending; |
934 | ++npending; |
953 | |
935 | |
954 | if (!reqq_push (&res_queue, req)) |
936 | if (!reqq_push (&res_queue, req)) |
955 | /* write a dummy byte to the pipe so fh becomes ready */ |
937 | s_epipe_signal (&respipe); |
956 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
|
|
957 | |
938 | |
958 | self->req = 0; |
939 | self->req = 0; |
959 | worker_clear (self); |
940 | worker_clear (self); |
960 | |
941 | |
961 | X_UNLOCK (reslock); |
942 | X_UNLOCK (reslock); |
… | |
… | |
1138 | } |
1119 | } |
1139 | |
1120 | |
1140 | return 0; |
1121 | return 0; |
1141 | } |
1122 | } |
1142 | |
1123 | |
|
|
1124 | /*****************************************************************************/ |
|
|
1125 | |
|
|
1126 | #if 0 |
|
|
1127 | static int |
|
|
1128 | bt_pfxc_compare (DB *db, const DBT *dbt1, const DBT *dbt2) |
|
|
1129 | { |
|
|
1130 | ssize_t size1 = dbt1->size; |
|
|
1131 | ssize_t size2 = dbt2->size; |
|
|
1132 | int res = memcmp ((void *)dbt1->data, (void *)dbt2->data, |
|
|
1133 | size1 <= size2 ? size1 : size2); |
|
|
1134 | |
|
|
1135 | if (res) |
|
|
1136 | return res; |
|
|
1137 | else if (size1 - size2) |
|
|
1138 | return size1 - size2; |
|
|
1139 | else |
|
|
1140 | return 0; |
|
|
1141 | } |
|
|
1142 | |
|
|
1143 | static size_t |
|
|
1144 | bt_pfxc_prefix_x (DB *db, const DBT *dbt1, const DBT *dbt2) |
|
|
1145 | { |
|
|
1146 | ssize_t size1 = dbt1->size; |
|
|
1147 | ssize_t size2 = dbt2->size; |
|
|
1148 | u_int8_t *p1 = (u_int8_t *)dbt1->data; |
|
|
1149 | u_int8_t *p2 = (u_int8_t *)dbt2->data; |
|
|
1150 | u_int8_t *pe = p1 + (size1 <= size2 ? size1 : size2); |
|
|
1151 | |
|
|
1152 | while (p1 < pe) |
|
|
1153 | if (*p1++ != *p2++) |
|
|
1154 | return p1 - (u_int8_t *)dbt1->data - 1; |
|
|
1155 | |
|
|
1156 | if (size1 < size2) return size1 + 1; |
|
|
1157 | if (size1 > size2) return size2 + 1; |
|
|
1158 | |
|
|
1159 | return size1; |
|
|
1160 | } |
|
|
1161 | #endif |
|
|
1162 | |
|
|
1163 | /*****************************************************************************/ |
|
|
1164 | |
1143 | /* stupid windoes defined CALLBACK as well */ |
1165 | /* stupid windows defines CALLBACK as well */ |
1144 | #undef CALLBACK |
1166 | #undef CALLBACK |
1145 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
1167 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
1146 | |
1168 | |
1147 | MODULE = BDB PACKAGE = BDB |
1169 | MODULE = BDB PACKAGE = BDB |
1148 | |
1170 | |
… | |
… | |
1201 | const_iv (NOSYNC) |
1223 | const_iv (NOSYNC) |
1202 | const_iv (CHKSUM) |
1224 | const_iv (CHKSUM) |
1203 | const_iv (ENCRYPT) |
1225 | const_iv (ENCRYPT) |
1204 | const_iv (DUP) |
1226 | const_iv (DUP) |
1205 | const_iv (DUPSORT) |
1227 | const_iv (DUPSORT) |
1206 | const_iv (RECNUM) |
1228 | //const_iv (RECNUM) |
1207 | const_iv (RENUMBER) |
1229 | const_iv (RENUMBER) |
1208 | const_iv (REVSPLITOFF) |
1230 | const_iv (REVSPLITOFF) |
1209 | const_iv (CONSUME) |
1231 | const_iv (CONSUME) |
1210 | const_iv (CONSUME_WAIT) |
1232 | const_iv (CONSUME_WAIT) |
1211 | const_iv (GET_BOTH) |
1233 | const_iv (GET_BOTH) |
… | |
… | |
1283 | const_iv (REP_UNAVAIL) |
1305 | const_iv (REP_UNAVAIL) |
1284 | const_iv (RUNRECOVERY) |
1306 | const_iv (RUNRECOVERY) |
1285 | const_iv (SECONDARY_BAD) |
1307 | const_iv (SECONDARY_BAD) |
1286 | const_iv (VERIFY_BAD) |
1308 | const_iv (VERIFY_BAD) |
1287 | |
1309 | |
|
|
1310 | const_iv (SALVAGE) |
|
|
1311 | const_iv (AGGRESSIVE) |
|
|
1312 | const_iv (PRINTABLE) |
|
|
1313 | const_iv (NOORDERCHK) |
|
|
1314 | const_iv (ORDERCHKONLY) |
|
|
1315 | |
|
|
1316 | const_iv (ARCH_ABS) |
|
|
1317 | const_iv (ARCH_DATA) |
|
|
1318 | const_iv (ARCH_LOG) |
|
|
1319 | const_iv (ARCH_REMOVE) |
|
|
1320 | |
1288 | const_iv (VERB_DEADLOCK) |
1321 | const_iv (VERB_DEADLOCK) |
1289 | const_iv (VERB_RECOVERY) |
1322 | const_iv (VERB_RECOVERY) |
1290 | const_iv (VERB_REPLICATION) |
1323 | const_iv (VERB_REPLICATION) |
1291 | const_iv (VERB_WAITSFOR) |
1324 | const_iv (VERB_WAITSFOR) |
1292 | |
1325 | |
… | |
… | |
1325 | const_iv (PRIORITY_VERY_LOW) |
1358 | const_iv (PRIORITY_VERY_LOW) |
1326 | const_iv (PRIORITY_LOW) |
1359 | const_iv (PRIORITY_LOW) |
1327 | const_iv (PRIORITY_DEFAULT) |
1360 | const_iv (PRIORITY_DEFAULT) |
1328 | const_iv (PRIORITY_HIGH) |
1361 | const_iv (PRIORITY_HIGH) |
1329 | const_iv (PRIORITY_VERY_HIGH) |
1362 | const_iv (PRIORITY_VERY_HIGH) |
|
|
1363 | const_iv (IGNORE_LEASE) |
1330 | #endif |
1364 | #endif |
1331 | #if DB_VERSION_MINOR >= 7 |
1365 | #if DB_VERSION_MINOR >= 7 |
|
|
1366 | //const_iv (MULTIPLE_KEY) |
1332 | const_iv (LOG_DIRECT) |
1367 | const_iv (LOG_DIRECT) |
1333 | const_iv (LOG_DSYNC) |
1368 | const_iv (LOG_DSYNC) |
1334 | const_iv (LOG_AUTO_REMOVE) |
1369 | const_iv (LOG_AUTO_REMOVE) |
1335 | const_iv (LOG_IN_MEMORY) |
1370 | const_iv (LOG_IN_MEMORY) |
1336 | const_iv (LOG_ZERO) |
1371 | const_iv (LOG_ZERO) |
… | |
… | |
1442 | |
1477 | |
1443 | int |
1478 | int |
1444 | poll_fileno () |
1479 | poll_fileno () |
1445 | PROTOTYPE: |
1480 | PROTOTYPE: |
1446 | CODE: |
1481 | CODE: |
1447 | RETVAL = respipe [0]; |
1482 | RETVAL = s_epipe_fd (&respipe); |
1448 | OUTPUT: |
1483 | OUTPUT: |
1449 | RETVAL |
1484 | RETVAL |
1450 | |
1485 | |
1451 | int |
1486 | int |
1452 | poll_cb (...) |
1487 | poll_cb (...) |
… | |
… | |
1553 | db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) |
1588 | db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) |
1554 | PREINIT: |
1589 | PREINIT: |
1555 | CALLBACK |
1590 | CALLBACK |
1556 | CODE: |
1591 | CODE: |
1557 | { |
1592 | { |
|
|
1593 | dREQ (REQ_ENV_CLOSE, 0); |
1558 | ptr_nuke (ST (0)); |
1594 | ptr_nuke (ST (0)); |
1559 | dREQ (REQ_ENV_CLOSE, 0); |
|
|
1560 | req->env = env; |
1595 | req->env = env; |
1561 | req->uint1 = flags; |
1596 | req->uint1 = flags; |
1562 | REQ_SEND; |
1597 | REQ_SEND; |
1563 | } |
1598 | } |
1564 | |
1599 | |
… | |
… | |
1636 | dREQ (REQ_ENV_DBRENAME, 2); |
1671 | dREQ (REQ_ENV_DBRENAME, 2); |
1637 | req->env = env; |
1672 | req->env = env; |
1638 | req->buf1 = strdup_ornull (file); |
1673 | req->buf1 = strdup_ornull (file); |
1639 | req->buf2 = strdup_ornull (database); |
1674 | req->buf2 = strdup_ornull (database); |
1640 | req->buf3 = strdup_ornull (newname); |
1675 | req->buf3 = strdup_ornull (newname); |
|
|
1676 | req->uint1 = flags; |
|
|
1677 | REQ_SEND; |
|
|
1678 | } |
|
|
1679 | |
|
|
1680 | void |
|
|
1681 | db_env_log_archive (DB_ENV *env, SV_mutable *listp, U32 flags = 0, SV *callback = 0) |
|
|
1682 | PREINIT: |
|
|
1683 | CALLBACK |
|
|
1684 | CODE: |
|
|
1685 | { |
|
|
1686 | dREQ (REQ_ENV_LOG_ARCHIVE, 1); |
|
|
1687 | req->sv1 = SvREFCNT_inc (listp); |
|
|
1688 | req->env = env; |
1641 | req->uint1 = flags; |
1689 | req->uint1 = flags; |
1642 | REQ_SEND; |
1690 | REQ_SEND; |
1643 | } |
1691 | } |
1644 | |
1692 | |
1645 | DB * |
1693 | DB * |
… | |
… | |
1677 | db_close (DB *db, U32 flags = 0, SV *callback = 0) |
1725 | db_close (DB *db, U32 flags = 0, SV *callback = 0) |
1678 | PREINIT: |
1726 | PREINIT: |
1679 | CALLBACK |
1727 | CALLBACK |
1680 | CODE: |
1728 | CODE: |
1681 | { |
1729 | { |
|
|
1730 | dREQ (REQ_DB_CLOSE, 0); |
1682 | ptr_nuke (ST (0)); |
1731 | ptr_nuke (ST (0)); |
1683 | dREQ (REQ_DB_CLOSE, 0); |
|
|
1684 | req->db = db; |
1732 | req->db = db; |
1685 | req->uint1 = flags; |
1733 | req->uint1 = flags; |
1686 | req->sv1 = (SV *)db->app_private; |
1734 | req->sv1 = (SV *)db->app_private; |
1687 | REQ_SEND; |
1735 | REQ_SEND; |
1688 | } |
1736 | } |
… | |
… | |
1696 | CODE: |
1744 | CODE: |
1697 | { |
1745 | { |
1698 | dREQ (REQ_DB_COMPACT, 2); |
1746 | dREQ (REQ_DB_COMPACT, 2); |
1699 | req->db = db; |
1747 | req->db = db; |
1700 | req->txn = txn; |
1748 | req->txn = txn; |
1701 | sv_to_dbt (&req->dbt1, start); |
1749 | if (start) sv_to_dbt (&req->dbt1, start); |
1702 | sv_to_dbt (&req->dbt2, stop); |
1750 | if (stop ) sv_to_dbt (&req->dbt2, stop ); |
1703 | req->uint1 = flags; |
1751 | req->uint1 = flags; |
1704 | REQ_SEND; |
1752 | REQ_SEND; |
1705 | } |
1753 | } |
1706 | |
1754 | |
1707 | #endif |
1755 | #endif |
… | |
… | |
1717 | req->uint1 = flags; |
1765 | req->uint1 = flags; |
1718 | REQ_SEND; |
1766 | REQ_SEND; |
1719 | } |
1767 | } |
1720 | |
1768 | |
1721 | void |
1769 | void |
|
|
1770 | db_verify (DB *db, bdb_filename file, bdb_filename database = 0, SV *dummy = 0, U32 flags = 0, SV *callback = 0) |
|
|
1771 | PREINIT: |
|
|
1772 | CALLBACK |
|
|
1773 | CODE: |
|
|
1774 | { |
|
|
1775 | dREQ (REQ_DB_VERIFY, 1); |
|
|
1776 | ptr_nuke (ST (0)); /* verify destroys the database handle, hopefully it is freed as well */ |
|
|
1777 | req->db = db; |
|
|
1778 | req->buf1 = strdup (file); |
|
|
1779 | req->buf2 = strdup_ornull (database); |
|
|
1780 | req->uint1 = flags; |
|
|
1781 | REQ_SEND; |
|
|
1782 | } |
|
|
1783 | |
|
|
1784 | void |
1722 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) |
1785 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) |
1723 | PREINIT: |
1786 | PREINIT: |
1724 | CALLBACK |
1787 | CALLBACK |
1725 | CODE: |
1788 | CODE: |
1726 | { |
1789 | { |
1727 | dREQ (REQ_DB_SYNC, 1); |
1790 | dREQ (REQ_DB_UPGRADE, 1); |
1728 | req->db = db; |
1791 | req->db = db; |
1729 | req->buf1 = strdup (file); |
1792 | req->buf1 = strdup (file); |
1730 | req->uint1 = flags; |
1793 | req->uint1 = flags; |
1731 | REQ_SEND; |
1794 | REQ_SEND; |
1732 | } |
1795 | } |
… | |
… | |
1836 | db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
1899 | db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
1837 | PREINIT: |
1900 | PREINIT: |
1838 | CALLBACK |
1901 | CALLBACK |
1839 | CODE: |
1902 | CODE: |
1840 | { |
1903 | { |
|
|
1904 | dREQ (REQ_TXN_COMMIT, 0); |
1841 | ptr_nuke (ST (0)); |
1905 | ptr_nuke (ST (0)); |
1842 | dREQ (REQ_TXN_COMMIT, 0); |
|
|
1843 | req->txn = txn; |
1906 | req->txn = txn; |
1844 | req->uint1 = flags; |
1907 | req->uint1 = flags; |
1845 | REQ_SEND; |
1908 | REQ_SEND; |
1846 | } |
1909 | } |
1847 | |
1910 | |
… | |
… | |
1849 | db_txn_abort (DB_TXN *txn, SV *callback = 0) |
1912 | db_txn_abort (DB_TXN *txn, SV *callback = 0) |
1850 | PREINIT: |
1913 | PREINIT: |
1851 | CALLBACK |
1914 | CALLBACK |
1852 | CODE: |
1915 | CODE: |
1853 | { |
1916 | { |
|
|
1917 | dREQ (REQ_TXN_ABORT, 0); |
1854 | ptr_nuke (ST (0)); |
1918 | ptr_nuke (ST (0)); |
1855 | dREQ (REQ_TXN_ABORT, 0); |
|
|
1856 | req->txn = txn; |
1919 | req->txn = txn; |
1857 | REQ_SEND; |
1920 | REQ_SEND; |
1858 | } |
1921 | } |
1859 | |
1922 | |
1860 | void |
1923 | void |
1861 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
1924 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
1862 | PREINIT: |
1925 | PREINIT: |
1863 | CALLBACK |
1926 | CALLBACK |
1864 | CODE: |
1927 | CODE: |
1865 | { |
1928 | { |
|
|
1929 | dREQ (REQ_TXN_FINISH, 0); |
1866 | ptr_nuke (ST (0)); |
1930 | ptr_nuke (ST (0)); |
1867 | dREQ (REQ_TXN_FINISH, 0); |
|
|
1868 | req->txn = txn; |
1931 | req->txn = txn; |
1869 | req->uint1 = flags; |
1932 | req->uint1 = flags; |
1870 | REQ_SEND; |
1933 | REQ_SEND; |
1871 | } |
1934 | } |
1872 | |
1935 | |
… | |
… | |
1874 | db_c_close (DBC *dbc, SV *callback = 0) |
1937 | db_c_close (DBC *dbc, SV *callback = 0) |
1875 | PREINIT: |
1938 | PREINIT: |
1876 | CALLBACK |
1939 | CALLBACK |
1877 | CODE: |
1940 | CODE: |
1878 | { |
1941 | { |
|
|
1942 | dREQ (REQ_C_CLOSE, 0); |
1879 | ptr_nuke (ST (0)); |
1943 | ptr_nuke (ST (0)); |
1880 | dREQ (REQ_C_CLOSE, 0); |
|
|
1881 | req->dbc = dbc; |
1944 | req->dbc = dbc; |
1882 | REQ_SEND; |
1945 | REQ_SEND; |
1883 | } |
1946 | } |
1884 | |
1947 | |
1885 | void |
1948 | void |
… | |
… | |
1912 | db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1975 | db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1913 | PREINIT: |
1976 | PREINIT: |
1914 | CALLBACK |
1977 | CALLBACK |
1915 | CODE: |
1978 | CODE: |
1916 | { |
1979 | { |
1917 | if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) |
1980 | 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"); |
1981 | croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET"); |
|
|
1982 | if (SvPOKp (key) && !sv_utf8_downgrade (key, 1)) |
|
|
1983 | croak ("argument \"%s\" must be byte/octet-encoded in %s", |
|
|
1984 | "key", |
|
|
1985 | "BDB::db_c_get"); |
1919 | |
1986 | |
|
|
1987 | { |
1920 | dREQ (REQ_C_GET, 1); |
1988 | dREQ (REQ_C_GET, 1); |
1921 | req->dbc = dbc; |
1989 | req->dbc = dbc; |
1922 | req->uint1 = flags; |
1990 | req->uint1 = flags; |
1923 | if (flags & DB_OPFLAGS_MASK == DB_SET) |
1991 | if ((flags & DB_OPFLAGS_MASK) == DB_SET) |
1924 | sv_to_dbt (&req->dbt1, key); |
1992 | sv_to_dbt (&req->dbt1, key); |
1925 | else |
1993 | else |
1926 | { |
1994 | { |
1927 | if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) |
1995 | if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE) |
1928 | sv_to_dbt (&req->dbt1, key); |
1996 | sv_to_dbt (&req->dbt1, key); |
1929 | else |
1997 | else |
1930 | req->dbt1.flags = DB_DBT_MALLOC; |
1998 | req->dbt1.flags = DB_DBT_MALLOC; |
1931 | |
1999 | |
1932 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
2000 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
1933 | } |
2001 | } |
1934 | |
2002 | |
1935 | if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH |
2003 | if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH |
1936 | || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) |
2004 | || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE) |
1937 | sv_to_dbt (&req->dbt3, data); |
2005 | sv_to_dbt (&req->dbt3, data); |
1938 | else |
2006 | else |
1939 | req->dbt3.flags = DB_DBT_MALLOC; |
2007 | req->dbt3.flags = DB_DBT_MALLOC; |
1940 | |
2008 | |
1941 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
2009 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1942 | REQ_SEND; |
2010 | REQ_SEND; |
|
|
2011 | } |
1943 | } |
2012 | } |
1944 | |
2013 | |
1945 | void |
2014 | void |
1946 | db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
2015 | db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1947 | PREINIT: |
2016 | PREINIT: |
1948 | CALLBACK |
2017 | CALLBACK |
1949 | CODE: |
2018 | CODE: |
1950 | { |
2019 | { |
1951 | if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) |
2020 | 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"); |
2021 | croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET"); |
|
|
2022 | if (SvPOKp (key) && !sv_utf8_downgrade (key, 1)) |
|
|
2023 | croak ("argument \"%s\" must be byte/octet-encoded in %s", |
|
|
2024 | "key", |
|
|
2025 | "BDB::db_c_pget"); |
1953 | |
2026 | |
|
|
2027 | { |
1954 | dREQ (REQ_C_PGET, 1); |
2028 | dREQ (REQ_C_PGET, 1); |
1955 | req->dbc = dbc; |
2029 | req->dbc = dbc; |
1956 | req->uint1 = flags; |
2030 | req->uint1 = flags; |
1957 | if (flags & DB_OPFLAGS_MASK == DB_SET) |
2031 | if ((flags & DB_OPFLAGS_MASK) == DB_SET) |
1958 | sv_to_dbt (&req->dbt1, key); |
2032 | sv_to_dbt (&req->dbt1, key); |
1959 | else |
2033 | else |
1960 | { |
2034 | { |
1961 | if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) |
2035 | if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE) |
1962 | sv_to_dbt (&req->dbt1, key); |
2036 | sv_to_dbt (&req->dbt1, key); |
1963 | else |
2037 | else |
1964 | req->dbt1.flags = DB_DBT_MALLOC; |
2038 | req->dbt1.flags = DB_DBT_MALLOC; |
1965 | |
2039 | |
1966 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
2040 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
1967 | } |
2041 | } |
1968 | |
2042 | |
1969 | req->dbt2.flags = DB_DBT_MALLOC; |
2043 | req->dbt2.flags = DB_DBT_MALLOC; |
1970 | req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); |
2044 | req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); |
1971 | |
2045 | |
1972 | if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH |
2046 | if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH |
1973 | || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) |
2047 | || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE) |
1974 | sv_to_dbt (&req->dbt3, data); |
2048 | sv_to_dbt (&req->dbt3, data); |
1975 | else |
2049 | else |
1976 | req->dbt3.flags = DB_DBT_MALLOC; |
2050 | req->dbt3.flags = DB_DBT_MALLOC; |
1977 | |
2051 | |
1978 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
2052 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1979 | REQ_SEND; |
2053 | REQ_SEND; |
|
|
2054 | } |
1980 | } |
2055 | } |
1981 | |
2056 | |
1982 | void |
2057 | void |
1983 | db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) |
2058 | db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) |
1984 | PREINIT: |
2059 | PREINIT: |
… | |
… | |
2012 | db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) |
2087 | db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) |
2013 | PREINIT: |
2088 | PREINIT: |
2014 | CALLBACK |
2089 | CALLBACK |
2015 | CODE: |
2090 | CODE: |
2016 | { |
2091 | { |
|
|
2092 | dREQ (REQ_SEQ_CLOSE, 0); |
2017 | ptr_nuke (ST (0)); |
2093 | ptr_nuke (ST (0)); |
2018 | dREQ (REQ_SEQ_CLOSE, 0); |
|
|
2019 | req->seq = seq; |
2094 | req->seq = seq; |
2020 | req->uint1 = flags; |
2095 | req->uint1 = flags; |
2021 | REQ_SEND; |
2096 | REQ_SEND; |
2022 | } |
2097 | } |
2023 | |
2098 | |
… | |
… | |
2259 | CODE: |
2334 | CODE: |
2260 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
2335 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
2261 | OUTPUT: |
2336 | OUTPUT: |
2262 | RETVAL |
2337 | RETVAL |
2263 | |
2338 | |
|
|
2339 | int set_pagesize (DB *db, U32 pagesize) |
|
|
2340 | CODE: |
|
|
2341 | RETVAL = db->set_pagesize (db, pagesize); |
|
|
2342 | OUTPUT: |
|
|
2343 | RETVAL |
|
|
2344 | |
2264 | int set_flags (DB *db, U32 flags) |
2345 | int set_flags (DB *db, U32 flags) |
2265 | CODE: |
2346 | CODE: |
2266 | RETVAL = db->set_flags (db, flags); |
2347 | RETVAL = db->set_flags (db, flags); |
2267 | OUTPUT: |
2348 | OUTPUT: |
2268 | RETVAL |
2349 | RETVAL |