Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDBM_File jumps over each 2nd pair when updating pairs while iterating #10368

Open
p5pRT opened this issue May 8, 2010 · 3 comments
Open

SDBM_File jumps over each 2nd pair when updating pairs while iterating #10368

p5pRT opened this issue May 8, 2010 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented May 8, 2010

Migrated from rt.perl.org#74984 (status was 'open')

Searchable as RT74984$

@p5pRT
Copy link
Author

p5pRT commented May 8, 2010

From rehsack@googlemail.com

Created by rehsack@googlemail.com

#!/usr/bin/perl

use strict;
use warnings;

use File​::Spec;
use SDBM_File;
use Fcntl;
use Data​::Dumper;
use Carp;

my $foo;
tie( %$foo, 'SDBM_File', File​::Spec->catfile( $ENV{HOME}, qw( test sdbm_foo
) ), O_RDWR | O_CREAT, 0644 )
  or die "Couldn't tie SDBM File​: $!";

$foo->{meta} = 'blub';
$foo->{1} = 'bar';
$foo->{2} = 'bar';
$foo->{3} = 'bar';
$foo->{4} = 'bar';
$foo->{5} = 'bar';
$foo->{6} = 'bar';

sub fetch_item { my @​row = each %$foo; @​row = each %$foo if(
defined($row[0]) and $row[0] and $row[0] eq 'meta' ); return @​row; }
sub update_item { my @​row = @​_; $foo->{$row[0]} = $row[1]; }

while( my ($key, $val) = fetch_item() )
{
  update_item( $key, 'foo' );
}

print Dumper(\$foo);

Should print​:
$VAR1 = \{
  'meta' => 'blub'
  '1' => 'foo',
  '2' => 'foo',
  '3' => 'foo',
  '4' => 'foo',
  '5' => 'foo',
  '6' => 'foo',
};

Prints​:
$VAR1 = \{
  'meta' => 'blub'
  '1' => 'foo',
  '2' => 'bar',
  '3' => 'foo',
  '4' => 'bar',
  '5' => 'foo',
  '6' => 'bar',
};

I expect that each hits every pair in a hash. If this is wrong, this might
be documented (in TIEHASH and SDBM_File),
if I'm right, it should be fixed and some documentation should be updated
with some warnings.

Perl Info

Flags:
     category=library
     severity=medium
     module=SDBM_File

Site configuration information for perl v5.8.9:

Configured by root at Wed Sep  2 07:37:18 UTC 2009.

Summary of my perl5 (revision 5 version 8 subversion 9) configuration:
   Platform:
     osname=freebsd, osvers=7.2-stable, archname=amd64-freebsd-thread-multi
     uname='freebsd waldorf.muppets.liwing.de 7.2-stable freebsd 7.2-stable 
#0: tue sep 1 19:21:10 utc 2009 
root@waldorf.muppets.liwing.de:usrobjusrsrcsyswaldorf amd64 '
     config_args='-sde -Dprefix=/usr/local 
-Darchlib=/usr/local/lib/perl5/5.8.9/mach 
-Dprivlib=/usr/local/lib/perl5/5.8.9 
-Dman3dir=/usr/local/lib/perl5/5.8.9/perl/man/man3 
-Dman1dir=/usr/local/man/man1 
-Dsitearch=/usr/local/lib/perl5/site_perl/5.8.9/mach 
-Dsitelib=/usr/local/lib/perl5/site_perl/5.8.9 -Dscriptdir=/usr/local/bin 
-Dsiteman3dir=/usr/local/lib/perl5/5.8.9/man/man3 
-Dsiteman1dir=/usr/local/man/man1 -Ui_malloc -Ui_iconv -Uinstallusrbinperl 
-Dcc=cc -Duseshrplib -Dinc_version_list=none 
-Dccflags=-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.9/BSDPAN" -Doptimize=-O2 
-fno-strict-aliasing -pipe -march=nocona -Ud_dosuid -Ui_gdbm -Dusethreads=y 
-Dusemymalloc=n -Duse64bitint'
     hint=recommended, useposix=true, d_sigaction=define
     usethreads=define use5005threads=undef useithreads=define 
usemultiplicity=define
     useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
     use64bitint=define use64bitall=define uselongdouble=undef
     usemymalloc=n, bincompat5005=undef
   Compiler:
     cc='cc', ccflags ='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.9/BSDPAN" 
-DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe 
-I/usr/local/include',
     optimize='-O2 -fno-strict-aliasing -pipe -march=nocona',
     cppflags='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.9/BSDPAN" 
-DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe 
-I/usr/local/include'
     ccversion='', gccversion='4.2.1 20070719  [FreeBSD]', gccosandvers=''
     intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
     ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
     alignbytes=8, prototype=define
   Linker and Libraries:
     ld='cc', ldflags ='-pthread -Wl,-E  -L/usr/local/lib'
     libpth=/usr/lib /usr/local/lib
     libs=-lgdbm -lm -lcrypt -lutil
     perllibs=-lm -lcrypt -lutil
     libc=, so=so, useshrplib=true, libperl=libperl.so
     gnulibc_version=''
   Dynamic Linking:
     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' 
-Wl,-R/usr/local/lib/perl5/5.8.9/mach/CORE'
     cccdlflags='-DPIC -fPIC', lddlflags='-shared  -L/usr/local/lib'

Locally applied patches:
     defined-or


@INC for perl v5.8.9:
     /usr/local/lib/perl5/5.8.9/BSDPAN
     /usr/local/lib/perl5/site_perl/5.8.9/mach
     /usr/local/lib/perl5/site_perl/5.8.9
     /usr/local/lib/perl5/5.8.9/mach
     /usr/local/lib/perl5/5.8.9
     .


Environment for perl v5.8.9:
     HOME=/home/trevor
     LANG=C
     LANGUAGE (unset)
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)
 
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/home/trevor/bin
     PERL_BADLANG (unset)
     SHELL=/usr/local/bin/bash

@p5pRT
Copy link
Author

p5pRT commented May 10, 2010

From @iabyn

Confirmed still present in blead; can be simplified to the following,
which demonstrates than only every second element is updated to B.
Words fine for a standard has or a normal tied hash, so the messing the
iterator is specific to SDBM_File.

use strict;
use warnings;

use SDBM_File;
use Fcntl;

my %h;
my $file = '/tmp/rt74984';

unlink "$file.pag"; unlink "$file.dir";
tie %h, 'SDBM_File', $file, O_RDWR | O_CREAT, 0644
  or die "Couldn't tie SDBM File​: $!";

$h{$_} = 'A' for 1..6;;

while (my $key = each %h) {
  warn "updating $key\n";
  $h{$key} = 'B';
}

printf "%d​: %s\n", $_, $h{$_} for sort keys %h;

--
Any [programming] language that doesn't occasionally surprise the
novice will pay for it by continually surprising the expert.
  -- Larry Wall

@p5pRT
Copy link
Author

p5pRT commented May 10, 2010

The RT System itself - Status changed from 'new' to 'open'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants