PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/MKQT/qtsdk/include/AssertMacros.h

#
C++ Header | 1117 lines | 518 code | 65 blank | 534 comment | 81 complexity | 9546b34fe72da079d379b186a0010a1f MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. File: AssertMacros.h
  3. Contains: This file defines structured error handling and assertion macros for
  4. programming in C. Originally used in QuickDraw GX and later enhanced.
  5. These macros are used throughout Apple's software.
  6. See "Living In an Exceptional World" by Sean Parent
  7. (develop, The Apple Technical Journal, Issue 11, August/September 1992)
  8. <http://developer.apple.com/dev/techsupport/develop/issue11toc.shtml>
  9. for the methodology behind these error handling and assertion macros.
  10. Copyright: Š 2002 by Apple Computer, Inc., all rights reserved.
  11. Bugs?: For bug reports, consult the following page on
  12. the World Wide Web:
  13. http://developer.apple.com/bugreporter/
  14. */
  15. #ifndef __ASSERTMACROS__
  16. #define __ASSERTMACROS__
  17. /*
  18. * Macro overview:
  19. *
  20. * check(assertion)
  21. * In production builds, pre-processed away
  22. * In debug builds, if assertion evaluates to false, calls DEBUG_ASSERT_MESSAGE
  23. *
  24. * verify(assertion)
  25. * In production builds, evaluates assertion and does nothing
  26. * In debug builds, if assertion evaluates to false, calls DEBUG_ASSERT_MESSAGE
  27. *
  28. * require(assertion, exceptionLabel)
  29. * In production builds, if the assertion expression evaluates to false, goto exceptionLabel
  30. * In debug builds, if the assertion expression evaluates to false, calls DEBUG_ASSERT_MESSAGE
  31. * and jumps to exceptionLabel
  32. *
  33. * In addition the following suffixes are available:
  34. *
  35. * _noerr Adds "!= 0" to assertion. Useful for asserting and OSStatus or OSErr is noErr (zero)
  36. * _action Adds statement to be executued if assertion fails
  37. * _quiet Suppress call to DEBUG_ASSERT_MESSAGE
  38. * _string Allows you to add explanitory message to DEBUG_ASSERT_MESSAGE
  39. *
  40. * For instance, require_noerr_string(resultCode, label, msg) will do nothing if
  41. * resultCode is zero, otherwise it will call DEBUG_ASSERT_MESSAGE with msg
  42. * and jump to label.
  43. *
  44. * Configuration:
  45. *
  46. * By default all macros generate "production code" (i.e non-debug). If
  47. * DEBUG_ASSERT_PRODUCTION_CODE is defined to zero or DEBUG is defined to non-zero
  48. * while this header is included, the macros will generated debug code.
  49. *
  50. * If DEBUG_ASSERT_COMPONENT_NAME_STRING is defined, all debug messages will
  51. * be prefixed with it.
  52. *
  53. * By default, all messages write to stderr. If you would like to write a custom
  54. * error message formater, defined DEBUG_ASSERT_MESSAGE to your function name.
  55. *
  56. */
  57. /*
  58. * Before including this file, #define DEBUG_ASSERT_COMPONENT_NAME_STRING to
  59. * a C-string containing the name of your client. This string will be passed to
  60. * the DEBUG_ASSERT_MESSAGE macro for inclusion in any assertion messages.
  61. *
  62. * If you do not define DEBUG_ASSERT_COMPONENT_NAME_STRING, the default
  63. * DEBUG_ASSERT_COMPONENT_NAME_STRING value, an empty string, will be used by
  64. * the assertion macros.
  65. */
  66. #ifndef DEBUG_ASSERT_COMPONENT_NAME_STRING
  67. #define DEBUG_ASSERT_COMPONENT_NAME_STRING ""
  68. #endif
  69. /*
  70. * To activate the additional assertion code and messages for non-production builds,
  71. * #define DEBUG_ASSERT_PRODUCTION_CODE to zero before including this file.
  72. *
  73. * If you do not define DEBUG_ASSERT_PRODUCTION_CODE, the default value 1 will be used
  74. * (production code = no assertion code and no messages).
  75. */
  76. #ifndef DEBUG_ASSERT_PRODUCTION_CODE
  77. #define DEBUG_ASSERT_PRODUCTION_CODE !DEBUG
  78. #endif
  79. /*
  80. * DEBUG_ASSERT_MESSAGE()
  81. *
  82. * Summary:
  83. * All assertion messages are routed through this macro. If you wish to use your
  84. * own routine to display assertion messages, you can override DEBUG_ASSERT_MESSAGE
  85. * by #defining DEBUG_ASSERT_MESSAGE before including this file.
  86. *
  87. * Parameters:
  88. *
  89. * componentNameString:
  90. * A pointer to a string constant containing the name of the
  91. * component this code is part of. This must be a string constant
  92. * (and not a string variable or NULL) because the preprocessor
  93. * concatenates it with other string constants.
  94. *
  95. * assertionString:
  96. * A pointer to a string constant containing the assertion.
  97. * This must be a string constant (and not a string variable or
  98. * NULL) because the Preprocessor concatenates it with other
  99. * string constants.
  100. *
  101. * exceptionLabelString:
  102. * A pointer to a string containing the exceptionLabel, or NULL.
  103. *
  104. * errorString:
  105. * A pointer to the error string, or NULL. DEBUG_ASSERT_MESSAGE macros
  106. * must not attempt to concatenate this string with constant
  107. * character strings.
  108. *
  109. * fileName:
  110. * A pointer to the fileName or pathname (generated by the
  111. * preprocessor __FILE__ identifier), or NULL.
  112. *
  113. * lineNumber:
  114. * The line number in the file (generated by the preprocessor
  115. * __LINE__ identifier), or 0 (zero).
  116. *
  117. * errorCode:
  118. * A value associated with the assertion, or 0.
  119. *
  120. * Here is an example of a DEBUG_ASSERT_MESSAGE macro and a routine which displays
  121. * assertion messsages:
  122. *
  123. * #define DEBUG_ASSERT_COMPONENT_NAME_STRING "MyCoolProgram"
  124. *
  125. * #define DEBUG_ASSERT_MESSAGE(componentNameString, assertionString, \
  126. * exceptionLabelString, errorString, fileName, lineNumber, errorCode) \
  127. * MyProgramDebugAssert(componentNameString, assertionString, \
  128. * exceptionLabelString, errorString, fileName, lineNumber, errorCode)
  129. *
  130. * static void
  131. * MyProgramDebugAssert(const char *componentNameString, const char *assertionString,
  132. * const char *exceptionLabelString, const char *errorString,
  133. * const char *fileName, long lineNumber, int errorCode)
  134. * {
  135. * if ( (assertionString != NULL) && (*assertionString != \'0') )
  136. * fprintf(stderr, "Assertion failed: %s: %s\n", componentNameString, assertionString);
  137. * else
  138. * fprintf(stderr, "Check failed: %s:\n", componentNameString);
  139. * if ( exceptionLabelString != NULL )
  140. * fprintf(stderr, " %s\n", exceptionLabelString);
  141. * if ( errorString != NULL )
  142. * fprintf(stderr, " %s\n", errorString);
  143. * if ( fileName != NULL )
  144. * fprintf(stderr, " file: %s\n", fileName);
  145. * if ( lineNumber != 0 )
  146. * fprintf(stderr, " line: %ld\n", lineNumber);
  147. * if ( errorCode != 0 )
  148. * fprintf(stderr, " error: %d\n", errorCode);
  149. * }
  150. *
  151. * If you do not define DEBUG_ASSERT_MESSAGE, a simple printf to stderr will be used.
  152. */
  153. #ifndef DEBUG_ASSERT_MESSAGE
  154. #ifdef KERNEL
  155. #include <syslog.h>
  156. #define DEBUG_ASSERT_MESSAGE(name, assertion, label, message, file, line, value) \
  157. syslog(LOG_ERR, "AssertMacros: %s, %s file: %s, line: %d\n", assertion, (message!=0) ? message : "", file, line);
  158. #else
  159. #include <stdio.h>
  160. #define DEBUG_ASSERT_MESSAGE(name, assertion, label, message, file, line, value) \
  161. fprintf(stderr, "AssertMacros: %s, %s file: %s, line: %d\n", assertion, (message!=0) ? message : "", file, line);
  162. #endif
  163. #endif
  164. /*
  165. * debug_string(message)
  166. *
  167. * Summary:
  168. * Production builds: does nothing and produces no code.
  169. *
  170. * Non-production builds: call DEBUG_ASSERT_MESSAGE.
  171. *
  172. * Parameters:
  173. *
  174. * message:
  175. * The C string to display.
  176. *
  177. */
  178. #if DEBUG_ASSERT_PRODUCTION_CODE
  179. #define debug_string(message)
  180. #else
  181. #define debug_string(message) \
  182. do \
  183. { \
  184. DEBUG_ASSERT_MESSAGE( \
  185. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  186. "", \
  187. 0, \
  188. message, \
  189. __FILE__, \
  190. __LINE__, \
  191. 0); \
  192. } while ( 0 )
  193. #endif
  194. /*
  195. * check(assertion)
  196. *
  197. * Summary:
  198. * Production builds: does nothing and produces no code.
  199. *
  200. * Non-production builds: if the assertion expression evaluates to false,
  201. * call DEBUG_ASSERT_MESSAGE.
  202. *
  203. * Parameters:
  204. *
  205. * assertion:
  206. * The assertion expression.
  207. */
  208. #if DEBUG_ASSERT_PRODUCTION_CODE
  209. #define check(assertion)
  210. #else
  211. #define check(assertion) \
  212. do \
  213. { \
  214. if ( !(assertion) ) \
  215. { \
  216. DEBUG_ASSERT_MESSAGE( \
  217. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  218. #assertion, \
  219. 0, \
  220. 0, \
  221. __FILE__, \
  222. __LINE__, \
  223. 0); \
  224. } \
  225. } while ( 0 )
  226. #endif
  227. #define ncheck(assertion) \
  228. check(!(assertion))
  229. /*
  230. * check_string(assertion, message)
  231. *
  232. * Summary:
  233. * Production builds: does nothing and produces no code.
  234. *
  235. * Non-production builds: if the assertion expression evaluates to false,
  236. * call DEBUG_ASSERT_MESSAGE.
  237. *
  238. * Parameters:
  239. *
  240. * assertion:
  241. * The assertion expression.
  242. *
  243. * message:
  244. * The C string to display.
  245. */
  246. #if DEBUG_ASSERT_PRODUCTION_CODE
  247. #define check_string(assertion, message)
  248. #else
  249. #define check_string(assertion, message) \
  250. do \
  251. { \
  252. if ( !(assertion) ) \
  253. { \
  254. DEBUG_ASSERT_MESSAGE( \
  255. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  256. #assertion, \
  257. 0, \
  258. message, \
  259. __FILE__, \
  260. __LINE__, \
  261. 0); \
  262. } \
  263. } while ( 0 )
  264. #endif
  265. #define ncheck_string(assertion, message) \
  266. check_string(!(assertion), message)
  267. /*
  268. * check_noerr(errorCode)
  269. *
  270. * Summary:
  271. * Production builds: does nothing and produces no code.
  272. *
  273. * Non-production builds: if the errorCode expression does not equal 0 (noErr),
  274. * call DEBUG_ASSERT_MESSAGE.
  275. *
  276. * Parameters:
  277. *
  278. * errorCode:
  279. * The errorCode expression to compare with 0.
  280. */
  281. #if DEBUG_ASSERT_PRODUCTION_CODE
  282. #define check_noerr(errorCode)
  283. #else
  284. #define check_noerr(errorCode) \
  285. do \
  286. { \
  287. int evalOnceErrorCode = (errorCode); \
  288. if ( 0 != evalOnceErrorCode ) \
  289. { \
  290. DEBUG_ASSERT_MESSAGE( \
  291. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  292. #errorCode " == 0 ", \
  293. 0, \
  294. 0, \
  295. __FILE__, \
  296. __LINE__, \
  297. evalOnceErrorCode); \
  298. } \
  299. } while ( 0 )
  300. #endif
  301. /*
  302. * check_noerr_string(errorCode, message)
  303. *
  304. * Summary:
  305. * Production builds: check_noerr_string() does nothing and produces
  306. * no code.
  307. *
  308. * Non-production builds: if the errorCode expression does not equal 0 (noErr),
  309. * call DEBUG_ASSERT_MESSAGE.
  310. *
  311. * Parameters:
  312. *
  313. * errorCode:
  314. * The errorCode expression to compare to 0.
  315. *
  316. * message:
  317. * The C string to display.
  318. */
  319. #if DEBUG_ASSERT_PRODUCTION_CODE
  320. #define check_noerr_string(errorCode, message)
  321. #else
  322. #define check_noerr_string(errorCode, message) \
  323. do \
  324. { \
  325. int evalOnceErrorCode = (errorCode); \
  326. if ( 0 != evalOnceErrorCode ) \
  327. { \
  328. DEBUG_ASSERT_MESSAGE( \
  329. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  330. #errorCode " == 0 ", \
  331. 0, \
  332. message, \
  333. __FILE__, \
  334. __LINE__, \
  335. evalOnceErrorCode); \
  336. } \
  337. } while ( 0 )
  338. #endif
  339. /*
  340. * verify(assertion)
  341. *
  342. * Summary:
  343. * Production builds: evaluate the assertion expression, but ignore
  344. * the result.
  345. *
  346. * Non-production builds: if the assertion expression evaluates to false,
  347. * call DEBUG_ASSERT_MESSAGE.
  348. *
  349. * Parameters:
  350. *
  351. * assertion:
  352. * The assertion expression.
  353. */
  354. #if DEBUG_ASSERT_PRODUCTION_CODE
  355. #define verify(assertion) \
  356. do \
  357. { \
  358. if ( !(assertion) ) \
  359. { \
  360. } \
  361. } while ( 0 )
  362. #else
  363. #define verify(assertion) \
  364. do \
  365. { \
  366. if ( !(assertion) ) \
  367. { \
  368. DEBUG_ASSERT_MESSAGE( \
  369. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  370. #assertion, \
  371. 0, \
  372. 0, \
  373. __FILE__, \
  374. __LINE__, \
  375. 0); \
  376. } \
  377. } while ( 0 )
  378. #endif
  379. #define nverify(assertion) \
  380. verify(!(assertion))
  381. /*
  382. * verify_string(assertion, message)
  383. *
  384. * Summary:
  385. * Production builds: evaluate the assertion expression, but ignore
  386. * the result.
  387. *
  388. * Non-production builds: if the assertion expression evaluates to false,
  389. * call DEBUG_ASSERT_MESSAGE.
  390. *
  391. * Parameters:
  392. *
  393. * assertion:
  394. * The assertion expression.
  395. *
  396. * message:
  397. * The C string to display.
  398. */
  399. #if DEBUG_ASSERT_PRODUCTION_CODE
  400. #define verify_string(assertion, message) \
  401. do \
  402. { \
  403. if ( !(assertion) ) \
  404. { \
  405. } \
  406. } while ( 0 )
  407. #else
  408. #define verify_string(assertion, message) \
  409. do \
  410. { \
  411. if ( !(assertion) ) \
  412. { \
  413. DEBUG_ASSERT_MESSAGE( \
  414. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  415. #assertion, \
  416. 0, \
  417. message, \
  418. __FILE__, \
  419. __LINE__, \
  420. 0); \
  421. } \
  422. } while ( 0 )
  423. #endif
  424. #define nverify_string(assertion, message) \
  425. verify_string(!(assertion), message)
  426. /*
  427. * verify_noerr(errorCode)
  428. *
  429. * Summary:
  430. * Production builds: evaluate the errorCode expression, but ignore
  431. * the result.
  432. *
  433. * Non-production builds: if the errorCode expression does not equal 0 (noErr),
  434. * call DEBUG_ASSERT_MESSAGE.
  435. *
  436. * Parameters:
  437. *
  438. * errorCode:
  439. * The expression to compare to 0.
  440. */
  441. #if DEBUG_ASSERT_PRODUCTION_CODE
  442. #define verify_noerr(errorCode) \
  443. do \
  444. { \
  445. if ( 0 != (errorCode) ) \
  446. { \
  447. } \
  448. } while ( 0 )
  449. #else
  450. #define verify_noerr(errorCode) \
  451. do \
  452. { \
  453. int evalOnceErrorCode = (errorCode); \
  454. if ( 0 != evalOnceErrorCode ) \
  455. { \
  456. DEBUG_ASSERT_MESSAGE( \
  457. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  458. #errorCode " == 0 ", \
  459. 0, \
  460. 0, \
  461. __FILE__, \
  462. __LINE__, \
  463. evalOnceErrorCode); \
  464. } \
  465. } while ( 0 )
  466. #endif
  467. /*
  468. * verify_noerr_string(errorCode, message)
  469. *
  470. * Summary:
  471. * Production builds: evaluate the errorCode expression, but ignore
  472. * the result.
  473. *
  474. * Non-production builds: if the errorCode expression does not equal 0 (noErr),
  475. * call DEBUG_ASSERT_MESSAGE.
  476. *
  477. * Parameters:
  478. *
  479. * errorCode:
  480. * The expression to compare to 0.
  481. *
  482. * message:
  483. * The C string to display.
  484. */
  485. #if DEBUG_ASSERT_PRODUCTION_CODE
  486. #define verify_noerr_string(errorCode, message) \
  487. do \
  488. { \
  489. if ( 0 != (errorCode) ) \
  490. { \
  491. } \
  492. } while ( 0 )
  493. #else
  494. #define verify_noerr_string(errorCode, message) \
  495. do \
  496. { \
  497. int evalOnceErrorCode = (errorCode); \
  498. if ( 0 != evalOnceErrorCode ) \
  499. { \
  500. DEBUG_ASSERT_MESSAGE( \
  501. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  502. #errorCode " == 0 ", \
  503. 0, \
  504. message, \
  505. __FILE__, \
  506. __LINE__, \
  507. evalOnceErrorCode); \
  508. } \
  509. } while ( 0 )
  510. #endif
  511. /*
  512. * require(assertion, exceptionLabel)
  513. *
  514. * Summary:
  515. * Production builds: if the assertion expression evaluates to false,
  516. * goto exceptionLabel.
  517. *
  518. * Non-production builds: if the assertion expression evaluates to false,
  519. * call DEBUG_ASSERT_MESSAGE and then goto exceptionLabel.
  520. *
  521. * Parameters:
  522. *
  523. * assertion:
  524. * The assertion expression.
  525. *
  526. * exceptionLabel:
  527. * The label.
  528. */
  529. #if DEBUG_ASSERT_PRODUCTION_CODE
  530. #define require(assertion, exceptionLabel) \
  531. do \
  532. { \
  533. if ( !(assertion) ) \
  534. { \
  535. goto exceptionLabel; \
  536. } \
  537. } while ( 0 )
  538. #else
  539. #define require(assertion, exceptionLabel) \
  540. do \
  541. { \
  542. if ( !(assertion) ) \
  543. { \
  544. DEBUG_ASSERT_MESSAGE( \
  545. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  546. #assertion, \
  547. #exceptionLabel, \
  548. 0, \
  549. __FILE__, \
  550. __LINE__, \
  551. 0); \
  552. goto exceptionLabel; \
  553. } \
  554. } while ( 0 )
  555. #endif
  556. #define nrequire(assertion, exceptionLabel) \
  557. require(!(assertion), exceptionLabel)
  558. /*
  559. * require_action(assertion, exceptionLabel, action)
  560. *
  561. * Summary:
  562. * Production builds: if the assertion expression evaluates to false,
  563. * execute the action statement or compound statement (block) and then
  564. * goto exceptionLabel.
  565. *
  566. * Non-production builds: if the assertion expression evaluates to false,
  567. * call DEBUG_ASSERT_MESSAGE, execute the action statement or compound
  568. * statement (block), and then goto exceptionLabel.
  569. *
  570. * Parameters:
  571. *
  572. * assertion:
  573. * The assertion expression.
  574. *
  575. * exceptionLabel:
  576. * The label.
  577. *
  578. * action:
  579. * The statement or compound statement (block).
  580. */
  581. #if DEBUG_ASSERT_PRODUCTION_CODE
  582. #define require_action(assertion, exceptionLabel, action) \
  583. do \
  584. { \
  585. if ( !(assertion) ) \
  586. { \
  587. { \
  588. action; \
  589. } \
  590. goto exceptionLabel; \
  591. } \
  592. } while ( 0 )
  593. #else
  594. #define require_action(assertion, exceptionLabel, action) \
  595. do \
  596. { \
  597. if ( !(assertion) ) \
  598. { \
  599. DEBUG_ASSERT_MESSAGE( \
  600. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  601. #assertion, \
  602. #exceptionLabel, \
  603. 0, \
  604. __FILE__, \
  605. __LINE__, \
  606. 0); \
  607. { \
  608. action; \
  609. } \
  610. goto exceptionLabel; \
  611. } \
  612. } while ( 0 )
  613. #endif
  614. #define nrequire_action(assertion, exceptionLabel, action) \
  615. require_action(!(assertion), exceptionLabel, action)
  616. /*
  617. * require_quiet(assertion, exceptionLabel)
  618. *
  619. * Summary:
  620. * If the assertion expression evaluates to false, goto exceptionLabel.
  621. *
  622. * Parameters:
  623. *
  624. * assertion:
  625. * The assertion expression.
  626. *
  627. * exceptionLabel:
  628. * The label.
  629. */
  630. #define require_quiet(assertion, exceptionLabel) \
  631. do \
  632. { \
  633. if ( !(assertion) ) \
  634. { \
  635. goto exceptionLabel; \
  636. } \
  637. } while ( 0 )
  638. #define nrequire_quiet(assertion, exceptionLabel) \
  639. require_quiet(!(assertion), exceptionLabel)
  640. /*
  641. * require_action_quiet(assertion, exceptionLabel, action)
  642. *
  643. * Summary:
  644. * If the assertion expression evaluates to false, execute the action
  645. * statement or compound statement (block), and goto exceptionLabel.
  646. *
  647. * Parameters:
  648. *
  649. * assertion:
  650. * The assertion expression.
  651. *
  652. * exceptionLabel:
  653. * The label.
  654. *
  655. * action:
  656. * The statement or compound statement (block).
  657. */
  658. #define require_action_quiet(assertion, exceptionLabel, action) \
  659. do \
  660. { \
  661. if ( !(assertion) ) \
  662. { \
  663. { \
  664. action; \
  665. } \
  666. goto exceptionLabel; \
  667. } \
  668. } while ( 0 )
  669. #define nrequire_action_quiet(assertion, exceptionLabel, action) \
  670. require_action_quiet(!(assertion), exceptionLabel, action)
  671. /*
  672. * require_string(assertion, exceptionLabel, message)
  673. *
  674. * Summary:
  675. * Production builds: if the assertion expression evaluates to false,
  676. * goto exceptionLabel.
  677. *
  678. * Non-production builds: if the assertion expression evaluates to false,
  679. * call DEBUG_ASSERT_MESSAGE, and then goto exceptionLabel.
  680. *
  681. * Parameters:
  682. *
  683. * assertion:
  684. * The assertion expression.
  685. *
  686. * exceptionLabel:
  687. * The label.
  688. *
  689. * message:
  690. * The C string to display.
  691. */
  692. #if DEBUG_ASSERT_PRODUCTION_CODE
  693. #define require_string(assertion, exceptionLabel, message) \
  694. do \
  695. { \
  696. if ( !(assertion) ) \
  697. { \
  698. goto exceptionLabel; \
  699. } \
  700. } while ( 0 )
  701. #else
  702. #define require_string(assertion, exceptionLabel, message) \
  703. do \
  704. { \
  705. if ( !(assertion) ) \
  706. { \
  707. DEBUG_ASSERT_MESSAGE( \
  708. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  709. #assertion, \
  710. #exceptionLabel, \
  711. message, \
  712. __FILE__, \
  713. __LINE__, \
  714. 0); \
  715. goto exceptionLabel; \
  716. } \
  717. } while ( 0 )
  718. #endif
  719. #define nrequire_string(assertion, exceptionLabel, string) \
  720. require_string(!(assertion), exceptionLabel, string)
  721. /*
  722. * require_action_string(assertion, exceptionLabel, action, message)
  723. *
  724. * Summary:
  725. * Production builds: if the assertion expression evaluates to false,
  726. * execute the action statement or compound statement (block), and then
  727. * goto exceptionLabel.
  728. *
  729. * Non-production builds: if the assertion expression evaluates to false,
  730. * call DEBUG_ASSERT_MESSAGE, execute the action statement or compound
  731. * statement (block), and then goto exceptionLabel.
  732. *
  733. * Parameters:
  734. *
  735. * assertion:
  736. * The assertion expression.
  737. *
  738. * exceptionLabel:
  739. * The label.
  740. *
  741. * action:
  742. * The statement or compound statement (block).
  743. *
  744. * message:
  745. * The C string to display.
  746. */
  747. #if DEBUG_ASSERT_PRODUCTION_CODE
  748. #define require_action_string(assertion, exceptionLabel, action, message) \
  749. do \
  750. { \
  751. if ( !(assertion) ) \
  752. { \
  753. { \
  754. action; \
  755. } \
  756. goto exceptionLabel; \
  757. } \
  758. } while ( 0 )
  759. #else
  760. #define require_action_string(assertion, exceptionLabel, action, message) \
  761. do \
  762. { \
  763. if ( !(assertion) ) \
  764. { \
  765. DEBUG_ASSERT_MESSAGE( \
  766. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  767. #assertion, \
  768. #exceptionLabel, \
  769. message, \
  770. __FILE__, \
  771. __LINE__, \
  772. 0); \
  773. { \
  774. action; \
  775. } \
  776. goto exceptionLabel; \
  777. } \
  778. } while ( 0 )
  779. #endif
  780. #define nrequire_action_string(assertion, exceptionLabel, action, message) \
  781. require_action_string(!(assertion), exceptionLabel, action, message)
  782. /*
  783. * require_noerr(errorCode, exceptionLabel)
  784. *
  785. * Summary:
  786. * Production builds: if the errorCode expression does not equal 0 (noErr),
  787. * goto exceptionLabel.
  788. *
  789. * Non-production builds: if the errorCode expression does not equal 0 (noErr),
  790. * call DEBUG_ASSERT_MESSAGE and then goto exceptionLabel.
  791. *
  792. * Parameters:
  793. *
  794. * errorCode:
  795. * The expression to compare to 0.
  796. *
  797. * exceptionLabel:
  798. * The label.
  799. */
  800. #if DEBUG_ASSERT_PRODUCTION_CODE
  801. #define require_noerr(errorCode, exceptionLabel) \
  802. do \
  803. { \
  804. if ( 0 != (errorCode) ) \
  805. { \
  806. goto exceptionLabel; \
  807. } \
  808. } while ( 0 )
  809. #else
  810. #define require_noerr(errorCode, exceptionLabel) \
  811. do \
  812. { \
  813. int evalOnceErrorCode = (errorCode); \
  814. if ( 0 != evalOnceErrorCode ) \
  815. { \
  816. DEBUG_ASSERT_MESSAGE( \
  817. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  818. #errorCode " == 0 ", \
  819. #exceptionLabel, \
  820. 0, \
  821. __FILE__, \
  822. __LINE__, \
  823. evalOnceErrorCode); \
  824. goto exceptionLabel; \
  825. } \
  826. } while ( 0 )
  827. #endif
  828. /*
  829. * require_noerr_action(errorCode, exceptionLabel, action)
  830. *
  831. * Summary:
  832. * Production builds: if the errorCode expression does not equal 0 (noErr),
  833. * execute the action statement or compound statement (block) and
  834. * goto exceptionLabel.
  835. *
  836. * Non-production builds: if the errorCode expression does not equal 0 (noErr),
  837. * call DEBUG_ASSERT_MESSAGE, execute the action statement or
  838. * compound statement (block), and then goto exceptionLabel.
  839. *
  840. * Parameters:
  841. *
  842. * errorCode:
  843. * The expression to compare to 0.
  844. *
  845. * exceptionLabel:
  846. * The label.
  847. *
  848. * action:
  849. * The statement or compound statement (block).
  850. */
  851. #if DEBUG_ASSERT_PRODUCTION_CODE
  852. #define require_noerr_action(errorCode, exceptionLabel, action) \
  853. do \
  854. { \
  855. if ( 0 != (errorCode) ) \
  856. { \
  857. { \
  858. action; \
  859. } \
  860. goto exceptionLabel; \
  861. } \
  862. } while ( 0 )
  863. #else
  864. #define require_noerr_action(errorCode, exceptionLabel, action) \
  865. do \
  866. { \
  867. int evalOnceErrorCode = (errorCode); \
  868. if ( 0 != evalOnceErrorCode ) \
  869. { \
  870. DEBUG_ASSERT_MESSAGE( \
  871. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  872. #errorCode " == 0 ", \
  873. #exceptionLabel, \
  874. 0, \
  875. __FILE__, \
  876. __LINE__, \
  877. evalOnceErrorCode); \
  878. { \
  879. action; \
  880. } \
  881. goto exceptionLabel; \
  882. } \
  883. } while ( 0 )
  884. #endif
  885. /*
  886. * require_noerr_quiet(errorCode, exceptionLabel)
  887. *
  888. * Summary:
  889. * If the errorCode expression does not equal 0 (noErr),
  890. * goto exceptionLabel.
  891. *
  892. * Parameters:
  893. *
  894. * errorCode:
  895. * The expression to compare to 0.
  896. *
  897. * exceptionLabel:
  898. * The label.
  899. */
  900. #define require_noerr_quiet(errorCode, exceptionLabel) \
  901. do \
  902. { \
  903. if ( 0 != (errorCode) ) \
  904. { \
  905. goto exceptionLabel; \
  906. } \
  907. } while ( 0 )
  908. /*
  909. * require_noerr_action_quiet(errorCode, exceptionLabel, action)
  910. *
  911. * Summary:
  912. * If the errorCode expression does not equal 0 (noErr),
  913. * execute the action statement or compound statement (block) and
  914. * goto exceptionLabel.
  915. *
  916. * Parameters:
  917. *
  918. * errorCode:
  919. * The expression to compare to 0.
  920. *
  921. * exceptionLabel:
  922. * The label.
  923. *
  924. * action:
  925. * The statement or compound statement (block).
  926. */
  927. #define require_noerr_action_quiet(errorCode, exceptionLabel, action) \
  928. do \
  929. { \
  930. if ( 0 != (errorCode) ) \
  931. { \
  932. { \
  933. action; \
  934. } \
  935. goto exceptionLabel; \
  936. } \
  937. } while ( 0 )
  938. /*
  939. * require_noerr_string(errorCode, exceptionLabel, message)
  940. *
  941. * Summary:
  942. * Production builds: if the errorCode expression does not equal 0 (noErr),
  943. * goto exceptionLabel.
  944. *
  945. * Non-production builds: if the errorCode expression does not equal 0 (noErr),
  946. * call DEBUG_ASSERT_MESSAGE, and then goto exceptionLabel.
  947. *
  948. * Parameters:
  949. *
  950. * errorCode:
  951. * The expression to compare to 0.
  952. *
  953. * exceptionLabel:
  954. * The label.
  955. *
  956. * message:
  957. * The C string to display.
  958. */
  959. #if DEBUG_ASSERT_PRODUCTION_CODE
  960. #define require_noerr_string(errorCode, exceptionLabel, message) \
  961. do \
  962. { \
  963. if ( 0 != (errorCode) ) \
  964. { \
  965. goto exceptionLabel; \
  966. } \
  967. } while ( 0 )
  968. #else
  969. #define require_noerr_string(errorCode, exceptionLabel, message) \
  970. do \
  971. { \
  972. int evalOnceErrorCode = (errorCode); \
  973. if ( 0 != evalOnceErrorCode ) \
  974. { \
  975. DEBUG_ASSERT_MESSAGE( \
  976. DEBUG_ASSERT_COMPONENT_NAME_STRING, \
  977. #errorCode " == 0 ", \
  978. #exceptionLabel, \
  979. message, \
  980. __FILE__, \
  981. __LINE__, \
  982. evalOnceErrorCode); \
  983. goto exceptionLabel; \
  984. } \
  985. } while ( 0 )
  986. #endif
  987. /*
  988. * require_noerr_action_string(errorCode, exceptionLabel, action, message)
  989. *
  990. * Summary:
  991. * Production builds: if the errorCode expression does not equal 0 (noErr),
  992. * execute the action statement or compound statement (block) and
  993. * goto exceptionLabel.
  994. *
  995. * Non-production builds: if the errorCode expression does not equal 0 (noErr),
  996. * call DEBUG_ASSERT_MESSAGE, execute the action statement or compound
  997. * statement (block), and then goto exceptionLabel.
  998. *
  999. * Parameters:
  1000. *
  1001. * errorCode:
  1002. * The expression to compare to 0.
  1003. *
  1004. * exceptionLabel:
  1005. * The label.
  1006. *
  1007. * action:
  1008. * The statement or compound statement (block).
  1009. *
  1010. * message:
  1011. * The C string to display.
  1012. */
  1013. #if DEBUG_ASSERT_PRODUCTION_CODE
  1014. #define require_noerr_action_string(errorCode, exceptionLabel, action, message)\
  1015. do \
  1016. { \
  1017. if ( 0 != (errorCode) ) \
  1018. { \
  1019. { \
  1020. action; \
  1021. }

Large files files are truncated, but you can click here to view the full file