resolve #906. Changed cursor management semantics. Should eliminate SEGV during finalize cleanup

This commit is contained in:
danj 2007-01-20 21:32:18 +00:00
parent d6f1523444
commit cf259ccc35

12
bdb.c
View file

@ -173,7 +173,7 @@ VALUE db_init_aux(VALUE obj,t_envh * eh)
rb_ary_push(eh->adb,obj); rb_ary_push(eh->adb,obj);
} }
dbh->adbc=rb_ary_new(); dbh->adbc=Qnil;
return obj; return obj;
} }
@ -244,8 +244,8 @@ VALUE db_open(VALUE obj, VALUE vtxn, VALUE vdisk_file,
mode=NUM2INT(vmode); mode=NUM2INT(vmode);
Data_Get_Struct(obj,t_dbh,dbh); Data_Get_Struct(obj,t_dbh,dbh);
if ( NIL_P(dbh->adbc) ) if ( ! NIL_P(dbh->adbc) )
raise_error(0,"db handle already used and closed"); raise_error(0,"db handle already opened");
rv = dbh->db->open(dbh->db,txn?txn->txn:NULL, rv = dbh->db->open(dbh->db,txn?txn->txn:NULL,
StringValueCStr(vdisk_file), StringValueCStr(vdisk_file),
@ -255,6 +255,8 @@ VALUE db_open(VALUE obj, VALUE vtxn, VALUE vdisk_file,
raise_error(rv,"db_open failure: %s(%d)",db_strerror(rv),rv); raise_error(rv,"db_open failure: %s(%d)",db_strerror(rv),rv);
} }
filename_copy(dbh->filename,vdisk_file) filename_copy(dbh->filename,vdisk_file)
dbh->adbc=rb_ary_new();
return obj; return obj;
} }
@ -437,7 +439,7 @@ VALUE db_close(VALUE obj, VALUE vflags)
if ( dbh->db==NULL || strlen(dbh->filename)==0 ) if ( dbh->db==NULL || strlen(dbh->filename)==0 )
return Qnil; return Qnil;
if (RARRAY(dbh->adbc)->len > 0 ) { if (! NIL_P(dbh->adbc) && RARRAY(dbh->adbc)->len > 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 ) {
@ -458,7 +460,7 @@ VALUE db_close(VALUE obj, VALUE vflags)
if ( dbh->env ) { if ( dbh->env ) {
rb_ary_delete(dbh->env->adb,obj); rb_ary_delete(dbh->env->adb,obj);
} }
dbh->adbc=Qnil;
return obj; return obj;
} }