Front page | perl.perl5.porters |
Postings from November 2000
SDBM_File under MS-Windows95/98 does not work correctly. (APR#1302)
Thread Next
From:
kipp
Date:
November 6, 2000 13:58
Subject:
SDBM_File under MS-Windows95/98 does not work correctly. (APR#1302)
Message ID:
200011062130.eA6LUpZ17387@smtp3.ActiveState.com
Full_Name: SUZUKI, Norio
Version: ActivePerl 620
OS: Windows 98
Submission from: (NULL) (210.198.167.27)
I found the same SDBM_File's BUG as Mr. Dave Mullen reported in modules/495.
When running the script shown below under MS-Windows95(or 98), you can find
some keys are missing after the 29th key is inserted.
---^
use Fcntl;
use SDBM_File;
unlink ('sdbm.pag','sdbm.dir');
%check = ();
$s0 = 'a'x 125;
for $n (1..30) {
$s = $s0.sprintf("%03d",$n);
tie(%sdbm, 'SDBM_File', 'sdbm', O_RDWR|O_CREAT, 0666);
$sdbm{$s}++;
$check{$s}++;
$n_sdbm = keys %sdbm;
$n_check = keys %check;
untie %sdbm;
$size = -s 'sdbm.pag';
print STDERR "n:$n,keys of \%check:$n_check,keys of sdbm:$n_sdbm, size of
sdbm.pag:$size\n";
last unless $n_sdbm == $n_check;
}
---$
When I asked this to Mr. WATANABE, Hirofumi (a patch author of jperl), he
showed a patch and told me that Unix file system suported a gap or hole,
but MS-Windows95/98 didn't.
> notes of lseek(2)
> Seeking far beyond the end of a file, then writing, may
> create a gap or "hole", which occupies no physical space and
> reads as zeros.
--- AP509_source/ext/SDBM_File/sdbm/sdbm.c.orig Fri Jan 22 09:40:54 1999
+++ AP509_source/ext/SDBM_File/sdbm/sdbm.c Fri Jan 22 10:08:49 1999
@@ -270,2 +270,6 @@
char twin[PBLKSIZ];
+#if defined(DOSISH) || defined(WIN32)
+ char zer[PBLKSIZ];
+ long oldtail;
+#endif
char *pag = db->pagbuf;
@@ -292,2 +296,19 @@
*/
+
+#if defined(DOSISH) || defined(WIN32)
+ /*
+ * Fill hole with 0 if made it.
+ * (hole is NOT read as 0)
+ */
+ oldtail = lseek(db->pagf, 0L, SEEK_END);
+ memset(zer, 0, PBLKSIZ);
+ while (OFF_PAG(newp) > oldtail) {
+ if (lseek(db->pagf, 0L, SEEK_END) < 0 ||
+ write(db->pagf, zer, PBLKSIZ) < 0) {
+
+ return 0;
+ }
+ oldtail += PBLKSIZ;
+ }
+#endif
if (hash & (db->hmask + 1)) {
Thread Next
-
SDBM_File under MS-Windows95/98 does not work correctly. (APR#1302)
by kipp