Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

419 lines
14 KiB

  1. # This file was created by warnings.pl
  2. # Any changes made here will be lost.
  3. #
  4. package warnings;
  5. =head1 NAME
  6. warnings - Perl pragma to control optional warnings
  7. =head1 SYNOPSIS
  8. use warnings;
  9. no warnings;
  10. use warnings "all";
  11. no warnings "all";
  12. use warnings::register;
  13. if (warnings::enabled()) {
  14. warnings::warn("some warning");
  15. }
  16. if (warnings::enabled("void")) {
  17. warnings::warn("void", "some warning");
  18. }
  19. if (warnings::enabled($object)) {
  20. warnings::warn($object, "some warning");
  21. }
  22. warnif("some warning");
  23. warnif("void", "some warning");
  24. warnif($object, "some warning");
  25. =head1 DESCRIPTION
  26. If no import list is supplied, all possible warnings are either enabled
  27. or disabled.
  28. A number of functions are provided to assist module authors.
  29. =over 4
  30. =item use warnings::register
  31. Creates a new warnings category with the same name as the package where
  32. the call to the pragma is used.
  33. =item warnings::enabled()
  34. Use the warnings category with the same name as the current package.
  35. Return TRUE if that warnings category is enabled in the calling module.
  36. Otherwise returns FALSE.
  37. =item warnings::enabled($category)
  38. Return TRUE if the warnings category, C<$category>, is enabled in the
  39. calling module.
  40. Otherwise returns FALSE.
  41. =item warnings::enabled($object)
  42. Use the name of the class for the object reference, C<$object>, as the
  43. warnings category.
  44. Return TRUE if that warnings category is enabled in the first scope
  45. where the object is used.
  46. Otherwise returns FALSE.
  47. =item warnings::warn($message)
  48. Print C<$message> to STDERR.
  49. Use the warnings category with the same name as the current package.
  50. If that warnings category has been set to "FATAL" in the calling module
  51. then die. Otherwise return.
  52. =item warnings::warn($category, $message)
  53. Print C<$message> to STDERR.
  54. If the warnings category, C<$category>, has been set to "FATAL" in the
  55. calling module then die. Otherwise return.
  56. =item warnings::warn($object, $message)
  57. Print C<$message> to STDERR.
  58. Use the name of the class for the object reference, C<$object>, as the
  59. warnings category.
  60. If that warnings category has been set to "FATAL" in the scope where C<$object>
  61. is first used then die. Otherwise return.
  62. =item warnings::warnif($message)
  63. Equivalent to:
  64. if (warnings::enabled())
  65. { warnings::warn($message) }
  66. =item warnings::warnif($category, $message)
  67. Equivalent to:
  68. if (warnings::enabled($category))
  69. { warnings::warn($category, $message) }
  70. =item warnings::warnif($object, $message)
  71. Equivalent to:
  72. if (warnings::enabled($object))
  73. { warnings::warn($object, $message) }
  74. =back
  75. See L<perlmodlib/Pragmatic Modules> and L<perllexwarn>.
  76. =cut
  77. use Carp ;
  78. %Offsets = (
  79. 'all' => 0,
  80. 'chmod' => 2,
  81. 'closure' => 4,
  82. 'exiting' => 6,
  83. 'glob' => 8,
  84. 'io' => 10,
  85. 'closed' => 12,
  86. 'exec' => 14,
  87. 'newline' => 16,
  88. 'pipe' => 18,
  89. 'unopened' => 20,
  90. 'misc' => 22,
  91. 'numeric' => 24,
  92. 'once' => 26,
  93. 'overflow' => 28,
  94. 'pack' => 30,
  95. 'portable' => 32,
  96. 'recursion' => 34,
  97. 'redefine' => 36,
  98. 'regexp' => 38,
  99. 'severe' => 40,
  100. 'debugging' => 42,
  101. 'inplace' => 44,
  102. 'internal' => 46,
  103. 'malloc' => 48,
  104. 'signal' => 50,
  105. 'substr' => 52,
  106. 'syntax' => 54,
  107. 'ambiguous' => 56,
  108. 'bareword' => 58,
  109. 'deprecated' => 60,
  110. 'digit' => 62,
  111. 'parenthesis' => 64,
  112. 'precedence' => 66,
  113. 'printf' => 68,
  114. 'prototype' => 70,
  115. 'qw' => 72,
  116. 'reserved' => 74,
  117. 'semicolon' => 76,
  118. 'taint' => 78,
  119. 'umask' => 80,
  120. 'uninitialized' => 82,
  121. 'unpack' => 84,
  122. 'untie' => 86,
  123. 'utf8' => 88,
  124. 'void' => 90,
  125. 'y2k' => 92,
  126. );
  127. %Bits = (
  128. 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15", # [0..46]
  129. 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", # [28]
  130. 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [29]
  131. 'chmod' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
  132. 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
  133. 'closure' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
  134. 'debugging' => "\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00", # [21]
  135. 'deprecated' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [30]
  136. 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [31]
  137. 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
  138. 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
  139. 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
  140. 'inplace' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [22]
  141. 'internal' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [23]
  142. 'io' => "\x00\x54\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..10]
  143. 'malloc' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00", # [24]
  144. 'misc' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
  145. 'newline' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
  146. 'numeric' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
  147. 'once' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
  148. 'overflow' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
  149. 'pack' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
  150. 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [32]
  151. 'pipe' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
  152. 'portable' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [16]
  153. 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [33]
  154. 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [34]
  155. 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [35]
  156. 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [36]
  157. 'recursion' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [17]
  158. 'redefine' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [18]
  159. 'regexp' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [19]
  160. 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [37]
  161. 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [38]
  162. 'severe' => "\x00\x00\x00\x00\x00\x55\x01\x00\x00\x00\x00\x00", # [20..24]
  163. 'signal' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [25]
  164. 'substr' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [26]
  165. 'syntax' => "\x00\x00\x00\x00\x00\x00\x40\x55\x55\x15\x00\x00", # [27..38]
  166. 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [39]
  167. 'umask' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [40]
  168. 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [41]
  169. 'unopened' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
  170. 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [42]
  171. 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [43]
  172. 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [44]
  173. 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [45]
  174. 'y2k' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [46]
  175. );
  176. %DeadBits = (
  177. 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\x2a", # [0..46]
  178. 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00", # [28]
  179. 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [29]
  180. 'chmod' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
  181. 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
  182. 'closure' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
  183. 'debugging' => "\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00", # [21]
  184. 'deprecated' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [30]
  185. 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [31]
  186. 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
  187. 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
  188. 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
  189. 'inplace' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [22]
  190. 'internal' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [23]
  191. 'io' => "\x00\xa8\x2a\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..10]
  192. 'malloc' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00", # [24]
  193. 'misc' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
  194. 'newline' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
  195. 'numeric' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
  196. 'once' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
  197. 'overflow' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
  198. 'pack' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
  199. 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [32]
  200. 'pipe' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
  201. 'portable' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [16]
  202. 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [33]
  203. 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [34]
  204. 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [35]
  205. 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [36]
  206. 'recursion' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [17]
  207. 'redefine' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [18]
  208. 'regexp' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [19]
  209. 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [37]
  210. 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [38]
  211. 'severe' => "\x00\x00\x00\x00\x00\xaa\x02\x00\x00\x00\x00\x00", # [20..24]
  212. 'signal' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [25]
  213. 'substr' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [26]
  214. 'syntax' => "\x00\x00\x00\x00\x00\x00\x80\xaa\xaa\x2a\x00\x00", # [27..38]
  215. 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [39]
  216. 'umask' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [40]
  217. 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [41]
  218. 'unopened' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
  219. 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [42]
  220. 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [43]
  221. 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [44]
  222. 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [45]
  223. 'y2k' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [46]
  224. );
  225. $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0";
  226. $LAST_BIT = 94 ;
  227. $BYTES = 12 ;
  228. $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
  229. sub bits {
  230. my $mask ;
  231. my $catmask ;
  232. my $fatal = 0 ;
  233. foreach my $word (@_) {
  234. if ($word eq 'FATAL') {
  235. $fatal = 1;
  236. }
  237. elsif ($catmask = $Bits{$word}) {
  238. $mask |= $catmask ;
  239. $mask |= $DeadBits{$word} if $fatal ;
  240. }
  241. else
  242. { croak("unknown warnings category '$word'")}
  243. }
  244. return $mask ;
  245. }
  246. sub import {
  247. shift;
  248. my $mask = ${^WARNING_BITS} ;
  249. if (vec($mask, $Offsets{'all'}, 1)) {
  250. $mask |= $Bits{'all'} ;
  251. $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
  252. }
  253. ${^WARNING_BITS} = $mask | bits(@_ ? @_ : 'all') ;
  254. }
  255. sub unimport {
  256. shift;
  257. my $mask = ${^WARNING_BITS} ;
  258. if (vec($mask, $Offsets{'all'}, 1)) {
  259. $mask |= $Bits{'all'} ;
  260. $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
  261. }
  262. ${^WARNING_BITS} = $mask & ~ (bits(@_ ? @_ : 'all') | $All) ;
  263. }
  264. sub __chk
  265. {
  266. my $category ;
  267. my $offset ;
  268. my $isobj = 0 ;
  269. if (@_) {
  270. # check the category supplied.
  271. $category = shift ;
  272. if (ref $category) {
  273. croak ("not an object")
  274. if $category !~ /^([^=]+)=/ ;+
  275. $category = $1 ;
  276. $isobj = 1 ;
  277. }
  278. $offset = $Offsets{$category};
  279. croak("unknown warnings category '$category'")
  280. unless defined $offset;
  281. }
  282. else {
  283. $category = (caller(1))[0] ;
  284. $offset = $Offsets{$category};
  285. croak("package '$category' not registered for warnings")
  286. unless defined $offset ;
  287. }
  288. my $this_pkg = (caller(1))[0] ;
  289. my $i = 2 ;
  290. my $pkg ;
  291. if ($isobj) {
  292. while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
  293. last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
  294. }
  295. $i -= 2 ;
  296. }
  297. else {
  298. for ($i = 2 ; $pkg = (caller($i))[0] ; ++ $i) {
  299. last if $pkg ne $this_pkg ;
  300. }
  301. $i = 2
  302. if !$pkg || $pkg eq $this_pkg ;
  303. }
  304. my $callers_bitmask = (caller($i))[9] ;
  305. return ($callers_bitmask, $offset, $i) ;
  306. }
  307. sub enabled
  308. {
  309. croak("Usage: warnings::enabled([category])")
  310. unless @_ == 1 || @_ == 0 ;
  311. my ($callers_bitmask, $offset, $i) = __chk(@_) ;
  312. return 0 unless defined $callers_bitmask ;
  313. return vec($callers_bitmask, $offset, 1) ||
  314. vec($callers_bitmask, $Offsets{'all'}, 1) ;
  315. }
  316. sub warn
  317. {
  318. croak("Usage: warnings::warn([category,] 'message')")
  319. unless @_ == 2 || @_ == 1 ;
  320. my $message = pop ;
  321. my ($callers_bitmask, $offset, $i) = __chk(@_) ;
  322. local $Carp::CarpLevel = $i ;
  323. croak($message)
  324. if vec($callers_bitmask, $offset+1, 1) ||
  325. vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
  326. carp($message) ;
  327. }
  328. sub warnif
  329. {
  330. croak("Usage: warnings::warnif([category,] 'message')")
  331. unless @_ == 2 || @_ == 1 ;
  332. my $message = pop ;
  333. my ($callers_bitmask, $offset, $i) = __chk(@_) ;
  334. local $Carp::CarpLevel = $i ;
  335. return
  336. unless defined $callers_bitmask &&
  337. (vec($callers_bitmask, $offset, 1) ||
  338. vec($callers_bitmask, $Offsets{'all'}, 1)) ;
  339. croak($message)
  340. if vec($callers_bitmask, $offset+1, 1) ||
  341. vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
  342. carp($message) ;
  343. }
  344. 1;