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.
52 If no import list is supplied, all possible warnings are either enabled
55 A number of functions are provided to assist module authors.
59 =item use warnings::register
61 Creates a new warnings category with the same name as the package where
62 the call to the pragma is used.
64 =item warnings::enabled()
66 Use the warnings category with the same name as the current package.
68 Return TRUE if that warnings category is enabled in the calling module.
69 Otherwise returns FALSE.
71 =item warnings::enabled($category)
73 Return TRUE if the warnings category, C<$category>, is enabled in the
75 Otherwise returns FALSE.
77 =item warnings::enabled($object)
79 Use the name of the class for the object reference, C<$object>, as the
82 Return TRUE if that warnings category is enabled in the first scope
83 where the object is used.
84 Otherwise returns FALSE.
86 =item warnings::fatal_enabled()
88 Return TRUE if the warnings category with the same name as the current
89 package has been set to FATAL in the calling module.
90 Otherwise returns FALSE.
92 =item warnings::fatal_enabled($category)
94 Return TRUE if the warnings category C<$category> has been set to FATAL in
96 Otherwise returns FALSE.
98 =item warnings::fatal_enabled($object)
100 Use the name of the class for the object reference, C<$object>, as the
103 Return TRUE if that warnings category has been set to FATAL in the first
104 scope where the object is used.
105 Otherwise returns FALSE.
107 =item warnings::warn($message)
109 Print C<$message> to STDERR.
111 Use the warnings category with the same name as the current package.
113 If that warnings category has been set to "FATAL" in the calling module
114 then die. Otherwise return.
116 =item warnings::warn($category, $message)
118 Print C<$message> to STDERR.
120 If the warnings category, C<$category>, has been set to "FATAL" in the
121 calling module then die. Otherwise return.
123 =item warnings::warn($object, $message)
125 Print C<$message> to STDERR.
127 Use the name of the class for the object reference, C<$object>, as the
130 If that warnings category has been set to "FATAL" in the scope where C<$object>
131 is first used then die. Otherwise return.
134 =item warnings::warnif($message)
138 if (warnings::enabled())
139 { warnings::warn($message) }
141 =item warnings::warnif($category, $message)
145 if (warnings::enabled($category))
146 { warnings::warn($category, $message) }
148 =item warnings::warnif($object, $message)
152 if (warnings::enabled($object))
153 { warnings::warn($object, $message) }
155 =item warnings::register_categories(@names)
157 This registers warning categories for the given names and is primarily for
158 use by the warnings::register pragma, for which see L<perllexwarn>.
162 See L<perlmodlib/Pragmatic Modules> and L<perllexwarn>.
168 # Warnings Categories added in Perl 5.008
211 'uninitialized' => 82,
217 # Warnings Categories added in Perl 5.011
220 'illegalproto' => 94,
222 # Warnings Categories added in Perl 5.013
230 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15", # [0..50]
231 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [29]
232 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [30]
233 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
234 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
235 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [22]
236 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
237 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [31]
238 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
239 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
240 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
241 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [47]
242 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [46]
243 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [23]
244 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [24]
245 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
246 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
247 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00", # [25]
248 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
249 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
250 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [48]
251 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [49]
252 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
253 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
254 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
255 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
256 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", # [32]
257 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
258 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
259 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [33]
260 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [34]
261 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [35]
262 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [36]
263 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
264 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
265 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [20]
266 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [37]
267 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [38]
268 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00\x00", # [21..25]
269 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [26]
270 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [27]
271 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [50]
272 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x40\x00", # [28..38,47]
273 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [39]
274 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [40]
275 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [41]
276 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
277 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [42]
278 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [43]
279 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x15", # [44,48..50]
280 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [45]
284 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\x2a", # [0..50]
285 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [29]
286 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [30]
287 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
288 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
289 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [22]
290 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
291 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [31]
292 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
293 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
294 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
295 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [47]
296 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [46]
297 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [23]
298 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [24]
299 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
300 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
301 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00", # [25]
302 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
303 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
304 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [48]
305 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [49]
306 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
307 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
308 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
309 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
310 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00", # [32]
311 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
312 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
313 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [33]
314 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [34]
315 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [35]
316 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [36]
317 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
318 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
319 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [20]
320 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [37]
321 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [38]
322 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00\x00", # [21..25]
323 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [26]
324 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [27]
325 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [50]
326 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x80\x00", # [28..38,47]
327 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [39]
328 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [40]
329 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [41]
330 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
331 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [42]
332 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [43]
333 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x2a", # [44,48..50]
334 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [45]
337 $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0\0";
341 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
345 require Carp; # this initializes %CarpInternal
346 local $Carp::CarpInternal{'warnings'};
347 delete $Carp::CarpInternal{'warnings'};
357 foreach my $word ( @_ ) {
358 if ($word eq 'FATAL') {
362 elsif ($word eq 'NONFATAL') {
366 elsif ($catmask = $Bits{$word}) {
368 $mask |= $DeadBits{$word} if $fatal ;
369 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
372 { Croaker("Unknown warnings category '$word'")}
380 # called from B::Deparse.pm
381 push @_, 'all' unless @_ ;
382 return _bits(undef, @_) ;
389 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $NONE) ;
391 if (vec($mask, $Offsets{'all'}, 1)) {
392 $mask |= $Bits{'all'} ;
393 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
396 # Empty @_ is equivalent to @_ = 'all' ;
397 ${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
405 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $NONE) ;
407 if (vec($mask, $Offsets{'all'}, 1)) {
408 $mask |= $Bits{'all'} ;
409 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
412 push @_, 'all' unless @_;
414 foreach my $word ( @_ ) {
415 if ($word eq 'FATAL') {
418 elsif ($catmask = $Bits{$word}) {
419 $mask &= ~($catmask | $DeadBits{$word} | $All);
422 { Croaker("Unknown warnings category '$word'")}
425 ${^WARNING_BITS} = $mask ;
428 my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
430 sub MESSAGE () { 4 };
440 my $has_message = $wanted & MESSAGE;
442 unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) {
443 my $sub = (caller 1)[3];
444 my $syntax = $has_message ? "[category,] 'message'" : '[category]';
445 Croaker("Usage: $sub($syntax)");
448 my $message = pop if $has_message;
451 # check the category supplied.
453 if (my $type = ref $category) {
454 Croaker("not an object")
455 if exists $builtin_type{$type};
459 $offset = $Offsets{$category};
460 Croaker("Unknown warnings category '$category'")
461 unless defined $offset;
464 $category = (caller(1))[0] ;
465 $offset = $Offsets{$category};
466 Croaker("package '$category' not registered for warnings")
467 unless defined $offset ;
475 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
476 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
481 $i = _error_loc(); # see where Carp will allocate the error
484 # Defaulting this to 0 reduces complexity in code paths below.
485 my $callers_bitmask = (caller($i))[9] || 0 ;
488 foreach my $type (FATAL, NORMAL) {
489 next unless $wanted & $type;
491 push @results, (vec($callers_bitmask, $offset + $type - 1, 1) ||
492 vec($callers_bitmask, $Offsets{'all'} + $type - 1, 1));
495 # &enabled and &fatal_enabled
496 return $results[0] unless $has_message;
498 # &warnif, and the category is neither enabled as warning nor as fatal
499 return if $wanted == (NORMAL | FATAL | MESSAGE)
500 && !($results[0] || $results[1]);
503 Carp::croak($message) if $results[0];
504 # will always get here for &warn. will only get here for &warnif if the
505 # category is enabled
506 Carp::carp($message);
514 vec($mask, $bit, 1) = 1;
518 sub register_categories
522 for my $name (@names) {
523 if (! defined $Bits{$name}) {
524 $Bits{$name} = _mkMask($LAST_BIT);
525 vec($Bits{'all'}, $LAST_BIT, 1) = 1;
526 $Offsets{$name} = $LAST_BIT ++;
527 foreach my $k (keys %Bits) {
528 vec($Bits{$k}, $LAST_BIT, 1) = 0;
530 $DeadBits{$name} = _mkMask($LAST_BIT);
531 vec($DeadBits{'all'}, $LAST_BIT++, 1) = 1;
538 goto &Carp::short_error_loc; # don't introduce another stack frame
543 return __chk(NORMAL, @_);
548 return __chk(FATAL, @_);
553 return __chk(FATAL | MESSAGE, @_);
558 return __chk(NORMAL | FATAL | MESSAGE, @_);
561 # These are not part of any public interface, so we can delete them to save
563 delete $warnings::{$_} foreach qw(NORMAL FATAL MESSAGE);