diff --git a/platform/x86real/noexcept.cpp b/platform/x86real/noexcept.cpp new file mode 100644 index 00000000..28365cbf --- /dev/null +++ b/platform/x86real/noexcept.cpp @@ -0,0 +1,50 @@ +// Remove C++ exception handler bloat on Borland compilers +// (see https://community.embarcadero.com/article/technical-articles/162/14700) +// ---------------------------------------------------------------------------- + +#pragma option -zC_TEXT + +#if defined(__TURBOC__) && defined(__MSDOS__) + +#include +#include +#include "platform.h" + +extern "C" void __cdecl _ExceptInit(void) +{ +} + +new_handler _new_handler = nullptr; + +new_handler __cdecl set_new_handler(new_handler p) +{ + new_handler t = _new_handler; + _new_handler = p; + return t; +} + +void* __cdecl operator new(size_t size) +{ + void* p = nullptr; + if(size == 0) { + size = 1; + } + while(((p = malloc(size)) == nullptr) && (_new_handler != nullptr)) { + _new_handler(); + } + return p; +} + +void far* __cdecl operator new(uint32_t size) +{ + void far* p = nullptr; + if(size == 0) { + size = 1; + } + while(((p = farmalloc(size)) == nullptr) && (_new_handler != nullptr)) { + _new_handler(); + } + return p; +} + +#endif