VirtualBox

Ignore:
Timestamp:
Nov 6, 2023 11:09:45 AM (14 months ago)
Author:
vboxsync
Message:

libs/xpcom: Get rid of nsMemoryImpl.{cpp,h} and nsIMemory and repalce it with direct calls to RTMem* APIs, bugref:10545

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/xpcom/glue/nsMemory.cpp

    r5522 r101852  
    3636 * ***** END LICENSE BLOCK ***** */
    3737
    38 #include "nsXPCOM.h"
    3938#include "nsMemory.h"
    40 #include "nsXPCOMPrivate.h"
    4139
    42 static nsIMemory* gMemory = nsnull;
    43 
    44 static NS_METHOD FreeGlobalMemory(void)
    45 {
    46     NS_ASSERTION(gMemory, "must be not null after SetupGlobalMemory");
    47     NS_IF_RELEASE(gMemory);
    48     return NS_OK;
    49 }
    50 
    51 #define ENSURE_ALLOCATOR \
    52   (gMemory ? PR_TRUE : (PRBool)(SetupGlobalMemory() != nsnull))
    53 
    54 static nsIMemory*
    55 SetupGlobalMemory()
    56 {
    57     NS_ASSERTION(!gMemory, "must be called once");
    58     if (!gMemory)
    59     {
    60         NS_GetMemoryManager(&gMemory);
    61         NS_ASSERTION(gMemory, "can't get memory manager!");
    62         if (gMemory)
    63             NS_RegisterXPCOMExitRoutine(FreeGlobalMemory, 0);
    64     }
    65     return gMemory;
    66 }
    67 
    68 #ifdef XPCOM_GLUE
    69 nsresult GlueStartupMemory()
    70 {
    71     NS_ASSERTION(!gMemory, "must be called once");
    72     if (!gMemory)
    73     {
    74         NS_GetMemoryManager(&gMemory);
    75         NS_ASSERTION(gMemory, "can't get memory manager!");
    76         if (!gMemory)
    77             return NS_ERROR_FAILURE;
    78     }
    79     return NS_OK;
    80 }
    81 
    82 void GlueShutdownMemory()
    83 {
    84     NS_IF_RELEASE(gMemory);
    85 }
    86 #endif
     40#include <iprt/mem.h>
    8741
    8842////////////////////////////////////////////////////////////////////////////////
     
    9246nsMemory::Alloc(PRSize size)
    9347{
    94     if (!ENSURE_ALLOCATOR)
    95         return nsnull;
    96  
    97    return gMemory->Alloc(size);
     48    return RTMemAlloc(size);
    9849}
    9950
     
    10152nsMemory::Realloc(void* ptr, PRSize size)
    10253{
    103     if (!ENSURE_ALLOCATOR)
    104         return nsnull;   
    105 
    106     return gMemory->Realloc(ptr, size);
     54    return RTMemRealloc(ptr, size);
    10755}
    10856
     
    11058nsMemory::Free(void* ptr)
    11159{
    112     if (!ENSURE_ALLOCATOR)
    113         return;   
    114 
    115     gMemory->Free(ptr);
    116 }
    117 
    118 NS_COM nsresult
    119 nsMemory::HeapMinimize(PRBool aImmediate)
    120 {
    121     if (!ENSURE_ALLOCATOR)
    122         return NS_ERROR_FAILURE;   
    123 
    124     return gMemory->HeapMinimize(aImmediate);
     60    RTMemFree(ptr);
    12561}
    12662
     
    12864nsMemory::Clone(const void* ptr, PRSize size)
    12965{
    130     if (!ENSURE_ALLOCATOR)
    131         return nsnull;   
    132 
    133     void* newPtr = gMemory->Alloc(size);
    134     if (newPtr)
    135         memcpy(newPtr, ptr, size);
    136     return newPtr;
    137 }
    138 
    139 NS_COM nsIMemory*
    140 nsMemory::GetGlobalMemoryService()
    141 {
    142     if (!ENSURE_ALLOCATOR)
    143         return nsnull;   
    144    
    145     nsIMemory* result = gMemory;
    146     NS_IF_ADDREF(result);
    147     return result;
     66    return RTMemDup(ptr, size);
    14867}
    14968
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette