Ruby 1.9 compatible

master
Denis Knauf 2010-01-29 23:17:31 +01:00
parent 1bf9900ea7
commit 58556ce892
3 changed files with 45 additions and 42 deletions

View File

@ -5,13 +5,13 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{bdb} s.name = %q{bdb}
s.version = "0.2.2" s.version = "0.2.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Justin Balthrop"] s.authors = ["Justin Balthrop", "Denis Knauf"]
s.date = %q{2009-12-17} s.date = %q{2010-01-29}
s.description = %q{Advanced Ruby Berkeley DB library.} s.description = %q{Advanced Ruby Berkeley DB library.}
s.email = %q{code@justinbalthrop.com} s.email = %q{code@justinbalthrop.com Denis.Knauf@gmail.com}
s.extensions = ["ext/extconf.rb"] s.extensions = ["ext/extconf.rb"]
s.extra_rdoc_files = [ s.extra_rdoc_files = [
"LICENSE", "LICENSE",

View File

@ -100,7 +100,7 @@ static void db_free(t_dbh *dbh)
dbh->db->close(dbh->db,NOFLAGS); dbh->db->close(dbh->db,NOFLAGS);
if ( RTEST(ruby_debug) && dbh->filename[0] != '\0') if ( RTEST(ruby_debug) && dbh->filename[0] != '\0')
fprintf(stderr,"%s/%d %s %p %s\n",__FILE__,__LINE__, fprintf(stderr,"%s/%d %s %p %s\n",__FILE__,__LINE__,
"db_free database was still open!",dbh->db,dbh->filename); "db_free database was still open!",(void*)dbh->db,dbh->filename);
dbh->db=NULL; dbh->db=NULL;
} }
free(dbh); free(dbh);
@ -230,7 +230,7 @@ VALUE db_open(VALUE obj, VALUE vtxn, VALUE vdisk_file,
u_int32_t flags=0; u_int32_t flags=0;
DBTYPE dbtype=DB_UNKNOWN; DBTYPE dbtype=DB_UNKNOWN;
char *logical_db=NULL; char *logical_db=NULL;
long len; //long len;
int mode=0; int mode=0;
if ( ! NIL_P(vflags) ) if ( ! NIL_P(vflags) )
@ -498,7 +498,7 @@ VALUE db_close(VALUE obj, VALUE vflags)
if ( dbh->db==NULL ) if ( dbh->db==NULL )
return Qnil; return Qnil;
if (! NIL_P(dbh->adbc) && RARRAY(dbh->adbc)->len > 0 ) { if (! NIL_P(dbh->adbc) && RARRAY_LEN(dbh->adbc) > 0 ) {
rb_warning("%s/%d %s",__FILE__,__LINE__, rb_warning("%s/%d %s",__FILE__,__LINE__,
"cursor handles still open"); "cursor handles still open");
while ( (cur=rb_ary_pop(dbh->adbc)) != Qnil ) { while ( (cur=rb_ary_pop(dbh->adbc)) != Qnil ) {
@ -507,8 +507,8 @@ VALUE db_close(VALUE obj, VALUE vflags)
} }
if ( RTEST(ruby_debug) ) if ( RTEST(ruby_debug) )
rb_warning("%s/%d %s 0x%x %s",__FILE__,__LINE__,"db_close!",dbh, rb_warning("%s/%d %s 0x%p %s",__FILE__,__LINE__,"db_close!", (void*)dbh,
(dbh->filename==NULL||*(dbh->filename)=='0') ? "unknown" : dbh->filename); (dbh->filename==NULL||*(dbh->filename)=='0') ? (char*)"unknown" : dbh->filename);
rv = dbh->db->close(dbh->db,flags); rv = dbh->db->close(dbh->db,flags);
dbh->db=NULL; dbh->db=NULL;
@ -516,7 +516,7 @@ VALUE db_close(VALUE obj, VALUE vflags)
dbh->sproc=Qnil; dbh->sproc=Qnil;
if ( dbh->env ) { if ( dbh->env ) {
if ( RTEST(ruby_debug) ) if ( RTEST(ruby_debug) )
rb_warning("%s/%d %s 0x%x",__FILE__,__LINE__,"db_close! removing",obj); rb_warning("%s/%d %s 0x%p",__FILE__,__LINE__,"db_close! removing",(void*)obj);
rb_ary_delete(dbh->env->adb,obj); rb_ary_delete(dbh->env->adb,obj);
dbh->env = NULL; dbh->env = NULL;
} }
@ -654,7 +654,7 @@ VALUE db_pget(VALUE obj, VALUE vtxn, VALUE vkey, VALUE vdata, VALUE vflags)
int rv; int rv;
u_int32_t flags=0; u_int32_t flags=0;
DBT key,data,pkey; DBT key,data,pkey;
VALUE str; //VALUE str;
t_txnh *txn=NULL; t_txnh *txn=NULL;
memset(&key,0,sizeof(DBT)); memset(&key,0,sizeof(DBT));
@ -749,9 +749,9 @@ VALUE db_join(VALUE obj, VALUE vacurs, VALUE vflags)
if (!dbh->db) if (!dbh->db)
raise(0, "db is closed"); raise(0, "db is closed");
curs = ALLOCA_N(DBC *,RARRAY(vacurs)->len); curs = ALLOCA_N(DBC *,RARRAY_LEN(vacurs));
for (i=0; i<RARRAY(vacurs)->len; i++) { for (i=0; i<RARRAY_LEN(vacurs); i++) {
Data_Get_Struct(RARRAY(vacurs)->ptr[i],t_dbch,dbch); Data_Get_Struct(RARRAY_PTR(vacurs)[i],t_dbch,dbch);
/* cursor is closed? */ /* cursor is closed? */
curs[i]=dbch->dbc; curs[i]=dbch->dbc;
} }
@ -890,7 +890,7 @@ VALUE db_remove(VALUE obj, VALUE vdisk_file,
t_dbh *dbh; t_dbh *dbh;
int rv; int rv;
u_int32_t flags=0; u_int32_t flags=0;
char *logical_db=NULL; //char *logical_db=NULL;
if ( ! NIL_P(vflags) ) if ( ! NIL_P(vflags) )
flags=NUM2UINT(vflags); flags=NUM2UINT(vflags);
@ -921,8 +921,8 @@ VALUE db_rename(VALUE obj, VALUE vdisk_file,
t_dbh *dbh; t_dbh *dbh;
int rv; int rv;
u_int32_t flags=0; u_int32_t flags=0;
char *disk_file=NULL; //char *disk_file=NULL;
char *logical_db=NULL; //char *logical_db=NULL;
if ( ! NIL_P(vflags) ) if ( ! NIL_P(vflags) )
flags=NUM2UINT(vflags); flags=NUM2UINT(vflags);
@ -978,7 +978,7 @@ VALUE db_truncate(VALUE obj, VALUE vtxn)
t_dbh *dbh; t_dbh *dbh;
t_txnh *txn=NULL; t_txnh *txn=NULL;
int rv; int rv;
VALUE result; //VALUE result;
u_int32_t count; u_int32_t count;
if ( ! NIL_P(vtxn) ) { if ( ! NIL_P(vtxn) ) {
@ -1011,7 +1011,7 @@ VALUE db_key_range(VALUE obj, VALUE vtxn, VALUE vkey, VALUE vflags)
t_dbh *dbh; t_dbh *dbh;
t_txnh *txn=NULL; t_txnh *txn=NULL;
DBT key; DBT key;
u_int32_t flags; u_int32_t flags = 0;
int rv; int rv;
DB_KEY_RANGE key_range; DB_KEY_RANGE key_range;
VALUE result; VALUE result;
@ -1062,7 +1062,7 @@ VALUE db_del(VALUE obj, VALUE vtxn, VALUE vkey, VALUE vflags)
int rv; int rv;
u_int32_t flags; u_int32_t flags;
DBT key; DBT key;
VALUE str; //VALUE str;
t_txnh *txn=NULL; t_txnh *txn=NULL;
memset(&key,0,sizeof(DBT)); memset(&key,0,sizeof(DBT));
@ -1117,12 +1117,13 @@ VALUE assoc_rescue(VALUE *error, VALUE e)
VALUE message = StringValue(e); VALUE message = StringValue(e);
rb_warn(RSTRING_PTR(message)); rb_warn(RSTRING_PTR(message));
*error = e; *error = e;
return Qnil;
} }
int assoc_callback(DB *secdb, const DBT* pkey, const DBT* data, DBT* skey) int assoc_callback(DB *secdb, const DBT* pkey, const DBT* data, DBT* skey)
{ {
t_dbh *dbh; t_dbh *dbh;
VALUE proc; //VALUE proc;
VALUE error = Qnil; VALUE error = Qnil;
VALUE retv; VALUE retv;
VALUE args[4]; VALUE args[4];
@ -1150,20 +1151,20 @@ int assoc_callback(DB *secdb, const DBT* pkey, const DBT* data, DBT* skey)
keys = rb_check_array_type(retv); keys = rb_check_array_type(retv);
if (!NIL_P(keys)) { if (!NIL_P(keys)) {
keys = rb_funcall(keys,fv_uniq,0); /* secondary keys must be uniq */ keys = rb_funcall(keys,fv_uniq,0); /* secondary keys must be uniq */
switch(RARRAY(keys)->len) { switch(RARRAY_LEN(keys)) {
case 0: case 0:
return DB_DONOTINDEX; return DB_DONOTINDEX;
case 1: case 1:
retv=RARRAY(keys)->ptr[0]; retv=RARRAY_PTR(keys)[0];
break; break;
default: default:
skey->size = RARRAY(keys)->len; skey->size = RARRAY_LEN(keys);
skey->flags = LMEMFLAG | DB_DBT_MULTIPLE | DB_DBT_APPMALLOC; skey->flags = LMEMFLAG | DB_DBT_MULTIPLE | DB_DBT_APPMALLOC;
skey->data = malloc(skey->size * sizeof(DBT)); skey->data = malloc(skey->size * sizeof(DBT));
memset(skey->data, 0, skey->size * sizeof(DBT)); memset(skey->data, 0, skey->size * sizeof(DBT));
for (i=0; i<skey->size; i++) { for (i=0; i<skey->size; i++) {
assoc_key(skey->data + i * sizeof(DBT), (VALUE)RARRAY(keys)->ptr[i]); assoc_key(skey->data + i * sizeof(DBT), (VALUE)RARRAY_PTR(keys)[i]);
} }
return 0; return 0;
} }
@ -1190,7 +1191,7 @@ VALUE db_associate(VALUE obj, VALUE vtxn, VALUE osecdb,
t_dbh *sdbh,*pdbh; t_dbh *sdbh,*pdbh;
int rv; int rv;
u_int32_t flags,flagsp,flagss; u_int32_t flags,flagsp,flagss;
int fdp; //int fdp;
t_txnh *txn=NOTXN; t_txnh *txn=NOTXN;
flags=NUM2UINT(vflags); flags=NUM2UINT(vflags);
@ -1246,7 +1247,7 @@ bt_compare_callback2(VALUE *args)
int bt_compare_callback(DB *db, const DBT* key1, const DBT* key2) int bt_compare_callback(DB *db, const DBT* key1, const DBT* key2)
{ {
t_dbh *dbh; t_dbh *dbh;
VALUE proc; //VALUE proc;
int cmp; int cmp;
VALUE retv; VALUE retv;
@ -1313,7 +1314,7 @@ VALUE db_cursor(VALUE obj, VALUE vtxn, VALUE vflags)
t_dbh *dbh; t_dbh *dbh;
int rv; int rv;
u_int32_t flags; u_int32_t flags;
DBC *dbc; //DBC *dbc;
t_txnh *txn=NOTXN; t_txnh *txn=NOTXN;
VALUE c_obj; VALUE c_obj;
t_dbch *dbch; t_dbch *dbch;
@ -1671,18 +1672,18 @@ VALUE env_close(VALUE obj)
if ( eh->env==NULL ) if ( eh->env==NULL )
return Qnil; return Qnil;
if (RARRAY(eh->adb)->len > 0) { if (RARRAY_LEN(eh->adb) > 0) {
rb_warning("%s/%d %s %d",__FILE__,__LINE__, rb_warning("%s/%d %s %li",__FILE__,__LINE__,
"database handles still open",RARRAY(eh->adb)->len); "database handles still open",RARRAY_LEN(eh->adb));
while (RARRAY(eh->adb)->len > 0) while (RARRAY_LEN(eh->adb) > 0)
if ((db=rb_ary_pop(eh->adb)) != Qnil ) { if ((db=rb_ary_pop(eh->adb)) != Qnil ) {
rb_warning("%s/%d %s 0x%x",__FILE__,__LINE__, rb_warning("%s/%d %s 0x%p",__FILE__,__LINE__,
"closing",db); "closing",(void*)db);
/* this could raise! needs rb_protect */ /* this could raise! needs rb_protect */
db_close(db,INT2FIX(0)); db_close(db,INT2FIX(0));
} }
} }
if (RARRAY(eh->atxn)->len > 0) { if (RARRAY_LEN(eh->atxn) > 0) {
rb_warning("%s/%d %s",__FILE__,__LINE__, rb_warning("%s/%d %s",__FILE__,__LINE__,
"database transactions still open"); "database transactions still open");
while ( (db=rb_ary_pop(eh->atxn)) != Qnil ) { while ( (db=rb_ary_pop(eh->atxn)) != Qnil ) {
@ -1692,7 +1693,7 @@ VALUE env_close(VALUE obj)
} }
if ( RTEST(ruby_debug) ) if ( RTEST(ruby_debug) )
rb_warning("%s/%d %s 0x%x",__FILE__,__LINE__,"env_close!",eh); rb_warning("%s/%d %s 0x%p",__FILE__,__LINE__,"env_close!",(void*)eh);
rv = eh->env->close(eh->env,NOFLAGS); rv = eh->env->close(eh->env,NOFLAGS);
eh->env=NULL; eh->env=NULL;
@ -1773,7 +1774,7 @@ VALUE env_set_cachesize(VALUE obj, VALUE size)
VALUE env_get_cachesize(VALUE obj) VALUE env_get_cachesize(VALUE obj)
{ {
t_envh *eh; t_envh *eh;
unsigned long long ln; //unsigned long long ln;
u_int32_t bytes=0,gbytes=0; u_int32_t bytes=0,gbytes=0;
int ncache; int ncache;
int rv; int rv;
@ -2131,6 +2132,8 @@ VALUE db_stat(VALUE obj, VALUE vtxn, VALUE vflags)
qs_int(qs_cur_recno); /* Next available record number. */ qs_int(qs_cur_recno); /* Next available record number. */
break; break;
case DB_UNKNOWN:
break;
} }
free(su.stat); free(su.stat);
@ -2145,7 +2148,7 @@ VALUE db_stat(VALUE obj, VALUE vtxn, VALUE vflags)
*/ */
VALUE stat_aref(VALUE obj, VALUE vname) VALUE stat_aref(VALUE obj, VALUE vname)
{ {
rb_iv_get(obj,RSTRING_PTR(rb_str_concat(rb_str_new2("@"),vname))); return rb_iv_get(obj,RSTRING_PTR(rb_str_concat(rb_str_new2("@"),vname)));
} }
/* /*
@ -2565,8 +2568,8 @@ VALUE env_get_lk_max_objects(VALUE obj)
VALUE env_report_stderr(VALUE obj) VALUE env_report_stderr(VALUE obj)
{ {
t_envh *eh; t_envh *eh;
u_int32_t max; //u_int32_t max;
int rv; //int rv;
Data_Get_Struct(obj,t_envh,eh); Data_Get_Struct(obj,t_envh,eh);
if (!eh->env) if (!eh->env)
@ -2953,7 +2956,7 @@ VALUE env_repmgr_stat_print(VALUE obj, VALUE flags)
static void txn_finish(t_txnh *txn) static void txn_finish(t_txnh *txn)
{ {
if ( RTEST(ruby_debug) ) if ( RTEST(ruby_debug) )
rb_warning("%s/%d %s 0x%x",__FILE__,__LINE__,"txn_finish",txn); rb_warning("%s/%d %s 0x%p",__FILE__,__LINE__,"txn_finish",(void*)txn);
txn->txn=NULL; txn->txn=NULL;
if (txn->env) { if (txn->env) {

View File

@ -16,7 +16,7 @@
#undef rename #undef rename
#endif #endif
#include <version.h> //#include <version.h>
#include <db.h> #include <db.h>
#define NOTXN NULL #define NOTXN NULL