develooper Front page | perl.perl5.porters | Postings from January 2001

[ID 20010102.004] A combination of eval {}, closures, and \@_manipulation leads to a coredump

From:
tobez
Date:
January 2, 2001 13:56
Subject:
[ID 20010102.004] A combination of eval {}, closures, and \@_manipulation leads to a coredump
Message ID:
20010102225555.B90099@heechee.tobez.org

This is a bug report for perl from tobez@tobez.org,
generated with the help of perlbug 1.28 running under perl v5.6.0.


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

The following Perl program (which is a mucho reduced module Set::Bag)
dumps core.

It works fine on 5.005_03.


package Set::Bag;

sub new {
    my $type = shift;
    my $bag = { };
    bless $bag, $type;
    $bag->insert(@_);
    return $bag;
}

sub _merge {
    my $bag     = shift;
    my $sub     = shift; # Element subroutine.
    my $ref_arg = shift; # Argument list.
    my $ref_bag = ref $bag;
    while (my $e = shift @{$ref_arg}) {
       $sub->($bag, $e, shift @{$ref_arg});
    }
}

my %universe;

sub _insert {
    my ($bag, $e, $n) = @_;
    $bag->{$e} += int $n;
    $universe{$e} = $bag->{$e}
        if $bag->{$e} > ($universe{$e} || 0);
}

my $over_delete = 'Set::Bag::__over_delete__';

sub over_delete {
    my $bag = shift;

    if (@_ == 1) {
	$bag->{$over_delete} = shift;
    } elsif (@_ == 0) {
	return ($bag->{$over_delete} ||= 0);
    } else {
	die "Set::Bag::over_delete: too many arguments (",
	    $#_+1,
	    "), want 0 or 1\n";
    }
}

sub _delete {
    my ($bag, $e, $n) = @_;

    unless ($bag->over_delete) {
	my $m = $bag->{$e} || 0;
	$m >= $n or
	    die "Set::Bag::delete: '$e' $m < $n\n";
    }
    $bag->{$e} -= int $n;
    delete $bag->{$e} if $bag->{$e} < 1;
}


sub insert {
    my $bag = shift;
    $bag->_merge(sub { my ($bag, $e, $n) = @_;
			   $bag->_insert($e, $n);
		     },
		 \@_);
    return $bag;
}

sub delete {
    my $bag = shift;
    $bag->_merge(sub { my ($bag, $e, $n) = @_;
			  $bag->_delete($e, $n);
                     },
		\@_);
    return $bag;
}


$bag_b = Set::Bag->new(mangos => 3);

eval { $bag_b->delete(mangos => 10) };

eval { $bag_b->delete(cherries => 1) };

print "Never reached,\n";
#      but if you remove the print above, everything works sorta fine


[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=high
---
Site configuration information for perl v5.6.0:

Configured by markm at Mon Apr 24 11:11:27 SAST 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=freebsd, osvers=5.0-current, archname=i386-freebsd
    uname='freebsd freefall.FreeBSD.org 5.0-current freebsd 5.0-current #0: $Date$ '
    config_args='-Dprefix=/usr/local -Darchlib=/usr/libdata/perl/5.6.0/mach -Dprivlib=/usr/libdata/perl/5.6.0 -Dsitearch=/usr/local/lib/perl5/site_perl/5.6.0/mach -Dsitelib=/usr/local/lib/perl5/site_perl/5.6.0 -Dinstallsitearch=/usr/local/lib/perl5/site_perl/5.6.0/mach -Dinstallsitelib=/usr/local/lib/perl5/site_perl/5.6.0 -Dinstallbin=/usr/local/bin -Dinstallsitebin=/usr/local/bin -Dinstallscript=/usr/local/bin -Dman1dir=/usr/local/man/man1 -Dman3dir=/usr/local/lib/perl5/5.6.0/man/man3 -Duseshrplib=true -Ulocincpth= -Uloclibpth= -Dpager=/usr/bin/more -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cc', optimize='undef', gccversion=2.95.2 19991024 (release)
    cppflags='-fno-strict-aliasing'
    ccflags ='-fno-strict-aliasing'
    stdchar='char', d_stdstdio=undef, usevfork=true
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    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, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags ='-Wl,-E -lperl -lm '
    libpth=/usr/lib
    libs=-lm -lc -lcrypt
    libc=, so=so, useshrplib=true, libperl=libperl.so.4
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -Wl,-R/usr/lib'
    cccdlflags='-DPIC -fpic', lddlflags='-Wl,-E -shared -lperl -lm '

Locally applied patches:
    SUIDMAIL - fixes for suidperl security

---
@INC for perl v5.6.0:
    /home/tobez/src/Prima
    /home/tobez/src/IPA
    /usr/libdata/perl/5.6.0/mach
    /usr/libdata/perl/5.6.0
    /usr/local/lib/perl5/site_perl/5.6.0/mach
    /usr/local/lib/perl5/site_perl/5.6.0
    /usr/local/lib/perl5/site_perl/5.6.0
    .

---
Environment for perl v5.6.0:
    HOME=/home/tobez
    LANG=ru_RU.KOI8-R
    LANGUAGE (unset)
    LC_MESSAGES=ASCII
    LC_MONETARY=ASCII
    LC_NUMERIC=ASCII
    LC_TIME=ASCII
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/home/tobez/bin:/usr/local/site/bin:/usr/local/pgsql/bin
    PERL5LIB=/home/tobez/src/Prima:/home/tobez/src/IPA
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/zsh




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About