Subject: | error during untie operation due to non-existing cursor |
Hi,
When running the sample code (see bottom), the following error occurs:
Can't call method "c_get" on an undefined value at /usr/local/lib/perl5/site_perl/5.6.1/alpha-dec_osf/BerkeleyDB.pm line 1179.
dist: BerkeleyDB 0.25
perl version: v5.6.1 built for alpha-dec_osf
OS: OSF1 psbdeva2 V4.0 1229 alpha
I noticed that in the CLEAR implementation, a cursor is freed. But there is no check whether the cursor does exist. This is what I included in the attached patch file.
The problem has to do with at least these things:
- I use a BerkeleyDB::Env (If I don't, the error does not occur)
- I copy hash %h2 to %h. (If I do '$h{"apple"} = "red";untie %h;' instead, no error occurs).
- We recently upgraded 0.16 to 0.25. Since the upgrade, we have this error.
regards,
Peter van Keulen
#================================= sample code ==========================
use BerkeleyDB ;
use vars qw/%h %h2/;
my $filename = "fruit" ;
unlink $filename ;
my $dbenv = new BerkeleyDB::Env
-Home => ".",
-Flags => DB_CREATE|DB_INIT_MPOOL;
tie %h, "BerkeleyDB::Btree",
-Filename => $filename,
-Flags => DB_CREATE,
-Env => $dbenv
or die "Cannot open file $filename: $! $BerkeleyDB::Error\n" ;
$h2{"apple"} = "red" ;
%h = %h2;
untie %h;
=======================================================================
*** BerkeleyDB.pm.orig Mon Apr 5 15:10:57 2004
--- BerkeleyDB.pm Mon Apr 5 16:29:24 2004
***************
*** 1176,1183 ****
my $self = shift ;
my ($key, $value) = (0, 0) ;
my $cursor = $self->_db_write_cursor() ;
! while ($cursor->c_get($key, $value, BerkeleyDB::DB_PREV()) == 0)
! { $cursor->c_del() }
}
#sub DESTROY
--- 1176,1185 ----
my $self = shift ;
my ($key, $value) = (0, 0) ;
my $cursor = $self->_db_write_cursor() ;
! if (defined ($cursor)) {
! while ($cursor->c_get($key, $value, BerkeleyDB::DB_PREV()) == 0)
! { $cursor->c_del() }
! }
}
#sub DESTROY