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

Comparing BDB/BDB.xs (file contents):
Revision 1.51 by root, Thu Sep 25 13:28:37 2008 UTC vs.
Revision 1.73 by root, Tue Dec 8 17:09:06 2009 UTC

1#include <sys/user.h>
2#include <sys/ptrace.h>
3
4#define X_STACKSIZE 1024 * 128 + sizeof (long) * 64 * 1024 / 4 1#define X_STACKSIZE 1024 * 128 + sizeof (long) * 64 * 1024 / 4
5 2
6#include "xthread.h" 3#include "xthread.h"
7 4
8#include <errno.h> 5#include <errno.h>
9 6
10#include "EXTERN.h" 7#include "EXTERN.h"
11#include "perl.h" 8#include "perl.h"
12#include "XSUB.h" 9#include "XSUB.h"
13 10
11#include "schmorp.h"
12
14// perl stupidly defines these as macros, breaking 13// perl stupidly defines these as argument-less macros, breaking
15// lots and lots of code. 14// lots and lots of code.
16#undef open 15#undef open
17#undef close 16#undef close
18#undef abort 17#undef abort
19#undef malloc 18#undef malloc
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
43typedef SV SV_mutable;
44
44typedef DB_ENV DB_ENV_ornull; 45typedef DB_ENV DB_ENV_ornull;
45typedef DB_TXN DB_TXN_ornull; 46typedef DB_TXN DB_TXN_ornull;
46typedef DBC DBC_ornull; 47typedef DBC DBC_ornull;
47typedef DB DB_ornull; 48typedef DB DB_ornull;
48 49
54#if DB_VERSION_MINOR >= 3 55#if DB_VERSION_MINOR >= 3
55typedef DB_SEQUENCE DB_SEQUENCE_ornull; 56typedef DB_SEQUENCE DB_SEQUENCE_ornull;
56typedef DB_SEQUENCE DB_SEQUENCE_ornuked; 57typedef DB_SEQUENCE DB_SEQUENCE_ornuked;
57#endif 58#endif
58 59
59typedef SV SV8; /* byte-sv, used for argument-checking */
60typedef char *bdb_filename; 60typedef char *bdb_filename;
61 61
62static SV *prepare_cb; 62static SV *prepare_cb;
63
64static HV
65 *bdb_stash,
66 *bdb_env_stash,
67 *bdb_txn_stash,
68 *bdb_cursor_stash,
69 *bdb_db_stash,
70 *bdb_sequence_stash;
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
135dbt_to_sv (SV *sv, DBT *dbt) 143dbt_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
148enum { 160enum {
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
244static volatile unsigned int nreqs, nready, npending; 257static volatile unsigned int nreqs, nready, npending;
245static volatile unsigned int max_idle = 4; 258static volatile unsigned int max_idle = 4;
246static volatile unsigned int max_outstanding = 0xffffffff; 259static volatile unsigned int max_outstanding = 0xffffffff;
247static int respipe_osf [2], respipe [2] = { -1, -1 }; 260static s_epipe respipe;
248 261
249static mutex_t reslock = X_MUTEX_INIT; 262static mutex_t reslock = X_MUTEX_INIT;
250static mutex_t reqlock = X_MUTEX_INIT; 263static mutex_t reqlock = X_MUTEX_INIT;
251static cond_t reqwait = X_COND_INIT; 264static cond_t reqwait = X_COND_INIT;
252 265
347 abort (); 360 abort ();
348} 361}
349 362
350static int poll_cb (void); 363static int poll_cb (void);
351static void req_free (bdb_req req); 364static void req_free (bdb_req req);
352static void req_cancel (bdb_req req);
353 365
354static int req_invoke (bdb_req req) 366static int req_invoke (bdb_req req)
355{ 367{
356 dSP; 368 switch (req->type)
369 {
370 case REQ_DB_CLOSE:
371 SvREFCNT_dec (req->sv1);
372 break;
373
374 case REQ_DB_GET:
375 case REQ_DB_PGET:
376 case REQ_C_GET:
377 case REQ_C_PGET:
378 case REQ_DB_PUT:
379 case REQ_C_PUT:
380 dbt_to_sv (req->sv1, &req->dbt1);
381 dbt_to_sv (req->sv2, &req->dbt2);
382 dbt_to_sv (req->sv3, &req->dbt3);
383 break;
384
385 case REQ_DB_KEY_RANGE:
386 {
387 AV *av = newAV ();
388
389 av_push (av, newSVnv (req->key_range.less));
390 av_push (av, newSVnv (req->key_range.equal));
391 av_push (av, newSVnv (req->key_range.greater));
392
393 av = (AV *)newRV_noinc ((SV *)av);
394
395 SvREADONLY_off (req->sv1);
396 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av));
397 SvREFCNT_dec (av);
398 SvREFCNT_dec (req->sv1);
399 }
400 break;
401
402#if DB_VERSION_MINOR >= 3
403 case REQ_SEQ_GET:
404 SvREADONLY_off (req->sv1);
405
406 if (sizeof (IV) > 4)
407 sv_setiv_mg (req->sv1, (IV)req->seq_t);
408 else
409 sv_setnv_mg (req->sv1, (NV)req->seq_t);
410
411 SvREFCNT_dec (req->sv1);
412 break;
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;
432 }
433
434 errno = req->result;
357 435
358 if (req->callback) 436 if (req->callback)
359 { 437 {
438 dSP;
439
360 ENTER; 440 ENTER;
361 SAVETMPS; 441 SAVETMPS;
362 PUSHMARK (SP); 442 PUSHMARK (SP);
363 443
364 switch (req->type)
365 {
366 case REQ_DB_CLOSE:
367 SvREFCNT_dec (req->sv1);
368 break;
369
370 case REQ_DB_GET:
371 case REQ_DB_PGET:
372 dbt_to_sv (req->sv3, &req->dbt3);
373 break;
374
375 case REQ_C_GET:
376 case REQ_C_PGET:
377 dbt_to_sv (req->sv1, &req->dbt1);
378 dbt_to_sv (req->sv2, &req->dbt2);
379 dbt_to_sv (req->sv3, &req->dbt3);
380 break;
381
382 case REQ_DB_PUT:
383 case REQ_C_PUT:
384 dbt_to_sv (0, &req->dbt1);
385 dbt_to_sv (0, &req->dbt2);
386 break;
387
388 case REQ_DB_KEY_RANGE:
389 {
390 AV *av = newAV ();
391
392 av_push (av, newSVnv (req->key_range.less));
393 av_push (av, newSVnv (req->key_range.equal));
394 av_push (av, newSVnv (req->key_range.greater));
395
396 SvREADONLY_off (req->sv1);
397 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av));
398 SvREFCNT_dec (req->sv1);
399 }
400 break;
401
402#if DB_VERSION_MINOR >= 3
403 case REQ_SEQ_GET:
404 SvREADONLY_off (req->sv1);
405
406 if (sizeof (IV) > 4)
407 sv_setiv_mg (req->sv1, (IV)req->seq_t);
408 else
409 sv_setnv_mg (req->sv1, (NV)req->seq_t);
410
411 SvREFCNT_dec (req->sv1);
412 break;
413#endif
414 }
415
416 errno = req->result;
417
418 PUTBACK; 444 PUTBACK;
419 call_sv (req->callback, G_VOID | G_EVAL); 445 call_sv (req->callback, G_VOID | G_EVAL);
420 SPAGAIN; 446 SPAGAIN;
421 447
422 FREETMPS; 448 FREETMPS;
423 LEAVE; 449 LEAVE;
450
451 return !SvTRUE (ERRSV);
424 } 452 }
425 453
426 return !SvTRUE (ERRSV); 454 return 1;
427} 455}
428 456
429static void req_free (bdb_req req) 457static void req_free (bdb_req req)
430{ 458{
431 SvREFCNT_dec (req->callback); 459 SvREFCNT_dec (req->callback);
438 free (req->buf3); 466 free (req->buf3);
439 467
440 Safefree (req); 468 Safefree (req);
441} 469}
442 470
443#ifdef USE_SOCKETS_AS_HANDLES
444# define TO_SOCKET(x) (win32_get_osfhandle (x))
445#else
446# define TO_SOCKET(x) (x)
447#endif
448
449static void 471static void
450create_respipe (void) 472create_respipe (void)
451{ 473{
452#ifdef _WIN32
453 int arg; /* argg */
454#endif
455 int old_readfd = respipe [0];
456
457 if (respipe [1] >= 0)
458 respipe_close (TO_SOCKET (respipe [1]));
459
460#ifdef _WIN32
461 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe))
462#else
463 if (pipe (respipe)) 474 if (s_epipe_renew (&respipe))
464#endif 475 croak ("BDB: unable to create event pipe");
465 croak ("unable to initialize result pipe");
466
467 if (old_readfd >= 0)
468 {
469 if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0)
470 croak ("unable to initialize result pipe(2)");
471
472 respipe_close (respipe [0]);
473 respipe [0] = old_readfd;
474 }
475
476#ifdef _WIN32
477 arg = 1;
478 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg)
479 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg))
480#else
481 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
482 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
483#endif
484 croak ("unable to initialize result pipe(3)");
485
486 respipe_osf [0] = TO_SOCKET (respipe [0]);
487 respipe_osf [1] = TO_SOCKET (respipe [1]);
488} 476}
489 477
478static void bdb_request (bdb_req req);
490X_THREAD_PROC (bdb_proc); 479X_THREAD_PROC (bdb_proc);
491 480
492static void start_thread (void) 481static void start_thread (void)
493{ 482{
494 worker *wrk = calloc (1, sizeof (worker)); 483 worker *wrk = calloc (1, sizeof (worker));
541 } 530 }
542 531
543 // synthesize callback if none given 532 // synthesize callback if none given
544 if (!req->callback) 533 if (!req->callback)
545 { 534 {
535 if (SvOK (prepare_cb))
536 {
546 int count; 537 int count;
547 538
548 dSP; 539 dSP;
549 PUSHMARK (SP); 540 PUSHMARK (SP);
550 PUTBACK; 541 PUTBACK;
551 count = call_sv (prepare_cb, G_ARRAY); 542 count = call_sv (prepare_cb, G_ARRAY);
552 SPAGAIN; 543 SPAGAIN;
553 544
554 if (count != 2) 545 if (count != 2)
555 croak ("prepare callback must return exactly two values\n"); 546 croak ("sync prepare callback must return exactly two values\n");
556 547
557 wait_callback = POPs; 548 wait_callback = POPs;
558 req->callback = SvREFCNT_inc (POPs); 549 req->callback = SvREFCNT_inc (POPs);
550 }
551 else
552 {
553 // execute request synchronously
554 bdb_request (req);
555 req_invoke (req);
556 req_free (req);
557 return;
558 }
559 } 559 }
560 560
561 ++nreqs; 561 ++nreqs;
562 562
563 X_LOCK (reqlock); 563 X_LOCK (reqlock);
577 } 577 }
578} 578}
579 579
580static void end_thread (void) 580static void end_thread (void)
581{ 581{
582 bdb_req req; 582 bdb_req req = calloc (1, sizeof (bdb_cb));
583
584 Newz (0, req, 1, bdb_cb);
585 583
586 req->type = REQ_QUIT; 584 req->type = REQ_QUIT;
587 req->pri = PRI_MAX + PRI_BIAS; 585 req->pri = PRI_MAX + PRI_BIAS;
588 586
589 X_LOCK (reqlock); 587 X_LOCK (reqlock);
618 end_thread (); 616 end_thread ();
619} 617}
620 618
621static void poll_wait (void) 619static void poll_wait (void)
622{ 620{
623 fd_set rfd;
624
625 while (nreqs) 621 while (nreqs)
626 { 622 {
627 int size; 623 int size;
628 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 624 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
629 size = res_queue.size; 625 size = res_queue.size;
632 if (size) 628 if (size)
633 return; 629 return;
634 630
635 maybe_start_thread (); 631 maybe_start_thread ();
636 632
637 FD_ZERO (&rfd); 633 s_epipe_wait (&respipe);
638 FD_SET (respipe [0], &rfd);
639
640 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
641 } 634 }
642} 635}
643 636
644static int poll_cb (void) 637static int poll_cb (void)
645{ 638{
665 if (req) 658 if (req)
666 { 659 {
667 --npending; 660 --npending;
668 661
669 if (!res_queue.size) 662 if (!res_queue.size)
670 {
671 /* read any signals sent by the worker threads */ 663 /* read any signals sent by the worker threads */
672 char buf [4]; 664 s_epipe_drain (&respipe);
673 while (respipe_read (respipe [0], buf, 4) == 4)
674 ;
675 }
676 } 665 }
677 666
678 X_UNLOCK (reslock); 667 X_UNLOCK (reslock);
679 668
680 if (!req) 669 if (!req)
762 req->result = req->db->close (req->db, req->uint1); 751 req->result = req->db->close (req->db, req->uint1);
763 break; 752 break;
764 753
765#if DB_VERSION_MINOR >= 4 754#if DB_VERSION_MINOR >= 4
766 case REQ_DB_COMPACT: 755 case REQ_DB_COMPACT:
767 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);
768 break; 757 break;
769#endif 758#endif
770 759
771 case REQ_DB_SYNC: 760 case REQ_DB_SYNC:
772 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);
773 break; 766 break;
774 767
775 case REQ_DB_UPGRADE: 768 case REQ_DB_UPGRADE:
776 req->result = req->db->upgrade (req->db, req->buf1, req->uint1); 769 req->result = req->db->upgrade (req->db, req->buf1, req->uint1);
777 break; 770 break;
864 case REQ_SEQ_REMOVE: 857 case REQ_SEQ_REMOVE:
865 req->result = req->seq->remove (req->seq, req->txn, req->uint1); 858 req->result = req->seq->remove (req->seq, req->txn, req->uint1);
866 break; 859 break;
867#endif 860#endif
868 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
869 default: 870 default:
870 req->result = ENOSYS; 871 req->result = ENOSYS;
871 break; 872 break;
872 } 873 }
873 874
884 /* try to distribute timeouts somewhat evenly */ 885 /* try to distribute timeouts somewhat evenly */
885 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 886 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
886 887
887 for (;;) 888 for (;;)
888 { 889 {
889 ts.tv_sec = time (0) + IDLE_TIMEOUT; 890 ts.tv_sec = time (0) + IDLE_TIMEOUT;
890 891
891 X_LOCK (reqlock); 892 X_LOCK (reqlock);
892 893
893 for (;;) 894 for (;;)
894 { 895 {
923 --nready; 924 --nready;
924 925
925 X_UNLOCK (reqlock); 926 X_UNLOCK (reqlock);
926 927
927 if (req->type == REQ_QUIT) 928 if (req->type == REQ_QUIT)
929 {
930 X_LOCK (reslock);
931 free (req);
932 self->req = 0;
933 X_UNLOCK (reslock);
934
928 goto quit; 935 goto quit;
936 }
929 937
930 bdb_request (req); 938 bdb_request (req);
931 939
932 X_LOCK (reslock); 940 X_LOCK (reslock);
933 941
934 ++npending; 942 ++npending;
935 943
936 if (!reqq_push (&res_queue, req)) 944 if (!reqq_push (&res_queue, req))
937 /* write a dummy byte to the pipe so fh becomes ready */ 945 s_epipe_signal (&respipe);
938 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
939 946
940 self->req = 0; 947 self->req = 0;
941 worker_clear (self); 948 worker_clear (self);
942 949
943 X_UNLOCK (reslock); 950 X_UNLOCK (reslock);
1019 (void)0; 1026 (void)0;
1020 1027
1021#define REQ_SEND \ 1028#define REQ_SEND \
1022 req_send (req) 1029 req_send (req)
1023 1030
1024#define SvPTR(var, arg, type, class, nullok) \ 1031#define SvPTR(var, arg, type, stash, class, nullok) \
1025 if (!SvOK (arg)) \ 1032 if (!SvOK (arg)) \
1026 { \ 1033 { \
1027 if (nullok != 1) \ 1034 if (nullok != 1) \
1028 croak (# var " must be a " # class " object, not undef"); \ 1035 croak (# var " must be a " # class " object, not undef"); \
1029 \ 1036 \
1030 (var) = 0; \ 1037 (var) = 0; \
1031 } \ 1038 } \
1032 else if (sv_derived_from ((arg), # class)) \ 1039 else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \
1033 { \ 1040 { \
1034 IV tmp = SvIV ((SV*) SvRV (arg)); \ 1041 IV tmp = SvIV ((SV*) SvRV (arg)); \
1035 (var) = INT2PTR (type, tmp); \ 1042 (var) = INT2PTR (type, tmp); \
1036 if (!var && nullok != 2) \ 1043 if (!var && nullok != 2) \
1037 croak (# var " is not a valid " # class " object anymore"); \ 1044 croak (# var " is not a valid " # class " object anymore"); \
1038 } \ 1045 } \
1039 else \ 1046 else \
1040 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
1053static SV *
1054newSVptr (void *ptr, HV *stash)
1055{
1056 SV *rv = NEWSV (0, 0);
1057 sv_upgrade (rv, SVt_PVMG);
1058 sv_setiv (rv, PTR2IV (ptr));
1059
1060 return sv_bless (newRV_noinc (rv), stash);
1061}
1041 1062
1042static void 1063static void
1043ptr_nuke (SV *sv) 1064ptr_nuke (SV *sv)
1044{ 1065{
1045 assert (SvROK (sv)); 1066 assert (SvROK (sv));
1116 } 1137 }
1117 1138
1118 return 0; 1139 return 0;
1119} 1140}
1120 1141
1142/*****************************************************************************/
1143
1144#if 0
1145static int
1146bt_pfxc_compare (DB *db, const DBT *dbt1, const DBT *dbt2)
1147{
1148 ssize_t size1 = dbt1->size;
1149 ssize_t size2 = dbt2->size;
1150 int res = memcmp ((void *)dbt1->data, (void *)dbt2->data,
1151 size1 <= size2 ? size1 : size2);
1152
1153 if (res)
1154 return res;
1155 else if (size1 - size2)
1156 return size1 - size2;
1157 else
1158 return 0;
1159}
1160
1161static size_t
1162bt_pfxc_prefix_x (DB *db, const DBT *dbt1, const DBT *dbt2)
1163{
1164 ssize_t size1 = dbt1->size;
1165 ssize_t size2 = dbt2->size;
1166 u_int8_t *p1 = (u_int8_t *)dbt1->data;
1167 u_int8_t *p2 = (u_int8_t *)dbt2->data;
1168 u_int8_t *pe = p1 + (size1 <= size2 ? size1 : size2);
1169
1170 while (p1 < pe)
1171 if (*p1++ != *p2++)
1172 return p1 - (u_int8_t *)dbt1->data - 1;
1173
1174 if (size1 < size2) return size1 + 1;
1175 if (size1 > size2) return size2 + 1;
1176
1177 return size1;
1178}
1179#endif
1180
1181/*****************************************************************************/
1182
1121/* stupid windoes defined CALLBACK as well */ 1183/* stupid windows defines CALLBACK as well */
1122#undef CALLBACK 1184#undef CALLBACK
1123#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); 1185#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1));
1124 1186
1125MODULE = BDB PACKAGE = BDB 1187MODULE = BDB PACKAGE = BDB
1126 1188
1127PROTOTYPES: ENABLE 1189PROTOTYPES: ENABLE
1128 1190
1129BOOT: 1191BOOT:
1130{ 1192{
1131 HV *stash = gv_stashpv ("BDB", 1);
1132
1133 static const struct { 1193 static const struct {
1134 const char *name; 1194 const char *name;
1135 IV iv; 1195 IV iv;
1136 } *civ, const_iv[] = { 1196 } *civ, const_iv[] = {
1137#define const_iv(name) { # name, (IV)DB_ ## name }, 1197#define const_iv(name) { # name, (IV)DB_ ## name },
1166 const_iv (TXN_NOT_DURABLE) 1226 const_iv (TXN_NOT_DURABLE)
1167 const_iv (TXN_WRITE_NOSYNC) 1227 const_iv (TXN_WRITE_NOSYNC)
1168 const_iv (WRITECURSOR) 1228 const_iv (WRITECURSOR)
1169 const_iv (YIELDCPU) 1229 const_iv (YIELDCPU)
1170 const_iv (ENCRYPT_AES) 1230 const_iv (ENCRYPT_AES)
1231#if DB_VERSION_MINOR < 8
1171 const_iv (XA_CREATE) 1232 const_iv (XA_CREATE)
1233#endif
1172 const_iv (BTREE) 1234 const_iv (BTREE)
1173 const_iv (HASH) 1235 const_iv (HASH)
1174 const_iv (QUEUE) 1236 const_iv (QUEUE)
1175 const_iv (RECNO) 1237 const_iv (RECNO)
1176 const_iv (UNKNOWN) 1238 const_iv (UNKNOWN)
1179 const_iv (NOSYNC) 1241 const_iv (NOSYNC)
1180 const_iv (CHKSUM) 1242 const_iv (CHKSUM)
1181 const_iv (ENCRYPT) 1243 const_iv (ENCRYPT)
1182 const_iv (DUP) 1244 const_iv (DUP)
1183 const_iv (DUPSORT) 1245 const_iv (DUPSORT)
1184 const_iv (RECNUM) 1246 //const_iv (RECNUM)
1185 const_iv (RENUMBER) 1247 const_iv (RENUMBER)
1186 const_iv (REVSPLITOFF) 1248 const_iv (REVSPLITOFF)
1187 const_iv (CONSUME) 1249 const_iv (CONSUME)
1188 const_iv (CONSUME_WAIT) 1250 const_iv (CONSUME_WAIT)
1189 const_iv (GET_BOTH) 1251 const_iv (GET_BOTH)
1240 const_iv (LOCK_OLDEST) 1302 const_iv (LOCK_OLDEST)
1241 const_iv (LOCK_RANDOM) 1303 const_iv (LOCK_RANDOM)
1242 const_iv (LOCK_YOUNGEST) 1304 const_iv (LOCK_YOUNGEST)
1243 1305
1244 const_iv (DONOTINDEX) 1306 const_iv (DONOTINDEX)
1245 const_iv (KEYEMPTY ) 1307 const_iv (KEYEMPTY)
1246 const_iv (KEYEXIST ) 1308 const_iv (KEYEXIST)
1247 const_iv (LOCK_DEADLOCK) 1309 const_iv (LOCK_DEADLOCK)
1248 const_iv (LOCK_NOTGRANTED) 1310 const_iv (LOCK_NOTGRANTED)
1249 const_iv (NOSERVER) 1311 const_iv (NOSERVER)
1250 const_iv (NOSERVER_HOME) 1312 const_iv (NOSERVER_HOME)
1251 const_iv (NOSERVER_ID) 1313 const_iv (NOSERVER_ID)
1261 const_iv (REP_UNAVAIL) 1323 const_iv (REP_UNAVAIL)
1262 const_iv (RUNRECOVERY) 1324 const_iv (RUNRECOVERY)
1263 const_iv (SECONDARY_BAD) 1325 const_iv (SECONDARY_BAD)
1264 const_iv (VERIFY_BAD) 1326 const_iv (VERIFY_BAD)
1265 1327
1328 const_iv (SALVAGE)
1329 const_iv (AGGRESSIVE)
1330 const_iv (PRINTABLE)
1331 const_iv (NOORDERCHK)
1332 const_iv (ORDERCHKONLY)
1333
1334 const_iv (ARCH_ABS)
1335 const_iv (ARCH_DATA)
1336 const_iv (ARCH_LOG)
1337 const_iv (ARCH_REMOVE)
1338
1266 const_iv (VERB_DEADLOCK) 1339 const_iv (VERB_DEADLOCK)
1267 const_iv (VERB_RECOVERY) 1340 const_iv (VERB_RECOVERY)
1268 const_iv (VERB_REPLICATION) 1341 const_iv (VERB_REPLICATION)
1269 const_iv (VERB_WAITSFOR) 1342 const_iv (VERB_WAITSFOR)
1270 1343
1271 const_iv (VERSION_MAJOR) 1344 const_iv (VERSION_MAJOR)
1272 const_iv (VERSION_MINOR) 1345 const_iv (VERSION_MINOR)
1273 const_iv (VERSION_PATCH) 1346 const_iv (VERSION_PATCH)
1347 const_iv (LOGVERSION)
1348 const_iv (LOGOLDVER)
1274#if DB_VERSION_MINOR >= 3 1349#if DB_VERSION_MINOR >= 3
1275 const_iv (INORDER) 1350 const_iv (INORDER)
1276 const_iv (LOCK_MAXWRITE) 1351 const_iv (LOCK_MAXWRITE)
1277 const_iv (SEQ_DEC) 1352 const_iv (SEQ_DEC)
1278 const_iv (SEQ_INC) 1353 const_iv (SEQ_INC)
1303 const_iv (PRIORITY_VERY_LOW) 1378 const_iv (PRIORITY_VERY_LOW)
1304 const_iv (PRIORITY_LOW) 1379 const_iv (PRIORITY_LOW)
1305 const_iv (PRIORITY_DEFAULT) 1380 const_iv (PRIORITY_DEFAULT)
1306 const_iv (PRIORITY_HIGH) 1381 const_iv (PRIORITY_HIGH)
1307 const_iv (PRIORITY_VERY_HIGH) 1382 const_iv (PRIORITY_VERY_HIGH)
1383 const_iv (IGNORE_LEASE)
1308#endif 1384#endif
1309#if DB_VERSION_MINOR >= 7 1385#if DB_VERSION_MINOR >= 7
1386 //const_iv (MULTIPLE_KEY)
1310 const_iv (LOG_DIRECT) 1387 const_iv (LOG_DIRECT)
1311 const_iv (LOG_DSYNC) 1388 const_iv (LOG_DSYNC)
1312 const_iv (LOG_AUTO_REMOVE) 1389 const_iv (LOG_AUTO_REMOVE)
1313 const_iv (LOG_IN_MEMORY) 1390 const_iv (LOG_IN_MEMORY)
1314 const_iv (LOG_ZERO) 1391 const_iv (LOG_ZERO)
1317 const_iv (LOG_AUTOREMOVE) 1394 const_iv (LOG_AUTOREMOVE)
1318# if DB_VERSION_MINOR >= 3 1395# if DB_VERSION_MINOR >= 3
1319 const_iv (DSYNC_LOG) 1396 const_iv (DSYNC_LOG)
1320 const_iv (LOG_INMEMORY) 1397 const_iv (LOG_INMEMORY)
1321# endif 1398# endif
1399#if DB_VERSION_MINOR >= 8
1400 const_iv (LOGVERSION_LATCHING)
1401#endif
1322#endif 1402#endif
1323 }; 1403 };
1324 1404
1405 bdb_stash = gv_stashpv ("BDB" , 1);
1406 bdb_env_stash = gv_stashpv ("BDB::Env" , 1);
1407 bdb_txn_stash = gv_stashpv ("BDB::Txn" , 1);
1408 bdb_cursor_stash = gv_stashpv ("BDB::Cursor" , 1);
1409 bdb_db_stash = gv_stashpv ("BDB::Db" , 1);
1410 bdb_sequence_stash = gv_stashpv ("BDB::Sequence", 1);
1411
1325 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1412 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1326 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1413 newCONSTSUB (bdb_stash, (char *)civ->name, newSViv (civ->iv));
1414
1415 prepare_cb = &PL_sv_undef;
1327 1416
1328 { 1417 {
1329 /* we currently only allow version, minor-version and patchlevel to go up to 255 */ 1418 /* we currently only allow version, minor-version and patchlevel to go up to 255 */
1330 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; 1419 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH };
1331 1420
1332 newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); 1421 newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3));
1333 } 1422 }
1334 1423
1335 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1424 newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1336 1425
1337 create_respipe (); 1426 create_respipe ();
1338 1427
1339 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1428 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1340 patch_errno (); 1429 patch_errno ();
1418 1507
1419int 1508int
1420poll_fileno () 1509poll_fileno ()
1421 PROTOTYPE: 1510 PROTOTYPE:
1422 CODE: 1511 CODE:
1423 RETVAL = respipe [0]; 1512 RETVAL = s_epipe_fd (&respipe);
1424 OUTPUT: 1513 OUTPUT:
1425 RETVAL 1514 RETVAL
1426 1515
1427int 1516int
1428poll_cb (...) 1517poll_cb (...)
1470 RETVAL = started; 1559 RETVAL = started;
1471 if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); 1560 if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock);
1472 OUTPUT: 1561 OUTPUT:
1473 RETVAL 1562 RETVAL
1474 1563
1475void 1564SV *
1476set_sync_prepare (SV *cb) 1565set_sync_prepare (SV *cb)
1477 PROTOTYPE: & 1566 PROTOTYPE: &
1478 CODE: 1567 CODE:
1479 SvREFCNT_dec (prepare_cb); 1568 RETVAL = prepare_cb;
1480 prepare_cb = newSVsv (cb); 1569 prepare_cb = newSVsv (cb);
1570 OUTPUT:
1571 RETVAL
1481 1572
1482char * 1573char *
1483strerror (int errorno = errno) 1574strerror (int errorno = errno)
1484 PROTOTYPE: ;$ 1575 PROTOTYPE: ;$
1485 CODE: 1576 CODE:
1527db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) 1618db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0)
1528 PREINIT: 1619 PREINIT:
1529 CALLBACK 1620 CALLBACK
1530 CODE: 1621 CODE:
1531{ 1622{
1532 dREQ (REQ_ENV_CLOSE, 1); 1623 dREQ (REQ_ENV_CLOSE, 0);
1624 ptr_nuke (ST (0));
1533 req->env = env; 1625 req->env = env;
1534 req->uint1 = flags; 1626 req->uint1 = flags;
1535 REQ_SEND; 1627 REQ_SEND;
1536 ptr_nuke (ST (0));
1537} 1628}
1538 1629
1539void 1630void
1540db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0) 1631db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0)
1541 PREINIT: 1632 PREINIT:
1610 dREQ (REQ_ENV_DBRENAME, 2); 1701 dREQ (REQ_ENV_DBRENAME, 2);
1611 req->env = env; 1702 req->env = env;
1612 req->buf1 = strdup_ornull (file); 1703 req->buf1 = strdup_ornull (file);
1613 req->buf2 = strdup_ornull (database); 1704 req->buf2 = strdup_ornull (database);
1614 req->buf3 = strdup_ornull (newname); 1705 req->buf3 = strdup_ornull (newname);
1706 req->uint1 = flags;
1707 REQ_SEND;
1708}
1709
1710void
1711db_env_log_archive (DB_ENV *env, SV_mutable *listp, U32 flags = 0, SV *callback = 0)
1712 PREINIT:
1713 CALLBACK
1714 CODE:
1715{
1716 dREQ (REQ_ENV_LOG_ARCHIVE, 1);
1717 req->sv1 = SvREFCNT_inc (listp);
1718 req->env = env;
1615 req->uint1 = flags; 1719 req->uint1 = flags;
1616 REQ_SEND; 1720 REQ_SEND;
1617} 1721}
1618 1722
1619DB * 1723DB *
1651db_close (DB *db, U32 flags = 0, SV *callback = 0) 1755db_close (DB *db, U32 flags = 0, SV *callback = 0)
1652 PREINIT: 1756 PREINIT:
1653 CALLBACK 1757 CALLBACK
1654 CODE: 1758 CODE:
1655{ 1759{
1656 dREQ (REQ_DB_CLOSE, 1); 1760 dREQ (REQ_DB_CLOSE, 0);
1761 ptr_nuke (ST (0));
1657 req->db = db; 1762 req->db = db;
1658 req->uint1 = flags; 1763 req->uint1 = flags;
1659 req->sv1 = (SV *)db->app_private; 1764 req->sv1 = (SV *)db->app_private;
1660 REQ_SEND; 1765 REQ_SEND;
1661 ptr_nuke (ST (0));
1662} 1766}
1663 1767
1664#if DB_VERSION_MINOR >= 4 1768#if DB_VERSION_MINOR >= 4
1665 1769
1666void 1770void
1670 CODE: 1774 CODE:
1671{ 1775{
1672 dREQ (REQ_DB_COMPACT, 2); 1776 dREQ (REQ_DB_COMPACT, 2);
1673 req->db = db; 1777 req->db = db;
1674 req->txn = txn; 1778 req->txn = txn;
1675 sv_to_dbt (&req->dbt1, start); 1779 if (start) sv_to_dbt (&req->dbt1, start);
1676 sv_to_dbt (&req->dbt2, stop); 1780 if (stop ) sv_to_dbt (&req->dbt2, stop );
1677 req->uint1 = flags; 1781 req->uint1 = flags;
1678 REQ_SEND; 1782 REQ_SEND;
1679} 1783}
1680 1784
1681#endif 1785#endif
1691 req->uint1 = flags; 1795 req->uint1 = flags;
1692 REQ_SEND; 1796 REQ_SEND;
1693} 1797}
1694 1798
1695void 1799void
1800db_verify (DB *db, bdb_filename file, bdb_filename database = 0, SV *dummy = 0, U32 flags = 0, SV *callback = 0)
1801 PREINIT:
1802 CALLBACK
1803 CODE:
1804{
1805 dREQ (REQ_DB_VERIFY, 1);
1806 ptr_nuke (ST (0)); /* verify destroys the database handle, hopefully it is freed as well */
1807 req->db = db;
1808 req->buf1 = strdup (file);
1809 req->buf2 = strdup_ornull (database);
1810 req->uint1 = flags;
1811 REQ_SEND;
1812}
1813
1814void
1696db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) 1815db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0)
1697 PREINIT: 1816 PREINIT:
1698 CALLBACK 1817 CALLBACK
1699 CODE: 1818 CODE:
1700{ 1819{
1701 dREQ (REQ_DB_SYNC, 1); 1820 dREQ (REQ_DB_UPGRADE, 1);
1702 req->db = db; 1821 req->db = db;
1703 req->buf1 = strdup (file); 1822 req->buf1 = strdup (file);
1704 req->uint1 = flags; 1823 req->uint1 = flags;
1705 REQ_SEND; 1824 REQ_SEND;
1706} 1825}
1707 1826
1708void 1827void
1709db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = 0) 1828db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *key_range, U32 flags = 0, SV *callback = 0)
1710 PREINIT: 1829 PREINIT:
1711 CALLBACK 1830 CALLBACK
1712 CODE: 1831 CODE:
1713{ 1832{
1714 dREQ (REQ_DB_KEY_RANGE, 2); 1833 dREQ (REQ_DB_KEY_RANGE, 2);
1752} 1871}
1753 1872
1754#endif 1873#endif
1755 1874
1756void 1875void
1757db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0) 1876db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1758 PREINIT: 1877 PREINIT:
1759 CALLBACK 1878 CALLBACK
1760 CODE: 1879 CODE:
1761 if (SvREADONLY (data))
1762 croak ("can't modify read-only data scalar in db_get");
1763{ 1880{
1881 //TODO: key is somtimesmutable
1764 dREQ (REQ_DB_GET, 2); 1882 dREQ (REQ_DB_GET, 2);
1765 req->db = db; 1883 req->db = db;
1766 req->txn = txn; 1884 req->txn = txn;
1767 req->uint1 = flags; 1885 req->uint1 = flags;
1768 sv_to_dbt (&req->dbt1, key); 1886 sv_to_dbt (&req->dbt1, key);
1770 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 1888 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1771 REQ_SEND; 1889 REQ_SEND;
1772} 1890}
1773 1891
1774void 1892void
1775db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) 1893db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1776 PREINIT: 1894 PREINIT:
1777 CALLBACK 1895 CALLBACK
1778 CODE: 1896 CODE:
1779 if (SvREADONLY (data))
1780 croak ("can't modify read-only data scalar in db_pget");
1781{ 1897{
1898 //TODO: key is somtimesmutable
1782 dREQ (REQ_DB_PGET, 2); 1899 dREQ (REQ_DB_PGET, 2);
1783 req->db = db; 1900 req->db = db;
1784 req->txn = txn; 1901 req->txn = txn;
1785 req->uint1 = flags; 1902 req->uint1 = flags;
1903
1786 sv_to_dbt (&req->dbt1, key); 1904 sv_to_dbt (&req->dbt1, key);
1787 sv_to_dbt (&req->dbt2, pkey); 1905
1906 req->dbt2.flags = DB_DBT_MALLOC;
1907 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1908
1788 req->dbt3.flags = DB_DBT_MALLOC; 1909 req->dbt3.flags = DB_DBT_MALLOC;
1789 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 1910 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1790 REQ_SEND; 1911 REQ_SEND;
1791} 1912}
1792 1913
1808db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) 1929db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1809 PREINIT: 1930 PREINIT:
1810 CALLBACK 1931 CALLBACK
1811 CODE: 1932 CODE:
1812{ 1933{
1813 dREQ (REQ_TXN_COMMIT, 1); 1934 dREQ (REQ_TXN_COMMIT, 0);
1935 ptr_nuke (ST (0));
1814 req->txn = txn; 1936 req->txn = txn;
1815 req->uint1 = flags; 1937 req->uint1 = flags;
1816 REQ_SEND; 1938 REQ_SEND;
1939}
1940
1941void
1942db_txn_abort (DB_TXN *txn, SV *callback = 0)
1943 PREINIT:
1944 CALLBACK
1945 CODE:
1946{
1947 dREQ (REQ_TXN_ABORT, 0);
1817 ptr_nuke (ST (0)); 1948 ptr_nuke (ST (0));
1818}
1819
1820void
1821db_txn_abort (DB_TXN *txn, SV *callback = 0)
1822 PREINIT:
1823 CALLBACK
1824 CODE:
1825{
1826 dREQ (REQ_TXN_ABORT, 1);
1827 req->txn = txn; 1949 req->txn = txn;
1828 REQ_SEND; 1950 REQ_SEND;
1951}
1952
1953void
1954db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1955 PREINIT:
1956 CALLBACK
1957 CODE:
1958{
1959 dREQ (REQ_TXN_FINISH, 0);
1829 ptr_nuke (ST (0)); 1960 ptr_nuke (ST (0));
1830}
1831
1832void
1833db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1834 PREINIT:
1835 CALLBACK
1836 CODE:
1837{
1838 dREQ (REQ_TXN_FINISH, 1);
1839 req->txn = txn; 1961 req->txn = txn;
1840 req->uint1 = flags; 1962 req->uint1 = flags;
1841 REQ_SEND; 1963 REQ_SEND;
1964}
1965
1966void
1967db_c_close (DBC *dbc, SV *callback = 0)
1968 PREINIT:
1969 CALLBACK
1970 CODE:
1971{
1972 dREQ (REQ_C_CLOSE, 0);
1842 ptr_nuke (ST (0)); 1973 ptr_nuke (ST (0));
1843}
1844
1845void
1846db_c_close (DBC *dbc, SV *callback = 0)
1847 PREINIT:
1848 CALLBACK
1849 CODE:
1850{
1851 dREQ (REQ_C_CLOSE, 1);
1852 req->dbc = dbc; 1974 req->dbc = dbc;
1853 REQ_SEND; 1975 REQ_SEND;
1854 ptr_nuke (ST (0));
1855} 1976}
1856 1977
1857void 1978void
1858db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0) 1979db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0)
1859 PREINIT: 1980 PREINIT:
1879 req->uint1 = flags; 2000 req->uint1 = flags;
1880 REQ_SEND; 2001 REQ_SEND;
1881} 2002}
1882 2003
1883void 2004void
1884db_c_get (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0) 2005db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1885 PREINIT: 2006 PREINIT:
1886 CALLBACK 2007 CALLBACK
1887 CODE: 2008 CODE:
1888{ 2009{
2010 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
2011 croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET");
2012 if (SvPOKp (key) && !sv_utf8_downgrade (key, 1))
2013 croak ("argument \"%s\" must be byte/octet-encoded in %s",
2014 "key",
2015 "BDB::db_c_get");
2016
2017 {
1889 dREQ (REQ_C_GET, 1); 2018 dREQ (REQ_C_GET, 1);
1890 req->dbc = dbc; 2019 req->dbc = dbc;
1891 req->uint1 = flags; 2020 req->uint1 = flags;
1892 if ((flags & DB_SET) == DB_SET 2021 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1893 || (flags & DB_SET_RANGE) == DB_SET_RANGE)
1894 sv_to_dbt (&req->dbt1, key); 2022 sv_to_dbt (&req->dbt1, key);
1895 else 2023 else
2024 {
2025 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
2026 sv_to_dbt (&req->dbt1, key);
2027 else
1896 req->dbt1.flags = DB_DBT_MALLOC; 2028 req->dbt1.flags = DB_DBT_MALLOC;
1897 2029
1898 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); 2030 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
2031 }
1899 2032
1900 if ((flags & DB_GET_BOTH) == DB_GET_BOTH 2033 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1901 || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE) 2034 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1902 sv_to_dbt (&req->dbt3, data); 2035 sv_to_dbt (&req->dbt3, data);
1903 else 2036 else
1904 req->dbt3.flags = DB_DBT_MALLOC; 2037 req->dbt3.flags = DB_DBT_MALLOC;
1905 2038
1906 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2039 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1907 REQ_SEND; 2040 REQ_SEND;
2041 }
1908} 2042}
1909 2043
1910void 2044void
1911db_c_pget (DBC *dbc, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) 2045db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1912 PREINIT: 2046 PREINIT:
1913 CALLBACK 2047 CALLBACK
1914 CODE: 2048 CODE:
1915{ 2049{
2050 if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key))
2051 croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET");
2052 if (SvPOKp (key) && !sv_utf8_downgrade (key, 1))
2053 croak ("argument \"%s\" must be byte/octet-encoded in %s",
2054 "key",
2055 "BDB::db_c_pget");
2056
2057 {
1916 dREQ (REQ_C_PGET, 1); 2058 dREQ (REQ_C_PGET, 1);
1917 req->dbc = dbc; 2059 req->dbc = dbc;
1918 req->uint1 = flags; 2060 req->uint1 = flags;
1919 if ((flags & DB_SET) == DB_SET 2061 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1920 || (flags & DB_SET_RANGE) == DB_SET_RANGE)
1921 sv_to_dbt (&req->dbt1, key); 2062 sv_to_dbt (&req->dbt1, key);
1922 else 2063 else
2064 {
2065 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
2066 sv_to_dbt (&req->dbt1, key);
2067 else
2068 req->dbt1.flags = DB_DBT_MALLOC;
2069
2070 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
2071 }
2072
1923 req->dbt1.flags = DB_DBT_MALLOC; 2073 req->dbt2.flags = DB_DBT_MALLOC;
1924
1925 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1926
1927 req->dbt2.flags = DB_DBT_MALLOC;
1928 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); 2074 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1929 2075
1930 if ((flags & DB_GET_BOTH) == DB_GET_BOTH 2076 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1931 || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE) 2077 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1932 sv_to_dbt (&req->dbt3, data); 2078 sv_to_dbt (&req->dbt3, data);
1933 else 2079 else
1934 req->dbt3.flags = DB_DBT_MALLOC; 2080 req->dbt3.flags = DB_DBT_MALLOC;
1935 2081
1936 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2082 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1937 REQ_SEND; 2083 REQ_SEND;
2084 }
1938} 2085}
1939 2086
1940void 2087void
1941db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) 2088db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0)
1942 PREINIT: 2089 PREINIT:
1970db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) 2117db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0)
1971 PREINIT: 2118 PREINIT:
1972 CALLBACK 2119 CALLBACK
1973 CODE: 2120 CODE:
1974{ 2121{
1975 dREQ (REQ_SEQ_CLOSE, 1); 2122 dREQ (REQ_SEQ_CLOSE, 0);
2123 ptr_nuke (ST (0));
1976 req->seq = seq; 2124 req->seq = seq;
1977 req->uint1 = flags; 2125 req->uint1 = flags;
1978 REQ_SEND; 2126 REQ_SEND;
1979 ptr_nuke (ST (0));
1980} 2127}
1981 2128
1982void 2129void
1983db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0) 2130db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV_mutable *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0)
1984 PREINIT: 2131 PREINIT:
1985 CALLBACK 2132 CALLBACK
1986 CODE: 2133 CODE:
1987{ 2134{
1988 dREQ (REQ_SEQ_GET, 2); 2135 dREQ (REQ_SEQ_GET, 2);
2217 CODE: 2364 CODE:
2218 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); 2365 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache);
2219 OUTPUT: 2366 OUTPUT:
2220 RETVAL 2367 RETVAL
2221 2368
2369int set_pagesize (DB *db, U32 pagesize)
2370 CODE:
2371 RETVAL = db->set_pagesize (db, pagesize);
2372 OUTPUT:
2373 RETVAL
2374
2222int set_flags (DB *db, U32 flags) 2375int set_flags (DB *db, U32 flags)
2223 CODE: 2376 CODE:
2224 RETVAL = db->set_flags (db, flags); 2377 RETVAL = db->set_flags (db, flags);
2225 OUTPUT: 2378 OUTPUT:
2226 RETVAL 2379 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines