• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 ******************************************************************************
3 *
4 *   Copyright (C) 2002-2005, 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 
operator new(size_t size)59 void * U_EXPORT2 UMemory::operator new(size_t size) {
60     return uprv_malloc(size);
61 }
62 
operator delete(void * p)63 void U_EXPORT2 UMemory::operator delete(void *p) {
64     if(p!=NULL) {
65         uprv_free(p);
66     }
67 }
68 
operator new[](size_t size)69 void * U_EXPORT2 UMemory::operator new[](size_t size) {
70     return uprv_malloc(size);
71 }
72 
operator delete[](void * p)73 void U_EXPORT2 UMemory::operator delete[](void *p) {
74     if(p!=NULL) {
75         uprv_free(p);
76     }
77 }
78 
79 #if U_HAVE_DEBUG_LOCATION_NEW
operator new(size_t size,const char *,int)80 void * U_EXPORT2 UMemory::operator new(size_t size, const char* /*file*/, int /*line*/) {
81     return UMemory::operator new(size);
82 }
83 
operator delete(void * p,const char *,int)84 void U_EXPORT2 UMemory::operator delete(void* p, const char* /*file*/, int /*line*/) {
85     UMemory::operator delete(p);
86 }
87 #endif /* U_HAVE_DEBUG_LOCATION_NEW */
88 
89 
90 #endif
91 
~UObject()92 UObject::~UObject() {}
93 
94 // Future implementation for RTTI that support subtyping. [alan]
95 //
96 // UClassID UObject::getStaticClassID() {
97 //     return (UClassID) NULL;
98 // }
99 //
100 // UBool UObject::instanceOf(UClassID type) const {
101 //     UClassID c = getDynamicClassID();
102 //     for (;;) {
103 //         if (c == type) {
104 //             return TRUE;
105 //         } else if (c == (UClassID) NULL) {
106 //             return FALSE;
107 //         }
108 //         c = * (UClassID*) c;
109 //     }
110 // }
111 
112 U_NAMESPACE_END
113 
114 
115