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.

479 lines
26 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: N C M E M . H
  7. //
  8. // Contents: Common memory management routines.
  9. //
  10. // Notes:
  11. //
  12. // Author: shaunco 24 Mar 1997
  13. // deonb 2 Jan 2002
  14. //
  15. //----------------------------------------------------------------------------
  16. #ifndef _NCMEM_H_
  17. #define _NCMEM_H_
  18. #ifdef _XMEMORY_
  19. #error "Include this file before any STL headers"
  20. // Complain if <xmemory> is included before us, since we may be redefining the allocator from that file.
  21. #endif
  22. #ifdef USE_CUSTOM_STL_ALLOCATOR
  23. // If using our custom allocator for STL, then remove STL's <xmemory> from the equation.
  24. #define _XMEMORY_
  25. #endif
  26. #ifdef COMPILE_WITH_TYPESAFE_PRINTF
  27. #define DEFINE_TYPESAFE_PRINTF(RETTYPE, printffunc, SZARG1) \
  28. RETTYPE printffunc(SZARG1); \
  29. template <class T1> \
  30. RETTYPE printffunc(SZARG1, T1 t1)\
  31. { LPCVOID cast1 = (LPCVOID)t1; return 0; }\
  32. template <class T1, class T2> \
  33. RETTYPE printffunc(SZARG1, T1 t1, T2 t2) \
  34. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; return 0; }\
  35. template <class T1, class T2, class T3> \
  36. RETTYPE printffunc(SZARG1, T1 t1, T2 t2, T3 t3) \
  37. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; return 0; }\
  38. template <class T1, class T2, class T3, class T4> \
  39. RETTYPE printffunc(SZARG1, T1 t1, T2 t2, T3 t3, T4 t4) \
  40. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; return 0; }\
  41. template <class T1, class T2, class T3, class T4, class T5> \
  42. RETTYPE printffunc(SZARG1, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) \
  43. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; return 0; }\
  44. template <class T1, class T2, class T3, class T4, class T5, class T6> \
  45. RETTYPE printffunc(SZARG1, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) \
  46. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; return 0; }\
  47. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7> \
  48. RETTYPE printffunc(SZARG1, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) \
  49. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; return 0; }\
  50. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8> \
  51. RETTYPE printffunc(SZARG1, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) \
  52. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; return 0; }\
  53. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9> \
  54. RETTYPE printffunc(SZARG1, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) \
  55. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; return 0; }\
  56. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10> \
  57. RETTYPE printffunc(SZARG1, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10) \
  58. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; LPCVOID cast10= (LPCVOID)t10; return 0; }\
  59. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11> \
  60. RETTYPE printffunc(SZARG1, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11) \
  61. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; LPCVOID cast10= (LPCVOID)t10; LPCVOID cast11= (LPCVOID)t11; return 0; } \
  62. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12> \
  63. RETTYPE printffunc(SZARG1, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12) \
  64. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; LPCVOID cast10= (LPCVOID)t10; LPCVOID cast11= (LPCVOID)t11; LPCVOID cast12= (LPCVOID)t12; return 0; } \
  65. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12, class T13> \
  66. RETTYPE printffunc(SZARG1, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13) \
  67. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; LPCVOID cast10= (LPCVOID)t10; LPCVOID cast11= (LPCVOID)t11; LPCVOID cast12= (LPCVOID)t12; LPCVOID cast13= (LPCVOID)t13; return 0; }
  68. #define DEFINE_TYPESAFE_PRINTF2(RETTYPE, printffunc, SZARG1, SZARG2) \
  69. RETTYPE printffunc(SZARG1, SZARG2); \
  70. template <class T1> \
  71. RETTYPE printffunc(SZARG1, SZARG2, T1 t1)\
  72. { LPCVOID cast1 = (LPCVOID)t1; return 0; } \
  73. template <class T1, class T2> \
  74. RETTYPE printffunc(SZARG1, SZARG2, T1 t1, T2 t2) \
  75. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; return 0; }\
  76. template <class T1, class T2, class T3> \
  77. RETTYPE printffunc(SZARG1, SZARG2, T1 t1, T2 t2, T3 t3) \
  78. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; return 0; }\
  79. template <class T1, class T2, class T3, class T4> \
  80. RETTYPE printffunc(SZARG1, SZARG2, T1 t1, T2 t2, T3 t3, T4 t4) \
  81. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; return 0; }\
  82. template <class T1, class T2, class T3, class T4, class T5> \
  83. RETTYPE printffunc(SZARG1, SZARG2, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) \
  84. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; return 0; }\
  85. template <class T1, class T2, class T3, class T4, class T5, class T6> \
  86. RETTYPE printffunc(SZARG1, SZARG2, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) \
  87. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; return 0; }\
  88. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7> \
  89. RETTYPE printffunc(SZARG1, SZARG2, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) \
  90. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; return 0; }\
  91. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8> \
  92. RETTYPE printffunc(SZARG1, SZARG2, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) \
  93. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; return 0; }\
  94. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9> \
  95. RETTYPE printffunc(SZARG1, SZARG2, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) \
  96. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; return 0; }\
  97. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10> \
  98. RETTYPE printffunc(SZARG1, SZARG2, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10) \
  99. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; LPCVOID cast10= (LPCVOID)t10; return 0; }\
  100. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11> \
  101. RETTYPE printffunc(SZARG1, SZARG2, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11) \
  102. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; LPCVOID cast10= (LPCVOID)t10; LPCVOID cast11= (LPCVOID)t11; return 0; } \
  103. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12> \
  104. RETTYPE printffunc(SZARG1, SZARG2, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12) \
  105. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; LPCVOID cast10= (LPCVOID)t10; LPCVOID cast11= (LPCVOID)t11; LPCVOID cast12= (LPCVOID)t12; return 0; } \
  106. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12, class T13> \
  107. RETTYPE printffunc(SZARG1, SZARG2, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13) \
  108. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; LPCVOID cast10= (LPCVOID)t10; LPCVOID cast11= (LPCVOID)t11; LPCVOID cast12= (LPCVOID)t12; LPCVOID cast13= (LPCVOID)t13; return 0; }
  109. #define DEFINE_TYPESAFE_PRINTF3(RETTYPE, printffunc, SZARG1, SZARG2, SZARG3) \
  110. RETTYPE printffunc(SZARG1, SZARG2, SZARG3); \
  111. template <class T1> \
  112. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1)\
  113. { LPCVOID cast1 = (LPCVOID)t1; return 0; } \
  114. template <class T1, class T2> \
  115. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1, T2 t2) \
  116. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; return 0; }\
  117. template <class T1, class T2, class T3> \
  118. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1, T2 t2, T3 t3) \
  119. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; return 0; }\
  120. template <class T1, class T2, class T3, class T4> \
  121. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1, T2 t2, T3 t3, T4 t4) \
  122. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; return 0; }\
  123. template <class T1, class T2, class T3, class T4, class T5> \
  124. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) \
  125. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; return 0; }\
  126. template <class T1, class T2, class T3, class T4, class T5, class T6> \
  127. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) \
  128. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; return 0; }\
  129. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7> \
  130. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) \
  131. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; return 0; }\
  132. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8> \
  133. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) \
  134. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; return 0; }\
  135. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9> \
  136. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) \
  137. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; return 0; }\
  138. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10> \
  139. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10) \
  140. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; LPCVOID cast10= (LPCVOID)t10; return 0; }\
  141. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11> \
  142. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11) \
  143. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; LPCVOID cast10= (LPCVOID)t10; LPCVOID cast11= (LPCVOID)t11; return 0; } \
  144. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12> \
  145. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12) \
  146. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; LPCVOID cast10= (LPCVOID)t10; LPCVOID cast11= (LPCVOID)t11; LPCVOID cast12= (LPCVOID)t12; return 0; } \
  147. template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12, class T13> \
  148. RETTYPE printffunc(SZARG1, SZARG2, SZARG3, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13) \
  149. { LPCVOID cast1 = (LPCVOID)t1; LPCVOID cast2 = (LPCVOID)t2; LPCVOID cast3 = (LPCVOID)t3; LPCVOID cast4 = (LPCVOID)t4; LPCVOID cast5 = (LPCVOID)t5; LPCVOID cast6 = (LPCVOID)t6; LPCVOID cast7 = (LPCVOID)t7; LPCVOID cast8 = (LPCVOID)t8; LPCVOID cast9 = (LPCVOID)t9; LPCVOID cast10= (LPCVOID)t10; LPCVOID cast11= (LPCVOID)t11; LPCVOID cast12= (LPCVOID)t12; LPCVOID cast13= (LPCVOID)t13; return 0; }
  150. #undef printf
  151. DEFINE_TYPESAFE_PRINTF(int, safe_printf, LPCSTR)
  152. #define printf safe_printf
  153. #undef _stprintf
  154. DEFINE_TYPESAFE_PRINTF(int, safe__stprintf, LPCWSTR)
  155. #define _stprintf safe__stprintf
  156. #undef wsprintf
  157. DEFINE_TYPESAFE_PRINTF2(int, safe_wsprintf, LPWSTR, LPCWSTR)
  158. #define wsprintf safe_wsprintf
  159. #undef wsprintfW
  160. DEFINE_TYPESAFE_PRINTF2(int, safe_wsprintfW, LPWSTR, LPCWSTR)
  161. #define wsprintfW safe_wsprintfW
  162. #undef swprintf
  163. DEFINE_TYPESAFE_PRINTF2(int, safe_swprintf, LPWSTR, LPCWSTR)
  164. #define swprintf safe_swprintf
  165. #undef wsprintfA
  166. DEFINE_TYPESAFE_PRINTF2(int, safe_wsprintfA, LPSTR, LPCSTR)
  167. #define wsprintfA safe_wsprintfA
  168. #undef sprintf
  169. DEFINE_TYPESAFE_PRINTF2(int, safe_sprintf, LPSTR, LPCSTR)
  170. #define sprintf safe_sprintf
  171. #undef _snwprintf
  172. DEFINE_TYPESAFE_PRINTF3(int, safe__snwprintf, LPWSTR, size_t, LPCWSTR)
  173. #define _snwprintf safe__snwprintf
  174. #undef _snprintf
  175. DEFINE_TYPESAFE_PRINTF3(int, safe__snprintf, LPSTR, size_t, LPCSTR)
  176. #define _snprintf safe__snprintf
  177. #undef fprintf
  178. DEFINE_TYPESAFE_PRINTF2(int, safe_fprintf, void*, LPCSTR)
  179. #define fprintf safe_fprintf
  180. #undef fwprintf
  181. DEFINE_TYPESAFE_PRINTF2(int, safe_fwprintf, void*, LPCWSTR)
  182. #define fwprintf safe_fwprintf
  183. #pragma warning(disable: 4005) // Avoid "macro redefinition" errors. We should win.
  184. #endif // COMPILE_WITH_TYPESAFE_PRINTF
  185. #include <new>
  186. #include <cstdlib>
  187. #include <malloc.h> // for _alloca
  188. VOID*
  189. MemAlloc (
  190. size_t cb) throw();
  191. VOID
  192. MemFree (
  193. VOID* pv) throw();
  194. // A simple wrapper around malloc that returns E_OUTOFMEMORY if the
  195. // allocation fails. Avoids having to explicitly do this at each
  196. // call site of malloc.
  197. //
  198. HRESULT
  199. HrMalloc (
  200. size_t cb,
  201. PVOID* ppv) throw();
  202. // This CANNOT be an inline function. If it is ever not inlined,
  203. // the memory allocated will be destroyed. (We're dealing with the stack
  204. // here.)
  205. //
  206. #define PvAllocOnStack(_st) _alloca(_st)
  207. // Define a structure so that we can overload operator new with a
  208. // signature specific to our purpose.
  209. //
  210. struct throwonfail_t {};
  211. extern const throwonfail_t throwonfail;
  212. VOID*
  213. __cdecl
  214. operator new (
  215. size_t cb,
  216. const throwonfail_t&
  217. ) throw (std::bad_alloc);
  218. // The matching operator delete is required to avoid C4291 (no matching operator delete found; memory will
  219. // not be freed if initialization throws an exception)
  220. // It is not needed to call this delete to free the memory allocated by operator new(size_t, const throwonfail&)
  221. VOID
  222. __cdecl
  223. operator delete (
  224. void* pv,
  225. const throwonfail_t&) throw ();
  226. // Define a structure so that we can overload operator new with a
  227. // signature specific to our purpose.
  228. //
  229. struct extrabytes_t {};
  230. extern const extrabytes_t extrabytes;
  231. VOID*
  232. __cdecl
  233. operator new (
  234. size_t cb,
  235. const extrabytes_t&,
  236. size_t cbExtra) throw();
  237. VOID
  238. __cdecl
  239. operator delete (
  240. VOID* pv,
  241. const extrabytes_t&,
  242. size_t cbExtra);
  243. inline
  244. void * Nccalloc(size_t n, size_t s)
  245. {
  246. return HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, (n * s));
  247. }
  248. inline
  249. void Ncfree(void * p)
  250. {
  251. HeapFree (GetProcessHeap(), 0, p);
  252. }
  253. inline
  254. void * Ncmalloc(size_t n)
  255. {
  256. return HeapAlloc (GetProcessHeap(), 0, n);
  257. }
  258. inline
  259. void * Ncrealloc(void * p, size_t n)
  260. {
  261. return (NULL == p)
  262. ? HeapAlloc (GetProcessHeap(), 0, n)
  263. : HeapReAlloc (GetProcessHeap(), 0, p, n);
  264. }
  265. #define calloc Nccalloc
  266. #define free Ncfree
  267. #define malloc Ncmalloc
  268. #define realloc Ncrealloc
  269. #ifdef USE_CUSTOM_STL_ALLOCATOR
  270. // Our implementation of the STL 'allocator' - STL's version of operator new.
  271. #pragma pack(push,8)
  272. #include <utility>
  273. #ifndef _FARQ // specify standard memory model
  274. #define _FARQ
  275. #define _PDFT ptrdiff_t
  276. #define _SIZT size_t
  277. #endif
  278. // Need to define these since <xmemory> defines these, and we're forcing that header file
  279. // not to be included anymore.
  280. #define _POINTER_X(T, A) T _FARQ *
  281. #define _REFERENCE_X(T, A) T _FARQ &
  282. namespace std
  283. {
  284. // TEMPLATE FUNCTION _Allocate.
  285. // This needs to be implemented seperate from our nc_allocator.allocate (below), since the rest
  286. // of the HP STL headers rely on this implementation to have the name _Allocate. This binds us
  287. // to the HP STL implementation, but given the choice between just rewriting the allocator and
  288. // implementing an entire STL for ourselves, it is better to just rewrite the allocator, albeit
  289. // specific to one implementation of it.
  290. template<class T> inline
  291. T _FARQ *_Allocate(_PDFT nCount, T _FARQ *)
  292. {
  293. if (nCount < 0)
  294. {
  295. nCount = 0;
  296. }
  297. // Call our throwing form of operator new. This will throw a bad_alloc on failure.
  298. return ((T _FARQ *)operator new((_SIZT)nCount * sizeof (T), throwonfail));
  299. }
  300. // TEMPLATE FUNCTION _Construct
  301. // See comments for _Allocate
  302. template<class T1, class T2> inline
  303. void _Construct(T1 _FARQ *p, const T2& v)
  304. {
  305. // Placement new only. No memory allocation, hence no need to throw.
  306. new ((void _FARQ *)p) T1(v);
  307. }
  308. // TEMPLATE FUNCTION _Destroy
  309. // See comments for _Allocate
  310. template<class T>
  311. inline void _Destroy(T _FARQ *p)
  312. {
  313. (p)->~T(); // call the destructor
  314. }
  315. // FUNCTION _Destroy
  316. // See comments for _Allocate
  317. inline void _Destroy(char _FARQ *p)
  318. {
  319. (void *)p;
  320. }
  321. // FUNCTION _Destroy
  322. // See comments for _Allocate
  323. inline void _Destroy(wchar_t _FARQ *p)
  324. {
  325. (void *)p;
  326. }
  327. // TEMPLATE CLASS nc_allocator.
  328. // Our allocator to be used by the STL internals for a type T class. The STL allocator is called:
  329. // 'allocator' and this class replaces that one.
  330. template<class T>
  331. class nc_allocator
  332. {
  333. public:
  334. typedef _SIZT size_type;
  335. typedef _PDFT difference_type;
  336. typedef T _FARQ *pointer;
  337. typedef const T _FARQ *const_pointer;
  338. typedef T _FARQ& reference;
  339. typedef const T _FARQ& const_reference;
  340. typedef T value_type;
  341. pointer address(reference x) const
  342. {
  343. return (&x);
  344. }
  345. const_pointer address(const_reference x) const
  346. {
  347. return (&x);
  348. }
  349. pointer allocate(size_type nCount, const void *)
  350. {
  351. return (_Allocate((difference_type)nCount, (pointer)0));
  352. }
  353. char _FARQ *_Charalloc(size_type nCount)
  354. {
  355. return (_Allocate((difference_type)nCount, (char _FARQ *)0));
  356. }
  357. void deallocate(void _FARQ *p, size_type)
  358. {
  359. operator delete(p);
  360. }
  361. void construct(pointer p, const T& v)
  362. {
  363. _Construct(p, v);
  364. }
  365. void destroy(pointer p)
  366. {
  367. _Destroy(p);
  368. }
  369. _SIZT max_size() const
  370. {
  371. _SIZT nCount = (_SIZT)(-1) / sizeof (T);
  372. return (0 < nCount ? nCount : 1);
  373. }
  374. };
  375. template<class T, class U> inline
  376. bool operator == (const nc_allocator<T>&, const nc_allocator<U>&)
  377. {
  378. return (true);
  379. }
  380. template<class T, class U> inline
  381. bool operator != (const nc_allocator<T>&, const nc_allocator<U>&)
  382. {
  383. return (false);
  384. }
  385. // TEMPLATE CLASS nc_allocator. Our allocator to be used by the STL internals for a void allocation.
  386. template<> class _CRTIMP nc_allocator<void>
  387. {
  388. public:
  389. typedef void T;
  390. typedef T _FARQ *pointer;
  391. typedef const T _FARQ *const_pointer;
  392. typedef T value_type;
  393. };
  394. #pragma pack(pop)
  395. }; // namespace std
  396. // Tell all of STL to use nc_allocator from now on instead of it's built-in allocator
  397. #define allocator nc_allocator
  398. //
  399. // Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  400. // Consult your license regarding permissions and restrictions.
  401. //
  402. // This file is derived from software bearing the following
  403. // restrictions:
  404. //
  405. // Copyright (c) 1994
  406. // Hewlett-Packard Company
  407. //
  408. // Permission to use, copy, modify, distribute and sell this
  409. // software and its documentation for any purpose is hereby
  410. // granted without fee, provided that the above copyright notice
  411. // appear in all copies and that both that copyright notice and
  412. // this permission notice appear in supporting documentation.
  413. // Hewlett-Packard Company makes no representations about the
  414. // suitability of this software for any purpose. It is provided
  415. // "as is" without express or implied warranty.
  416. //
  417. #endif // USE_CUSTOM_STL_ALLOCATOR
  418. #endif // _NCMEM_H_