… | |
… | |
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 |
… | |
… | |
29 | # include <unistd.h> |
31 | # include <unistd.h> |
30 | #endif |
32 | #endif |
31 | |
33 | |
32 | #include <db.h> |
34 | #include <db.h> |
33 | |
35 | |
34 | #if DB_VERSION_MAJOR != 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 3) |
36 | #define DBVER DB_VERSION_MAJOR * 100 + DB_VERSION_MINOR |
|
|
37 | |
|
|
38 | #if DBVER < 403 |
35 | # error you need Berkeley DB 4.3 or a newer 4.x version installed |
39 | # error you need Berkeley DB 4.3 or a newer version installed |
36 | #endif |
40 | #endif |
37 | |
41 | |
38 | /* number of seconds after which idle threads exit */ |
42 | /* number of seconds after which idle threads exit */ |
39 | #define IDLE_TIMEOUT 10 |
43 | #define IDLE_TIMEOUT 10 |
40 | |
44 | |
… | |
… | |
48 | typedef DB_ENV DB_ENV_ornuked; |
52 | typedef DB_ENV DB_ENV_ornuked; |
49 | typedef DB_TXN DB_TXN_ornuked; |
53 | typedef DB_TXN DB_TXN_ornuked; |
50 | typedef DBC DBC_ornuked; |
54 | typedef DBC DBC_ornuked; |
51 | typedef DB DB_ornuked; |
55 | typedef DB DB_ornuked; |
52 | |
56 | |
53 | #if DB_VERSION_MINOR >= 3 |
57 | #if DBVER >= 403 |
54 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
58 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
55 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
59 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
56 | #endif |
60 | #endif |
57 | |
61 | |
58 | typedef char *bdb_filename; |
62 | typedef char *bdb_filename; |
59 | |
63 | |
60 | static SV *prepare_cb; |
64 | static SV *prepare_cb; |
61 | |
65 | |
62 | #if DB_VERSION_MINOR >= 6 |
66 | static HV |
|
|
67 | *bdb_stash, |
|
|
68 | *bdb_env_stash, |
|
|
69 | *bdb_txn_stash, |
|
|
70 | *bdb_cursor_stash, |
|
|
71 | *bdb_db_stash, |
|
|
72 | *bdb_sequence_stash; |
|
|
73 | |
|
|
74 | #if DBVER >= 406 |
63 | # define c_close close |
75 | # define c_close close |
64 | # define c_count count |
76 | # define c_count count |
65 | # define c_del del |
77 | # define c_del del |
66 | # define c_dup dup |
78 | # define c_dup dup |
67 | # define c_get get |
79 | # define c_get get |
… | |
… | |
149 | |
161 | |
150 | enum { |
162 | enum { |
151 | REQ_QUIT, |
163 | REQ_QUIT, |
152 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
164 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
153 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
165 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
|
|
166 | REQ_ENV_LOG_ARCHIVE, REQ_ENV_LSN_RESET, |
154 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
167 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_VERIFY, REQ_DB_UPGRADE, |
155 | REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
168 | REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
156 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
169 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
157 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
170 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
158 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
171 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
159 | }; |
172 | }; |
… | |
… | |
175 | char *buf1, *buf2, *buf3; |
188 | char *buf1, *buf2, *buf3; |
176 | SV *sv1, *sv2, *sv3; |
189 | SV *sv1, *sv2, *sv3; |
177 | |
190 | |
178 | DBT dbt1, dbt2, dbt3; |
191 | DBT dbt1, dbt2, dbt3; |
179 | DB_KEY_RANGE key_range; |
192 | DB_KEY_RANGE key_range; |
180 | #if DB_VERSION_MINOR >= 3 |
193 | #if DBVER >= 403 |
181 | DB_SEQUENCE *seq; |
194 | DB_SEQUENCE *seq; |
182 | db_seq_t seq_t; |
195 | db_seq_t seq_t; |
183 | #endif |
196 | #endif |
184 | |
197 | |
185 | SV *rsv1, *rsv2; // keep some request objects alive |
198 | SV *rsv1, *rsv2; // keep some request objects alive |
… | |
… | |
213 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
226 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
214 | |
227 | |
215 | static unsigned int started, idle, wanted; |
228 | static unsigned int started, idle, wanted; |
216 | |
229 | |
217 | /* worker threads management */ |
230 | /* worker threads management */ |
218 | static mutex_t wrklock = X_MUTEX_INIT; |
231 | static xmutex_t wrklock = X_MUTEX_INIT; |
219 | |
232 | |
220 | typedef struct worker { |
233 | typedef struct worker { |
221 | /* locked by wrklock */ |
234 | /* locked by wrklock */ |
222 | struct worker *prev, *next; |
235 | struct worker *prev, *next; |
223 | |
236 | |
224 | thread_t tid; |
237 | xthread_t tid; |
225 | |
238 | |
226 | /* locked by reslock, reqlock or wrklock */ |
239 | /* locked by reslock, reqlock or wrklock */ |
227 | bdb_req req; /* currently processed request */ |
240 | bdb_req req; /* currently processed request */ |
228 | void *dbuf; |
241 | void *dbuf; |
229 | DIR *dirp; |
242 | DIR *dirp; |
… | |
… | |
244 | } |
257 | } |
245 | |
258 | |
246 | static volatile unsigned int nreqs, nready, npending; |
259 | static volatile unsigned int nreqs, nready, npending; |
247 | static volatile unsigned int max_idle = 4; |
260 | static volatile unsigned int max_idle = 4; |
248 | static volatile unsigned int max_outstanding = 0xffffffff; |
261 | static volatile unsigned int max_outstanding = 0xffffffff; |
249 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
262 | static s_epipe respipe; |
250 | |
263 | |
251 | static mutex_t reslock = X_MUTEX_INIT; |
264 | static xmutex_t reslock = X_MUTEX_INIT; |
252 | static mutex_t reqlock = X_MUTEX_INIT; |
265 | static xmutex_t reqlock = X_MUTEX_INIT; |
253 | static cond_t reqwait = X_COND_INIT; |
266 | static xcond_t reqwait = X_COND_INIT; |
254 | |
267 | |
255 | #if WORDACCESS_UNSAFE |
268 | #if WORDACCESS_UNSAFE |
256 | |
269 | |
257 | static unsigned int get_nready (void) |
270 | static unsigned int get_nready (void) |
258 | { |
271 | { |
… | |
… | |
377 | |
390 | |
378 | av_push (av, newSVnv (req->key_range.less)); |
391 | av_push (av, newSVnv (req->key_range.less)); |
379 | av_push (av, newSVnv (req->key_range.equal)); |
392 | av_push (av, newSVnv (req->key_range.equal)); |
380 | av_push (av, newSVnv (req->key_range.greater)); |
393 | av_push (av, newSVnv (req->key_range.greater)); |
381 | |
394 | |
|
|
395 | av = (AV *)newRV_noinc ((SV *)av); |
|
|
396 | |
382 | SvREADONLY_off (req->sv1); |
397 | SvREADONLY_off (req->sv1); |
383 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
398 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
|
|
399 | SvREFCNT_dec (av); |
384 | SvREFCNT_dec (req->sv1); |
400 | SvREFCNT_dec (req->sv1); |
385 | } |
401 | } |
386 | break; |
402 | break; |
387 | |
403 | |
388 | #if DB_VERSION_MINOR >= 3 |
404 | #if DBVER >= 403 |
389 | case REQ_SEQ_GET: |
405 | case REQ_SEQ_GET: |
390 | SvREADONLY_off (req->sv1); |
406 | SvREADONLY_off (req->sv1); |
391 | |
407 | |
392 | if (sizeof (IV) > 4) |
408 | if (sizeof (IV) > 4) |
393 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
409 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
… | |
… | |
395 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
411 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
396 | |
412 | |
397 | SvREFCNT_dec (req->sv1); |
413 | SvREFCNT_dec (req->sv1); |
398 | break; |
414 | break; |
399 | #endif |
415 | #endif |
|
|
416 | |
|
|
417 | case REQ_ENV_LOG_ARCHIVE: |
|
|
418 | { |
|
|
419 | AV *av = newAV (); |
|
|
420 | char **listp = (char **)req->buf1; |
|
|
421 | |
|
|
422 | if (listp) |
|
|
423 | while (*listp) |
|
|
424 | av_push (av, newSVpv (*listp, 0)), ++listp; |
|
|
425 | |
|
|
426 | av = (AV *)newRV_noinc ((SV *)av); |
|
|
427 | |
|
|
428 | SvREADONLY_off (req->sv1); |
|
|
429 | sv_setsv_mg (req->sv1, (SV *)av); |
|
|
430 | SvREFCNT_dec (av); |
|
|
431 | SvREFCNT_dec (req->sv1); |
|
|
432 | } |
|
|
433 | break; |
400 | } |
434 | } |
401 | |
435 | |
402 | errno = req->result; |
436 | errno = req->result; |
403 | |
437 | |
404 | if (req->callback) |
438 | if (req->callback) |
… | |
… | |
434 | free (req->buf3); |
468 | free (req->buf3); |
435 | |
469 | |
436 | Safefree (req); |
470 | Safefree (req); |
437 | } |
471 | } |
438 | |
472 | |
439 | #ifdef USE_SOCKETS_AS_HANDLES |
|
|
440 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
|
|
441 | #else |
|
|
442 | # define TO_SOCKET(x) (x) |
|
|
443 | #endif |
|
|
444 | |
|
|
445 | static void |
473 | static void |
446 | create_respipe (void) |
474 | create_respipe (void) |
447 | { |
475 | { |
448 | #ifdef _WIN32 |
|
|
449 | int arg; /* argg */ |
|
|
450 | #endif |
|
|
451 | int old_readfd = respipe [0]; |
|
|
452 | |
|
|
453 | if (respipe [1] >= 0) |
|
|
454 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
455 | |
|
|
456 | #ifdef _WIN32 |
|
|
457 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
|
|
458 | #else |
|
|
459 | if (pipe (respipe)) |
476 | if (s_epipe_renew (&respipe)) |
460 | #endif |
477 | croak ("BDB: unable to create event pipe"); |
461 | croak ("unable to initialize result pipe"); |
|
|
462 | |
|
|
463 | if (old_readfd >= 0) |
|
|
464 | { |
|
|
465 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
466 | croak ("unable to initialize result pipe(2)"); |
|
|
467 | |
|
|
468 | respipe_close (respipe [0]); |
|
|
469 | respipe [0] = old_readfd; |
|
|
470 | } |
|
|
471 | |
|
|
472 | #ifdef _WIN32 |
|
|
473 | arg = 1; |
|
|
474 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
475 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
476 | #else |
|
|
477 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
478 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
479 | #endif |
|
|
480 | croak ("unable to initialize result pipe(3)"); |
|
|
481 | |
|
|
482 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
|
|
483 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
|
|
484 | } |
478 | } |
485 | |
479 | |
486 | static void bdb_request (bdb_req req); |
480 | static void bdb_request (bdb_req req); |
487 | X_THREAD_PROC (bdb_proc); |
481 | X_THREAD_PROC (bdb_proc); |
488 | |
482 | |
… | |
… | |
492 | |
486 | |
493 | if (!wrk) |
487 | if (!wrk) |
494 | croak ("unable to allocate worker thread data"); |
488 | croak ("unable to allocate worker thread data"); |
495 | |
489 | |
496 | X_LOCK (wrklock); |
490 | X_LOCK (wrklock); |
497 | if (thread_create (&wrk->tid, bdb_proc, (void *)wrk)) |
491 | if (xthread_create (&wrk->tid, bdb_proc, (void *)wrk)) |
498 | { |
492 | { |
499 | wrk->prev = &wrk_first; |
493 | wrk->prev = &wrk_first; |
500 | wrk->next = wrk_first.next; |
494 | wrk->next = wrk_first.next; |
501 | wrk_first.next->prev = wrk; |
495 | wrk_first.next->prev = wrk; |
502 | wrk_first.next = wrk; |
496 | wrk_first.next = wrk; |
… | |
… | |
624 | end_thread (); |
618 | end_thread (); |
625 | } |
619 | } |
626 | |
620 | |
627 | static void poll_wait (void) |
621 | static void poll_wait (void) |
628 | { |
622 | { |
629 | fd_set rfd; |
|
|
630 | |
|
|
631 | while (nreqs) |
623 | while (nreqs) |
632 | { |
624 | { |
633 | int size; |
625 | int size; |
634 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
626 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
635 | size = res_queue.size; |
627 | size = res_queue.size; |
… | |
… | |
638 | if (size) |
630 | if (size) |
639 | return; |
631 | return; |
640 | |
632 | |
641 | maybe_start_thread (); |
633 | maybe_start_thread (); |
642 | |
634 | |
643 | FD_ZERO (&rfd); |
635 | s_epipe_wait (&respipe); |
644 | FD_SET (respipe [0], &rfd); |
|
|
645 | |
|
|
646 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
647 | } |
636 | } |
648 | } |
637 | } |
649 | |
638 | |
650 | static int poll_cb (void) |
639 | static int poll_cb (void) |
651 | { |
640 | { |
… | |
… | |
671 | if (req) |
660 | if (req) |
672 | { |
661 | { |
673 | --npending; |
662 | --npending; |
674 | |
663 | |
675 | if (!res_queue.size) |
664 | if (!res_queue.size) |
676 | { |
|
|
677 | /* read any signals sent by the worker threads */ |
665 | /* read any signals sent by the worker threads */ |
678 | char buf [4]; |
666 | s_epipe_drain (&respipe); |
679 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
680 | ; |
|
|
681 | } |
|
|
682 | } |
667 | } |
683 | |
668 | |
684 | X_UNLOCK (reslock); |
669 | X_UNLOCK (reslock); |
685 | |
670 | |
686 | if (!req) |
671 | if (!req) |
… | |
… | |
766 | |
751 | |
767 | case REQ_DB_CLOSE: |
752 | case REQ_DB_CLOSE: |
768 | req->result = req->db->close (req->db, req->uint1); |
753 | req->result = req->db->close (req->db, req->uint1); |
769 | break; |
754 | break; |
770 | |
755 | |
771 | #if DB_VERSION_MINOR >= 4 |
756 | #if DBVER >= 404 |
772 | case REQ_DB_COMPACT: |
757 | case REQ_DB_COMPACT: |
773 | req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0); |
758 | req->result = req->db->compact (req->db, req->txn, req->dbt1.data ? &req->dbt1 : 0, req->dbt2.data ? &req->dbt2 : 0, 0, req->uint1, 0); |
774 | break; |
759 | break; |
775 | #endif |
760 | #endif |
776 | |
761 | |
777 | case REQ_DB_SYNC: |
762 | case REQ_DB_SYNC: |
778 | req->result = req->db->sync (req->db, req->uint1); |
763 | req->result = req->db->sync (req->db, req->uint1); |
779 | break; |
764 | break; |
780 | |
765 | |
|
|
766 | case REQ_DB_VERIFY: |
|
|
767 | req->result = req->db->verify (req->db, req->buf1, req->buf2, 0, req->uint1); |
|
|
768 | break; |
|
|
769 | |
781 | case REQ_DB_UPGRADE: |
770 | case REQ_DB_UPGRADE: |
782 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
771 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
783 | break; |
772 | break; |
784 | |
773 | |
785 | case REQ_DB_PUT: |
774 | case REQ_DB_PUT: |
786 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
775 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
787 | break; |
776 | break; |
788 | |
777 | |
789 | #if DB_VERSION_MINOR >= 6 |
778 | #if DBVER >= 406 |
790 | case REQ_DB_EXISTS: |
779 | case REQ_DB_EXISTS: |
791 | req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1); |
780 | req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1); |
792 | break; |
781 | break; |
793 | #endif |
782 | #endif |
794 | case REQ_DB_GET: |
783 | case REQ_DB_GET: |
… | |
… | |
852 | |
841 | |
853 | case REQ_C_DEL: |
842 | case REQ_C_DEL: |
854 | req->result = req->dbc->c_del (req->dbc, req->uint1); |
843 | req->result = req->dbc->c_del (req->dbc, req->uint1); |
855 | break; |
844 | break; |
856 | |
845 | |
857 | #if DB_VERSION_MINOR >= 3 |
846 | #if DBVER >= 403 |
858 | case REQ_SEQ_OPEN: |
847 | case REQ_SEQ_OPEN: |
859 | req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); |
848 | req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); |
860 | break; |
849 | break; |
861 | |
850 | |
862 | case REQ_SEQ_CLOSE: |
851 | case REQ_SEQ_CLOSE: |
… | |
… | |
869 | |
858 | |
870 | case REQ_SEQ_REMOVE: |
859 | case REQ_SEQ_REMOVE: |
871 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
860 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
872 | break; |
861 | break; |
873 | #endif |
862 | #endif |
|
|
863 | |
|
|
864 | case REQ_ENV_LSN_RESET: |
|
|
865 | req->result = req->env->lsn_reset (req->env, req->buf1, req->uint1); |
|
|
866 | break; |
|
|
867 | |
|
|
868 | case REQ_ENV_LOG_ARCHIVE: |
|
|
869 | { |
|
|
870 | char **listp = 0; /* DB_ARCH_REMOVE does not touch listp, contrary to docs */ |
|
|
871 | req->result = req->env->log_archive (req->env, &listp, req->uint1); |
|
|
872 | req->buf1 = (char *)listp; |
|
|
873 | } |
|
|
874 | break; |
874 | |
875 | |
875 | default: |
876 | default: |
876 | req->result = ENOSYS; |
877 | req->result = ENOSYS; |
877 | break; |
878 | break; |
878 | } |
879 | } |
… | |
… | |
890 | /* try to distribute timeouts somewhat evenly */ |
891 | /* try to distribute timeouts somewhat evenly */ |
891 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
892 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
892 | |
893 | |
893 | for (;;) |
894 | for (;;) |
894 | { |
895 | { |
895 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
896 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
896 | |
897 | |
897 | X_LOCK (reqlock); |
898 | X_LOCK (reqlock); |
898 | |
899 | |
899 | for (;;) |
900 | for (;;) |
900 | { |
901 | { |
… | |
… | |
945 | X_LOCK (reslock); |
946 | X_LOCK (reslock); |
946 | |
947 | |
947 | ++npending; |
948 | ++npending; |
948 | |
949 | |
949 | if (!reqq_push (&res_queue, req)) |
950 | if (!reqq_push (&res_queue, req)) |
950 | /* write a dummy byte to the pipe so fh becomes ready */ |
951 | s_epipe_signal (&respipe); |
951 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
|
|
952 | |
952 | |
953 | self->req = 0; |
953 | self->req = 0; |
954 | worker_clear (self); |
954 | worker_clear (self); |
955 | |
955 | |
956 | X_UNLOCK (reslock); |
956 | X_UNLOCK (reslock); |
… | |
… | |
1018 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
1018 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
1019 | \ |
1019 | \ |
1020 | if (callback && SvOK (callback)) \ |
1020 | if (callback && SvOK (callback)) \ |
1021 | croak ("callback has illegal type or extra arguments"); \ |
1021 | croak ("callback has illegal type or extra arguments"); \ |
1022 | \ |
1022 | \ |
1023 | Newz (0, req, 1, bdb_cb); \ |
1023 | Newz (0, req, 1, bdb_cb); \ |
1024 | if (!req) \ |
1024 | if (!req) \ |
1025 | croak ("out of memory during bdb_req allocation"); \ |
1025 | croak ("out of memory during bdb_req allocation"); \ |
1026 | \ |
1026 | \ |
1027 | req->callback = SvREFCNT_inc (cb); \ |
1027 | req->callback = SvREFCNT_inc (cb); \ |
1028 | req->type = (reqtype); \ |
1028 | req->type = (reqtype); \ |
1029 | req->pri = req_pri; \ |
1029 | req->pri = req_pri; \ |
1030 | if (rsvcnt >= 1) req->rsv1 = SvREFCNT_inc (ST (0)); \ |
1030 | if (rsvcnt >= 1) req->rsv1 = SvREFCNT_inc (ST (0)); \ |
1031 | if (rsvcnt >= 2) req->rsv2 = SvREFCNT_inc (ST (1)); \ |
1031 | if (rsvcnt >= 2) req->rsv2 = SvREFCNT_inc (ST (1)); \ |
1032 | (void)0; |
1032 | (void)0; |
1033 | |
1033 | |
1034 | #define REQ_SEND \ |
1034 | #define REQ_SEND \ |
1035 | req_send (req) |
1035 | req_send (req) |
1036 | |
1036 | |
1037 | #define SvPTR(var, arg, type, class, nullok) \ |
1037 | #define SvPTR(var, arg, type, stash, class, nullok) \ |
1038 | if (!SvOK (arg)) \ |
1038 | if (!SvOK (arg)) \ |
1039 | { \ |
1039 | { \ |
1040 | if (nullok != 1) \ |
1040 | if (nullok != 1) \ |
1041 | croak (# var " must be a " # class " object, not undef"); \ |
1041 | croak (# var " must be a " # class " object, not undef"); \ |
1042 | \ |
1042 | \ |
1043 | (var) = 0; \ |
1043 | (var) = 0; \ |
1044 | } \ |
1044 | } \ |
1045 | else if (sv_derived_from ((arg), # class)) \ |
1045 | else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \ |
1046 | { \ |
1046 | { \ |
1047 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1047 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1048 | (var) = INT2PTR (type, tmp); \ |
1048 | (var) = INT2PTR (type, tmp); \ |
1049 | if (!var && nullok != 2) \ |
1049 | if (!var && nullok != 2) \ |
1050 | croak (# var " is not a valid " # class " object anymore"); \ |
1050 | croak (# var " is not a valid " # class " object anymore"); \ |
… | |
… | |
1053 | croak (# var " is not of type " # class); |
1053 | croak (# var " is not of type " # class); |
1054 | |
1054 | |
1055 | #define ARG_MUTABLE(name) \ |
1055 | #define ARG_MUTABLE(name) \ |
1056 | if (SvREADONLY (name)) \ |
1056 | if (SvREADONLY (name)) \ |
1057 | croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); |
1057 | croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); |
|
|
1058 | |
|
|
1059 | static SV * |
|
|
1060 | newSVptr (void *ptr, HV *stash) |
|
|
1061 | { |
|
|
1062 | SV *rv = NEWSV (0, 0); |
|
|
1063 | sv_upgrade (rv, SVt_PVMG); |
|
|
1064 | sv_setiv (rv, PTR2IV (ptr)); |
|
|
1065 | |
|
|
1066 | return sv_bless (newRV_noinc (rv), stash); |
|
|
1067 | } |
1058 | |
1068 | |
1059 | static void |
1069 | static void |
1060 | ptr_nuke (SV *sv) |
1070 | ptr_nuke (SV *sv) |
1061 | { |
1071 | { |
1062 | assert (SvROK (sv)); |
1072 | assert (SvROK (sv)); |
… | |
… | |
1133 | } |
1143 | } |
1134 | |
1144 | |
1135 | return 0; |
1145 | return 0; |
1136 | } |
1146 | } |
1137 | |
1147 | |
|
|
1148 | /*****************************************************************************/ |
|
|
1149 | |
|
|
1150 | #if 0 |
|
|
1151 | static int |
|
|
1152 | bt_pfxc_compare (DB *db, const DBT *dbt1, const DBT *dbt2) |
|
|
1153 | { |
|
|
1154 | ssize_t size1 = dbt1->size; |
|
|
1155 | ssize_t size2 = dbt2->size; |
|
|
1156 | int res = memcmp ((void *)dbt1->data, (void *)dbt2->data, |
|
|
1157 | size1 <= size2 ? size1 : size2); |
|
|
1158 | |
|
|
1159 | if (res) |
|
|
1160 | return res; |
|
|
1161 | else if (size1 - size2) |
|
|
1162 | return size1 - size2; |
|
|
1163 | else |
|
|
1164 | return 0; |
|
|
1165 | } |
|
|
1166 | |
|
|
1167 | static size_t |
|
|
1168 | bt_pfxc_prefix_x (DB *db, const DBT *dbt1, const DBT *dbt2) |
|
|
1169 | { |
|
|
1170 | ssize_t size1 = dbt1->size; |
|
|
1171 | ssize_t size2 = dbt2->size; |
|
|
1172 | u_int8_t *p1 = (u_int8_t *)dbt1->data; |
|
|
1173 | u_int8_t *p2 = (u_int8_t *)dbt2->data; |
|
|
1174 | u_int8_t *pe = p1 + (size1 <= size2 ? size1 : size2); |
|
|
1175 | |
|
|
1176 | while (p1 < pe) |
|
|
1177 | if (*p1++ != *p2++) |
|
|
1178 | return p1 - (u_int8_t *)dbt1->data - 1; |
|
|
1179 | |
|
|
1180 | if (size1 < size2) return size1 + 1; |
|
|
1181 | if (size1 > size2) return size2 + 1; |
|
|
1182 | |
|
|
1183 | return size1; |
|
|
1184 | } |
|
|
1185 | #endif |
|
|
1186 | |
|
|
1187 | /*****************************************************************************/ |
|
|
1188 | |
1138 | /* stupid windows defines CALLBACK as well */ |
1189 | /* stupid windows defines CALLBACK as well */ |
1139 | #undef CALLBACK |
1190 | #undef CALLBACK |
1140 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
1191 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
1141 | |
1192 | |
1142 | MODULE = BDB PACKAGE = BDB |
1193 | MODULE = BDB PACKAGE = BDB |
1143 | |
1194 | |
1144 | PROTOTYPES: ENABLE |
1195 | PROTOTYPES: ENABLE |
1145 | |
1196 | |
1146 | BOOT: |
1197 | BOOT: |
1147 | { |
1198 | { |
1148 | HV *stash = gv_stashpv ("BDB", 1); |
|
|
1149 | |
|
|
1150 | static const struct { |
1199 | static const struct { |
1151 | const char *name; |
1200 | const char *name; |
1152 | IV iv; |
1201 | IV iv; |
1153 | } *civ, const_iv[] = { |
1202 | } *civ, const_iv[] = { |
1154 | #define const_iv(name) { # name, (IV)DB_ ## name }, |
1203 | #define const_iv(name) { # name, (IV)DB_ ## name }, |
|
|
1204 | #if DBVER <= 408 |
1155 | const_iv (RPCCLIENT) |
1205 | const_iv (RPCCLIENT) |
|
|
1206 | #endif |
1156 | const_iv (INIT_CDB) |
1207 | const_iv (INIT_CDB) |
1157 | const_iv (INIT_LOCK) |
1208 | const_iv (INIT_LOCK) |
1158 | const_iv (INIT_LOG) |
1209 | const_iv (INIT_LOG) |
1159 | const_iv (INIT_MPOOL) |
1210 | const_iv (INIT_MPOOL) |
1160 | const_iv (INIT_REP) |
1211 | const_iv (INIT_REP) |
… | |
… | |
1183 | const_iv (TXN_NOT_DURABLE) |
1234 | const_iv (TXN_NOT_DURABLE) |
1184 | const_iv (TXN_WRITE_NOSYNC) |
1235 | const_iv (TXN_WRITE_NOSYNC) |
1185 | const_iv (WRITECURSOR) |
1236 | const_iv (WRITECURSOR) |
1186 | const_iv (YIELDCPU) |
1237 | const_iv (YIELDCPU) |
1187 | const_iv (ENCRYPT_AES) |
1238 | const_iv (ENCRYPT_AES) |
|
|
1239 | #if DBVER < 408 |
1188 | const_iv (XA_CREATE) |
1240 | const_iv (XA_CREATE) |
|
|
1241 | #endif |
1189 | const_iv (BTREE) |
1242 | const_iv (BTREE) |
1190 | const_iv (HASH) |
1243 | const_iv (HASH) |
1191 | const_iv (QUEUE) |
1244 | const_iv (QUEUE) |
1192 | const_iv (RECNO) |
1245 | const_iv (RECNO) |
1193 | const_iv (UNKNOWN) |
1246 | const_iv (UNKNOWN) |
… | |
… | |
1196 | const_iv (NOSYNC) |
1249 | const_iv (NOSYNC) |
1197 | const_iv (CHKSUM) |
1250 | const_iv (CHKSUM) |
1198 | const_iv (ENCRYPT) |
1251 | const_iv (ENCRYPT) |
1199 | const_iv (DUP) |
1252 | const_iv (DUP) |
1200 | const_iv (DUPSORT) |
1253 | const_iv (DUPSORT) |
1201 | const_iv (RECNUM) |
1254 | //const_iv (RECNUM) |
1202 | const_iv (RENUMBER) |
1255 | const_iv (RENUMBER) |
1203 | const_iv (REVSPLITOFF) |
1256 | const_iv (REVSPLITOFF) |
1204 | const_iv (CONSUME) |
1257 | const_iv (CONSUME) |
1205 | const_iv (CONSUME_WAIT) |
1258 | const_iv (CONSUME_WAIT) |
1206 | const_iv (GET_BOTH) |
1259 | const_iv (GET_BOTH) |
… | |
… | |
1257 | const_iv (LOCK_OLDEST) |
1310 | const_iv (LOCK_OLDEST) |
1258 | const_iv (LOCK_RANDOM) |
1311 | const_iv (LOCK_RANDOM) |
1259 | const_iv (LOCK_YOUNGEST) |
1312 | const_iv (LOCK_YOUNGEST) |
1260 | |
1313 | |
1261 | const_iv (DONOTINDEX) |
1314 | const_iv (DONOTINDEX) |
1262 | const_iv (KEYEMPTY ) |
1315 | const_iv (KEYEMPTY) |
1263 | const_iv (KEYEXIST ) |
1316 | const_iv (KEYEXIST) |
1264 | const_iv (LOCK_DEADLOCK) |
1317 | const_iv (LOCK_DEADLOCK) |
1265 | const_iv (LOCK_NOTGRANTED) |
1318 | const_iv (LOCK_NOTGRANTED) |
1266 | const_iv (NOSERVER) |
1319 | const_iv (NOSERVER) |
|
|
1320 | #if DBVER < 502 |
1267 | const_iv (NOSERVER_HOME) |
1321 | const_iv (NOSERVER_HOME) |
1268 | const_iv (NOSERVER_ID) |
1322 | const_iv (NOSERVER_ID) |
|
|
1323 | #endif |
1269 | const_iv (NOTFOUND) |
1324 | const_iv (NOTFOUND) |
1270 | const_iv (PAGE_NOTFOUND) |
1325 | const_iv (PAGE_NOTFOUND) |
1271 | const_iv (REP_DUPMASTER) |
1326 | const_iv (REP_DUPMASTER) |
1272 | const_iv (REP_HANDLE_DEAD) |
1327 | const_iv (REP_HANDLE_DEAD) |
1273 | const_iv (REP_HOLDELECTION) |
1328 | const_iv (REP_HOLDELECTION) |
… | |
… | |
1278 | const_iv (REP_UNAVAIL) |
1333 | const_iv (REP_UNAVAIL) |
1279 | const_iv (RUNRECOVERY) |
1334 | const_iv (RUNRECOVERY) |
1280 | const_iv (SECONDARY_BAD) |
1335 | const_iv (SECONDARY_BAD) |
1281 | const_iv (VERIFY_BAD) |
1336 | const_iv (VERIFY_BAD) |
1282 | |
1337 | |
|
|
1338 | const_iv (SALVAGE) |
|
|
1339 | const_iv (AGGRESSIVE) |
|
|
1340 | const_iv (PRINTABLE) |
|
|
1341 | const_iv (NOORDERCHK) |
|
|
1342 | const_iv (ORDERCHKONLY) |
|
|
1343 | |
|
|
1344 | const_iv (ARCH_ABS) |
|
|
1345 | const_iv (ARCH_DATA) |
|
|
1346 | const_iv (ARCH_LOG) |
|
|
1347 | const_iv (ARCH_REMOVE) |
|
|
1348 | |
1283 | const_iv (VERB_DEADLOCK) |
1349 | const_iv (VERB_DEADLOCK) |
1284 | const_iv (VERB_RECOVERY) |
1350 | const_iv (VERB_RECOVERY) |
1285 | const_iv (VERB_REPLICATION) |
1351 | const_iv (VERB_REPLICATION) |
1286 | const_iv (VERB_WAITSFOR) |
1352 | const_iv (VERB_WAITSFOR) |
1287 | |
1353 | |
1288 | const_iv (VERSION_MAJOR) |
1354 | const_iv (VERSION_MAJOR) |
1289 | const_iv (VERSION_MINOR) |
1355 | const_iv (VERSION_MINOR) |
1290 | const_iv (VERSION_PATCH) |
1356 | const_iv (VERSION_PATCH) |
1291 | #if DB_VERSION_MINOR >= 3 |
1357 | const_iv (LOGVERSION) |
|
|
1358 | const_iv (LOGOLDVER) |
|
|
1359 | #if DBVER >= 403 |
1292 | const_iv (INORDER) |
1360 | const_iv (INORDER) |
1293 | const_iv (LOCK_MAXWRITE) |
1361 | const_iv (LOCK_MAXWRITE) |
1294 | const_iv (SEQ_DEC) |
1362 | const_iv (SEQ_DEC) |
1295 | const_iv (SEQ_INC) |
1363 | const_iv (SEQ_INC) |
1296 | const_iv (SEQ_WRAP) |
1364 | const_iv (SEQ_WRAP) |
1297 | const_iv (BUFFER_SMALL) |
1365 | const_iv (BUFFER_SMALL) |
1298 | const_iv (LOG_BUFFER_FULL) |
1366 | const_iv (LOG_BUFFER_FULL) |
1299 | const_iv (VERSION_MISMATCH) |
1367 | const_iv (VERSION_MISMATCH) |
1300 | #endif |
1368 | #endif |
1301 | #if DB_VERSION_MINOR >= 4 |
1369 | #if DBVER >= 404 |
1302 | const_iv (REGISTER) |
1370 | const_iv (REGISTER) |
1303 | const_iv (DSYNC_DB) |
1371 | const_iv (DSYNC_DB) |
1304 | const_iv (READ_COMMITTED) |
1372 | const_iv (READ_COMMITTED) |
1305 | const_iv (READ_UNCOMMITTED) |
1373 | const_iv (READ_UNCOMMITTED) |
1306 | const_iv (REP_IGNORE) |
1374 | const_iv (REP_IGNORE) |
… | |
… | |
1308 | const_iv (REP_JOIN_FAILURE) |
1376 | const_iv (REP_JOIN_FAILURE) |
1309 | const_iv (FREE_SPACE) |
1377 | const_iv (FREE_SPACE) |
1310 | const_iv (FREELIST_ONLY) |
1378 | const_iv (FREELIST_ONLY) |
1311 | const_iv (VERB_REGISTER) |
1379 | const_iv (VERB_REGISTER) |
1312 | #endif |
1380 | #endif |
1313 | #if DB_VERSION_MINOR >= 5 |
1381 | #if DBVER >= 405 |
1314 | const_iv (MULTIVERSION) |
1382 | const_iv (MULTIVERSION) |
1315 | const_iv (TXN_SNAPSHOT) |
1383 | const_iv (TXN_SNAPSHOT) |
1316 | #endif |
1384 | #endif |
1317 | #if DB_VERSION_MINOR >= 6 |
1385 | #if DBVER >= 406 |
1318 | const_iv (PREV_DUP) |
1386 | const_iv (PREV_DUP) |
1319 | const_iv (PRIORITY_UNCHANGED) |
1387 | const_iv (PRIORITY_UNCHANGED) |
1320 | const_iv (PRIORITY_VERY_LOW) |
1388 | const_iv (PRIORITY_VERY_LOW) |
1321 | const_iv (PRIORITY_LOW) |
1389 | const_iv (PRIORITY_LOW) |
1322 | const_iv (PRIORITY_DEFAULT) |
1390 | const_iv (PRIORITY_DEFAULT) |
1323 | const_iv (PRIORITY_HIGH) |
1391 | const_iv (PRIORITY_HIGH) |
1324 | const_iv (PRIORITY_VERY_HIGH) |
1392 | const_iv (PRIORITY_VERY_HIGH) |
|
|
1393 | const_iv (IGNORE_LEASE) |
1325 | #endif |
1394 | #endif |
1326 | #if DB_VERSION_MINOR >= 7 |
1395 | #if DBVER >= 407 |
|
|
1396 | //const_iv (MULTIPLE_KEY) |
1327 | const_iv (LOG_DIRECT) |
1397 | const_iv (LOG_DIRECT) |
1328 | const_iv (LOG_DSYNC) |
1398 | const_iv (LOG_DSYNC) |
1329 | const_iv (LOG_AUTO_REMOVE) |
1399 | const_iv (LOG_AUTO_REMOVE) |
1330 | const_iv (LOG_IN_MEMORY) |
1400 | const_iv (LOG_IN_MEMORY) |
1331 | const_iv (LOG_ZERO) |
1401 | const_iv (LOG_ZERO) |
1332 | #else |
1402 | #else |
1333 | const_iv (DIRECT_LOG) |
1403 | const_iv (DIRECT_LOG) |
1334 | const_iv (LOG_AUTOREMOVE) |
1404 | const_iv (LOG_AUTOREMOVE) |
1335 | # if DB_VERSION_MINOR >= 3 |
1405 | # if DBVER >= 403 |
1336 | const_iv (DSYNC_LOG) |
1406 | const_iv (DSYNC_LOG) |
1337 | const_iv (LOG_INMEMORY) |
1407 | const_iv (LOG_INMEMORY) |
1338 | # endif |
1408 | # endif |
|
|
1409 | #if DBVER >= 408 |
|
|
1410 | const_iv (LOGVERSION_LATCHING) |
|
|
1411 | #endif |
1339 | #endif |
1412 | #endif |
1340 | }; |
1413 | }; |
1341 | |
1414 | |
|
|
1415 | bdb_stash = gv_stashpv ("BDB" , 1); |
|
|
1416 | bdb_env_stash = gv_stashpv ("BDB::Env" , 1); |
|
|
1417 | bdb_txn_stash = gv_stashpv ("BDB::Txn" , 1); |
|
|
1418 | bdb_cursor_stash = gv_stashpv ("BDB::Cursor" , 1); |
|
|
1419 | bdb_db_stash = gv_stashpv ("BDB::Db" , 1); |
|
|
1420 | bdb_sequence_stash = gv_stashpv ("BDB::Sequence", 1); |
|
|
1421 | |
1342 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1422 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
1343 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1423 | newCONSTSUB (bdb_stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
1344 | |
1424 | |
1345 | prepare_cb = &PL_sv_undef; |
1425 | prepare_cb = &PL_sv_undef; |
1346 | |
1426 | |
1347 | { |
1427 | { |
1348 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
1428 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
1349 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
1429 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
1350 | |
1430 | |
1351 | newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); |
1431 | newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3)); |
1352 | } |
1432 | } |
1353 | |
1433 | |
1354 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1434 | newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1355 | |
1435 | |
1356 | create_respipe (); |
1436 | create_respipe (); |
1357 | |
1437 | |
1358 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1438 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1359 | patch_errno (); |
1439 | patch_errno (); |
… | |
… | |
1437 | |
1517 | |
1438 | int |
1518 | int |
1439 | poll_fileno () |
1519 | poll_fileno () |
1440 | PROTOTYPE: |
1520 | PROTOTYPE: |
1441 | CODE: |
1521 | CODE: |
1442 | RETVAL = respipe [0]; |
1522 | RETVAL = s_epipe_fd (&respipe); |
1443 | OUTPUT: |
1523 | OUTPUT: |
1444 | RETVAL |
1524 | RETVAL |
1445 | |
1525 | |
1446 | int |
1526 | int |
1447 | poll_cb (...) |
1527 | poll_cb (...) |
… | |
… | |
1631 | dREQ (REQ_ENV_DBRENAME, 2); |
1711 | dREQ (REQ_ENV_DBRENAME, 2); |
1632 | req->env = env; |
1712 | req->env = env; |
1633 | req->buf1 = strdup_ornull (file); |
1713 | req->buf1 = strdup_ornull (file); |
1634 | req->buf2 = strdup_ornull (database); |
1714 | req->buf2 = strdup_ornull (database); |
1635 | req->buf3 = strdup_ornull (newname); |
1715 | req->buf3 = strdup_ornull (newname); |
|
|
1716 | req->uint1 = flags; |
|
|
1717 | REQ_SEND; |
|
|
1718 | } |
|
|
1719 | |
|
|
1720 | void |
|
|
1721 | db_env_lsn_reset (DB_ENV *env, bdb_filename db, U32 flags = 0, SV *callback = 0) |
|
|
1722 | PREINIT: |
|
|
1723 | CALLBACK |
|
|
1724 | CODE: |
|
|
1725 | { |
|
|
1726 | dREQ (REQ_ENV_LSN_RESET, 1); |
|
|
1727 | req->env = env; |
|
|
1728 | req->uint1 = flags; |
|
|
1729 | req->buf1 = strdup_ornull (db); |
|
|
1730 | REQ_SEND; |
|
|
1731 | } |
|
|
1732 | |
|
|
1733 | void |
|
|
1734 | db_env_log_archive (DB_ENV *env, SV_mutable *listp, U32 flags = 0, SV *callback = 0) |
|
|
1735 | PREINIT: |
|
|
1736 | CALLBACK |
|
|
1737 | CODE: |
|
|
1738 | { |
|
|
1739 | dREQ (REQ_ENV_LOG_ARCHIVE, 1); |
|
|
1740 | req->sv1 = SvREFCNT_inc (listp); |
|
|
1741 | req->env = env; |
1636 | req->uint1 = flags; |
1742 | req->uint1 = flags; |
1637 | REQ_SEND; |
1743 | REQ_SEND; |
1638 | } |
1744 | } |
1639 | |
1745 | |
1640 | DB * |
1746 | DB * |
… | |
… | |
1680 | req->uint1 = flags; |
1786 | req->uint1 = flags; |
1681 | req->sv1 = (SV *)db->app_private; |
1787 | req->sv1 = (SV *)db->app_private; |
1682 | REQ_SEND; |
1788 | REQ_SEND; |
1683 | } |
1789 | } |
1684 | |
1790 | |
1685 | #if DB_VERSION_MINOR >= 4 |
1791 | #if DBVER >= 404 |
1686 | |
1792 | |
1687 | void |
1793 | void |
1688 | db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = 0) |
1794 | db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = 0) |
1689 | PREINIT: |
1795 | PREINIT: |
1690 | CALLBACK |
1796 | CALLBACK |
1691 | CODE: |
1797 | CODE: |
1692 | { |
1798 | { |
1693 | dREQ (REQ_DB_COMPACT, 2); |
1799 | dREQ (REQ_DB_COMPACT, 2); |
1694 | req->db = db; |
1800 | req->db = db; |
1695 | req->txn = txn; |
1801 | req->txn = txn; |
1696 | sv_to_dbt (&req->dbt1, start); |
1802 | if (start) sv_to_dbt (&req->dbt1, start); |
1697 | sv_to_dbt (&req->dbt2, stop); |
1803 | if (stop ) sv_to_dbt (&req->dbt2, stop ); |
1698 | req->uint1 = flags; |
1804 | req->uint1 = flags; |
1699 | REQ_SEND; |
1805 | REQ_SEND; |
1700 | } |
1806 | } |
1701 | |
1807 | |
1702 | #endif |
1808 | #endif |
… | |
… | |
1712 | req->uint1 = flags; |
1818 | req->uint1 = flags; |
1713 | REQ_SEND; |
1819 | REQ_SEND; |
1714 | } |
1820 | } |
1715 | |
1821 | |
1716 | void |
1822 | void |
|
|
1823 | db_verify (DB *db, bdb_filename file, bdb_filename database = 0, SV *dummy = 0, U32 flags = 0, SV *callback = 0) |
|
|
1824 | PREINIT: |
|
|
1825 | CALLBACK |
|
|
1826 | CODE: |
|
|
1827 | { |
|
|
1828 | dREQ (REQ_DB_VERIFY, 1); |
|
|
1829 | ptr_nuke (ST (0)); /* verify destroys the database handle, hopefully it is freed as well */ |
|
|
1830 | req->db = db; |
|
|
1831 | req->buf1 = strdup (file); |
|
|
1832 | req->buf2 = strdup_ornull (database); |
|
|
1833 | req->uint1 = flags; |
|
|
1834 | REQ_SEND; |
|
|
1835 | } |
|
|
1836 | |
|
|
1837 | void |
1717 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) |
1838 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) |
1718 | PREINIT: |
1839 | PREINIT: |
1719 | CALLBACK |
1840 | CALLBACK |
1720 | CODE: |
1841 | CODE: |
1721 | { |
1842 | { |
1722 | dREQ (REQ_DB_SYNC, 1); |
1843 | dREQ (REQ_DB_UPGRADE, 1); |
1723 | req->db = db; |
1844 | req->db = db; |
1724 | req->buf1 = strdup (file); |
1845 | req->buf1 = strdup (file); |
1725 | req->uint1 = flags; |
1846 | req->uint1 = flags; |
1726 | REQ_SEND; |
1847 | REQ_SEND; |
1727 | } |
1848 | } |
… | |
… | |
1754 | sv_to_dbt (&req->dbt2, data); |
1875 | sv_to_dbt (&req->dbt2, data); |
1755 | req->uint1 = flags; |
1876 | req->uint1 = flags; |
1756 | REQ_SEND; |
1877 | REQ_SEND; |
1757 | } |
1878 | } |
1758 | |
1879 | |
1759 | #if DB_VERSION_MINOR >= 6 |
1880 | #if DBVER >= 406 |
1760 | |
1881 | |
1761 | void |
1882 | void |
1762 | db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) |
1883 | db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) |
1763 | PREINIT: |
1884 | PREINIT: |
1764 | CALLBACK |
1885 | CALLBACK |
… | |
… | |
1907 | db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
2028 | db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1908 | PREINIT: |
2029 | PREINIT: |
1909 | CALLBACK |
2030 | CALLBACK |
1910 | CODE: |
2031 | CODE: |
1911 | { |
2032 | { |
1912 | if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) |
2033 | if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key)) |
1913 | croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET"); |
2034 | croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET"); |
1914 | if (SvPOKp (key) && !sv_utf8_downgrade (key, 1)) |
2035 | if (SvPOKp (key) && !sv_utf8_downgrade (key, 1)) |
1915 | croak ("argument \"%s\" must be byte/octet-encoded in %s", |
2036 | croak ("argument \"%s\" must be byte/octet-encoded in %s", |
1916 | "key", |
2037 | "key", |
1917 | "BDB::db_c_get"); |
2038 | "BDB::db_c_get"); |
1918 | |
2039 | |
1919 | { |
2040 | { |
1920 | dREQ (REQ_C_GET, 1); |
2041 | dREQ (REQ_C_GET, 1); |
1921 | req->dbc = dbc; |
2042 | req->dbc = dbc; |
1922 | req->uint1 = flags; |
2043 | req->uint1 = flags; |
1923 | if (flags & DB_OPFLAGS_MASK == DB_SET) |
2044 | if ((flags & DB_OPFLAGS_MASK) == DB_SET) |
1924 | sv_to_dbt (&req->dbt1, key); |
2045 | sv_to_dbt (&req->dbt1, key); |
1925 | else |
2046 | else |
1926 | { |
2047 | { |
1927 | if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) |
2048 | if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE) |
1928 | sv_to_dbt (&req->dbt1, key); |
2049 | sv_to_dbt (&req->dbt1, key); |
1929 | else |
2050 | else |
1930 | req->dbt1.flags = DB_DBT_MALLOC; |
2051 | req->dbt1.flags = DB_DBT_MALLOC; |
1931 | |
2052 | |
1932 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
2053 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
1933 | } |
2054 | } |
1934 | |
2055 | |
1935 | if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH |
2056 | if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH |
1936 | || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) |
2057 | || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE) |
1937 | sv_to_dbt (&req->dbt3, data); |
2058 | sv_to_dbt (&req->dbt3, data); |
1938 | else |
2059 | else |
1939 | req->dbt3.flags = DB_DBT_MALLOC; |
2060 | req->dbt3.flags = DB_DBT_MALLOC; |
1940 | |
2061 | |
1941 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
2062 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
… | |
… | |
1947 | db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
2068 | db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1948 | PREINIT: |
2069 | PREINIT: |
1949 | CALLBACK |
2070 | CALLBACK |
1950 | CODE: |
2071 | CODE: |
1951 | { |
2072 | { |
1952 | if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key)) |
2073 | if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key)) |
1953 | croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET"); |
2074 | croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET"); |
1954 | if (SvPOKp (key) && !sv_utf8_downgrade (key, 1)) |
2075 | if (SvPOKp (key) && !sv_utf8_downgrade (key, 1)) |
1955 | croak ("argument \"%s\" must be byte/octet-encoded in %s", |
2076 | croak ("argument \"%s\" must be byte/octet-encoded in %s", |
1956 | "key", |
2077 | "key", |
1957 | "BDB::db_c_pget"); |
2078 | "BDB::db_c_pget"); |
1958 | |
2079 | |
1959 | { |
2080 | { |
1960 | dREQ (REQ_C_PGET, 1); |
2081 | dREQ (REQ_C_PGET, 1); |
1961 | req->dbc = dbc; |
2082 | req->dbc = dbc; |
1962 | req->uint1 = flags; |
2083 | req->uint1 = flags; |
1963 | if (flags & DB_OPFLAGS_MASK == DB_SET) |
2084 | if ((flags & DB_OPFLAGS_MASK) == DB_SET) |
1964 | sv_to_dbt (&req->dbt1, key); |
2085 | sv_to_dbt (&req->dbt1, key); |
1965 | else |
2086 | else |
1966 | { |
2087 | { |
1967 | if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE) |
2088 | if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE) |
1968 | sv_to_dbt (&req->dbt1, key); |
2089 | sv_to_dbt (&req->dbt1, key); |
1969 | else |
2090 | else |
1970 | req->dbt1.flags = DB_DBT_MALLOC; |
2091 | req->dbt1.flags = DB_DBT_MALLOC; |
1971 | |
2092 | |
1972 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
2093 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
1973 | } |
2094 | } |
1974 | |
2095 | |
1975 | req->dbt2.flags = DB_DBT_MALLOC; |
2096 | req->dbt2.flags = DB_DBT_MALLOC; |
1976 | req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); |
2097 | req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); |
1977 | |
2098 | |
1978 | if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH |
2099 | if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH |
1979 | || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE) |
2100 | || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE) |
1980 | sv_to_dbt (&req->dbt3, data); |
2101 | sv_to_dbt (&req->dbt3, data); |
1981 | else |
2102 | else |
1982 | req->dbt3.flags = DB_DBT_MALLOC; |
2103 | req->dbt3.flags = DB_DBT_MALLOC; |
1983 | |
2104 | |
1984 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
2105 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
… | |
… | |
1997 | req->uint1 = flags; |
2118 | req->uint1 = flags; |
1998 | REQ_SEND; |
2119 | REQ_SEND; |
1999 | } |
2120 | } |
2000 | |
2121 | |
2001 | |
2122 | |
2002 | #if DB_VERSION_MINOR >= 3 |
2123 | #if DBVER >= 403 |
2003 | |
2124 | |
2004 | void |
2125 | void |
2005 | db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) |
2126 | db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) |
2006 | PREINIT: |
2127 | PREINIT: |
2007 | CALLBACK |
2128 | CALLBACK |
… | |
… | |
2101 | CODE: |
2222 | CODE: |
2102 | RETVAL = env->set_flags (env, flags, onoff); |
2223 | RETVAL = env->set_flags (env, flags, onoff); |
2103 | OUTPUT: |
2224 | OUTPUT: |
2104 | RETVAL |
2225 | RETVAL |
2105 | |
2226 | |
2106 | #if DB_VERSION_MINOR >= 7 |
2227 | #if DBVER >= 407 |
2107 | |
2228 | |
2108 | int set_intermediate_dir_mode (DB_ENV *env, const char *mode) |
2229 | int set_intermediate_dir_mode (DB_ENV *env, const char *mode) |
2109 | CODE: |
2230 | CODE: |
2110 | RETVAL = env->set_intermediate_dir_mode (env, mode); |
2231 | RETVAL = env->set_intermediate_dir_mode (env, mode); |
2111 | OUTPUT: |
2232 | OUTPUT: |
… | |
… | |
2198 | CODE: |
2319 | CODE: |
2199 | RETVAL = env->set_lg_max (env, max); |
2320 | RETVAL = env->set_lg_max (env, max); |
2200 | OUTPUT: |
2321 | OUTPUT: |
2201 | RETVAL |
2322 | RETVAL |
2202 | |
2323 | |
2203 | #if DB_VERSION_MINOR >= 4 |
2324 | #if DBVER >= 404 |
2204 | |
2325 | |
2205 | int mutex_set_max (DB_ENV *env, U32 max) |
2326 | int mutex_set_max (DB_ENV *env, U32 max) |
2206 | CODE: |
2327 | CODE: |
2207 | RETVAL = env->mutex_set_max (env, max); |
2328 | RETVAL = env->mutex_set_max (env, max); |
2208 | OUTPUT: |
2329 | OUTPUT: |
… | |
… | |
2235 | if (errno) |
2356 | if (errno) |
2236 | croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); |
2357 | croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); |
2237 | OUTPUT: |
2358 | OUTPUT: |
2238 | RETVAL |
2359 | RETVAL |
2239 | |
2360 | |
2240 | #if DB_VERSION_MINOR >= 5 |
2361 | #if DBVER >= 405 |
2241 | |
2362 | |
2242 | DB_TXN * |
2363 | DB_TXN * |
2243 | cdsgroup_begin (DB_ENV *env) |
2364 | cdsgroup_begin (DB_ENV *env) |
2244 | CODE: |
2365 | CODE: |
2245 | errno = env->cdsgroup_begin (env, &RETVAL); |
2366 | errno = env->cdsgroup_begin (env, &RETVAL); |
… | |
… | |
2347 | if (errno) |
2468 | if (errno) |
2348 | croak ("DB->cursor: %s", db_strerror (errno)); |
2469 | croak ("DB->cursor: %s", db_strerror (errno)); |
2349 | OUTPUT: |
2470 | OUTPUT: |
2350 | RETVAL |
2471 | RETVAL |
2351 | |
2472 | |
2352 | #if DB_VERSION_MINOR >= 3 |
2473 | #if DBVER >= 403 |
2353 | |
2474 | |
2354 | DB_SEQUENCE * |
2475 | DB_SEQUENCE * |
2355 | sequence (DB *db, U32 flags = 0) |
2476 | sequence (DB *db, U32 flags = 0) |
2356 | CODE: |
2477 | CODE: |
2357 | { |
2478 | { |
… | |
… | |
2392 | DESTROY (DBC_ornuked *dbc) |
2513 | DESTROY (DBC_ornuked *dbc) |
2393 | CODE: |
2514 | CODE: |
2394 | if (dbc) |
2515 | if (dbc) |
2395 | dbc->c_close (dbc); |
2516 | dbc->c_close (dbc); |
2396 | |
2517 | |
2397 | #if DB_VERSION_MINOR >= 6 |
2518 | #if DBVER >= 406 |
2398 | |
2519 | |
2399 | int set_priority (DBC *dbc, int priority) |
2520 | int set_priority (DBC *dbc, int priority) |
2400 | CODE: |
2521 | CODE: |
2401 | dbc->set_priority (dbc, priority); |
2522 | dbc->set_priority (dbc, priority); |
2402 | |
2523 | |
2403 | #endif |
2524 | #endif |
2404 | |
2525 | |
2405 | #if DB_VERSION_MINOR >= 3 |
2526 | #if DBVER >= 403 |
2406 | |
2527 | |
2407 | MODULE = BDB PACKAGE = BDB::Sequence |
2528 | MODULE = BDB PACKAGE = BDB::Sequence |
2408 | |
2529 | |
2409 | void |
2530 | void |
2410 | DESTROY (DB_SEQUENCE_ornuked *seq) |
2531 | DESTROY (DB_SEQUENCE_ornuked *seq) |