From 8a3c9ecf3d03b69d8503753b3d2040c26d1668a8 Mon Sep 17 00:00:00 2001 From: "warren%netscape.com" Date: Fri, 18 Sep 1998 07:22:15 +0000 Subject: [PATCH] Moved nsIMalloc and impl from xpcom. git-svn-id: svn://10.0.0.236/trunk@10369 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/plugin/base/public/Makefile | 2 +- .../modules/plugin/base/public/Makefile.in | 2 +- .../modules/plugin/base/public/makefile.win | 2 +- .../modules/plugin/base/public/nsIMalloc.h | 94 ++++++++++++++ mozilla/modules/plugin/public/Makefile | 2 +- mozilla/modules/plugin/public/Makefile.in | 2 +- mozilla/modules/plugin/public/makefile.win | 2 +- mozilla/modules/plugin/public/nsIMalloc.h | 94 ++++++++++++++ mozilla/modules/plugin/src/Makefile | 4 +- mozilla/modules/plugin/src/Makefile.in | 4 +- mozilla/modules/plugin/src/makefile.win | 6 +- mozilla/modules/plugin/src/nsMalloc.cpp | 120 ++++++++++++++++++ mozilla/modules/plugin/src/nsMalloc.h | 101 +++++++++++++++ 13 files changed, 423 insertions(+), 12 deletions(-) create mode 100644 mozilla/modules/plugin/base/public/nsIMalloc.h create mode 100644 mozilla/modules/plugin/public/nsIMalloc.h create mode 100644 mozilla/modules/plugin/src/nsMalloc.cpp create mode 100644 mozilla/modules/plugin/src/nsMalloc.h diff --git a/mozilla/modules/plugin/base/public/Makefile b/mozilla/modules/plugin/base/public/Makefile index e3099394456..a9a67df8278 100644 --- a/mozilla/modules/plugin/base/public/Makefile +++ b/mozilla/modules/plugin/base/public/Makefile @@ -26,7 +26,7 @@ EXPORTS = \ nsIJRILiveConnectPlugInstPeer.h \ nsILiveConnectPlugin.h \ nsILiveConnectPlugInstPeer.h \ - nsINetworkManager.h \ + nsIMalloc.h \ nsIPlugin.h \ nsIPluginInstance.h \ nsIPluginInstancePeer.h \ diff --git a/mozilla/modules/plugin/base/public/Makefile.in b/mozilla/modules/plugin/base/public/Makefile.in index b4fece1b0fd..f10c41b5676 100644 --- a/mozilla/modules/plugin/base/public/Makefile.in +++ b/mozilla/modules/plugin/base/public/Makefile.in @@ -31,7 +31,7 @@ EXPORTS = \ nsIJRILiveConnectPlugInstPeer.h \ nsILiveConnectPlugin.h \ nsILiveConnectPlugInstPeer.h \ - nsINetworkManager.h \ + nsIMalloc.h \ nsIPlugin.h \ nsIPluginInstance.h \ nsIPluginInstancePeer.h \ diff --git a/mozilla/modules/plugin/base/public/makefile.win b/mozilla/modules/plugin/base/public/makefile.win index 3bda15a285e..9db9fe57661 100644 --- a/mozilla/modules/plugin/base/public/makefile.win +++ b/mozilla/modules/plugin/base/public/makefile.win @@ -28,7 +28,7 @@ EXPORTS = \ nsIJRILiveConnectPlugInstPeer.h \ nsILiveConnectPlugin.h \ nsILiveConnectPlugInstPeer.h \ - nsINetworkManager.h \ + nsIMalloc.h \ nsIPlugin.h \ nsIPluginInstance.h \ nsIPluginInstancePeer.h \ diff --git a/mozilla/modules/plugin/base/public/nsIMalloc.h b/mozilla/modules/plugin/base/public/nsIMalloc.h new file mode 100644 index 00000000000..f936d72d8a4 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIMalloc.h @@ -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___ */ diff --git a/mozilla/modules/plugin/public/Makefile b/mozilla/modules/plugin/public/Makefile index e3099394456..a9a67df8278 100644 --- a/mozilla/modules/plugin/public/Makefile +++ b/mozilla/modules/plugin/public/Makefile @@ -26,7 +26,7 @@ EXPORTS = \ nsIJRILiveConnectPlugInstPeer.h \ nsILiveConnectPlugin.h \ nsILiveConnectPlugInstPeer.h \ - nsINetworkManager.h \ + nsIMalloc.h \ nsIPlugin.h \ nsIPluginInstance.h \ nsIPluginInstancePeer.h \ diff --git a/mozilla/modules/plugin/public/Makefile.in b/mozilla/modules/plugin/public/Makefile.in index b4fece1b0fd..f10c41b5676 100644 --- a/mozilla/modules/plugin/public/Makefile.in +++ b/mozilla/modules/plugin/public/Makefile.in @@ -31,7 +31,7 @@ EXPORTS = \ nsIJRILiveConnectPlugInstPeer.h \ nsILiveConnectPlugin.h \ nsILiveConnectPlugInstPeer.h \ - nsINetworkManager.h \ + nsIMalloc.h \ nsIPlugin.h \ nsIPluginInstance.h \ nsIPluginInstancePeer.h \ diff --git a/mozilla/modules/plugin/public/makefile.win b/mozilla/modules/plugin/public/makefile.win index 3bda15a285e..9db9fe57661 100644 --- a/mozilla/modules/plugin/public/makefile.win +++ b/mozilla/modules/plugin/public/makefile.win @@ -28,7 +28,7 @@ EXPORTS = \ nsIJRILiveConnectPlugInstPeer.h \ nsILiveConnectPlugin.h \ nsILiveConnectPlugInstPeer.h \ - nsINetworkManager.h \ + nsIMalloc.h \ nsIPlugin.h \ nsIPluginInstance.h \ nsIPluginInstancePeer.h \ diff --git a/mozilla/modules/plugin/public/nsIMalloc.h b/mozilla/modules/plugin/public/nsIMalloc.h new file mode 100644 index 00000000000..f936d72d8a4 --- /dev/null +++ b/mozilla/modules/plugin/public/nsIMalloc.h @@ -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___ */ diff --git a/mozilla/modules/plugin/src/Makefile b/mozilla/modules/plugin/src/Makefile index ce8d036e875..28aced11805 100644 --- a/mozilla/modules/plugin/src/Makefile +++ b/mozilla/modules/plugin/src/Makefile @@ -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 diff --git a/mozilla/modules/plugin/src/Makefile.in b/mozilla/modules/plugin/src/Makefile.in index f7f20c247b8..fd725f5bc20 100644 --- a/mozilla/modules/plugin/src/Makefile.in +++ b/mozilla/modules/plugin/src/Makefile.in @@ -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)) diff --git a/mozilla/modules/plugin/src/makefile.win b/mozilla/modules/plugin/src/makefile.win index c33a25bec31..d59836e1adf 100644 --- a/mozilla/modules/plugin/src/makefile.win +++ b/mozilla/modules/plugin/src/makefile.win @@ -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> diff --git a/mozilla/modules/plugin/src/nsMalloc.cpp b/mozilla/modules/plugin/src/nsMalloc.cpp new file mode 100644 index 00000000000..54d9782b79b --- /dev/null +++ b/mozilla/modules/plugin/src/nsMalloc.cpp @@ -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 +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/modules/plugin/src/nsMalloc.h b/mozilla/modules/plugin/src/nsMalloc.h new file mode 100644 index 00000000000..a8a9f08ae4c --- /dev/null +++ b/mozilla/modules/plugin/src/nsMalloc.h @@ -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__