Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Name : stdcpp_support.cpp
15 // Part of : standard c++ library.
20 #include <stdcpp_support.h>
26 EXPORT_C void TranslateSymErrorToCppException(TInt aError)
31 // This is about to use the emergency buffer!
32 __THROW(std::bad_alloc());
34 __THROW(std::invalid_argument("Invalid argument"));
36 __THROW(std::overflow_error("Overflow error"));
38 __THROW(std::underflow_error("Underflow error"));
40 __THROW(Symbian_error(KErrGeneral));
44 EXPORT_C TInt TranslateCppExceptionToSymError(const std::exception& aThrow)
47 const std::type_info& atype = typeid(aThrow);
49 if(atype == typeid (std::bad_alloc))
51 else if(atype == typeid(std::invalid_argument))
53 else if(atype == typeid(std::out_of_range))
54 // std::out_of_range is of type logic_error which by definition means that it is
55 // "presumably detectable before the program executes".
56 // std::out_of_range is used to report an argument is not within the expected range.
57 // The description of KErrArgument says an argument is out of range. Hence the mapping.
59 else if(atype == typeid(std::overflow_error))
61 else if(atype == typeid(std::underflow_error))
72 * The StdC++ global new and delete operators defined here. They are done only for the emulator
73 * as for EABI platforms, it is part of the runtime support(i.e., stdnew.dll).
77 EXPORT_C const std::nothrow_t std::nothrow;
79 EXPORT_C void* operator new(std::size_t a_size) __THROW(std::bad_alloc)
83 void* p = User::Alloc(a_size);
89 std::new_handler nh_func ;
90 std::new_handler *ptr = reinterpret_cast<std::new_handler*>(Dll::Tls());
91 nh_func = (ptr)?(*ptr):NULL;
99 __THROW(std::bad_alloc());
104 EXPORT_C void* operator new[](std::size_t a_size) __THROW(std::bad_alloc)
106 return ::operator new(a_size);
109 EXPORT_C void* operator new(std::size_t a_size, const std::nothrow_t&) __NO_THROW
113 void* p = User::Alloc(a_size);
120 std::new_handler nh_func ;
121 std::new_handler *ptr = reinterpret_cast<std::new_handler*>(Dll::Tls());
122 nh_func = (ptr)?(*ptr):NULL;
142 EXPORT_C void* operator new[](std::size_t a_size, const std::nothrow_t) __NO_THROW
144 return ::operator new(a_size, std::nothrow);
147 // Symbian-specific addition.
148 EXPORT_C void* operator new(std::size_t a_size, std::size_t a_extra_size) __NO_THROW
150 return ::operator new(a_size + a_extra_size, std::nothrow);
153 EXPORT_C void operator delete(void* p) __NO_THROW
158 EXPORT_C void operator delete(void* p, const std::nothrow_t&) __NO_THROW
163 EXPORT_C void operator delete[](void* p) __NO_THROW
168 EXPORT_C void operator delete[](void* p, const std::nothrow_t&) __NO_THROW
173 // Symbian-specific addition.
174 EXPORT_C void operator delete(void* p, std::size_t) __NO_THROW
178 _LIT(K,"set_new_handler");
181 using std::new_handler;
183 EXPORT_C new_handler std::set_new_handler(new_handler a_new_nh) __NO_THROW
185 new_handler current_nh;
186 TAny* tls_word_p = Dll::Tls();
190 // This is the first time we're called, so we need to set up the TLS.
192 tls_word_p = User::Alloc( sizeof(new_handler) );
195 User::Panic(K, KErrNoMemory);
198 Dll::SetTls(tls_word_p);
203 // Get the currently installed new_handler function.
204 current_nh = *reinterpret_cast<new_handler*>(tls_word_p);
207 // Set the new new_handler.
208 *reinterpret_cast<new_handler*>(tls_word_p) = a_new_nh;