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 |
… | |
… | |
39 | #endif |
38 | #endif |
40 | |
39 | |
41 | /* number of seconds after which idle threads exit */ |
40 | /* number of seconds after which idle threads exit */ |
42 | #define IDLE_TIMEOUT 10 |
41 | #define IDLE_TIMEOUT 10 |
43 | |
42 | |
|
|
43 | typedef SV SV_mutable; |
|
|
44 | |
44 | typedef DB_ENV DB_ENV_ornull; |
45 | typedef DB_ENV DB_ENV_ornull; |
45 | typedef DB_TXN DB_TXN_ornull; |
46 | typedef DB_TXN DB_TXN_ornull; |
46 | typedef DBC DBC_ornull; |
47 | typedef DBC DBC_ornull; |
47 | typedef DB DB_ornull; |
48 | typedef DB DB_ornull; |
48 | |
49 | |
… | |
… | |
54 | #if DB_VERSION_MINOR >= 3 |
55 | #if DB_VERSION_MINOR >= 3 |
55 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
56 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
56 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
57 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
57 | #endif |
58 | #endif |
58 | |
59 | |
59 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
|
|
60 | typedef char *bdb_filename; |
60 | typedef char *bdb_filename; |
61 | |
61 | |
62 | static SV *prepare_cb; |
62 | static SV *prepare_cb; |
|
|
63 | |
|
|
64 | static HV |
|
|
65 | *bdb_stash, |
|
|
66 | *bdb_env_stash, |
|
|
67 | *bdb_txn_stash, |
|
|
68 | *bdb_cursor_stash, |
|
|
69 | *bdb_db_stash, |
|
|
70 | *bdb_sequence_stash; |
63 | |
71 | |
64 | #if DB_VERSION_MINOR >= 6 |
72 | #if DB_VERSION_MINOR >= 6 |
65 | # define c_close close |
73 | # define c_close close |
66 | # define c_count count |
74 | # define c_count count |
67 | # define c_del del |
75 | # define c_del del |
… | |
… | |
135 | dbt_to_sv (SV *sv, DBT *dbt) |
143 | dbt_to_sv (SV *sv, DBT *dbt) |
136 | { |
144 | { |
137 | if (sv) |
145 | if (sv) |
138 | { |
146 | { |
139 | SvREADONLY_off (sv); |
147 | SvREADONLY_off (sv); |
140 | sv_setsv_mg (sv, dbt->data ? newSVpvn (dbt->data, dbt->size) : &PL_sv_undef); |
148 | |
|
|
149 | if (dbt->data) |
|
|
150 | sv_setpvn_mg (sv, dbt->data, dbt->size); |
|
|
151 | else |
|
|
152 | sv_setsv_mg (sv, &PL_sv_undef); |
|
|
153 | |
141 | SvREFCNT_dec (sv); |
154 | SvREFCNT_dec (sv); |
142 | } |
155 | } |
143 | |
156 | |
144 | //assert (dbt->flags & DBT_MALLOC || !dbt->data); |
|
|
145 | free (dbt->data); |
157 | free (dbt->data); |
146 | } |
158 | } |
147 | |
159 | |
148 | enum { |
160 | enum { |
149 | REQ_QUIT, |
161 | REQ_QUIT, |
150 | 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, |
151 | 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, |
152 | 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, |
153 | 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, |
154 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
167 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
155 | 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, |
156 | 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, |
157 | }; |
170 | }; |
… | |
… | |
242 | } |
255 | } |
243 | |
256 | |
244 | static volatile unsigned int nreqs, nready, npending; |
257 | static volatile unsigned int nreqs, nready, npending; |
245 | static volatile unsigned int max_idle = 4; |
258 | static volatile unsigned int max_idle = 4; |
246 | static volatile unsigned int max_outstanding = 0xffffffff; |
259 | static volatile unsigned int max_outstanding = 0xffffffff; |
247 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
260 | static s_epipe respipe; |
248 | |
261 | |
249 | static mutex_t reslock = X_MUTEX_INIT; |
262 | static mutex_t reslock = X_MUTEX_INIT; |
250 | static mutex_t reqlock = X_MUTEX_INIT; |
263 | static mutex_t reqlock = X_MUTEX_INIT; |
251 | static cond_t reqwait = X_COND_INIT; |
264 | static cond_t reqwait = X_COND_INIT; |
252 | |
265 | |
… | |
… | |
347 | abort (); |
360 | abort (); |
348 | } |
361 | } |
349 | |
362 | |
350 | static int poll_cb (void); |
363 | static int poll_cb (void); |
351 | static void req_free (bdb_req req); |
364 | static void req_free (bdb_req req); |
352 | static void req_cancel (bdb_req req); |
|
|
353 | |
365 | |
354 | static int req_invoke (bdb_req req) |
366 | static int req_invoke (bdb_req req) |
355 | { |
367 | { |
356 | switch (req->type) |
368 | switch (req->type) |
357 | { |
369 | { |
… | |
… | |
359 | SvREFCNT_dec (req->sv1); |
371 | SvREFCNT_dec (req->sv1); |
360 | break; |
372 | break; |
361 | |
373 | |
362 | case REQ_DB_GET: |
374 | case REQ_DB_GET: |
363 | case REQ_DB_PGET: |
375 | case REQ_DB_PGET: |
364 | dbt_to_sv (req->sv3, &req->dbt3); |
|
|
365 | break; |
|
|
366 | |
|
|
367 | case REQ_C_GET: |
376 | case REQ_C_GET: |
368 | case REQ_C_PGET: |
377 | case REQ_C_PGET: |
|
|
378 | case REQ_DB_PUT: |
|
|
379 | case REQ_C_PUT: |
369 | dbt_to_sv (req->sv1, &req->dbt1); |
380 | dbt_to_sv (req->sv1, &req->dbt1); |
370 | dbt_to_sv (req->sv2, &req->dbt2); |
381 | dbt_to_sv (req->sv2, &req->dbt2); |
371 | dbt_to_sv (req->sv3, &req->dbt3); |
382 | dbt_to_sv (req->sv3, &req->dbt3); |
372 | break; |
383 | break; |
373 | |
384 | |
374 | case REQ_DB_PUT: |
|
|
375 | case REQ_C_PUT: |
|
|
376 | dbt_to_sv (0, &req->dbt1); |
|
|
377 | dbt_to_sv (0, &req->dbt2); |
|
|
378 | break; |
|
|
379 | |
|
|
380 | case REQ_DB_KEY_RANGE: |
385 | case REQ_DB_KEY_RANGE: |
381 | { |
386 | { |
382 | AV *av = newAV (); |
387 | AV *av = newAV (); |
383 | |
388 | |
384 | av_push (av, newSVnv (req->key_range.less)); |
389 | av_push (av, newSVnv (req->key_range.less)); |
385 | av_push (av, newSVnv (req->key_range.equal)); |
390 | av_push (av, newSVnv (req->key_range.equal)); |
386 | av_push (av, newSVnv (req->key_range.greater)); |
391 | av_push (av, newSVnv (req->key_range.greater)); |
387 | |
392 | |
|
|
393 | av = (AV *)newRV_noinc ((SV *)av); |
|
|
394 | |
388 | SvREADONLY_off (req->sv1); |
395 | SvREADONLY_off (req->sv1); |
389 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
396 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
|
|
397 | SvREFCNT_dec (av); |
390 | SvREFCNT_dec (req->sv1); |
398 | SvREFCNT_dec (req->sv1); |
391 | } |
399 | } |
392 | break; |
400 | break; |
393 | |
401 | |
394 | #if DB_VERSION_MINOR >= 3 |
402 | #if DB_VERSION_MINOR >= 3 |
… | |
… | |
401 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
409 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
402 | |
410 | |
403 | SvREFCNT_dec (req->sv1); |
411 | SvREFCNT_dec (req->sv1); |
404 | break; |
412 | break; |
405 | #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; |
406 | } |
432 | } |
407 | |
433 | |
408 | errno = req->result; |
434 | errno = req->result; |
409 | |
435 | |
410 | if (req->callback) |
436 | if (req->callback) |
… | |
… | |
440 | free (req->buf3); |
466 | free (req->buf3); |
441 | |
467 | |
442 | Safefree (req); |
468 | Safefree (req); |
443 | } |
469 | } |
444 | |
470 | |
445 | #ifdef USE_SOCKETS_AS_HANDLES |
|
|
446 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
|
|
447 | #else |
|
|
448 | # define TO_SOCKET(x) (x) |
|
|
449 | #endif |
|
|
450 | |
|
|
451 | static void |
471 | static void |
452 | create_respipe (void) |
472 | create_respipe (void) |
453 | { |
473 | { |
454 | #ifdef _WIN32 |
|
|
455 | int arg; /* argg */ |
|
|
456 | #endif |
|
|
457 | int old_readfd = respipe [0]; |
|
|
458 | |
|
|
459 | if (respipe [1] >= 0) |
|
|
460 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
461 | |
|
|
462 | #ifdef _WIN32 |
|
|
463 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
|
|
464 | #else |
|
|
465 | if (pipe (respipe)) |
474 | if (s_epipe_renew (&respipe)) |
466 | #endif |
475 | croak ("BDB: unable to create event pipe"); |
467 | croak ("unable to initialize result pipe"); |
|
|
468 | |
|
|
469 | if (old_readfd >= 0) |
|
|
470 | { |
|
|
471 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
472 | croak ("unable to initialize result pipe(2)"); |
|
|
473 | |
|
|
474 | respipe_close (respipe [0]); |
|
|
475 | respipe [0] = old_readfd; |
|
|
476 | } |
|
|
477 | |
|
|
478 | #ifdef _WIN32 |
|
|
479 | arg = 1; |
|
|
480 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
481 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
482 | #else |
|
|
483 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
484 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
485 | #endif |
|
|
486 | croak ("unable to initialize result pipe(3)"); |
|
|
487 | |
|
|
488 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
|
|
489 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
|
|
490 | } |
476 | } |
491 | |
477 | |
492 | static void bdb_request (bdb_req req); |
478 | static void bdb_request (bdb_req req); |
493 | X_THREAD_PROC (bdb_proc); |
479 | X_THREAD_PROC (bdb_proc); |
494 | |
480 | |
… | |
… | |
555 | PUTBACK; |
541 | PUTBACK; |
556 | count = call_sv (prepare_cb, G_ARRAY); |
542 | count = call_sv (prepare_cb, G_ARRAY); |
557 | SPAGAIN; |
543 | SPAGAIN; |
558 | |
544 | |
559 | if (count != 2) |
545 | if (count != 2) |
560 | croak ("prepare callback must return exactly two values\n"); |
546 | croak ("sync prepare callback must return exactly two values\n"); |
561 | |
547 | |
562 | wait_callback = POPs; |
548 | wait_callback = POPs; |
563 | req->callback = SvREFCNT_inc (POPs); |
549 | req->callback = SvREFCNT_inc (POPs); |
564 | } |
550 | } |
565 | else |
551 | else |
… | |
… | |
630 | end_thread (); |
616 | end_thread (); |
631 | } |
617 | } |
632 | |
618 | |
633 | static void poll_wait (void) |
619 | static void poll_wait (void) |
634 | { |
620 | { |
635 | fd_set rfd; |
|
|
636 | |
|
|
637 | while (nreqs) |
621 | while (nreqs) |
638 | { |
622 | { |
639 | int size; |
623 | int size; |
640 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
624 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
641 | size = res_queue.size; |
625 | size = res_queue.size; |
… | |
… | |
644 | if (size) |
628 | if (size) |
645 | return; |
629 | return; |
646 | |
630 | |
647 | maybe_start_thread (); |
631 | maybe_start_thread (); |
648 | |
632 | |
649 | FD_ZERO (&rfd); |
633 | s_epipe_wait (&respipe); |
650 | FD_SET (respipe [0], &rfd); |
|
|
651 | |
|
|
652 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
653 | } |
634 | } |
654 | } |
635 | } |
655 | |
636 | |
656 | static int poll_cb (void) |
637 | static int poll_cb (void) |
657 | { |
638 | { |
… | |
… | |
677 | if (req) |
658 | if (req) |
678 | { |
659 | { |
679 | --npending; |
660 | --npending; |
680 | |
661 | |
681 | if (!res_queue.size) |
662 | if (!res_queue.size) |
682 | { |
|
|
683 | /* read any signals sent by the worker threads */ |
663 | /* read any signals sent by the worker threads */ |
684 | char buf [4]; |
664 | s_epipe_drain (&respipe); |
685 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
686 | ; |
|
|
687 | } |
|
|
688 | } |
665 | } |
689 | |
666 | |
690 | X_UNLOCK (reslock); |
667 | X_UNLOCK (reslock); |
691 | |
668 | |
692 | if (!req) |
669 | if (!req) |
… | |
… | |
774 | req->result = req->db->close (req->db, req->uint1); |
751 | req->result = req->db->close (req->db, req->uint1); |
775 | break; |
752 | break; |
776 | |
753 | |
777 | #if DB_VERSION_MINOR >= 4 |
754 | #if DB_VERSION_MINOR >= 4 |
778 | case REQ_DB_COMPACT: |
755 | case REQ_DB_COMPACT: |
779 | 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); |
780 | break; |
757 | break; |
781 | #endif |
758 | #endif |
782 | |
759 | |
783 | case REQ_DB_SYNC: |
760 | case REQ_DB_SYNC: |
784 | 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); |
785 | break; |
766 | break; |
786 | |
767 | |
787 | case REQ_DB_UPGRADE: |
768 | case REQ_DB_UPGRADE: |
788 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
769 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
789 | break; |
770 | break; |
… | |
… | |
876 | case REQ_SEQ_REMOVE: |
857 | case REQ_SEQ_REMOVE: |
877 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
858 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
878 | break; |
859 | break; |
879 | #endif |
860 | #endif |
880 | |
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 | |
881 | default: |
870 | default: |
882 | req->result = ENOSYS; |
871 | req->result = ENOSYS; |
883 | break; |
872 | break; |
884 | } |
873 | } |
885 | |
874 | |
… | |
… | |
896 | /* try to distribute timeouts somewhat evenly */ |
885 | /* try to distribute timeouts somewhat evenly */ |
897 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
886 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
898 | |
887 | |
899 | for (;;) |
888 | for (;;) |
900 | { |
889 | { |
901 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
890 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
902 | |
891 | |
903 | X_LOCK (reqlock); |
892 | X_LOCK (reqlock); |
904 | |
893 | |
905 | for (;;) |
894 | for (;;) |
906 | { |
895 | { |
… | |
… | |
951 | X_LOCK (reslock); |
940 | X_LOCK (reslock); |
952 | |
941 | |
953 | ++npending; |
942 | ++npending; |
954 | |
943 | |
955 | if (!reqq_push (&res_queue, req)) |
944 | if (!reqq_push (&res_queue, req)) |
956 | /* write a dummy byte to the pipe so fh becomes ready */ |
945 | s_epipe_signal (&respipe); |
957 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
|
|
958 | |
946 | |
959 | self->req = 0; |
947 | self->req = 0; |
960 | worker_clear (self); |
948 | worker_clear (self); |
961 | |
949 | |
962 | X_UNLOCK (reslock); |
950 | X_UNLOCK (reslock); |
… | |
… | |
1038 | (void)0; |
1026 | (void)0; |
1039 | |
1027 | |
1040 | #define REQ_SEND \ |
1028 | #define REQ_SEND \ |
1041 | req_send (req) |
1029 | req_send (req) |
1042 | |
1030 | |
1043 | #define SvPTR(var, arg, type, class, nullok) \ |
1031 | #define SvPTR(var, arg, type, stash, class, nullok) \ |
1044 | if (!SvOK (arg)) \ |
1032 | if (!SvOK (arg)) \ |
1045 | { \ |
1033 | { \ |
1046 | if (nullok != 1) \ |
1034 | if (nullok != 1) \ |
1047 | croak (# var " must be a " # class " object, not undef"); \ |
1035 | croak (# var " must be a " # class " object, not undef"); \ |
1048 | \ |
1036 | \ |
1049 | (var) = 0; \ |
1037 | (var) = 0; \ |
1050 | } \ |
1038 | } \ |
1051 | else if (sv_derived_from ((arg), # class)) \ |
1039 | else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \ |
1052 | { \ |
1040 | { \ |
1053 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1041 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1054 | (var) = INT2PTR (type, tmp); \ |
1042 | (var) = INT2PTR (type, tmp); \ |
1055 | if (!var && nullok != 2) \ |
1043 | if (!var && nullok != 2) \ |
1056 | croak (# var " is not a valid " # class " object anymore"); \ |
1044 | croak (# var " is not a valid " # class " object anymore"); \ |
1057 | } \ |
1045 | } \ |
1058 | else \ |
1046 | else \ |
1059 | croak (# var " is not of type " # class); |
1047 | croak (# var " is not of type " # class); |
|
|
1048 | |
|
|
1049 | #define ARG_MUTABLE(name) \ |
|
|
1050 | if (SvREADONLY (name)) \ |
|
|
1051 | croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); |
|
|
1052 | |
|
|
1053 | static SV * |
|
|
1054 | newSVptr (void *ptr, HV *stash) |
|
|
1055 | { |
|
|
1056 | SV *rv = NEWSV (0, 0); |
|
|
1057 | sv_upgrade (rv, SVt_PVMG); |
|
|
1058 | sv_setiv (rv, PTR2IV (ptr)); |
|
|
1059 | |
|
|
1060 | return sv_bless (newRV_noinc (rv), stash); |
|
|
1061 | } |
1060 | |
1062 | |
1061 | static void |
1063 | static void |
1062 | ptr_nuke (SV *sv) |
1064 | ptr_nuke (SV *sv) |
1063 | { |
1065 | { |
1064 | assert (SvROK (sv)); |
1066 | assert (SvROK (sv)); |
… | |
… | |
1135 | } |
1137 | } |
1136 | |
1138 | |
1137 | return 0; |
1139 | return 0; |
1138 | } |
1140 | } |
1139 | |
1141 | |
|
|
1142 | /*****************************************************************************/ |
|
|
1143 | |
|
|
1144 | #if 0 |
|
|
1145 | static int |
|
|
1146 | bt_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 | |
|
|
1161 | static size_t |
|
|
1162 | bt_pfxc_prefix_x (DB *db, const DBT *dbt1, const DBT *dbt2) |
|
|
1163 | { |
|
|
1164 | ssize_t size1 = dbt1->size; |
|
|
1165 | ssize_t size2 = dbt2->size; |
|
|
1166 | u_int8_t *p1 = (u_int8_t *)dbt1->data; |
|
|
1167 | u_int8_t *p2 = (u_int8_t *)dbt2->data; |
|
|
1168 | u_int8_t *pe = p1 + (size1 <= size2 ? size1 : size2); |
|
|
1169 | |
|
|
1170 | while (p1 < pe) |
|
|
1171 | if (*p1++ != *p2++) |
|
|
1172 | return p1 - (u_int8_t *)dbt1->data - 1; |
|
|
1173 | |
|
|
1174 | if (size1 < size2) return size1 + 1; |
|
|
1175 | if (size1 > size2) return size2 + 1; |
|
|
1176 | |
|
|
1177 | return size1; |
|
|
1178 | } |
|
|
1179 | #endif |
|
|
1180 | |
|
|
1181 | /*****************************************************************************/ |
|
|
1182 | |
1140 | /* stupid windoes defined CALLBACK as well */ |
1183 | /* stupid windows defines CALLBACK as well */ |
1141 | #undef CALLBACK |
1184 | #undef CALLBACK |
1142 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
1185 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
1143 | |
1186 | |
1144 | MODULE = BDB PACKAGE = BDB |
1187 | MODULE = BDB PACKAGE = BDB |
1145 | |
1188 | |
1146 | PROTOTYPES: ENABLE |
1189 | PROTOTYPES: ENABLE |
1147 | |
1190 | |
1148 | BOOT: |
1191 | BOOT: |
1149 | { |
1192 | { |
1150 | HV *stash = gv_stashpv ("BDB", 1); |
1193 | bdb_stash = gv_stashpv ("BDB" , 1); |
|
|
1194 | bdb_env_stash = gv_stashpv ("BDB::Env" , 1); |
|
|
1195 | bdb_txn_stash = gv_stashpv ("BDB::Txn" , 1); |
|
|
1196 | bdb_cursor_stash = gv_stashpv ("BDB::Cursor" , 1); |
|
|
1197 | bdb_db_stash = gv_stashpv ("BDB::Db" , 1); |
|
|
1198 | bdb_sequence_stash = gv_stashpv ("BDB::Sequence", 1); |
1151 | |
1199 | |
1152 | static const struct { |
1200 | static const struct { |
1153 | const char *name; |
1201 | const char *name; |
1154 | IV iv; |
1202 | IV iv; |
1155 | } *civ, const_iv[] = { |
1203 | } *civ, const_iv[] = { |
… | |
… | |
1198 | const_iv (NOSYNC) |
1246 | const_iv (NOSYNC) |
1199 | const_iv (CHKSUM) |
1247 | const_iv (CHKSUM) |
1200 | const_iv (ENCRYPT) |
1248 | const_iv (ENCRYPT) |
1201 | const_iv (DUP) |
1249 | const_iv (DUP) |
1202 | const_iv (DUPSORT) |
1250 | const_iv (DUPSORT) |
1203 | const_iv (RECNUM) |
1251 | //const_iv (RECNUM) |
1204 | const_iv (RENUMBER) |
1252 | const_iv (RENUMBER) |
1205 | const_iv (REVSPLITOFF) |
1253 | const_iv (REVSPLITOFF) |
1206 | const_iv (CONSUME) |
1254 | const_iv (CONSUME) |
1207 | const_iv (CONSUME_WAIT) |
1255 | const_iv (CONSUME_WAIT) |
1208 | const_iv (GET_BOTH) |
1256 | const_iv (GET_BOTH) |
… | |
… | |
1280 | const_iv (REP_UNAVAIL) |
1328 | const_iv (REP_UNAVAIL) |
1281 | const_iv (RUNRECOVERY) |
1329 | const_iv (RUNRECOVERY) |
1282 | const_iv (SECONDARY_BAD) |
1330 | const_iv (SECONDARY_BAD) |
1283 | const_iv (VERIFY_BAD) |
1331 | const_iv (VERIFY_BAD) |
1284 | |
1332 | |
|
|
1333 | const_iv (SALVAGE) |
|
|
1334 | const_iv (AGGRESSIVE) |
|
|
1335 | const_iv (PRINTABLE) |
|
|
1336 | const_iv (NOORDERCHK) |
|
|
1337 | const_iv (ORDERCHKONLY) |
|
|
1338 | |
|
|
1339 | const_iv (ARCH_ABS) |
|
|
1340 | const_iv (ARCH_DATA) |
|
|
1341 | const_iv (ARCH_LOG) |
|
|
1342 | const_iv (ARCH_REMOVE) |
|
|
1343 | |
1285 | const_iv (VERB_DEADLOCK) |
1344 | const_iv (VERB_DEADLOCK) |
1286 | const_iv (VERB_RECOVERY) |
1345 | const_iv (VERB_RECOVERY) |
1287 | const_iv (VERB_REPLICATION) |
1346 | const_iv (VERB_REPLICATION) |
1288 | const_iv (VERB_WAITSFOR) |
1347 | const_iv (VERB_WAITSFOR) |
1289 | |
1348 | |
… | |
… | |
1322 | const_iv (PRIORITY_VERY_LOW) |
1381 | const_iv (PRIORITY_VERY_LOW) |
1323 | const_iv (PRIORITY_LOW) |
1382 | const_iv (PRIORITY_LOW) |
1324 | const_iv (PRIORITY_DEFAULT) |
1383 | const_iv (PRIORITY_DEFAULT) |
1325 | const_iv (PRIORITY_HIGH) |
1384 | const_iv (PRIORITY_HIGH) |
1326 | const_iv (PRIORITY_VERY_HIGH) |
1385 | const_iv (PRIORITY_VERY_HIGH) |
|
|
1386 | const_iv (IGNORE_LEASE) |
1327 | #endif |
1387 | #endif |
1328 | #if DB_VERSION_MINOR >= 7 |
1388 | #if DB_VERSION_MINOR >= 7 |
|
|
1389 | //const_iv (MULTIPLE_KEY) |
1329 | const_iv (LOG_DIRECT) |
1390 | const_iv (LOG_DIRECT) |
1330 | const_iv (LOG_DSYNC) |
1391 | const_iv (LOG_DSYNC) |
1331 | const_iv (LOG_AUTO_REMOVE) |
1392 | const_iv (LOG_AUTO_REMOVE) |
1332 | const_iv (LOG_IN_MEMORY) |
1393 | const_iv (LOG_IN_MEMORY) |
1333 | const_iv (LOG_ZERO) |
1394 | const_iv (LOG_ZERO) |
… | |
… | |
1340 | # endif |
1401 | # endif |
1341 | #endif |
1402 | #endif |
1342 | }; |
1403 | }; |
1343 | |
1404 | |
1344 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1405 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1345 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1406 | newCONSTSUB (bdb_stash, (char *)civ->name, newSViv (civ->iv)); |
1346 | |
1407 | |
1347 | prepare_cb = &PL_sv_undef; |
1408 | prepare_cb = &PL_sv_undef; |
1348 | |
1409 | |
1349 | { |
1410 | { |
1350 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
1411 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
1351 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
1412 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
1352 | |
1413 | |
1353 | newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); |
1414 | newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3)); |
1354 | } |
1415 | } |
1355 | |
1416 | |
1356 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1417 | newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1357 | |
1418 | |
1358 | create_respipe (); |
1419 | create_respipe (); |
1359 | |
1420 | |
1360 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1421 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1361 | patch_errno (); |
1422 | patch_errno (); |
… | |
… | |
1439 | |
1500 | |
1440 | int |
1501 | int |
1441 | poll_fileno () |
1502 | poll_fileno () |
1442 | PROTOTYPE: |
1503 | PROTOTYPE: |
1443 | CODE: |
1504 | CODE: |
1444 | RETVAL = respipe [0]; |
1505 | RETVAL = s_epipe_fd (&respipe); |
1445 | OUTPUT: |
1506 | OUTPUT: |
1446 | RETVAL |
1507 | RETVAL |
1447 | |
1508 | |
1448 | int |
1509 | int |
1449 | poll_cb (...) |
1510 | poll_cb (...) |
… | |
… | |
1550 | db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) |
1611 | db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) |
1551 | PREINIT: |
1612 | PREINIT: |
1552 | CALLBACK |
1613 | CALLBACK |
1553 | CODE: |
1614 | CODE: |
1554 | { |
1615 | { |
1555 | dREQ (REQ_ENV_CLOSE, 1); |
1616 | dREQ (REQ_ENV_CLOSE, 0); |
|
|
1617 | ptr_nuke (ST (0)); |
1556 | req->env = env; |
1618 | req->env = env; |
1557 | req->uint1 = flags; |
1619 | req->uint1 = flags; |
1558 | REQ_SEND; |
1620 | REQ_SEND; |
1559 | ptr_nuke (ST (0)); |
|
|
1560 | } |
1621 | } |
1561 | |
1622 | |
1562 | void |
1623 | void |
1563 | db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0) |
1624 | db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0) |
1564 | PREINIT: |
1625 | PREINIT: |
… | |
… | |
1633 | dREQ (REQ_ENV_DBRENAME, 2); |
1694 | dREQ (REQ_ENV_DBRENAME, 2); |
1634 | req->env = env; |
1695 | req->env = env; |
1635 | req->buf1 = strdup_ornull (file); |
1696 | req->buf1 = strdup_ornull (file); |
1636 | req->buf2 = strdup_ornull (database); |
1697 | req->buf2 = strdup_ornull (database); |
1637 | req->buf3 = strdup_ornull (newname); |
1698 | req->buf3 = strdup_ornull (newname); |
|
|
1699 | req->uint1 = flags; |
|
|
1700 | REQ_SEND; |
|
|
1701 | } |
|
|
1702 | |
|
|
1703 | void |
|
|
1704 | db_env_log_archive (DB_ENV *env, SV_mutable *listp, U32 flags = 0, SV *callback = 0) |
|
|
1705 | PREINIT: |
|
|
1706 | CALLBACK |
|
|
1707 | CODE: |
|
|
1708 | { |
|
|
1709 | dREQ (REQ_ENV_LOG_ARCHIVE, 1); |
|
|
1710 | req->sv1 = SvREFCNT_inc (listp); |
|
|
1711 | req->env = env; |
1638 | req->uint1 = flags; |
1712 | req->uint1 = flags; |
1639 | REQ_SEND; |
1713 | REQ_SEND; |
1640 | } |
1714 | } |
1641 | |
1715 | |
1642 | DB * |
1716 | DB * |
… | |
… | |
1674 | db_close (DB *db, U32 flags = 0, SV *callback = 0) |
1748 | db_close (DB *db, U32 flags = 0, SV *callback = 0) |
1675 | PREINIT: |
1749 | PREINIT: |
1676 | CALLBACK |
1750 | CALLBACK |
1677 | CODE: |
1751 | CODE: |
1678 | { |
1752 | { |
1679 | dREQ (REQ_DB_CLOSE, 1); |
1753 | dREQ (REQ_DB_CLOSE, 0); |
|
|
1754 | ptr_nuke (ST (0)); |
1680 | req->db = db; |
1755 | req->db = db; |
1681 | req->uint1 = flags; |
1756 | req->uint1 = flags; |
1682 | req->sv1 = (SV *)db->app_private; |
1757 | req->sv1 = (SV *)db->app_private; |
1683 | REQ_SEND; |
1758 | REQ_SEND; |
1684 | ptr_nuke (ST (0)); |
|
|
1685 | } |
1759 | } |
1686 | |
1760 | |
1687 | #if DB_VERSION_MINOR >= 4 |
1761 | #if DB_VERSION_MINOR >= 4 |
1688 | |
1762 | |
1689 | void |
1763 | void |
… | |
… | |
1693 | CODE: |
1767 | CODE: |
1694 | { |
1768 | { |
1695 | dREQ (REQ_DB_COMPACT, 2); |
1769 | dREQ (REQ_DB_COMPACT, 2); |
1696 | req->db = db; |
1770 | req->db = db; |
1697 | req->txn = txn; |
1771 | req->txn = txn; |
1698 | sv_to_dbt (&req->dbt1, start); |
1772 | if (start) sv_to_dbt (&req->dbt1, start); |
1699 | sv_to_dbt (&req->dbt2, stop); |
1773 | if (stop ) sv_to_dbt (&req->dbt2, stop ); |
1700 | req->uint1 = flags; |
1774 | req->uint1 = flags; |
1701 | REQ_SEND; |
1775 | REQ_SEND; |
1702 | } |
1776 | } |
1703 | |
1777 | |
1704 | #endif |
1778 | #endif |
… | |
… | |
1714 | req->uint1 = flags; |
1788 | req->uint1 = flags; |
1715 | REQ_SEND; |
1789 | REQ_SEND; |
1716 | } |
1790 | } |
1717 | |
1791 | |
1718 | void |
1792 | void |
|
|
1793 | db_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 | |
|
|
1807 | void |
1719 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) |
1808 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) |
1720 | PREINIT: |
1809 | PREINIT: |
1721 | CALLBACK |
1810 | CALLBACK |
1722 | CODE: |
1811 | CODE: |
1723 | { |
1812 | { |
1724 | dREQ (REQ_DB_SYNC, 1); |
1813 | dREQ (REQ_DB_UPGRADE, 1); |
1725 | req->db = db; |
1814 | req->db = db; |
1726 | req->buf1 = strdup (file); |
1815 | req->buf1 = strdup (file); |
1727 | req->uint1 = flags; |
1816 | req->uint1 = flags; |
1728 | REQ_SEND; |
1817 | REQ_SEND; |
1729 | } |
1818 | } |
1730 | |
1819 | |
1731 | void |
1820 | void |
1732 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = 0) |
1821 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *key_range, U32 flags = 0, SV *callback = 0) |
1733 | PREINIT: |
1822 | PREINIT: |
1734 | CALLBACK |
1823 | CALLBACK |
1735 | CODE: |
1824 | CODE: |
1736 | { |
1825 | { |
1737 | dREQ (REQ_DB_KEY_RANGE, 2); |
1826 | dREQ (REQ_DB_KEY_RANGE, 2); |
… | |
… | |
1775 | } |
1864 | } |
1776 | |
1865 | |
1777 | #endif |
1866 | #endif |
1778 | |
1867 | |
1779 | void |
1868 | void |
1780 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0) |
1869 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1781 | PREINIT: |
1870 | PREINIT: |
1782 | CALLBACK |
1871 | CALLBACK |
1783 | CODE: |
1872 | CODE: |
1784 | if (SvREADONLY (data)) |
|
|
1785 | croak ("can't modify read-only data scalar in db_get"); |
|
|
1786 | { |
1873 | { |
|
|
1874 | //TODO: key is somtimesmutable |
1787 | dREQ (REQ_DB_GET, 2); |
1875 | dREQ (REQ_DB_GET, 2); |
1788 | req->db = db; |
1876 | req->db = db; |
1789 | req->txn = txn; |
1877 | req->txn = txn; |
1790 | req->uint1 = flags; |
1878 | req->uint1 = flags; |
1791 | sv_to_dbt (&req->dbt1, key); |
1879 | sv_to_dbt (&req->dbt1, key); |
… | |
… | |
1793 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1881 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1794 | REQ_SEND; |
1882 | REQ_SEND; |
1795 | } |
1883 | } |
1796 | |
1884 | |
1797 | void |
1885 | void |
1798 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) |
1886 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1799 | PREINIT: |
1887 | PREINIT: |
1800 | CALLBACK |
1888 | CALLBACK |
1801 | CODE: |
1889 | CODE: |
1802 | if (SvREADONLY (data)) |
|
|
1803 | croak ("can't modify read-only data scalar in db_pget"); |
|
|
1804 | { |
1890 | { |
|
|
1891 | //TODO: key is somtimesmutable |
1805 | dREQ (REQ_DB_PGET, 2); |
1892 | dREQ (REQ_DB_PGET, 2); |
1806 | req->db = db; |
1893 | req->db = db; |
1807 | req->txn = txn; |
1894 | req->txn = txn; |
1808 | req->uint1 = flags; |
1895 | req->uint1 = flags; |
|
|
1896 | |
1809 | sv_to_dbt (&req->dbt1, key); |
1897 | sv_to_dbt (&req->dbt1, key); |
1810 | sv_to_dbt (&req->dbt2, pkey); |
1898 | |
|
|
1899 | req->dbt2.flags = DB_DBT_MALLOC; |
|
|
1900 | req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); |
|
|
1901 | |
1811 | req->dbt3.flags = DB_DBT_MALLOC; |
1902 | req->dbt3.flags = DB_DBT_MALLOC; |
1812 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1903 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1813 | REQ_SEND; |
1904 | REQ_SEND; |
1814 | } |
1905 | } |
1815 | |
1906 | |
… | |
… | |
1831 | db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
1922 | db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
1832 | PREINIT: |
1923 | PREINIT: |
1833 | CALLBACK |
1924 | CALLBACK |
1834 | CODE: |
1925 | CODE: |
1835 | { |
1926 | { |
1836 | dREQ (REQ_TXN_COMMIT, 1); |
1927 | dREQ (REQ_TXN_COMMIT, 0); |
|
|
1928 | ptr_nuke (ST (0)); |
1837 | req->txn = txn; |
1929 | req->txn = txn; |
1838 | req->uint1 = flags; |
1930 | req->uint1 = flags; |
1839 | REQ_SEND; |
1931 | REQ_SEND; |
|
|
1932 | } |
|
|
1933 | |
|
|
1934 | void |
|
|
1935 | db_txn_abort (DB_TXN *txn, SV *callback = 0) |
|
|
1936 | PREINIT: |
|
|
1937 | CALLBACK |
|
|
1938 | CODE: |
|
|
1939 | { |
|
|
1940 | dREQ (REQ_TXN_ABORT, 0); |
1840 | ptr_nuke (ST (0)); |
1941 | ptr_nuke (ST (0)); |
1841 | } |
|
|
1842 | |
|
|
1843 | void |
|
|
1844 | db_txn_abort (DB_TXN *txn, SV *callback = 0) |
|
|
1845 | PREINIT: |
|
|
1846 | CALLBACK |
|
|
1847 | CODE: |
|
|
1848 | { |
|
|
1849 | dREQ (REQ_TXN_ABORT, 1); |
|
|
1850 | req->txn = txn; |
1942 | req->txn = txn; |
1851 | REQ_SEND; |
1943 | REQ_SEND; |
|
|
1944 | } |
|
|
1945 | |
|
|
1946 | void |
|
|
1947 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
|
|
1948 | PREINIT: |
|
|
1949 | CALLBACK |
|
|
1950 | CODE: |
|
|
1951 | { |
|
|
1952 | dREQ (REQ_TXN_FINISH, 0); |
1852 | ptr_nuke (ST (0)); |
1953 | ptr_nuke (ST (0)); |
1853 | } |
|
|
1854 | |
|
|
1855 | void |
|
|
1856 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
|
|
1857 | PREINIT: |
|
|
1858 | CALLBACK |
|
|
1859 | CODE: |
|
|
1860 | { |
|
|
1861 | dREQ (REQ_TXN_FINISH, 1); |
|
|
1862 | req->txn = txn; |
1954 | req->txn = txn; |
1863 | req->uint1 = flags; |
1955 | req->uint1 = flags; |
1864 | REQ_SEND; |
1956 | REQ_SEND; |
|
|
1957 | } |
|
|
1958 | |
|
|
1959 | void |
|
|
1960 | db_c_close (DBC *dbc, SV *callback = 0) |
|
|
1961 | PREINIT: |
|
|
1962 | CALLBACK |
|
|
1963 | CODE: |
|
|
1964 | { |
|
|
1965 | dREQ (REQ_C_CLOSE, 0); |
1865 | ptr_nuke (ST (0)); |
1966 | ptr_nuke (ST (0)); |
1866 | } |
|
|
1867 | |
|
|
1868 | void |
|
|
1869 | db_c_close (DBC *dbc, SV *callback = 0) |
|
|
1870 | PREINIT: |
|
|
1871 | CALLBACK |
|
|
1872 | CODE: |
|
|
1873 | { |
|
|
1874 | dREQ (REQ_C_CLOSE, 1); |
|
|
1875 | req->dbc = dbc; |
1967 | req->dbc = dbc; |
1876 | REQ_SEND; |
1968 | REQ_SEND; |
1877 | ptr_nuke (ST (0)); |
|
|
1878 | } |
1969 | } |
1879 | |
1970 | |
1880 | void |
1971 | void |
1881 | db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0) |
1972 | db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0) |
1882 | PREINIT: |
1973 | PREINIT: |
… | |
… | |
1902 | req->uint1 = flags; |
1993 | req->uint1 = flags; |
1903 | REQ_SEND; |
1994 | REQ_SEND; |
1904 | } |
1995 | } |
1905 | |
1996 | |
1906 | void |
1997 | void |
1907 | db_c_get (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0) |
1998 | db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1908 | PREINIT: |
1999 | PREINIT: |
1909 | CALLBACK |
2000 | CALLBACK |
1910 | CODE: |
2001 | CODE: |
1911 | { |
2002 | { |
|
|
2003 | if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key)) |
|
|
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"); |
|
|
2009 | |
|
|
2010 | { |
1912 | dREQ (REQ_C_GET, 1); |
2011 | dREQ (REQ_C_GET, 1); |
1913 | req->dbc = dbc; |
2012 | req->dbc = dbc; |
1914 | req->uint1 = flags; |
2013 | req->uint1 = flags; |
1915 | if ((flags & DB_SET) == DB_SET |
2014 | if ((flags & DB_OPFLAGS_MASK) == DB_SET) |
1916 | || (flags & DB_SET_RANGE) == DB_SET_RANGE) |
|
|
1917 | sv_to_dbt (&req->dbt1, key); |
2015 | sv_to_dbt (&req->dbt1, key); |
1918 | else |
2016 | else |
|
|
2017 | { |
|
|
2018 | if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE) |
|
|
2019 | sv_to_dbt (&req->dbt1, key); |
|
|
2020 | else |
1919 | req->dbt1.flags = DB_DBT_MALLOC; |
2021 | req->dbt1.flags = DB_DBT_MALLOC; |
1920 | |
2022 | |
1921 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
2023 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
|
|
2024 | } |
1922 | |
2025 | |
1923 | if ((flags & DB_GET_BOTH) == DB_GET_BOTH |
2026 | if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH |
1924 | || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE) |
2027 | || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE) |
1925 | sv_to_dbt (&req->dbt3, data); |
2028 | sv_to_dbt (&req->dbt3, data); |
1926 | else |
2029 | else |
1927 | req->dbt3.flags = DB_DBT_MALLOC; |
2030 | req->dbt3.flags = DB_DBT_MALLOC; |
1928 | |
2031 | |
1929 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
2032 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1930 | REQ_SEND; |
2033 | REQ_SEND; |
|
|
2034 | } |
1931 | } |
2035 | } |
1932 | |
2036 | |
1933 | void |
2037 | void |
1934 | db_c_pget (DBC *dbc, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) |
2038 | db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1935 | PREINIT: |
2039 | PREINIT: |
1936 | CALLBACK |
2040 | CALLBACK |
1937 | CODE: |
2041 | CODE: |
1938 | { |
2042 | { |
|
|
2043 | if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key)) |
|
|
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"); |
|
|
2049 | |
|
|
2050 | { |
1939 | dREQ (REQ_C_PGET, 1); |
2051 | dREQ (REQ_C_PGET, 1); |
1940 | req->dbc = dbc; |
2052 | req->dbc = dbc; |
1941 | req->uint1 = flags; |
2053 | req->uint1 = flags; |
1942 | if ((flags & DB_SET) == DB_SET |
2054 | if ((flags & DB_OPFLAGS_MASK) == DB_SET) |
1943 | || (flags & DB_SET_RANGE) == DB_SET_RANGE) |
|
|
1944 | sv_to_dbt (&req->dbt1, key); |
2055 | sv_to_dbt (&req->dbt1, key); |
1945 | else |
2056 | else |
|
|
2057 | { |
|
|
2058 | if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE) |
|
|
2059 | sv_to_dbt (&req->dbt1, key); |
|
|
2060 | else |
|
|
2061 | req->dbt1.flags = DB_DBT_MALLOC; |
|
|
2062 | |
|
|
2063 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
|
|
2064 | } |
|
|
2065 | |
1946 | req->dbt1.flags = DB_DBT_MALLOC; |
2066 | req->dbt2.flags = DB_DBT_MALLOC; |
1947 | |
|
|
1948 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
|
|
1949 | |
|
|
1950 | req->dbt2.flags = DB_DBT_MALLOC; |
|
|
1951 | req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); |
2067 | req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); |
1952 | |
2068 | |
1953 | if ((flags & DB_GET_BOTH) == DB_GET_BOTH |
2069 | if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH |
1954 | || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE) |
2070 | || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE) |
1955 | sv_to_dbt (&req->dbt3, data); |
2071 | sv_to_dbt (&req->dbt3, data); |
1956 | else |
2072 | else |
1957 | req->dbt3.flags = DB_DBT_MALLOC; |
2073 | req->dbt3.flags = DB_DBT_MALLOC; |
1958 | |
2074 | |
1959 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
2075 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1960 | REQ_SEND; |
2076 | REQ_SEND; |
|
|
2077 | } |
1961 | } |
2078 | } |
1962 | |
2079 | |
1963 | void |
2080 | void |
1964 | db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) |
2081 | db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) |
1965 | PREINIT: |
2082 | PREINIT: |
… | |
… | |
1993 | db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) |
2110 | db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) |
1994 | PREINIT: |
2111 | PREINIT: |
1995 | CALLBACK |
2112 | CALLBACK |
1996 | CODE: |
2113 | CODE: |
1997 | { |
2114 | { |
1998 | dREQ (REQ_SEQ_CLOSE, 1); |
2115 | dREQ (REQ_SEQ_CLOSE, 0); |
|
|
2116 | ptr_nuke (ST (0)); |
1999 | req->seq = seq; |
2117 | req->seq = seq; |
2000 | req->uint1 = flags; |
2118 | req->uint1 = flags; |
2001 | REQ_SEND; |
2119 | REQ_SEND; |
2002 | ptr_nuke (ST (0)); |
|
|
2003 | } |
2120 | } |
2004 | |
2121 | |
2005 | void |
2122 | void |
2006 | db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0) |
2123 | db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV_mutable *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0) |
2007 | PREINIT: |
2124 | PREINIT: |
2008 | CALLBACK |
2125 | CALLBACK |
2009 | CODE: |
2126 | CODE: |
2010 | { |
2127 | { |
2011 | dREQ (REQ_SEQ_GET, 2); |
2128 | dREQ (REQ_SEQ_GET, 2); |
… | |
… | |
2240 | CODE: |
2357 | CODE: |
2241 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
2358 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
2242 | OUTPUT: |
2359 | OUTPUT: |
2243 | RETVAL |
2360 | RETVAL |
2244 | |
2361 | |
|
|
2362 | int set_pagesize (DB *db, U32 pagesize) |
|
|
2363 | CODE: |
|
|
2364 | RETVAL = db->set_pagesize (db, pagesize); |
|
|
2365 | OUTPUT: |
|
|
2366 | RETVAL |
|
|
2367 | |
2245 | int set_flags (DB *db, U32 flags) |
2368 | int set_flags (DB *db, U32 flags) |
2246 | CODE: |
2369 | CODE: |
2247 | RETVAL = db->set_flags (db, flags); |
2370 | RETVAL = db->set_flags (db, flags); |
2248 | OUTPUT: |
2371 | OUTPUT: |
2249 | RETVAL |
2372 | RETVAL |