os/ossrv/genericopenlibs/cppstdlib/src/set_new_handler.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Name        : new_handler.cpp
    15 // Part of     : libstdcpp
    16 // Adaptation layer to get locale functionality.
    17 // Version     : 
    18 // This material, including documentation and any related 
    19 // computer programs, is protected by copyright controlled by 
    20 // Nokia Corporation. All rights are reserved. Copying, 
    21 // including reproducing, storing, adapting or translating, any 
    22 // or all of this material requires the prior written consent of 
    23 // Nokia Corporation. This material also contains confidential 
    24 // information which may not be disclosed to others without the 
    25 // prior written consent of Nokia Corporation.
    26 //
    27 
    28 
    29 
    30 #include "new"
    31 #include <e32std.h>
    32 
    33 _LIT(K,"set_new_handler");
    34 
    35 
    36 using std::new_handler;
    37 
    38 #ifdef __SYMBIAN_STDCPP_SUPPORT__ 
    39 
    40 EXPORT_C new_handler std::set_new_handler(new_handler a_new_nh) __NO_THROW
    41 	{
    42 	new_handler current_nh;
    43 	TAny* tls_word_p = Dll::Tls();
    44 
    45 	if (!tls_word_p)
    46 		{
    47 		// This is the first time we're called, so we need to set up the TLS.
    48 
    49 		tls_word_p = User::Alloc( sizeof(new_handler) );
    50 		if ( !tls_word_p )
    51 			{
    52 			User::Panic(K, KErrNoMemory);
    53 			}
    54 
    55 		Dll::SetTls(tls_word_p);
    56 		current_nh = 0;
    57 		}
    58 	else
    59 		{
    60 		// Get the currently installed new_handler function.
    61 		current_nh = *reinterpret_cast<new_handler*>(tls_word_p);
    62 		}
    63 	
    64 	// Set the new new_handler.
    65 	*reinterpret_cast<new_handler*>(tls_word_p) = a_new_nh;
    66 
    67 	return current_nh;
    68 	}
    69 
    70 #endif // __SYMBIAN_STDCPP_SUPPORT__