ldc/ddmd/root/newdelete.c
Johan Engelen 29ce4012af dmd2 --> ddmd. Merge (almost all of) our changes to dmd source into the new D source of dmd 2.069.2.
Also adds the CMake infrastructure to compile and link the D source files.

The build is partially broken:
- A few files in Phobos and druntime do not build
- MSVC build is broken because of unresolved symbols involving reals
2016-01-28 19:03:58 +01:00

59 lines
1 KiB
C

/* Copyright (c) 2000-2014 by Digital Mars
* All Rights Reserved, written by Walter Bright
* http://www.digitalmars.com
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
* https://github.com/D-Programming-Language/dmd/blob/master/src/root/rmem.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(__has_feature)
# if __has_feature(address_sanitizer)
# define USE_ASAN_NEW_DELETE
# endif
#elif defined(__SANITIZE_ADDRESS__)
# define USE_ASAN_NEW_DELETE
#endif
#if !defined(USE_ASAN_NEW_DELETE) && !defined(IN_LLVM)
#if 1
extern "C"
{
void *allocmemory(size_t m_size);
}
void * operator new(size_t m_size)
{
return allocmemory(m_size);
}
void operator delete(void *p)
{
}
#else
void * operator new(size_t m_size)
{
void *p = malloc(m_size);
if (p)
return p;
printf("Error: out of memory\n");
exit(EXIT_FAILURE);
return p;
}
void operator delete(void *p)
{
free(p);
}
#endif
#endif