BDB

 view release on metacpan or  search on metacpan

BDB.xs  view on Meta::CPAN


#include "schmorp.h"

// perl stupidly defines these as argument-less macros, breaking
// lots and lots of code.
#undef open
#undef close
#undef abort
#undef malloc
#undef free
#undef send

#include <stddef.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <limits.h>
#include <fcntl.h>

#ifndef _WIN32
# include <sys/time.h>
# include <unistd.h>
#endif

#include <db.h>

#define DBVER DB_VERSION_MAJOR * 100 + DB_VERSION_MINOR

#if DBVER < 403
# error you need Berkeley DB 4.3 or a newer version installed
#endif

/* number of seconds after which idle threads exit */
#define IDLE_TIMEOUT 10

typedef SV          SV_mutable;

typedef DB_ENV      DB_ENV_ornull;
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 DBVER >= 403
typedef DB_SEQUENCE DB_SEQUENCE_ornull;
typedef DB_SEQUENCE DB_SEQUENCE_ornuked;
#endif

typedef char *bdb_filename;

static SV *prepare_cb;

static HV
  *bdb_stash,
  *bdb_env_stash,
  *bdb_txn_stash,
  *bdb_cursor_stash,
  *bdb_db_stash,
  *bdb_sequence_stash;

#if DBVER >= 406
# define c_close close 
# define c_count count 
# define c_del   del   
# define c_dup   dup   
# define c_get   get   
# define c_pget  pget  
# 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)
{
  printf ("err[%s]\n", msg);
}

static void
debug_msgcall (const DB_ENV *dbenv, const char *msg)
{
  printf ("msg[%s]\n", msg);
}

static char *
strdup_ornull (const char *s)
{
  return s ? strdup (s) : 0;
}

BDB.xs  view on Meta::CPAN

          const_iv (LOGOLDVER)
#if DBVER >= 403
          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 DBVER >= 404
          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 DBVER >= 405
          const_iv (MULTIVERSION)
          const_iv (TXN_SNAPSHOT)
#endif
#if DBVER >= 406
          const_iv (PREV_DUP)
          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)
          const_iv (IGNORE_LEASE)
#endif
#if DBVER >= 407
          //const_iv (MULTIPLE_KEY)
          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 DBVER >= 403
          const_iv (DSYNC_LOG)
          const_iv (LOG_INMEMORY)
# endif
#if DBVER >= 408
          const_iv (LOGVERSION_LATCHING)
#endif
#endif
        };

	bdb_stash          = gv_stashpv ("BDB"          , 1);
        bdb_env_stash      = gv_stashpv ("BDB::Env"     , 1);
        bdb_txn_stash      = gv_stashpv ("BDB::Txn"     , 1);
        bdb_cursor_stash   = gv_stashpv ("BDB::Cursor"  , 1);
        bdb_db_stash       = gv_stashpv ("BDB::Db"      , 1);
        bdb_sequence_stash = gv_stashpv ("BDB::Sequence", 1);

        for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
          newCONSTSUB (bdb_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));

        prepare_cb = &PL_sv_undef;

        {
          /* 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 (bdb_stash, "VERSION_v", newSVpvn (vstring, 3));
        }

        newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));

        create_respipe ();

        X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
        patch_errno ();
}

void
max_poll_reqs (int nreqs)
	PROTOTYPE: $
        CODE:
        max_poll_reqs = nreqs;

void
max_poll_time (double nseconds)
	PROTOTYPE: $
        CODE:
        max_poll_time = nseconds * AIO_TICKS;

void
min_parallel (int nthreads)
	PROTOTYPE: $

void
max_parallel (int nthreads)
	PROTOTYPE: $

void
max_idle (int nthreads)
	PROTOTYPE: $
        CODE:
        set_max_idle (nthreads);

int
max_outstanding (int maxreqs)
	PROTOTYPE: $
        CODE:
        RETVAL = max_outstanding;
        max_outstanding = maxreqs;
	OUTPUT:
        RETVAL

int
dbreq_pri (int pri = 0)

BDB.xs  view on Meta::CPAN

	CODE:
        RETVAL = db->set_encrypt (db, password, flags);
	OUTPUT:
        RETVAL

int set_lorder (DB *db, int lorder)
	CODE:
        RETVAL = db->set_lorder (db, lorder);
	OUTPUT:
        RETVAL

int set_bt_minkey (DB *db, U32 minkey)
	CODE:
        RETVAL = db->set_bt_minkey (db, minkey);
	OUTPUT:
        RETVAL

int set_re_delim (DB *db, int delim)
	CODE:
        RETVAL = db->set_re_delim (db, delim);
	OUTPUT:
        RETVAL

int set_re_pad (DB *db, int re_pad)
	CODE:
        RETVAL = db->set_re_pad (db, re_pad);
	OUTPUT:
        RETVAL

int set_re_source (DB *db, char *source)
	CODE:
        RETVAL = db->set_re_source (db, source);
	OUTPUT:
        RETVAL

int set_re_len (DB *db, U32 re_len)
	CODE:
        RETVAL = db->set_re_len (db, re_len);
	OUTPUT:
        RETVAL

int set_h_ffactor (DB *db, U32 h_ffactor)
	CODE:
        RETVAL = db->set_h_ffactor (db, h_ffactor);
	OUTPUT:
        RETVAL

int set_h_nelem (DB *db, U32 h_nelem)
	CODE:
        RETVAL = db->set_h_nelem (db, h_nelem);
	OUTPUT:
        RETVAL

int set_q_extentsize (DB *db, U32 extentsize)
	CODE:
        RETVAL = db->set_q_extentsize (db, extentsize);
	OUTPUT:
        RETVAL

DBC *
cursor (DB *db, DB_TXN_ornull *txn = 0, U32 flags = 0)
	CODE:
        errno = db->cursor (db, txn, &RETVAL, flags);
        if (errno)
          croak ("DB->cursor: %s", db_strerror (errno));
        OUTPUT:
        RETVAL

#if DBVER >= 403

DB_SEQUENCE *
sequence (DB *db, U32 flags = 0)
	CODE:
{
        errno = db_sequence_create (&RETVAL, db, flags);
        if (errno)
          croak ("db_sequence_create: %s", db_strerror (errno));
}
	OUTPUT:
	RETVAL

#endif


MODULE = BDB		PACKAGE = BDB::Txn

void
DESTROY (DB_TXN_ornuked *txn)
	CODE:
        if (txn)
          txn->abort (txn);

int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT)
	CODE:
        RETVAL = txn->set_timeout (txn, timeout * 1000000, flags);
	OUTPUT:
        RETVAL

int failed (DB_TXN *txn)
	CODE:
        RETVAL = !!(txn->flags & TXN_DEADLOCK);
	OUTPUT:
        RETVAL


MODULE = BDB		PACKAGE = BDB::Cursor

void
DESTROY (DBC_ornuked *dbc)
	CODE:
        if (dbc)
          dbc->c_close (dbc);

#if DBVER >= 406

int set_priority (DBC *dbc, int priority)
        CODE:
        dbc->set_priority (dbc, priority);

#endif

#if DBVER >= 403

MODULE = BDB		PACKAGE = BDB::Sequence



( run in 0.671 second using v1.01-cache-2.11-cpan-39bf76dae61 )