summaryrefslogtreecommitdiff
path: root/ext/NDBM_File
diff options
context:
space:
mode:
authorPaul Marquess <paul.marquess@btinternet.com>2001-10-21 22:11:15 +0100
committerJarkko Hietaniemi <jhi@iki.fi>2001-10-22 12:17:00 +0000
commit0bf2e7072c2c1360a32d348a7c800f40c1108f8a (patch)
treebcc20ad90d2634a789df217845b7a8923775ae2c /ext/NDBM_File
parentb309b8ae430d85542056be4d1a80055ed0cb7b0e (diff)
downloadperl-0bf2e7072c2c1360a32d348a7c800f40c1108f8a.tar.gz
Fix for FETCH/NEXTKEY problem in all *DB*_File modules
Message-ID: <AIEAJICLCBDNAAOLLOKLAEOMDCAA.paul.marquess@openwave.com> p4raw-id: //depot/perl@12564
Diffstat (limited to 'ext/NDBM_File')
-rw-r--r--ext/NDBM_File/NDBM_File.xs2
-rwxr-xr-xext/NDBM_File/ndbm.t45
2 files changed, 45 insertions, 2 deletions
diff --git a/ext/NDBM_File/NDBM_File.xs b/ext/NDBM_File/NDBM_File.xs
index 55dd639e95..78a56cb7cc 100644
--- a/ext/NDBM_File/NDBM_File.xs
+++ b/ext/NDBM_File/NDBM_File.xs
@@ -107,7 +107,7 @@ ndbm_FIRSTKEY(db)
datum_key
ndbm_NEXTKEY(db, key)
NDBM_File db
- datum_key key
+ datum_key key = NO_INIT
#define ndbm_error(db) dbm_error(db->dbp)
int
diff --git a/ext/NDBM_File/ndbm.t b/ext/NDBM_File/ndbm.t
index f56034387a..a340e33214 100755
--- a/ext/NDBM_File/ndbm.t
+++ b/ext/NDBM_File/ndbm.t
@@ -28,7 +28,7 @@ require NDBM_File;
#If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT
use Fcntl;
-print "1..65\n";
+print "1..71\n";
unlink <Op.dbmx*>;
@@ -418,3 +418,46 @@ EOM
ok(65, tie(%h, 'NDBM_File','Op.dbmx', O_RDWR|O_CREAT, 0640)) ;
}
+
+{
+ # When iterating over a tied hash using "each", the key passed to FETCH
+ # will be recycled and passed to NEXTKEY. If a Source Filter modifies the
+ # key in FETCH via a filter_fetch_key method we need to check that the
+ # modified key doesn't get passed to NEXTKEY.
+ # Also Test "keys" & "values" while we are at it.
+
+ use warnings ;
+ use strict ;
+ use NDBM_File ;
+
+ unlink <Op.dbmx*>;
+ my $bad_key = 0 ;
+ my %h = () ;
+ ok(66, my $db = tie(%h, 'NDBM_File','Op.dbmx', O_RDWR|O_CREAT, 0640)) ;
+ $db->filter_fetch_key (sub { $_ =~ s/^Beta_/Alpha_/ if defined $_}) ;
+ $db->filter_store_key (sub { $bad_key = 1 if /^Beta_/ ; $_ =~ s/^Alpha_/Beta_/}) ;
+
+ $h{'Alpha_ABC'} = 2 ;
+ $h{'Alpha_DEF'} = 5 ;
+
+ ok(67, $h{'Alpha_ABC'} == 2);
+ ok(68, $h{'Alpha_DEF'} == 5);
+
+ my ($k, $v) = ("","");
+ while (($k, $v) = each %h) {}
+ ok(69, $bad_key == 0);
+
+ $bad_key = 0 ;
+ foreach $k (keys %h) {}
+ ok(70, $bad_key == 0);
+
+ $bad_key = 0 ;
+ foreach $v (values %h) {}
+ ok(71, $bad_key == 0);
+
+ undef $db ;
+ untie %h ;
+ unlink <Op.dbmx*>;
+}
+
+exit ;