New.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "core/utils/New.hpp"
  2. #include <stdlib.h>
  3. #include "ErrorSimulator.hpp"
  4. void* operator new(size_t bytes, const NoThrow&) noexcept {
  5. #ifdef ERROR_SIMULATOR
  6. if(Core::Fail::leftAllocations > 0) {
  7. Core::Fail::leftAllocations--;
  8. } else if(Core::Fail::leftAllocations == 0) {
  9. return nullptr;
  10. }
  11. #endif
  12. return malloc(bytes);
  13. }
  14. void* operator new[](size_t bytes, const NoThrow&) noexcept {
  15. #ifdef ERROR_SIMULATOR
  16. if(Core::Fail::leftAllocations > 0) {
  17. Core::Fail::leftAllocations--;
  18. } else if(Core::Fail::leftAllocations == 0) {
  19. return nullptr;
  20. }
  21. #endif
  22. return malloc(bytes);
  23. }
  24. void operator delete(void* p) noexcept {
  25. free(p);
  26. }
  27. void operator delete[](void* p) noexcept {
  28. free(p);
  29. }
  30. void operator delete(void* p, size_t bytes) noexcept {
  31. (void)bytes;
  32. operator delete(p);
  33. }
  34. void operator delete[](void* p, size_t bytes) noexcept {
  35. (void)bytes;
  36. free(p);
  37. }
  38. void* operator new(size_t bytes, void* p) noexcept {
  39. (void)bytes;
  40. return p;
  41. }