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.

43 lines
1.3 KiB

  1. /***
  2. *thrownew.cpp - explicit replacement operator new that throws std::bad_alloc
  3. *
  4. * Copyright (c) 2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Provide an explicit operator new that throws std::bad_alloc on
  8. * memory allocation failure.
  9. *
  10. * Link with this object to get ANSI C++ new handler behavior. This is
  11. * provided for those circumstances where the normal throwing new found
  12. * in the C++ Standard Library (libcp, libcpmt, or msvcprt.lib) isn't
  13. * being found by the linker before the legacy non-throwing new in the
  14. * main C Runtime (libc, libcmt, or msvcrt.lib).
  15. *
  16. *
  17. *Revision History:
  18. * 06-14-01 PML Module created.
  19. *
  20. *******************************************************************************/
  21. #ifndef _POSIX_
  22. /* Suppress any linker directives for the C++ Standard Library */
  23. #define _USE_ANSI_CPP
  24. #include <stddef.h>
  25. #include <internal.h>
  26. #include <new>
  27. #include <stdlib.h>
  28. extern "C" int __cdecl _callnewh(size_t size) _THROW1(_STD bad_alloc);
  29. void *__cdecl operator new(size_t size) _THROW1(_STD bad_alloc)
  30. { // try to allocate size bytes
  31. void *p;
  32. while ((p = malloc(size)) == 0)
  33. if (_callnewh(size) == 0)
  34. _STD _Nomemory();
  35. return (p);
  36. }
  37. #endif /* _POSIX_ */