--- BDB/BDB.xs 2007/12/06 02:44:48 1.21 +++ BDB/BDB.xs 2008/07/29 03:33:16 1.48 @@ -1,3 +1,5 @@ +#define X_STACKSIZE 1024 * 128 + sizeof (long) * 64 * 1024 / 4 + #include "xthread.h" #include @@ -29,8 +31,8 @@ #include -#if DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 4) -# error you need Berkeley DB 4.4 or newer installed +#if DB_VERSION_MAJOR != 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 3) +# error you need Berkeley DB 4.3 or a newer 4.x version installed #endif /* number of seconds after which idle threads exit */ @@ -40,10 +42,19 @@ typedef DB_TXN DB_TXN_ornull; typedef DBC DBC_ornull; typedef DB DB_ornull; + +typedef DB_ENV DB_ENV_ornuked; +typedef DB_TXN DB_TXN_ornuked; +typedef DBC DBC_ornuked; +typedef DB DB_ornuked; + +#if DB_VERSION_MINOR >= 3 typedef DB_SEQUENCE DB_SEQUENCE_ornull; +typedef DB_SEQUENCE DB_SEQUENCE_ornuked; +#endif typedef SV SV8; /* byte-sv, used for argument-checking */ -typedef char *octetstring; +typedef char *bdb_filename; static SV *prepare_cb; @@ -57,6 +68,36 @@ # define c_put put #endif +static char * +get_bdb_filename (SV *sv) +{ + if (!SvOK (sv)) + return 0; + +#if _WIN32 + /* win32 madness + win32 perl absolutely brokenness make for horrible hacks */ + { + STRLEN len; + char *src = SvPVbyte (sv, len); + SV *t1 = sv_newmortal (); + SV *t2 = sv_newmortal (); + + sv_upgrade (t1, SVt_PV); SvPOK_only (t1); SvGROW (t1, len * 16 + 1); + sv_upgrade (t2, SVt_PV); SvPOK_only (t2); SvGROW (t2, len * 16 + 1); + + len = MultiByteToWideChar (CP_ACP, 0, src, len, (WCHAR *)SvPVX (t1), SvLEN (t1) / sizeof (WCHAR)); + len = WideCharToMultiByte (CP_UTF8, 0, (WCHAR *)SvPVX (t1), len, SvPVX (t2), SvLEN (t2), 0, 0); + SvPOK_only (t2); + SvPVX (t2)[len] = 0; + SvCUR_set (t2, len); + + return SvPVX (t2); + } +#else + return SvPVbyte_nolen (sv); +#endif +} + static void debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) { @@ -103,17 +144,17 @@ enum { REQ_QUIT, REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, - REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, - REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, - REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, + REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, + REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, + REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, }; -typedef struct aio_cb +typedef struct bdb_cb { - struct aio_cb *volatile next; + struct bdb_cb *volatile next; SV *callback; int type, pri, result; @@ -125,16 +166,18 @@ UV uv1; int int1, int2; U32 uint1, uint2; - char *buf1, *buf2; + char *buf1, *buf2, *buf3; SV *sv1, *sv2, *sv3; DBT dbt1, dbt2, dbt3; DB_KEY_RANGE key_range; +#if DB_VERSION_MINOR >= 3 DB_SEQUENCE *seq; db_seq_t seq_t; -} aio_cb; +#endif +} bdb_cb; -typedef aio_cb *aio_req; +typedef bdb_cb *bdb_req; enum { PRI_MIN = -4, @@ -147,6 +190,8 @@ #define AIO_TICKS ((1000000 + 1023) >> 10) +static SV *on_next_submit; + static unsigned int max_poll_time = 0; static unsigned int max_poll_reqs = 0; @@ -171,7 +216,7 @@ thread_t tid; /* locked by reslock, reqlock or wrklock */ - aio_req req; /* currently processed request */ + bdb_req req; /* currently processed request */ void *dbuf; DIR *dirp; } worker; @@ -201,7 +246,7 @@ #if WORDACCESS_UNSAFE -static unsigned int get_nready () +static unsigned int get_nready (void) { unsigned int retval; @@ -212,7 +257,7 @@ return retval; } -static unsigned int get_npending () +static unsigned int get_npending (void) { unsigned int retval; @@ -223,7 +268,7 @@ return retval; } -static unsigned int get_nthreads () +static unsigned int get_nthreads (void) { unsigned int retval; @@ -248,14 +293,14 @@ * per shift, the most expensive operation. */ typedef struct { - aio_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ + bdb_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ int size; } reqq; static reqq req_queue; static reqq res_queue; -int reqq_push (reqq *q, aio_req req) +int reqq_push (reqq *q, bdb_req req) { int pri = req->pri; req->next = 0; @@ -271,7 +316,7 @@ return q->size++; } -aio_req reqq_shift (reqq *q) +bdb_req reqq_shift (reqq *q) { int pri; @@ -282,7 +327,7 @@ for (pri = NUM_PRI; pri--; ) { - aio_req req = q->qs[pri]; + bdb_req req = q->qs[pri]; if (req) { @@ -296,15 +341,15 @@ abort (); } -static int poll_cb (); -static void req_free (aio_req req); -static void req_cancel (aio_req req); +static int poll_cb (void); +static void req_free (bdb_req req); +static void req_cancel (bdb_req req); -static int req_invoke (aio_req req) +static int req_invoke (bdb_req req) { dSP; - if (SvOK (req->callback)) + if (req->callback) { ENTER; SAVETMPS; @@ -328,6 +373,12 @@ dbt_to_sv (req->sv3, &req->dbt3); break; + case REQ_DB_PUT: + case REQ_C_PUT: + dbt_to_sv (0, &req->dbt1); + dbt_to_sv (0, &req->dbt2); + break; + case REQ_DB_KEY_RANGE: { AV *av = newAV (); @@ -342,6 +393,7 @@ } break; +#if DB_VERSION_MINOR >= 3 case REQ_SEQ_GET: SvREADONLY_off (req->sv1); @@ -352,6 +404,7 @@ SvREFCNT_dec (req->sv1); break; +#endif } errno = req->result; @@ -367,10 +420,14 @@ return !SvTRUE (ERRSV); } -static void req_free (aio_req req) +static void req_free (bdb_req req) { + SvREFCNT_dec (req->callback); + free (req->buf1); free (req->buf2); + free (req->buf3); + Safefree (req); } @@ -381,7 +438,7 @@ #endif static void -create_respipe () +create_respipe (void) { #ifdef _WIN32 int arg; /* argg */ @@ -445,7 +502,7 @@ X_UNLOCK (wrklock); } -static void maybe_start_thread () +static void maybe_start_thread (void) { if (get_nthreads () >= wanted) return; @@ -457,12 +514,24 @@ start_thread (); } -static void req_send (aio_req req) +static void req_send (bdb_req req) { SV *wait_callback = 0; + if (on_next_submit) + { + dSP; + SV *cb = sv_2mortal (on_next_submit); + + on_next_submit = 0; + + PUSHMARK (SP); + PUTBACK; + call_sv (cb, G_DISCARD | G_EVAL); + } + // synthesize callback if none given - if (!SvOK (req->callback)) + if (!req->callback) { int count; @@ -475,7 +544,7 @@ if (count != 2) croak ("prepare callback must return exactly two values\n"); - wait_callback = SvREFCNT_inc (POPs); + wait_callback = POPs; SvREFCNT_dec (req->callback); req->callback = SvREFCNT_inc (POPs); } @@ -496,15 +565,14 @@ PUSHMARK (SP); PUTBACK; call_sv (wait_callback, G_DISCARD); - SvREFCNT_dec (wait_callback); } } static void end_thread (void) { - aio_req req; + bdb_req req; - Newz (0, req, 1, aio_cb); + Newz (0, req, 1, bdb_cb); req->type = REQ_QUIT; req->pri = PRI_MAX + PRI_BIAS; @@ -541,7 +609,7 @@ end_thread (); } -static void poll_wait () +static void poll_wait (void) { fd_set rfd; @@ -564,14 +632,14 @@ } } -static int poll_cb () +static int poll_cb (void) { dSP; int count = 0; int maxreqs = max_poll_reqs; int do_croak = 0; struct timeval tv_start, tv_now; - aio_req req; + bdb_req req; if (max_poll_time) gettimeofday (&tv_start, 0); @@ -642,7 +710,7 @@ X_THREAD_PROC (bdb_proc) { - aio_req req; + bdb_req req; struct timespec ts; worker *self = (worker *)thr_arg; @@ -719,6 +787,14 @@ req->result = req->env->memp_trickle (req->env, req->int1, &req->int2); break; + case REQ_ENV_DBREMOVE: + req->result = req->env->dbremove (req->env, req->txn, req->buf1, req->buf2, req->uint1); + break; + + case REQ_ENV_DBRENAME: + req->result = req->env->dbrename (req->env, req->txn, req->buf1, req->buf2, req->buf3, req->uint1); + break; + case REQ_DB_OPEN: req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2); break; @@ -727,18 +803,29 @@ req->result = req->db->close (req->db, req->uint1); break; +#if DB_VERSION_MINOR >= 4 case REQ_DB_COMPACT: req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0); break; +#endif case REQ_DB_SYNC: req->result = req->db->sync (req->db, req->uint1); break; + case REQ_DB_UPGRADE: + req->result = req->db->upgrade (req->db, req->buf1, req->uint1); + break; + case REQ_DB_PUT: req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); break; +#if DB_VERSION_MINOR >= 6 + case REQ_DB_EXISTS: + req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1); + break; +#endif case REQ_DB_GET: req->result = req->db->get (req->db, req->txn, &req->dbt1, &req->dbt3, req->uint1); break; @@ -802,6 +889,7 @@ req->result = req->dbc->c_del (req->dbc, req->uint1); break; +#if DB_VERSION_MINOR >= 3 case REQ_SEQ_OPEN: req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); break; @@ -817,6 +905,7 @@ case REQ_SEQ_REMOVE: req->result = req->seq->remove (req->seq, req->txn, req->uint1); break; +#endif default: req->result = ENOSYS; @@ -866,7 +955,7 @@ static void atfork_child (void) { - aio_req prv; + bdb_req prv; while (prv = reqq_shift (&req_queue)) req_free (prv); @@ -897,28 +986,28 @@ } #define dREQ(reqtype) \ - aio_req req; \ + bdb_req req; \ int req_pri = next_pri; \ next_pri = DEFAULT_PRI + PRI_BIAS; \ \ - if (SvOK (callback) && !SvROK (callback)) \ - croak ("callback must be undef or of reference type"); \ + if (callback && SvOK (callback)) \ + croak ("callback has illegal type or extra arguments"); \ \ - Newz (0, req, 1, aio_cb); \ + Newz (0, req, 1, bdb_cb); \ if (!req) \ - croak ("out of memory during aio_req allocation"); \ + croak ("out of memory during bdb_req allocation"); \ \ - req->callback = newSVsv (callback); \ + req->callback = cb ? SvREFCNT_inc (cb) : 0; \ req->type = (reqtype); \ req->pri = req_pri #define REQ_SEND \ req_send (req) -#define SvPTR(var, arg, type, class, nullok) \ +#define SvPTR(var, arg, type, class, nullok) \ if (!SvOK (arg)) \ { \ - if (!nullok) \ + if (nullok != 1) \ croak (# var " must be a " # class " object, not undef"); \ \ (var) = 0; \ @@ -927,12 +1016,11 @@ { \ IV tmp = SvIV ((SV*) SvRV (arg)); \ (var) = INT2PTR (type, tmp); \ - if (!var) \ + if (!var && nullok != 2) \ croak (# var " is not a valid " # class " object anymore"); \ } \ else \ - croak (# var " is not of type " # class); \ - \ + croak (# var " is not of type " # class); static void ptr_nuke (SV *sv) @@ -941,6 +1029,82 @@ sv_setiv (SvRV (sv), 0); } +static int +errno_get (pTHX_ SV *sv, MAGIC *mg) +{ + if (*mg->mg_ptr == '!') // should always be the case + if (-30999 <= errno && errno <= -30800) + { + sv_setnv (sv, (NV)errno); + sv_setpv (sv, db_strerror (errno)); + SvNOK_on (sv); /* what a wonderful hack! */ + // ^^^ copied from perl sources + return 0; + } + + return PL_vtbl_sv.svt_get (aTHX_ sv, mg); +} + +static MGVTBL vtbl_errno; + +// this wonderful hack :( patches perl's $! variable to support our errno values +static void +patch_errno (void) +{ + SV *sv; + MAGIC *mg; + + if (!(sv = get_sv ("!", 1))) + return; + + if (!(mg = mg_find (sv, PERL_MAGIC_sv))) + return; + + if (mg->mg_virtual != &PL_vtbl_sv) + return; + + vtbl_errno = PL_vtbl_sv; + vtbl_errno.svt_get = errno_get; + mg->mg_virtual = &vtbl_errno; +} + +#if __GNUC__ >= 4 +# define noinline __attribute__ ((noinline)) +#else +# define noinline +#endif + +static noinline SV * +pop_callback (I32 *ritems, SV *sv) +{ + if (SvROK (sv)) + { + HV *st; + GV *gvp; + CV *cv; + const char *name; + + /* forgive me */ + if (SvTYPE (SvRV (sv)) == SVt_PVMG + && (st = SvSTASH (SvRV (sv))) + && (name = HvNAME_get (st)) + && (name [0] == 'B' && name [1] == 'D' && name [2] == 'B' && name [3] == ':')) + return 0; + + if ((cv = sv_2cv (sv, &st, &gvp, 0))) + { + --*ritems; + return (SV *)cv; + } + } + + return 0; +} + +/* stupid windoes defined CALLBACK as well */ +#undef CALLBACK +#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); + MODULE = BDB PACKAGE = BDB PROTOTYPES: ENABLE @@ -970,16 +1134,10 @@ const_iv (USE_ENVIRON_ROOT) const_iv (LOCKDOWN) const_iv (PRIVATE) - const_iv (REGISTER) const_iv (SYSTEM_MEM) const_iv (AUTO_COMMIT) const_iv (CDB_ALLDB) const_iv (DIRECT_DB) - const_iv (DIRECT_LOG) - const_iv (DSYNC_DB) - const_iv (DSYNC_LOG) - const_iv (LOG_AUTOREMOVE) - const_iv (LOG_INMEMORY) const_iv (NOLOCKING) const_iv (NOMMAP) const_iv (NOPANIC) @@ -1000,8 +1158,6 @@ const_iv (RECNO) const_iv (UNKNOWN) const_iv (EXCL) - const_iv (READ_COMMITTED) - const_iv (READ_UNCOMMITTED) const_iv (TRUNCATE) const_iv (NOSYNC) const_iv (CHKSUM) @@ -1011,7 +1167,6 @@ const_iv (RECNUM) const_iv (RENUMBER) const_iv (REVSPLITOFF) - const_iv (INORDER) const_iv (CONSUME) const_iv (CONSUME_WAIT) const_iv (GET_BOTH) @@ -1020,6 +1175,7 @@ //const_iv (MULTIPLE) const_iv (SNAPSHOT) const_iv (JOIN_ITEM) + const_iv (JOIN_NOSORT) const_iv (RMW) const_iv (NOTFOUND) @@ -1029,12 +1185,8 @@ const_iv (RUNRECOVERY) const_iv (OLD_VERSION) const_iv (REP_HANDLE_DEAD) - const_iv (REP_LOCKOUT) const_iv (SECONDARY_BAD) - const_iv (FREE_SPACE) - const_iv (FREELIST_ONLY) - const_iv (APPEND) const_iv (NODUPDATA) const_iv (NOOVERWRITE) @@ -1045,7 +1197,6 @@ const_iv (SET_LOCK_TIMEOUT) const_iv (SET_TXN_TIMEOUT) - const_iv (JOIN_ITEM) const_iv (FIRST) const_iv (NEXT) const_iv (NEXT_DUP) @@ -1067,37 +1218,26 @@ const_iv (LOCK_DEFAULT) const_iv (LOCK_EXPIRE) const_iv (LOCK_MAXLOCKS) - const_iv (LOCK_MAXWRITE) const_iv (LOCK_MINLOCKS) const_iv (LOCK_MINWRITE) const_iv (LOCK_OLDEST) const_iv (LOCK_RANDOM) const_iv (LOCK_YOUNGEST) - const_iv (SEQ_DEC) - const_iv (SEQ_INC) - const_iv (SEQ_WRAP) - - const_iv (BUFFER_SMALL) const_iv (DONOTINDEX) const_iv (KEYEMPTY ) const_iv (KEYEXIST ) const_iv (LOCK_DEADLOCK) const_iv (LOCK_NOTGRANTED) - const_iv (LOG_BUFFER_FULL) const_iv (NOSERVER) const_iv (NOSERVER_HOME) const_iv (NOSERVER_ID) const_iv (NOTFOUND) - const_iv (OLD_VERSION) const_iv (PAGE_NOTFOUND) const_iv (REP_DUPMASTER) const_iv (REP_HANDLE_DEAD) const_iv (REP_HOLDELECTION) - const_iv (REP_IGNORE) const_iv (REP_ISPERM) - const_iv (REP_JOIN_FAILURE) - const_iv (REP_LOCKOUT) const_iv (REP_NEWMASTER) const_iv (REP_NEWSITE) const_iv (REP_NOTPERM) @@ -1105,30 +1245,62 @@ const_iv (RUNRECOVERY) const_iv (SECONDARY_BAD) const_iv (VERIFY_BAD) - const_iv (VERSION_MISMATCH) const_iv (VERB_DEADLOCK) const_iv (VERB_RECOVERY) - const_iv (VERB_REGISTER) const_iv (VERB_REPLICATION) const_iv (VERB_WAITSFOR) const_iv (VERSION_MAJOR) const_iv (VERSION_MINOR) const_iv (VERSION_PATCH) +#if DB_VERSION_MINOR >= 3 + const_iv (INORDER) + const_iv (LOCK_MAXWRITE) + const_iv (SEQ_DEC) + const_iv (SEQ_INC) + const_iv (SEQ_WRAP) + const_iv (BUFFER_SMALL) + const_iv (LOG_BUFFER_FULL) + const_iv (VERSION_MISMATCH) +#endif +#if DB_VERSION_MINOR >= 4 + const_iv (REGISTER) + const_iv (DSYNC_DB) + const_iv (READ_COMMITTED) + const_iv (READ_UNCOMMITTED) + const_iv (REP_IGNORE) + const_iv (REP_LOCKOUT) + const_iv (REP_JOIN_FAILURE) + const_iv (FREE_SPACE) + const_iv (FREELIST_ONLY) + const_iv (VERB_REGISTER) +#endif #if DB_VERSION_MINOR >= 5 const_iv (MULTIVERSION) const_iv (TXN_SNAPSHOT) #endif #if DB_VERSION_MINOR >= 6 const_iv (PREV_DUP) -# if 0 const_iv (PRIORITY_UNCHANGED) const_iv (PRIORITY_VERY_LOW) const_iv (PRIORITY_LOW) const_iv (PRIORITY_DEFAULT) const_iv (PRIORITY_HIGH) const_iv (PRIORITY_VERY_HIGH) +#endif +#if DB_VERSION_MINOR >= 7 + const_iv (LOG_DIRECT) + const_iv (LOG_DSYNC) + const_iv (LOG_AUTO_REMOVE) + const_iv (LOG_IN_MEMORY) + const_iv (LOG_ZERO) +#else + const_iv (DIRECT_LOG) + const_iv (LOG_AUTOREMOVE) +# if DB_VERSION_MINOR >= 3 + const_iv (DSYNC_LOG) + const_iv (LOG_INMEMORY) # endif #endif }; @@ -1136,19 +1308,19 @@ for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); - newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); - newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); + { + /* we currently only allow version, minor-version and patchlevel to go up to 255 */ + char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; + + newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); + } + + newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); create_respipe (); X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); -#ifdef _WIN32 - X_MUTEX_CHECK (wrklock); - X_MUTEX_CHECK (reslock); - X_MUTEX_CHECK (reqlock); - - X_COND_CHECK (reqwait); -#endif + patch_errno (); } void @@ -1298,6 +1470,11 @@ OUTPUT: RETVAL +void _on_next_submit (SV *cb) + CODE: + SvREFCNT_dec (on_next_submit); + on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; + DB_ENV * db_env_create (U32 env_flags = 0) CODE: @@ -1316,13 +1493,12 @@ RETVAL void -db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) +db_env_open (DB_ENV *env, bdb_filename db_home, U32 open_flags, int mode, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_ENV_OPEN); - - env->set_thread_count (env, wanted + 2); - req->env = env; req->uint1 = open_flags | DB_THREAD; req->int1 = mode; @@ -1331,7 +1507,9 @@ } void -db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = &PL_sv_undef) +db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_ENV_CLOSE); @@ -1342,7 +1520,9 @@ } void -db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = &PL_sv_undef) +db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_ENV_TXN_CHECKPOINT); @@ -1354,18 +1534,23 @@ } void -db_env_lock_detect (DB_ENV *env, U32 flags = 0, U32 atype = DB_LOCK_DEFAULT, SV *dummy = 0, SV *callback = &PL_sv_undef) +db_env_lock_detect (DB_ENV *env, U32 flags = 0, U32 atype = DB_LOCK_DEFAULT, SV *dummy = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_ENV_LOCK_DETECT); req->env = env; req->uint1 = flags; req->uint2 = atype; + /* req->int2 = 0; dummy */ REQ_SEND; } void -db_env_memp_sync (DB_ENV *env, SV *dummy = 0, SV *callback = &PL_sv_undef) +db_env_memp_sync (DB_ENV *env, SV *dummy = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_ENV_MEMP_SYNC); @@ -1374,7 +1559,9 @@ } void -db_env_memp_trickle (DB_ENV *env, int percent, SV *dummy = 0, SV *callback = &PL_sv_undef) +db_env_memp_trickle (DB_ENV *env, int percent, SV *dummy = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_ENV_MEMP_TRICKLE); @@ -1383,6 +1570,34 @@ REQ_SEND; } +void +db_env_dbremove (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK + CODE: +{ + dREQ (REQ_ENV_DBREMOVE); + req->env = env; + req->buf1 = strdup_ornull (file); + req->buf2 = strdup_ornull (database); + req->uint1 = flags; + REQ_SEND; +} + +void +db_env_dbrename (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, bdb_filename newname, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK + CODE: +{ + dREQ (REQ_ENV_DBRENAME); + req->env = env; + req->buf1 = strdup_ornull (file); + req->buf2 = strdup_ornull (database); + req->buf3 = strdup_ornull (newname); + req->uint1 = flags; + REQ_SEND; +} DB * db_create (DB_ENV *env = 0, U32 flags = 0) @@ -1399,7 +1614,9 @@ RETVAL void -db_open (DB *db, DB_TXN_ornull *txnid, octetstring file, octetstring database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) +db_open (DB *db, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, int type, U32 flags, int mode, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_DB_OPEN); @@ -1414,7 +1631,9 @@ } void -db_close (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) +db_close (DB *db, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_DB_CLOSE); @@ -1425,8 +1644,12 @@ ptr_nuke (ST (0)); } +#if DB_VERSION_MINOR >= 4 + void -db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = &PL_sv_undef) +db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_DB_COMPACT); @@ -1438,18 +1661,37 @@ REQ_SEND; } +#endif + +void +db_sync (DB *db, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK + CODE: +{ + dREQ (REQ_DB_SYNC); + req->db = db; + req->uint1 = flags; + REQ_SEND; +} + void -db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) +db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_DB_SYNC); req->db = db; + req->buf1 = strdup (file); req->uint1 = flags; REQ_SEND; } void -db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) +db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_DB_KEY_RANGE); @@ -1462,7 +1704,9 @@ } void -db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) +db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_DB_PUT); @@ -1474,10 +1718,32 @@ REQ_SEND; } +#if DB_VERSION_MINOR >= 6 + void -db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) +db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { + dREQ (REQ_DB_EXISTS); + req->db = db; + req->txn = txn; + req->uint1 = flags; + sv_to_dbt (&req->dbt1, key); + REQ_SEND; +} + +#endif + +void +db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK + CODE: + if (SvREADONLY (data)) + croak ("can't modify read-only data scalar in db_get"); +{ dREQ (REQ_DB_GET); req->db = db; req->txn = txn; @@ -1489,8 +1755,12 @@ } void -db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) +db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: + if (SvREADONLY (data)) + croak ("can't modify read-only data scalar in db_pget"); { dREQ (REQ_DB_PGET); req->db = db; @@ -1504,7 +1774,9 @@ } void -db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) +db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_DB_DEL); @@ -1516,7 +1788,9 @@ } void -db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) +db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_TXN_COMMIT); @@ -1527,7 +1801,9 @@ } void -db_txn_abort (DB_TXN *txn, SV *callback = &PL_sv_undef) +db_txn_abort (DB_TXN *txn, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_TXN_ABORT); @@ -1537,7 +1813,9 @@ } void -db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) +db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_TXN_FINISH); @@ -1548,7 +1826,9 @@ } void -db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) +db_c_close (DBC *dbc, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_C_CLOSE); @@ -1558,7 +1838,9 @@ } void -db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = &PL_sv_undef) +db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_C_COUNT); @@ -1568,7 +1850,9 @@ } void -db_c_put (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) +db_c_put (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_C_PUT); @@ -1580,7 +1864,9 @@ } void -db_c_get (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) +db_c_get (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_C_GET); @@ -1605,7 +1891,9 @@ } void -db_c_pget (DBC *dbc, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) +db_c_pget (DBC *dbc, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_C_PGET); @@ -1633,7 +1921,9 @@ } void -db_c_del (DBC *dbc, U32 flags = 0, SV *callback = &PL_sv_undef) +db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_C_DEL); @@ -1643,8 +1933,12 @@ } +#if DB_VERSION_MINOR >= 3 + void -db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) +db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_SEQ_OPEN); @@ -1656,7 +1950,9 @@ } void -db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = &PL_sv_undef) +db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_SEQ_CLOSE); @@ -1667,7 +1963,9 @@ } void -db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = &PL_sv_undef) +db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_SEQ_GET); @@ -1680,7 +1978,9 @@ } void -db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = &PL_sv_undef) +db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = 0) + PREINIT: + CALLBACK CODE: { dREQ (REQ_SEQ_REMOVE); @@ -1690,11 +1990,13 @@ REQ_SEND; } +#endif + MODULE = BDB PACKAGE = BDB::Env void -DESTROY (DB_ENV_ornull *env) +DESTROY (DB_ENV_ornuked *env) CODE: if (env) env->close (env, 0); @@ -1729,12 +2031,29 @@ OUTPUT: RETVAL -int set_flags (DB_ENV *env, U32 flags, int onoff) +int set_flags (DB_ENV *env, U32 flags, int onoff = 1) CODE: RETVAL = env->set_flags (env, flags, onoff); OUTPUT: RETVAL +#if DB_VERSION_MINOR >= 7 + +int set_intermediate_dir_mode (DB_ENV *env, const char *mode) + CODE: + RETVAL = env->set_intermediate_dir_mode (env, mode); + OUTPUT: + RETVAL + +int log_set_config (DB_ENV *env, U32 flags, int onoff = 1) + CODE: + RETVAL = env->log_set_config (env, flags, onoff); + OUTPUT: + RETVAL + +#endif + + void set_errfile (DB_ENV *env, FILE *errfile = 0) CODE: env->set_errfile (env, errfile); @@ -1743,7 +2062,7 @@ CODE: env->set_msgfile (env, msgfile); -int set_verbose (DB_ENV *env, U32 which, int onoff = 1) +int set_verbose (DB_ENV *env, U32 which = -1, int onoff = 1) CODE: RETVAL = env->set_verbose (env, which, onoff); OUTPUT: @@ -1815,6 +2134,34 @@ OUTPUT: RETVAL +#if DB_VERSION_MINOR >= 4 + +int mutex_set_max (DB_ENV *env, U32 max) + CODE: + RETVAL = env->mutex_set_max (env, max); + OUTPUT: + RETVAL + +int mutex_set_increment (DB_ENV *env, U32 increment) + CODE: + RETVAL = env->mutex_set_increment (env, increment); + OUTPUT: + RETVAL + +int mutex_set_tas_spins (DB_ENV *env, U32 tas_spins) + CODE: + RETVAL = env->mutex_set_tas_spins (env, tas_spins); + OUTPUT: + RETVAL + +int mutex_set_align (DB_ENV *env, U32 align) + CODE: + RETVAL = env->mutex_set_align (env, align); + OUTPUT: + RETVAL + +#endif + DB_TXN * txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0) CODE: @@ -1824,10 +2171,23 @@ OUTPUT: RETVAL +#if DB_VERSION_MINOR >= 5 + +DB_TXN * +cdsgroup_begin (DB_ENV *env) + CODE: + errno = env->cdsgroup_begin (env, &RETVAL); + if (errno) + croak ("DB_ENV->cdsgroup_begin: %s", db_strerror (errno)); + OUTPUT: + RETVAL + +#endif + MODULE = BDB PACKAGE = BDB::Db void -DESTROY (DB_ornull *db) +DESTROY (DB_ornuked *db) CODE: if (db) { @@ -1917,6 +2277,8 @@ OUTPUT: RETVAL +#if DB_VERSION_MINOR >= 3 + DB_SEQUENCE * sequence (DB *db, U32 flags = 0) CODE: @@ -1928,11 +2290,13 @@ OUTPUT: RETVAL +#endif + MODULE = BDB PACKAGE = BDB::Txn void -DESTROY (DB_TXN_ornull *txn) +DESTROY (DB_TXN_ornuked *txn) CODE: if (txn) txn->abort (txn); @@ -1953,15 +2317,25 @@ MODULE = BDB PACKAGE = BDB::Cursor void -DESTROY (DBC_ornull *dbc) +DESTROY (DBC_ornuked *dbc) CODE: if (dbc) dbc->c_close (dbc); +#if DB_VERSION_MINOR >= 6 + +int set_priority (DBC *dbc, int priority) + CODE: + dbc->set_priority (dbc, priority); + +#endif + +#if DB_VERSION_MINOR >= 3 + MODULE = BDB PACKAGE = BDB::Sequence void -DESTROY (DB_SEQUENCE_ornull *seq) +DESTROY (DB_SEQUENCE_ornuked *seq) CODE: if (seq) seq->close (seq, 0); @@ -1990,3 +2364,6 @@ OUTPUT: RETVAL +#endif + +