os/ossrv/genericopenlibs/cppstdlib/src/operator_new.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Name        : operator_new.cpp
sl@0
    15
// Part of     : libstdcpp
sl@0
    16
// Adaptation layer to get locale functionality.
sl@0
    17
// Version     : 
sl@0
    18
// This material, including documentation and any related 
sl@0
    19
// computer programs, is protected by copyright controlled by 
sl@0
    20
// Nokia Corporation. All rights are reserved. Copying, 
sl@0
    21
// including reproducing, storing, adapting or translating, any 
sl@0
    22
// or all of this material requires the prior written consent of 
sl@0
    23
// Nokia Corporation. This material also contains confidential 
sl@0
    24
// information which may not be disclosed to others without the 
sl@0
    25
// prior written consent of Nokia Corporation.
sl@0
    26
//
sl@0
    27
sl@0
    28
sl@0
    29
#include "new"
sl@0
    30
#include <e32std.h>
sl@0
    31
sl@0
    32
sl@0
    33
#ifdef __SYMBIAN_STDCPP_SUPPORT__ 
sl@0
    34
sl@0
    35
EXPORT_C void* operator new(std::size_t a_size) __THROW(std::bad_alloc)
sl@0
    36
	{
sl@0
    37
	for (;;)
sl@0
    38
		{
sl@0
    39
		void* p = User::Alloc(a_size);
sl@0
    40
sl@0
    41
		if (p)
sl@0
    42
			{
sl@0
    43
			return p; 
sl@0
    44
			}
sl@0
    45
sl@0
    46
		std::new_handler nh_func ;
sl@0
    47
		std::new_handler *ptr = reinterpret_cast<std::new_handler*>(Dll::Tls());
sl@0
    48
		nh_func = (ptr)?(*ptr):NULL;
sl@0
    49
sl@0
    50
		if (nh_func)
sl@0
    51
			{
sl@0
    52
			nh_func();
sl@0
    53
			}
sl@0
    54
		else
sl@0
    55
			{
sl@0
    56
			__THROW(std::bad_alloc());
sl@0
    57
			}
sl@0
    58
		}
sl@0
    59
	}
sl@0
    60
sl@0
    61
EXPORT_C void* operator new[](std::size_t a_size) __THROW(std::bad_alloc)
sl@0
    62
	{
sl@0
    63
	return ::operator new(a_size);
sl@0
    64
	}
sl@0
    65
sl@0
    66
EXPORT_C void* operator new(std::size_t a_size, const std::nothrow_t&) __NO_THROW
sl@0
    67
	{
sl@0
    68
	for (;;)
sl@0
    69
		{
sl@0
    70
		void* p = User::Alloc(a_size);
sl@0
    71
sl@0
    72
		if (p)
sl@0
    73
			{
sl@0
    74
			return p;
sl@0
    75
			}
sl@0
    76
sl@0
    77
		std::new_handler nh_func ;
sl@0
    78
		std::new_handler *ptr = reinterpret_cast<std::new_handler*>(Dll::Tls());
sl@0
    79
		nh_func = (ptr)?(*ptr):NULL;
sl@0
    80
sl@0
    81
		if (nh_func)
sl@0
    82
			{
sl@0
    83
			try
sl@0
    84
				{
sl@0
    85
				nh_func();
sl@0
    86
				}
sl@0
    87
			catch (...)
sl@0
    88
				{
sl@0
    89
				return 0;
sl@0
    90
				}
sl@0
    91
			}
sl@0
    92
		else
sl@0
    93
			{
sl@0
    94
			return 0;
sl@0
    95
			}
sl@0
    96
		}
sl@0
    97
	}
sl@0
    98
sl@0
    99
EXPORT_C void* operator new[](std::size_t a_size, const std::nothrow_t&) __NO_THROW
sl@0
   100
	{
sl@0
   101
	return ::operator new(a_size, std::nothrow);
sl@0
   102
	}
sl@0
   103
sl@0
   104
// Symbian-specific addition.
sl@0
   105
EXPORT_C void* operator new(std::size_t a_size, std::size_t a_extra_size) __NO_THROW
sl@0
   106
	{
sl@0
   107
	return User::Alloc(a_size + a_extra_size);
sl@0
   108
	}
sl@0
   109
sl@0
   110
#ifdef __EABI__
sl@0
   111
//TODO: MOVE to another file
sl@0
   112
EXPORT_C std::bad_alloc::bad_alloc() __NO_THROW 
sl@0
   113
	{}
sl@0
   114
EXPORT_C std::bad_alloc::bad_alloc(const std::bad_alloc&) __NO_THROW
sl@0
   115
	{}
sl@0
   116
EXPORT_C std::bad_alloc& std::bad_alloc::operator=(const std::bad_alloc&) __NO_THROW
sl@0
   117
	{ return *this;}
sl@0
   118
EXPORT_C std::bad_alloc::~bad_alloc() __NO_THROW
sl@0
   119
	{}
sl@0
   120
EXPORT_C const char* std::bad_alloc::what() const __NO_THROW
sl@0
   121
    { return "bad_alloc";}
sl@0
   122
#endif  // __EABI__
sl@0
   123
sl@0
   124
#endif // __SYMBIAN_STDCPP_SUPPORT__