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.

89 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 1999-2001 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. gldebug.h
  6. Abstract:
  7. Macros used for debugging purposes
  8. Environment:
  9. Windows NT printer drivers
  10. Revision History:
  11. 03/16/96 -davidx-
  12. Created it.
  13. --*/
  14. #ifndef _GLDEBUG_H_
  15. #define _GLDEBUG_H_
  16. #include "debug.h"
  17. ///////////////////////////////////////////////////////////////////////////
  18. // REQUIRE macros
  19. //
  20. // REQUIRE_VALID_POINTER(ptr, err, exitclause)
  21. //
  22. // General purpose macro to check pointer, set last error and bug out with
  23. // the given exit clause.
  24. //
  25. // REQUIRE_VALID_ALLOC(ptr, exitclause)
  26. //
  27. // Special case version of REQIRE_VALID_POINTER for use when allocating mem.
  28. //
  29. // REQUIRE_VALID_DATA(ptr, exitclause)
  30. //
  31. // Special case version of REQUIRE_VALID_POINTER for use when checking a
  32. // data pointer.
  33. //
  34. // These macros are meant as an alternative to the use of ASSERT (which
  35. // behaves differently in DBG and release modes). For simple pointer
  36. // checking of parameters and allocations use these macros in the
  37. // following ways:
  38. //
  39. // void Foo(ISomeType *pSome)
  40. // {
  41. // // Example #1: no return type--use "return" for pSome exit clause
  42. // REQUIRE_VALID_DATA(pSome, return);
  43. // //...
  44. // }
  45. //
  46. // HRESULT Bar(ISomeType *pSome)
  47. // {
  48. // // Example #2: return a value--use desired value with return
  49. // REQUIRE_VALID_DATA(pSome, return E_POINTER);
  50. //
  51. // // Example #3: use other macro for allocations
  52. // PBYTE pData = (PBYTE) MemAlloc(CHUNK_O_DATA);
  53. // REQUIRE_VALID_ALLOC(pData, return E_OUTOFMEMORY);
  54. //
  55. // HRESULT hRet = S_OK;
  56. // switch(pSome->m_bleah)
  57. // {
  58. // case SNAFU:
  59. // ISomeType *pGump = GetSomething();
  60. // // Example #4: use assignment and break for exit clause
  61. // REQUIRE_VALID_DATA(pGump, hRet = E_FAIL; break);
  62. // break;
  63. // }
  64. // return hRet;
  65. // }
  66. //
  67. ///////////////////////////////////////////////////////////////////////////
  68. #define REQUIRE_VALID_POINTER(ptr, err, exitclause) { if ( !(ptr) ) { SetLastError(err); exitclause; } }
  69. #define REQUIRE_VALID_ALLOC(ptr, exitclause) REQUIRE_VALID_POINTER(ptr, ERROR_OUTOFMEMORY, exitclause)
  70. #define REQUIRE_VALID_DATA(ptr, exitclause) REQUIRE_VALID_POINTER(ptr, ERROR_INVALID_DATA, exitclause)
  71. #endif // !_GLDEBUG_H_