diff options
author | Paul Marquess <paul.marquess@btinternet.com> | 2001-10-21 22:11:15 +0100 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-10-22 12:17:00 +0000 |
commit | 0bf2e7072c2c1360a32d348a7c800f40c1108f8a (patch) | |
tree | bcc20ad90d2634a789df217845b7a8923775ae2c /ext/ODBM_File | |
parent | b309b8ae430d85542056be4d1a80055ed0cb7b0e (diff) | |
download | perl-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/ODBM_File')
-rw-r--r-- | ext/ODBM_File/ODBM_File.xs | 3 | ||||
-rwxr-xr-x | ext/ODBM_File/odbm.t | 44 | ||||
-rw-r--r-- | ext/ODBM_File/typemap | 13 |
3 files changed, 58 insertions, 2 deletions
diff --git a/ext/ODBM_File/ODBM_File.xs b/ext/ODBM_File/ODBM_File.xs index 3724dae962..5a556bfd2f 100644 --- a/ext/ODBM_File/ODBM_File.xs +++ b/ext/ODBM_File/ODBM_File.xs @@ -53,6 +53,7 @@ typedef struct { typedef ODBM_File_type * ODBM_File ; typedef datum datum_key ; +typedef datum datum_key_copy ; typedef datum datum_value ; #define ckFilter(arg,type,name) \ @@ -133,7 +134,7 @@ DESTROY(db) datum_value odbm_FETCH(db, key) ODBM_File db - datum_key key + datum_key_copy key int odbm_STORE(db, key, value, flags = DBM_REPLACE) diff --git a/ext/ODBM_File/odbm.t b/ext/ODBM_File/odbm.t index a43e70bd99..ecffffd81a 100755 --- a/ext/ODBM_File/odbm.t +++ b/ext/ODBM_File/odbm.t @@ -28,7 +28,7 @@ require ODBM_File; #If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT use Fcntl; -print "1..66\n"; +print "1..72\n"; unlink <Op.dbmx*>; @@ -425,6 +425,48 @@ EOM unlink <Op.dbmx*>; } +{ + # 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 ODBM_File ; + + unlink <Op.dbmx*>; + my $bad_key = 0 ; + my %h = () ; + ok(67, my $db = tie(%h, 'ODBM_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(68, $h{'Alpha_ABC'} == 2); + ok(69, $h{'Alpha_DEF'} == 5); + + my ($k, $v) = ("",""); + while (($k, $v) = each %h) {} + ok(70, $bad_key == 0); + + $bad_key = 0 ; + foreach $k (keys %h) {} + ok(71, $bad_key == 0); + + $bad_key = 0 ; + foreach $v (values %h) {} + ok(72, $bad_key == 0); + + undef $db ; + untie %h ; + unlink <Op.dbmx*>; +} + +exit ; if ($^O eq 'hpux') { print <<EOM; # diff --git a/ext/ODBM_File/typemap b/ext/ODBM_File/typemap index 096427ea7f..62b8622569 100644 --- a/ext/ODBM_File/typemap +++ b/ext/ODBM_File/typemap @@ -3,6 +3,7 @@ # datum_key T_DATUM_K +datum_key_copy T_DATUM_K_C datum_value T_DATUM_V gdatum T_GDATUM NDBM_File T_PTROBJ @@ -18,6 +19,18 @@ T_DATUM_K ckFilter($arg, filter_store_key, \"filter_store_key\"); $var.dptr = SvPV($arg, PL_na); $var.dsize = (int)PL_na; +T_DATUM_K_C + { + SV * tmpSV ; + if (db->filter_store_key){ + tmpSV = sv_2mortal(newSVsv($arg)); + ckFilter(tmpSV, filter_store_key, \"filter_store_key\"); + } + else + tmpSV = $arg; + $var.dptr = SvPV(tmpSV, PL_na); + $var.dsize = (int)PL_na; + } T_DATUM_V ckFilter($arg, filter_store_value, \"filter_store_value\"); if (SvOK($arg)) { |