2002-06-27 01:37:52 +00:00
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
2012-08-08 00:50:16 +00:00
|
|
|
* Copyright (C) 2002-2012, International Business Machines
|
2002-06-27 01:37:52 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
* file name: uobject.h
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2002jun26
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/uobject.h"
|
2002-07-30 07:42:00 +00:00
|
|
|
#include "cmemory.h"
|
2002-06-27 01:37:52 +00:00
|
|
|
|
2002-07-30 07:42:00 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
2002-07-16 15:47:46 +00:00
|
|
|
|
2003-09-18 17:19:30 +00:00
|
|
|
#if U_OVERRIDE_CXX_ALLOCATION
|
|
|
|
|
2002-07-16 15:47:46 +00:00
|
|
|
/*
|
2002-10-03 01:13:01 +00:00
|
|
|
* Default implementation of UMemory::new/delete
|
2002-07-16 15:47:46 +00:00
|
|
|
* using uprv_malloc() and uprv_free().
|
2002-10-03 01:13:01 +00:00
|
|
|
*
|
|
|
|
* For testing, this is used together with a list of imported symbols to verify
|
2002-07-16 15:47:46 +00:00
|
|
|
* that ICU is not using the global ::new and ::delete operators.
|
|
|
|
*
|
|
|
|
* These operators can be implemented like this or any other appropriate way
|
|
|
|
* when customizing ICU for certain environments.
|
|
|
|
* Whenever ICU is customized in binary incompatible ways please be sure
|
|
|
|
* to use library name suffixes to distinguish such libraries from
|
|
|
|
* the standard build.
|
|
|
|
*
|
2002-10-03 01:13:01 +00:00
|
|
|
* Instead of just modifying these C++ new/delete operators, it is usually best
|
|
|
|
* to modify the uprv_malloc()/uprv_free()/uprv_realloc() functions in cmemory.c.
|
|
|
|
*
|
2002-07-16 15:47:46 +00:00
|
|
|
* Memory test on Windows/MSVC 6:
|
|
|
|
* The global operators new and delete look as follows:
|
2002-07-16 15:56:35 +00:00
|
|
|
* 04F 00000000 UNDEF notype () External | ??2@YAPAXI@Z (void * __cdecl operator new(unsigned int))
|
2002-07-16 15:47:46 +00:00
|
|
|
* 03F 00000000 UNDEF notype () External | ??3@YAXPAX@Z (void __cdecl operator delete(void *))
|
|
|
|
*
|
|
|
|
* These lines are from output generated by the MSVC 6 tool dumpbin with
|
|
|
|
* dumpbin /symbols *.obj
|
|
|
|
*
|
2002-07-16 15:56:35 +00:00
|
|
|
* ??2@YAPAXI@Z and ??3@YAXPAX@Z are the linker symbols in the .obj
|
2002-07-16 15:47:46 +00:00
|
|
|
* files and are imported from msvcrtd.dll (in a debug build).
|
|
|
|
*
|
2002-10-03 01:13:01 +00:00
|
|
|
* Make sure that with the UMemory operators new and delete defined these two symbols
|
2002-07-16 15:47:46 +00:00
|
|
|
* do not appear in the dumpbin /symbols output for the ICU libraries!
|
|
|
|
*
|
|
|
|
* If such a symbol appears in the output then look in the preceding lines in the output
|
|
|
|
* for which file and function calls the global new or delete operator,
|
|
|
|
* and replace with uprv_malloc/uprv_free.
|
|
|
|
*/
|
|
|
|
|
2008-10-07 15:40:37 +00:00
|
|
|
void * U_EXPORT2 UMemory::operator new(size_t size) U_NO_THROW {
|
2002-07-16 15:47:46 +00:00
|
|
|
return uprv_malloc(size);
|
|
|
|
}
|
|
|
|
|
2008-10-07 15:40:37 +00:00
|
|
|
void U_EXPORT2 UMemory::operator delete(void *p) U_NO_THROW {
|
2002-07-16 15:47:46 +00:00
|
|
|
if(p!=NULL) {
|
|
|
|
uprv_free(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-07 15:40:37 +00:00
|
|
|
void * U_EXPORT2 UMemory::operator new[](size_t size) U_NO_THROW {
|
2002-07-30 01:42:26 +00:00
|
|
|
return uprv_malloc(size);
|
|
|
|
}
|
|
|
|
|
2008-10-07 15:40:37 +00:00
|
|
|
void U_EXPORT2 UMemory::operator delete[](void *p) U_NO_THROW {
|
2002-07-16 15:47:46 +00:00
|
|
|
if(p!=NULL) {
|
|
|
|
uprv_free(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-15 04:07:47 +00:00
|
|
|
#if U_HAVE_DEBUG_LOCATION_NEW
|
2008-10-07 15:40:37 +00:00
|
|
|
void * U_EXPORT2 UMemory::operator new(size_t size, const char* /*file*/, int /*line*/) U_NO_THROW {
|
2005-06-15 04:07:47 +00:00
|
|
|
return UMemory::operator new(size);
|
|
|
|
}
|
|
|
|
|
2008-10-07 15:40:37 +00:00
|
|
|
void U_EXPORT2 UMemory::operator delete(void* p, const char* /*file*/, int /*line*/) U_NO_THROW {
|
2005-06-15 04:07:47 +00:00
|
|
|
UMemory::operator delete(p);
|
|
|
|
}
|
|
|
|
#endif /* U_HAVE_DEBUG_LOCATION_NEW */
|
|
|
|
|
|
|
|
|
2003-09-18 17:19:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
UObject::~UObject() {}
|
|
|
|
|
2004-04-22 19:08:22 +00:00
|
|
|
// Future implementation for RTTI that support subtyping. [alan]
|
|
|
|
//
|
|
|
|
// UClassID UObject::getStaticClassID() {
|
|
|
|
// return (UClassID) NULL;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// UBool UObject::instanceOf(UClassID type) const {
|
|
|
|
// UClassID c = getDynamicClassID();
|
|
|
|
// for (;;) {
|
|
|
|
// if (c == type) {
|
|
|
|
// return TRUE;
|
|
|
|
// } else if (c == (UClassID) NULL) {
|
|
|
|
// return FALSE;
|
|
|
|
// }
|
|
|
|
// c = * (UClassID*) c;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2002-07-30 07:42:00 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2011-06-03 05:23:57 +00:00
|
|
|
U_NAMESPACE_USE
|
2002-07-16 15:47:46 +00:00
|
|
|
|
2011-06-03 05:23:57 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
uprv_deleteUObject(void *obj) {
|
2012-08-08 00:50:16 +00:00
|
|
|
delete static_cast<UObject *>(obj);
|
2011-06-03 05:23:57 +00:00
|
|
|
}
|