new.cpp: split new and delete into 8 files.
This commit is contained in:
98
src/new.cpp
98
src/new.cpp
@@ -23,107 +23,11 @@
|
|||||||
_LIBCPP_END_NAMESPACE_STD
|
_LIBCPP_END_NAMESPACE_STD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
// Implement all new and delete operators as weak definitions
|
// Implement all new and delete operators as weak definitions
|
||||||
// in this shared library, so that they can be overriden by programs
|
// in this shared library, so that they can be overriden by programs
|
||||||
// that define non-weak copies of the functions.
|
// that define non-weak copies of the functions.
|
||||||
|
|
||||||
__attribute__((__weak__, __visibility__("default")))
|
|
||||||
void *
|
|
||||||
operator new(std::size_t size) throw (std::bad_alloc)
|
|
||||||
{
|
|
||||||
if (size == 0)
|
|
||||||
size = 1;
|
|
||||||
void* p;
|
|
||||||
while ((p = ::malloc(size)) == 0)
|
|
||||||
{
|
|
||||||
// If malloc fails and there is a new_handler,
|
|
||||||
// call it to try free up memory.
|
|
||||||
std::new_handler nh = std::get_new_handler();
|
|
||||||
if (nh)
|
|
||||||
nh();
|
|
||||||
else
|
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
||||||
throw std::bad_alloc();
|
|
||||||
#else
|
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((__weak__, __visibility__("default")))
|
|
||||||
void*
|
|
||||||
operator new(size_t size, const std::nothrow_t&) throw()
|
|
||||||
{
|
|
||||||
void* p = 0;
|
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
||||||
try
|
|
||||||
{
|
|
||||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
||||||
p = ::operator new(size);
|
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((__weak__, __visibility__("default")))
|
|
||||||
void*
|
|
||||||
operator new[](size_t size) throw (std::bad_alloc)
|
|
||||||
{
|
|
||||||
return ::operator new(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((__weak__, __visibility__("default")))
|
|
||||||
void*
|
|
||||||
operator new[](size_t size, const std::nothrow_t& nothrow) throw()
|
|
||||||
{
|
|
||||||
void* p = 0;
|
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
||||||
try
|
|
||||||
{
|
|
||||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
||||||
p = ::operator new[](size);
|
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((__weak__, __visibility__("default")))
|
|
||||||
void
|
|
||||||
operator delete(void* ptr) throw ()
|
|
||||||
{
|
|
||||||
if (ptr)
|
|
||||||
::free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((__weak__, __visibility__("default")))
|
|
||||||
void
|
|
||||||
operator delete(void* ptr, const std::nothrow_t&) throw ()
|
|
||||||
{
|
|
||||||
::operator delete(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((__weak__, __visibility__("default")))
|
|
||||||
void
|
|
||||||
operator delete[] (void* ptr) throw ()
|
|
||||||
{
|
|
||||||
::operator delete (ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((__weak__, __visibility__("default")))
|
|
||||||
void
|
|
||||||
operator delete[] (void* ptr, const std::nothrow_t&) throw ()
|
|
||||||
{
|
|
||||||
::operator delete[](ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace std
|
namespace std
|
||||||
{
|
{
|
||||||
|
7
src/new_ZdaPv.cpp
Normal file
7
src/new_ZdaPv.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "new"
|
||||||
|
|
||||||
|
void
|
||||||
|
operator delete[] (void* ptr) throw ()
|
||||||
|
{
|
||||||
|
::operator delete (ptr);
|
||||||
|
}
|
7
src/new_ZdaPvRKSt9nothrow_t.cpp
Normal file
7
src/new_ZdaPvRKSt9nothrow_t.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "new"
|
||||||
|
|
||||||
|
void
|
||||||
|
operator delete[] (void* ptr, const std::nothrow_t&) throw ()
|
||||||
|
{
|
||||||
|
::operator delete[](ptr);
|
||||||
|
}
|
10
src/new_ZdlPv.cpp
Normal file
10
src/new_ZdlPv.cpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "new"
|
||||||
|
|
||||||
|
void
|
||||||
|
operator delete(void* ptr) throw ()
|
||||||
|
{
|
||||||
|
if (ptr)
|
||||||
|
::free(ptr);
|
||||||
|
}
|
7
src/new_ZdlPvRKSt9nothrow_t.cpp
Normal file
7
src/new_ZdlPvRKSt9nothrow_t.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "new"
|
||||||
|
|
||||||
|
void
|
||||||
|
operator delete(void* ptr, const std::nothrow_t&) throw ()
|
||||||
|
{
|
||||||
|
::operator delete(ptr);
|
||||||
|
}
|
7
src/new_Znay.cpp
Normal file
7
src/new_Znay.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "new"
|
||||||
|
|
||||||
|
void*
|
||||||
|
operator new[](size_t size) throw (std::bad_alloc)
|
||||||
|
{
|
||||||
|
return ::operator new(size);
|
||||||
|
}
|
19
src/new_ZnayRKSt9nothrow_t.cpp
Normal file
19
src/new_ZnayRKSt9nothrow_t.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "new"
|
||||||
|
|
||||||
|
void*
|
||||||
|
operator new[](size_t size, const std::nothrow_t& nothrow) throw()
|
||||||
|
{
|
||||||
|
void* p = 0;
|
||||||
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
|
try
|
||||||
|
{
|
||||||
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||||
|
p = ::operator new[](size);
|
||||||
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||||
|
return p;
|
||||||
|
}
|
26
src/new_Znwy.cpp
Normal file
26
src/new_Znwy.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "new"
|
||||||
|
|
||||||
|
void *
|
||||||
|
operator new(std::size_t size) throw (std::bad_alloc)
|
||||||
|
{
|
||||||
|
if (size == 0)
|
||||||
|
size = 1;
|
||||||
|
void* p;
|
||||||
|
while ((p = ::malloc(size)) == 0)
|
||||||
|
{
|
||||||
|
// If malloc fails and there is a new_handler,
|
||||||
|
// call it to try free up memory.
|
||||||
|
std::new_handler nh = std::get_new_handler();
|
||||||
|
if (nh)
|
||||||
|
nh();
|
||||||
|
else
|
||||||
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
|
throw std::bad_alloc();
|
||||||
|
#else
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
19
src/new_ZnwyRKSt9nothrow_t.cpp
Normal file
19
src/new_ZnwyRKSt9nothrow_t.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "new"
|
||||||
|
|
||||||
|
void*
|
||||||
|
operator new(size_t size, const std::nothrow_t&) throw()
|
||||||
|
{
|
||||||
|
void* p = 0;
|
||||||
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
|
try
|
||||||
|
{
|
||||||
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||||
|
p = ::operator new(size);
|
||||||
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||||
|
return p;
|
||||||
|
}
|
Reference in New Issue
Block a user