#!/usr/bin/perl -w

=comment
This is a test-case for a bug, leading to a core dump (SIGBUS)
 after die() in DBD::Informix HandleError handler.
The bug (a core dump) reveals when DBD::Informix::db::prepare
 method is called implicitly, via a 'goto &$subref' method
Uncommenting a line in the prepare_sql() function (see comment there)
 eliminates a SIGBUS to happen.
=cut

use strict;

use DBI qw(:sql_types);
use DBD::Informix qw(:ix_types);

use vars qw($DBH $INFORMIX_OPTIONS);

$INFORMIX_OPTIONS = { RaiseError => 1, ChopBlanks => 1 };
$DBH = DBI->connect( 'dbi:Informix:docflow@sun_shm', '', '', $INFORMIX_OPTIONS);

die "please provide DBI->connect with valid parameters for a database session"
 unless defined $DBH;

$DBH->{HandleError} = \&handleSQLError;

sub handleSQLError
{
 die "Text exception";
}

sub prepare_sql
{
# uncommenting the next line will avoid core dump
# return $DBH->prepare( 'select * from ');
 my $sub = $DBH->can( 'prepare');
 @_ = ( $DBH, 'select * from ' );
 goto &$sub;
}

sub firstEval()
{
 prepare_sql();
# return 1 unless $@;
# eval q{print scalar localtime;print scalar localtime;print scalar localtime;print scalar localtime;
#  print scalar localtime;print scalar localtime;print scalar localtime;print scalar localtime;};
# print "OK\n";
}

firstEval();
