stdcpp/src/libstd_cpp_init.cpp
changeset 0 e4d67989cc36
child 22 ddc455616bd6
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 # include "stlport_prefix.h"
       
    20 #include <e32base.h>
       
    21 #include <e32err.h>
       
    22 //#include <typeinfo.h>
       
    23 #include <memory>
       
    24 
       
    25 #include "libstdcppwsd.h"
       
    26 #ifdef __WINSCW__
       
    27 #include <pls.h>
       
    28 const TUid KLibstdcppUID = {0x10282872};
       
    29 #endif
       
    30 
       
    31 #ifdef	__WINSCW__
       
    32 #ifdef __cplusplus
       
    33 extern "C" {
       
    34 #endif
       
    35 #ifdef __cplusplus
       
    36 }	// extern "C"
       
    37 #endif
       
    38 #include <e32std.h>
       
    39 #endif //__WINSCW__
       
    40 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
    41 #include "sysif.h"
       
    42 #endif
       
    43 
       
    44 
       
    45 
       
    46 
       
    47 _STLP_BEGIN_NAMESPACE
       
    48 
       
    49 void CallIosInit();
       
    50 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
    51 extern void CallCloseStdLib();
       
    52 #endif
       
    53 
       
    54 _STLP_EXP_DECLSPEC void LibStdCppInit()
       
    55     {
       
    56 	//Create Cleanup Stack
       
    57 	CTrapCleanup* pCleanup = CTrapCleanup::New();
       
    58 
       
    59 	if( pCleanup )
       
    60 		{
       
    61 		CallIosInit();
       
    62 		delete pCleanup;
       
    63 		}
       
    64     }
       
    65 
       
    66 #if 0
       
    67 _STLP_EXP_DECLSPEC type_info::~type_info () {}
       
    68 
       
    69 
       
    70 _STLP_EXP_DECLSPEC bad_cast::~bad_cast() throw() { }
       
    71 
       
    72 _STLP_EXP_DECLSPEC bad_typeid::~bad_typeid() throw() { }
       
    73     
       
    74 
       
    75 // return true if this is a type_info for a pointer type
       
    76 _STLP_EXP_DECLSPEC bool type_info::__is_pointer_p () const
       
    77 {
       
    78   return false;
       
    79 }
       
    80 
       
    81 _STLP_EXP_DECLSPEC bool type_info::__is_function_p () const
       
    82 {
       
    83   return false;
       
    84 }
       
    85 
       
    86 _STLP_EXP_DECLSPEC bool type_info::__do_catch (const type_info *thr_type, void **, unsigned) const
       
    87 {
       
    88   return *this == *thr_type;
       
    89 }
       
    90 
       
    91 #endif
       
    92 
       
    93 
       
    94 _STLP_EXP_DECLSPEC new_handler set_new_handler(new_handler pnew) __NO_THROW
       
    95 {
       
    96     new_handler& phandler = get_new_handler();
       
    97     new_handler phold = phandler;
       
    98     phandler = pnew;
       
    99     return phold;
       
   100 }
       
   101 
       
   102 _STLP_END_NAMESPACE
       
   103 
       
   104 using namespace std;
       
   105 
       
   106 int
       
   107 init_libcpp_wsdvar(_Libcpp_wsd* g_libcpp_wsd)
       
   108 {
       
   109 	g_libcpp_wsd->is_Initialized = false;
       
   110 	return KErrNone;
       
   111 }
       
   112 
       
   113 #ifdef __WINSCW__
       
   114 void* GetGlobalTlsData()
       
   115     {
       
   116     return Pls<_Libcpp_wsd>(KLibstdcppUID, &init_libcpp_wsdvar);
       
   117     }
       
   118 
       
   119 void SetGlobalTlsData(void* aData)
       
   120     {
       
   121     SetPls(aData, KLibstdcppUID);
       
   122     }
       
   123 #endif
       
   124 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   125 void* SetBackendHeap()
       
   126 {
       
   127 
       
   128 	RHeap* oldHeap = User::SwitchHeap( Backend()->Heap() ); // From now, new allocates memory form backend heap
       
   129 	
       
   130 	return (void*)oldHeap;
       
   131 	
       
   132 }
       
   133 
       
   134 void ReSetUserHeap(void* oldHeap)
       
   135 {
       
   136 	
       
   137 	User::SwitchHeap( (RHeap*)oldHeap);
       
   138 }
       
   139 
       
   140 
       
   141 #endif
       
   142 
       
   143 
       
   144 
       
   145 _STLP_EXP_DECLSPEC void CloseStdLibCpp()
       
   146     {
       
   147 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   148     std::CallCloseStdLib();
       
   149 #endif
       
   150     }
       
   151 
       
   152 
       
   153 
       
   154 
       
   155 _STLP_EXP_DECLSPEC void *operator new(unsigned int aSize)
       
   156 	{
       
   157 	void* __y;
       
   158 
       
   159 	__y = _STLP_NEW(aSize);
       
   160 
       
   161 	if (__y == 0)
       
   162 	    {
       
   163 	    new_handler& phandler = get_new_handler();
       
   164 	    if(phandler == NULL)
       
   165 	        _STLP_THROW(bad_alloc());
       
   166 	    else
       
   167 	      phandler();
       
   168 	    }
       
   169     return __y;
       
   170 	}
       
   171 
       
   172 _STLP_EXP_DECLSPEC void *operator new[](unsigned int aSize)
       
   173     {
       
   174     return ::operator new(aSize);
       
   175     }
       
   176 
       
   177 _STLP_EXP_DECLSPEC void operator delete(void* aPtr) __NO_THROW
       
   178     {
       
   179 
       
   180     ::free(aPtr);
       
   181 
       
   182     }
       
   183 
       
   184 _STLP_EXP_DECLSPEC void operator delete[](void* aPtr) __NO_THROW
       
   185     {
       
   186     ::operator delete(aPtr);
       
   187     }
       
   188 
       
   189 _STLP_EXP_DECLSPEC void* operator new(unsigned int aSize, const std::nothrow_t& /*aNoThrow*/) __NO_THROW
       
   190     { 
       
   191 	void* __y = _STLP_NEW(aSize);
       
   192 	if (__y == 0)
       
   193 	    {
       
   194 	    new_handler& phandler = get_new_handler();
       
   195 	    if(phandler != NULL)
       
   196 	      phandler();
       
   197 	    }
       
   198     return __y;
       
   199     }
       
   200 
       
   201 _STLP_EXP_DECLSPEC void* operator new[](unsigned int aSize, const std::nothrow_t& aNoThrow) __NO_THROW
       
   202     { 
       
   203     return operator new (aSize, aNoThrow); 
       
   204     }
       
   205 
       
   206 _STLP_EXP_DECLSPEC void operator delete(void* aPtr, const std::nothrow_t& /*aNoThrow*/) __NO_THROW
       
   207     {
       
   208     operator delete(aPtr);
       
   209     }
       
   210 
       
   211 _STLP_EXP_DECLSPEC void operator delete[](void* aPtr, const std::nothrow_t& /*aNoThrow*/) __NO_THROW
       
   212     {
       
   213     operator delete(aPtr);
       
   214     }
       
   215 
       
   216 
       
   217 // end of file