mirror of https://github.com/nmlgc/ReC98.git
[Platform] [x86 Real Mode] Implement Turbo C++ 4.0J exception handler removal
Full version with support for `operator new`. Part of P0230, funded by [Anonymous].
This commit is contained in:
parent
4a0d2f3f20
commit
6b5102d2e7
|
@ -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 <malloc.h>
|
||||
#include <new.h>
|
||||
#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
|
Loading…
Reference in New Issue