]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/uobject.cpp
ICU-461.18.tar.gz
[apple/icu.git] / icuSources / common / uobject.cpp
CommitLineData
b75a7d8f
A
1/*
2******************************************************************************
3*
729e4ab9 4* Copyright (C) 2002-2008, International Business Machines
b75a7d8f
A
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"
b75a7d8f
A
18#include "cmemory.h"
19
20U_NAMESPACE_BEGIN
21
374ca955
A
22#if U_OVERRIDE_CXX_ALLOCATION
23
b75a7d8f
A
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
729e4ab9 59void * U_EXPORT2 UMemory::operator new(size_t size) U_NO_THROW {
b75a7d8f
A
60 return uprv_malloc(size);
61}
62
729e4ab9 63void U_EXPORT2 UMemory::operator delete(void *p) U_NO_THROW {
b75a7d8f
A
64 if(p!=NULL) {
65 uprv_free(p);
66 }
67}
68
729e4ab9 69void * U_EXPORT2 UMemory::operator new[](size_t size) U_NO_THROW {
b75a7d8f
A
70 return uprv_malloc(size);
71}
72
729e4ab9 73void U_EXPORT2 UMemory::operator delete[](void *p) U_NO_THROW {
b75a7d8f
A
74 if(p!=NULL) {
75 uprv_free(p);
76 }
77}
78
73c04bcf 79#if U_HAVE_DEBUG_LOCATION_NEW
729e4ab9 80void * U_EXPORT2 UMemory::operator new(size_t size, const char* /*file*/, int /*line*/) U_NO_THROW {
73c04bcf
A
81 return UMemory::operator new(size);
82}
83
729e4ab9 84void U_EXPORT2 UMemory::operator delete(void* p, const char* /*file*/, int /*line*/) U_NO_THROW {
73c04bcf
A
85 UMemory::operator delete(p);
86}
87#endif /* U_HAVE_DEBUG_LOCATION_NEW */
88
89
374ca955
A
90#endif
91
92UObject::~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
b75a7d8f
A
112U_NAMESPACE_END
113
b75a7d8f 114