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

tied SPLICE splice(@x, 2, 2, @x[3, 2]) fails #6552

Closed
p5pRT opened this issue Jun 4, 2003 · 4 comments
Closed

tied SPLICE splice(@x, 2, 2, @x[3, 2]) fails #6552

p5pRT opened this issue Jun 4, 2003 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 4, 2003

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

Searchable as RT22570$

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2003

From @muir

Created by @muir

I've found a paticular use of splice fails when applied to a tied
array.

Enclosed is a test that illustrates the problem.

In the code below,

  splice(@​$x, 2, 2, @​$x[3, 2]);

behaves differently from
 
  splice(@​$x, 2, 2, $x->[3], $x->[2]);

------------ cut here -----------
print "1..1\n";

my $x = [ 'a', 'b', 'c', 'd', 'e' ];

tie @​$x, 'OverArray', $x;

#print "3,2 = ".join(' ', @​$x[3, 2])."\n";

splice(@​$x, 2, 2, @​$x[3, 2]);
#splice(@​$x, 2, 2, $x->[3], $x->[2]);

#print "x = @​$x\n";

print ($x->[3] eq 'c' ? "ok 1\n" : "not ok 1\n");

package OverArray;

sub UNTIE
{
}

sub DESTROY
{
}

sub TIEARRAY
{
  my $pkg = shift;
  my $orig = shift;
  my $self = bless [ [ @​$orig ], $orig ], $pkg;
  return $self;
}

sub FETCH
{
  my $self = shift;
  my ($fake, $real) = @​$self;
  my $index = shift;
  return $fake->[$index];
}

sub STORE
{
  my $self = shift;
  my ($fake, $real) = @​$self;
  my ($index, $value) = @​_;
  $fake->[$index] = $value;
}

sub FETCHSIZE
{
  my $self = shift;
  my ($fake, $real) = @​$self;
  return scalar(@​$fake);
}

sub STORESIZE
{
  my $self = shift;
  my ($fake, $real) = @​$self;
  my $count = shift;
  $self->SPLICE($count - scalar(@​$fake))
  if $count < @​$fake;
  $#$fake = $count-1;
}

sub EXTEND
{
  my $self = shift;
  my ($fake, $real) = @​$self;
  my $count = shift;
  $#$fake = $count-1 if $count > @​$fake;
}

sub EXISTS
{
  my $self = shift;
  my ($fake, $real) = @​$self;
  my $index = shift;
  return exists($fake->[$index]);
}

sub DELETE
{
  my $self = shift;
  my ($fake, $real) = @​$self;
  delete $fake->[$index];
}

sub CLEAR
{
  my $self = shift;
  my ($fake, $real) = @​$self;
  $fake->STORESIZE(0);
}

sub PUSH
{
  my $self = shift;
  my ($fake, $real) = @​$self;
  push(@​$fake, @​_);
}

sub POP
{
  my $self = shift;
  return $self->SPLICE(-1,1);
}

sub SHIFT
{
  my $self = shift;
  return $self->SPLICE(0,1);
}

sub UNSHIFT
{
  my $self = shift;
  return $self->SPLICE(0,0,@​_);
}

sub SPLICE
{
  my $self = shift;
  my ($fake, $real) = @​$self;
  my $offset = shift || 0;
  my $length = shift;
  $offset += @​$fake if $offset < 0;
  $length = $#$fake - $offset
  unless defined $length;
  my (@​rv) = splice(@​$fake, $offset, $length, @​_);
  return @​rv;
}
------------ cut here -----------

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.8.0:

