1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/uobject.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* 1.5 +****************************************************************************** 1.6 +* 1.7 +* Copyright (C) 2002-2012, International Business Machines 1.8 +* Corporation and others. All Rights Reserved. 1.9 +* 1.10 +****************************************************************************** 1.11 +* file name: uobject.h 1.12 +* encoding: US-ASCII 1.13 +* tab size: 8 (not used) 1.14 +* indentation:4 1.15 +* 1.16 +* created on: 2002jun26 1.17 +* created by: Markus W. Scherer 1.18 +*/ 1.19 + 1.20 +#include "unicode/uobject.h" 1.21 +#include "cmemory.h" 1.22 + 1.23 +U_NAMESPACE_BEGIN 1.24 + 1.25 +#if U_OVERRIDE_CXX_ALLOCATION 1.26 + 1.27 +/* 1.28 + * Default implementation of UMemory::new/delete 1.29 + * using uprv_malloc() and uprv_free(). 1.30 + * 1.31 + * For testing, this is used together with a list of imported symbols to verify 1.32 + * that ICU is not using the global ::new and ::delete operators. 1.33 + * 1.34 + * These operators can be implemented like this or any other appropriate way 1.35 + * when customizing ICU for certain environments. 1.36 + * Whenever ICU is customized in binary incompatible ways please be sure 1.37 + * to use library name suffixes to distinguish such libraries from 1.38 + * the standard build. 1.39 + * 1.40 + * Instead of just modifying these C++ new/delete operators, it is usually best 1.41 + * to modify the uprv_malloc()/uprv_free()/uprv_realloc() functions in cmemory.c. 1.42 + * 1.43 + * Memory test on Windows/MSVC 6: 1.44 + * The global operators new and delete look as follows: 1.45 + * 04F 00000000 UNDEF notype () External | ??2@YAPAXI@Z (void * __cdecl operator new(unsigned int)) 1.46 + * 03F 00000000 UNDEF notype () External | ??3@YAXPAX@Z (void __cdecl operator delete(void *)) 1.47 + * 1.48 + * These lines are from output generated by the MSVC 6 tool dumpbin with 1.49 + * dumpbin /symbols *.obj 1.50 + * 1.51 + * ??2@YAPAXI@Z and ??3@YAXPAX@Z are the linker symbols in the .obj 1.52 + * files and are imported from msvcrtd.dll (in a debug build). 1.53 + * 1.54 + * Make sure that with the UMemory operators new and delete defined these two symbols 1.55 + * do not appear in the dumpbin /symbols output for the ICU libraries! 1.56 + * 1.57 + * If such a symbol appears in the output then look in the preceding lines in the output 1.58 + * for which file and function calls the global new or delete operator, 1.59 + * and replace with uprv_malloc/uprv_free. 1.60 + */ 1.61 + 1.62 +void * U_EXPORT2 UMemory::operator new(size_t size) U_NO_THROW { 1.63 + return uprv_malloc(size); 1.64 +} 1.65 + 1.66 +void U_EXPORT2 UMemory::operator delete(void *p) U_NO_THROW { 1.67 + if(p!=NULL) { 1.68 + uprv_free(p); 1.69 + } 1.70 +} 1.71 + 1.72 +void * U_EXPORT2 UMemory::operator new[](size_t size) U_NO_THROW { 1.73 + return uprv_malloc(size); 1.74 +} 1.75 + 1.76 +void U_EXPORT2 UMemory::operator delete[](void *p) U_NO_THROW { 1.77 + if(p!=NULL) { 1.78 + uprv_free(p); 1.79 + } 1.80 +} 1.81 + 1.82 +#if U_HAVE_DEBUG_LOCATION_NEW 1.83 +void * U_EXPORT2 UMemory::operator new(size_t size, const char* /*file*/, int /*line*/) U_NO_THROW { 1.84 + return UMemory::operator new(size); 1.85 +} 1.86 + 1.87 +void U_EXPORT2 UMemory::operator delete(void* p, const char* /*file*/, int /*line*/) U_NO_THROW { 1.88 + UMemory::operator delete(p); 1.89 +} 1.90 +#endif /* U_HAVE_DEBUG_LOCATION_NEW */ 1.91 + 1.92 + 1.93 +#endif 1.94 + 1.95 +UObject::~UObject() {} 1.96 + 1.97 +UClassID UObject::getDynamicClassID() const { return NULL; } 1.98 + 1.99 +U_NAMESPACE_END 1.100 + 1.101 +U_NAMESPACE_USE 1.102 + 1.103 +U_CAPI void U_EXPORT2 1.104 +uprv_deleteUObject(void *obj) { 1.105 + delete static_cast<UObject *>(obj); 1.106 +}