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

Data::Dumper Purity mode t/dumper.t fails if slightly rearranged #4160

Open
p5pRT opened this issue Jul 4, 2001 · 3 comments
Open

Data::Dumper Purity mode t/dumper.t fails if slightly rearranged #4160

p5pRT opened this issue Jul 4, 2001 · 3 comments
Labels
dist-Data-Dumper issues in the dual-life blead-first Data-Dumper distribution type-library

Comments

@p5pRT
Copy link

p5pRT commented Jul 4, 2001

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

Searchable as RT7233$

@p5pRT
Copy link
Author

p5pRT commented Jul 4, 2001

From @RandalSchwartz

  use Data​::Dumper;
  my @​dogs = ( 'Fido', 'Wags' );
  my %kennel = (
  First => \$dogs[0],
  Second => \$dogs[1],
  );
  $dogs[2] = \%kennel;
  my $mutts = \%kennel;

  print "CORRECT​:\n";
  print Data​::Dumper->new(
  [\@​dogs, \%kennel, $mutts],
  [qw($dogs $kennel $mutts)])->Purity(1)->Dump;

  print "WRONG​:\n";
  print Data​::Dumper->new(
  [\%kennel, \@​dogs, $mutts],
  [qw($kennel $dogs $mutts)])->Purity(1)->Dump;

Output​:

  CORRECT​:
  $dogs = [
  'Fido',
  'Wags',
  {
  'First' => '',
  'Second' => ''
  }
  ];
  $dogs->[2]{'First'} = \$dogs->[0];
  $dogs->[2]{'Second'} = \$dogs->[1];
  $kennel = $dogs->[2];
  $mutts = $dogs->[2];
  WRONG​:
  $kennel = {
  'First' => \'Fido',
  'Second' => \'Wags'
  };
  $dogs = [
  ${$kennel->{'First'}},
  ${$kennel->{'Second'}},
  {}
  ];
  $dogs->[2] = $kennel;
  $mutts = $kennel;

The WRONG is wrong because the $dogs->[0] is set to a separate copy of
the 'Fido' string, and no longer is associated with $kennel->{First}.
Ditto for 'Wags'.

I'm not sure how to fix this... you really need to dump $dogs before
$kennel here so you can take a reference to the array element in
place. Or it has to be patched up afterward. I'm turning Purity on,
which is usually pretty good about constructing the patchups. But it
wasn't sufficient here.

Site configuration information for perl 5.00503​:

Configured by root at Sat May 15 13​:27​:02 PDT 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration​:
  Platform​:
  osname=linux, osvers=2.0.35, archname=i686-linux
  uname='linux halfdome.holdit.com 2.0.35 #10 mon nov 23 19​:37​:42 pst 1998 i686 unknown '
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=undef useperlio=undef d_sfio=undef
  Compiler​:
  cc='cc', optimize='-O2', gccversion=egcs-2.91.60 19981201 (egcs-1.1.1 release)
  cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
  ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
  stdchar='char', d_stdstdio=define, usevfork=false
  intsize=4, longsize=4, ptrsize=4, doublesize=8
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib
  libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt
  libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
  cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches​:
 


@​INC for perl 5.00503​:
  /usr/lib/perl5/5.00503/i686-linux
  /usr/lib/perl5/5.00503
  /usr/lib/perl5/site_perl/5.005/i686-linux
  /usr/lib/perl5/site_perl/5.005
  .


Environment for perl 5.00503​:
  HOME=/home/merlyn
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/home/merlyn/bin​:/usr/local/bin​:/bin​:/usr/bin
  PERL_BADLANG (unset)
  SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented May 1, 2010

From @chorny

Similar results on 5.12.0.

On Wed Jul 04 06​:11​:31 2001, merlyn@​stonehenge.com wrote​:

use Data​::Dumper;
my @​dogs = \( 'Fido'\, 'Wags' \);
my %kennel = \(
  First => \\$dogs\[0\]\,
  Second =>  \\$dogs\[1\]\,
\);
$dogs\[2\] = \\%kennel;
my $mutts = \\%kennel;

print "CORRECT​:\\n";
print Data​::Dumper\->new\(
  \[\\@​dogs\, \\%kennel\, $mutts\]\,
  \[qw\($dogs $kennel $mutts\)\]\)\->Purity\(1\)\->Dump;