Configured by muir at Wed Dec 18 00:21:13 PST 2002.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=freebsd, osvers=4.7-release, archname=i386-freebsd
    uname='freebsd charm.idiom.com 4.7-release freebsd 4.7-release #4: thu oct 10 22:04:24 pdt 2002 muir@charm.idiom.com:charmbuildobjcharmbuildsrcsyscharm i386 '
    config_args='-sde -Dprefix=/usr/local -Darchlib=/usr/local/lib/perl5/5.8.0/mach -Dprivlib=/usr/local/lib/perl5/5.8.0 -Dman3dir=/usr/local/lib/perl5/5.8.0/man/man3 -Dsitearch=/usr/local/lib/perl5/site_perl/5.8.0/mach -Dsitelib=/usr/local/lib/perl5/site_perl/5.8.0 -Ui_malloc -Ui_iconv -Uinstallusrbinperl -Dccflags=-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.0/BSDPAN" -Ui_gdbm -Dusemymalloc=n'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.0/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -I/usr/local/include',
    optimize='-O -pipe -m486 -mcpu=i686 -march=pentiumpro ',
    cppflags='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.0/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.4 20020320 [FreeBSD]', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags ='-Wl,-E  -L/usr/local/lib'
    libpth=/usr/lib /usr/local/lib
    libs=-lgdbm -lm -lc -lcrypt -lutil
    perllibs=-lm -lc -lcrypt -lutil
    libc=, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-DPIC -fPIC', lddlflags='-shared  -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.8.0:
    /usr/local/lib/perl5/site_perl/5.8.0/mach
    /usr/local/lib/perl5/site_perl/5.8.0
    /usr/local/lib/perl5/site_perl/5.6.1
    /usr/local/lib/perl5/site_perl/5.005
    /usr/local/lib/perl5/site_perl
    /usr/local/lib/perl5/5.8.0/BSDPAN
    /usr/local/lib/perl5/5.8.0/mach
    /usr/local/lib/perl5/5.8.0
    .


Environment for perl v5.8.0:
    HOME=/home/muir
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=.:/home/muir/bin/charm:/home/muir/bin:/home/muir/bin/share:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/shbin:/usr/local/sbin:/usr/local/bin:/usr/local/ptybin:/usr/X11R6/bin:/usr/bin/X11:/usr/local/tex/bin:/usr/ucb:/usr/bin:/bin:/etc:/usr/etc:/usr/games:/lib:/usr/lib:/usr/local/java/bin:/usr/lib/uucp:/usr/openwin/bin:/usr/openwin/bin/xview:/usr/openwin/demo:/usr/adm:/home/muir/tmp
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Jun 5, 2003

From @ap

* muir@​charm.idiom.com (via RT) <perlbug-followup@​perl.org> [2003-06-04 21​:02]​:

I've found a paticular use of splice fails when applied to a
tied array.

Enclosed is a test that illustrates the problem.

I clearly remember there have been problems with slices read from
tied arrays before. If you instrument the code a bit you'll find
that the version which attempts to use a slice deref FETCHes them
twice (one extra time after splice() is called). This might be
going awry depending on the order of operations.


Inline Patch
--- t.pl.orig   2003-06-05 16:50:39.000000000 +0200
+++ t.pl        2003-06-05 16:51:39.000000000 +0200
@@ -33,6 +33,7 @@
 
 sub FETCH
 {
+       warn "FETCH @_\n";
        my $self = shift;
        my ($fake, $real) = @$self;
        my $index = shift;
@@ -122,6 +123,7 @@
 
 sub SPLICE
 {
+       warn "SPLICE @_\n";
        my $self = shift;
        my ($fake, $real) = @$self;
        my $offset = shift || 0;
-----------------------------------------------------------------

-- 

Regards,
Aristotle

@p5pRT
Copy link
Author

p5pRT commented Jun 27, 2008

From p5p@spam.wizbit.be

On Wed Jun 04 12​:29​:23 2003, muir@​charm.idiom.com wrote​:

This is a bug report for perl from muir@​charm.idiom.com,
generated with the help of perlbug 1.34 running under perl v5.8.0.

-----------------------------------------------------------------
[Please enter your report here]

I've found a paticular use of splice fails when applied to a tied
array.

Enclosed is a test that illustrates the problem.

In the code below,

splice\(@&#8203;$x\, 2\, 2\, @&#8203;$x\[3\, 2\]\);

behaves differently from

splice\(@&#8203;$x\, 2\, 2\, $x\->\[3\]\, $x\->\[2\]\);

This was fixed in perl-5.8.6

perl-5.8.5 /tmp/rt-22570.pl
1..1
not ok 1

perl-5.8.6 /tmp/rt-22570.pl
1..1
ok 1

@p5pRT
Copy link
Author

p5pRT commented Jun 27, 2008

p5p@spam.wizbit.be - 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