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

Comparing BDB/BDB.xs (file contents):
Revision 1.68 by root, Tue Jul 14 19:29:23 2009 UTC vs.
Revision 1.77 by root, Mon Dec 26 01:46:33 2011 UTC

8#include "perl.h" 8#include "perl.h"
9#include "XSUB.h" 9#include "XSUB.h"
10 10
11#include "schmorp.h" 11#include "schmorp.h"
12 12
13// perl stupidly defines these as macros, breaking 13// perl stupidly defines these as argument-less macros, breaking
14// lots and lots of code. 14// lots and lots of code.
15#undef open 15#undef open
16#undef close 16#undef close
17#undef abort 17#undef abort
18#undef malloc 18#undef malloc
31# include <unistd.h> 31# include <unistd.h>
32#endif 32#endif
33 33
34#include <db.h> 34#include <db.h>
35 35
36#if DB_VERSION_MAJOR != 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 3) 36#define DBVER DB_VERSION_MAJOR * 100 + DB_VERSION_MINOR
37
38#if DBVER < 403
37# error you need Berkeley DB 4.3 or a newer 4.x version installed 39# error you need Berkeley DB 4.3 or a newer version installed
38#endif 40#endif
39 41
40/* number of seconds after which idle threads exit */ 42/* number of seconds after which idle threads exit */
41#define IDLE_TIMEOUT 10 43#define IDLE_TIMEOUT 10
42 44
50typedef DB_ENV DB_ENV_ornuked; 52typedef DB_ENV DB_ENV_ornuked;
51typedef DB_TXN DB_TXN_ornuked; 53typedef DB_TXN DB_TXN_ornuked;
52typedef DBC DBC_ornuked; 54typedef DBC DBC_ornuked;
53typedef DB DB_ornuked; 55typedef DB DB_ornuked;
54 56
55#if DB_VERSION_MINOR >= 3 57#if DBVER >= 403
56typedef DB_SEQUENCE DB_SEQUENCE_ornull; 58typedef DB_SEQUENCE DB_SEQUENCE_ornull;
57typedef DB_SEQUENCE DB_SEQUENCE_ornuked; 59typedef DB_SEQUENCE DB_SEQUENCE_ornuked;
58#endif 60#endif
59 61
60typedef char *bdb_filename; 62typedef char *bdb_filename;
61 63
62static SV *prepare_cb; 64static SV *prepare_cb;
63 65
64#if DB_VERSION_MINOR >= 6 66static HV
67 *bdb_stash,
68 *bdb_env_stash,
69 *bdb_txn_stash,
70 *bdb_cursor_stash,
71 *bdb_db_stash,
72 *bdb_sequence_stash;
73
74#if DBVER >= 406
65# define c_close close 75# define c_close close
66# define c_count count 76# define c_count count
67# define c_del del 77# define c_del del
68# define c_dup dup 78# define c_dup dup
69# define c_get get 79# define c_get get
178 char *buf1, *buf2, *buf3; 188 char *buf1, *buf2, *buf3;
179 SV *sv1, *sv2, *sv3; 189 SV *sv1, *sv2, *sv3;
180 190
181 DBT dbt1, dbt2, dbt3; 191 DBT dbt1, dbt2, dbt3;
182 DB_KEY_RANGE key_range; 192 DB_KEY_RANGE key_range;
183#if DB_VERSION_MINOR >= 3 193#if DBVER >= 403
184 DB_SEQUENCE *seq; 194 DB_SEQUENCE *seq;
185 db_seq_t seq_t; 195 db_seq_t seq_t;
186#endif 196#endif
187 197
188 SV *rsv1, *rsv2; // keep some request objects alive 198 SV *rsv1, *rsv2; // keep some request objects alive
216static int next_pri = DEFAULT_PRI + PRI_BIAS; 226static int next_pri = DEFAULT_PRI + PRI_BIAS;
217 227
218static unsigned int started, idle, wanted; 228static unsigned int started, idle, wanted;
219 229
220/* worker threads management */ 230/* worker threads management */
221static mutex_t wrklock = X_MUTEX_INIT; 231static xmutex_t wrklock = X_MUTEX_INIT;
222 232
223typedef struct worker { 233typedef struct worker {
224 /* locked by wrklock */ 234 /* locked by wrklock */
225 struct worker *prev, *next; 235 struct worker *prev, *next;
226 236
227 thread_t tid; 237 xthread_t tid;
228 238
229 /* locked by reslock, reqlock or wrklock */ 239 /* locked by reslock, reqlock or wrklock */
230 bdb_req req; /* currently processed request */ 240 bdb_req req; /* currently processed request */
231 void *dbuf; 241 void *dbuf;
232 DIR *dirp; 242 DIR *dirp;
247} 257}
248 258
249static volatile unsigned int nreqs, nready, npending; 259static volatile unsigned int nreqs, nready, npending;
250static volatile unsigned int max_idle = 4; 260static volatile unsigned int max_idle = 4;
251static volatile unsigned int max_outstanding = 0xffffffff; 261static volatile unsigned int max_outstanding = 0xffffffff;
252static int respipe_osf [2], respipe [2] = { -1, -1 }; 262static s_epipe respipe;
253 263
254static mutex_t reslock = X_MUTEX_INIT; 264static xmutex_t reslock = X_MUTEX_INIT;
255static mutex_t reqlock = X_MUTEX_INIT; 265static xmutex_t reqlock = X_MUTEX_INIT;
256static cond_t reqwait = X_COND_INIT; 266static xcond_t reqwait = X_COND_INIT;
257 267
258#if WORDACCESS_UNSAFE 268#if WORDACCESS_UNSAFE
259 269
260static unsigned int get_nready (void) 270static unsigned int get_nready (void)
261{ 271{
389 SvREFCNT_dec (av); 399 SvREFCNT_dec (av);
390 SvREFCNT_dec (req->sv1); 400 SvREFCNT_dec (req->sv1);
391 } 401 }
392 break; 402 break;
393 403
394#if DB_VERSION_MINOR >= 3 404#if DBVER >= 403
395 case REQ_SEQ_GET: 405 case REQ_SEQ_GET:
396 SvREADONLY_off (req->sv1); 406 SvREADONLY_off (req->sv1);
397 407
398 if (sizeof (IV) > 4) 408 if (sizeof (IV) > 4)
399 sv_setiv_mg (req->sv1, (IV)req->seq_t); 409 sv_setiv_mg (req->sv1, (IV)req->seq_t);
461} 471}
462 472
463static void 473static void
464create_respipe (void) 474create_respipe (void)
465{ 475{
466#ifdef _WIN32
467 int arg; /* argg */
468#endif
469 int old_readfd = respipe [0];
470
471 if (respipe [1] >= 0)
472 respipe_close (S_TO_SOCKET (respipe [1]));
473
474 if (s_pipe (respipe)) 476 if (s_epipe_renew (&respipe))
475 croak ("unable to initialize result pipe"); 477 croak ("BDB: unable to create event pipe");
476
477 if (old_readfd >= 0)
478 {
479 if (dup2 (S_TO_SOCKET (respipe [0]), S_TO_SOCKET (old_readfd)) < 0)
480 croak ("unable to initialize result pipe(2)");
481
482 respipe_close (respipe [0]);
483 respipe [0] = old_readfd;
484 }
485
486#ifdef _WIN32
487 arg = 1;
488 if (ioctlsocket (S_TO_SOCKET (respipe [0]), FIONBIO, &arg)
489 || ioctlsocket (S_TO_SOCKET (respipe [1]), FIONBIO, &arg))
490#else
491 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
492 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
493#endif
494 croak ("unable to initialize result pipe(3)");
495
496 respipe_osf [0] = S_TO_SOCKET (respipe [0]);
497 respipe_osf [1] = S_TO_SOCKET (respipe [1]);
498} 478}
499 479
500static void bdb_request (bdb_req req); 480static void bdb_request (bdb_req req);
501X_THREAD_PROC (bdb_proc); 481X_THREAD_PROC (bdb_proc);
502 482
638 end_thread (); 618 end_thread ();
639} 619}
640 620
641static void poll_wait (void) 621static void poll_wait (void)
642{ 622{
643 fd_set rfd;
644
645 while (nreqs) 623 while (nreqs)
646 { 624 {
647 int size; 625 int size;
648 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 626 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
649 size = res_queue.size; 627 size = res_queue.size;
652 if (size) 630 if (size)
653 return; 631 return;
654 632
655 maybe_start_thread (); 633 maybe_start_thread ();
656 634
657 FD_ZERO (&rfd); 635 s_epipe_wait (&respipe);
658 FD_SET (respipe [0], &rfd);
659
660 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
661 } 636 }
662} 637}
663 638
664static int poll_cb (void) 639static int poll_cb (void)
665{ 640{
685 if (req) 660 if (req)
686 { 661 {
687 --npending; 662 --npending;
688 663
689 if (!res_queue.size) 664 if (!res_queue.size)
690 {
691 /* read any signals sent by the worker threads */ 665 /* read any signals sent by the worker threads */
692 char buf [4]; 666 s_epipe_drain (&respipe);
693 while (respipe_read (respipe [0], buf, 4) == 4)
694 ;
695 }
696 } 667 }
697 668
698 X_UNLOCK (reslock); 669 X_UNLOCK (reslock);
699 670
700 if (!req) 671 if (!req)
780 751
781 case REQ_DB_CLOSE: 752 case REQ_DB_CLOSE:
782 req->result = req->db->close (req->db, req->uint1); 753 req->result = req->db->close (req->db, req->uint1);
783 break; 754 break;
784 755
785#if DB_VERSION_MINOR >= 4 756#if DBVER >= 404
786 case REQ_DB_COMPACT: 757 case REQ_DB_COMPACT:
787 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); 758 req->result = req->db->compact (req->db, req->txn, req->dbt1.data ? &req->dbt1 : 0, req->dbt2.data ? &req->dbt2 : 0, 0, req->uint1, 0);
788 break; 759 break;
789#endif 760#endif
790 761
802 773
803 case REQ_DB_PUT: 774 case REQ_DB_PUT:
804 req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); 775 req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1);
805 break; 776 break;
806 777
807#if DB_VERSION_MINOR >= 6 778#if DBVER >= 406
808 case REQ_DB_EXISTS: 779 case REQ_DB_EXISTS:
809 req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1); 780 req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1);
810 break; 781 break;
811#endif 782#endif
812 case REQ_DB_GET: 783 case REQ_DB_GET:
870 841
871 case REQ_C_DEL: 842 case REQ_C_DEL:
872 req->result = req->dbc->c_del (req->dbc, req->uint1); 843 req->result = req->dbc->c_del (req->dbc, req->uint1);
873 break; 844 break;
874 845
875#if DB_VERSION_MINOR >= 3 846#if DBVER >= 403
876 case REQ_SEQ_OPEN: 847 case REQ_SEQ_OPEN:
877 req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); 848 req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1);
878 break; 849 break;
879 850
880 case REQ_SEQ_CLOSE: 851 case REQ_SEQ_CLOSE:
916 /* try to distribute timeouts somewhat evenly */ 887 /* try to distribute timeouts somewhat evenly */
917 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 888 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
918 889
919 for (;;) 890 for (;;)
920 { 891 {
921 ts.tv_sec = time (0) + IDLE_TIMEOUT; 892 ts.tv_sec = time (0) + IDLE_TIMEOUT;
922 893
923 X_LOCK (reqlock); 894 X_LOCK (reqlock);
924 895
925 for (;;) 896 for (;;)
926 { 897 {
971 X_LOCK (reslock); 942 X_LOCK (reslock);
972 943
973 ++npending; 944 ++npending;
974 945
975 if (!reqq_push (&res_queue, req)) 946 if (!reqq_push (&res_queue, req))
976 /* write a dummy byte to the pipe so fh becomes ready */ 947 s_epipe_signal (&respipe);
977 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
978 948
979 self->req = 0; 949 self->req = 0;
980 worker_clear (self); 950 worker_clear (self);
981 951
982 X_UNLOCK (reslock); 952 X_UNLOCK (reslock);
1058 (void)0; 1028 (void)0;
1059 1029
1060#define REQ_SEND \ 1030#define REQ_SEND \
1061 req_send (req) 1031 req_send (req)
1062 1032
1063#define SvPTR(var, arg, type, class, nullok) \ 1033#define SvPTR(var, arg, type, stash, class, nullok) \
1064 if (!SvOK (arg)) \ 1034 if (!SvOK (arg)) \
1065 { \ 1035 { \
1066 if (nullok != 1) \ 1036 if (nullok != 1) \
1067 croak (# var " must be a " # class " object, not undef"); \ 1037 croak (# var " must be a " # class " object, not undef"); \
1068 \ 1038 \
1069 (var) = 0; \ 1039 (var) = 0; \
1070 } \ 1040 } \
1071 else if (sv_derived_from ((arg), # class)) \ 1041 else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \
1072 { \ 1042 { \
1073 IV tmp = SvIV ((SV*) SvRV (arg)); \ 1043 IV tmp = SvIV ((SV*) SvRV (arg)); \
1074 (var) = INT2PTR (type, tmp); \ 1044 (var) = INT2PTR (type, tmp); \
1075 if (!var && nullok != 2) \ 1045 if (!var && nullok != 2) \
1076 croak (# var " is not a valid " # class " object anymore"); \ 1046 croak (# var " is not a valid " # class " object anymore"); \
1079 croak (# var " is not of type " # class); 1049 croak (# var " is not of type " # class);
1080 1050
1081#define ARG_MUTABLE(name) \ 1051#define ARG_MUTABLE(name) \
1082 if (SvREADONLY (name)) \ 1052 if (SvREADONLY (name)) \
1083 croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); 1053 croak ("argument " #name " is read-only/constant, but the request requires it to be mutable");
1054
1055static SV *
1056newSVptr (void *ptr, HV *stash)
1057{
1058 SV *rv = NEWSV (0, 0);
1059 sv_upgrade (rv, SVt_PVMG);
1060 sv_setiv (rv, PTR2IV (ptr));
1061
1062 return sv_bless (newRV_noinc (rv), stash);
1063}
1084 1064
1085static void 1065static void
1086ptr_nuke (SV *sv) 1066ptr_nuke (SV *sv)
1087{ 1067{
1088 assert (SvROK (sv)); 1068 assert (SvROK (sv));
1210 1190
1211PROTOTYPES: ENABLE 1191PROTOTYPES: ENABLE
1212 1192
1213BOOT: 1193BOOT:
1214{ 1194{
1215 HV *stash = gv_stashpv ("BDB", 1);
1216
1217 static const struct { 1195 static const struct {
1218 const char *name; 1196 const char *name;
1219 IV iv; 1197 IV iv;
1220 } *civ, const_iv[] = { 1198 } *civ, const_iv[] = {
1221#define const_iv(name) { # name, (IV)DB_ ## name }, 1199#define const_iv(name) { # name, (IV)DB_ ## name },
1200#if DBVER <= 408
1222 const_iv (RPCCLIENT) 1201 const_iv (RPCCLIENT)
1202#endif
1223 const_iv (INIT_CDB) 1203 const_iv (INIT_CDB)
1224 const_iv (INIT_LOCK) 1204 const_iv (INIT_LOCK)
1225 const_iv (INIT_LOG) 1205 const_iv (INIT_LOG)
1226 const_iv (INIT_MPOOL) 1206 const_iv (INIT_MPOOL)
1227 const_iv (INIT_REP) 1207 const_iv (INIT_REP)
1250 const_iv (TXN_NOT_DURABLE) 1230 const_iv (TXN_NOT_DURABLE)
1251 const_iv (TXN_WRITE_NOSYNC) 1231 const_iv (TXN_WRITE_NOSYNC)
1252 const_iv (WRITECURSOR) 1232 const_iv (WRITECURSOR)
1253 const_iv (YIELDCPU) 1233 const_iv (YIELDCPU)
1254 const_iv (ENCRYPT_AES) 1234 const_iv (ENCRYPT_AES)
1235#if DBVER < 408
1255 const_iv (XA_CREATE) 1236 const_iv (XA_CREATE)
1237#endif
1256 const_iv (BTREE) 1238 const_iv (BTREE)
1257 const_iv (HASH) 1239 const_iv (HASH)
1258 const_iv (QUEUE) 1240 const_iv (QUEUE)
1259 const_iv (RECNO) 1241 const_iv (RECNO)
1260 const_iv (UNKNOWN) 1242 const_iv (UNKNOWN)
1324 const_iv (LOCK_OLDEST) 1306 const_iv (LOCK_OLDEST)
1325 const_iv (LOCK_RANDOM) 1307 const_iv (LOCK_RANDOM)
1326 const_iv (LOCK_YOUNGEST) 1308 const_iv (LOCK_YOUNGEST)
1327 1309
1328 const_iv (DONOTINDEX) 1310 const_iv (DONOTINDEX)
1329 const_iv (KEYEMPTY ) 1311 const_iv (KEYEMPTY)
1330 const_iv (KEYEXIST ) 1312 const_iv (KEYEXIST)
1331 const_iv (LOCK_DEADLOCK) 1313 const_iv (LOCK_DEADLOCK)
1332 const_iv (LOCK_NOTGRANTED) 1314 const_iv (LOCK_NOTGRANTED)
1333 const_iv (NOSERVER) 1315 const_iv (NOSERVER)
1316#if DBVER < 502
1334 const_iv (NOSERVER_HOME) 1317 const_iv (NOSERVER_HOME)
1335 const_iv (NOSERVER_ID) 1318 const_iv (NOSERVER_ID)
1319#endif
1336 const_iv (NOTFOUND) 1320 const_iv (NOTFOUND)
1337 const_iv (PAGE_NOTFOUND) 1321 const_iv (PAGE_NOTFOUND)
1338 const_iv (REP_DUPMASTER) 1322 const_iv (REP_DUPMASTER)
1339 const_iv (REP_HANDLE_DEAD) 1323 const_iv (REP_HANDLE_DEAD)
1340 const_iv (REP_HOLDELECTION) 1324 const_iv (REP_HOLDELECTION)
1364 const_iv (VERB_WAITSFOR) 1348 const_iv (VERB_WAITSFOR)
1365 1349
1366 const_iv (VERSION_MAJOR) 1350 const_iv (VERSION_MAJOR)
1367 const_iv (VERSION_MINOR) 1351 const_iv (VERSION_MINOR)
1368 const_iv (VERSION_PATCH) 1352 const_iv (VERSION_PATCH)
1369#if DB_VERSION_MINOR >= 3 1353 const_iv (LOGVERSION)
1354 const_iv (LOGOLDVER)
1355#if DBVER >= 403
1370 const_iv (INORDER) 1356 const_iv (INORDER)
1371 const_iv (LOCK_MAXWRITE) 1357 const_iv (LOCK_MAXWRITE)
1372 const_iv (SEQ_DEC) 1358 const_iv (SEQ_DEC)
1373 const_iv (SEQ_INC) 1359 const_iv (SEQ_INC)
1374 const_iv (SEQ_WRAP) 1360 const_iv (SEQ_WRAP)
1375 const_iv (BUFFER_SMALL) 1361 const_iv (BUFFER_SMALL)
1376 const_iv (LOG_BUFFER_FULL) 1362 const_iv (LOG_BUFFER_FULL)
1377 const_iv (VERSION_MISMATCH) 1363 const_iv (VERSION_MISMATCH)
1378#endif 1364#endif
1379#if DB_VERSION_MINOR >= 4 1365#if DBVER >= 404
1380 const_iv (REGISTER) 1366 const_iv (REGISTER)
1381 const_iv (DSYNC_DB) 1367 const_iv (DSYNC_DB)
1382 const_iv (READ_COMMITTED) 1368 const_iv (READ_COMMITTED)
1383 const_iv (READ_UNCOMMITTED) 1369 const_iv (READ_UNCOMMITTED)
1384 const_iv (REP_IGNORE) 1370 const_iv (REP_IGNORE)
1386 const_iv (REP_JOIN_FAILURE) 1372 const_iv (REP_JOIN_FAILURE)
1387 const_iv (FREE_SPACE) 1373 const_iv (FREE_SPACE)
1388 const_iv (FREELIST_ONLY) 1374 const_iv (FREELIST_ONLY)
1389 const_iv (VERB_REGISTER) 1375 const_iv (VERB_REGISTER)
1390#endif 1376#endif
1391#if DB_VERSION_MINOR >= 5 1377#if DBVER >= 405
1392 const_iv (MULTIVERSION) 1378 const_iv (MULTIVERSION)
1393 const_iv (TXN_SNAPSHOT) 1379 const_iv (TXN_SNAPSHOT)
1394#endif 1380#endif
1395#if DB_VERSION_MINOR >= 6 1381#if DBVER >= 406
1396 const_iv (PREV_DUP) 1382 const_iv (PREV_DUP)
1397 const_iv (PRIORITY_UNCHANGED) 1383 const_iv (PRIORITY_UNCHANGED)
1398 const_iv (PRIORITY_VERY_LOW) 1384 const_iv (PRIORITY_VERY_LOW)
1399 const_iv (PRIORITY_LOW) 1385 const_iv (PRIORITY_LOW)
1400 const_iv (PRIORITY_DEFAULT) 1386 const_iv (PRIORITY_DEFAULT)
1401 const_iv (PRIORITY_HIGH) 1387 const_iv (PRIORITY_HIGH)
1402 const_iv (PRIORITY_VERY_HIGH) 1388 const_iv (PRIORITY_VERY_HIGH)
1403 const_iv (IGNORE_LEASE) 1389 const_iv (IGNORE_LEASE)
1404#endif 1390#endif
1405#if DB_VERSION_MINOR >= 7 1391#if DBVER >= 407
1406 //const_iv (MULTIPLE_KEY) 1392 //const_iv (MULTIPLE_KEY)
1407 const_iv (LOG_DIRECT) 1393 const_iv (LOG_DIRECT)
1408 const_iv (LOG_DSYNC) 1394 const_iv (LOG_DSYNC)
1409 const_iv (LOG_AUTO_REMOVE) 1395 const_iv (LOG_AUTO_REMOVE)
1410 const_iv (LOG_IN_MEMORY) 1396 const_iv (LOG_IN_MEMORY)
1411 const_iv (LOG_ZERO) 1397 const_iv (LOG_ZERO)
1412#else 1398#else
1413 const_iv (DIRECT_LOG) 1399 const_iv (DIRECT_LOG)
1414 const_iv (LOG_AUTOREMOVE) 1400 const_iv (LOG_AUTOREMOVE)
1415# if DB_VERSION_MINOR >= 3 1401# if DBVER >= 403
1416 const_iv (DSYNC_LOG) 1402 const_iv (DSYNC_LOG)
1417 const_iv (LOG_INMEMORY) 1403 const_iv (LOG_INMEMORY)
1418# endif 1404# endif
1405#if DBVER >= 408
1406 const_iv (LOGVERSION_LATCHING)
1407#endif
1419#endif 1408#endif
1420 }; 1409 };
1421 1410
1411 bdb_stash = gv_stashpv ("BDB" , 1);
1412 bdb_env_stash = gv_stashpv ("BDB::Env" , 1);
1413 bdb_txn_stash = gv_stashpv ("BDB::Txn" , 1);
1414 bdb_cursor_stash = gv_stashpv ("BDB::Cursor" , 1);
1415 bdb_db_stash = gv_stashpv ("BDB::Db" , 1);
1416 bdb_sequence_stash = gv_stashpv ("BDB::Sequence", 1);
1417
1422 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1418 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
1423 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1419 newCONSTSUB (bdb_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
1424 1420
1425 prepare_cb = &PL_sv_undef; 1421 prepare_cb = &PL_sv_undef;
1426 1422
1427 { 1423 {
1428 /* we currently only allow version, minor-version and patchlevel to go up to 255 */ 1424 /* we currently only allow version, minor-version and patchlevel to go up to 255 */
1429 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; 1425 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH };
1430 1426
1431 newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); 1427 newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3));
1432 } 1428 }
1433 1429
1434 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1430 newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1435 1431
1436 create_respipe (); 1432 create_respipe ();
1437 1433
1438 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1434 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1439 patch_errno (); 1435 patch_errno ();
1517 1513
1518int 1514int
1519poll_fileno () 1515poll_fileno ()
1520 PROTOTYPE: 1516 PROTOTYPE:
1521 CODE: 1517 CODE:
1522 RETVAL = respipe [0]; 1518 RETVAL = s_epipe_fd (&respipe);
1523 OUTPUT: 1519 OUTPUT:
1524 RETVAL 1520 RETVAL
1525 1521
1526int 1522int
1527poll_cb (...) 1523poll_cb (...)
1773 req->uint1 = flags; 1769 req->uint1 = flags;
1774 req->sv1 = (SV *)db->app_private; 1770 req->sv1 = (SV *)db->app_private;
1775 REQ_SEND; 1771 REQ_SEND;
1776} 1772}
1777 1773
1778#if DB_VERSION_MINOR >= 4 1774#if DBVER >= 404
1779 1775
1780void 1776void
1781db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = 0) 1777db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = 0)
1782 PREINIT: 1778 PREINIT:
1783 CALLBACK 1779 CALLBACK
1862 sv_to_dbt (&req->dbt2, data); 1858 sv_to_dbt (&req->dbt2, data);
1863 req->uint1 = flags; 1859 req->uint1 = flags;
1864 REQ_SEND; 1860 REQ_SEND;
1865} 1861}
1866 1862
1867#if DB_VERSION_MINOR >= 6 1863#if DBVER >= 406
1868 1864
1869void 1865void
1870db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) 1866db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0)
1871 PREINIT: 1867 PREINIT:
1872 CALLBACK 1868 CALLBACK
2105 req->uint1 = flags; 2101 req->uint1 = flags;
2106 REQ_SEND; 2102 REQ_SEND;
2107} 2103}
2108 2104
2109 2105
2110#if DB_VERSION_MINOR >= 3 2106#if DBVER >= 403
2111 2107
2112void 2108void
2113db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) 2109db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0)
2114 PREINIT: 2110 PREINIT:
2115 CALLBACK 2111 CALLBACK
2209 CODE: 2205 CODE:
2210 RETVAL = env->set_flags (env, flags, onoff); 2206 RETVAL = env->set_flags (env, flags, onoff);
2211 OUTPUT: 2207 OUTPUT:
2212 RETVAL 2208 RETVAL
2213 2209
2214#if DB_VERSION_MINOR >= 7 2210#if DBVER >= 407
2215 2211
2216int set_intermediate_dir_mode (DB_ENV *env, const char *mode) 2212int set_intermediate_dir_mode (DB_ENV *env, const char *mode)
2217 CODE: 2213 CODE:
2218 RETVAL = env->set_intermediate_dir_mode (env, mode); 2214 RETVAL = env->set_intermediate_dir_mode (env, mode);
2219 OUTPUT: 2215 OUTPUT:
2306 CODE: 2302 CODE:
2307 RETVAL = env->set_lg_max (env, max); 2303 RETVAL = env->set_lg_max (env, max);
2308 OUTPUT: 2304 OUTPUT:
2309 RETVAL 2305 RETVAL
2310 2306
2311#if DB_VERSION_MINOR >= 4 2307#if DBVER >= 404
2312 2308
2313int mutex_set_max (DB_ENV *env, U32 max) 2309int mutex_set_max (DB_ENV *env, U32 max)
2314 CODE: 2310 CODE:
2315 RETVAL = env->mutex_set_max (env, max); 2311 RETVAL = env->mutex_set_max (env, max);
2316 OUTPUT: 2312 OUTPUT:
2343 if (errno) 2339 if (errno)
2344 croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); 2340 croak ("DB_ENV->txn_begin: %s", db_strerror (errno));
2345 OUTPUT: 2341 OUTPUT:
2346 RETVAL 2342 RETVAL
2347 2343
2348#if DB_VERSION_MINOR >= 5 2344#if DBVER >= 405
2349 2345
2350DB_TXN * 2346DB_TXN *
2351cdsgroup_begin (DB_ENV *env) 2347cdsgroup_begin (DB_ENV *env)
2352 CODE: 2348 CODE:
2353 errno = env->cdsgroup_begin (env, &RETVAL); 2349 errno = env->cdsgroup_begin (env, &RETVAL);
2455 if (errno) 2451 if (errno)
2456 croak ("DB->cursor: %s", db_strerror (errno)); 2452 croak ("DB->cursor: %s", db_strerror (errno));
2457 OUTPUT: 2453 OUTPUT:
2458 RETVAL 2454 RETVAL
2459 2455
2460#if DB_VERSION_MINOR >= 3 2456#if DBVER >= 403
2461 2457
2462DB_SEQUENCE * 2458DB_SEQUENCE *
2463sequence (DB *db, U32 flags = 0) 2459sequence (DB *db, U32 flags = 0)
2464 CODE: 2460 CODE:
2465{ 2461{
2500DESTROY (DBC_ornuked *dbc) 2496DESTROY (DBC_ornuked *dbc)
2501 CODE: 2497 CODE:
2502 if (dbc) 2498 if (dbc)
2503 dbc->c_close (dbc); 2499 dbc->c_close (dbc);
2504 2500
2505#if DB_VERSION_MINOR >= 6 2501#if DBVER >= 406
2506 2502
2507int set_priority (DBC *dbc, int priority) 2503int set_priority (DBC *dbc, int priority)
2508 CODE: 2504 CODE:
2509 dbc->set_priority (dbc, priority); 2505 dbc->set_priority (dbc, priority);
2510 2506
2511#endif 2507#endif
2512 2508
2513#if DB_VERSION_MINOR >= 3 2509#if DBVER >= 403
2514 2510
2515MODULE = BDB PACKAGE = BDB::Sequence 2511MODULE = BDB PACKAGE = BDB::Sequence
2516 2512
2517void 2513void
2518DESTROY (DB_SEQUENCE_ornuked *seq) 2514DESTROY (DB_SEQUENCE_ornuked *seq)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines