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