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

Comparing BDB/BDB.xs (file contents):
Revision 1.52 by root, Thu Sep 25 13:44:44 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);
616 end_thread (); 616 end_thread ();
617} 617}
618 618
619static void poll_wait (void) 619static void poll_wait (void)
620{ 620{
621 fd_set rfd;
622
623 while (nreqs) 621 while (nreqs)
624 { 622 {
625 int size; 623 int size;
626 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 624 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
627 size = res_queue.size; 625 size = res_queue.size;
630 if (size) 628 if (size)
631 return; 629 return;
632 630
633 maybe_start_thread (); 631 maybe_start_thread ();
634 632
635 FD_ZERO (&rfd); 633 s_epipe_wait (&respipe);
636 FD_SET (respipe [0], &rfd);
637
638 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
639 } 634 }
640} 635}
641 636
642static int poll_cb (void) 637static int poll_cb (void)
643{ 638{
663 if (req) 658 if (req)
664 { 659 {
665 --npending; 660 --npending;
666 661
667 if (!res_queue.size) 662 if (!res_queue.size)
668 {
669 /* read any signals sent by the worker threads */ 663 /* read any signals sent by the worker threads */
670 char buf [4]; 664 s_epipe_drain (&respipe);
671 while (respipe_read (respipe [0], buf, 4) == 4)
672 ;
673 }
674 } 665 }
675 666
676 X_UNLOCK (reslock); 667 X_UNLOCK (reslock);
677 668
678 if (!req) 669 if (!req)
760 req->result = req->db->close (req->db, req->uint1); 751 req->result = req->db->close (req->db, req->uint1);
761 break; 752 break;
762 753
763#if DB_VERSION_MINOR >= 4 754#if DB_VERSION_MINOR >= 4
764 case REQ_DB_COMPACT: 755 case REQ_DB_COMPACT:
765 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);
766 break; 757 break;
767#endif 758#endif
768 759
769 case REQ_DB_SYNC: 760 case REQ_DB_SYNC:
770 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);
771 break; 766 break;
772 767
773 case REQ_DB_UPGRADE: 768 case REQ_DB_UPGRADE:
774 req->result = req->db->upgrade (req->db, req->buf1, req->uint1); 769 req->result = req->db->upgrade (req->db, req->buf1, req->uint1);
775 break; 770 break;
862 case REQ_SEQ_REMOVE: 857 case REQ_SEQ_REMOVE:
863 req->result = req->seq->remove (req->seq, req->txn, req->uint1); 858 req->result = req->seq->remove (req->seq, req->txn, req->uint1);
864 break; 859 break;
865#endif 860#endif
866 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
867 default: 870 default:
868 req->result = ENOSYS; 871 req->result = ENOSYS;
869 break; 872 break;
870 } 873 }
871 874
882 /* try to distribute timeouts somewhat evenly */ 885 /* try to distribute timeouts somewhat evenly */
883 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 886 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
884 887
885 for (;;) 888 for (;;)
886 { 889 {
887 ts.tv_sec = time (0) + IDLE_TIMEOUT; 890 ts.tv_sec = time (0) + IDLE_TIMEOUT;
888 891
889 X_LOCK (reqlock); 892 X_LOCK (reqlock);
890 893
891 for (;;) 894 for (;;)
892 { 895 {
937 X_LOCK (reslock); 940 X_LOCK (reslock);
938 941
939 ++npending; 942 ++npending;
940 943
941 if (!reqq_push (&res_queue, req)) 944 if (!reqq_push (&res_queue, req))
942 /* write a dummy byte to the pipe so fh becomes ready */ 945 s_epipe_signal (&respipe);
943 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
944 946
945 self->req = 0; 947 self->req = 0;
946 worker_clear (self); 948 worker_clear (self);
947 949
948 X_UNLOCK (reslock); 950 X_UNLOCK (reslock);
1024 (void)0; 1026 (void)0;
1025 1027
1026#define REQ_SEND \ 1028#define REQ_SEND \
1027 req_send (req) 1029 req_send (req)
1028 1030
1029#define SvPTR(var, arg, type, class, nullok) \ 1031#define SvPTR(var, arg, type, stash, class, nullok) \
1030 if (!SvOK (arg)) \ 1032 if (!SvOK (arg)) \
1031 { \ 1033 { \
1032 if (nullok != 1) \ 1034 if (nullok != 1) \
1033 croak (# var " must be a " # class " object, not undef"); \ 1035 croak (# var " must be a " # class " object, not undef"); \
1034 \ 1036 \
1035 (var) = 0; \ 1037 (var) = 0; \
1036 } \ 1038 } \
1037 else if (sv_derived_from ((arg), # class)) \ 1039 else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \
1038 { \ 1040 { \
1039 IV tmp = SvIV ((SV*) SvRV (arg)); \ 1041 IV tmp = SvIV ((SV*) SvRV (arg)); \
1040 (var) = INT2PTR (type, tmp); \ 1042 (var) = INT2PTR (type, tmp); \
1041 if (!var && nullok != 2) \ 1043 if (!var && nullok != 2) \
1042 croak (# var " is not a valid " # class " object anymore"); \ 1044 croak (# var " is not a valid " # class " object anymore"); \
1043 } \ 1045 } \
1044 else \ 1046 else \
1045 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}
1046 1062
1047static void 1063static void
1048ptr_nuke (SV *sv) 1064ptr_nuke (SV *sv)
1049{ 1065{
1050 assert (SvROK (sv)); 1066 assert (SvROK (sv));
1121 } 1137 }
1122 1138
1123 return 0; 1139 return 0;
1124} 1140}
1125 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
1126/* stupid windoes defined CALLBACK as well */ 1183/* stupid windows defines CALLBACK as well */
1127#undef CALLBACK 1184#undef CALLBACK
1128#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); 1185#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1));
1129 1186
1130MODULE = BDB PACKAGE = BDB 1187MODULE = BDB PACKAGE = BDB
1131 1188
1132PROTOTYPES: ENABLE 1189PROTOTYPES: ENABLE
1133 1190
1134BOOT: 1191BOOT:
1135{ 1192{
1136 HV *stash = gv_stashpv ("BDB", 1);
1137
1138 static const struct { 1193 static const struct {
1139 const char *name; 1194 const char *name;
1140 IV iv; 1195 IV iv;
1141 } *civ, const_iv[] = { 1196 } *civ, const_iv[] = {
1142#define const_iv(name) { # name, (IV)DB_ ## name }, 1197#define const_iv(name) { # name, (IV)DB_ ## name },
1171 const_iv (TXN_NOT_DURABLE) 1226 const_iv (TXN_NOT_DURABLE)
1172 const_iv (TXN_WRITE_NOSYNC) 1227 const_iv (TXN_WRITE_NOSYNC)
1173 const_iv (WRITECURSOR) 1228 const_iv (WRITECURSOR)
1174 const_iv (YIELDCPU) 1229 const_iv (YIELDCPU)
1175 const_iv (ENCRYPT_AES) 1230 const_iv (ENCRYPT_AES)
1231#if DB_VERSION_MINOR < 8
1176 const_iv (XA_CREATE) 1232 const_iv (XA_CREATE)
1233#endif
1177 const_iv (BTREE) 1234 const_iv (BTREE)
1178 const_iv (HASH) 1235 const_iv (HASH)
1179 const_iv (QUEUE) 1236 const_iv (QUEUE)
1180 const_iv (RECNO) 1237 const_iv (RECNO)
1181 const_iv (UNKNOWN) 1238 const_iv (UNKNOWN)
1184 const_iv (NOSYNC) 1241 const_iv (NOSYNC)
1185 const_iv (CHKSUM) 1242 const_iv (CHKSUM)
1186 const_iv (ENCRYPT) 1243 const_iv (ENCRYPT)
1187 const_iv (DUP) 1244 const_iv (DUP)
1188 const_iv (DUPSORT) 1245 const_iv (DUPSORT)
1189 const_iv (RECNUM) 1246 //const_iv (RECNUM)
1190 const_iv (RENUMBER) 1247 const_iv (RENUMBER)
1191 const_iv (REVSPLITOFF) 1248 const_iv (REVSPLITOFF)
1192 const_iv (CONSUME) 1249 const_iv (CONSUME)
1193 const_iv (CONSUME_WAIT) 1250 const_iv (CONSUME_WAIT)
1194 const_iv (GET_BOTH) 1251 const_iv (GET_BOTH)
1245 const_iv (LOCK_OLDEST) 1302 const_iv (LOCK_OLDEST)
1246 const_iv (LOCK_RANDOM) 1303 const_iv (LOCK_RANDOM)
1247 const_iv (LOCK_YOUNGEST) 1304 const_iv (LOCK_YOUNGEST)
1248 1305
1249 const_iv (DONOTINDEX) 1306 const_iv (DONOTINDEX)
1250 const_iv (KEYEMPTY ) 1307 const_iv (KEYEMPTY)
1251 const_iv (KEYEXIST ) 1308 const_iv (KEYEXIST)
1252 const_iv (LOCK_DEADLOCK) 1309 const_iv (LOCK_DEADLOCK)
1253 const_iv (LOCK_NOTGRANTED) 1310 const_iv (LOCK_NOTGRANTED)
1254 const_iv (NOSERVER) 1311 const_iv (NOSERVER)
1255 const_iv (NOSERVER_HOME) 1312 const_iv (NOSERVER_HOME)
1256 const_iv (NOSERVER_ID) 1313 const_iv (NOSERVER_ID)
1266 const_iv (REP_UNAVAIL) 1323 const_iv (REP_UNAVAIL)
1267 const_iv (RUNRECOVERY) 1324 const_iv (RUNRECOVERY)
1268 const_iv (SECONDARY_BAD) 1325 const_iv (SECONDARY_BAD)
1269 const_iv (VERIFY_BAD) 1326 const_iv (VERIFY_BAD)
1270 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
1271 const_iv (VERB_DEADLOCK) 1339 const_iv (VERB_DEADLOCK)
1272 const_iv (VERB_RECOVERY) 1340 const_iv (VERB_RECOVERY)
1273 const_iv (VERB_REPLICATION) 1341 const_iv (VERB_REPLICATION)
1274 const_iv (VERB_WAITSFOR) 1342 const_iv (VERB_WAITSFOR)
1275 1343
1276 const_iv (VERSION_MAJOR) 1344 const_iv (VERSION_MAJOR)
1277 const_iv (VERSION_MINOR) 1345 const_iv (VERSION_MINOR)
1278 const_iv (VERSION_PATCH) 1346 const_iv (VERSION_PATCH)
1347 const_iv (LOGVERSION)
1348 const_iv (LOGOLDVER)
1279#if DB_VERSION_MINOR >= 3 1349#if DB_VERSION_MINOR >= 3
1280 const_iv (INORDER) 1350 const_iv (INORDER)
1281 const_iv (LOCK_MAXWRITE) 1351 const_iv (LOCK_MAXWRITE)
1282 const_iv (SEQ_DEC) 1352 const_iv (SEQ_DEC)
1283 const_iv (SEQ_INC) 1353 const_iv (SEQ_INC)
1308 const_iv (PRIORITY_VERY_LOW) 1378 const_iv (PRIORITY_VERY_LOW)
1309 const_iv (PRIORITY_LOW) 1379 const_iv (PRIORITY_LOW)
1310 const_iv (PRIORITY_DEFAULT) 1380 const_iv (PRIORITY_DEFAULT)
1311 const_iv (PRIORITY_HIGH) 1381 const_iv (PRIORITY_HIGH)
1312 const_iv (PRIORITY_VERY_HIGH) 1382 const_iv (PRIORITY_VERY_HIGH)
1383 const_iv (IGNORE_LEASE)
1313#endif 1384#endif
1314#if DB_VERSION_MINOR >= 7 1385#if DB_VERSION_MINOR >= 7
1386 //const_iv (MULTIPLE_KEY)
1315 const_iv (LOG_DIRECT) 1387 const_iv (LOG_DIRECT)
1316 const_iv (LOG_DSYNC) 1388 const_iv (LOG_DSYNC)
1317 const_iv (LOG_AUTO_REMOVE) 1389 const_iv (LOG_AUTO_REMOVE)
1318 const_iv (LOG_IN_MEMORY) 1390 const_iv (LOG_IN_MEMORY)
1319 const_iv (LOG_ZERO) 1391 const_iv (LOG_ZERO)
1322 const_iv (LOG_AUTOREMOVE) 1394 const_iv (LOG_AUTOREMOVE)
1323# if DB_VERSION_MINOR >= 3 1395# if DB_VERSION_MINOR >= 3
1324 const_iv (DSYNC_LOG) 1396 const_iv (DSYNC_LOG)
1325 const_iv (LOG_INMEMORY) 1397 const_iv (LOG_INMEMORY)
1326# endif 1398# endif
1399#if DB_VERSION_MINOR >= 8
1400 const_iv (LOGVERSION_LATCHING)
1401#endif
1327#endif 1402#endif
1328 }; 1403 };
1329 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
1330 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; )
1331 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;
1332 1416
1333 { 1417 {
1334 /* 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 */
1335 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 };
1336 1420
1337 newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); 1421 newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3));
1338 } 1422 }
1339 1423
1340 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1424 newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1341 1425
1342 create_respipe (); 1426 create_respipe ();
1343 1427
1344 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1428 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1345 patch_errno (); 1429 patch_errno ();
1423 1507
1424int 1508int
1425poll_fileno () 1509poll_fileno ()
1426 PROTOTYPE: 1510 PROTOTYPE:
1427 CODE: 1511 CODE:
1428 RETVAL = respipe [0]; 1512 RETVAL = s_epipe_fd (&respipe);
1429 OUTPUT: 1513 OUTPUT:
1430 RETVAL 1514 RETVAL
1431 1515
1432int 1516int
1433poll_cb (...) 1517poll_cb (...)
1475 RETVAL = started; 1559 RETVAL = started;
1476 if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); 1560 if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock);
1477 OUTPUT: 1561 OUTPUT:
1478 RETVAL 1562 RETVAL
1479 1563
1480void 1564SV *
1481set_sync_prepare (SV *cb) 1565set_sync_prepare (SV *cb)
1482 PROTOTYPE: & 1566 PROTOTYPE: &
1483 CODE: 1567 CODE:
1484 SvREFCNT_dec (prepare_cb); 1568 RETVAL = prepare_cb;
1485 prepare_cb = newSVsv (cb); 1569 prepare_cb = newSVsv (cb);
1570 OUTPUT:
1571 RETVAL
1486 1572
1487char * 1573char *
1488strerror (int errorno = errno) 1574strerror (int errorno = errno)
1489 PROTOTYPE: ;$ 1575 PROTOTYPE: ;$
1490 CODE: 1576 CODE:
1532db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) 1618db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0)
1533 PREINIT: 1619 PREINIT:
1534 CALLBACK 1620 CALLBACK
1535 CODE: 1621 CODE:
1536{ 1622{
1537 dREQ (REQ_ENV_CLOSE, 1); 1623 dREQ (REQ_ENV_CLOSE, 0);
1624 ptr_nuke (ST (0));
1538 req->env = env; 1625 req->env = env;
1539 req->uint1 = flags; 1626 req->uint1 = flags;
1540 REQ_SEND; 1627 REQ_SEND;
1541 ptr_nuke (ST (0));
1542} 1628}
1543 1629
1544void 1630void
1545db_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)
1546 PREINIT: 1632 PREINIT:
1615 dREQ (REQ_ENV_DBRENAME, 2); 1701 dREQ (REQ_ENV_DBRENAME, 2);
1616 req->env = env; 1702 req->env = env;
1617 req->buf1 = strdup_ornull (file); 1703 req->buf1 = strdup_ornull (file);
1618 req->buf2 = strdup_ornull (database); 1704 req->buf2 = strdup_ornull (database);
1619 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;
1620 req->uint1 = flags; 1719 req->uint1 = flags;
1621 REQ_SEND; 1720 REQ_SEND;
1622} 1721}
1623 1722
1624DB * 1723DB *
1656db_close (DB *db, U32 flags = 0, SV *callback = 0) 1755db_close (DB *db, U32 flags = 0, SV *callback = 0)
1657 PREINIT: 1756 PREINIT:
1658 CALLBACK 1757 CALLBACK
1659 CODE: 1758 CODE:
1660{ 1759{
1661 dREQ (REQ_DB_CLOSE, 1); 1760 dREQ (REQ_DB_CLOSE, 0);
1761 ptr_nuke (ST (0));
1662 req->db = db; 1762 req->db = db;
1663 req->uint1 = flags; 1763 req->uint1 = flags;
1664 req->sv1 = (SV *)db->app_private; 1764 req->sv1 = (SV *)db->app_private;
1665 REQ_SEND; 1765 REQ_SEND;
1666 ptr_nuke (ST (0));
1667} 1766}
1668 1767
1669#if DB_VERSION_MINOR >= 4 1768#if DB_VERSION_MINOR >= 4
1670 1769
1671void 1770void
1675 CODE: 1774 CODE:
1676{ 1775{
1677 dREQ (REQ_DB_COMPACT, 2); 1776 dREQ (REQ_DB_COMPACT, 2);
1678 req->db = db; 1777 req->db = db;
1679 req->txn = txn; 1778 req->txn = txn;
1680 sv_to_dbt (&req->dbt1, start); 1779 if (start) sv_to_dbt (&req->dbt1, start);
1681 sv_to_dbt (&req->dbt2, stop); 1780 if (stop ) sv_to_dbt (&req->dbt2, stop );
1682 req->uint1 = flags; 1781 req->uint1 = flags;
1683 REQ_SEND; 1782 REQ_SEND;
1684} 1783}
1685 1784
1686#endif 1785#endif
1696 req->uint1 = flags; 1795 req->uint1 = flags;
1697 REQ_SEND; 1796 REQ_SEND;
1698} 1797}
1699 1798
1700void 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
1701db_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)
1702 PREINIT: 1816 PREINIT:
1703 CALLBACK 1817 CALLBACK
1704 CODE: 1818 CODE:
1705{ 1819{
1706 dREQ (REQ_DB_SYNC, 1); 1820 dREQ (REQ_DB_UPGRADE, 1);
1707 req->db = db; 1821 req->db = db;
1708 req->buf1 = strdup (file); 1822 req->buf1 = strdup (file);
1709 req->uint1 = flags; 1823 req->uint1 = flags;
1710 REQ_SEND; 1824 REQ_SEND;
1711} 1825}
1712 1826
1713void 1827void
1714db_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)
1715 PREINIT: 1829 PREINIT:
1716 CALLBACK 1830 CALLBACK
1717 CODE: 1831 CODE:
1718{ 1832{
1719 dREQ (REQ_DB_KEY_RANGE, 2); 1833 dREQ (REQ_DB_KEY_RANGE, 2);
1757} 1871}
1758 1872
1759#endif 1873#endif
1760 1874
1761void 1875void
1762db_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)
1763 PREINIT: 1877 PREINIT:
1764 CALLBACK 1878 CALLBACK
1765 CODE: 1879 CODE:
1766 if (SvREADONLY (data))
1767 croak ("can't modify read-only data scalar in db_get");
1768{ 1880{
1881 //TODO: key is somtimesmutable
1769 dREQ (REQ_DB_GET, 2); 1882 dREQ (REQ_DB_GET, 2);
1770 req->db = db; 1883 req->db = db;
1771 req->txn = txn; 1884 req->txn = txn;
1772 req->uint1 = flags; 1885 req->uint1 = flags;
1773 sv_to_dbt (&req->dbt1, key); 1886 sv_to_dbt (&req->dbt1, key);
1775 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 1888 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1776 REQ_SEND; 1889 REQ_SEND;
1777} 1890}
1778 1891
1779void 1892void
1780db_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)
1781 PREINIT: 1894 PREINIT:
1782 CALLBACK 1895 CALLBACK
1783 CODE: 1896 CODE:
1784 if (SvREADONLY (data))
1785 croak ("can't modify read-only data scalar in db_pget");
1786{ 1897{
1898 //TODO: key is somtimesmutable
1787 dREQ (REQ_DB_PGET, 2); 1899 dREQ (REQ_DB_PGET, 2);
1788 req->db = db; 1900 req->db = db;
1789 req->txn = txn; 1901 req->txn = txn;
1790 req->uint1 = flags; 1902 req->uint1 = flags;
1903
1791 sv_to_dbt (&req->dbt1, key); 1904 sv_to_dbt (&req->dbt1, key);
1792 sv_to_dbt (&req->dbt2, pkey); 1905
1906 req->dbt2.flags = DB_DBT_MALLOC;
1907 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1908
1793 req->dbt3.flags = DB_DBT_MALLOC; 1909 req->dbt3.flags = DB_DBT_MALLOC;
1794 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 1910 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1795 REQ_SEND; 1911 REQ_SEND;
1796} 1912}
1797 1913
1813db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) 1929db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1814 PREINIT: 1930 PREINIT:
1815 CALLBACK 1931 CALLBACK
1816 CODE: 1932 CODE:
1817{ 1933{
1818 dREQ (REQ_TXN_COMMIT, 1); 1934 dREQ (REQ_TXN_COMMIT, 0);
1935 ptr_nuke (ST (0));
1819 req->txn = txn; 1936 req->txn = txn;
1820 req->uint1 = flags; 1937 req->uint1 = flags;
1821 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);
1822 ptr_nuke (ST (0)); 1948 ptr_nuke (ST (0));
1823}
1824
1825void
1826db_txn_abort (DB_TXN *txn, SV *callback = 0)
1827 PREINIT:
1828 CALLBACK
1829 CODE:
1830{
1831 dREQ (REQ_TXN_ABORT, 1);
1832 req->txn = txn; 1949 req->txn = txn;
1833 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);
1834 ptr_nuke (ST (0)); 1960 ptr_nuke (ST (0));
1835}
1836
1837void
1838db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1839 PREINIT:
1840 CALLBACK
1841 CODE:
1842{
1843 dREQ (REQ_TXN_FINISH, 1);
1844 req->txn = txn; 1961 req->txn = txn;
1845 req->uint1 = flags; 1962 req->uint1 = flags;
1846 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);
1847 ptr_nuke (ST (0)); 1973 ptr_nuke (ST (0));
1848}
1849
1850void
1851db_c_close (DBC *dbc, SV *callback = 0)
1852 PREINIT:
1853 CALLBACK
1854 CODE:
1855{
1856 dREQ (REQ_C_CLOSE, 1);
1857 req->dbc = dbc; 1974 req->dbc = dbc;
1858 REQ_SEND; 1975 REQ_SEND;
1859 ptr_nuke (ST (0));
1860} 1976}
1861 1977
1862void 1978void
1863db_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)
1864 PREINIT: 1980 PREINIT:
1884 req->uint1 = flags; 2000 req->uint1 = flags;
1885 REQ_SEND; 2001 REQ_SEND;
1886} 2002}
1887 2003
1888void 2004void
1889db_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)
1890 PREINIT: 2006 PREINIT:
1891 CALLBACK 2007 CALLBACK
1892 CODE: 2008 CODE:
1893{ 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 {
1894 dREQ (REQ_C_GET, 1); 2018 dREQ (REQ_C_GET, 1);
1895 req->dbc = dbc; 2019 req->dbc = dbc;
1896 req->uint1 = flags; 2020 req->uint1 = flags;
1897 if ((flags & DB_SET) == DB_SET 2021 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1898 || (flags & DB_SET_RANGE) == DB_SET_RANGE)
1899 sv_to_dbt (&req->dbt1, key); 2022 sv_to_dbt (&req->dbt1, key);
1900 else 2023 else
2024 {
2025 if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE)
2026 sv_to_dbt (&req->dbt1, key);
2027 else
1901 req->dbt1.flags = DB_DBT_MALLOC; 2028 req->dbt1.flags = DB_DBT_MALLOC;
1902 2029
1903 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); 2030 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
2031 }
1904 2032
1905 if ((flags & DB_GET_BOTH) == DB_GET_BOTH 2033 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1906 || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE) 2034 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1907 sv_to_dbt (&req->dbt3, data); 2035 sv_to_dbt (&req->dbt3, data);
1908 else 2036 else
1909 req->dbt3.flags = DB_DBT_MALLOC; 2037 req->dbt3.flags = DB_DBT_MALLOC;
1910 2038
1911 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2039 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1912 REQ_SEND; 2040 REQ_SEND;
2041 }
1913} 2042}
1914 2043
1915void 2044void
1916db_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)
1917 PREINIT: 2046 PREINIT:
1918 CALLBACK 2047 CALLBACK
1919 CODE: 2048 CODE:
1920{ 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 {
1921 dREQ (REQ_C_PGET, 1); 2058 dREQ (REQ_C_PGET, 1);
1922 req->dbc = dbc; 2059 req->dbc = dbc;
1923 req->uint1 = flags; 2060 req->uint1 = flags;
1924 if ((flags & DB_SET) == DB_SET 2061 if ((flags & DB_OPFLAGS_MASK) == DB_SET)
1925 || (flags & DB_SET_RANGE) == DB_SET_RANGE)
1926 sv_to_dbt (&req->dbt1, key); 2062 sv_to_dbt (&req->dbt1, key);
1927 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
1928 req->dbt1.flags = DB_DBT_MALLOC; 2073 req->dbt2.flags = DB_DBT_MALLOC;
1929
1930 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1931
1932 req->dbt2.flags = DB_DBT_MALLOC;
1933 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); 2074 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1934 2075
1935 if ((flags & DB_GET_BOTH) == DB_GET_BOTH 2076 if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH
1936 || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE) 2077 || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE)
1937 sv_to_dbt (&req->dbt3, data); 2078 sv_to_dbt (&req->dbt3, data);
1938 else 2079 else
1939 req->dbt3.flags = DB_DBT_MALLOC; 2080 req->dbt3.flags = DB_DBT_MALLOC;
1940 2081
1941 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 2082 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1942 REQ_SEND; 2083 REQ_SEND;
2084 }
1943} 2085}
1944 2086
1945void 2087void
1946db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) 2088db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0)
1947 PREINIT: 2089 PREINIT:
1975db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) 2117db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0)
1976 PREINIT: 2118 PREINIT:
1977 CALLBACK 2119 CALLBACK
1978 CODE: 2120 CODE:
1979{ 2121{
1980 dREQ (REQ_SEQ_CLOSE, 1); 2122 dREQ (REQ_SEQ_CLOSE, 0);
2123 ptr_nuke (ST (0));
1981 req->seq = seq; 2124 req->seq = seq;
1982 req->uint1 = flags; 2125 req->uint1 = flags;
1983 REQ_SEND; 2126 REQ_SEND;
1984 ptr_nuke (ST (0));
1985} 2127}
1986 2128
1987void 2129void
1988db_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)
1989 PREINIT: 2131 PREINIT:
1990 CALLBACK 2132 CALLBACK
1991 CODE: 2133 CODE:
1992{ 2134{
1993 dREQ (REQ_SEQ_GET, 2); 2135 dREQ (REQ_SEQ_GET, 2);
2222 CODE: 2364 CODE:
2223 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); 2365 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache);
2224 OUTPUT: 2366 OUTPUT:
2225 RETVAL 2367 RETVAL
2226 2368
2369int set_pagesize (DB *db, U32 pagesize)
2370 CODE:
2371 RETVAL = db->set_pagesize (db, pagesize);
2372 OUTPUT:
2373 RETVAL
2374
2227int set_flags (DB *db, U32 flags) 2375int set_flags (DB *db, U32 flags)
2228 CODE: 2376 CODE:
2229 RETVAL = db->set_flags (db, flags); 2377 RETVAL = db->set_flags (db, flags);
2230 OUTPUT: 2378 OUTPUT:
2231 RETVAL 2379 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines