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,
224 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55", # [0..47]
225 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [29]
226 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [30]
227 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
228 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
229 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [22]
230 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
231 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [31]
232 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
233 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
234 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
235 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40", # [47]
236 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [46]
237 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [23]
238 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00", # [24]
239 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
240 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
241 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [25]
242 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
243 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
244 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
245 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
246 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
247 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [16]
248 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [32]
249 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
250 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [17]
251 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [33]
252 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [34]
253 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [35]
254 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [36]
255 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [18]
256 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [19]
257 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [20]
258 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [37]
259 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [38]
260 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00", # [21..25]
261 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [26]
262 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [27]
263 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x40", # [28..38,47]
264 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [39]
265 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [40]
266 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [41]
267 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
268 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [42]
269 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [43]
270 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [44]
271 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [45]
275 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", # [0..47]
276 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [29]
277 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [30]
278 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
279 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
280 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [22]
281 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
282 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [31]
283 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
284 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
285 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
286 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80", # [47]
287 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [46]
288 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [23]
289 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00", # [24]
290 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
291 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
292 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [25]
293 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
294 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
295 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
296 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
297 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
298 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [16]
299 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [32]
300 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
301 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [17]
302 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [33]
303 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [34]
304 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [35]
305 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [36]
306 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [18]
307 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [19]
308 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [20]
309 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [37]
310 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [38]
311 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00", # [21..25]
312 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [26]
313 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [27]
314 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x80", # [28..38,47]
315 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [39]
316 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [40]
317 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [41]
318 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
319 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [42]
320 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [43]
321 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [44]
322 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [45]
325 $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0";
329 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
333 require Carp; # this initializes %CarpInternal
334 local $Carp::CarpInternal{'warnings'};
335 delete $Carp::CarpInternal{'warnings'};
345 foreach my $word ( @_ ) {
346 if ($word eq 'FATAL') {
350 elsif ($word eq 'NONFATAL') {
354 elsif ($catmask = $Bits{$word}) {
356 $mask |= $DeadBits{$word} if $fatal ;
357 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
360 { Croaker("Unknown warnings category '$word'")}
368 # called from B::Deparse.pm
369 push @_, 'all' unless @_ ;
370 return _bits(undef, @_) ;
377 my $mask = ${^WARNING_BITS} ;
379 if (vec($mask, $Offsets{'all'}, 1)) {
380 $mask |= $Bits{'all'} ;
381 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
384 # Empty @_ is equivalent to @_ = 'all' ;
385 ${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
393 my $mask = ${^WARNING_BITS} ;
395 if (vec($mask, $Offsets{'all'}, 1)) {
396 $mask |= $Bits{'all'} ;
397 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
400 push @_, 'all' unless @_;
402 foreach my $word ( @_ ) {
403 if ($word eq 'FATAL') {
406 elsif ($catmask = $Bits{$word}) {
407 $mask &= ~($catmask | $DeadBits{$word} | $All);
410 { Croaker("Unknown warnings category '$word'")}
413 ${^WARNING_BITS} = $mask ;
416 my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
418 sub MESSAGE () { 4 };
428 my $has_message = $wanted & MESSAGE;
430 unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) {
431 my $sub = (caller 1)[3];
432 my $syntax = $has_message ? "[category,] 'message'" : '[category]';
433 Croaker("Usage: $sub($syntax)");
436 my $message = pop if $has_message;
439 # check the category supplied.
441 if (my $type = ref $category) {
442 Croaker("not an object")
443 if exists $builtin_type{$type};
447 $offset = $Offsets{$category};
448 Croaker("Unknown warnings category '$category'")
449 unless defined $offset;
452 $category = (caller(1))[0] ;
453 $offset = $Offsets{$category};
454 Croaker("package '$category' not registered for warnings")
455 unless defined $offset ;
463 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
464 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
469 $i = _error_loc(); # see where Carp will allocate the error
472 # Defaulting this to 0 reduces complexity in code paths below.
473 my $callers_bitmask = (caller($i))[9] || 0 ;
476 foreach my $type (FATAL, NORMAL) {
477 next unless $wanted & $type;
479 push @results, (vec($callers_bitmask, $offset + $type - 1, 1) ||
480 vec($callers_bitmask, $Offsets{'all'} + $type - 1, 1));
483 # &enabled and &fatal_enabled
484 return $results[0] unless $has_message;
486 # &warnif, and the category is neither enabled as warning nor as fatal
487 return if $wanted == (NORMAL | FATAL | MESSAGE)
488 && !($results[0] || $results[1]);
491 Carp::croak($message) if $results[0];
492 # will always get here for &warn. will only get here for &warnif if the
493 # category is enabled
494 Carp::carp($message);
502 vec($mask, $bit, 1) = 1;
506 sub register_categories
510 for my $name (@names) {
511 if (! defined $Bits{$name}) {
512 $Bits{$name} = _mkMask($LAST_BIT);
513 vec($Bits{'all'}, $LAST_BIT, 1) = 1;
514 $Offsets{$name} = $LAST_BIT ++;
515 foreach my $k (keys %Bits) {
516 vec($Bits{$k}, $LAST_BIT, 1) = 0;
518 $DeadBits{$name} = _mkMask($LAST_BIT);
519 vec($DeadBits{'all'}, $LAST_BIT++, 1) = 1;
526 goto &Carp::short_error_loc; # don't introduce another stack frame
531 return __chk(NORMAL, @_);
536 return __chk(FATAL, @_);
541 return __chk(FATAL | MESSAGE, @_);
546 return __chk(NORMAL | FATAL | MESSAGE, @_);
549 # These are not part of any public interface, so we can delete them to save
551 delete $warnings::{$_} foreach qw(NORMAL FATAL MESSAGE);