print "WRONG​:\\n";
print Data​::Dumper\->new\(
  \[\\%kennel\, \\@​dogs\, $mutts\]\,
  \[qw\($kennel $dogs $mutts\)\]\)\->Purity\(1\)\->Dump;

Output​:

CORRECT​:
$dogs = \[
          'Fido'\,
          'Wags'\,
          \{
            'First' => ''\,
            'Second' => ''
          \}
        \];
$dogs\->\[2\]\{'First'\} = \\$dogs\->\[0\];
$dogs\->\[2\]\{'Second'\} = \\$dogs\->\[1\];
$kennel = $dogs\->\[2\];
$mutts = $dogs\->\[2\];
WRONG​:
$kennel = \{
            'First' => \\'Fido'\,
            'Second' => \\'Wags'
          \};
$dogs = \[
          $\{$kennel\->\{'First'\}\}\,
          $\{$kennel\->\{'Second'\}\}\,
          \{\}
        \];
$dogs\->\[2\] = $kennel;
$mutts = $kennel;

The WRONG is wrong because the $dogs->[0] is set to a separate copy of
the 'Fido' string, and no longer is associated with $kennel->{First}.
Ditto for 'Wags'.

I'm not sure how to fix this... you really need to dump $dogs before
$kennel here so you can take a reference to the array element in
place. Or it has to be patched up afterward. I'm turning Purity on,
which is usually pretty good about constructing the patchups. But it
wasn't sufficient here.

--
Alexandr Ciornii, http​://chorny.net

@p5pRT
Copy link
Author

p5pRT commented May 1, 2010

From [Unknown Contact. See original ticket]

Similar results on 5.12.0.

On Wed Jul 04 06​:11​:31 2001, merlyn@​stonehenge.com wrote​:

use Data​::Dumper;
my @​dogs = \( 'Fido'\, 'Wags' \);
my %kennel = \(
  First => \\$dogs\[0\]\,
  Second =>  \\$dogs\[1\]\,
\);
$dogs\[2\] = \\%kennel;
my $mutts = \\%kennel;

print "CORRECT​:\\n";
print Data​::Dumper\->new\(
  \[\\@​dogs\, \\%kennel\, $mutts\]\,
  \[qw\($dogs $kennel $mutts\)\]\)\->Purity\(1\)\->Dump;

print "WRONG​:\\n";
print Data​::Dumper\->new\(
  \[\\%kennel\, \\@​dogs\, $mutts\]\,
  \[qw\($kennel $dogs $mutts\)\]\)\->Purity\(1\)\->Dump;

Output​:

CORRECT​:
$dogs = \[
          'Fido'\,
          'Wags'\,
          \{
            'First' => ''\,
            'Second' => ''
          \}
        \];
$dogs\->\[2\]\{'First'\} = \\$dogs\->\[0\];
$dogs\->\[2\]\{'Second'\} = \\$dogs\->\[1\];
$kennel = $dogs\->\[2\];
$mutts = $dogs\->\[2\];
WRONG​:
$kennel = \{
            'First' => \\'Fido'\,
            'Second' => \\'Wags'
          \};
$dogs = \[
          $\{$kennel\->\{'First'\}\}\,
          $\{$kennel\->\{'Second'\}\}\,
          \{\}
        \];
$dogs\->\[2\] = $kennel;
$mutts = $kennel;

The WRONG is wrong because the $dogs->[0] is set to a separate copy of
the 'Fido' string, and no longer is associated with $kennel->{First}.
Ditto for 'Wags'.

I'm not sure how to fix this... you really need to dump $dogs before
$kennel here so you can take a reference to the array element in
place. Or it has to be patched up afterward. I'm turning Purity on,
which is usually pretty good about constructing the patchups. But it
wasn't sufficient here.

--
Alexandr Ciornii, http​://chorny.net

@jkeenan jkeenan added dist-Data-Dumper issues in the dual-life blead-first Data-Dumper distribution and removed Severity Low distro-Linux labels Jul 5, 2021
@xenu xenu removed the affects-5.12 label Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dist-Data-Dumper issues in the dual-life blead-first Data-Dumper distribution type-library
Projects
None yet
Development

No branches or pull requests

3 participants