1 # -*- buffer-read-only: t -*-
2 # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
3 # This file is built by regen/warnings.pl.
4 # Any changes made here will be lost!
10 # Verify that we're called correctly so that warnings will work.
12 unless ( __FILE__ =~ /(^|[\/\\])\Q${\__PACKAGE__}\E\.pmc?$/ ) {
13 my (undef, $f, $l) = caller;
14 die("Incorrect use of pragma '${\__PACKAGE__}' at $f line $l.\n");
19 warnings - Perl pragma to control optional warnings
29 use warnings::register;
30 if (warnings::enabled()) {
31 warnings::warn("some warning");
34 if (warnings::enabled("void")) {
35 warnings::warn("void", "some warning");
38 if (warnings::enabled($object)) {
39 warnings::warn($object, "some warning");
42 warnings::warnif("some warning");
43 warnings::warnif("void", "some warning");
44 warnings::warnif($object, "some warning");
48 The C<warnings> pragma is a replacement for the command line flag C<-w>,
49 but the pragma is limited to the enclosing block, while the flag is global.
50 See L<perllexwarn> for more information and the list of built-in warning
53 If no import list is supplied, all possible warnings are either enabled
56 A number of functions are provided to assist module authors.
60 =item use warnings::register
62 Creates a new warnings category with the same name as the package where
63 the call to the pragma is used.
65 =item warnings::enabled()
67 Use the warnings category with the same name as the current package.
69 Return TRUE if that warnings category is enabled in the calling module.
70 Otherwise returns FALSE.
72 =item warnings::enabled($category)
74 Return TRUE if the warnings category, C<$category>, is enabled in the
76 Otherwise returns FALSE.
78 =item warnings::enabled($object)
80 Use the name of the class for the object reference, C<$object>, as the
83 Return TRUE if that warnings category is enabled in the first scope
84 where the object is used.
85 Otherwise returns FALSE.
87 =item warnings::fatal_enabled()
89 Return TRUE if the warnings category with the same name as the current
90 package has been set to FATAL in the calling module.
91 Otherwise returns FALSE.
93 =item warnings::fatal_enabled($category)
95 Return TRUE if the warnings category C<$category> has been set to FATAL in
97 Otherwise returns FALSE.
99 =item warnings::fatal_enabled($object)
101 Use the name of the class for the object reference, C<$object>, as the
104 Return TRUE if that warnings category has been set to FATAL in the first
105 scope where the object is used.
106 Otherwise returns FALSE.
108 =item warnings::warn($message)
110 Print C<$message> to STDERR.
112 Use the warnings category with the same name as the current package.
114 If that warnings category has been set to "FATAL" in the calling module
115 then die. Otherwise return.
117 =item warnings::warn($category, $message)
119 Print C<$message> to STDERR.
121 If the warnings category, C<$category>, has been set to "FATAL" in the
122 calling module then die. Otherwise return.
124 =item warnings::warn($object, $message)
126 Print C<$message> to STDERR.
128 Use the name of the class for the object reference, C<$object>, as the
131 If that warnings category has been set to "FATAL" in the scope where C<$object>
132 is first used then die. Otherwise return.
135 =item warnings::warnif($message)
139 if (warnings::enabled())
140 { warnings::warn($message) }
142 =item warnings::warnif($category, $message)
146 if (warnings::enabled($category))
147 { warnings::warn($category, $message) }
149 =item warnings::warnif($object, $message)
153 if (warnings::enabled($object))
154 { warnings::warn($object, $message) }
156 =item warnings::register_categories(@names)
158 This registers warning categories for the given names and is primarily for
159 use by the warnings::register pragma, for which see L<perllexwarn>.
163 See L<perlmodlib/Pragmatic Modules> and L<perllexwarn>.
169 # Warnings Categories added in Perl 5.008
212 'uninitialized' => 82,
218 # Warnings Categories added in Perl 5.011
221 'illegalproto' => 94,
223 # Warnings Categories added in Perl 5.013
231 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15", # [0..50]
232 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [29]
233 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [30]
234 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
235 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
236 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [22]
237 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
238 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [31]
239 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
240 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
241 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
242 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [47]
243 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [46]
244 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [23]
245 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [24]
246 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
247 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
248 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00", # [25]
249 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
250 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
251 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [48]
252 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [49]
253 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
254 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
255 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
256 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
257 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", # [32]
258 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
259 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
260 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [33]
261 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [34]
262 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [35]
263 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [36]
264 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
265 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
266 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [20]
267 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [37]
268 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [38]
269 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00\x00", # [21..25]
270 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [26]
271 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [27]
272 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [50]
273 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x40\x00", # [28..38,47]
274 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [39]
275 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [40]
276 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [41]
277 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
278 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [42]
279 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [43]
280 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x15", # [44,48..50]
281 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [45]
285 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\x2a", # [0..50]
286 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [29]
287 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [30]
288 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
289 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
290 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [22]
291 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
292 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [31]
293 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
294 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
295 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
296 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [47]
297 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [46]
298 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [23]
299 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [24]
300 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
301 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
302 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00", # [25]
303 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
304 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
305 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [48]
306 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [49]
307 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
308 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
309 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
310 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
311 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00", # [32]
312 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
313 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
314 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [33]
315 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [34]
316 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [35]
317 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [36]
318 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
319 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
320 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [20]
321 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [37]
322 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [38]
323 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00\x00", # [21..25]
324 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [26]
325 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [27]
326 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [50]
327 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x80\x00", # [28..38,47]
328 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [39]
329 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [40]
330 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [41]
331 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
332 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [42]
333 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [43]
334 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x2a", # [44,48..50]
335 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [45]
338 $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0\0";
342 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
346 require Carp; # this initializes %CarpInternal
347 local $Carp::CarpInternal{'warnings'};
348 delete $Carp::CarpInternal{'warnings'};
358 foreach my $word ( @_ ) {
359 if ($word eq 'FATAL') {
363 elsif ($word eq 'NONFATAL') {
367 elsif ($catmask = $Bits{$word}) {
369 $mask |= $DeadBits{$word} if $fatal ;
370 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
373 { Croaker("Unknown warnings category '$word'")}
381 # called from B::Deparse.pm
382 push @_, 'all' unless @_ ;
383 return _bits(undef, @_) ;
390 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $NONE) ;
392 if (vec($mask, $Offsets{'all'}, 1)) {
393 $mask |= $Bits{'all'} ;
394 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
397 # Empty @_ is equivalent to @_ = 'all' ;
398 ${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
406 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $NONE) ;
408 if (vec($mask, $Offsets{'all'}, 1)) {
409 $mask |= $Bits{'all'} ;
410 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
413 push @_, 'all' unless @_;
415 foreach my $word ( @_ ) {
416 if ($word eq 'FATAL') {
419 elsif ($catmask = $Bits{$word}) {
420 $mask &= ~($catmask | $DeadBits{$word} | $All);
423 { Croaker("Unknown warnings category '$word'")}
426 ${^WARNING_BITS} = $mask ;
429 my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
431 sub MESSAGE () { 4 };
441 my $has_message = $wanted & MESSAGE;
443 unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) {
444 my $sub = (caller 1)[3];
445 my $syntax = $has_message ? "[category,] 'message'" : '[category]';
446 Croaker("Usage: $sub($syntax)");
449 my $message = pop if $has_message;
452 # check the category supplied.
454 if (my $type = ref $category) {
455 Croaker("not an object")
456 if exists $builtin_type{$type};
460 $offset = $Offsets{$category};
461 Croaker("Unknown warnings category '$category'")
462 unless defined $offset;
465 $category = (caller(1))[0] ;
466 $offset = $Offsets{$category};
467 Croaker("package '$category' not registered for warnings")
468 unless defined $offset ;
476 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
477 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
482 $i = _error_loc(); # see where Carp will allocate the error
485 # Defaulting this to 0 reduces complexity in code paths below.
486 my $callers_bitmask = (caller($i))[9] || 0 ;
489 foreach my $type (FATAL, NORMAL) {
490 next unless $wanted & $type;
492 push @results, (vec($callers_bitmask, $offset + $type - 1, 1) ||
493 vec($callers_bitmask, $Offsets{'all'} + $type - 1, 1));
496 # &enabled and &fatal_enabled
497 return $results[0] unless $has_message;
499 # &warnif, and the category is neither enabled as warning nor as fatal
500 return if $wanted == (NORMAL | FATAL | MESSAGE)
501 && !($results[0] || $results[1]);
504 Carp::croak($message) if $results[0];
505 # will always get here for &warn. will only get here for &warnif if the
506 # category is enabled
507 Carp::carp($message);
515 vec($mask, $bit, 1) = 1;
519 sub register_categories
523 for my $name (@names) {
524 if (! defined $Bits{$name}) {
525 $Bits{$name} = _mkMask($LAST_BIT);
526 vec($Bits{'all'}, $LAST_BIT, 1) = 1;
527 $Offsets{$name} = $LAST_BIT ++;
528 foreach my $k (keys %Bits) {
529 vec($Bits{$k}, $LAST_BIT, 1) = 0;
531 $DeadBits{$name} = _mkMask($LAST_BIT);
532 vec($DeadBits{'all'}, $LAST_BIT++, 1) = 1;
539 goto &Carp::short_error_loc; # don't introduce another stack frame
544 return __chk(NORMAL, @_);
549 return __chk(FATAL, @_);
554 return __chk(FATAL | MESSAGE, @_);
559 return __chk(NORMAL | FATAL | MESSAGE, @_);
562 # These are not part of any public interface, so we can delete them to save
564 delete $warnings::{$_} foreach qw(NORMAL FATAL MESSAGE);