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

Tie::RefHash DELETE does not return value for ref keys #7565

Closed
p5pRT opened this issue Oct 28, 2004 · 5 comments
Closed

Tie::RefHash DELETE does not return value for ref keys #7565

p5pRT opened this issue Oct 28, 2004 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 28, 2004

Migrated from rt.perl.org#32193 (status was 'resolved')

Searchable as RT32193$

@p5pRT
Copy link
Author

p5pRT commented Oct 28, 2004

From @nothingmuch

Created by @nothingmuch

L<perlfunc/delete> documents delete as returning the value of the deleted key.

Given

<<TEST
use strict;
use warnings;

use Test​::More tests => 5;

use_ok('Tie​::RefHash');

tie my %hash, 'Tie​::RefHash';

$hash{blah} = "poot";
is($hash{blah}, "poot", "stored properly with scalar key");
is(delete($hash{blah}), "poot", "delete returns value with scalar key");

my $var = "oink";
my $ref = \$var;

$hash{$ref} = "ding";
is($hash{$ref}, "ding", "stored properly with ref key");
is(delete($hash{$ref}), "ding", "delete returns value with ref key");
TEST

test 5 fails, saying that ARRAY(0xdecaf) isn't 'ding'

<<PATCH

Inline Patch
--- RefHash.pm~ Tue Aug 10 11:14:00 2004
+++ RefHash.pm  Thu Oct 28 12:22:00 2004
@@ -115,7 +115,7 @@
 
 sub DELETE {
   my($s, $k) = @_;
-  (ref $k) ? delete($s->[0]{overload::StrVal($k)}) : delete($s->[1]{$k});
+  (ref $k) ? delete($s->[0]{overload::StrVal($k)})->[1] : delete($s->[1]{$k});
 }
 
 sub EXISTS {
PATCH

In Tie​::RefHash CORE​::delete is used to remove an array reference, that stores
the reference-that-isa-key, and the value, from a hash structure that is used
internally.

The value returned by the delete is the array reference.

The patch thus dereferences the value returned from CORE​::delete as an ARRAY,
and returns the second element therein.

Ciao!

Perl Info

Flags:
    category=library
    severity=low

Site configuration information for perl v5.9.1:

Configured by nothingmuch at Tue Aug 10 10:59:22 IDT 2004.

Summary of my perl5 (revision 5 version 9 subversion 1) configuration:
  Platform:
    osname=darwin, osvers=7.4.0, archname=darwin-thread-multi-2level
    uname='darwin syeeda.int.hyperroll.com 7.4.0 darwin kernel version 7.4.0: wed may 12 16:58:24 pdt 2004; root:xnuxnu-517.7.7.obj~7release_ppc power macintosh powerpc '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-pipe -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -I/usr/local/include',
    optimize='-Os',
    cppflags='-no-cpp-precomp -pipe -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='3.3 20030304 (Apple Computer, Inc. build 1640)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib
    libs=-ldbm -ldl -lm -lc
    perllibs=-ldl -lm -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=true, libperl=libperl.dylib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.9.1:
    CODE(0x808ec4)
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/config/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/common/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/schema/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/support/Algorithm-Bucketizer/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/support/Algorithm-Dependency/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/support/Class-DBI/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/support/Class-Delegation/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/support/Maypole/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/support/Queue-Base-Sane/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/support/aux/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/support/base/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/support/overlay/lib
    /Users/nothingmuch/Perl/Devel-FIXME/lib
    /Users/nothingmuch/Perl/Test-Harness-Daemon/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/generic/Class-DBI-Schema-SQL-Translator/lib
    /Users/nothingmuch/HyperRoll/Tools/TestRunner/generic/Tie-RefHash-Weak/lib
    /usr/local/lib/perl5/5.9.1/darwin-thread-multi-2level
    /usr/local/lib/perl5/5.9.1
    /usr/local/lib/perl5/site_perl/5.9.1/darwin-thread-multi-2level
    /usr/local/lib/perl5/site_perl/5.9.1
    /usr/local/lib/perl5/site_perl
    .


Environment for perl v5.9.1:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/nothingmuch
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/mysql/bin:/Applications/Gimp.app/Contents/Resources/bin:/Applications/Graphviz.app/Contents/MacOS
    PERL5LIB=/Users/nothingmuch/HyperRoll/Tools/TestRunner/config/lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/common/lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/schema/lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/support/Algorithm-Bucketizer/lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/support/Algorithm-Dependency/lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/support/Class-DBI/lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/support/Class-Delegation/lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/support/Maypole/lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/support/Queue-Base-Sane/lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/support/aux/lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/support/base/lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/support/overlay/lib:/Users/nothingmuch/Perl/Devel-FIXME/lib:/Users/nothingmuch/Perl/Test-Harness-Daemon/lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/generic/Class-DBI-Schema-SQL-Translator/
 lib:/Users/nothingmuch/HyperRoll/Tools/TestRunner/generic/Tie-RefHash-Weak/lib
    PERL5OPT=-MDevel::FIXME::Rules::PerlFile
    PERL5_CPANPLUS_CONFIG=/Users/nothingmuch/.cpanplus/config
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Oct 28, 2004

From @nothingmuch

Hmm... Oddly,

delete()->[1] sometimes dies saying that undef is not an array reference, but if I say

sub DELETE {
  my($s, $k) = @​_;
  if (ref $k){
  my $v = delete($s->[0]{overload​::StrVal($k)});
  return $v->[1];
  } else { delete($s->[1]{$k}) }
}

the problem goes away.

@p5pRT
Copy link
Author

p5pRT commented Oct 28, 2004

@nothingmuch - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Mar 3, 2005

From @rgs

Yuval Kojman (via RT) wrote​:

Given

<<TEST
use strict;
use warnings;

use Test​::More tests => 5;

use_ok('Tie​::RefHash');

tie my %hash, 'Tie​::RefHash';

$hash{blah} = "poot";
is($hash{blah}, "poot", "stored properly with scalar key");
is(delete($hash{blah}), "poot", "delete returns value with scalar key");

my $var = "oink";
my $ref = \$var;

$hash{$ref} = "ding";
is($hash{$ref}, "ding", "stored properly with ref key");
is(delete($hash{$ref}), "ding", "delete returns value with ref key");
TEST

test 5 fails, saying that ARRAY(0xdecaf) isn't 'ding'

<<PATCH
--- RefHash.pm~ Tue Aug 10 11​:14​:00 2004
+++ RefHash.pm Thu Oct 28 12​:22​:00 2004
@​@​ -115,7 +115,7 @​@​

sub DELETE {
my($s, $k) = @​_;
- (ref $k) ? delete($s->[0]{overload​::StrVal($k)}) : delete($s->[1]{$k});
+ (ref $k) ? delete($s->[0]{overload​::StrVal($k)})->[1] : delete($s->[1]{$k});
}

Thanks, applied as change #24001 to bleadperl.

sub EXISTS {
PATCH

In Tie​::RefHash CORE​::delete is used to remove an array reference, that stores
the reference-that-isa-key, and the value, from a hash structure that is used
internally.

The value returned by the delete is the array reference.

The patch thus dereferences the value returned from CORE​::delete as an ARRAY,
and returns the second element therein.

@p5pRT
Copy link
Author

p5pRT commented Mar 3, 2005

@rgs - Status changed from 'open' to 'resolved'

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

1 participant