Home | History | Annotate | Download | only in common
      1 /*
      2 ******************************************************************************
      3 *
      4 *   Copyright (C) 2002-2012, International Business Machines
      5 *   Corporation and others.  All Rights Reserved.
      6 *
      7 ******************************************************************************
      8 *   file name:  uobject.h
      9 *   encoding:   US-ASCII
     10 *   tab size:   8 (not used)
     11 *   indentation:4
     12 *
     13 *   created on: 2002jun26
     14 *   created by: Markus W. Scherer
     15 */
     16 
     17 #include "unicode/uobject.h"
     18 #include "cmemory.h"
     19 
     20 U_NAMESPACE_BEGIN
     21 
     22 #if U_OVERRIDE_CXX_ALLOCATION
     23 
     24 /*
     25  * Default implementation of UMemory::new/delete
     26  * using uprv_malloc() and uprv_free().
     27  *
     28  * For testing, this is used together with a list of imported symbols to verify
     29  * that ICU is not using the global ::new and ::delete operators.
     30  *
     31  * These operators can be implemented like this or any other appropriate way
     32  * when customizing ICU for certain environments.
     33  * Whenever ICU is customized in binary incompatible ways please be sure
     34  * to use library name suffixes to distinguish such libraries from
     35  * the standard build.
     36  *
     37  * Instead of just modifying these C++ new/delete operators, it is usually best
     38  * to modify the uprv_malloc()/uprv_free()/uprv_realloc() functions in cmemory.c.
     39  *
     40  * Memory test on Windows/MSVC 6:
     41  * The global operators new and delete look as follows:
     42  *   04F 00000000 UNDEF  notype ()    External     | ??2@YAPAXI@Z (void * __cdecl operator new(unsigned int))
     43  *   03F 00000000 UNDEF  notype ()    External     | ??3@YAXPAX@Z (void __cdecl operator delete(void *))
     44  *
     45  * These lines are from output generated by the MSVC 6 tool dumpbin with
     46  * dumpbin /symbols *.obj
     47  *
     48  * ??2@YAPAXI@Z and ??3@YAXPAX@Z are the linker symbols in the .obj
     49  * files and are imported from msvcrtd.dll (in a debug build).
     50  *
     51  * Make sure that with the UMemory operators new and delete defined these two symbols
     52  * do not appear in the dumpbin /symbols output for the ICU libraries!
     53  *
     54  * If such a symbol appears in the output then look in the preceding lines in the output
     55  * for which file and function calls the global new or delete operator,
     56  * and replace with uprv_malloc/uprv_free.
     57  */
     58 
     59 void * U_EXPORT2 UMemory::operator new(size_t size) U_NO_THROW {
     60     return uprv_malloc(size);
     61 }
     62 
     63 void U_EXPORT2 UMemory::operator delete(void *p) U_NO_THROW {
     64     if(p!=NULL) {
     65         uprv_free(p);
     66     }
     67 }
     68 
     69 void * U_EXPORT2 UMemory::operator new[](size_t size) U_NO_THROW {
     70     return uprv_malloc(size);
     71 }
     72 
     73 void U_EXPORT2 UMemory::operator delete[](void *p) U_NO_THROW {
     74     if(p!=NULL) {
     75         uprv_free(p);
     76     }
     77 }
     78 
     79 #if U_HAVE_DEBUG_LOCATION_NEW
     80 void * U_EXPORT2 UMemory::operator new(size_t size, const char* /*file*/, int /*line*/) U_NO_THROW {
     81     return UMemory::operator new(size);
     82 }
     83 
     84 void U_EXPORT2 UMemory::operator delete(void* p, const char* /*file*/, int /*line*/) U_NO_THROW {
     85     UMemory::operator delete(p);
     86 }
     87 #endif /* U_HAVE_DEBUG_LOCATION_NEW */
     88 
     89 
     90 #endif
     91 
     92 UObject::~UObject() {}
     93 
     94 UClassID UObject::getDynamicClassID() const { return NULL; }
     95 
     96 U_NAMESPACE_END
     97 
     98 U_NAMESPACE_USE
     99 
    100 U_CAPI void U_EXPORT2
    101 uprv_deleteUObject(void *obj) {
    102     delete static_cast<UObject *>(obj);
    103 }
    104