1 # -*- buffer-read-only: t -*-
2 # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
3 # This file was created by regen/warnings.pl
4 # Any changes made here will be lost.
11 # Verify that we're called correctly so that warnings will work.
13 unless ( __FILE__ =~ /(^|[\/\\])\Q${\__PACKAGE__}\E\.pmc?$/ ) {
14 my (undef, $f, $l) = caller;
15 die("Incorrect use of pragma '${\__PACKAGE__}' at $f line $l.\n");
20 warnings - Perl pragma to control optional warnings
30 use warnings::register;
31 if (warnings::enabled()) {
32 warnings::warn("some warning");
35 if (warnings::enabled("void")) {
36 warnings::warn("void", "some warning");
39 if (warnings::enabled($object)) {
40 warnings::warn($object, "some warning");
43 warnings::warnif("some warning");
44 warnings::warnif("void", "some warning");
45 warnings::warnif($object, "some warning");
49 The C<warnings> pragma is a replacement for the command line flag C<-w>,
50 but the pragma is limited to the enclosing block, while the flag is global.
51 See L<perllexwarn> for more information.
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,
225 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55", # [0..47]
226 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [29]
227 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [30]
228 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
229 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
230 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [22]
231 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
232 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [31]
233 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
234 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
235 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
236 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40", # [47]
237 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [46]
238 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [23]
239 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00", # [24]
240 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
241 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
242 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [25]
243 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
244 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
245 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
246 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
247 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
248 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [16]
249 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [32]
250 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
251 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [17]
252 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [33]
253 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [34]
254 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [35]
255 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [36]
256 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [18]
257 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [19]
258 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [20]
259 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [37]
260 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [38]
261 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00", # [21..25]
262 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [26]
263 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [27]
264 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x40", # [28..38,47]
265 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [39]
266 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [40]
267 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [41]
268 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
269 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [42]
270 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [43]
271 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [44]
272 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [45]
276 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", # [0..47]
277 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [29]
278 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [30]
279 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
280 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
281 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [22]
282 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
283 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [31]
284 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
285 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
286 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
287 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80", # [47]
288 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [46]
289 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [23]
290 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00", # [24]
291 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
292 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
293 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [25]
294 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
295 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
296 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
297 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
298 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
299 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [16]
300 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [32]
301 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
302 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [17]
303 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [33]
304 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [34]
305 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [35]
306 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [36]
307 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [18]
308 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [19]
309 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [20]
310 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [37]
311 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [38]
312 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00", # [21..25]
313 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [26]
314 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [27]
315 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x80", # [28..38,47]
316 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [39]
317 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [40]
318 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [41]
319 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
320 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [42]
321 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [43]
322 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [44]
323 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [45]
326 $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0";
330 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
334 require Carp; # this initializes %CarpInternal
335 local $Carp::CarpInternal{'warnings'};
336 delete $Carp::CarpInternal{'warnings'};
346 foreach my $word ( @_ ) {
347 if ($word eq 'FATAL') {
351 elsif ($word eq 'NONFATAL') {
355 elsif ($catmask = $Bits{$word}) {
357 $mask |= $DeadBits{$word} if $fatal ;
358 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
361 { Croaker("Unknown warnings category '$word'")}
369 # called from B::Deparse.pm
370 push @_, 'all' unless @_ ;
371 return _bits(undef, @_) ;
378 my $mask = ${^WARNING_BITS} ;
380 if (vec($mask, $Offsets{'all'}, 1)) {
381 $mask |= $Bits{'all'} ;
382 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
385 # Empty @_ is equivalent to @_ = 'all' ;
386 ${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
394 my $mask = ${^WARNING_BITS} ;
396 if (vec($mask, $Offsets{'all'}, 1)) {
397 $mask |= $Bits{'all'} ;
398 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
401 push @_, 'all' unless @_;
403 foreach my $word ( @_ ) {
404 if ($word eq 'FATAL') {
407 elsif ($catmask = $Bits{$word}) {
408 $mask &= ~($catmask | $DeadBits{$word} | $All);
411 { Croaker("Unknown warnings category '$word'")}
414 ${^WARNING_BITS} = $mask ;
417 my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
419 sub MESSAGE () { 4 };
429 my $has_message = $wanted & MESSAGE;
431 unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) {
432 my $sub = (caller 1)[3];
433 my $syntax = $has_message ? "[category,] 'message'" : '[category]';
434 Croaker("Usage: $sub($syntax)");
437 my $message = pop if $has_message;
440 # check the category supplied.
442 if (my $type = ref $category) {
443 Croaker("not an object")
444 if exists $builtin_type{$type};
448 $offset = $Offsets{$category};
449 Croaker("Unknown warnings category '$category'")
450 unless defined $offset;
453 $category = (caller(1))[0] ;
454 $offset = $Offsets{$category};
455 Croaker("package '$category' not registered for warnings")
456 unless defined $offset ;
464 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
465 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
470 $i = _error_loc(); # see where Carp will allocate the error
473 # Defaulting this to 0 reduces complexity in code paths below.
474 my $callers_bitmask = (caller($i))[9] || 0 ;
477 foreach my $type (FATAL, NORMAL) {
478 next unless $wanted & $type;
480 push @results, (vec($callers_bitmask, $offset + $type - 1, 1) ||
481 vec($callers_bitmask, $Offsets{'all'} + $type - 1, 1));
484 # &enabled and &fatal_enabled
485 return $results[0] unless $has_message;
487 # &warnif, and the category is neither enabled as warning nor as fatal
488 return if $wanted == (NORMAL | FATAL | MESSAGE)
489 && !($results[0] || $results[1]);
492 Carp::croak($message) if $results[0];
493 # will always get here for &warn. will only get here for &warnif if the
494 # category is enabled
495 Carp::carp($message);
503 vec($mask, $bit, 1) = 1;
507 sub register_categories
511 for my $name (@names) {
512 if (! defined $Bits{$name}) {
513 $Bits{$name} = _mkMask($LAST_BIT);
514 vec($Bits{'all'}, $LAST_BIT, 1) = 1;
515 $Offsets{$name} = $LAST_BIT ++;
516 foreach my $k (keys %Bits) {
517 vec($Bits{$k}, $LAST_BIT, 1) = 0;
519 $DeadBits{$name} = _mkMask($LAST_BIT);
520 vec($DeadBits{'all'}, $LAST_BIT++, 1) = 1;
527 goto &Carp::short_error_loc; # don't introduce another stack frame
532 return __chk(NORMAL, @_);
537 return __chk(FATAL, @_);
542 return __chk(FATAL | MESSAGE, @_);
547 return __chk(NORMAL | FATAL | MESSAGE, @_);
550 # These are not part of any public interface, so we can delete them to save
552 delete $warnings::{$_} foreach qw(NORMAL FATAL MESSAGE);