mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-04 04:58:00 +00:00
Moved nsIMalloc and impl from xpcom.
This commit is contained in:
parent
234fdfae3c
commit
6e7ac8e7be
@ -26,7 +26,7 @@ EXPORTS = \
|
||||
nsIJRILiveConnectPlugInstPeer.h \
|
||||
nsILiveConnectPlugin.h \
|
||||
nsILiveConnectPlugInstPeer.h \
|
||||
nsINetworkManager.h \
|
||||
nsIMalloc.h \
|
||||
nsIPlugin.h \
|
||||
nsIPluginInstance.h \
|
||||
nsIPluginInstancePeer.h \
|
||||
|
@ -31,7 +31,7 @@ EXPORTS = \
|
||||
nsIJRILiveConnectPlugInstPeer.h \
|
||||
nsILiveConnectPlugin.h \
|
||||
nsILiveConnectPlugInstPeer.h \
|
||||
nsINetworkManager.h \
|
||||
nsIMalloc.h \
|
||||
nsIPlugin.h \
|
||||
nsIPluginInstance.h \
|
||||
nsIPluginInstancePeer.h \
|
||||
|
@ -28,7 +28,7 @@ EXPORTS = \
|
||||
nsIJRILiveConnectPlugInstPeer.h \
|
||||
nsILiveConnectPlugin.h \
|
||||
nsILiveConnectPlugInstPeer.h \
|
||||
nsINetworkManager.h \
|
||||
nsIMalloc.h \
|
||||
nsIPlugin.h \
|
||||
nsIPluginInstance.h \
|
||||
nsIPluginInstancePeer.h \
|
||||
|
94
modules/plugin/base/public/nsIMalloc.h
Normal file
94
modules/plugin/base/public/nsIMalloc.h
Normal file
@ -0,0 +1,94 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIMalloc_h___
|
||||
#define nsIMalloc_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIMalloc : public nsISupports {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Allocates a block of memory of a particular size.
|
||||
*
|
||||
* @param size - the size of the block to allocate
|
||||
* @result the block of memory
|
||||
*/
|
||||
NS_IMETHOD_(void*)
|
||||
Alloc(PRUint32 size) = 0;
|
||||
|
||||
/**
|
||||
* Reallocates a block of memory to a new size.
|
||||
*
|
||||
* @param ptr - the block of memory to reallocate
|
||||
* @param size - the new size
|
||||
* @result the rellocated block of memory
|
||||
*/
|
||||
NS_IMETHOD_(void*)
|
||||
Realloc(void* ptr, PRUint32 size) = 0;
|
||||
|
||||
/**
|
||||
* Frees a block of memory.
|
||||
*
|
||||
* @param ptr - the block of memory to free
|
||||
*/
|
||||
NS_IMETHOD_(void)
|
||||
Free(void* ptr) = 0;
|
||||
|
||||
/**
|
||||
* Returns the size of a block of memory. Returns -1
|
||||
* if the size is not available.
|
||||
*
|
||||
* @param ptr - the block of memory
|
||||
* @result the size or -1 if not available
|
||||
*/
|
||||
NS_IMETHOD_(PRInt32)
|
||||
GetSize(void* ptr) = 0;
|
||||
|
||||
/**
|
||||
* Returns whether the block of memory was allocated by this
|
||||
* memory allocator. Returns PR_FALSE if this information is
|
||||
* not available.
|
||||
*
|
||||
* @param ptr - the block of memory
|
||||
* @result true if allocated by this nsIMalloc, false if not or
|
||||
* if it can't be determined
|
||||
*/
|
||||
NS_IMETHOD_(PRBool)
|
||||
DidAlloc(void* ptr) = 0;
|
||||
|
||||
/**
|
||||
* Attempts to shrink the heap.
|
||||
*/
|
||||
NS_IMETHOD_(void)
|
||||
HeapMinimize(void) = 0;
|
||||
|
||||
};
|
||||
|
||||
#define NS_IMALLOC_IID \
|
||||
{ /* c4744e60-1875-11d2-815f-006008119d7a */ \
|
||||
0xc4744e60, \
|
||||
0x1875, \
|
||||
0x11d2, \
|
||||
{0x81, 0x5f, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif /* nsIMalloc_h___ */
|
@ -26,7 +26,7 @@ EXPORTS = \
|
||||
nsIJRILiveConnectPlugInstPeer.h \
|
||||
nsILiveConnectPlugin.h \
|
||||
nsILiveConnectPlugInstPeer.h \
|
||||
nsINetworkManager.h \
|
||||
nsIMalloc.h \
|
||||
nsIPlugin.h \
|
||||
nsIPluginInstance.h \
|
||||
nsIPluginInstancePeer.h \
|
||||
|
@ -31,7 +31,7 @@ EXPORTS = \
|
||||
nsIJRILiveConnectPlugInstPeer.h \
|
||||
nsILiveConnectPlugin.h \
|
||||
nsILiveConnectPlugInstPeer.h \
|
||||
nsINetworkManager.h \
|
||||
nsIMalloc.h \
|
||||
nsIPlugin.h \
|
||||
nsIPluginInstance.h \
|
||||
nsIPluginInstancePeer.h \
|
||||
|
@ -28,7 +28,7 @@ EXPORTS = \
|
||||
nsIJRILiveConnectPlugInstPeer.h \
|
||||
nsILiveConnectPlugin.h \
|
||||
nsILiveConnectPlugInstPeer.h \
|
||||
nsINetworkManager.h \
|
||||
nsIMalloc.h \
|
||||
nsIPlugin.h \
|
||||
nsIPluginInstance.h \
|
||||
nsIPluginInstancePeer.h \
|
||||
|
94
modules/plugin/public/nsIMalloc.h
Normal file
94
modules/plugin/public/nsIMalloc.h
Normal file
@ -0,0 +1,94 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIMalloc_h___
|
||||
#define nsIMalloc_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIMalloc : public nsISupports {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Allocates a block of memory of a particular size.
|
||||
*
|
||||
* @param size - the size of the block to allocate
|
||||
* @result the block of memory
|
||||
*/
|
||||
NS_IMETHOD_(void*)
|
||||
Alloc(PRUint32 size) = 0;
|
||||
|
||||
/**
|
||||
* Reallocates a block of memory to a new size.
|
||||
*
|
||||
* @param ptr - the block of memory to reallocate
|
||||
* @param size - the new size
|
||||
* @result the rellocated block of memory
|
||||
*/
|
||||
NS_IMETHOD_(void*)
|
||||
Realloc(void* ptr, PRUint32 size) = 0;
|
||||
|
||||
/**
|
||||
* Frees a block of memory.
|
||||
*
|
||||
* @param ptr - the block of memory to free
|
||||
*/
|
||||
NS_IMETHOD_(void)
|
||||
Free(void* ptr) = 0;
|
||||
|
||||
/**
|
||||
* Returns the size of a block of memory. Returns -1
|
||||
* if the size is not available.
|
||||
*
|
||||
* @param ptr - the block of memory
|
||||
* @result the size or -1 if not available
|
||||
*/
|
||||
NS_IMETHOD_(PRInt32)
|
||||
GetSize(void* ptr) = 0;
|
||||
|
||||
/**
|
||||
* Returns whether the block of memory was allocated by this
|
||||
* memory allocator. Returns PR_FALSE if this information is
|
||||
* not available.
|
||||
*
|
||||
* @param ptr - the block of memory
|
||||
* @result true if allocated by this nsIMalloc, false if not or
|
||||
* if it can't be determined
|
||||
*/
|
||||
NS_IMETHOD_(PRBool)
|
||||
DidAlloc(void* ptr) = 0;
|
||||
|
||||
/**
|
||||
* Attempts to shrink the heap.
|
||||
*/
|
||||
NS_IMETHOD_(void)
|
||||
HeapMinimize(void) = 0;
|
||||
|
||||
};
|
||||
|
||||
#define NS_IMALLOC_IID \
|
||||
{ /* c4744e60-1875-11d2-815f-006008119d7a */ \
|
||||
0xc4744e60, \
|
||||
0x1875, \
|
||||
0x11d2, \
|
||||
{0x81, 0x5f, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif /* nsIMalloc_h___ */
|
@ -22,9 +22,9 @@ LIBRARY_NAME = plug
|
||||
|
||||
CSRCS = npassoc.c
|
||||
|
||||
CPPSRCS = nsplugin.cpp npglue.cpp
|
||||
CPPSRCS = nsplugin.cpp npglue.cpp nsMalloc.cpp
|
||||
|
||||
EXPORTS = nppg.h npglue.h nppriv.h
|
||||
EXPORTS = nppg.h npglue.h nppriv.h nsMalloc.h
|
||||
|
||||
REQUIRES = lay layer js style applet nspr dbm img util java pref xpcom raptor netcnvts plugin plugimpl oji ojiimpl caps
|
||||
|
||||
|
@ -27,9 +27,9 @@ LIBRARY_NAME = plug
|
||||
|
||||
CSRCS = npassoc.c
|
||||
|
||||
CPPSRCS = nsplugin.cpp npglue.cpp
|
||||
CPPSRCS = nsplugin.cpp npglue.cpp nsMalloc.cpp
|
||||
|
||||
EXPORTS = nppg.h npglue.h nppriv.h
|
||||
EXPORTS = nppg.h npglue.h nppriv.h nsMalloc.h
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
|
@ -24,7 +24,8 @@ MODULE = plugimpl
|
||||
EXPORTS = \
|
||||
nppg.h \
|
||||
npglue.h \
|
||||
nppriv.h
|
||||
nppriv.h \
|
||||
nsMalloc.h
|
||||
|
||||
LIBRARY_NAME = plug
|
||||
|
||||
@ -44,7 +45,8 @@ LINCS = -I$(DIST)\include \
|
||||
|
||||
OBJS = .\$(OBJDIR)\npassoc.obj \
|
||||
.\$(OBJDIR)\nsplugin.obj \
|
||||
.\$(OBJDIR)\npglue.obj
|
||||
.\$(OBJDIR)\npglue.obj \
|
||||
.\$(OBJDIR)\nsMalloc.obj
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
|
120
modules/plugin/src/nsMalloc.cpp
Normal file
120
modules/plugin/src/nsMalloc.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation of nsIMalloc using NSPR
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "nsMalloc.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIMallocIID, NS_IMALLOC_IID);
|
||||
|
||||
nsMalloc::nsMalloc(nsISupports* outer)
|
||||
{
|
||||
NS_INIT_AGGREGATED(outer);
|
||||
}
|
||||
|
||||
nsMalloc::~nsMalloc(void)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_AGGREGATED(nsMalloc);
|
||||
|
||||
NS_METHOD
|
||||
nsMalloc::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kIMallocIID) ||
|
||||
aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsMalloc::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
|
||||
{
|
||||
if (outer && !aIID.Equals(kISupportsIID))
|
||||
return NS_NOINTERFACE; // XXX right error?
|
||||
nsMalloc* mm = new nsMalloc(outer);
|
||||
if (mm == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
mm->AddRef();
|
||||
if (aIID.Equals(kISupportsIID))
|
||||
*aInstancePtr = mm->GetInner();
|
||||
else
|
||||
*aInstancePtr = mm;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_METHOD_(void*)
|
||||
nsMalloc::Alloc(PRUint32 size)
|
||||
{
|
||||
return PR_Malloc(size);
|
||||
}
|
||||
|
||||
NS_METHOD_(void*)
|
||||
nsMalloc::Realloc(void* ptr, PRUint32 size)
|
||||
{
|
||||
return PR_Realloc(ptr, size);
|
||||
}
|
||||
|
||||
NS_METHOD_(void)
|
||||
nsMalloc::Free(void* ptr)
|
||||
{
|
||||
PR_Free(ptr);
|
||||
}
|
||||
|
||||
NS_METHOD_(PRInt32)
|
||||
nsMalloc::GetSize(void* ptr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
NS_METHOD_(PRBool)
|
||||
nsMalloc::DidAlloc(void* ptr)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// For the definition of CallCacheFlushers()
|
||||
#ifdef XP_MAC
|
||||
# ifndef NSPR20
|
||||
# include "prmacos.h"
|
||||
# else
|
||||
# include "MacMemAllocator.h"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
NS_METHOD_(void)
|
||||
nsMalloc::HeapMinimize(void)
|
||||
{
|
||||
#ifdef XP_MAC
|
||||
// something wonderful
|
||||
CallCacheFlushers(0x7fffffff);
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
101
modules/plugin/src/nsMalloc.h
Normal file
101
modules/plugin/src/nsMalloc.h
Normal file
@ -0,0 +1,101 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation of nsIMalloc using NSPR
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef nsMalloc_h__
|
||||
#define nsMalloc_h__
|
||||
|
||||
#include "nsIMalloc.h"
|
||||
#include "prmem.h"
|
||||
#include "nsAgg.h"
|
||||
|
||||
class nsMalloc : nsIMalloc {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Allocates a block of memory of a particular size.
|
||||
*
|
||||
* @param size - the size of the block to allocate
|
||||
* @result the block of memory
|
||||
*/
|
||||
NS_IMETHOD_(void*)
|
||||
Alloc(PRUint32 size);
|
||||
|
||||
/**
|
||||
* Reallocates a block of memory to a new size.
|
||||
*
|
||||
* @param ptr - the block of memory to reallocate
|
||||
* @param size - the new size
|
||||
* @result the rellocated block of memory
|
||||
*/
|
||||
NS_IMETHOD_(void*)
|
||||
Realloc(void* ptr, PRUint32 size);
|
||||
|
||||
/**
|
||||
* Frees a block of memory.
|
||||
*
|
||||
* @param ptr - the block of memory to free
|
||||
*/
|
||||
NS_IMETHOD_(void)
|
||||
Free(void* ptr);
|
||||
|
||||
/**
|
||||
* Returns the size of a block of memory. Returns -1
|
||||
* if the size is not available.
|
||||
*
|
||||
* @param ptr - the block of memory
|
||||
* @result the size or -1 if not available
|
||||
*/
|
||||
NS_IMETHOD_(PRInt32)
|
||||
GetSize(void* ptr);
|
||||
|
||||
/**
|
||||
* Returns whether the block of memory was allocated by this
|
||||
* memory allocator. Returns PR_FALSE if this information is
|
||||
* not available.
|
||||
*
|
||||
* @param ptr - the block of memory
|
||||
* @result true if allocated by this nsIMalloc, false if not or
|
||||
* if it can't be determined
|
||||
*/
|
||||
NS_IMETHOD_(PRBool)
|
||||
DidAlloc(void* ptr);
|
||||
|
||||
/**
|
||||
* Attempts to shrink the heap.
|
||||
*/
|
||||
NS_IMETHOD_(void)
|
||||
HeapMinimize(void);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsMalloc(nsISupports* outer);
|
||||
virtual ~nsMalloc(void);
|
||||
|
||||
NS_DECL_AGGREGATED
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#endif // nsMalloc_h__
|
Loading…
x
Reference in New Issue
Block a user