develooper Front page | perl.perl5.porters | Postings from November 2000

[ID 20001108.005] Bus-error when trapping die via eval {}

From:
Raphael Manfredi
Date:
November 8, 2000 07:41
Subject:
[ID 20001108.005] Bus-error when trapping die via eval {}
Message ID:
16047.973698159@lod23.gnb.st.com
The following program produces a core dump with strange UNKNOWN refs
when ran with perl 5.6.0:

-------------------------------------
	package DRIVER;

	sub make { bless [], shift }

	sub logdie {
		my $self = shift;
		print "Driver's logdie\n";
		die "LOGDIE: @_\n";
	}

	package INTERCEPTOR;

	sub make {
		my $self = bless [], shift;
		$self->[0] = $_[0];
		return $self;
	}

	sub logdie {
		my $self = shift;
		my $ref = \@_;
		print "Interceptor's logdie, ref=$ref\n";
		$self->[0]->logdie(@_);
	}

	package main;

	my $Driver = DRIVER->make;

	sub install_interceptor {
		$Driver = INTERCEPTOR->make($Driver);
	}

	sub logdie {
		$Driver->logdie(@_);
	}

	#############

	install_interceptor();
	eval {logdie 'foo'};
	print "Error from eval: $@\n";
	logdie $@; 
-------------------------------------

It produces (note the UNKNOWN, probably signalling memory corruption):

	Interceptor's logdie, ref=ARRAY(0x1289e4)
	Driver's logdie
	Error from eval: LOGDIE: foo
	 
	Interceptor's logdie, ref=UNKNOWN(0x1289e4)
	Driver's logdie
	LOGDIE: LOGDIE: foo
	 
	Bus error (core dumped) 

Under 5.005_03, the same program correctly generates:

	Interceptor's logdie, ref=ARRAY(0xe9954)
	Driver's logdie
	Error from eval: LOGDIE: foo
	 
	Interceptor's logdie, ref=ARRAY(0xe9954)
	Driver's logdie
	LOGDIE: LOGDIE: foo

It also works correctly with 5.7.0 (the version I just downloaded
from www.perl.com).

Raphael




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