develooper Front page | perl.perl5.porters | Postings from December 2014

Is the warning fatalization mechanism in fact safe (specificaly FATAL=> 'ununitialized')

Thread Next
From:
Peter Rabbitson
Date:
December 27, 2014 11:18
Subject:
Is the warning fatalization mechanism in fact safe (specificaly FATAL=> 'ununitialized')
Message ID:
549E9561.2000504@rabbit.us
An important preamble - this thread is *not* about the lately 
fashionable `use warnings FATAL => 'all';` Instead I want to focus on 
one very specific case to ensure that the discussion doesn't sray ftom 
the technical details.

Greetings,

Over the years I have heard several off-the-record remarks that the 
FATAL warning mechanism is in fact rather broken and can not be relied 
upon. Problems described ranged from "both warning and exception will 
disappear in the ether" to "will corrupt the callstack in cases of 
DESTROY-unwind FATAL warnings".

Hence I want to check whether the following two snippets from what is 
essentially a common oneliner are in fact 1:1 compatible (from a 
practical point of view) and behave identically, aside from the obvious 
problem of SIG-globalism:

# 1
{
   use warnings FATAL => 'uninitialized';
   my $nuclear_warhead_code = do { something that should never return 
undef };
   print STDOUT "Unlock: $nuclear_warhead_arm_code\n";
}

# 2
{
   my $nuclear_warhead_code = do { something that should never return 
undef };
   local $SIG{__WARN__} = sub { ($_[0] =~ /uninitialized value/)
     ? die $_[0]
     : warn $_[0]
   };
   print STDOUT "Unlock: $nuclear_warhead_arm_code\n";
}

The examples are deliberately stupid - I want to facilitate a discussion 
of what happens in the perl guts, as opposed to "this is not something 
you should be doing anyway".

Thanks in advance!

Thread Next


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