tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

uobject.cpp (3257B)


      1 // © 2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html
      3 /*
      4 ******************************************************************************
      5 *
      6 *   Copyright (C) 2002-2012, International Business Machines
      7 *   Corporation and others.  All Rights Reserved.
      8 *
      9 ******************************************************************************
     10 *   file name:  uobject.h
     11 *   encoding:   UTF-8
     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"
     20 #include "cmemory.h"
     21 
     22 U_NAMESPACE_BEGIN
     23 
     24 #if U_OVERRIDE_CXX_ALLOCATION
     25 
     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 
     61 void * U_EXPORT2 UMemory::operator new(size_t size) noexcept {
     62    return uprv_malloc(size);
     63 }
     64 
     65 void U_EXPORT2 UMemory::operator delete(void *p) noexcept {
     66    if(p!=nullptr) {
     67        uprv_free(p);
     68    }
     69 }
     70 
     71 void * U_EXPORT2 UMemory::operator new[](size_t size) noexcept {
     72    return uprv_malloc(size);
     73 }
     74 
     75 void U_EXPORT2 UMemory::operator delete[](void *p) noexcept {
     76    if(p!=nullptr) {
     77        uprv_free(p);
     78    }
     79 }
     80 
     81 #if U_HAVE_DEBUG_LOCATION_NEW
     82 void * U_EXPORT2 UMemory::operator new(size_t size, const char* /*file*/, int /*line*/) noexcept {
     83    return UMemory::operator new(size);
     84 }
     85 
     86 void U_EXPORT2 UMemory::operator delete(void* p, const char* /*file*/, int /*line*/) noexcept {
     87    UMemory::operator delete(p);
     88 }
     89 #endif /* U_HAVE_DEBUG_LOCATION_NEW */
     90 
     91 
     92 #endif
     93 
     94 UObject::~UObject() {}
     95 
     96 UClassID UObject::getDynamicClassID() const { return nullptr; }
     97 
     98 U_NAMESPACE_END
     99 
    100 U_NAMESPACE_USE
    101 
    102 U_CAPI void U_EXPORT2
    103 uprv_deleteUObject(void *obj) {
    104    delete static_cast<UObject *>(obj);
    105 }