1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/src/operator_new.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,124 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Name : operator_new.cpp
1.18 +// Part of : libstdcpp
1.19 +// Adaptation layer to get locale functionality.
1.20 +// Version :
1.21 +// This material, including documentation and any related
1.22 +// computer programs, is protected by copyright controlled by
1.23 +// Nokia Corporation. All rights are reserved. Copying,
1.24 +// including reproducing, storing, adapting or translating, any
1.25 +// or all of this material requires the prior written consent of
1.26 +// Nokia Corporation. This material also contains confidential
1.27 +// information which may not be disclosed to others without the
1.28 +// prior written consent of Nokia Corporation.
1.29 +//
1.30 +
1.31 +
1.32 +#include "new"
1.33 +#include <e32std.h>
1.34 +
1.35 +
1.36 +#ifdef __SYMBIAN_STDCPP_SUPPORT__
1.37 +
1.38 +EXPORT_C void* operator new(std::size_t a_size) __THROW(std::bad_alloc)
1.39 + {
1.40 + for (;;)
1.41 + {
1.42 + void* p = User::Alloc(a_size);
1.43 +
1.44 + if (p)
1.45 + {
1.46 + return p;
1.47 + }
1.48 +
1.49 + std::new_handler nh_func ;
1.50 + std::new_handler *ptr = reinterpret_cast<std::new_handler*>(Dll::Tls());
1.51 + nh_func = (ptr)?(*ptr):NULL;
1.52 +
1.53 + if (nh_func)
1.54 + {
1.55 + nh_func();
1.56 + }
1.57 + else
1.58 + {
1.59 + __THROW(std::bad_alloc());
1.60 + }
1.61 + }
1.62 + }
1.63 +
1.64 +EXPORT_C void* operator new[](std::size_t a_size) __THROW(std::bad_alloc)
1.65 + {
1.66 + return ::operator new(a_size);
1.67 + }
1.68 +
1.69 +EXPORT_C void* operator new(std::size_t a_size, const std::nothrow_t&) __NO_THROW
1.70 + {
1.71 + for (;;)
1.72 + {
1.73 + void* p = User::Alloc(a_size);
1.74 +
1.75 + if (p)
1.76 + {
1.77 + return p;
1.78 + }
1.79 +
1.80 + std::new_handler nh_func ;
1.81 + std::new_handler *ptr = reinterpret_cast<std::new_handler*>(Dll::Tls());
1.82 + nh_func = (ptr)?(*ptr):NULL;
1.83 +
1.84 + if (nh_func)
1.85 + {
1.86 + try
1.87 + {
1.88 + nh_func();
1.89 + }
1.90 + catch (...)
1.91 + {
1.92 + return 0;
1.93 + }
1.94 + }
1.95 + else
1.96 + {
1.97 + return 0;
1.98 + }
1.99 + }
1.100 + }
1.101 +
1.102 +EXPORT_C void* operator new[](std::size_t a_size, const std::nothrow_t&) __NO_THROW
1.103 + {
1.104 + return ::operator new(a_size, std::nothrow);
1.105 + }
1.106 +
1.107 +// Symbian-specific addition.
1.108 +EXPORT_C void* operator new(std::size_t a_size, std::size_t a_extra_size) __NO_THROW
1.109 + {
1.110 + return User::Alloc(a_size + a_extra_size);
1.111 + }
1.112 +
1.113 +#ifdef __EABI__
1.114 +//TODO: MOVE to another file
1.115 +EXPORT_C std::bad_alloc::bad_alloc() __NO_THROW
1.116 + {}
1.117 +EXPORT_C std::bad_alloc::bad_alloc(const std::bad_alloc&) __NO_THROW
1.118 + {}
1.119 +EXPORT_C std::bad_alloc& std::bad_alloc::operator=(const std::bad_alloc&) __NO_THROW
1.120 + { return *this;}
1.121 +EXPORT_C std::bad_alloc::~bad_alloc() __NO_THROW
1.122 + {}
1.123 +EXPORT_C const char* std::bad_alloc::what() const __NO_THROW
1.124 + { return "bad_alloc";}
1.125 +#endif // __EABI__
1.126 +
1.127 +#endif // __SYMBIAN_STDCPP_SUPPORT__