Source code of Windows XP (NT5)
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.

145 lines
3.4 KiB

  1. /***
  2. *setnewh.cpp - defines C++ set_new_handler() routine
  3. *
  4. * Copyright (c) 1990-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Defines C++ set_new_handler() routine.
  8. *
  9. * OBSOLETE - the conforming std::set_new_handler can be found in
  10. * stdhndlr.cpp. This version remains for backwards-compatibility,
  11. * and can no longer be referenced using headers new or new.h.
  12. *
  13. *Revision History:
  14. * 12-28-95 JWM Split from handler.cpp for granularity.
  15. * 10-31-96 JWM Now in namespace std.
  16. * 11-06-96 JWM Now "using std::set_new_handler".
  17. * 03-18-01 PML Force define of ::set_new_handler, not
  18. * std::set_new_handler
  19. *
  20. *******************************************************************************/
  21. #include <stddef.h>
  22. #include <internal.h>
  23. #include <cruntime.h>
  24. #include <mtdll.h>
  25. #include <process.h>
  26. #include <dbgint.h>
  27. #ifndef ANSI_NEW_HANDLER
  28. #define set_new_handler set_new_handler_ignore
  29. #endif /* ANSI_NEW_HANDLER */
  30. #include <new.h>
  31. #ifndef ANSI_NEW_HANDLER
  32. #undef set_new_handler
  33. #endif /* ANSI_NEW_HANDLER */
  34. #ifndef ANSI_NEW_HANDLER
  35. #define _ASSERT_OK
  36. #include <assert.h>
  37. #endif /* ANSI_NEW_HANDLER */
  38. #ifndef ANSI_NEW_HANDLER
  39. /***
  40. *new_handler set_new_handler - set the ANSI C++ new handler
  41. *
  42. *Purpose:
  43. * Set the ANSI C++ per-thread new handler.
  44. *
  45. *Entry:
  46. * Pointer to the new handler to be installed.
  47. *
  48. * WARNING: set_new_handler is a stub function that is provided to
  49. * allow compilation of the Standard Template Library (STL).
  50. *
  51. * Do NOT use it to register a new handler. Use _set_new_handler instead.
  52. *
  53. * However, it can be called to remove the current handler:
  54. *
  55. * set_new_handler(NULL); // calls _set_new_handler(NULL)
  56. *
  57. *Return:
  58. * Previous ANSI C++ new handler
  59. *
  60. *******************************************************************************/
  61. new_handler __cdecl set_new_handler (
  62. new_handler new_p
  63. )
  64. {
  65. // cannot use stub to register a new handler
  66. assert(new_p == 0);
  67. // remove current handler
  68. _set_new_handler(0);
  69. return 0;
  70. }
  71. #else /* ANSI_NEW_HANDLER */
  72. /***
  73. *new_handler set_new_handler - set the ANSI C++ new handler
  74. *
  75. *Purpose:
  76. * Set the ANSI C++ per-thread new handler.
  77. *
  78. *Entry:
  79. * Pointer to the new handler to be installed.
  80. *
  81. * WARNING: This function conforms to the current ANSI C++ draft. If the
  82. * final ANSI specifications change, this function WILL be changed.
  83. *
  84. *Return:
  85. * Previous ANSI C++ new handler
  86. *
  87. *******************************************************************************/
  88. new_handler __cdecl set_new_handler (
  89. new_handler new_p
  90. )
  91. {
  92. new_handler oldh;
  93. #ifdef _MT
  94. _ptiddata ptd;
  95. ptd = _getptd();
  96. oldh = ptd->_newh;
  97. ptd->_newh = new_p;
  98. #else
  99. oldh = _defnewh;
  100. _defnewh = new_p;
  101. #endif
  102. return oldh;
  103. }
  104. /***
  105. *new_handler _query_new_ansi_handler(void) - query value of ANSI C++ new handler
  106. *
  107. *Purpose:
  108. * Obtain current ANSI C++ (per-thread) new handler value.
  109. *
  110. *Entry:
  111. * None
  112. *
  113. *Return:
  114. * Currently installed ANSI C++ new handler
  115. *
  116. *******************************************************************************/
  117. new_handler __cdecl _query_new_ansi_handler (
  118. void
  119. )
  120. {
  121. #ifdef _MT
  122. _ptiddata ptd;
  123. ptd = _getptd();
  124. return ptd->_newh;
  125. #else
  126. return _defnewh;
  127. #endif
  128. }
  129. #endif /* ANSI_NEW_HANDLER */