Compare commits

..

1 Commits

Author SHA1 Message Date
(no author)
258dc9fead This commit was manufactured by cvs2svn to create branch 'src'.
git-svn-id: svn://10.0.0.236/branches/src@33658 18797224-902f-48f8-a5cc-f745e15eee43
1999-06-03 23:10:01 +00:00
995 changed files with 18581 additions and 307456 deletions

View File

@@ -1,636 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsAVLTree.h"
enum eLean {eLeft,eNeutral,eRight};
struct NS_COM nsAVLNode {
public:
nsAVLNode(void* aValue) {
mLeft=0;
mRight=0;
mSkew=eNeutral;
mValue=aValue;
}
nsAVLNode* mLeft;
nsAVLNode* mRight;
eLean mSkew;
void* mValue;
};
/************************************************************
Now begin the tree class. Don't forget that the comparison
between nodes must occur via the comparitor function,
otherwise all you're testing is pointer addresses.
************************************************************/
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
nsAVLTree::nsAVLTree(nsAVLNodeComparitor& aComparitor,
nsAVLNodeFunctor* aDeallocator) :
mComparitor(aComparitor), mDeallocator(aDeallocator) {
mRoot=0;
mCount=0;
}
static void
avlDeleteTree(nsAVLNode* aNode){
if (aNode) {
avlDeleteTree(aNode->mLeft);
avlDeleteTree(aNode->mRight);
delete aNode;
}
}
/**
*
* @update gess12/27/98
* @param
* @return
*/
nsAVLTree::~nsAVLTree(){
if (mDeallocator) {
ForEachDepthFirst(*mDeallocator);
}
avlDeleteTree(mRoot);
}
class CDoesntExist: public nsAVLNodeFunctor {
public:
CDoesntExist(const nsAVLTree& anotherTree) : mOtherTree(anotherTree) {
}
virtual void* operator()(void* anItem) {
void* result=mOtherTree.FindItem(anItem);
if(result)
return nsnull;
return anItem;
}
protected:
const nsAVLTree& mOtherTree;
};
/**
* This method compares two trees (members by identity).
* @update gess12/27/98
* @param tree to compare against
* @return true if they are identical (contain same stuff).
*/
PRBool nsAVLTree::operator==(const nsAVLTree& aCopy) const{
CDoesntExist functor(aCopy);
void* theItem=FirstThat(functor);
PRBool result=PRBool(!theItem);
return result;
}
/**
*
* @update gess12/27/98
* @param
* @return
*/
static void
avlRotateRight(nsAVLNode*& aRootNode){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
ptr2=aRootNode->mRight;
if(ptr2->mSkew==eRight) {
aRootNode->mRight=ptr2->mLeft;
ptr2->mLeft=aRootNode;
aRootNode->mSkew=eNeutral;
aRootNode=ptr2;
}
else {
ptr3=ptr2->mLeft;
ptr2->mLeft=ptr3->mRight;
ptr3->mRight=ptr2;
aRootNode->mRight=ptr3->mLeft;
ptr3->mLeft=aRootNode;
if(ptr3->mSkew==eLeft)
ptr2->mSkew=eRight;
else ptr2->mSkew=eNeutral;
if(ptr3->mSkew==eRight)
aRootNode->mSkew=eLeft;
else aRootNode->mSkew=eNeutral;
aRootNode=ptr3;
}
aRootNode->mSkew=eNeutral;
return;
}
/**
*
* @update gess12/27/98
* @param
* @return
*/
static void
avlRotateLeft(nsAVLNode*& aRootNode){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
ptr2=aRootNode->mLeft;
if(ptr2->mSkew==eLeft) {
aRootNode->mLeft=ptr2->mRight;
ptr2->mRight=aRootNode;
aRootNode->mSkew=eNeutral;
aRootNode=ptr2;
}
else {
ptr3=ptr2->mRight;
ptr2->mRight=ptr3->mLeft;
ptr3->mLeft=ptr2;
aRootNode->mLeft=ptr3->mRight;
ptr3->mRight=aRootNode;
if(ptr3->mSkew==eRight)
ptr2->mSkew=eLeft;
else ptr2->mSkew=eNeutral;
if(ptr3->mSkew==eLeft)
aRootNode->mSkew=eRight;
else aRootNode->mSkew=eNeutral;
aRootNode=ptr3;
}
aRootNode->mSkew=eNeutral;
return;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static eAVLStatus
avlInsert(nsAVLNode*& aRootNode, nsAVLNode* aNewNode,
nsAVLNodeComparitor& aComparitor) {
eAVLStatus result=eAVL_unknown;
if(!aRootNode) {
aRootNode = aNewNode;
return eAVL_ok;
}
if(aNewNode==aRootNode->mValue) {
return eAVL_duplicate;
}
PRInt32 theCompareResult=aComparitor(aRootNode->mValue,aNewNode->mValue);
if(0 < theCompareResult) { //if(anItem<aRootNode->mValue)
result=avlInsert(aRootNode->mLeft,aNewNode,aComparitor);
if(eAVL_ok==result) {
switch(aRootNode->mSkew){
case eLeft:
avlRotateLeft(aRootNode);
result=eAVL_fail;
break;
case eRight:
aRootNode->mSkew=eNeutral;
result=eAVL_fail;
break;
case eNeutral:
aRootNode->mSkew=eLeft;
break;
} //switch
}//if
} //if
else {
result=avlInsert(aRootNode->mRight,aNewNode,aComparitor);
if(eAVL_ok==result) {
switch(aRootNode->mSkew){
case eLeft:
aRootNode->mSkew=eNeutral;
result=eAVL_fail;
break;
case eRight:
avlRotateRight(aRootNode);
result=eAVL_fail;
break;
case eNeutral:
aRootNode->mSkew=eRight;
break;
} //switch
}
} //if
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static void
avlBalanceLeft(nsAVLNode*& aRootNode, PRBool& delOk){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
eLean balnc2;
eLean balnc3;
switch(aRootNode->mSkew){
case eLeft:
ptr2=aRootNode->mLeft;
balnc2=ptr2->mSkew;
if(balnc2!=eRight) {
aRootNode->mLeft=ptr2->mRight;
ptr2->mRight=aRootNode;
if(balnc2==eNeutral){
aRootNode->mSkew=eLeft;
ptr2->mSkew=eRight;
delOk=PR_FALSE;
}
else{
aRootNode->mSkew=eNeutral;
ptr2->mSkew=eNeutral;
}
aRootNode=ptr2;
}
else{
ptr3=ptr2->mRight;
balnc3=ptr3->mSkew;
ptr2->mRight=ptr3->mLeft;
ptr3->mLeft=ptr2;
aRootNode->mLeft=ptr3->mRight;
ptr3->mRight=aRootNode;
if(balnc3==eRight) {
ptr2->mSkew=eLeft;
}
else {
ptr2->mSkew=eNeutral;
}
if(balnc3==eLeft) {
aRootNode->mSkew=eRight;
}
else {
aRootNode->mSkew=eNeutral;
}
aRootNode=ptr3;
ptr3->mSkew=eNeutral;
}
break;
case eRight:
aRootNode->mSkew=eNeutral;
break;
case eNeutral:
aRootNode->mSkew=eLeft;
delOk=PR_FALSE;
break;
}//switch
return;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static void
avlBalanceRight(nsAVLNode*& aRootNode, PRBool& delOk){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
eLean balnc2;
eLean balnc3;
switch(aRootNode->mSkew){
case eLeft:
aRootNode->mSkew=eNeutral;
break;
case eRight:
ptr2=aRootNode->mRight;
balnc2=ptr2->mSkew;
if(balnc2!=eLeft) {
aRootNode->mRight=ptr2->mLeft;
ptr2->mLeft=aRootNode;
if(balnc2==eNeutral){
aRootNode->mSkew=eRight;
ptr2->mSkew=eLeft;
delOk=PR_FALSE;
}
else{
aRootNode->mSkew=eNeutral;
ptr2->mSkew=eNeutral;
}
aRootNode=ptr2;
}
else{
ptr3=ptr2->mLeft;
balnc3=ptr3->mSkew;
ptr2->mLeft=ptr3->mRight;
ptr3->mRight=ptr2;
aRootNode->mRight=ptr3->mLeft;
ptr3->mLeft=aRootNode;
if(balnc3==eLeft) {
ptr2->mSkew=eRight;
}
else {
ptr2->mSkew=eNeutral;
}
if(balnc3==eRight) {
aRootNode->mSkew=eLeft;
}
else {
aRootNode->mSkew=eNeutral;
}
aRootNode=ptr3;
ptr3->mSkew=eNeutral;
}
break;
case eNeutral:
aRootNode->mSkew=eRight;
delOk=PR_FALSE;
break;
}//switch
return;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static eAVLStatus
avlRemoveChildren(nsAVLNode*& aRootNode,nsAVLNode*& anotherNode, PRBool& delOk){
eAVLStatus result=eAVL_ok;
if(!anotherNode->mRight){
aRootNode->mValue=anotherNode->mValue; //swap
anotherNode=anotherNode->mLeft;
delOk=PR_TRUE;
}
else{
avlRemoveChildren(aRootNode,anotherNode->mRight,delOk);
if(delOk)
avlBalanceLeft(anotherNode,delOk);
}
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static eAVLStatus
avlRemove(nsAVLNode*& aRootNode, void* anItem, PRBool& delOk,
nsAVLNodeComparitor& aComparitor){
eAVLStatus result=eAVL_ok;
if(!aRootNode)
delOk=PR_FALSE;
else {
PRInt32 cmp=aComparitor(anItem,aRootNode->mValue);
if(cmp<0){
avlRemove(aRootNode->mLeft,anItem,delOk,aComparitor);
if(delOk)
avlBalanceRight(aRootNode,delOk);
}
else if(cmp>0){
avlRemove(aRootNode->mRight,anItem,delOk,aComparitor);
if(delOk)
avlBalanceLeft(aRootNode,delOk);
}
else{ //they match...
nsAVLNode* temp=aRootNode;
if(!aRootNode->mRight) {
aRootNode=aRootNode->mLeft;
delOk=PR_TRUE;
delete temp;
}
else if(!aRootNode->mLeft) {
aRootNode=aRootNode->mRight;
delOk=PR_TRUE;
delete temp;
}
else {
avlRemoveChildren(aRootNode,aRootNode->mLeft,delOk);
if(delOk)
avlBalanceRight(aRootNode,delOk);
}
}
}
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
eAVLStatus
nsAVLTree::AddItem(void* anItem){
eAVLStatus result=eAVL_ok;
nsAVLNode* theNewNode=new nsAVLNode(anItem);
result=avlInsert(mRoot,theNewNode,mComparitor);
if(eAVL_duplicate!=result)
mCount++;
else {
delete theNewNode;
}
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
void* nsAVLTree::FindItem(void* aValue) const{
nsAVLNode* result=mRoot;
PRInt32 count=0;
while(result) {
count++;
PRInt32 cmp=mComparitor(aValue,result->mValue);
if(0==cmp) {
//we matched...
break;
}
else if(0>cmp){
//theNode was greater...
result=result->mLeft;
}
else {
//aValue is greater...
result=result->mRight;
}
}
if(result) {
return result->mValue;
}
return nsnull;
}
/**
*
* @update gess12/30/98
* @param
* @return
*/
eAVLStatus
nsAVLTree::RemoveItem(void* aValue){
PRBool delOk=PR_TRUE;
eAVLStatus result=avlRemove(mRoot,aValue,delOk,mComparitor);
if(eAVL_ok==result)
mCount--;
return result;
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
static void
avlForEachDepthFirst(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor){
if(aNode) {
avlForEachDepthFirst(aNode->mLeft,aFunctor);
avlForEachDepthFirst(aNode->mRight,aFunctor);
aFunctor(aNode->mValue);
}
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
void
nsAVLTree::ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const{
::avlForEachDepthFirst(mRoot,aFunctor);
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
static void
avlForEach(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) {
if(aNode) {
avlForEach(aNode->mLeft,aFunctor);
aFunctor(aNode->mValue);
avlForEach(aNode->mRight,aFunctor);
}
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
void
nsAVLTree::ForEach(nsAVLNodeFunctor& aFunctor) const{
::avlForEach(mRoot,aFunctor);
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
static void*
avlFirstThat(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) {
void* result=nsnull;
if(aNode) {
result = avlFirstThat(aNode->mLeft,aFunctor);
if (result) {
return result;
}
result = aFunctor(aNode->mValue);
if (result) {
return result;
}
result = avlFirstThat(aNode->mRight,aFunctor);
}
return result;
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
void*
nsAVLTree::FirstThat(nsAVLNodeFunctor& aFunctor) const{
return ::avlFirstThat(mRoot,aFunctor);
}

View File

@@ -1,93 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsAVLTree_h___
#define nsAVLTree_h___
#include "nscore.h"
enum eAVLStatus {eAVL_unknown,eAVL_ok,eAVL_fail,eAVL_duplicate};
struct nsAVLNode;
/**
*
* @update gess12/26/98
* @param anObject1 is the first object to be compared
* @param anObject2 is the second object to be compared
* @return -1,0,1 if object1 is less, equal, greater than object2
*/
class NS_COM nsAVLNodeComparitor {
public:
virtual PRInt32 operator()(void* anItem1,void* anItem2)=0;
};
class NS_COM nsAVLNodeFunctor {
public:
virtual void* operator()(void* anItem)=0;
};
class NS_COM nsAVLTree {
public:
nsAVLTree(nsAVLNodeComparitor& aComparitor, nsAVLNodeFunctor* aDeallocator);
~nsAVLTree(void);
PRBool operator==(const nsAVLTree& aOther) const;
PRInt32 GetCount(void) const {return mCount;}
//main functions...
eAVLStatus AddItem(void* anItem);
eAVLStatus RemoveItem(void* anItem);
void* FindItem(void* anItem) const;
void ForEach(nsAVLNodeFunctor& aFunctor) const;
void ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const;
void* FirstThat(nsAVLNodeFunctor& aFunctor) const;
protected:
nsAVLNode* mRoot;
PRInt32 mCount;
nsAVLNodeComparitor& mComparitor;
nsAVLNodeFunctor* mDeallocator;
};
#endif /* nsAVLTree_h___ */

View File

@@ -1,165 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "MPL"); you may not use this file except in
* compliance with the MPL. You may obtain a copy of the MPL at
* http://www.mozilla.org/MPL/
*
* Software distributed under the MPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the MPL
* for the specific language governing rights and limitations under the
* MPL.
*
* The Initial Developer of this code under the MPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
#include "nsIEnumerator.idl"
typedef PRUint32 nsRegistryKey;
typedef long nsWellKnownRegistry;
[scriptable,uuid(5D41A440-8E37-11d2-8059-00600811A9C3)]
interface nsIRegistry : nsISupports
{
const long None = 0;
const long Users = 1;
const long Common = 2;
const long CurrentUser = 3;
const long ApplicationComponentRegistry = 1;
const long ApplicationRegistry = 2;
// Dont use this one. This for internal use only.
const long ApplicationCustomRegistry = -1;
void open(in string regFile);
void openWellKnownRegistry(in nsWellKnownRegistry regid);
void flush();
boolean isOpen();
nsRegistryKey addKey(in nsRegistryKey baseKey, in wstring keyname);
nsRegistryKey getKey(in nsRegistryKey baseKey, in wstring keyname);
void removeKey(in nsRegistryKey baseKey, in wstring keyname);
wstring getString(in nsRegistryKey baseKey, in wstring valname);
void setString(in nsRegistryKey baseKey, in wstring valname, in wstring value);
string getStringUTF8(in nsRegistryKey baseKey, in string path);
void setStringUTF8(in nsRegistryKey baseKey, in string path, in string value);
void getBytesUTF8(in nsRegistryKey baseKey, in string path, out PRUint32 length, [retval, array, size_is(length)] out PRUint8 valueArray);
void setBytesUTF8(in nsRegistryKey baseKey, in string path, in PRUint32 length, [array, size_is(length)] in PRUint8 valueArray);
PRInt32 getInt(in nsRegistryKey baseKey, in string path);
void setInt(in nsRegistryKey baseKey, in string path, in PRInt32 value);
PRInt64 getLongLong(in nsRegistryKey baseKey, in string path);
void setLongLong(in nsRegistryKey baseKey, in string path, inout PRInt64 value);
/**
* addSubtree() and friends need to be renamed to addKeyUTF8().
* If you are using these forms make sure you pass UTF8 data
*/
nsRegistryKey addSubtree(in nsRegistryKey baseKey, in string path);
void removeSubtree(in nsRegistryKey baseKey, in string path);
nsRegistryKey getSubtree(in nsRegistryKey baseKey, in string path);
nsRegistryKey addSubtreeRaw(in nsRegistryKey baseKey, in string path);
void removeSubtreeRaw(in nsRegistryKey baseKey, in string path);
nsRegistryKey getSubtreeRaw(in nsRegistryKey baseKey, in string path);
nsIEnumerator enumerateSubtrees(in nsRegistryKey baseKey);
nsIEnumerator enumerateAllSubtrees(in nsRegistryKey baseKey);
nsIEnumerator enumerateValues(in nsRegistryKey baseKey);
const unsigned long String = 1;
const unsigned long Int32 = 2;
const unsigned long Bytes = 3;
const unsigned long File = 4;
unsigned long getValueType(in nsRegistryKey baseKey, in string path);
PRUint32 getValueLength(in nsRegistryKey baseKey, in string path);
void deleteValue(in nsRegistryKey baseKey, in string path);
/**
* escapeKey() takes arbitrary binary data and converts it into
* valid ASCII which can be used as registry key or value names
*/
void escapeKey([array, size_is(length)] in PRUint8 key, in PRUint32 terminator, inout PRUint32 length, [retval, array, size_is(length)] out PRUint8 escaped);
void unescapeKey([array, size_is(length)] in PRUint8 escaped, in PRUint32 terminator, inout PRUint32 length, [retval, array, size_is(length)] out PRUint8 key);
attribute string currentUserName;
void pack();
};
[scriptable, uuid(8cecf236-1dd2-11b2-893c-f9848956eaec)]
interface nsIRegistryEnumerator : nsIEnumerator
{
void currentItemInPlaceUTF8(out nsRegistryKey key,
[shared, retval] out string item);
};
[scriptable, uuid(D1B54831-AC07-11d2-805E-00600811A9C3)]
interface nsIRegistryNode : nsISupports
{
readonly attribute string nameUTF8;
readonly attribute wstring name;
readonly attribute nsRegistryKey key;
};
[scriptable,uuid(5316C380-B2F8-11d2-A374-0080C6F80E4B)]
interface nsIRegistryValue : nsISupports
{
readonly attribute wstring name;
readonly attribute string nameUTF8;
readonly attribute unsigned long type;
readonly attribute PRUint32 length;
};
[uuid(3A15FC88-7A61-4Ab4-8E58-31E95fAB3DA8)]
/**
* It sucks that nsIRegistry has to always allocate and return
* strings. nsIRegistryGetter adds in interfaces for non allocating getters
* to registry values.
*/
interface nsIRegistryGetter : nsISupports
{
/**
* Get a string value of attribute valname in widestring or utf8 format
*
* @return
* NS_OK on success.
* buf has the string value copied into it. length is NOT changed.
* NS_ERROR_REG_BUFFER_TOO_SMALL if not enough buffer space.
* length is updated to actual length in chars including
* terminating NULL and buf will be unchanged.
* NS_ERROR_FAILURE if an unknown error happened. state of buf and
* length undefined.
* various failure codes otherwise. buf and length wont be updated.
*/
void getStringUTF8IntoBuffer(in nsRegistryKey baseKey, in string path,
inout char buf, inout PRUint32 length);
/**
* Get a a byte array value of attribute valname
*
* @return
* NS_OK on success. buf has the string value copied into it.
* length is updated to actual number of bytes copied into buf.
* NS_ERROR_REG_BUFFER_TOO_SMALL if not enough buffer space.
* length is updated to actual length in PRUint8s including
* terminating NULL and buf will be unchanged.
* NS_ERROR_FAILURE if an unknown error happened. state of buf and
* length undefined.
* various other failure codes otherwise. buf and length wont be updated.
*/
void getBytesUTF8IntoBuffer(in nsRegistryKey baseKey, in string path,
inout PRUint8 buf, inout PRUint32 length);
};
%{ C++
#include "nsIRegistryUtils.h"
%}

View File

@@ -1,59 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __nsIRegistryUtils_h
#define __nsIRegistryUtils_h
#define NS_REGISTRY_CONTRACTID "@mozilla.org/registry;1"
#define NS_REGISTRY_CLASSNAME "Mozilla Registry"
/* be761f00-a3b0-11d2-996c-0080c7cb1081 */
#define NS_REGISTRY_CID \
{ 0xbe761f00, 0xa3b0, 0x11d2, \
{0x99, 0x6c, 0x00, 0x80, 0xc7, 0xcb, 0x10, 0x81} }
/*------------------------------- Error Codes ----------------------------------
------------------------------------------------------------------------------*/
#define NS_ERROR_REG_BADTYPE NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 1 )
#define NS_ERROR_REG_NO_MORE NS_ERROR_GENERATE_SUCCESS( NS_ERROR_MODULE_REG, 2 )
#define NS_ERROR_REG_NOT_FOUND NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 3 )
#define NS_ERROR_REG_NOFILE NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 4 )
#define NS_ERROR_REG_BUFFER_TOO_SMALL NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 5 )
#define NS_ERROR_REG_NAME_TOO_LONG NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 6 )
#define NS_ERROR_REG_NO_PATH NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 7 )
#define NS_ERROR_REG_READ_ONLY NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 8 )
#define NS_ERROR_REG_BAD_UTF8 NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 9 )
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,73 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Edward Kandrot <kandrot@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsRegistry_h__
#define nsRegistry_h__
#include "nsIRegistry.h"
#include "NSReg.h"
struct nsRegistry : public nsIRegistry, nsIRegistryGetter {
// This class implements the nsISupports interface functions.
NS_DECL_ISUPPORTS
// This class implements the nsIRegistry interface functions.
NS_DECL_NSIREGISTRY
// Fast registry getters
NS_DECL_NSIREGISTRYGETTER
// ctor/dtor
nsRegistry();
virtual ~nsRegistry();
int SetBufferSize( int bufsize ); // changes the file buffer size for this registry
protected:
HREG mReg; // Registry handle.
#ifdef EXTRA_THREADSAFE
PRLock *mregLock; // libreg isn't threadsafe. Use locks to synchronize.
#endif
char *mCurRegFile; // these are to prevent open from opening the registry again
nsWellKnownRegistry mCurRegID;
NS_IMETHOD Close();
}; // nsRegistry
#endif

View File

@@ -1,636 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsAVLTree.h"
enum eLean {eLeft,eNeutral,eRight};
struct NS_COM nsAVLNode {
public:
nsAVLNode(void* aValue) {
mLeft=0;
mRight=0;
mSkew=eNeutral;
mValue=aValue;
}
nsAVLNode* mLeft;
nsAVLNode* mRight;
eLean mSkew;
void* mValue;
};
/************************************************************
Now begin the tree class. Don't forget that the comparison
between nodes must occur via the comparitor function,
otherwise all you're testing is pointer addresses.
************************************************************/
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
nsAVLTree::nsAVLTree(nsAVLNodeComparitor& aComparitor,
nsAVLNodeFunctor* aDeallocator) :
mComparitor(aComparitor), mDeallocator(aDeallocator) {
mRoot=0;
mCount=0;
}
static void
avlDeleteTree(nsAVLNode* aNode){
if (aNode) {
avlDeleteTree(aNode->mLeft);
avlDeleteTree(aNode->mRight);
delete aNode;
}
}
/**
*
* @update gess12/27/98
* @param
* @return
*/
nsAVLTree::~nsAVLTree(){
if (mDeallocator) {
ForEachDepthFirst(*mDeallocator);
}
avlDeleteTree(mRoot);
}
class CDoesntExist: public nsAVLNodeFunctor {
public:
CDoesntExist(const nsAVLTree& anotherTree) : mOtherTree(anotherTree) {
}
virtual void* operator()(void* anItem) {
void* result=mOtherTree.FindItem(anItem);
if(result)
return nsnull;
return anItem;
}
protected:
const nsAVLTree& mOtherTree;
};
/**
* This method compares two trees (members by identity).
* @update gess12/27/98
* @param tree to compare against
* @return true if they are identical (contain same stuff).
*/
PRBool nsAVLTree::operator==(const nsAVLTree& aCopy) const{
CDoesntExist functor(aCopy);
void* theItem=FirstThat(functor);
PRBool result=PRBool(!theItem);
return result;
}
/**
*
* @update gess12/27/98
* @param
* @return
*/
static void
avlRotateRight(nsAVLNode*& aRootNode){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
ptr2=aRootNode->mRight;
if(ptr2->mSkew==eRight) {
aRootNode->mRight=ptr2->mLeft;
ptr2->mLeft=aRootNode;
aRootNode->mSkew=eNeutral;
aRootNode=ptr2;
}
else {
ptr3=ptr2->mLeft;
ptr2->mLeft=ptr3->mRight;
ptr3->mRight=ptr2;
aRootNode->mRight=ptr3->mLeft;
ptr3->mLeft=aRootNode;
if(ptr3->mSkew==eLeft)
ptr2->mSkew=eRight;
else ptr2->mSkew=eNeutral;
if(ptr3->mSkew==eRight)
aRootNode->mSkew=eLeft;
else aRootNode->mSkew=eNeutral;
aRootNode=ptr3;
}
aRootNode->mSkew=eNeutral;
return;
}
/**
*
* @update gess12/27/98
* @param
* @return
*/
static void
avlRotateLeft(nsAVLNode*& aRootNode){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
ptr2=aRootNode->mLeft;
if(ptr2->mSkew==eLeft) {
aRootNode->mLeft=ptr2->mRight;
ptr2->mRight=aRootNode;
aRootNode->mSkew=eNeutral;
aRootNode=ptr2;
}
else {
ptr3=ptr2->mRight;
ptr2->mRight=ptr3->mLeft;
ptr3->mLeft=ptr2;
aRootNode->mLeft=ptr3->mRight;
ptr3->mRight=aRootNode;
if(ptr3->mSkew==eRight)
ptr2->mSkew=eLeft;
else ptr2->mSkew=eNeutral;
if(ptr3->mSkew==eLeft)
aRootNode->mSkew=eRight;
else aRootNode->mSkew=eNeutral;
aRootNode=ptr3;
}
aRootNode->mSkew=eNeutral;
return;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static eAVLStatus
avlInsert(nsAVLNode*& aRootNode, nsAVLNode* aNewNode,
nsAVLNodeComparitor& aComparitor) {
eAVLStatus result=eAVL_unknown;
if(!aRootNode) {
aRootNode = aNewNode;
return eAVL_ok;
}
if(aNewNode==aRootNode->mValue) {
return eAVL_duplicate;
}
PRInt32 theCompareResult=aComparitor(aRootNode->mValue,aNewNode->mValue);
if(0 < theCompareResult) { //if(anItem<aRootNode->mValue)
result=avlInsert(aRootNode->mLeft,aNewNode,aComparitor);
if(eAVL_ok==result) {
switch(aRootNode->mSkew){
case eLeft:
avlRotateLeft(aRootNode);
result=eAVL_fail;
break;
case eRight:
aRootNode->mSkew=eNeutral;
result=eAVL_fail;
break;
case eNeutral:
aRootNode->mSkew=eLeft;
break;
} //switch
}//if
} //if
else {
result=avlInsert(aRootNode->mRight,aNewNode,aComparitor);
if(eAVL_ok==result) {
switch(aRootNode->mSkew){
case eLeft:
aRootNode->mSkew=eNeutral;
result=eAVL_fail;
break;
case eRight:
avlRotateRight(aRootNode);
result=eAVL_fail;
break;
case eNeutral:
aRootNode->mSkew=eRight;
break;
} //switch
}
} //if
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static void
avlBalanceLeft(nsAVLNode*& aRootNode, PRBool& delOk){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
eLean balnc2;
eLean balnc3;
switch(aRootNode->mSkew){
case eLeft:
ptr2=aRootNode->mLeft;
balnc2=ptr2->mSkew;
if(balnc2!=eRight) {
aRootNode->mLeft=ptr2->mRight;
ptr2->mRight=aRootNode;
if(balnc2==eNeutral){
aRootNode->mSkew=eLeft;
ptr2->mSkew=eRight;
delOk=PR_FALSE;
}
else{
aRootNode->mSkew=eNeutral;
ptr2->mSkew=eNeutral;
}
aRootNode=ptr2;
}
else{
ptr3=ptr2->mRight;
balnc3=ptr3->mSkew;
ptr2->mRight=ptr3->mLeft;
ptr3->mLeft=ptr2;
aRootNode->mLeft=ptr3->mRight;
ptr3->mRight=aRootNode;
if(balnc3==eRight) {
ptr2->mSkew=eLeft;
}
else {
ptr2->mSkew=eNeutral;
}
if(balnc3==eLeft) {
aRootNode->mSkew=eRight;
}
else {
aRootNode->mSkew=eNeutral;
}
aRootNode=ptr3;
ptr3->mSkew=eNeutral;
}
break;
case eRight:
aRootNode->mSkew=eNeutral;
break;
case eNeutral:
aRootNode->mSkew=eLeft;
delOk=PR_FALSE;
break;
}//switch
return;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static void
avlBalanceRight(nsAVLNode*& aRootNode, PRBool& delOk){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
eLean balnc2;
eLean balnc3;
switch(aRootNode->mSkew){
case eLeft:
aRootNode->mSkew=eNeutral;
break;
case eRight:
ptr2=aRootNode->mRight;
balnc2=ptr2->mSkew;
if(balnc2!=eLeft) {
aRootNode->mRight=ptr2->mLeft;
ptr2->mLeft=aRootNode;
if(balnc2==eNeutral){
aRootNode->mSkew=eRight;
ptr2->mSkew=eLeft;
delOk=PR_FALSE;
}
else{
aRootNode->mSkew=eNeutral;
ptr2->mSkew=eNeutral;
}
aRootNode=ptr2;
}
else{
ptr3=ptr2->mLeft;
balnc3=ptr3->mSkew;
ptr2->mLeft=ptr3->mRight;
ptr3->mRight=ptr2;
aRootNode->mRight=ptr3->mLeft;
ptr3->mLeft=aRootNode;
if(balnc3==eLeft) {
ptr2->mSkew=eRight;
}
else {
ptr2->mSkew=eNeutral;
}
if(balnc3==eRight) {
aRootNode->mSkew=eLeft;
}
else {
aRootNode->mSkew=eNeutral;
}
aRootNode=ptr3;
ptr3->mSkew=eNeutral;
}
break;
case eNeutral:
aRootNode->mSkew=eRight;
delOk=PR_FALSE;
break;
}//switch
return;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static eAVLStatus
avlRemoveChildren(nsAVLNode*& aRootNode,nsAVLNode*& anotherNode, PRBool& delOk){
eAVLStatus result=eAVL_ok;
if(!anotherNode->mRight){
aRootNode->mValue=anotherNode->mValue; //swap
anotherNode=anotherNode->mLeft;
delOk=PR_TRUE;
}
else{
avlRemoveChildren(aRootNode,anotherNode->mRight,delOk);
if(delOk)
avlBalanceLeft(anotherNode,delOk);
}
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static eAVLStatus
avlRemove(nsAVLNode*& aRootNode, void* anItem, PRBool& delOk,
nsAVLNodeComparitor& aComparitor){
eAVLStatus result=eAVL_ok;
if(!aRootNode)
delOk=PR_FALSE;
else {
PRInt32 cmp=aComparitor(anItem,aRootNode->mValue);
if(cmp<0){
avlRemove(aRootNode->mLeft,anItem,delOk,aComparitor);
if(delOk)
avlBalanceRight(aRootNode,delOk);
}
else if(cmp>0){
avlRemove(aRootNode->mRight,anItem,delOk,aComparitor);
if(delOk)
avlBalanceLeft(aRootNode,delOk);
}
else{ //they match...
nsAVLNode* temp=aRootNode;
if(!aRootNode->mRight) {
aRootNode=aRootNode->mLeft;
delOk=PR_TRUE;
delete temp;
}
else if(!aRootNode->mLeft) {
aRootNode=aRootNode->mRight;
delOk=PR_TRUE;
delete temp;
}
else {
avlRemoveChildren(aRootNode,aRootNode->mLeft,delOk);
if(delOk)
avlBalanceRight(aRootNode,delOk);
}
}
}
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
eAVLStatus
nsAVLTree::AddItem(void* anItem){
eAVLStatus result=eAVL_ok;
nsAVLNode* theNewNode=new nsAVLNode(anItem);
result=avlInsert(mRoot,theNewNode,mComparitor);
if(eAVL_duplicate!=result)
mCount++;
else {
delete theNewNode;
}
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
void* nsAVLTree::FindItem(void* aValue) const{
nsAVLNode* result=mRoot;
PRInt32 count=0;
while(result) {
count++;
PRInt32 cmp=mComparitor(aValue,result->mValue);
if(0==cmp) {
//we matched...
break;
}
else if(0>cmp){
//theNode was greater...
result=result->mLeft;
}
else {
//aValue is greater...
result=result->mRight;
}
}
if(result) {
return result->mValue;
}
return nsnull;
}
/**
*
* @update gess12/30/98
* @param
* @return
*/
eAVLStatus
nsAVLTree::RemoveItem(void* aValue){
PRBool delOk=PR_TRUE;
eAVLStatus result=avlRemove(mRoot,aValue,delOk,mComparitor);
if(eAVL_ok==result)
mCount--;
return result;
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
static void
avlForEachDepthFirst(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor){
if(aNode) {
avlForEachDepthFirst(aNode->mLeft,aFunctor);
avlForEachDepthFirst(aNode->mRight,aFunctor);
aFunctor(aNode->mValue);
}
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
void
nsAVLTree::ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const{
::avlForEachDepthFirst(mRoot,aFunctor);
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
static void
avlForEach(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) {
if(aNode) {
avlForEach(aNode->mLeft,aFunctor);
aFunctor(aNode->mValue);
avlForEach(aNode->mRight,aFunctor);
}
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
void
nsAVLTree::ForEach(nsAVLNodeFunctor& aFunctor) const{
::avlForEach(mRoot,aFunctor);
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
static void*
avlFirstThat(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) {
void* result=nsnull;
if(aNode) {
result = avlFirstThat(aNode->mLeft,aFunctor);
if (result) {
return result;
}
result = aFunctor(aNode->mValue);
if (result) {
return result;
}
result = avlFirstThat(aNode->mRight,aFunctor);
}
return result;
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
void*
nsAVLTree::FirstThat(nsAVLNodeFunctor& aFunctor) const{
return ::avlFirstThat(mRoot,aFunctor);
}

View File

@@ -1,93 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsAVLTree_h___
#define nsAVLTree_h___
#include "nscore.h"
enum eAVLStatus {eAVL_unknown,eAVL_ok,eAVL_fail,eAVL_duplicate};
struct nsAVLNode;
/**
*
* @update gess12/26/98
* @param anObject1 is the first object to be compared
* @param anObject2 is the second object to be compared
* @return -1,0,1 if object1 is less, equal, greater than object2
*/
class NS_COM nsAVLNodeComparitor {
public:
virtual PRInt32 operator()(void* anItem1,void* anItem2)=0;
};
class NS_COM nsAVLNodeFunctor {
public:
virtual void* operator()(void* anItem)=0;
};
class NS_COM nsAVLTree {
public:
nsAVLTree(nsAVLNodeComparitor& aComparitor, nsAVLNodeFunctor* aDeallocator);
~nsAVLTree(void);
PRBool operator==(const nsAVLTree& aOther) const;
PRInt32 GetCount(void) const {return mCount;}
//main functions...
eAVLStatus AddItem(void* anItem);
eAVLStatus RemoveItem(void* anItem);
void* FindItem(void* anItem) const;
void ForEach(nsAVLNodeFunctor& aFunctor) const;
void ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const;
void* FirstThat(nsAVLNodeFunctor& aFunctor) const;
protected:
nsAVLNode* mRoot;
PRInt32 mCount;
nsAVLNodeComparitor& mComparitor;
nsAVLNodeFunctor* mDeallocator;
};
#endif /* nsAVLTree_h___ */

View File

@@ -1,496 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* John Bandhauer <jband@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* Win32 x86 code for stack walking, symbol resolution, and function hooking */
#if defined(_WIN32) && defined(_M_IX86)
// This is the .cpp file where the globals live
#define DHW_IMPLEMENT_GLOBALS
#include <stdio.h>
#include "prtypes.h"
#include "prprf.h"
#include "prlog.h"
#include "plstr.h"
#include "prlock.h"
#include "nscore.h"
#include "nsAutoLock.h"
#include "nsDebugHelpWin32.h"
#else
#error "nsDebugHelpWin32.cpp should only be built in Win32 x86 builds"
#endif
PRBool
dhwEnsureImageHlpInitialized()
{
static PRBool gInitialized = PR_FALSE;
static PRBool gTried = PR_FALSE;
if (!gInitialized && !gTried) {
gTried = PR_TRUE;
HMODULE module = ::LoadLibrary("DBGHELP.DLL");
if (!module) {
DWORD dw = GetLastError();
printf("DumpStack Error: DBGHELP.DLL wasn't found. GetLastError() returned 0x%8.8X\n"
" This DLL is needed for succeessfully implementing trace-malloc.\n"
" This dll ships by default on Win2k. Disabling trace-malloc functionality.\n"
, dw);
return PR_FALSE;
}
#define INIT_PROC(typename_, name_) \
dhw##name_ = (typename_) ::GetProcAddress(module, #name_); \
if(!dhw##name_) return PR_FALSE;
INIT_PROC(SYMINITIALIZEPROC, SymInitialize);
INIT_PROC(SYMSETOPTIONS, SymSetOptions);
INIT_PROC(SYMGETOPTIONS, SymGetOptions);
INIT_PROC(SYMGETMODULEINFO, SymGetModuleInfo);
INIT_PROC(SYMGETSYMFROMADDRPROC, SymGetSymFromAddr);
INIT_PROC(ENUMERATELOADEDMODULES, EnumerateLoadedModules);
INIT_PROC(IMAGEDIRECTORYENTRYTODATA, ImageDirectoryEntryToData);
// INIT_PROC(SYMGETLINEFROMADDR, SymGetLineFromAddr);
// INIT_PROC(SYMCLEANUPPROC, SymCleanup);
// INIT_PROC(STACKWALKPROC, StackWalk);
// INIT_PROC(SYMFUNCTIONTABLEACCESSPROC, SymFunctionTableAccess);
// INIT_PROC(SYMGETMODULEBASEPROC, SymGetModuleBase);
// INIT_PROC(SYMLOADMODULE, SymLoadModule);
// INIT_PROC(UNDECORATESYMBOLNAME, UnDecorateSymbolName);
// INIT_PROC(SYMUNDNAME, SymUnDName);
#undef INIT_PROC
gInitialized = PR_TRUE;
}
return gInitialized;
}
PRBool
dhwEnsureSymInitialized()
{
static PRBool gInitialized = PR_FALSE;
if (! gInitialized) {
if (! dhwEnsureImageHlpInitialized())
return PR_FALSE;
dhwSymSetOptions(
#if defined(NS_TRACE_MALLOC)
SYMOPT_LOAD_LINES |
#endif
SYMOPT_UNDNAME);
// dhwSymSetOptions(SYMOPT_UNDNAME);
if (! dhwSymInitialize(::GetCurrentProcess(), NULL, TRUE))
return PR_FALSE;
gInitialized = PR_TRUE;
}
return gInitialized;
}
/***************************************************************************/
PRLock* DHWImportHooker::gLock = nsnull;
DHWImportHooker* DHWImportHooker::gHooks = nsnull;
GETPROCADDRESS DHWImportHooker::gRealGetProcAddress = nsnull;
DHWImportHooker&
DHWImportHooker::getGetProcAddressHooker()
{
static DHWImportHooker gGetProcAddress("Kernel32.dll", "GetProcAddress",
(PROC)DHWImportHooker::GetProcAddress);
return gGetProcAddress;
}
DHWImportHooker&
DHWImportHooker::getLoadLibraryWHooker()
{
static DHWImportHooker gLoadLibraryW("Kernel32.dll", "LoadLibraryW",
(PROC)DHWImportHooker::LoadLibraryW);
return gLoadLibraryW;
}
DHWImportHooker&
DHWImportHooker::getLoadLibraryExWHooker()
{
static DHWImportHooker gLoadLibraryExW("Kernel32.dll", "LoadLibraryExW",
(PROC)DHWImportHooker::LoadLibraryExW);
return gLoadLibraryExW;
}
DHWImportHooker&
DHWImportHooker::getLoadLibraryAHooker()
{
static DHWImportHooker gLoadLibraryA("Kernel32.dll", "LoadLibraryA",
(PROC)DHWImportHooker::LoadLibraryA);
return gLoadLibraryA;
}
DHWImportHooker&
DHWImportHooker::getLoadLibraryExAHooker()
{
static DHWImportHooker gLoadLibraryExA("Kernel32.dll", "LoadLibraryExA",
(PROC)DHWImportHooker::LoadLibraryExA);
return gLoadLibraryExA;
}
static HMODULE ThisModule()
{
MEMORY_BASIC_INFORMATION info;
return VirtualQuery(ThisModule, &info, sizeof(info)) ?
(HMODULE) info.AllocationBase : nsnull;
}
DHWImportHooker::DHWImportHooker(const char* aModuleName,
const char* aFunctionName,
PROC aHook,
PRBool aExcludeOurModule /* = PR_FALSE */)
: mNext(nsnull),
mModuleName(aModuleName),
mFunctionName(aFunctionName),
mOriginal(nsnull),
mHook(aHook),
mIgnoreModule(aExcludeOurModule ? ThisModule() : nsnull),
mHooking(PR_TRUE)
{
//printf("DHWImportHooker hooking %s, function %s\n",aModuleName, aFunctionName);
if(!gLock)
gLock = PR_NewLock();
nsAutoLock lock(gLock);
dhwEnsureImageHlpInitialized();
if(!gRealGetProcAddress)
gRealGetProcAddress = ::GetProcAddress;
mOriginal = gRealGetProcAddress(::GetModuleHandleA(aModuleName),
aFunctionName),
mNext = gHooks;
gHooks = this;
PatchAllModules();
}
DHWImportHooker::~DHWImportHooker()
{
nsAutoLock lock(gLock);
mHooking = PR_FALSE;
PatchAllModules();
if(gHooks == this)
gHooks = mNext;
else
{
for(DHWImportHooker* cur = gHooks; cur; cur = cur->mNext)
{
if(cur->mNext == this)
{
cur->mNext = mNext;
break;
}
}
NS_ASSERTION(cur, "we were not in the list!");
}
if(!gHooks)
{
PRLock* theLock = gLock;
gLock = nsnull;
lock.unlock();
PR_DestroyLock(theLock);
}
}
static BOOL CALLBACK ModuleEnumCallback(LPSTR ModuleName,
ULONG ModuleBase,
ULONG ModuleSize,
PVOID UserContext)
{
//printf("Module Name %s\n",ModuleName);
DHWImportHooker* self = (DHWImportHooker*) UserContext;
HMODULE aModule = (HMODULE) ModuleBase;
return self->PatchOneModule(aModule, ModuleName);
}
PRBool
DHWImportHooker::PatchAllModules()
{
return dhwEnumerateLoadedModules(::GetCurrentProcess(),
ModuleEnumCallback, this);
}
PRBool
DHWImportHooker::PatchOneModule(HMODULE aModule, const char* name)
{
if(aModule == mIgnoreModule)
{
return PR_TRUE;
}
// do the fun stuff...
PIMAGE_IMPORT_DESCRIPTOR desc;
uint32 size;
desc = (PIMAGE_IMPORT_DESCRIPTOR)
dhwImageDirectoryEntryToData(aModule, PR_TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT, &size);
if(!desc)
{
return PR_TRUE;
}
for(; desc->Name; desc++)
{
const char* entryModuleName = (const char*)
((char*)aModule + desc->Name);
if(!lstrcmpi(entryModuleName, mModuleName))
break;
}
if(!desc->Name)
{
return PR_TRUE;
}
PIMAGE_THUNK_DATA thunk = (PIMAGE_THUNK_DATA)
((char*) aModule + desc->FirstThunk);
for(; thunk->u1.Function; thunk++)
{
PROC original;
PROC replacement;
if(mHooking)
{
original = mOriginal;
replacement = mHook;
}
else
{
original = mHook;
replacement = mOriginal;
}
PROC* ppfn = (PROC*) &thunk->u1.Function;
if(*ppfn == original)
{
DWORD dwDummy;
VirtualProtect(ppfn, sizeof(ppfn), PAGE_EXECUTE_READWRITE, &dwDummy);
BOOL result = WriteProcessMemory(GetCurrentProcess(),
ppfn, &replacement, sizeof(replacement), nsnull);
if (!result) //failure
{
printf("failure name %s func %x\n",name,*ppfn);
DWORD error = GetLastError();
return PR_TRUE;
}
else
{
// printf("success name %s func %x\n",name,*ppfn);
DWORD filler = result+1;
return result;
}
}
}
return PR_TRUE;
}
PRBool
DHWImportHooker::ModuleLoaded(HMODULE aModule, DWORD flags)
{
//printf("ModuleLoaded\n");
if(aModule && !(flags & LOAD_LIBRARY_AS_DATAFILE))
{
nsAutoLock lock(gLock);
// We don't know that the newly loaded module didn't drag in implicitly
// linked modules, so we patch everything in sight.
for(DHWImportHooker* cur = gHooks; cur; cur = cur->mNext)
cur->PatchAllModules();
}
return PR_TRUE;
}
// static
HMODULE WINAPI
DHWImportHooker::LoadLibraryW(PCWSTR path)
{
//wprintf(L"LoadLibraryW %s\n",path);
DHW_DECLARE_FUN_TYPE(HMODULE, __stdcall, LOADLIBRARYW_, (PCWSTR));
HMODULE hmod = DHW_ORIGINAL(LOADLIBRARYW_, getLoadLibraryWHooker())(path);
ModuleLoaded(hmod, 0);
return hmod;
}
// static
HMODULE WINAPI
DHWImportHooker::LoadLibraryExW(PCWSTR path, HANDLE file, DWORD flags)
{
//wprintf(L"LoadLibraryExW %s\n",path);
DHW_DECLARE_FUN_TYPE(HMODULE, __stdcall, LOADLIBRARYEXW_, (PCWSTR, HANDLE, DWORD));
HMODULE hmod = DHW_ORIGINAL(LOADLIBRARYEXW_, getLoadLibraryExWHooker())(path, file, flags);
ModuleLoaded(hmod, flags);
return hmod;
}
// static
HMODULE WINAPI
DHWImportHooker::LoadLibraryA(PCSTR path)
{
//printf("LoadLibraryA %s\n",path);
DHW_DECLARE_FUN_TYPE(HMODULE, __stdcall, LOADLIBRARYA_, (PCSTR));
HMODULE hmod = DHW_ORIGINAL(LOADLIBRARYA_, getLoadLibraryAHooker())(path);
ModuleLoaded(hmod, 0);
return hmod;
}
// static
HMODULE WINAPI
DHWImportHooker::LoadLibraryExA(PCSTR path, HANDLE file, DWORD flags)
{
//printf("LoadLibraryExA %s\n",path);
DHW_DECLARE_FUN_TYPE(HMODULE, __stdcall, LOADLIBRARYEXA_, (PCSTR, HANDLE, DWORD));
HMODULE hmod = DHW_ORIGINAL(LOADLIBRARYEXA_, getLoadLibraryExAHooker())(path, file, flags);
ModuleLoaded(hmod, flags);
return hmod;
}
// static
FARPROC WINAPI
DHWImportHooker::GetProcAddress(HMODULE aModule, PCSTR aFunctionName)
{
FARPROC pfn = gRealGetProcAddress(aModule, aFunctionName);
if(pfn)
{
nsAutoLock lock(gLock);
for(DHWImportHooker* cur = gHooks; cur; cur = cur->mNext)
{
if(pfn == cur->mOriginal)
{
pfn = cur->mHook;
break;
}
}
}
return pfn;
}
/***************************************************************************/
#if 0
static _CRT_ALLOC_HOOK defaultDbgAllocHook = nsnull;
static DHWAllocationSizeDebugHook* gAllocationSizeHook = nsnull;
int __cdecl dhw_DbgAllocHook(int nAllocType, void *pvData,
size_t nSize, int nBlockUse, long lRequest,
const unsigned char * szFileName, int nLine )
{
DHWAllocationSizeDebugHook* hook = gAllocationSizeHook;
if(hook)
{
PRBool res;
_CrtSetAllocHook(defaultDbgAllocHook);
switch(nAllocType)
{
case _HOOK_ALLOC:
res = hook->AllocHook(nSize);
break;
case _HOOK_REALLOC:
res = hook->ReallocHook(nSize, pvData ?
_msize_dbg(pvData, nBlockUse) : 0);
break;
case _HOOK_FREE:
res = hook->FreeHook(pvData ?
_msize_dbg(pvData, nBlockUse) : 0);
break;
default:
NS_ASSERTION(0,"huh?");
res = PR_TRUE;
break;
}
_CrtSetAllocHook(dhw_DbgAllocHook);
return (int) res;
}
return 1;
}
PRBool
dhwSetAllocationSizeDebugHook(DHWAllocationSizeDebugHook* hook)
{
if(!hook || gAllocationSizeHook)
return PR_FALSE;
gAllocationSizeHook = hook;
if(!defaultDbgAllocHook)
defaultDbgAllocHook = _CrtSetAllocHook(dhw_DbgAllocHook);
else
_CrtSetAllocHook(dhw_DbgAllocHook);
return PR_TRUE;
}
PRBool
dhwClearAllocationSizeDebugHook()
{
if(!gAllocationSizeHook)
return PR_FALSE;
gAllocationSizeHook = nsnull;
_CrtSetAllocHook(defaultDbgAllocHook);
return PR_TRUE;
}
#endif //0

View File

@@ -1,250 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* John Bandhauer <jband@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* Win32 x86 code for stack walking, symbol resolution, and function hooking */
#ifndef __nsDebugHelpWin32_h__
#define __nsDebugHelpWin32_h__
#if defined(_WIN32) && defined(_M_IX86)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <imagehlp.h>
#include <crtdbg.h>
#else
#error "nsDebugHelpWin32.h should only be included in Win32 x86 builds"
#endif
// XXX temporary hack...
//#include "hacky_defines.h"
/***************************************************************************/
// useful macros...
#define DHW_DECLARE_FUN_TYPE(retval_, conv_, typename_, args_) \
typedef retval_ ( conv_ * typename_ ) args_ ;
#ifdef DHW_IMPLEMENT_GLOBALS
#define DHW_DECLARE_FUN_GLOBAL(typename_, name_) typename_ dhw##name_
#else
#define DHW_DECLARE_FUN_GLOBAL(typename_, name_) extern typename_ dhw##name_
#endif
#define DHW_DECLARE_FUN_PROTO(retval_, conv_, name_, args_) \
retval_ conv_ name_ args_
#define DHW_DECLARE_FUN_STATIC_PROTO(retval_, name_, args_) \
static retval_ conv_ name_ args_
#define DHW_DECLARE_FUN_TYPE_AND_PROTO(name_, retval_, conv_, typename_, args_) \
DHW_DECLARE_FUN_TYPE(retval_, conv_, typename_, args_); \
DHW_DECLARE_FUN_PROTO(retval_, conv_, name_, args_)
#define DHW_DECLARE_FUN_TYPE_AND_STATIC_PROTO(name_, retval_, conv_, typename_, args_) \
DHW_DECLARE_FUN_TYPE(retval_, conv_, typename_, args_); \
DHW_DECLARE_FUN_STATIC_PROTO(retval_, conv_, name_, args_)
#define DHW_DECLARE_FUN_TYPE_AND_GLOBAL(typename_, name_, retval_, conv_, args_) \
DHW_DECLARE_FUN_TYPE(retval_, conv_, typename_, args_); \
DHW_DECLARE_FUN_GLOBAL(typename_, name_)
/**********************************************************/
// These are used to get 'original' function addresses from DHWImportHooker.
#define DHW_DECLARE_ORIGINAL(type_, name_, hooker_) \
type_ name_ = (type_) hooker_ . GetOriginalFunction()
#define DHW_DECLARE_ORIGINAL_PTR(type_, name_, hooker_) \
type_ name_ = (type_) hooker_ -> GetOriginalFunction()
#define DHW_ORIGINAL(type_, hooker_) \
((type_) hooker_ . GetOriginalFunction())
#define DHW_ORIGINAL_PTR(type_, hooker_) \
((type_) hooker_ -> GetOriginalFunction())
/***************************************************************************/
// Global declarations of entry points into ImgHelp functions
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMINITIALIZEPROC, SymInitialize, \
BOOL, __stdcall, (HANDLE, LPSTR, BOOL));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMSETOPTIONS, SymSetOptions, \
DWORD, __stdcall, (DWORD));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETOPTIONS, SymGetOptions, \
DWORD, __stdcall, ());
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETMODULEINFO, SymGetModuleInfo, \
BOOL, __stdcall, (HANDLE, DWORD, PIMAGEHLP_MODULE));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETSYMFROMADDRPROC, SymGetSymFromAddr, \
BOOL, __stdcall, (HANDLE, DWORD, PDWORD, PIMAGEHLP_SYMBOL));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(ENUMERATELOADEDMODULES, EnumerateLoadedModules, \
BOOL, __stdcall, (HANDLE, PENUMLOADED_MODULES_CALLBACK, PVOID));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(IMAGEDIRECTORYENTRYTODATA, ImageDirectoryEntryToData, \
PVOID, __stdcall, (PVOID, BOOL, USHORT, PULONG));
// We aren't using any of the below yet...
/*
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMCLEANUPPROC, SymCleanup, \
BOOL, __stdcall, (HANDLE));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(STACKWALKPROC, StackWalk, \
BOOL,
__stdcall,
(DWORD, HANDLE, HANDLE, LPSTACKFRAME, LPVOID, \
PREAD_PROCESS_MEMORY_ROUTINE, \
PFUNCTION_TABLE_ACCESS_ROUTINE, \
PGET_MODULE_BASE_ROUTINE, \
PTRANSLATE_ADDRESS_ROUTINE));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMFUNCTIONTABLEACCESSPROC, SymFunctionTableAccess, \
LPVOID, __stdcall, (HANDLE, DWORD));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETMODULEBASEPROC, SymGetModuleBase, \
DWORD, __stdcall, (HANDLE, DWORD));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMLOADMODULE, SymLoadModule, \
DWORD, __stdcall, (HANDLE, HANDLE, PSTR, PSTR, DWORD, DWORD));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(UNDECORATESYMBOLNAME, _UnDecorateSymbolName, \
DWORD, __stdcall, (LPCSTR, LPSTR, DWORD, DWORD));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMUNDNAME, SymUnDName, \
BOOL, __stdcall, (PIMAGEHLP_SYMBOL, LPSTR, DWORD));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETLINEFROMADDR, SymGetLineFromAddr, \
BOOL, __stdcall, (HANDLE, DWORD, PDWORD, PIMAGEHLP_LINE));
*/
/***************************************************************************/
extern PRBool
dhwEnsureImageHlpInitialized();
extern PRBool
dhwEnsureSymInitialized();
/***************************************************************************/
DHW_DECLARE_FUN_TYPE(FARPROC, __stdcall, GETPROCADDRESS, (HMODULE, PCSTR));
class DHWImportHooker
{
public:
DHWImportHooker(const char* aModuleName,
const char* aFunctionName,
PROC aHook,
PRBool aExcludeOurModule = PR_FALSE);
~DHWImportHooker();
PROC GetOriginalFunction() {return mOriginal;}
PRBool PatchAllModules();
PRBool PatchOneModule(HMODULE aModule, const char* name);
static PRBool ModuleLoaded(HMODULE aModule, DWORD flags);
// I think that these should be made not static members, but allocated
// things created in an explicit static 'init' method and cleaned up in
// an explicit static 'finish' method. This would allow the application
// to have proper lifetime control over all the hooks.
static DHWImportHooker &getLoadLibraryWHooker();
static DHWImportHooker &getLoadLibraryExWHooker();
static DHWImportHooker &getLoadLibraryAHooker();
static DHWImportHooker &getLoadLibraryExAHooker();
static DHWImportHooker &getGetProcAddressHooker();
static HMODULE WINAPI LoadLibraryA(PCSTR path);
private:
DHWImportHooker* mNext;
const char* mModuleName;
const char* mFunctionName;
PROC mOriginal;
PROC mHook;
HMODULE mIgnoreModule;
PRBool mHooking;
private:
static PRLock* gLock;
static DHWImportHooker* gHooks;
static GETPROCADDRESS gRealGetProcAddress;
static HMODULE WINAPI LoadLibraryW(PCWSTR path);
static HMODULE WINAPI LoadLibraryExW(PCWSTR path, HANDLE file, DWORD flags);
static HMODULE WINAPI LoadLibraryExA(PCSTR path, HANDLE file, DWORD flags);
static FARPROC WINAPI GetProcAddress(HMODULE aModule, PCSTR aFunctionName);
};
/***************************************************************************/
// This supports the _CrtSetAllocHook based hooking.
// This system sucks because you don't get to see the allocated pointer. I
// don't think it appropriate for nsTraceMalloc, but is useful as a means to make
// malloc fail for testing purposes.
#if 0 //comment out this stuff. not necessary
class DHWAllocationSizeDebugHook
{
public:
virtual PRBool AllocHook(size_t size) = 0;
virtual PRBool ReallocHook(size_t size, size_t sizeOld) = 0;
virtual PRBool FreeHook(size_t size) = 0;
};
extern PRBool dhwSetAllocationSizeDebugHook(DHWAllocationSizeDebugHook* hook);
extern PRBool dhwClearAllocationSizeDebugHook();
/***************************************************************************/
#endif //0
#endif /* __nsDebugHelpWin32_h__ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,216 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is nsTraceMalloc.c/bloatblame.c code, released
* April 19, 2000.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Brendan Eich, 14-April-2000
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*/
#ifndef nsTraceMalloc_h___
#define nsTraceMalloc_h___
#include "prtypes.h"
PR_BEGIN_EXTERN_C
/**
* Magic "number" at start of a trace-malloc log file. Inspired by the PNG
* magic string, which inspired XPCOM's typelib (.xpt) file magic. See the
* NS_TraceMallocStartup comment (below) for magic number differences in log
* file structure.
*/
#define NS_TRACE_MALLOC_MAGIC "XPCOM\nTMLog08\r\n\032"
#define NS_TRACE_MALLOC_MAGIC_SIZE 16
/**
* Trace-malloc stats, traced via the 'Z' event at the end of a log file.
*/
typedef struct nsTMStats {
uint32 calltree_maxstack;
uint32 calltree_maxdepth;
uint32 calltree_parents;
uint32 calltree_maxkids;
uint32 calltree_kidhits;
uint32 calltree_kidmisses;
uint32 calltree_kidsteps;
uint32 callsite_recurrences;
uint32 backtrace_calls;
uint32 backtrace_failures;
uint32 btmalloc_failures;
uint32 dladdr_failures;
uint32 malloc_calls;
uint32 malloc_failures;
uint32 calloc_calls;
uint32 calloc_failures;
uint32 realloc_calls;
uint32 realloc_failures;
uint32 free_calls;
uint32 null_free_calls;
} nsTMStats;
#define NS_TMSTATS_STATIC_INITIALIZER {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
/**
* Call NS_TraceMallocStartup with a valid file descriptor to enable logging
* of compressed malloc traces, including callsite chains. Integers may be
* unsigned serial numbers, sizes, or offsets, and require at most 32 bits.
* They're encoded as follows:
* 0-127 0xxxxxxx (binary, one byte)
* 128-16383 10xxxxxx xxxxxxxx
* 16384-0x1fffff 110xxxxx xxxxxxxx xxxxxxxx
* 0x200000-0xfffffff 1110xxxx xxxxxxxx xxxxxxxx xxxxxxxx
* 0x10000000-0xffffffff 11110000 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx
* Strings are NUL-terminated ASCII.
*
* Event Operands (magic TMLog01)
* 'L' library serial, shared object filename string
* 'N' method serial, library serial, demangled name string
* 'S' site serial, parent serial, method serial, calling pc offset
* 'M' site serial, malloc size
* 'C' site serial, calloc size
* 'R' site serial, realloc oldsize, realloc size
* 'F' site serial, free size
*
* Event Operands (magic TMLog02)
* 'Z' serialized struct tmstats (20 unsigned integers),
* maxkids parent callsite serial,
* maxstack top callsite serial
*
* Event Operands (magic TMLog03)
* 'T' seconds, microseconds, caption
*
* Event Operands (magic TMLog04)
* 'R' site serial, realloc size, old site serial, realloc oldsize
*
* Event Operands (magic TMLog05)
* 'M' site serial, address, malloc size
* 'C' site serial, address, calloc size
* 'R' site serial, address, realloc size, old site serial,
* old address, old size
* 'F' site serial, address, free size
*
* Event Operands (magic TMLog06)
* 'M' site serial, interval, address, malloc size
* 'C' site serial, interval, address, calloc size
* 'R' site serial, interval, address, realloc size, old site serial,
* old address, old size
* 'F' site serial, interval, address, free size
*
* Event Operands (magic TMLog07)
* no one documented their changes.
* best of luck....
*
* Event Operands (magic TMLog08)
* 'G' filename serial, source filename string.
* 'N' method serial, library serial, source filename serial,
* source file linenumber, demangled name string
*
* See tools/trace-malloc/bloatblame.c for an example log-file reader.
*/
#define TM_EVENT_LIBRARY 'L'
#define TM_EVENT_FILENAME 'G'
#define TM_EVENT_METHOD 'N'
#define TM_EVENT_CALLSITE 'S'
#define TM_EVENT_MALLOC 'M'
#define TM_EVENT_CALLOC 'C'
#define TM_EVENT_REALLOC 'R'
#define TM_EVENT_FREE 'F'
#define TM_EVENT_STATS 'Z'
#define TM_EVENT_TIMESTAMP 'T'
PR_EXTERN(void) NS_TraceMallocStartup(int logfd);
/**
* Initialize malloc tracing, using the ``standard'' startup arguments.
*/
PR_EXTERN(int) NS_TraceMallocStartupArgs(int argc, char* argv[]);
/**
* Stop all malloc tracing, flushing any buffered events to the logfile.
*/
PR_EXTERN(void) NS_TraceMallocShutdown(void);
/**
* Disable malloc tracing.
*/
PR_EXTERN(void) NS_TraceMallocDisable(void);
/**
* Enable malloc tracing.
*/
PR_EXTERN(void) NS_TraceMallocEnable(void);
/**
* Change the log file descriptor, flushing any buffered output to the old
* fd, and writing NS_TRACE_MALLOC_MAGIC to the new file if it is zero length.
* Return the old fd, so the caller can swap open fds. Return -2 on failure,
* which means malloc failure.
*/
PR_EXTERN(int) NS_TraceMallocChangeLogFD(int fd);
/**
* Close the file descriptor fd and forget any bookkeeping associated with it.
* Do nothing if fd is -1.
*/
PR_EXTERN(void) NS_TraceMallocCloseLogFD(int fd);
/**
* Emit a timestamp event with the given caption to the current log file.
*/
PR_EXTERN(void) NS_TraceMallocLogTimestamp(const char *caption);
/**
* Walk the stack, dumping frames in standard form to ofp. If skip is 0,
* exclude the frames for NS_TraceStack and anything it calls to do the walk.
* If skip is less than 0, include -skip such frames. If skip is positive,
* exclude that many frames leading to the call to NS_TraceStack.
*/
PR_EXTERN(void)
NS_TraceStack(int skip, FILE *ofp);
/**
* Dump a human-readable listing of current allocations and their compressed
* stack backtraces to the file named by pathname. Beware this file may have
* very long lines.
*
* Return -1 on error with errno set by the system, 0 on success.
*/
PR_EXTERN(int)
NS_TraceMallocDumpAllocations(const char *pathname);
/**
* Flush all logfile buffers.
*/
PR_EXTERN(void)
NS_TraceMallocFlushLogfiles(void);
PR_END_EXTERN_C
#endif /* nsTraceMalloc_h___ */

View File

@@ -1,20 +0,0 @@
#ifndef NSTRACEMALLOCCALLBACKS_H
#define NSTRACEMALLOCCALLBACKS_H
PR_BEGIN_EXTERN_C
PR_EXTERN(void) StartupHooker();/*implemented in TraceMalloc.cpp*/
PR_EXTERN(void) ShutdownHooker();
PR_EXTERN(void) MallocCallback(void *aPtr, size_t aSize, PRUint32 start, PRUint32 end);/*implemented in nsTraceMalloc.c*/
PR_EXTERN(void) CallocCallback(void *aPtr, size_t aCount, size_t aSize, PRUint32 start, PRUint32 end);
PR_EXTERN(void) ReallocCallback(void *aPin, void* aPout, size_t aSize, PRUint32 start, PRUint32 end);
PR_EXTERN(void) FreeCallback(void *aPtr, PRUint32 start, PRUint32 end);
PR_END_EXTERN_C
#endif //NSTRACEMALLOCCALLBACKS_H

View File

@@ -1,292 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is nsTypeInfo.cpp code, released
* November 27, 2000.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Patrick C. Beard <beard@netscape.com>
* Chris Waterson <waterson@netscape.com>
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*/
/*
typeinfo.cpp
Speculatively use RTTI on a random object. If it contains a pointer at offset 0
that is in the current process' address space, and that so on, then attempt to
use C++ RTTI's typeid operation to obtain the name of the type.
by Patrick C. Beard.
*/
#include <typeinfo>
#include <ctype.h>
extern "C" const char* nsGetTypeName(void* ptr);
class IUnknown {
public:
virtual long QueryInterface() = 0;
virtual long AddRef() = 0;
virtual long Release() = 0;
};
#if defined(MACOS)
#include <Processes.h>
class AddressSpace {
public:
AddressSpace();
Boolean contains(void* ptr);
private:
ProcessInfoRec mInfo;
};
AddressSpace::AddressSpace()
{
ProcessSerialNumber psn = { 0, kCurrentProcess };
mInfo.processInfoLength = sizeof(mInfo);
::GetProcessInformation(&psn, &mInfo);
}
Boolean AddressSpace::contains(void* ptr)
{
UInt32 start = UInt32(mInfo.processLocation);
return (UInt32(ptr) >= start && UInt32(ptr) < (start + mInfo.processSize));
}
const char* nsGetTypeName(void* ptr)
{
// construct only one of these per process.
static AddressSpace space;
// sanity check the vtable pointer, before trying to use RTTI on the object.
void** vt = *(void***)ptr;
if (vt && !(unsigned(vt) & 0x3) && space.contains(vt) && space.contains(*vt)) {
IUnknown* u = static_cast<IUnknown*>(ptr);
const char* type = typeid(*u).name();
// make sure it looks like a C++ identifier.
if (type && (isalnum(type[0]) || type[0] == '_'))
return type;
}
return "void*";
}
#endif
// New, more "portable" Linux code is below, but this might be a useful
// model for other platforms, so keeping.
//#if defined(linux)
#if 0
#include <signal.h>
#include <setjmp.h>
static jmp_buf context;
static void handler(int signum)
{
longjmp(context, signum);
}
#define attempt() setjmp(context)
class Signaller {
public:
Signaller(int signum);
~Signaller();
private:
typedef void (*handler_t) (int signum);
int mSignal;
handler_t mOldHandler;
};
Signaller::Signaller(int signum)
: mSignal(signum), mOldHandler(signal(signum, &handler))
{
}
Signaller::~Signaller()
{
signal(mSignal, mOldHandler);
}
// The following are pointers that bamboozle our otherwise feeble
// attempts to "safely" collect type names.
//
// XXX this kind of sucks because it means that anyone trying to use
// this without NSPR will get unresolved symbols when this library
// loads. It's also not very extensible. Oh well: FIX ME!
extern "C" {
// from nsprpub/pr/src/io/priometh.c (libnspr4.so)
extern void* _pr_faulty_methods;
};
static inline int
sanity_check_vtable_i386(void** vt)
{
// Now that we're "safe" inside the signal handler, we can
// start poking around. If we're really an object with
// RTTI, then the second entry in the vtable should point
// to a function.
//
// Let's see if the second entry:
//
// 1) looks like a 4-byte aligned pointer
//
// 2) points to something that looks like the following
// i386 instructions:
//
// 55 push %ebp
// 89e5 mov %esp,%ebp
// 53 push %ebx
//
// or
//
// 55 push %ebp
// 89e5 mov %esp,%ebp
// 56 push %esi
//
// (which is the standard function prologue generated
// by egcs, plus a ``signature'' instruction that appears
// in the typeid() function's implementation).
unsigned char** fp1 = reinterpret_cast<unsigned char**>(vt) + 1;
// Does it look like an address?
unsigned char* ip = *fp1;
if ((unsigned(ip) & 3) != 0)
return 0;
// Does it look like it refers to the standard prologue?
static unsigned char prologue[] = { 0x55, 0x89, 0xE5 };
for (unsigned i = 0; i < sizeof(prologue); ++i)
if (*ip++ != prologue[i])
return 0;
// Is the next instruction a `push %ebx' or `push %esi'?
if (*ip == 0x53 || *ip == 0x56) {
return 1;
}
// Nope. There's another variant that has a `sub' instruction,
// followed by a `cmpl' and a `jne'. Check for that.
if (ip[0] == 0x83 && ip[1] == 0xec // sub
&& ip[3] == 0x83 && ip[4] == 0x3d // cmpl
&& ip[10] == 0x75 // jne
) {
return 1;
}
return 0;
}
static inline int
sanity_check_vtable_ppc(void** vt)
{
// XXX write me!
return 1;
}
#if defined(__i386)
# define SANITY_CHECK_VTABLE(vt) (sanity_check_vtable_i386(vt))
#elif defined(PPC)
# define SANITY_CHECK_VTABLE(vt) (sanity_check_vtable_ppc(vt))
#else
# define SANITY_CHECK_VTABLE(vt) (1)
#endif
const char* nsGetTypeName(void* ptr)
{
// sanity check the vtable pointer, before trying to use RTTI on the object.
void** vt = *(void***)ptr;
if (vt && !(unsigned(vt) & 3) && (vt != &_pr_faulty_methods)) {
Signaller s1(SIGSEGV);
if (attempt() == 0) {
if (SANITY_CHECK_VTABLE(vt)) {
// Looks like a function: what the hell, let's call it.
IUnknown* u = static_cast<IUnknown*>(ptr);
const char* type = typeid(*u).name();
// EGCS seems to prefix a length string.
while (isdigit(*type)) ++type;
return type;
}
}
}
return "void*";
}
#endif
#if defined(linux)
#define __USE_GNU
#include <dlfcn.h>
#include <ctype.h>
#include <string.h>
const char* nsGetTypeName(void* ptr)
{
#if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100 /* G++ V3 ABI */
const int expected_offset = 8;
const char vtable_sym_start[] = "_ZTV";
const int vtable_sym_start_length = sizeof(vtable_sym_start) - 1;
#else
const int expected_offset = 0;
const char vtable_sym_start[] = "__vt_";
const int vtable_sym_start_length = sizeof(vtable_sym_start) - 1;
#endif
void* vt = *(void**)ptr;
Dl_info info;
// If dladdr fails, if we're not at the expected offset in the vtable,
// or if the symbol name isn't a vtable symbol name, return "void*".
if ( !dladdr(vt, &info) ||
((char*)info.dli_saddr) + expected_offset != vt ||
!info.dli_sname ||
strncmp(info.dli_sname, vtable_sym_start, vtable_sym_start_length))
return "void*";
// skip the garbage at the beginning of things like
// __vt_14nsRootBoxFrame (gcc 2.96) or _ZTV14nsRootBoxFrame (gcc 3.0)
const char* rv = info.dli_sname + vtable_sym_start_length;
while (*rv && isdigit(*rv))
++rv;
return rv;
}
#endif
#ifdef XP_WIN32
const char* nsGetTypeName(void* ptr)
{
//TODO: COMPLETE THIS
return "void*";
}
#endif //XP_WIN32

View File

@@ -1,438 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "prtypes.h"
#include "prlock.h"
#include "nscore.h"
#include "nsAutoLock.h"
#include "nsDebugHelpWin32.h"
#include "nsTraceMallocCallbacks.h"
// XXX These are *very* quick hacks and need improvement!
static PRBool GetSymbolFromAddress(uint32 addr, char* outBuf)
{
PRBool ok;
ok = dhwEnsureSymInitialized();
if(!ok)
return ok;
char buf[sizeof(IMAGEHLP_SYMBOL) + 512];
PIMAGEHLP_SYMBOL symbol = (PIMAGEHLP_SYMBOL) buf;
symbol->SizeOfStruct = sizeof(buf);
symbol->MaxNameLength = 512;
DWORD displacement;
ok = dhwSymGetSymFromAddr(::GetCurrentProcess(),
addr,
&displacement,
symbol);
if(ok)
{
char buf2[512];
sprintf(buf2, "%s+0x%08X", symbol->Name, displacement);
strcat(outBuf, buf2);
}
else
strcat(outBuf, "dunno");
return ok;
}
static PRBool GetModuleFromAddress(uint32 addr, char* outBuf)
{
PRBool ok;
ok = dhwEnsureSymInitialized();
if(!ok)
return ok;
IMAGEHLP_MODULE module;
module.SizeOfStruct = sizeof(IMAGEHLP_MODULE);
ok = dhwSymGetModuleInfo(::GetCurrentProcess(),
addr,
&module);
if(ok)
strcat(outBuf, module.ModuleName);
else
strcat(outBuf, "dunno");
return ok;
}
/***************************************************************************/
#ifdef VERBOSE
#define SHOW(x_, buf_) \
printf(#x_" = %#x... %s\n", x_, \
(buf_[0] = 0, \
GetModuleFromAddress((uint32)x_, buf_), \
strcat(buf," :: "), \
GetSymbolFromAddress((uint32)x_, buf_), \
buf_));
#else
#define SHOW(x_, buf_)
#endif //VERBOSE
/***************************************************************************/
#ifdef VERBOSE
// XXX This is a quick hack to show that x86 Win32 stack walking can be done
// with this sort of loop following the bp.
void dumpStack()
{
uint32* bp_;
uint32* bpdown;
uint32 pc;
char buf[512];
_asm { mov bp_ , ebp }
/* Stack walking code adapted from Kipp's "leaky". */
while (1) {
bpdown = (uint32*) *bp_++;
pc = *bp_;
// These addresses are iffy...
if (pc < 0x00400000 || pc > 0x7fffffff || bpdown < bp_)
break;
SHOW(pc, buf);
bp_ = bpdown;
}
printf("\n");
}
#endif
char* _stdcall call2(void* v)
{
// dumpStack();
// return 0;
return (char *)malloc(123);
}
int call1(char c, int i, double d, ... )
{
free(call2(0));
return 0;
}
/***************************************************************************/
// shows how to use the dhw stuff to hook imported functions
static BOOL g_lockOut = FALSE; //stop reentrancy
DHW_DECLARE_FUN_TYPE_AND_PROTO(dhw_malloc, void*, __cdecl, MALLOC_, (size_t));
DHWImportHooker &getMallocHooker()
{
static DHWImportHooker gMallocHooker("MSVCRTD.dll", "malloc", (PROC) dhw_malloc);
return gMallocHooker;
}
void * __cdecl dhw_malloc( size_t size )
{
PRUint32 start = PR_IntervalNow();
void* result = DHW_ORIGINAL(MALLOC_, getMallocHooker())(size);
PRUint32 end = PR_IntervalNow();
if (g_lockOut)
return result;
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* malloc called to get %d bytes. returned %#x\n", size, result);
#endif
MallocCallback(result, size, start, end);
// dumpStack();
// printf("\n");
g_lockOut = FALSE;
return result;
}
DHW_DECLARE_FUN_TYPE_AND_PROTO(dhw_calloc, void*, __cdecl, CALLOC_, (size_t,size_t));
DHWImportHooker &getCallocHooker()
{
static DHWImportHooker gCallocHooker("MSVCRTD.dll", "calloc", (PROC) dhw_calloc);
return gCallocHooker;
}
void * __cdecl dhw_calloc( size_t count, size_t size )
{
PRUint32 start = PR_IntervalNow();
void* result = DHW_ORIGINAL(CALLOC_, getCallocHooker())(count,size);
PRUint32 end = PR_IntervalNow();
if (g_lockOut)
return result;
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* calloc called to get %d many of %d bytes. returned %#x\n", count, size, result);
#endif
CallocCallback(result, count, size, start, end);
// dumpStack();
// printf("\n");
g_lockOut = FALSE;
return result;
}
DHW_DECLARE_FUN_TYPE_AND_PROTO(dhw_free, void, __cdecl, FREE_, (void*));
DHWImportHooker &getFreeHooker()
{
static DHWImportHooker gFreeHooker("MSVCRTD.dll", "free", (PROC) dhw_free);
return gFreeHooker;
}
void __cdecl dhw_free( void* p )
{
PRUint32 start = PR_IntervalNow();
DHW_ORIGINAL(FREE_, getFreeHooker())(p);
PRUint32 end = PR_IntervalNow();
if (g_lockOut)
return;
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* free called for %#x\n", p);
#endif
FreeCallback(p, start, end);
// dumpStack();
// printf("\n");
g_lockOut = FALSE;
}
DHW_DECLARE_FUN_TYPE_AND_PROTO(dhw_realloc, void*, __cdecl, REALLOC_, (void*, size_t));
DHWImportHooker &getReallocHooker()
{
static DHWImportHooker gReallocHooker("MSVCRTD.dll", "realloc", (PROC) dhw_realloc);
return gReallocHooker;
}
void * __cdecl dhw_realloc(void * pin, size_t size)
{
PRUint32 start = PR_IntervalNow();
void* pout = DHW_ORIGINAL(REALLOC_, getReallocHooker())(pin, size);
PRUint32 end = PR_IntervalNow();
if (g_lockOut)
return pout;
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* realloc called to resize to %d. old ptr: %#x. new ptr: %#x\n",
size, pin, pout);
#endif
ReallocCallback(pin, pout, size, start, end);
// dumpStack();
// printf("\n");
g_lockOut = FALSE;
return pout;
}
// Note the mangled name!
DHW_DECLARE_FUN_TYPE_AND_PROTO(dhw_new, void*, __cdecl, NEW_, (size_t));
DHWImportHooker &getNewHooker()
{
static DHWImportHooker gNewHooker("MSVCRTD.dll", "??2@YAPAXI@Z", (PROC) dhw_new);
return gNewHooker;
}
void * __cdecl dhw_new(size_t size)
{
PRUint32 start = PR_IntervalNow();
void* result = DHW_ORIGINAL(NEW_, getNewHooker())(size);
PRUint32 end = PR_IntervalNow();
if (g_lockOut)
return result;
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* new called to get %d bytes. returned %#x\n", size, result);
dumpStack();
#endif
MallocCallback(result, size, start, end);//do we need a different one for new?
// printf("\n");
g_lockOut = FALSE;
return result;
}
// Note the mangled name!
DHW_DECLARE_FUN_TYPE_AND_PROTO(dhw_delete, void, __cdecl, DELETE_, (void*));
DHWImportHooker &getDeleteHooker()
{
static DHWImportHooker gDeleteHooker("MSVCRTD.dll", "??3@YAXPAX@Z", (PROC) dhw_delete);
return gDeleteHooker;
}
void __cdecl dhw_delete(void* p)
{
PRUint32 start = PR_IntervalNow();
DHW_ORIGINAL(DELETE_, getDeleteHooker())(p);
PRUint32 end = PR_IntervalNow();
if (g_lockOut)
return;
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* delete called for %#x\n", p);
dumpStack();
#endif
FreeCallback(p, start, end);
// printf("\n");
g_lockOut = FALSE;
}
/***************************************************************************/
// A demonstration of using the _CrtSetAllocHook based hooking.
// This system sucks because you don't get to see the allocated pointer.
#if 0
class myAllocationSizePrinter : public DHWAllocationSizeDebugHook
{
public:
PRBool AllocHook(size_t size)
{
alloc_calls++ ;
total_mem += size;
if(verbosity)
{
printf("alloc called to get %d bytes.\n", size);
dumpStack();
}
return PR_TRUE;
}
PRBool ReallocHook(size_t size, size_t sizeOld)
{
realloc_calls++ ;
total_mem += size;
total_mem -= sizeOld;
if(verbosity)
{
printf("realloc called to size to %d bytes. Old size: %d.\n",
size, sizeOld);
dumpStack();
}
return PR_TRUE;
}
PRBool FreeHook(size_t size)
{
free_calls++ ;
total_mem -= size;
if(verbosity)
{
printf("free called to release %d bytes.\n", size);
dumpStack();
}
return PR_TRUE;
}
myAllocationSizePrinter(int v)
: verbosity(v),
alloc_calls(0),
realloc_calls(0),
free_calls(0),
total_mem(0) {}
virtual ~myAllocationSizePrinter(){}
void report()
{
printf("%d allocs, %d reallocs, %d frees, %d bytes leaked\n",
alloc_calls, realloc_calls, free_calls, total_mem);
}
private:
void dumpStack()
{
if(verbosity == 2)
::dumpStack();
}
int verbosity;
int alloc_calls;
int realloc_calls;
int free_calls;
size_t total_mem;
};
#endif
/*C Callbacks*/
PR_IMPLEMENT(void)
StartupHooker()
{
if (!dhwEnsureSymInitialized())
return;
//run through get all hookers
DHWImportHooker &loadlibraryW = DHWImportHooker::getLoadLibraryWHooker();
DHWImportHooker &loadlibraryExW = DHWImportHooker::getLoadLibraryExWHooker();
DHWImportHooker &loadlibraryA = DHWImportHooker::getLoadLibraryAHooker();
DHWImportHooker &loadlibraryExA = DHWImportHooker::getLoadLibraryExAHooker();
DHWImportHooker &mallochooker = getMallocHooker();
DHWImportHooker &reallochooker = getReallocHooker();
DHWImportHooker &callochooker = getCallocHooker();
DHWImportHooker &freehooker = getFreeHooker();
DHWImportHooker &newhooker = getNewHooker();
DHWImportHooker &deletehooker = getDeleteHooker();
printf("Startup Hooker\n");
}
PR_IMPLEMENT(void)
ShutdownHooker()
{
}
#if 0
int main()
{
// A demonstration of using the (sucky) _CrtSetAllocHook based hooking.
myAllocationSizePrinter ap(0);
dhwSetAllocationSizeDebugHook(&ap);
// show that the ImportHooker is hooking calls from loaded dll
DHW_DECLARE_FUN_TYPE(void, __stdcall, SOMECALL_, (void));
HMODULE module = ::LoadLibrary("Other.dll");
if(module) {
SOMECALL_ _SomeCall = (SOMECALL_) GetProcAddress(module, "SomeCall");
if(_SomeCall)
_SomeCall();
}
// show that the ImportHooker is hooking sneaky calls made from this dll.
HMODULE module2 = ::LoadLibrary("MSVCRTD.dll");
if(module2) {
MALLOC_ _sneakyMalloc = (MALLOC_) GetProcAddress(module2, "malloc");
if(_sneakyMalloc)
{
void* p = _sneakyMalloc(987);
free(p);
}
}
call1('x', 1, 1.0, "hi there", 2);
char* p = new char[10];
delete p;
void* v = malloc(10);
v = realloc(v, 15);
v = realloc(v, 5);
free(v);`
ap.report();
dhwClearAllocationSizeDebugHook();
return 0;
}
#endif //0

View File

@@ -1,59 +0,0 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = \
typelib \
glue \
base \
ds \
io \
components \
threads \
reflect \
proxy \
build \
tools \
$(NULL)
ifeq ($(OS_ARCH),WINNT)
ifdef MOZ_DEBUG
DIRS += windbgdlg
endif
endif
ifdef ENABLE_TESTS
DIRS += \
sample \
typelib/xpt/tests \
reflect/xptinfo/tests \
reflect/xptcall/tests \
proxy/tests
endif
include $(topsrcdir)/config/rules.mk

File diff suppressed because it is too large Load Diff

View File

@@ -1,17 +0,0 @@
nsAgg.h
nsIAllocator.h
nsCom.h
nsComObsolete.h
nsCWeakReference.h
nsError.h
nsID.h
nsIID.h
nsISupportsBase.h
nsISupportsImpl.h
nsISupportsUtils.h
nsISupportsObsolete.h
nsIWeakReferenceUtils.h
nsTraceRefcnt.h
nsWeakPtr.h
nscore.h
nsIInterfaceRequestorUtils.h

View File

@@ -1,11 +0,0 @@
nsISupports.idl
nsIMemory.idl
nsrootidl.idl
nsIInterfaceRequestor.idl
nsIConsoleService.idl
nsIConsoleMessage.idl
nsIConsoleListener.idl
nsIWeakReference.idl
nsIException.idl
nsIExceptionService.idl
nsIProgrammingLanguage.idl

View File

@@ -1,133 +0,0 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpcom
XPIDL_MODULE = xpcom_base
LIBRARY_NAME = xpcombase_s
REQUIRES = string \
$(NULL)
CPPSRCS = \
nsAllocator.cpp \
nsMemoryImpl.cpp \
nsErrorService.cpp \
nsIInterfaceRequestor.cpp \
nsTraceRefcnt.cpp \
nsID.cpp \
nsCWeakReference.cpp \
nsConsoleService.cpp \
nsConsoleMessage.cpp \
nsExceptionService.cpp \
$(NULL)
ifdef GC_LEAK_DETECTOR
CSRCS += nsGarbageCollector.c
CPPSRCS += nsLeakDetector.cpp
REQUIRES += boehm
endif
EXPORTS = \
nsAgg.h \
nsIAllocator.h \
nsCom.h \
nsComObsolete.h \
nsCWeakReference.h \
nsError.h \
nsIID.h \
nsISupportsImpl.h \
nsISupportsUtils.h \
nsISupportsObsolete.h \
nsIWeakReferenceUtils.h \
nsTraceRefcnt.h \
nsWeakPtr.h \
nsIInterfaceRequestorUtils.h \
$(NULL)
ifdef NS_TRACE_MALLOC
CSRCS += nsTraceMalloc.c
CPPSRCS += nsTypeInfo.cpp
ifeq ($(OS_ARCH),WINNT)
CPPSRCS += nsDebugHelpWin32.cpp nsWinTraceMalloc.cpp
endif
EXPORTS += nsTraceMalloc.h
DEFINES += -DNS_TRACE_MALLOC
endif
ifeq ($(OS_ARCH),WINNT)
ifdef MOZ_DEBUG
CSRCS += pure_api.c
EXPORTS += pure.h
endif
endif
SDK_XPIDLSRCS = \
nsIInterfaceRequestor.idl \
nsIProgrammingLanguage.idl \
nsISupports.idl \
nsIWeakReference.idl \
nsIMemory.idl \
nsrootidl.idl \
SDK_HEADERS = \
nsISupportsBase.h \
nscore.h \
nsID.h \
XPIDLSRCS = \
nsIErrorService.idl \
nsIConsoleService.idl \
nsIConsoleMessage.idl \
nsIConsoleListener.idl \
nsIException.idl \
nsIExceptionService.idl \
$(NULL)
ifdef GC_LEAK_DETECTOR
XPIDLSRCS += nsILeakDetector.idl
endif
# we don't want the shared lib, but we want to force the creation of a static lib.
FORCE_STATIC_LIB = 1
# Force use of PIC
FORCE_USE_PIC = 1
include $(topsrcdir)/config/rules.mk
DEFINES += -D_IMPL_NS_COM
ifeq ($(OS_ARCH), Linux)
DEFINES += -D_BSD_SOURCE
endif
ifeq ($(OS_ARCH), WINNT)
DEFINES += -DWIN32_LEAN_AND_MEAN
endif

View File

@@ -1,2 +0,0 @@
en-US.jar:
locale/en-US/global/xpcom.properties

View File

@@ -1,134 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH=..\..
MODULE = xpcom
REQUIRES = string \
$(NULL)
include <$(DEPTH)\config\config.mak>
################################################################################
## exports
EXPORTS = \
nsAgg.h \
nsIAllocator.h \
nsCom.h \
nsComObsolete.h \
nsCWeakReference.h \
nsError.h \
nsID.h \
nsIID.h \
nsISupportsBase.h \
nsISupportsImpl.h \
nsISupportsObsolete.h \
nsISupportsUtils.h \
nsIWeakReferenceUtils.h \
nsTraceRefcnt.h \
nsWeakPtr.h \
nscore.h \
pure.h \
!ifdef MOZ_TRACE_MALLOC
nsTraceMalloc.h \
!endif
nsIInterfaceRequestorUtils.h \
$(NULL)
XPIDL_MODULE = xpcom_base
XPIDLSRCS = \
.\nsrootidl.idl \
.\nsIErrorService.idl \
.\nsIMemory.idl \
.\nsILeakDetector.idl \
.\nsIInterfaceRequestor.idl \
.\nsIException.idl \
.\nsIExceptionService.idl \
.\nsISupports.idl \
# .\nsISystemInfo.idl \
.\nsIWeakReference.idl \
.\nsIConsoleService.idl \
.\nsIConsoleMessage.idl \
.\nsIConsoleListener.idl \
.\nsIProgrammingLanguage.idl \
$(NULL)
################################################################################
## library
#MAKE_OBJ_TYPE = DLL
#LIBNAME = .\$(OBJDIR)\xpcombase
#DLL = $(LIBNAME).dll
LIBRARY_NAME=xpcombase_s
LCFLAGS = -D_IMPL_NS_COM -D_IMPL_NS_BASE -DWIN32_LEAN_AND_MEAN
!ifdef GC_LEAK_DETECTOR
LCFLAGS = $(LCFLAGS) -DGC_LEAK_DETECTOR
!endif
!ifdef MOZ_TRACE_MALLOC
C_OBJS = $(C_OBJS) \
.\$(OBJDIR)\nsTraceMalloc.obj \
$(NULL)
!endif
CPP_OBJS = \
.\$(OBJDIR)\nsErrorService.obj \
.\$(OBJDIR)\nsAllocator.obj \
.\$(OBJDIR)\nsMemoryImpl.obj \
.\$(OBJDIR)\nsCWeakReference.obj \
.\$(OBJDIR)\nsID.obj \
.\$(OBJDIR)\nsIInterfaceRequestor.obj \
# .\$(OBJDIR)\nsSystemInfo.obj \
.\$(OBJDIR)\nsExceptionService.obj \
.\$(OBJDIR)\nsTraceRefcnt.obj \
.\$(OBJDIR)\nsConsoleService.obj \
.\$(OBJDIR)\nsConsoleMessage.obj \
!ifdef GC_LEAK_DETECTOR
.\$(OBJDIR)\nsGarbageCollector.obj \
.\$(OBJDIR)\nsLeakDetector.obj \
!endif
!ifdef MOZ_DEBUG
.\$(OBJDIR)\pure_api.obj \
!endif
!ifdef MOZ_TRACE_MALLOC
.\$(OBJDIR)\nsTypeInfo.obj \
.\$(OBJDIR)\nsDebugHelpWin32.obj \
.\$(OBJDIR)\nsWinTraceMalloc.obj \
!endif
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -1,153 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsAgg_h___
#define nsAgg_h___
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
// Put this in your class's declaration:
#define NS_DECL_AGGREGATED \
NS_DECL_ISUPPORTS \
\
public: \
\
/* You must implement this operation instead of the nsISupports */ \
/* methods if you inherit from nsAggregated. */ \
NS_IMETHOD \
AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr); \
\
protected: \
\
class Internal : public nsISupports { \
public: \
\
Internal() {} \
\
NS_IMETHOD QueryInterface(const nsIID& aIID, \
void** aInstancePtr); \
NS_IMETHOD_(nsrefcnt) AddRef(void); \
NS_IMETHOD_(nsrefcnt) Release(void); \
\
}; \
\
friend class Internal; \
\
nsISupports* fOuter; \
Internal fAggregated; \
\
nsISupports* GetInner(void) { return &fAggregated; } \
\
public: \
// Put this in your class's constructor:
#define NS_INIT_AGGREGATED(outer) \
PR_BEGIN_MACRO \
NS_INIT_REFCNT(); \
fOuter = outer ? outer : &fAggregated; \
PR_END_MACRO
// Put this in your class's implementation file:
#define NS_IMPL_AGGREGATED(_class) \
NS_IMETHODIMP \
_class::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
{ \
return fOuter->QueryInterface(aIID, aInstancePtr); \
} \
\
NS_IMETHODIMP_(nsrefcnt) \
_class::AddRef(void) \
{ \
return fOuter->AddRef(); \
} \
\
NS_IMETHODIMP_(nsrefcnt) \
_class::Release(void) \
{ \
return fOuter->Release(); \
} \
\
NS_IMETHODIMP \
_class::Internal::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
{ \
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
return agg->AggregatedQueryInterface(aIID, aInstancePtr); \
} \
\
NS_IMETHODIMP_(nsrefcnt) \
_class::Internal::AddRef(void) \
{ \
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
NS_PRECONDITION(PRInt32(agg->mRefCnt) >= 0, "illegal refcnt"); \
++agg->mRefCnt; \
NS_LOG_ADDREF(this, agg->mRefCnt, #_class, sizeof(*this)); \
return agg->mRefCnt; \
} \
\
NS_IMETHODIMP_(nsrefcnt) \
_class::Internal::Release(void) \
{ \
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
NS_PRECONDITION(0 != agg->mRefCnt, "dup release"); \
--agg->mRefCnt; \
NS_LOG_RELEASE(this, agg->mRefCnt, #_class); \
if (agg->mRefCnt == 0) { \
agg->mRefCnt = 1; /* stabilize */ \
NS_DELETEXPCOM(agg); \
return 0; \
} \
return agg->mRefCnt; \
} \
// for use with QI macros in nsISupportsUtils.h:
#define NS_IMPL_AGGREGATED_QUERY_HEAD(_class) \
NS_IMETHODIMP \
_class::AggregatedQueryInterface(REFNSIID aIID, void** aInstancePtr) \
{ \
NS_ASSERTION(aInstancePtr, \
"AggregatedQueryInterface requires a non-NULL result ptr!"); \
if ( !aInstancePtr ) \
return NS_ERROR_NULL_POINTER; \
nsISupports* foundInterface;
#endif /* nsAgg_h___ */

View File

@@ -1,41 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
////////////////////////////////////////////////////////////////////////////////
// obsolete
////////////////////////////////////////////////////////////////////////////////

View File

@@ -1,50 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
////////////////////////////////////////////////////////////////////////////////
// obsolete
////////////////////////////////////////////////////////////////////////////////
#ifndef nsAllocator_h__
#define nsAllocator_h__
#include "nsIAllocator.h"
#include "prmem.h"
#include "nsAgg.h"
#include "nsIFactory.h"
#endif // nsAllocator_h__

View File

@@ -1,406 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:cindent:ts=4:et:sw=4:
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is nsAutoPtr.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by the Initial Developer are Copyright (C)
* 2001 the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* L. David Baron <dbaron@fas.harvard.edu> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h" // for |already_AddRefed|
#include "nsMemory.h" // for |nsMemory::Free| for |nsMemoryAutoPtr|
template <class T>
class
nsAutoPtr
{
private:
inline void enter(T* aPtr) { }
inline void exit(T* aPtr) { delete aPtr; }
public:
nsAutoPtr() : mPtr(0) { }
// not |explicit| to allow |nsAutoPtr<T> ptr = foo;|
nsAutoPtr(T* aPtr) : mPtr(aPtr) { enter(aPtr); }
~nsAutoPtr() { exit(mPtr); }
nsAutoPtr<T>&
operator=(T* aPtr)
{
T* temp = mPtr;
enter(aPtr);
mPtr = aPtr;
exit(temp);
return *this;
}
nsAutoPtr<T>&
operator=(nsAutoPtr<T>& aSmartPtr)
{
T* temp = mPtr;
enter(aPtr);
mPtr = aPtr.release();
exit(temp);
return *this;
}
operator T*() const { return mPtr; }
T* get() const { return mPtr; }
T* release() { T* temp = mPtr; mPtr = 0; return temp; }
// To be used only by helpers (such as |getter_Transfers| below)
T** begin_assignment() { mPtr = 0; return &mPtr; }
private:
// Helpers (such as |getter_Transfers| below) should use
// begin_assignment(), others should not do this.
nsAutoPtr<T>* operator&() { return this; }
T* mPtr;
};
template <class T>
class
nsAutoArrayPtr
{
private:
inline void enter(T* aPtr) { }
inline void exit(T* aPtr) { delete [] aPtr; }
public:
nsAutoArrayPtr() : mPtr(0) { }
// not |explicit| to allow |nsAutoArrayPtr<T> ptr = foo;|
nsAutoArrayPtr(T* aPtr) : mPtr(aPtr) { enter(aPtr); }
~nsAutoArrayPtr() { exit(mPtr); }
nsAutoArrayPtr<T>&
operator=(T* aPtr)
{
T* temp = mPtr;
enter(aPtr);
mPtr = aPtr;
exit(temp);
return *this;
}
nsAutoArrayPtr<T>&
operator=(nsAutoArrayPtr<T>& aSmartPtr)
{
T* temp = mPtr;
enter(aPtr);
mPtr = aPtr.release();
exit(temp);
return *this;
}
operator T*() const { return mPtr; }
T* get() const { return mPtr; }
T* release() { T* temp = mPtr; mPtr = 0; return temp; }
// To be used only by helpers (such as |getter_Transfers| below)
T** begin_assignment() { mPtr = 0; return &mPtr; }
private:
// Helpers (such as |getter_Transfers| below) should use
// begin_assignment(), others should not do this.
nsAutoArrayPtr<T>* operator&() { return this; }
T* mPtr;
};
/*
* NOTE: nsMemoryAutoArrayPtr uses nsMemory, not nsIMemory, so using it
* requires linking against the xpcom library.
*/
template <class T>
class
nsMemoryAutoPtr
{
private:
inline void enter(T* aPtr) { }
inline void exit(T* aPtr) { nsMemory::Free(aPtr); }
public:
nsMemoryAutoPtr() : mPtr(0) { }
// not |explicit| to allow |nsMemoryAutoPtr<T> ptr = foo;|
nsMemoryAutoPtr(T* aPtr) : mPtr(aPtr) { enter(aPtr); }
~nsMemoryAutoPtr() { exit(mPtr); }
nsMemoryAutoPtr<T>&
operator=(T* aPtr)
{
T* temp = mPtr;
enter(aPtr);
mPtr = aPtr;
exit(temp);
return *this;
}
nsMemoryAutoPtr<T>&
operator=(nsMemoryAutoPtr<T>& aSmartPtr)
{
T* temp = mPtr;
enter(aPtr);
mPtr = aPtr.release();
exit(temp);
return *this;
}
operator T*() const { return mPtr; }
T* get() const { return mPtr; }
T* release() { T* temp = mPtr; mPtr = 0; return temp; }
// To be used only by helpers (such as |getter_Transfers| below)
T** begin_assignment() { mPtr = 0; return &mPtr; }
private:
// Helpers (such as |getter_Transfers| below) should use
// begin_assignment(), others should not do this.
nsMemoryAutoPtr<T>* operator&() { return this; }
T* mPtr;
};
template <class T>
class
nsRefPtr
{
private:
inline void enter(T* aPtr) { aPtr->AddRef(); }
inline void exit(T* aPtr) { aPtr->Release(); }
public:
nsRefPtr() : mPtr(0) { }
// not |explicit| to allow |nsRefPtr<T> ptr = foo;|
nsRefPtr(T* aPtr) : mPtr(aPtr) { enter(aPtr); }
nsRefPtr(const already_AddRefed<T>& aPtr) : mPtr(aPtr.get()) { }
// needed because ctor for already_AddRefed<T> is not explicit
nsRefPtr(const nsRefPtr<T>& aPtr) : mPtr(aPtr.get()) { enter(mPtr); }
~nsRefPtr() { exit(mPtr); }
nsRefPtr<T>&
operator=(T* aPtr)
{
T* temp = mPtr;
enter(aPtr);
mPtr = aPtr;
exit(temp);
return *this;
}
nsRefPtr<T>&
operator=(already_AddRefed<T> aPtr)
{
T* temp = mPtr;
mPtr = aPtr.get();
exit(temp);
return *this;
}
operator T*() const { return mPtr; }
T* get() const { return mPtr; }
// To be used only by helpers (such as |getter_AddRefs| below)
T** begin_assignment_assuming_AddRef() { mPtr = 0 ; return &mPtr; }
private:
// Helpers (such as |getter_AddRefs| below) should use
// begin_assignment_assuming_AddRef(), others should not do this.
nsRefPtr<T>* operator&() { return this; }
T* mPtr;
};
template <class T>
class
nsAutoPtrGetterTransfers
{
public:
explicit nsAutoPtrGetterTransfers(nsAutoPtr<T>& aSmartPtr)
: mPtrPtr(aSmartPtr.begin_assignment()) { }
operator T**() { return mPtrPtr; }
T& operator*() { return *mPtrPtr; }
private:
T** mPtrPtr;
};
template <class T>
inline nsAutoPtrGetterTransfers<T>
getter_Transfers(nsAutoPtr<T>& aSmartPtr)
{
return nsAutoPtrGetterTransfers<T>(aSmartPtr);
}
template <class T>
class
nsAutoArrayPtrGetterTransfers
{
public:
explicit nsAutoArrayPtrGetterTransfers(nsAutoArrayPtr<T>& aSmartPtr)
: mPtrPtr(aSmartPtr.begin_assignment()) { }
operator T**() { return mPtrPtr; }
T& operator*() { return *mPtrPtr; }
private:
T** mPtrPtr;
};
template <class T>
inline nsAutoArrayPtrGetterTransfers<T>
getter_Transfers(nsAutoArrayPtr<T>& aSmartPtr)
{
return nsAutoArrayPtrGetterTransfers<T>(aSmartPtr);
}
template <class T>
class
nsMemoryAutoPtrGetterTransfers
{
public:
explicit nsMemoryAutoPtrGetterTransfers(nsMemoryAutoPtr<T>& aSmartPtr)
: mPtrPtr(aSmartPtr.begin_assignment()) { }
operator T**() { return mPtrPtr; }
T& operator*() { return *mPtrPtr; }
private:
T** mPtrPtr;
};
template <class T>
inline nsMemoryAutoPtrGetterTransfers<T>
getter_Transfers(nsMemoryAutoPtr<T>& aSmartPtr)
{
return nsMemoryAutoPtrGetterTransfers<T>(aSmartPtr);
}
template <class T>
class
nsRefPtrGetterAddRefs
{
public:
explicit nsRefPtrGetterAddRefs(nsRefPtr<T>& aSmartPtr)
: mPtrPtr(aSmartPtr.begin_assignment_assuming_AddRef()) { }
operator T**() { return mPtrPtr; }
T& operator*() { return *mPtrPtr; }
private:
T** mPtrPtr;
};
template <class T>
inline nsRefPtrGetterAddRefs<T>
getter_AddRefs(nsRefPtr<T>& aSmartPtr)
{
return nsRefPtrGetterAddRefs<T>(aSmartPtr);
}
#define EQ_OP(op_, lhtype_, rhtype_, lhget_, rhget_) \
template <class T, class U> \
inline PRBool \
operator op_( lhtype_ lhs, rhtype_ rhs ) \
{ \
return lhs lhget_ op_ rhs rhget_; \
}
#define NS_AUTO_PTR_EMPTY_
#define SMART_SMART_EQ_OP(op_, type_, lhconst_, rhconst_) \
EQ_OP(op_, const type_<lhconst_ T>&, const type_<rhconst_ U>&, \
.get(), .get())
#define SMART_RAW_EQ_OP(op_, type_, lhconst_, rhconst_) \
EQ_OP(op_, const type_<lhconst_ T>&, rhconst_ U *, \
.get(), NS_AUTO_PTR_EMPTY_)
#define RAW_SMART_EQ_OP(op_, type_, lhconst_, rhconst_) \
EQ_OP(op_, lhconst_ T *, const type_<rhconst_ U>&, \
NS_AUTO_PTR_EMPTY_, .get())
#define PORTABLE_EQ_OPS(type_) \
SMART_SMART_EQ_OP(==, type_, const, const) \
SMART_SMART_EQ_OP(!=, type_, const, const) \
SMART_RAW_EQ_OP(==, type_, const, const) \
SMART_RAW_EQ_OP(!=, type_, const, const) \
RAW_SMART_EQ_OP(==, type_, const, const) \
RAW_SMART_EQ_OP(!=, type_, const, const)
#define NON_CONST_EQ_OPS(type_) \
SMART_SMART_EQ_OP(==, type_, NS_AUTO_PTR_EMPTY_, const) \
SMART_SMART_EQ_OP(!=, type_, NS_AUTO_PTR_EMPTY_, const) \
SMART_SMART_EQ_OP(==, type_, const, NS_AUTO_PTR_EMPTY_) \
SMART_SMART_EQ_OP(!=, type_, const, NS_AUTO_PTR_EMPTY_) \
SMART_SMART_EQ_OP(==, type_, NS_AUTO_PTR_EMPTY_, NS_AUTO_PTR_EMPTY_) \
SMART_SMART_EQ_OP(!=, type_, NS_AUTO_PTR_EMPTY_, NS_AUTO_PTR_EMPTY_) \
SMART_RAW_EQ_OP(==, type_, NS_AUTO_PTR_EMPTY_, const) \
SMART_RAW_EQ_OP(!=, type_, NS_AUTO_PTR_EMPTY_, const) \
SMART_RAW_EQ_OP(==, type_, const, NS_AUTO_PTR_EMPTY_) \
SMART_RAW_EQ_OP(!=, type_, const, NS_AUTO_PTR_EMPTY_) \
SMART_RAW_EQ_OP(==, type_, NS_AUTO_PTR_EMPTY_, NS_AUTO_PTR_EMPTY_) \
SMART_RAW_EQ_OP(!=, type_, NS_AUTO_PTR_EMPTY_, NS_AUTO_PTR_EMPTY_) \
RAW_SMART_EQ_OP(==, type_, NS_AUTO_PTR_EMPTY_, const) \
RAW_SMART_EQ_OP(!=, type_, NS_AUTO_PTR_EMPTY_, const) \
RAW_SMART_EQ_OP(==, type_, const, NS_AUTO_PTR_EMPTY_) \
RAW_SMART_EQ_OP(!=, type_, const, NS_AUTO_PTR_EMPTY_) \
RAW_SMART_EQ_OP(==, type_, NS_AUTO_PTR_EMPTY_, NS_AUTO_PTR_EMPTY_) \
RAW_SMART_EQ_OP(!=, type_, NS_AUTO_PTR_EMPTY_, NS_AUTO_PTR_EMPTY_)
#ifdef NSCAP_DONT_PROVIDE_NONCONST_OPEQ
#define ALL_EQ_OPS(type_) \
PORTABLE_EQ_OPS(type_)
#else
#define ALL_EQ_OPS(type_) \
NON_CONST_EQ_OPS(type_) \
PORTABLE_EQ_OPS(type_)
#endif
ALL_EQ_OPS(nsAutoPtr)
ALL_EQ_OPS(nsAutoArrayPtr)
ALL_EQ_OPS(nsMemoryAutoPtr)
ALL_EQ_OPS(nsRefPtr)

View File

@@ -1,84 +0,0 @@
/* -*- 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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* A set of support classes for defining weak references, rather like
nsIWeakReference, but for use with non-COM objects
*/
#include "nsCWeakReference.h"
/************ a thing supporting weak references to itself ***********/
nsCWeakReferent::nsCWeakReferent(void *aRealThing) :
mRealThing(aRealThing),
mProxy(0) {
}
nsCWeakReferent::~nsCWeakReferent() {
if (mProxy)
mProxy->RealThingDeleted();
}
void nsCWeakReferent::SetReferent(void *aRealThing) {
NS_ASSERTION(!mRealThing && !mProxy, "weak referent set twice");
mRealThing = aRealThing;
mProxy = 0;
}
nsCWeakProxy *nsCWeakReferent::GetProxy() {
if (!mProxy)
mProxy = new nsCWeakProxy(mRealThing, this);
return mProxy;
}
/************ a reference proxy whose lifetime we control ***********/
/* the nsCWeakProxy object is an object whose creation and lifetime is
under our control, unlike the nsCWeakReferent and its family of
nsCWeakReferences. An nsCWeakProxy is created by the nsCWeakReferent
when the first weak reference is necessary, and refcounted for each
additional reference. It knows about the lifetime of the nsCWeakReferent,
and deletes itself once all weak references have been broken.
*/
nsCWeakProxy::nsCWeakProxy(void *aRealThing, nsCWeakReferent *aReferent) :
mRealPointer(aRealThing),
mReferent(aReferent),
mRefCount(0) {
NS_ASSERTION(aRealThing && aReferent, "weak proxy constructed with null ptr");
}
nsCWeakProxy::~nsCWeakProxy() {
if (mReferent)
mReferent->ProxyDeleted();
}
void nsCWeakProxy::ReleaseReference() {
if (--mRefCount == 0) {
delete this;
}
}

View File

@@ -1,171 +0,0 @@
/* -*- 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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsCWeakReference_h___
#define nsCWeakReference_h___
#include "nsDebug.h"
/* A set of support classes for defining weak references, rather like
nsIWeakReference, but for use with non-COM objects.
Expected use is when an object, call it A, holds a reference to an object B,
and B may be unexpectedly deleted from underneath A. To use these classes
to solve that problem, add an nsCWeakReferent member variable to B and
construct that member in B's constructor. (B::B():mWeakRef(this)).
Hold an nsCWeakReference<B> variable in A, rather than a B directly, and
dereference B from that variable afresh each time that B may have been
deleted.
*/
class nsCWeakProxy;
/* An object wishing to support weak references to itself has an nsCWeakReferent
member variable and provides an accessor for getting to it. Notice that
nsCWeakReferent has no default constructor, so must be initialized with
a pointer to the object.
*/
class NS_COM nsCWeakReferent {
public:
nsCWeakReferent(void *aRealThing);
virtual ~nsCWeakReferent();
void SetReferent(void *aRealThing);
nsCWeakProxy *GetProxy();
void ProxyDeleted()
{ mProxy = 0; }
private:
// copy and assignment constructors can't be implemented without help
// from the containing class, so they're made inaccessible, forcing
// the container to address this issue explicitly.
nsCWeakReferent(const nsCWeakReferent &aOriginal);
nsCWeakReferent& operator= (const nsCWeakReferent &aOriginal);
void *mRealThing;
nsCWeakProxy *mProxy;
};
/* The nsCWeakProxy object is an object whose creation and lifetime is
under our control, unlike the nsCWeakReferent and its family of
nsCWeakReferences. An nsCWeakProxy is created by the nsCWeakReferent
when the first weak reference is necessary, and refcounted for each
additional reference. It knows about the lifetime of the nsCWeakReferent,
and deletes itself once all weak references have been broken.
This is an internal-use class; clients need not use it or ever see it.
*/
class NS_COM nsCWeakProxy {
public:
nsCWeakProxy(void *aRealThing, nsCWeakReferent *aReferent);
virtual ~nsCWeakProxy();
void *Reference()
{ return mRealPointer; }
void AddReference()
{ ++mRefCount; }
void ReleaseReference();
void RealThingDeleted()
{ mRealPointer = 0; mReferent = 0; }
private:
void *mRealPointer;
nsCWeakReferent *mReferent;
PRUint32 mRefCount;
};
/* internal use only: there's no need for clients to use this class */
class nsCWeakReferenceBase {
public:
nsCWeakReferenceBase() {};
virtual ~nsCWeakReferenceBase() {};
};
/* This class is the actual weak reference. Clients hold one of these
and access the actual object by dereferencing this weak reference
using operator*, operator-> or Reference().
*/
template<class T> class nsCWeakReference : public nsCWeakReferenceBase {
public:
nsCWeakReference()
{ mProxy = 0; }
nsCWeakReference(nsCWeakReferent *aReferent) {
mProxy = 0;
SetReference(aReferent);
}
nsCWeakReference(const nsCWeakReference<T> &aOriginal) {
mProxy = aOriginal.mProxy;
if (mProxy)
mProxy->AddReference();
}
nsCWeakReference<T>& operator= (const nsCWeakReference<T> &aOriginal) {
nsCWeakProxy *temp = mProxy;
mProxy = aOriginal.mProxy;
if (mProxy)
mProxy->AddReference();
if (temp)
temp->ReleaseReference();
return *this;
}
T& operator*() const {
NS_ASSERTION(mProxy, "weak reference used without being set");
return (T&) *(T*)mProxy->Reference();
}
T* operator->() const {
NS_ASSERTION(mProxy, "weak reference used without being set");
return (T*) mProxy->Reference();
}
virtual ~nsCWeakReference() {
mProxy->ReleaseReference();
}
T* Reference() {
NS_ASSERTION(mProxy, "weak reference used without being set");
return (T*) mProxy->Reference();
}
void SetReference(nsCWeakReferent *aReferent) {
NS_ASSERTION(aReferent, "weak reference set with null referent");
if (mProxy)
mProxy->ReleaseReference();
mProxy = aReferent->GetProxy();
NS_ASSERTION(mProxy, "weak reference proxy allocation failed");
mProxy->AddReference();
}
private:
nsCWeakProxy *mProxy;
};
#endif

View File

@@ -1,43 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsCom_h__
#define nsCom_h__
#include "nscore.h"
#endif

View File

@@ -1,129 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is XPCOM.
*
* The Initial Developer of the Original Code is Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsComObsolete_h__
#define nsComObsolete_h__
/* These _IMPL_NS_* defines should move into their own directories. */
#ifdef _IMPL_NS_BASE
#define NS_BASE NS_EXPORT
#else
#define NS_BASE NS_IMPORT
#endif
#ifdef _IMPL_NS_NET
#define NS_NET NS_EXPORT
#else
#define NS_NET NS_IMPORT
#endif
#ifdef _IMPL_NS_DOM
#define NS_DOM NS_EXPORT
#else
#define NS_DOM NS_IMPORT
#endif
#ifdef _IMPL_NS_WIDGET
#define NS_WIDGET NS_EXPORT
#else
#define NS_WIDGET NS_IMPORT
#endif
#ifdef _IMPL_NS_VIEW
#define NS_VIEW NS_EXPORT
#else
#define NS_VIEW NS_IMPORT
#endif
#ifdef _IMPL_NS_GFXNONXP
#define NS_GFXNONXP NS_EXPORT
#define NS_GFXNONXP_(type) NS_EXPORT_(type)
#else
#define NS_GFXNONXP NS_IMPORT
#define NS_GFXNONXP_(type) NS_IMPORT_(type)
#endif
#ifdef _IMPL_NS_GFX
#define NS_GFX NS_EXPORT
#define NS_GFX_(type) NS_EXPORT_(type)
#else
#define NS_GFX NS_IMPORT
#define NS_GFX_(type) NS_IMPORT_(type)
#endif
#ifdef _IMPL_NS_PLUGIN
#define NS_PLUGIN NS_EXPORT
#else
#define NS_PLUGIN NS_IMPORT
#endif
#ifdef _IMPL_NS_APPSHELL
#define NS_APPSHELL NS_EXPORT
#else
#define NS_APPSHELL NS_IMPORT
#endif
/*
* People who create their own Win32 MSDev projects to compile against mozilla
* code *often* neglect to define XP_WIN and XP_WIN32. Rather than force
* those definitions here - and risk having some code get compiled incorrectly
* before this code is reached - we #error here to let the programmers know
* that they must modify their build projects.
* We would *like* to reduce the usage of these roughly synonymous defines.
* But it is a big modular project with a lot of brainprint issues...
* See bug: http://bugzilla.mozilla.org/show_bug.cgi?id=65727
*/
#if defined(_WIN32) && (!defined(XP_WIN) || !defined(XP_WIN32))
#error Add defines for XP_WIN and XP_WIN32 to your Win32 build project.
#endif
/* Define brackets for protecting C code from C++ */
#ifdef __cplusplus
#define NS_BEGIN_EXTERN_C extern "C" {
#define NS_END_EXTERN_C }
#else
#define NS_BEGIN_EXTERN_C
#define NS_END_EXTERN_C
#endif
#ifdef __cplusplus
#include "nsDebug.h"
#endif
#endif

View File

@@ -1,73 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Base implementation for console messages.
*/
#include "nsConsoleMessage.h"
#include "nsReadableUtils.h"
NS_IMPL_THREADSAFE_ISUPPORTS1(nsConsoleMessage, nsIConsoleMessage);
nsConsoleMessage::nsConsoleMessage()
{
NS_INIT_ISUPPORTS();
}
nsConsoleMessage::nsConsoleMessage(const PRUnichar *message)
{
NS_INIT_ISUPPORTS();
mMessage.Assign(message);
}
nsConsoleMessage::~nsConsoleMessage() {};
NS_IMETHODIMP
nsConsoleMessage::GetMessage(PRUnichar **result) {
*result = ToNewUnicode(mMessage);
return NS_OK;
}
// NS_IMETHODIMP
// nsConsoleMessage::Init(const PRUnichar *message) {
// nsAutoString newMessage(message);
// mMessage = ToNewUnicode(newMessage);
// return NS_OK;
// }

View File

@@ -1,58 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __nsconsolemessage_h__
#define __nsconsolemessage_h__
#include "nsIConsoleMessage.h"
#include "nsString.h"
class nsConsoleMessage : public nsIConsoleMessage {
public:
nsConsoleMessage();
nsConsoleMessage(const PRUnichar *message);
virtual ~nsConsoleMessage();
NS_DECL_ISUPPORTS
NS_DECL_NSICONSOLEMESSAGE
private:
nsString mMessage;
};
#endif /* __nsconsolemessage_h__ */

View File

@@ -1,323 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Maintains a circular buffer of recent messages, and notifies
* listeners when new messages are logged.
*/
/* Threadsafe. */
#include "nsMemory.h"
#include "nsIServiceManager.h"
#include "nsIProxyObjectManager.h"
#include "nsSupportsArray.h"
#include "nsConsoleService.h"
#include "nsConsoleMessage.h"
NS_IMPL_THREADSAFE_ISUPPORTS1(nsConsoleService, nsIConsoleService);
nsConsoleService::nsConsoleService()
: mCurrent(0), mFull(PR_FALSE), mListening(PR_FALSE), mLock(nsnull)
{
NS_INIT_REFCNT();
// XXX grab this from a pref!
// hm, but worry about circularity, bc we want to be able to report
// prefs errs...
mBufferSize = 250;
// XXX deal with these two allocations by detecting null mLock in factory?
mMessages = (nsIConsoleMessage **)
nsMemory::Alloc(mBufferSize * sizeof(nsIConsoleMessage *));
mLock = PR_NewLock();
// Array elements should be 0 initially for circular buffer algorithm.
for (PRUint32 i = 0; i < mBufferSize; i++) {
mMessages[i] = nsnull;
}
}
nsConsoleService::~nsConsoleService()
{
PRUint32 i = 0;
while (i < mBufferSize && mMessages[i] != nsnull) {
NS_RELEASE(mMessages[i]);
i++;
}
#ifdef DEBUG_mccabe
if (mListeners.Count() != 0) {
fprintf(stderr,
"WARNING - %d console error listeners still registered!\n"
"More calls to nsIConsoleService::UnregisterListener needed.\n",
mListeners.Count());
}
#endif
nsMemory::Free(mMessages);
if (mLock)
PR_DestroyLock(mLock);
}
static PRBool PR_CALLBACK snapshot_enum_func(nsHashKey *key, void *data, void* closure)
{
nsISupportsArray *array = (nsISupportsArray *)closure;
// Copy each element into the temporary nsSupportsArray...
array->AppendElement((nsISupports*)data);
return PR_TRUE;
}
// nsIConsoleService methods
NS_IMETHODIMP
nsConsoleService::LogMessage(nsIConsoleMessage *message)
{
if (message == nsnull)
return NS_ERROR_INVALID_ARG;
nsSupportsArray listenersSnapshot;
nsIConsoleMessage *retiredMessage;
NS_ADDREF(message); // early, in case it's same as replaced below.
/*
* Lock while updating buffer, and while taking snapshot of
* listeners array.
*/
{
nsAutoLock lock(mLock);
/*
* If there's already a message in the slot we're about to replace,
* we've wrapped around, and we need to release the old message. We
* save a pointer to it, so we can release below outside the lock.
*/
retiredMessage = mMessages[mCurrent];
mMessages[mCurrent++] = message;
if (mCurrent == mBufferSize) {
mCurrent = 0; // wrap around.
mFull = PR_TRUE;
}
/*
* Copy the listeners into the snapshot array - in case a listener
* is removed during an Observe(...) notification...
*/
mListeners.Enumerate(snapshot_enum_func, &listenersSnapshot);
}
if (retiredMessage != nsnull)
NS_RELEASE(retiredMessage);
/*
* Iterate through any registered listeners and tell them about
* the message. We use the mListening flag to guard against
* recursive message logs. This could sometimes result in
* listeners being skipped because of activity on other threads,
* when we only care about the recursive case.
*/
nsCOMPtr<nsIConsoleListener> listener;
nsresult rv;
nsresult returned_rv;
PRUint32 snapshotCount;
rv = listenersSnapshot.Count(&snapshotCount);
if (NS_FAILED(rv))
return rv;
{
nsAutoLock lock(mLock);
if (mListening)
return NS_OK;
mListening = PR_TRUE;
}
returned_rv = NS_OK;
for (PRUint32 i = 0; i < snapshotCount; i++) {
rv = listenersSnapshot.GetElementAt(i, getter_AddRefs(listener));
if (NS_FAILED(rv)) {
returned_rv = rv;
break; // fall thru to mListening restore code below.
}
listener->Observe(message);
}
{
nsAutoLock lock(mLock);
mListening = PR_FALSE;
}
return returned_rv;
}
NS_IMETHODIMP
nsConsoleService::LogStringMessage(const PRUnichar *message)
{
nsConsoleMessage *msg = new nsConsoleMessage(message);
return this->LogMessage(msg);
}
NS_IMETHODIMP
nsConsoleService::GetMessageArray(nsIConsoleMessage ***messages, PRUint32 *count)
{
nsIConsoleMessage **messageArray;
/*
* Lock the whole method, as we don't want anyone mucking with mCurrent or
* mFull while we're copying out the buffer.
*/
nsAutoLock lock(mLock);
if (mCurrent == 0 && !mFull) {
/*
* Make a 1-length output array so that nobody gets confused,
* and return a count of 0. This should result in a 0-length
* array object when called from script.
*/
messageArray = (nsIConsoleMessage **)
nsMemory::Alloc(sizeof (nsIConsoleMessage *));
*messageArray = nsnull;
*messages = messageArray;
*count = 0;
return NS_OK;
}
PRUint32 resultSize = mFull ? mBufferSize : mCurrent;
messageArray =
(nsIConsoleMessage **)nsMemory::Alloc((sizeof (nsIConsoleMessage *))
* resultSize);
if (messageArray == nsnull) {
*messages = nsnull;
*count = 0;
return NS_ERROR_FAILURE;
}
PRUint32 i;
if (mFull) {
for (i = 0; i < mBufferSize; i++) {
// if full, fill the buffer starting from mCurrent (which'll be
// oldest) wrapping around the buffer to the most recent.
messageArray[i] = mMessages[(mCurrent + i) % mBufferSize];
NS_ADDREF(messageArray[i]);
}
} else {
for (i = 0; i < mCurrent; i++) {
messageArray[i] = mMessages[i];
NS_ADDREF(messageArray[i]);
}
}
*count = resultSize;
*messages = messageArray;
return NS_OK;
}
NS_IMETHODIMP
nsConsoleService::RegisterListener(nsIConsoleListener *listener) {
nsresult rv;
/*
* Store a threadsafe proxy to the listener rather than the
* listener itself; we want the console service to be callable
* from any thread, but listeners can be implemented in
* thread-specific ways, and we always want to call them on their
* originating thread. JavaScript is the motivating example.
*/
nsCOMPtr<nsIConsoleListener> proxiedListener;
rv = GetProxyForListener(listener, getter_AddRefs(proxiedListener));
if (NS_FAILED(rv))
return rv;
{
nsAutoLock lock(mLock);
nsISupportsKey key(listener);
/*
* Put the proxy event listener into a hashtable using the *real*
* listener as the key.
*
* This is necessary because proxy objects do *not* maintain
* nsISupports identity. Therefore, since GetProxyForListener(...)
* can return different proxies for the same object (see bug #85831)
* we need to use the real object as the unique key...
*/
mListeners.Put(&key, proxiedListener);
}
return NS_OK;
}
NS_IMETHODIMP
nsConsoleService::UnregisterListener(nsIConsoleListener *listener) {
nsAutoLock lock(mLock);
nsISupportsKey key(listener);
mListeners.Remove(&key);
return NS_OK;
}
nsresult
nsConsoleService::GetProxyForListener(nsIConsoleListener* aListener,
nsIConsoleListener** aProxy)
{
nsresult rv;
*aProxy = nsnull;
nsCOMPtr<nsIProxyObjectManager> proxyManager =
(do_GetService(NS_XPCOMPROXY_CONTRACTID));
if (proxyManager == nsnull)
return NS_ERROR_NOT_AVAILABLE;
/*
* NOTE this will fail if the calling thread doesn't have an eventQ.
*
* Would it be better to catch that case and leave the listener unproxied?
*/
rv = proxyManager->GetProxyForObject(NS_CURRENT_EVENTQ,
NS_GET_IID(nsIConsoleListener),
aListener,
PROXY_ASYNC | PROXY_ALWAYS,
(void**) aProxy);
return rv;
}

View File

@@ -1,88 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* nsConsoleService class declaration.
*/
#ifndef __nsconsoleservice_h__
#define __nsconsoleservice_h__
#include "nsCOMPtr.h"
#include "nsHashtable.h"
#include "nsAutoLock.h"
#include "nsIConsoleService.h"
class nsConsoleService : public nsIConsoleService
{
public:
nsConsoleService();
virtual ~nsConsoleService();
NS_DECL_ISUPPORTS
NS_DECL_NSICONSOLESERVICE
private:
// build (or find) a proxy for the listener
nsresult GetProxyForListener(nsIConsoleListener* aListener,
nsIConsoleListener** aProxy);
// Circular buffer of saved messages
nsIConsoleMessage **mMessages;
// How big?
PRUint32 mBufferSize;
// Index of slot in mMessages that'll be filled by *next* log message
PRUint32 mCurrent;
// Is the buffer full? (Has mCurrent wrapped around at least once?)
PRBool mFull;
// Listeners to notify whenever a new message is logged.
nsSupportsHashtable mListeners;
// Current listener being notified of a logged error - to prevent
// stack overflows.
PRBool mListening;
// To serialize interesting methods.
PRLock *mLock;
};
#endif /* __nsconsoleservice_h__ */

View File

@@ -1,496 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* John Bandhauer <jband@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* Win32 x86 code for stack walking, symbol resolution, and function hooking */
#if defined(_WIN32) && defined(_M_IX86)
// This is the .cpp file where the globals live
#define DHW_IMPLEMENT_GLOBALS
#include <stdio.h>
#include "prtypes.h"
#include "prprf.h"
#include "prlog.h"
#include "plstr.h"
#include "prlock.h"
#include "nscore.h"
#include "nsAutoLock.h"
#include "nsDebugHelpWin32.h"
#else
#error "nsDebugHelpWin32.cpp should only be built in Win32 x86 builds"
#endif
PRBool
dhwEnsureImageHlpInitialized()
{
static PRBool gInitialized = PR_FALSE;
static PRBool gTried = PR_FALSE;
if (!gInitialized && !gTried) {
gTried = PR_TRUE;
HMODULE module = ::LoadLibrary("DBGHELP.DLL");
if (!module) {
DWORD dw = GetLastError();
printf("DumpStack Error: DBGHELP.DLL wasn't found. GetLastError() returned 0x%8.8X\n"
" This DLL is needed for succeessfully implementing trace-malloc.\n"
" This dll ships by default on Win2k. Disabling trace-malloc functionality.\n"
, dw);
return PR_FALSE;
}
#define INIT_PROC(typename_, name_) \
dhw##name_ = (typename_) ::GetProcAddress(module, #name_); \
if(!dhw##name_) return PR_FALSE;
INIT_PROC(SYMINITIALIZEPROC, SymInitialize);
INIT_PROC(SYMSETOPTIONS, SymSetOptions);
INIT_PROC(SYMGETOPTIONS, SymGetOptions);
INIT_PROC(SYMGETMODULEINFO, SymGetModuleInfo);
INIT_PROC(SYMGETSYMFROMADDRPROC, SymGetSymFromAddr);
INIT_PROC(ENUMERATELOADEDMODULES, EnumerateLoadedModules);
INIT_PROC(IMAGEDIRECTORYENTRYTODATA, ImageDirectoryEntryToData);
// INIT_PROC(SYMGETLINEFROMADDR, SymGetLineFromAddr);
// INIT_PROC(SYMCLEANUPPROC, SymCleanup);
// INIT_PROC(STACKWALKPROC, StackWalk);
// INIT_PROC(SYMFUNCTIONTABLEACCESSPROC, SymFunctionTableAccess);
// INIT_PROC(SYMGETMODULEBASEPROC, SymGetModuleBase);
// INIT_PROC(SYMLOADMODULE, SymLoadModule);
// INIT_PROC(UNDECORATESYMBOLNAME, UnDecorateSymbolName);
// INIT_PROC(SYMUNDNAME, SymUnDName);
#undef INIT_PROC
gInitialized = PR_TRUE;
}
return gInitialized;
}
PRBool
dhwEnsureSymInitialized()
{
static PRBool gInitialized = PR_FALSE;
if (! gInitialized) {
if (! dhwEnsureImageHlpInitialized())
return PR_FALSE;
dhwSymSetOptions(
#if defined(NS_TRACE_MALLOC)
SYMOPT_LOAD_LINES |
#endif
SYMOPT_UNDNAME);
// dhwSymSetOptions(SYMOPT_UNDNAME);
if (! dhwSymInitialize(::GetCurrentProcess(), NULL, TRUE))
return PR_FALSE;
gInitialized = PR_TRUE;
}
return gInitialized;
}
/***************************************************************************/
PRLock* DHWImportHooker::gLock = nsnull;
DHWImportHooker* DHWImportHooker::gHooks = nsnull;
GETPROCADDRESS DHWImportHooker::gRealGetProcAddress = nsnull;
DHWImportHooker&
DHWImportHooker::getGetProcAddressHooker()
{
static DHWImportHooker gGetProcAddress("Kernel32.dll", "GetProcAddress",
(PROC)DHWImportHooker::GetProcAddress);
return gGetProcAddress;
}
DHWImportHooker&
DHWImportHooker::getLoadLibraryWHooker()
{
static DHWImportHooker gLoadLibraryW("Kernel32.dll", "LoadLibraryW",
(PROC)DHWImportHooker::LoadLibraryW);
return gLoadLibraryW;
}
DHWImportHooker&
DHWImportHooker::getLoadLibraryExWHooker()
{
static DHWImportHooker gLoadLibraryExW("Kernel32.dll", "LoadLibraryExW",
(PROC)DHWImportHooker::LoadLibraryExW);
return gLoadLibraryExW;
}
DHWImportHooker&
DHWImportHooker::getLoadLibraryAHooker()
{
static DHWImportHooker gLoadLibraryA("Kernel32.dll", "LoadLibraryA",
(PROC)DHWImportHooker::LoadLibraryA);
return gLoadLibraryA;
}
DHWImportHooker&
DHWImportHooker::getLoadLibraryExAHooker()
{
static DHWImportHooker gLoadLibraryExA("Kernel32.dll", "LoadLibraryExA",
(PROC)DHWImportHooker::LoadLibraryExA);
return gLoadLibraryExA;
}
static HMODULE ThisModule()
{
MEMORY_BASIC_INFORMATION info;
return VirtualQuery(ThisModule, &info, sizeof(info)) ?
(HMODULE) info.AllocationBase : nsnull;
}
DHWImportHooker::DHWImportHooker(const char* aModuleName,
const char* aFunctionName,
PROC aHook,
PRBool aExcludeOurModule /* = PR_FALSE */)
: mNext(nsnull),
mModuleName(aModuleName),
mFunctionName(aFunctionName),
mOriginal(nsnull),
mHook(aHook),
mIgnoreModule(aExcludeOurModule ? ThisModule() : nsnull),
mHooking(PR_TRUE)
{
//printf("DHWImportHooker hooking %s, function %s\n",aModuleName, aFunctionName);
if(!gLock)
gLock = PR_NewLock();
nsAutoLock lock(gLock);
dhwEnsureImageHlpInitialized();
if(!gRealGetProcAddress)
gRealGetProcAddress = ::GetProcAddress;
mOriginal = gRealGetProcAddress(::GetModuleHandleA(aModuleName),
aFunctionName),
mNext = gHooks;
gHooks = this;
PatchAllModules();
}
DHWImportHooker::~DHWImportHooker()
{
nsAutoLock lock(gLock);
mHooking = PR_FALSE;
PatchAllModules();
if(gHooks == this)
gHooks = mNext;
else
{
for(DHWImportHooker* cur = gHooks; cur; cur = cur->mNext)
{
if(cur->mNext == this)
{
cur->mNext = mNext;
break;
}
}
NS_ASSERTION(cur, "we were not in the list!");
}
if(!gHooks)
{
PRLock* theLock = gLock;
gLock = nsnull;
lock.unlock();
PR_DestroyLock(theLock);
}
}
static BOOL CALLBACK ModuleEnumCallback(LPSTR ModuleName,
ULONG ModuleBase,
ULONG ModuleSize,
PVOID UserContext)
{
//printf("Module Name %s\n",ModuleName);
DHWImportHooker* self = (DHWImportHooker*) UserContext;
HMODULE aModule = (HMODULE) ModuleBase;
return self->PatchOneModule(aModule, ModuleName);
}
PRBool
DHWImportHooker::PatchAllModules()
{
return dhwEnumerateLoadedModules(::GetCurrentProcess(),
ModuleEnumCallback, this);
}
PRBool
DHWImportHooker::PatchOneModule(HMODULE aModule, const char* name)
{
if(aModule == mIgnoreModule)
{
return PR_TRUE;
}
// do the fun stuff...
PIMAGE_IMPORT_DESCRIPTOR desc;
uint32 size;
desc = (PIMAGE_IMPORT_DESCRIPTOR)
dhwImageDirectoryEntryToData(aModule, PR_TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT, &size);
if(!desc)
{
return PR_TRUE;
}
for(; desc->Name; desc++)
{
const char* entryModuleName = (const char*)
((char*)aModule + desc->Name);
if(!lstrcmpi(entryModuleName, mModuleName))
break;
}
if(!desc->Name)
{
return PR_TRUE;
}
PIMAGE_THUNK_DATA thunk = (PIMAGE_THUNK_DATA)
((char*) aModule + desc->FirstThunk);
for(; thunk->u1.Function; thunk++)
{
PROC original;
PROC replacement;
if(mHooking)
{
original = mOriginal;
replacement = mHook;
}
else
{
original = mHook;
replacement = mOriginal;
}
PROC* ppfn = (PROC*) &thunk->u1.Function;
if(*ppfn == original)
{
DWORD dwDummy;
VirtualProtect(ppfn, sizeof(ppfn), PAGE_EXECUTE_READWRITE, &dwDummy);
BOOL result = WriteProcessMemory(GetCurrentProcess(),
ppfn, &replacement, sizeof(replacement), nsnull);
if (!result) //failure
{
printf("failure name %s func %x\n",name,*ppfn);
DWORD error = GetLastError();
return PR_TRUE;
}
else
{
// printf("success name %s func %x\n",name,*ppfn);
DWORD filler = result+1;
return result;
}
}
}
return PR_TRUE;
}
PRBool
DHWImportHooker::ModuleLoaded(HMODULE aModule, DWORD flags)
{
//printf("ModuleLoaded\n");
if(aModule && !(flags & LOAD_LIBRARY_AS_DATAFILE))
{
nsAutoLock lock(gLock);
// We don't know that the newly loaded module didn't drag in implicitly
// linked modules, so we patch everything in sight.
for(DHWImportHooker* cur = gHooks; cur; cur = cur->mNext)
cur->PatchAllModules();
}
return PR_TRUE;
}
// static
HMODULE WINAPI
DHWImportHooker::LoadLibraryW(PCWSTR path)
{
//wprintf(L"LoadLibraryW %s\n",path);
DHW_DECLARE_FUN_TYPE(HMODULE, __stdcall, LOADLIBRARYW_, (PCWSTR));
HMODULE hmod = DHW_ORIGINAL(LOADLIBRARYW_, getLoadLibraryWHooker())(path);
ModuleLoaded(hmod, 0);
return hmod;
}
// static
HMODULE WINAPI
DHWImportHooker::LoadLibraryExW(PCWSTR path, HANDLE file, DWORD flags)
{
//wprintf(L"LoadLibraryExW %s\n",path);
DHW_DECLARE_FUN_TYPE(HMODULE, __stdcall, LOADLIBRARYEXW_, (PCWSTR, HANDLE, DWORD));
HMODULE hmod = DHW_ORIGINAL(LOADLIBRARYEXW_, getLoadLibraryExWHooker())(path, file, flags);
ModuleLoaded(hmod, flags);
return hmod;
}
// static
HMODULE WINAPI
DHWImportHooker::LoadLibraryA(PCSTR path)
{
//printf("LoadLibraryA %s\n",path);
DHW_DECLARE_FUN_TYPE(HMODULE, __stdcall, LOADLIBRARYA_, (PCSTR));
HMODULE hmod = DHW_ORIGINAL(LOADLIBRARYA_, getLoadLibraryAHooker())(path);
ModuleLoaded(hmod, 0);
return hmod;
}
// static
HMODULE WINAPI
DHWImportHooker::LoadLibraryExA(PCSTR path, HANDLE file, DWORD flags)
{
//printf("LoadLibraryExA %s\n",path);
DHW_DECLARE_FUN_TYPE(HMODULE, __stdcall, LOADLIBRARYEXA_, (PCSTR, HANDLE, DWORD));
HMODULE hmod = DHW_ORIGINAL(LOADLIBRARYEXA_, getLoadLibraryExAHooker())(path, file, flags);
ModuleLoaded(hmod, flags);
return hmod;
}
// static
FARPROC WINAPI
DHWImportHooker::GetProcAddress(HMODULE aModule, PCSTR aFunctionName)
{
FARPROC pfn = gRealGetProcAddress(aModule, aFunctionName);
if(pfn)
{
nsAutoLock lock(gLock);
for(DHWImportHooker* cur = gHooks; cur; cur = cur->mNext)
{
if(pfn == cur->mOriginal)
{
pfn = cur->mHook;
break;
}
}
}
return pfn;
}
/***************************************************************************/
#if 0
static _CRT_ALLOC_HOOK defaultDbgAllocHook = nsnull;
static DHWAllocationSizeDebugHook* gAllocationSizeHook = nsnull;
int __cdecl dhw_DbgAllocHook(int nAllocType, void *pvData,
size_t nSize, int nBlockUse, long lRequest,
const unsigned char * szFileName, int nLine )
{
DHWAllocationSizeDebugHook* hook = gAllocationSizeHook;
if(hook)
{
PRBool res;
_CrtSetAllocHook(defaultDbgAllocHook);
switch(nAllocType)
{
case _HOOK_ALLOC:
res = hook->AllocHook(nSize);
break;
case _HOOK_REALLOC:
res = hook->ReallocHook(nSize, pvData ?
_msize_dbg(pvData, nBlockUse) : 0);
break;
case _HOOK_FREE:
res = hook->FreeHook(pvData ?
_msize_dbg(pvData, nBlockUse) : 0);
break;
default:
NS_ASSERTION(0,"huh?");
res = PR_TRUE;
break;
}
_CrtSetAllocHook(dhw_DbgAllocHook);
return (int) res;
}
return 1;
}
PRBool
dhwSetAllocationSizeDebugHook(DHWAllocationSizeDebugHook* hook)
{
if(!hook || gAllocationSizeHook)
return PR_FALSE;
gAllocationSizeHook = hook;
if(!defaultDbgAllocHook)
defaultDbgAllocHook = _CrtSetAllocHook(dhw_DbgAllocHook);
else
_CrtSetAllocHook(dhw_DbgAllocHook);
return PR_TRUE;
}
PRBool
dhwClearAllocationSizeDebugHook()
{
if(!gAllocationSizeHook)
return PR_FALSE;
gAllocationSizeHook = nsnull;
_CrtSetAllocHook(defaultDbgAllocHook);
return PR_TRUE;
}
#endif //0

View File

@@ -1,250 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* John Bandhauer <jband@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* Win32 x86 code for stack walking, symbol resolution, and function hooking */
#ifndef __nsDebugHelpWin32_h__
#define __nsDebugHelpWin32_h__
#if defined(_WIN32) && defined(_M_IX86)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <imagehlp.h>
#include <crtdbg.h>
#else
#error "nsDebugHelpWin32.h should only be included in Win32 x86 builds"
#endif
// XXX temporary hack...
//#include "hacky_defines.h"
/***************************************************************************/
// useful macros...
#define DHW_DECLARE_FUN_TYPE(retval_, conv_, typename_, args_) \
typedef retval_ ( conv_ * typename_ ) args_ ;
#ifdef DHW_IMPLEMENT_GLOBALS
#define DHW_DECLARE_FUN_GLOBAL(typename_, name_) typename_ dhw##name_
#else
#define DHW_DECLARE_FUN_GLOBAL(typename_, name_) extern typename_ dhw##name_
#endif
#define DHW_DECLARE_FUN_PROTO(retval_, conv_, name_, args_) \
retval_ conv_ name_ args_
#define DHW_DECLARE_FUN_STATIC_PROTO(retval_, name_, args_) \
static retval_ conv_ name_ args_
#define DHW_DECLARE_FUN_TYPE_AND_PROTO(name_, retval_, conv_, typename_, args_) \
DHW_DECLARE_FUN_TYPE(retval_, conv_, typename_, args_); \
DHW_DECLARE_FUN_PROTO(retval_, conv_, name_, args_)
#define DHW_DECLARE_FUN_TYPE_AND_STATIC_PROTO(name_, retval_, conv_, typename_, args_) \
DHW_DECLARE_FUN_TYPE(retval_, conv_, typename_, args_); \
DHW_DECLARE_FUN_STATIC_PROTO(retval_, conv_, name_, args_)
#define DHW_DECLARE_FUN_TYPE_AND_GLOBAL(typename_, name_, retval_, conv_, args_) \
DHW_DECLARE_FUN_TYPE(retval_, conv_, typename_, args_); \
DHW_DECLARE_FUN_GLOBAL(typename_, name_)
/**********************************************************/
// These are used to get 'original' function addresses from DHWImportHooker.
#define DHW_DECLARE_ORIGINAL(type_, name_, hooker_) \
type_ name_ = (type_) hooker_ . GetOriginalFunction()
#define DHW_DECLARE_ORIGINAL_PTR(type_, name_, hooker_) \
type_ name_ = (type_) hooker_ -> GetOriginalFunction()
#define DHW_ORIGINAL(type_, hooker_) \
((type_) hooker_ . GetOriginalFunction())
#define DHW_ORIGINAL_PTR(type_, hooker_) \
((type_) hooker_ -> GetOriginalFunction())
/***************************************************************************/
// Global declarations of entry points into ImgHelp functions
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMINITIALIZEPROC, SymInitialize, \
BOOL, __stdcall, (HANDLE, LPSTR, BOOL));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMSETOPTIONS, SymSetOptions, \
DWORD, __stdcall, (DWORD));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETOPTIONS, SymGetOptions, \
DWORD, __stdcall, ());
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETMODULEINFO, SymGetModuleInfo, \
BOOL, __stdcall, (HANDLE, DWORD, PIMAGEHLP_MODULE));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETSYMFROMADDRPROC, SymGetSymFromAddr, \
BOOL, __stdcall, (HANDLE, DWORD, PDWORD, PIMAGEHLP_SYMBOL));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(ENUMERATELOADEDMODULES, EnumerateLoadedModules, \
BOOL, __stdcall, (HANDLE, PENUMLOADED_MODULES_CALLBACK, PVOID));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(IMAGEDIRECTORYENTRYTODATA, ImageDirectoryEntryToData, \
PVOID, __stdcall, (PVOID, BOOL, USHORT, PULONG));
// We aren't using any of the below yet...
/*
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMCLEANUPPROC, SymCleanup, \
BOOL, __stdcall, (HANDLE));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(STACKWALKPROC, StackWalk, \
BOOL,
__stdcall,
(DWORD, HANDLE, HANDLE, LPSTACKFRAME, LPVOID, \
PREAD_PROCESS_MEMORY_ROUTINE, \
PFUNCTION_TABLE_ACCESS_ROUTINE, \
PGET_MODULE_BASE_ROUTINE, \
PTRANSLATE_ADDRESS_ROUTINE));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMFUNCTIONTABLEACCESSPROC, SymFunctionTableAccess, \
LPVOID, __stdcall, (HANDLE, DWORD));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETMODULEBASEPROC, SymGetModuleBase, \
DWORD, __stdcall, (HANDLE, DWORD));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMLOADMODULE, SymLoadModule, \
DWORD, __stdcall, (HANDLE, HANDLE, PSTR, PSTR, DWORD, DWORD));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(UNDECORATESYMBOLNAME, _UnDecorateSymbolName, \
DWORD, __stdcall, (LPCSTR, LPSTR, DWORD, DWORD));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMUNDNAME, SymUnDName, \
BOOL, __stdcall, (PIMAGEHLP_SYMBOL, LPSTR, DWORD));
DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETLINEFROMADDR, SymGetLineFromAddr, \
BOOL, __stdcall, (HANDLE, DWORD, PDWORD, PIMAGEHLP_LINE));
*/
/***************************************************************************/
extern PRBool
dhwEnsureImageHlpInitialized();
extern PRBool
dhwEnsureSymInitialized();
/***************************************************************************/
DHW_DECLARE_FUN_TYPE(FARPROC, __stdcall, GETPROCADDRESS, (HMODULE, PCSTR));
class DHWImportHooker
{
public:
DHWImportHooker(const char* aModuleName,
const char* aFunctionName,
PROC aHook,
PRBool aExcludeOurModule = PR_FALSE);
~DHWImportHooker();
PROC GetOriginalFunction() {return mOriginal;}
PRBool PatchAllModules();
PRBool PatchOneModule(HMODULE aModule, const char* name);
static PRBool ModuleLoaded(HMODULE aModule, DWORD flags);
// I think that these should be made not static members, but allocated
// things created in an explicit static 'init' method and cleaned up in
// an explicit static 'finish' method. This would allow the application
// to have proper lifetime control over all the hooks.
static DHWImportHooker &getLoadLibraryWHooker();
static DHWImportHooker &getLoadLibraryExWHooker();
static DHWImportHooker &getLoadLibraryAHooker();
static DHWImportHooker &getLoadLibraryExAHooker();
static DHWImportHooker &getGetProcAddressHooker();
static HMODULE WINAPI LoadLibraryA(PCSTR path);
private:
DHWImportHooker* mNext;
const char* mModuleName;
const char* mFunctionName;
PROC mOriginal;
PROC mHook;
HMODULE mIgnoreModule;
PRBool mHooking;
private:
static PRLock* gLock;
static DHWImportHooker* gHooks;
static GETPROCADDRESS gRealGetProcAddress;
static HMODULE WINAPI LoadLibraryW(PCWSTR path);
static HMODULE WINAPI LoadLibraryExW(PCWSTR path, HANDLE file, DWORD flags);
static HMODULE WINAPI LoadLibraryExA(PCSTR path, HANDLE file, DWORD flags);
static FARPROC WINAPI GetProcAddress(HMODULE aModule, PCSTR aFunctionName);
};
/***************************************************************************/
// This supports the _CrtSetAllocHook based hooking.
// This system sucks because you don't get to see the allocated pointer. I
// don't think it appropriate for nsTraceMalloc, but is useful as a means to make
// malloc fail for testing purposes.
#if 0 //comment out this stuff. not necessary
class DHWAllocationSizeDebugHook
{
public:
virtual PRBool AllocHook(size_t size) = 0;
virtual PRBool ReallocHook(size_t size, size_t sizeOld) = 0;
virtual PRBool FreeHook(size_t size) = 0;
};
extern PRBool dhwSetAllocationSizeDebugHook(DHWAllocationSizeDebugHook* hook);
extern PRBool dhwClearAllocationSizeDebugHook();
/***************************************************************************/
#endif //0
#endif /* __nsDebugHelpWin32_h__ */

View File

@@ -1,301 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsError_h__
#define nsError_h__
#ifndef nscore_h___
#include "nscore.h" // needed for nsresult
#endif
/*
* To add error code to your module, you need to do the following:
*
* 1) Add a module offset code. Add yours to the bottom of the list
* right below this comment, adding 1.
*
* 2) In your module, define a header file which uses one of the
* NE_ERROR_GENERATExxxxxx macros. Some examples below:
*
* #define NS_ERROR_MYMODULE_MYERROR1 NS_ERROR_GENERATE(NS_ERROR_SEVERITY_ERROR,NS_ERROR_MODULE_MYMODULE,1)
* #define NS_ERROR_MYMODULE_MYERROR2 NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_MYMODULE,2)
* #define NS_ERROR_MYMODULE_MYERROR3 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_MYMODULE,3)
*
*/
/**
* @name Standard Module Offset Code. Each Module should identify a unique number
* and then all errors associated with that module become offsets from the
* base associated with that module id. There are 16 bits of code bits for
* each module.
*/
#define NS_ERROR_MODULE_XPCOM 1
#define NS_ERROR_MODULE_BASE 2
#define NS_ERROR_MODULE_GFX 3
#define NS_ERROR_MODULE_WIDGET 4
#define NS_ERROR_MODULE_CALENDAR 5
#define NS_ERROR_MODULE_NETWORK 6
#define NS_ERROR_MODULE_PLUGINS 7
#define NS_ERROR_MODULE_LAYOUT 8
#define NS_ERROR_MODULE_HTMLPARSER 9
#define NS_ERROR_MODULE_RDF 10
#define NS_ERROR_MODULE_UCONV 11
#define NS_ERROR_MODULE_REG 12
#define NS_ERROR_MODULE_FILES 13
#define NS_ERROR_MODULE_DOM 14
#define NS_ERROR_MODULE_IMGLIB 15
#define NS_ERROR_MODULE_MAILNEWS 16
#define NS_ERROR_MODULE_EDITOR 17
#define NS_ERROR_MODULE_XPCONNECT 18
#define NS_ERROR_MODULE_PROFILE 19
#define NS_ERROR_MODULE_LDAP 20
#define NS_ERROR_MODULE_SECURITY 21
#define NS_ERROR_MODULE_DOM_XPATH 22
// NS_ERROR_MODULE_GENERAL should be used by modules that don't
// care if return code values overlap. Callers of methods that
// return such codes should be aware that they are not
// globally unique. Implementors should be careful about blindly
// returning codes from other modules that might also use
// the generic base.
#define NS_ERROR_MODULE_GENERAL 51
/**
* @name Standard Error Handling Macros
*/
#define NS_FAILED(_nsresult) ((_nsresult) & 0x80000000)
#define NS_SUCCEEDED(_nsresult) (!((_nsresult) & 0x80000000))
/**
* @name Severity Code. This flag identifies the level of warning
*/
#define NS_ERROR_SEVERITY_SUCCESS 0
#define NS_ERROR_SEVERITY_ERROR 1
/**
* @name Mozilla Code. This flag separates consumers of mozilla code
* from the native platform
*/
#define NS_ERROR_MODULE_BASE_OFFSET 0x45
/**
* @name Standard Error Generating Macros
*/
#define NS_ERROR_GENERATE(sev,module,code) \
((nsresult) (((PRUint32)(sev)<<31) | ((PRUint32)(module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | ((PRUint32)(code))) )
#define NS_ERROR_GENERATE_SUCCESS(module,code) \
((nsresult) (((PRUint32)(NS_ERROR_SEVERITY_SUCCESS)<<31) | ((PRUint32)(module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | ((PRUint32)(code))) )
#define NS_ERROR_GENERATE_FAILURE(module,code) \
((nsresult) (((PRUint32)(NS_ERROR_SEVERITY_ERROR)<<31) | ((PRUint32)(module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | ((PRUint32)(code))) )
/**
* @name Standard Macros for retrieving error bits
*/
#define NS_ERROR_GET_CODE(err) ((err) & 0xffff)
#define NS_ERROR_GET_MODULE(err) (((((err) >> 16) - NS_ERROR_MODULE_BASE_OFFSET) & 0x1fff))
#define NS_ERROR_GET_SEVERITY(err) (((err) >> 31) & 0x1)
/**
* @name Standard return values
*/
/*@{*/
/* Standard "it worked" return value */
#define NS_OK 0
/* The backwards COM false. This is deprecated, please do not use */
#define NS_COMFALSE 1
#define NS_ERROR_BASE ((nsresult) 0xC1F30000)
/* Returned when an instance is not initialized */
#define NS_ERROR_NOT_INITIALIZED (NS_ERROR_BASE + 1)
/* Returned when an instance is already initialized */
#define NS_ERROR_ALREADY_INITIALIZED (NS_ERROR_BASE + 2)
/* Returned by a not implemented function */
#define NS_ERROR_NOT_IMPLEMENTED ((nsresult) 0x80004001L)
/* Returned when a given interface is not supported. */
#define NS_NOINTERFACE ((nsresult) 0x80004002L)
#define NS_ERROR_NO_INTERFACE NS_NOINTERFACE
#define NS_ERROR_INVALID_POINTER ((nsresult) 0x80004003L)
#define NS_ERROR_NULL_POINTER NS_ERROR_INVALID_POINTER
/* Returned when a function aborts */
#define NS_ERROR_ABORT ((nsresult) 0x80004004L)
/* Returned when a function fails */
#define NS_ERROR_FAILURE ((nsresult) 0x80004005L)
/* Returned when an unexpected error occurs */
#define NS_ERROR_UNEXPECTED ((nsresult) 0x8000ffffL)
/* Returned when a memory allocation failes */
#define NS_ERROR_OUT_OF_MEMORY ((nsresult) 0x8007000eL)
/* Returned when an illegal value is passed */
#define NS_ERROR_ILLEGAL_VALUE ((nsresult) 0x80070057L)
#define NS_ERROR_INVALID_ARG NS_ERROR_ILLEGAL_VALUE
/* Returned when a class doesn't allow aggregation */
#define NS_ERROR_NO_AGGREGATION ((nsresult) 0x80040110L)
/* Returned when an operation can't complete due to an unavailable resource */
#define NS_ERROR_NOT_AVAILABLE ((nsresult) 0x80040111L)
/* Returned when a class is not registered */
#define NS_ERROR_FACTORY_NOT_REGISTERED ((nsresult) 0x80040154L)
/* Returned when a class cannot be registered, but may be tried again later */
#define NS_ERROR_FACTORY_REGISTER_AGAIN ((nsresult) 0x80040155L)
/* Returned when a dynamically loaded factory couldn't be found */
#define NS_ERROR_FACTORY_NOT_LOADED ((nsresult) 0x800401f8L)
/* Returned when a factory doesn't support signatures */
#define NS_ERROR_FACTORY_NO_SIGNATURE_SUPPORT \
(NS_ERROR_BASE + 0x101)
/* Returned when a factory already is registered */
#define NS_ERROR_FACTORY_EXISTS (NS_ERROR_BASE + 0x100)
/* For COM compatibility reasons, we want to use exact error code numbers
for NS_ERROR_PROXY_INVALID_IN_PARAMETER and NS_ERROR_PROXY_INVALID_OUT_PARAMETER.
The first matches:
#define RPC_E_INVALID_PARAMETER _HRESULT_TYPEDEF_(0x80010010L)
Errors returning this mean that the xpcom proxy code could not create a proxy for
one of the in paramaters.
Because of this, we are ignoring the convention if using a base and offset for
error numbers.
*/
/* Returned when a proxy could not be create a proxy for one of the IN parameters
This is returned only when the "real" meathod has NOT been invoked.
*/
#define NS_ERROR_PROXY_INVALID_IN_PARAMETER ((nsresult) 0x80010010L)
/* Returned when a proxy could not be create a proxy for one of the OUT parameters
This is returned only when the "real" meathod has ALREADY been invoked.
*/
#define NS_ERROR_PROXY_INVALID_OUT_PARAMETER ((nsresult) 0x80010011L)
/*@}*/
////////////////////////////////////////////////////////////////////////////////
// I/O Errors
/// Stream closed
#define NS_BASE_STREAM_CLOSED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 2)
/// Error from the operating system
#define NS_BASE_STREAM_OSERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 3)
/// Illegal arguments
#define NS_BASE_STREAM_ILLEGAL_ARGS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 4)
/// For unichar streams
#define NS_BASE_STREAM_NO_CONVERTER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 5)
/// For unichar streams
#define NS_BASE_STREAM_BAD_CONVERSION NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 6)
#define NS_BASE_STREAM_WOULD_BLOCK NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 7)
#define NS_ERROR_FILE_UNRECOGNIZED_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 1)
#define NS_ERROR_FILE_UNRESOLVABLE_SYMLINK NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 2)
#define NS_ERROR_FILE_EXECUTION_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 3)
#define NS_ERROR_FILE_UNKNOWN_TYPE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 4)
#define NS_ERROR_FILE_DESTINATION_NOT_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 5)
#define NS_ERROR_FILE_TARGET_DOES_NOT_EXIST NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 6)
#define NS_ERROR_FILE_COPY_OR_MOVE_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 7)
#define NS_ERROR_FILE_ALREADY_EXISTS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 8)
#define NS_ERROR_FILE_INVALID_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 9)
#define NS_ERROR_FILE_DISK_FULL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 10)
#define NS_ERROR_FILE_CORRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 11)
#define NS_ERROR_FILE_NOT_DIRECTORY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 12)
#define NS_ERROR_FILE_IS_DIRECTORY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 13)
#define NS_ERROR_FILE_IS_LOCKED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 14)
#define NS_ERROR_FILE_TOO_BIG NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 15)
#define NS_ERROR_FILE_NO_DEVICE_SPACE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 16)
#define NS_ERROR_FILE_NAME_TOO_LONG NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 17)
#define NS_ERROR_FILE_NOT_FOUND NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 18)
#define NS_ERROR_FILE_READ_ONLY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 19)
#define NS_ERROR_FILE_DIR_NOT_EMPTY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 20)
#define NS_ERROR_FILE_ACCESS_DENIED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 21)
////////////////////////////////////////////////////////////////////////////////
// Result codes used by nsIVariant
#define NS_ERROR_CANNOT_CONVERT_DATA NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 1)
#define NS_ERROR_OBJECT_IS_IMMUTABLE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 2)
#define NS_ERROR_LOSS_OF_SIGNIFICANT_DATA NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 3)
#define NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_XPCOM, 1)
////////////////////////////////////////////////////////////////////////////////
// This will return the nsresult corresponding to the most recent NSPR failure
// returned by PR_GetError.
extern NS_COM nsresult
NS_ErrorAccordingToNSPR();
////////////////////////////////////////////////////////////////////////////////
#if defined(XP_WIN)
#pragma warning(disable: 4251) // 'nsCOMPtr<class nsIInputStream>' needs to have dll-interface to be used by clients of class 'nsInputStream'
#pragma warning(disable: 4275) // non dll-interface class 'nsISupports' used as base for dll-interface class 'nsIRDFNode'
#endif
#endif

View File

@@ -1,157 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsErrorService.h"
#include "nsCRT.h"
static void* PR_CALLBACK
CloneCString(nsHashKey *aKey, void *aData, void* closure)
{
return nsCRT::strdup((const char*)aData);
}
static PRBool PR_CALLBACK
DeleteCString(nsHashKey *aKey, void *aData, void* closure)
{
nsCRT::free((char*)aData);
return PR_TRUE;
}
nsInt2StrHashtable::nsInt2StrHashtable()
: mHashtable(CloneCString, nsnull, DeleteCString, nsnull, 16)
{
}
nsInt2StrHashtable::~nsInt2StrHashtable()
{
}
nsresult
nsInt2StrHashtable::Put(PRUint32 key, const char* aData)
{
char* value = nsCRT::strdup(aData);
if (value == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
nsVoidKey k((void*)key);
char* oldValue = (char*)mHashtable.Put(&k, value);
if (oldValue)
nsCRT::free(oldValue);
return NS_OK;
}
char*
nsInt2StrHashtable::Get(PRUint32 key)
{
nsVoidKey k((void*)key);
const char* value = (const char*)mHashtable.Get(&k);
if (value == nsnull)
return nsnull;
return nsCRT::strdup(value);
}
nsresult
nsInt2StrHashtable::Remove(PRUint32 key)
{
nsVoidKey k((void*)key);
char* oldValue = (char*)mHashtable.Remove(&k);
if (oldValue)
nsCRT::free(oldValue);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
NS_IMPL_ISUPPORTS1(nsErrorService, nsIErrorService)
NS_METHOD
nsErrorService::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
NS_ENSURE_NO_AGGREGATION(outer);
nsErrorService* serv = new nsErrorService();
if (serv == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(serv);
nsresult rv = serv->QueryInterface(aIID, aInstancePtr);
NS_RELEASE(serv);
return rv;
}
NS_IMETHODIMP
nsErrorService::RegisterErrorStringBundle(PRInt16 errorModule, const char *stringBundleURL)
{
return mErrorStringBundleURLMap.Put(errorModule, stringBundleURL);
}
NS_IMETHODIMP
nsErrorService::UnregisterErrorStringBundle(PRInt16 errorModule)
{
return mErrorStringBundleURLMap.Remove(errorModule);
}
NS_IMETHODIMP
nsErrorService::GetErrorStringBundle(PRInt16 errorModule, char **result)
{
char* value = mErrorStringBundleURLMap.Get(errorModule);
if (value == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
*result = value;
return NS_OK;
}
NS_IMETHODIMP
nsErrorService::RegisterErrorStringBundleKey(nsresult error, const char *stringBundleKey)
{
return mErrorStringBundleKeyMap.Put(error, stringBundleKey);
}
NS_IMETHODIMP
nsErrorService::UnregisterErrorStringBundleKey(nsresult error)
{
return mErrorStringBundleKeyMap.Remove(error);
}
NS_IMETHODIMP
nsErrorService::GetErrorStringBundleKey(nsresult error, char **result)
{
char* value = mErrorStringBundleKeyMap.Get(error);
if (value == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
*result = value;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -1,75 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsErrorService_h__
#define nsErrorService_h__
#include "nsIErrorService.h"
#include "nsHashtable.h"
class nsInt2StrHashtable
{
public:
nsInt2StrHashtable();
virtual ~nsInt2StrHashtable();
nsresult Put(PRUint32 key, const char* aData);
char* Get(PRUint32 key);
nsresult Remove(PRUint32 key);
protected:
nsObjectHashtable mHashtable;
};
class nsErrorService : public nsIErrorService
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIERRORSERVICE
nsErrorService() { NS_INIT_ISUPPORTS(); }
virtual ~nsErrorService() {}
static NS_METHOD
Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
protected:
nsInt2StrHashtable mErrorStringBundleURLMap;
nsInt2StrHashtable mErrorStringBundleKeyMap;
};
#endif // nsErrorService_h__

View File

@@ -1,350 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* ActiveState Tool Corp..
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Contributor(s): Mark Hammond <MarkH@ActiveState.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.h"
#include "nsExceptionService.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
#include "prthread.h"
#include "prlock.h"
static const PRUintn BAD_TLS_INDEX = (PRUintn) -1;
#define CHECK_SERVICE_USE_OK() if (!lock) return NS_ERROR_NOT_INITIALIZED
#define CHECK_MANAGER_USE_OK() if (!mService || !nsExceptionService::lock) return NS_ERROR_NOT_INITIALIZED
// A key for our registered module providers hashtable
class nsProviderKey : public nsHashKey {
protected:
PRUint32 mKey;
public:
nsProviderKey(PRUint32 key) : mKey(key) {}
PRUint32 HashCode(void) const {
return mKey;
}
PRBool Equals(const nsHashKey *aKey) const {
return mKey == ((const nsProviderKey *) aKey)->mKey;
}
nsHashKey *Clone() const {
return new nsProviderKey(mKey);
}
PRUint32 GetValue() { return mKey; }
};
/** Exception Manager definition **/
class nsExceptionManager : public nsIExceptionManager
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIEXCEPTIONMANAGER
nsExceptionManager(nsExceptionService *svc);
virtual ~nsExceptionManager();
/* additional members */
nsCOMPtr<nsIException> mCurrentException;
nsExceptionManager *mNextThread; // not ref-counted.
nsExceptionService *mService; // not ref-counted
#ifdef NS_DEBUG
static PRInt32 totalInstances;
#endif
};
#ifdef NS_DEBUG
PRInt32 nsExceptionManager::totalInstances = 0;
#endif
// Note this object is single threaded - the service itself ensures
// one per thread.
// An exception if the destructor, which may be called on
// the thread shutting down xpcom
NS_IMPL_ISUPPORTS1(nsExceptionManager, nsIExceptionManager)
nsExceptionManager::nsExceptionManager(nsExceptionService *svc) :
mNextThread(nsnull),
mService(svc)
{
/* member initializers and constructor code */
NS_INIT_ISUPPORTS();
#ifdef NS_DEBUG
PR_AtomicIncrement(&totalInstances);
#endif
}
nsExceptionManager::~nsExceptionManager()
{
/* destructor code */
#ifdef NS_DEBUG
PR_AtomicDecrement(&totalInstances);
#endif // NS_DEBUG
}
/* void setCurrentException (in nsIException error); */
NS_IMETHODIMP nsExceptionManager::SetCurrentException(nsIException *error)
{
CHECK_MANAGER_USE_OK();
mCurrentException = error;
return NS_OK;
}
/* nsIException getCurrentException (); */
NS_IMETHODIMP nsExceptionManager::GetCurrentException(nsIException **_retval)
{
CHECK_MANAGER_USE_OK();
*_retval = mCurrentException;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
/* nsIException getExceptionFromProvider( in nsresult rc, in nsIException defaultException); */
NS_IMETHODIMP nsExceptionManager::GetExceptionFromProvider(nsresult rc, nsIException * defaultException, nsIException **_retval)
{
CHECK_MANAGER_USE_OK();
// Just delegate back to the service with the provider map.
return mService->GetExceptionFromProvider(rc, defaultException, _retval);
}
/* The Exception Service */
PRUintn nsExceptionService::tlsIndex = BAD_TLS_INDEX;
PRLock *nsExceptionService::lock = PR_FALSE;
nsExceptionManager *nsExceptionService::firstThread = nsnull;
#ifdef NS_DEBUG
PRInt32 nsExceptionService::totalInstances = 0;
#endif
NS_IMPL_THREADSAFE_ISUPPORTS2(nsExceptionService, nsIExceptionService, nsIObserver)
nsExceptionService::nsExceptionService()
: mProviders(4, PR_TRUE) /* small, thread-safe hashtable */
{
#ifdef NS_DEBUG
if (PR_AtomicIncrement(&totalInstances)!=1) {
NS_ERROR("The nsExceptionService is a singleton!");
}
#endif
NS_INIT_ISUPPORTS();
/* member initializers and constructor code */
if (tlsIndex == BAD_TLS_INDEX) {
PRStatus status;
status = PR_NewThreadPrivateIndex( &tlsIndex, ThreadDestruct );
NS_WARN_IF_FALSE(status==0, "ScriptErrorService could not allocate TLS storage.");
}
lock = PR_NewLock();
NS_WARN_IF_FALSE(lock, "Error allocating ExceptionService lock");
// observe XPCOM shutdown.
nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1");
NS_WARN_IF_FALSE(observerService, "Could not get observer service!");
if (observerService)
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
}
nsExceptionService::~nsExceptionService()
{
Shutdown();
/* destructor code */
#ifdef NS_DEBUG
PR_AtomicDecrement(&totalInstances);
#endif
}
/*static*/
void nsExceptionService::ThreadDestruct( void *data )
{
if (!lock) {
NS_WARNING("nsExceptionService ignoring thread destruction after shutdown");
return;
}
DropThread( (nsExceptionManager *)data );
}
void nsExceptionService::Shutdown()
{
mProviders.Reset();
if (lock) {
DropAllThreads();
PR_DestroyLock(lock);
lock = nsnull;
}
}
/* void setCurrentException (in nsIException error); */
NS_IMETHODIMP nsExceptionService::SetCurrentException(nsIException *error)
{
CHECK_SERVICE_USE_OK();
nsCOMPtr<nsIExceptionManager> sm;
nsresult nr = GetCurrentExceptionManager(getter_AddRefs(sm));
if (NS_FAILED(nr))
return nr;
return sm->SetCurrentException(error);
}
/* nsIException getCurrentException (); */
NS_IMETHODIMP nsExceptionService::GetCurrentException(nsIException **_retval)
{
CHECK_SERVICE_USE_OK();
nsCOMPtr<nsIExceptionManager> sm;
nsresult nr = GetCurrentExceptionManager(getter_AddRefs(sm));
if (NS_FAILED(nr))
return nr;
return sm->GetCurrentException(_retval);
}
/* nsIException getExceptionFromProvider( in nsresult rc, in nsIException defaultException); */
NS_IMETHODIMP nsExceptionService::GetExceptionFromProvider(nsresult rc,
nsIException * defaultException, nsIException **_retval)
{
CHECK_SERVICE_USE_OK();
return DoGetExceptionFromProvider(rc, defaultException, _retval);
}
/* readonly attribute nsIExceptionManager currentExceptionManager; */
NS_IMETHODIMP nsExceptionService::GetCurrentExceptionManager(nsIExceptionManager * *aCurrentScriptManager)
{
CHECK_SERVICE_USE_OK();
nsExceptionManager *mgr = (nsExceptionManager *)PR_GetThreadPrivate(tlsIndex);
if (mgr == nsnull) {
// Stick the new exception object in with no reference count.
mgr = new nsExceptionManager(this);
if (mgr == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
PR_SetThreadPrivate(tlsIndex, mgr);
// The reference count is held in the thread-list
AddThread(mgr);
}
*aCurrentScriptManager = mgr;
NS_ADDREF(*aCurrentScriptManager);
return NS_OK;
}
/* void registerErrorProvider (in nsIExceptionProvider provider, in PRUint32 moduleCode); */
NS_IMETHODIMP nsExceptionService::RegisterExceptionProvider(nsIExceptionProvider *provider, PRUint32 errorModule)
{
CHECK_SERVICE_USE_OK();
nsProviderKey key(errorModule);
if (mProviders.Put(&key, provider)) {
NS_WARNING("Registration of exception provider overwrote another provider with the same module code!");
}
return NS_OK;
}
/* void unregisterErrorProvider (in nsIExceptionProvider provider, in PRUint32 errorModule); */
NS_IMETHODIMP nsExceptionService::UnregisterExceptionProvider(nsIExceptionProvider *provider, PRUint32 errorModule)
{
CHECK_SERVICE_USE_OK();
nsProviderKey key(errorModule);
if (!mProviders.Remove(&key)) {
NS_WARNING("Attempt to unregister an unregistered exception provider!");
return NS_ERROR_UNEXPECTED;
}
return NS_OK;
}
// nsIObserver
NS_IMETHODIMP nsExceptionService::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
{
Shutdown();
return NS_OK;
}
nsresult
nsExceptionService::DoGetExceptionFromProvider(nsresult errCode,
nsIException * defaultException,
nsIException **_exc)
{
// Check for an existing exception
nsresult nr = GetCurrentException(_exc);
if (NS_SUCCEEDED(nr) && *_exc) {
(*_exc)->GetResult(&nr);
// If it matches our result then use it
if (nr == errCode)
return NS_OK;
NS_RELEASE(*_exc);
}
nsProviderKey key(NS_ERROR_GET_MODULE(errCode));
nsCOMPtr<nsIExceptionProvider> provider =
dont_AddRef((nsIExceptionProvider *)mProviders.Get(&key));
// No provider so we'll return the default exception
if (!provider) {
*_exc = defaultException;
NS_IF_ADDREF(*_exc);
return NS_OK;
}
return provider->GetException(errCode, defaultException, _exc);
}
// thread management
/*static*/ void nsExceptionService::AddThread(nsExceptionManager *thread)
{
PR_Lock(lock);
thread->mNextThread = firstThread;
firstThread = thread;
NS_ADDREF(thread);
PR_Unlock(lock);
}
/*static*/ void nsExceptionService::DoDropThread(nsExceptionManager *thread)
{
nsExceptionManager **emp = &firstThread;
while (*emp != thread) {
NS_ABORT_IF_FALSE(*emp, "Could not find the thread to drop!");
emp = &(*emp)->mNextThread;
}
*emp = thread->mNextThread;
NS_RELEASE(thread);
}
/*static*/ void nsExceptionService::DropThread(nsExceptionManager *thread)
{
PR_Lock(lock);
DoDropThread(thread);
PR_Unlock(lock);
}
/*static*/ void nsExceptionService::DropAllThreads()
{
PR_Lock(lock);
while (firstThread)
DoDropThread(firstThread);
PR_Unlock(lock);
}

View File

@@ -1,92 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* ActiveState Tool Corp..
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Contributor(s): Mark Hammond <MarkH@ActiveState.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsExceptionService_h__
#define nsExceptionService_h__
#include "nsVoidArray.h"
#include "nsIException.h"
#include "nsIExceptionService.h"
#include "nsIObserverService.h"
#include "nsHashtable.h"
#include "nsIObserver.h"
class nsExceptionManager;
/** Exception Service definition **/
class nsExceptionService : public nsIExceptionService, public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIEXCEPTIONSERVICE
NS_DECL_NSIEXCEPTIONMANAGER
NS_DECL_NSIOBSERVER
nsExceptionService();
virtual ~nsExceptionService();
/* additional members */
nsresult DoGetExceptionFromProvider(nsresult errCode,
nsIException *defaultException,
nsIException **_richError);
void Shutdown();
/* thread management and cleanup */
static void AddThread(nsExceptionManager *);
static void DropThread(nsExceptionManager *);
static void DoDropThread(nsExceptionManager *thread);
static void DropAllThreads();
static nsExceptionManager *firstThread;
nsSupportsHashtable mProviders;
/* single lock protects both providers hashtable
and thread list */
static PRLock* lock;
static PRUintn tlsIndex;
static void PR_CALLBACK ThreadDestruct( void *data );
#ifdef NS_DEBUG
static PRInt32 totalInstances;
#endif
};
#endif // nsExceptionService_h__

View File

@@ -1,110 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Patrick Beard <beard@netscape.com>
*/
/*
nsGarbageCollector.c
*/
#ifdef GC_LEAK_DETECTOR
/* for FILE */
#include <stdio.h>
/* NSPR stuff */
#include "generic_threads.h"
#include "prthread.h"
#include "prlock.h"
/* Linux/Win32 export private NSPR files to include/private */
#ifdef XP_MAC
#include "pprthred.h"
#else
#include "private/pprthred.h"
#endif
#include "nsLeakDetector.h"
extern FILE *GC_stdout, *GC_stderr;
extern void GC_gcollect(void);
extern void GC_clear_roots(void);
static PRStatus PR_CALLBACK scanner(PRThread* t, void** baseAddr, PRUword count, void* closure)
{
char* begin = (char*)baseAddr;
char* end = (char*)(baseAddr + count);
GC_mark_range_proc marker = (GC_mark_range_proc) closure;
marker(begin, end);
return PR_SUCCESS;
}
static void mark_all_stacks(GC_mark_range_proc marker)
{
/* PR_ThreadScanStackPointers(PR_GetCurrentThread(), &scanner, marker); */
PR_ScanStackPointers(&scanner, (void *)marker);
}
static void locker(void* mutex)
{
PR_Lock(mutex);
}
static void unlocker(void* mutex)
{
PR_Unlock(mutex);
}
static void stopper(void* unused)
{
PR_SuspendAll();
}
static void starter(void* unused)
{
PR_ResumeAll();
}
nsresult NS_InitGarbageCollector()
{
PRLock* mutex;
/* redirect GC's stderr to catch startup leaks. */
GC_stderr = fopen("StartupLeaks", "w");
mutex = PR_NewLock();
if (mutex == NULL)
return NS_ERROR_FAILURE;
GC_generic_init_threads(&mark_all_stacks, mutex,
&locker, &unlocker,
&stopper, &starter);
return NS_OK;
}
nsresult NS_ShutdownGarbageCollector()
{
/* do anything you need to shut down the collector. */
return NS_OK;
}
#endif /* GC_LEAK_DETECTOR */

View File

@@ -1,56 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* XXX This file is obsolete. Use nsIMemory.idl or nsMemory.h instead.
*/
#ifndef nsIAllocator_h___
#define nsIAllocator_h___
#include "nsMemory.h"
#define nsIAllocator nsIMemory
#define nsAllocator nsMemory
#define GetGlobalAllocator GetGlobalMemoryService
#define NS_IALLOCATOR_IID NS_GET_IID(nsIMemory)
#define NS_ALLOCATOR_CONTRACTID NS_MEMORY_CONTRACTID
#define NS_ALLOCATOR_CLASSNAME NS_MEMORY_CLASSNAME
#define NS_ALLOCATOR_CID NS_MEMORY_CID
#endif /* nsIAllocator_h___ */

View File

@@ -1,49 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Used by the console service to notify listeners of new console messages.
*/
#include "nsISupports.idl"
#include "nsIConsoleMessage.idl"
[scriptable, uuid(eaaf61d6-1dd1-11b2-bc6e-8fc96480f20d)]
interface nsIConsoleListener : nsISupports
{
void observe(in nsIConsoleMessage aMessage);
};

View File

@@ -1,56 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
/**
* This is intended as a base interface; implementations may want to
* provide an object that can be qi'ed to provide more specific
* message information.
*/
[scriptable, uuid(41bd8784-1dd2-11b2-9553-8606958fffe1)]
interface nsIConsoleMessage : nsISupports
{
readonly attribute wstring message;
};
%{ C++
#define NS_CONSOLEMESSAGE_CID \
{ 0x56c9d666, 0x1dd2, 0x11b2, { 0xb4, 0x3c, 0xa8, 0x4b, 0xf3, 0xb3, 0xec, 0xbb }}
#define NS_CONSOLEMESSAGE_CONTRACTID "@mozilla.org/consolemessage;1"
%}

View File

@@ -1,85 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "nsIConsoleListener.idl"
#include "nsIConsoleMessage.idl"
[scriptable, uuid(a647f184-1dd1-11b2-a9d1-8537b201161b)]
interface nsIConsoleService : nsISupports
{
void logMessage(in nsIConsoleMessage message);
/**
* Convenience method for logging simple messages.
*/
void logStringMessage(in wstring message);
/**
* Get an array of all the messages logged so far. If no messages
* are logged, this function will return a count of 0, but still
* will allocate one word for messages, so as to show up as a
* 0-length array when called from script.
*/
void getMessageArray([array, size_is(count)] out nsIConsoleMessage messages,
out PRUint32 count);
/**
* To guard against stack overflows from listeners that could log
* messages (it's easy to do this inadvertently from listeners
* implemented in JavaScript), we don't call any listeners when
* another error is already being logged.
*/
void registerListener(in nsIConsoleListener listener);
/**
* Each registered listener should also be unregistered.
*/
void unregisterListener(in nsIConsoleListener listener);
};
%{ C++
#define NS_CONSOLESERVICE_CLASSNAME "Console Service"
#define NS_CONSOLESERVICE_CID \
{ 0x7e3ff85c, 0x1dd2, 0x11b2, { 0x8d, 0x4b, 0xeb, 0x45, 0x2c, 0xb0, 0xff, 0x40 }}
#define NS_CONSOLESERVICE_CONTRACTID "@mozilla.org/consoleservice;1"
%}

View File

@@ -1,140 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Bratell <bratell@lysator.liu.se>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsID.h"
#include "prprf.h"
#include "prmem.h"
static const char gIDFormat[] =
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
static const char gIDFormat2[] =
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
/**
* Multiplies the_int_var with 16 (0x10) and adds the value of the
* hexadecimal digit the_char. If it fails it returns PR_FALSE from
* the function it's used in.
*/
#define ADD_HEX_CHAR_TO_INT_OR_RETURN_FALSE(the_char, the_int_var) \
the_int_var = (the_int_var << 4) + the_char; \
if(the_char >= '0' && the_char <= '9') the_int_var -= '0'; \
else if(the_char >= 'a' && the_char <= 'f') the_int_var -= 'a'-10; \
else if(the_char >= 'A' && the_char <= 'F') the_int_var -= 'A'-10; \
else return PR_FALSE
/**
* Parses number_of_chars characters from the char_pointer pointer and
* puts the number in the dest_variable. The pointer is moved to point
* at the first character after the parsed ones. If it fails it returns
* PR_FALSE from the function the macro is used in.
*/
#define PARSE_CHARS_TO_NUM(char_pointer, dest_variable, number_of_chars) \
do { PRInt32 _i=number_of_chars; \
dest_variable = 0; \
while(_i) { \
ADD_HEX_CHAR_TO_INT_OR_RETURN_FALSE(*char_pointer, dest_variable); \
char_pointer++; \
_i--; \
} } while(0)
/**
* Parses a hyphen from the char_pointer string. If there is no hyphen there
* the function returns PR_FALSE from the function it's used in. The
* char_pointer is advanced one step.
*/
#define PARSE_HYPHEN(char_pointer) if(*(char_pointer++) != '-') return PR_FALSE
/*
* Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} string into
* an nsID. It can also handle the old format without the { and }.
*/
NS_COM PRBool nsID::Parse(const char *aIDStr)
{
/* Optimized for speed */
if(!aIDStr) {
return PR_FALSE;
}
PRBool expectFormat1 = (aIDStr[0] == '{');
if(expectFormat1) aIDStr++;
PARSE_CHARS_TO_NUM(aIDStr, m0, 8);
PARSE_HYPHEN(aIDStr);
PARSE_CHARS_TO_NUM(aIDStr, m1, 4);
PARSE_HYPHEN(aIDStr);
PARSE_CHARS_TO_NUM(aIDStr, m2, 4);
PARSE_HYPHEN(aIDStr);
int i;
for(i=0; i<2; i++)
PARSE_CHARS_TO_NUM(aIDStr, m3[i], 2);
PARSE_HYPHEN(aIDStr);
while(i < 8) {
PARSE_CHARS_TO_NUM(aIDStr, m3[i], 2);
i++;
}
return expectFormat1 ? *aIDStr == '}' : PR_TRUE;
}
/*
* Returns an allocated string in {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
* format. The string is allocated with PR_Malloc and should be freed by
* the caller.
*/
NS_COM char *nsID::ToString() const
{
char *res = (char*)PR_Malloc(39); // use PR_Malloc if this is to be freed with nsCRT::free
if (res != NULL) {
PR_snprintf(res, 39, gIDFormat,
m0, (PRUint32) m1, (PRUint32) m2,
(PRUint32) m3[0], (PRUint32) m3[1], (PRUint32) m3[2],
(PRUint32) m3[3], (PRUint32) m3[4], (PRUint32) m3[5],
(PRUint32) m3[6], (PRUint32) m3[7]);
}
return res;
}

View File

@@ -1,144 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsID_h__
#define nsID_h__
#include <string.h>
#ifndef nscore_h___
#include "nscore.h"
#endif
/**
* A "unique identifier". This is modeled after OSF DCE UUIDs.
* @status FROZEN
*/
struct nsID {
/**
* @name Indentifier values
*/
//@{
PRUint32 m0;
PRUint16 m1;
PRUint16 m2;
PRUint8 m3[8];
//@}
/**
* @name Methods
*/
//@{
/**
* Equivalency method. Compares this nsID with another.
* @return <b>PR_TRUE</b> if they are the same, <b>PR_FALSE</b> if not.
*/
inline PRBool Equals(const nsID& other) const {
return (PRBool)
((((PRUint32*) &m0)[0] == ((PRUint32*) &other.m0)[0]) &&
(((PRUint32*) &m0)[1] == ((PRUint32*) &other.m0)[1]) &&
(((PRUint32*) &m0)[2] == ((PRUint32*) &other.m0)[2]) &&
(((PRUint32*) &m0)[3] == ((PRUint32*) &other.m0)[3]));
}
/**
* nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
* string into an nsID
*/
NS_COM PRBool Parse(const char *aIDStr);
/**
* nsID string encoder. Returns an allocated string in
* {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string.
*/
NS_COM char* ToString() const;
//@}
};
/*
* Class IDs
*/
typedef nsID nsCID;
// Define an CID
#define NS_DEFINE_CID(_name, _cidspec) \
const nsCID _name = _cidspec
#define REFNSCID const nsCID&
/**
* An "interface id" which can be used to uniquely identify a given
* interface.
*/
typedef nsID nsIID;
/**
* A macro shorthand for <tt>const nsIID&<tt>
*/
#define REFNSIID const nsIID&
/**
* Define an IID
* obsolete - do not use this macro
*/
#define NS_DEFINE_IID(_name, _iidspec) \
const nsIID _name = _iidspec
/**
* A macro to build the static const IID accessor method
*/
#define NS_DEFINE_STATIC_IID_ACCESSOR(the_iid) \
static const nsIID& GetIID() {static const nsIID iid = the_iid; return iid;}
/**
* A macro to build the static const CID accessor method
*/
#define NS_DEFINE_STATIC_CID_ACCESSOR(the_cid) \
static const nsID& GetCID() {static const nsID cid = the_cid; return cid;}
#endif

View File

@@ -1,100 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
/**
* nsIErrorService: This is an interim service that allows nsresult codes to be mapped to
* string bundles that can be used to look up error messages. String bundle keys can also
* be mapped.
*
* This service will eventually get replaced by extending xpidl to allow errors to be defined.
* (http://bugzilla.mozilla.org/show_bug.cgi?id=13423).
*/
[scriptable, uuid(e72f94b2-5f85-11d4-9877-00c04fa0cf4a)]
interface nsIErrorService : nsISupports
{
/**
* Registers a string bundle URL for an error module. Error modules are obtained from
* nsresult code with NS_ERROR_GET_MODULE.
*/
void registerErrorStringBundle(in short errorModule, in string stringBundleURL);
/**
* Registers a string bundle URL for an error module.
*/
void unregisterErrorStringBundle(in short errorModule);
/**
* Retrieves a string bundle URL for an error module.
*/
string getErrorStringBundle(in short errorModule);
/**
* Registers a key in a string bundle for an nsresult error code. Only the code portion
* of the nsresult is used (obtained with NS_ERROR_GET_CODE) in this registration. The
* string bundle key is used to look up internationalized messages in the string bundle.
*/
void registerErrorStringBundleKey(in nsresult error, in string stringBundleKey);
/**
* Unregisters a key in a string bundle for an nsresult error code.
*/
void unregisterErrorStringBundleKey(in nsresult error);
/**
* Retrieves a key in a string bundle for an nsresult error code. If no key is registered
* for the specified nsresult's code (obtained with NS_ERROR_GET_CODE), then the stringified
* version of the nsresult code is returned.
*/
string getErrorStringBundleKey(in nsresult error);
};
%{C++
// The global nsIErrorService:
#define NS_ERRORSERVICE_NAME "Error Service"
#define NS_ERRORSERVICE_CONTRACTID "@mozilla.org/xpcom/error-service;1"
#define NS_ERRORSERVICE_CID \
{ /* 744afd5e-5f8c-11d4-9877-00c04fa0cf4a */ \
0x744afd5e, \
0x5f8c, \
0x11d4, \
{0x98, 0x77, 0x00, 0xc0, 0x4f, 0xa0, 0xcf, 0x4a} \
}
%}

View File

@@ -1,101 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Interfaces for representing cross-language exceptions and stack traces.
*/
#include "nsISupports.idl"
#include "nsIProgrammingLanguage.idl"
// XXX - most "string"s in this file should probably move to Unicode
// so may as well use AStrings...
[scriptable, uuid(91d82105-7c62-4f8b-9779-154277c0ee90)]
interface nsIStackFrame : nsISupports
{
// see nsIProgrammingLanguage for list of language consts
readonly attribute PRUint32 language;
readonly attribute string languageName;
readonly attribute string filename;
readonly attribute string name;
// Valid line numbers begin at '1'. '0' indicates unknown.
readonly attribute PRInt32 lineNumber;
readonly attribute string sourceLine;
readonly attribute nsIStackFrame caller;
string toString();
};
[scriptable, uuid(F3A8D3B4-C424-4edc-8BF6-8974C983BA78)]
interface nsIException : nsISupports
{
// A custom message set by the thrower.
readonly attribute string message;
// The nsresult associated with this exception.
readonly attribute nsresult result;
// The name of the error code (ie, a string repr of |result|)
readonly attribute string name;
// Filename location. This is the location that caused the
// error, which may or may not be a source file location.
// For example, standard language errors would generally have
// the same location as their top stack entry. File
// parsers may put the location of the file they were parsing,
// etc.
// null indicates "no data"
readonly attribute string filename;
// Valid line numbers begin at '1'. '0' indicates unknown.
readonly attribute PRUint32 lineNumber;
// Valid column numbers begin at 0.
// We don't have an unambiguous indicator for unknown.
readonly attribute PRUint32 columnNumber;
// A stack trace, if available.
readonly attribute nsIStackFrame location;
// An inner exception that triggered this, if available.
readonly attribute nsIException inner;
// Arbitary data for the implementation.
readonly attribute nsISupports data;
// A generic formatter - make it suitable to print, etc.
string toString();
};

View File

@@ -1,97 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* ActiveState Tool Corp..
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Contributor(s): Mark Hammond <MarkH@ActiveState.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "nsIException.idl"
// An exception provider. These can turn special nsresult codes
// into nsIExceptions
[scriptable, uuid(0577744c-c1d2-47f2-8bcc-ce7a9e5a88fc)]
interface nsIExceptionProvider : nsISupports
{
/** Gets an nsIException or returns NULL if not possible. **/
nsIException getException(in nsresult result, in nsIException defaultException);
};
// A ScriptErrorManager for a single thread. These objects
// are _not_ thread-safe. Use the ScriptErrorService
// to get a script error manager for your current thread.
[scriptable, uuid(efc9d00b-231c-4feb-852c-ac017266a415)]
interface nsIExceptionManager : nsISupports
{
/** Sets (or clears with nsnull) the current error on the this thread. */
void setCurrentException( in nsIException error);
/** Gets the current error for the current thread, or NULL if no error */
nsIException getCurrentException();
/** Gets an exception from a registered exception provider..
This has no effect on the "current exception" */
nsIException getExceptionFromProvider( in nsresult rc, in nsIException defaultException);
};
// The Exception Service. Allows you to get an set exceptions in a thread
// safe manner, or to get an ExceptionManager for your specific thread.
[scriptable, uuid(35A88F54-F267-4414-92A7-191F6454AB52)]
interface nsIExceptionService : nsIExceptionManager
{
/** Obtains an exception manager for the current thread. */
readonly attribute nsIExceptionManager currentExceptionManager;
/** Installs an "exception provider" which is capable of
translating an nsresult into an exception. This enables
error providers to return simple nsresults and only provide
rich errors when specifically requested. It also has the
advantage of allowing code like the DOM to handle all errors
in a single function rather than at each XPCOM entry point.
NOTE: This interface must be thread-safe - it will be called
on whatever thread needs the error translation performed.*/
void registerExceptionProvider( in nsIExceptionProvider provider, in PRUint32 moduleCode );
void unregisterExceptionProvider( in nsIExceptionProvider provider, in PRUint32 moduleCode );
};
%{ C++
#define NS_EXCEPTIONSERVICE_CLASSNAME "Exception Service"
// {35A88F54-F267-4414-92A7-191F6454AB52}
#define NS_EXCEPTIONSERVICE_CID \
{ 0x35a88f54, 0xf267, 0x4414, { 0x92, 0xa7, 0x19, 0x1f, 0x64, 0x54, 0xab, 0x52 } }
#define NS_EXCEPTIONSERVICE_CONTRACTID "@mozilla.org/exceptionservice;1"
%}

View File

@@ -1,41 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __nsIID_h
#define __nsIID_h
#include "nsID.h"
#endif /* __nsIID_h */

View File

@@ -1,64 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Scott Collins <scc@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
nsresult
nsGetInterface::operator()( const nsIID& aIID, void** aInstancePtr ) const
{
nsresult status;
if ( mSource )
{
nsCOMPtr<nsIInterfaceRequestor> factoryPtr = do_QueryInterface(mSource, &status);
NS_ASSERTION(factoryPtr, "Did you know you were calling |do_GetInterface()| on an object that doesn't support the |nsIInterfaceRequestor| interface?");
if ( factoryPtr )
status = factoryPtr->GetInterface(aIID, aInstancePtr);
if ( NS_FAILED(status) )
*aInstancePtr = 0;
}
else
status = NS_ERROR_NULL_POINTER;
if ( mErrorPtr )
*mErrorPtr = status;
return status;
}

View File

@@ -1,55 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
*/
#include "nsISupports.idl"
/**
* The nsIInterfaceRequestor interface defines a generic interface for
* requesting interfaces that a given object might provide access to.
* This is very similar to QueryInterface found in nsISupports.
* The main difference is that interfaces returned from GetInterface()
* are not required to provide a way back to the object implementing this
* interface. The semantics of QI() dictate that given an interface A that
* you QI() on to get to interface B, you must be able to QI on B to get back
* to A. This interface however allows you to obtain an interface C from A
* that may or most likely will not have the ability to get back to A.
*
* @status FROZEN
*/
[scriptable, uuid(033A1470-8B2A-11d3-AF88-00A024FFC08C)]
interface nsIInterfaceRequestor : nsISupports
{
/**
* Retrieves the specified interface pointer.
*
* @param uuid The IID of the interface being requested.
* @param result [out] The interface pointer to be filled in if
* the interface is accessible.
* @return NS_OK - interface was successfully returned.
* NS_NOINTERFACE - interface not accessible.
* NS_ERROR* - method failure.
*/
void getInterface(in nsIIDRef uuid,
[iid_is(uuid),retval] out nsQIResult result);
};

View File

@@ -1,67 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
*/
#ifndef __nsInterfaceRequestorUtils_h
#define __nsInterfaceRequestorUtils_h
#include "nsCOMPtr.h"
// a type-safe shortcut for calling the |GetInterface()| member function
// T must inherit from nsIInterfaceRequestor, but the cast may be ambiguous.
template <class T, class DestinationType>
inline
nsresult
CallGetInterface( T* aSource, DestinationType** aDestination )
{
NS_PRECONDITION(aSource, "null parameter");
NS_PRECONDITION(aDestination, "null parameter");
return aSource->GetInterface(NS_GET_IID(DestinationType),
NS_REINTERPRET_CAST(void**, aDestination));
}
class NS_EXPORT nsGetInterface : public nsCOMPtr_helper
{
public:
nsGetInterface( nsISupports* aSource, nsresult* error )
: mSource(aSource),
mErrorPtr(error)
{
// nothing else to do here
}
virtual nsresult operator()( const nsIID&, void** ) const;
virtual ~nsGetInterface() {};
private:
nsCOMPtr<nsISupports> mSource;
nsresult* mErrorPtr;
};
inline
const nsGetInterface
do_GetInterface( nsISupports* aSource, nsresult* error = 0 )
{
return nsGetInterface(aSource, error);
}
#endif // __nsInterfaceRequestorUtils_h

View File

@@ -1,37 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Patrick C. Beard <beard@netscape.com>
*/
#include "nsISupports.idl"
interface nsICollection;
/**
* Controls the leak detector.
*/
[scriptable, uuid(a2ec052c-1dd1-11b2-9c92-84be252fe47e)]
interface nsILeakDetector : nsISupports {
void dumpLeaks();
void traceObject(in nsISupports object, in PRBool verbose);
void traceCollection(in nsICollection objects, in PRBool verbose);
void markObject(in nsISupports object, in PRBool marked);
readonly attribute nsISupports services;
};

View File

@@ -1,126 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
/**
*
* nsIMemory: interface to allocate and deallocate memory. Also provides
* for notifications in low-memory situations.
*
* A client that wishes to be notified of low memory situations (for
* example, because the client maintains a large memory cache that
* could be released when memory is tight) should register with the
* observer service (see nsIObserverService) using the topic
* "memory-pressure". There are three specific types of notications
* that can occur. These types will be passed as the |aData|
* parameter of the of the "memory-pressure" notification:
*
* "low-memory"
* This will be passed as the extra data when the pressure
* observer is being asked to flush for low-memory conditions.
*
* "heap-minimize"
* This will be passed as the extra data when the pressure
* observer is being asked to flush because of a heap minimize
* call.
*
* "alloc-failure"
* This will be passed as the extra data when the pressure
* observer has been asked to flush because a malloc() or
* realloc() has failed.
*
* @status FROZEN
*/
[scriptable, uuid(59e7e77a-38e4-11d4-8cf5-0060b0fc14a3)]
interface nsIMemory : nsISupports
{
/**
* Allocates a block of memory of a particular size. If the memory
* cannot be allocated (because of an out-of-memory condition), null
* is returned.
*
* @param size - the size of the block to allocate
* @result the block of memory
*/
[noscript, notxpcom] voidPtr alloc(in size_t 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 reallocated block of memory
*
* If ptr is null, this function behaves like malloc.
* If s is the size of the block to which ptr points, the first
* min(s, size) bytes of ptr's block are copied to the new block.
* If the allocation succeeds, ptr is freed and a pointer to the
* new block returned. If the allocation fails, ptr is not freed
* and null is returned. The returned value may be the same as ptr.
*/
[noscript, notxpcom] voidPtr realloc(in voidPtr ptr,
in size_t newSize);
/**
* Frees a block of memory. Null is a permissible value, in which case
* nothing happens.
*
* @param ptr - the block of memory to free
*/
[noscript, notxpcom] void free(in voidPtr ptr);
/**
* Attempts to shrink the heap.
* @param immediate - if true, heap minimization will occur
* immediately if the call was made on the main thread. If
* false, the flush will be scheduled to happen when the app is
* idle.
* @return NS_ERROR_FAILURE if 'immediate' is set an the call
* was not on the application's main thread.
*/
void heapMinimize(in boolean immediate);
/**
* This predicate can be used to determine if we're in a low-memory
* situation (what constitutes low-memory is platform dependent). This
* can be used to trigger the memory pressure observers.
*/
boolean isLowMemory();
};

View File

@@ -1,65 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* John Bandhauer <jband@netscape.com>
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
#include "nsISupports.idl"
%{C++
#ifdef XP_OS2 // OS2 has UNKNOWN problems :)
#undef UNKNOWN
#endif
%}
/**
* Enumeration of Programming Languages
* @status FROZEN
*/
[scriptable, uuid(ea604e90-40ba-11d5-90bb-0010a4e73d9a)]
interface nsIProgrammingLanguage : nsISupports
{
/**
* Identifiers for programming languages.
*/
const PRUint32 UNKNOWN = 0;
const PRUint32 CPLUSPLUS = 1;
const PRUint32 JAVASCRIPT = 2;
const PRUint32 PYTHON = 3;
const PRUint32 PERL = 4;
const PRUint32 JAVA = 5;
const PRUint32 ZX81_BASIC = 6; // it could happen :)
const PRUint32 JAVASCRIPT2 = 7;
// This list can grow indefinitely. Just don't ever change an existing item.
};

View File

@@ -1,80 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* The mother of all xpcom interfaces.
* @status FROZEN
*/
/* In order to get both the right typelib and the right header we force
* the 'real' output from xpidl to be commented out in the generated header
* and includes a copy of the original nsISupports.h. This is all just to deal
* with the Mac specific ": public __comobject" thing.
*/
#include "nsrootidl.idl"
%{C++
/*
* Start commenting out the C++ versions of the below in the output header
*/
#if 0
%}
[scriptable, uuid(00000000-0000-0000-c000-000000000046)]
interface nsISupports {
void QueryInterface(in nsIIDRef uuid,
[iid_is(uuid),retval] out nsQIResult result);
[noscript, notxpcom] nsrefcnt AddRef();
[noscript, notxpcom] nsrefcnt Release();
};
%{C++
/*
* End commenting out the C++ versions of the above in the output header
*/
#endif
%}
%{C++
#include "nsISupportsBase.h"
#ifndef MOZILLA_STRICT_API
#include "nsISupportsUtils.h"
#endif
%}

View File

@@ -1,119 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is XPCOM.
*
* The Initial Developer of the Original Code is Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsISupportsBase_h__
#define nsISupportsBase_h__
#ifndef nscore_h___
#include "nscore.h"
#endif
#ifndef nsID_h__
#include "nsID.h"
#endif
/*@{*/
/**
* IID for the nsISupports interface
* {00000000-0000-0000-c000-000000000046}
*
* To maintain binary compatibility with COM's nsIUnknown, we define the IID
* of nsISupports to be the same as that of COM's nsIUnknown.
*/
#define NS_ISUPPORTS_IID \
{ 0x00000000, 0x0000, 0x0000, \
{0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} }
/**
* Reference count values
*
* This is type of return value from Addref() and Release() in nsISupports.
* nsIUnknown of COM returns a unsigned long from equivalent functions.
* To maintain binary compatibility of nsISupports with nsIUnknown, we are
* doing this ifdeffing.
*/
#if defined(XP_WIN) && PR_BYTES_PER_LONG == 4
typedef unsigned long nsrefcnt;
#else
typedef PRUint32 nsrefcnt;
#endif
/**
* Basic component object model interface. Objects which implement
* this interface support runtime interface discovery (QueryInterface)
* and a reference counted memory model (AddRef/Release). This is
* modelled after the win32 IUnknown API.
*/
class NS_NO_VTABLE nsISupports {
public:
/**
* @name Methods
*/
//@{
/**
* A run time mechanism for interface discovery.
* @param aIID [in] A requested interface IID
* @param aInstancePtr [out] A pointer to an interface pointer to
* receive the result.
* @return <b>NS_OK</b> if the interface is supported by the associated
* instance, <b>NS_NOINTERFACE</b> if it is not.
* <b>NS_ERROR_INVALID_POINTER</b> if <i>aInstancePtr</i> is <b>NULL</b>.
*/
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) = 0;
/**
* Increases the reference count for this interface.
* The associated instance will not be deleted unless
* the reference count is returned to zero.
*
* @return The resulting reference count.
*/
NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
/**
* Decreases the reference count for this interface.
* Generally, if the reference count returns to zero,
* the associated instance is deleted.
*
* @return The resulting reference count.
*/
NS_IMETHOD_(nsrefcnt) Release(void) = 0;
//@}
};
/*@}*/
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,303 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is XPCOM.
*
* The Initial Developer of the Original Code is Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsISupportsObsolete_h__
#define nsISupportsObsolete_h__
#if defined(NS_MT_SUPPORTED)
#include "prcmon.h"
#endif /* NS_MT_SUPPORTED */
///////////////////////////////////////////////////////////////////////////////
#define NS_INIT_REFCNT() NS_INIT_ISUPPORTS()
#define NS_DECL_ISUPPORTS_EXPORTED \
public: \
NS_EXPORT NS_IMETHOD QueryInterface(REFNSIID aIID, \
void** aInstancePtr); \
NS_EXPORT NS_IMETHOD_(nsrefcnt) AddRef(void); \
NS_EXPORT NS_IMETHOD_(nsrefcnt) Release(void); \
protected: \
nsrefcnt mRefCnt; \
NS_DECL_OWNINGTHREAD \
public:
#ifdef NS_DEBUG
/*
* Adding this debug-only function as per bug #26803. If you are debugging
* and this function returns wrong refcounts, fix the objects |AddRef()| and
* |Release()| to do the right thing.
*
* Of course, this function is only available for debug builds.
*/
inline
nsrefcnt
NS_DebugGetRefCount( nsISupports* obj )
// Warning: don't apply this to an object whose refcount is
// |0| or not yet initialized ... it may be destroyed.
{
nsrefcnt ref_count = 0;
if ( obj )
{
// |AddRef()| and |Release()| are supposed to return
// the new refcount of the object
obj->AddRef();
ref_count = obj->Release();
// Can't use |NS_[ADDREF|RELEASE]| since (a) they _don't_ return
// the refcount, and (b) we don't want to log these guaranteed
// balanced calls.
NS_ASSERTION(ref_count,
"Oops! Calling |NS_DebugGetRefCount()| probably just "
"destroyed this object.");
}
return ref_count;
}
#endif // NS_DEBUG
/**
* Macro to free an array of pointers to nsISupports (or classes
* derived from it). A convenience wrapper around
* NS_FREE_XPCOM_POINTER_ARRAY.
*
* Note that if you know that none of your nsISupports pointers are
* going to be 0, you can gain a bit of speed by calling
* NS_FREE_XPCOM_POINTER_ARRAY directly and using NS_RELEASE as your
* free function.
*
* @param size Number of elements in the array. If not a constant, this
* should be a PRInt32. Note that this means this macro
* will not work if size >= 2^31.
* @param array The array to be freed.
*/
#define NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(size, array) \
NS_FREE_XPCOM_POINTER_ARRAY((size), (array), NS_IF_RELEASE)
///////////////////////////////////////////////////////////////////////////////
/* use these functions to associate get/set methods with a
C++ member variable
*/
#define NS_METHOD_GETTER(_method, _type, _member) \
_method(_type* aResult) \
{\
if (!aResult) return NS_ERROR_NULL_POINTER; \
*aResult = _member; \
return NS_OK; \
}
#define NS_METHOD_SETTER(_method, _type, _member) \
_method(_type aResult) \
{ \
_member = aResult; \
return NS_OK; \
}
/*
* special for strings to get/set char* strings
* using PL_strdup and PR_FREEIF
*/
#define NS_METHOD_GETTER_STR(_method,_member) \
_method(char* *aString)\
{\
if (!aString) return NS_ERROR_NULL_POINTER; \
*aString = PL_strdup(_member); \
return NS_OK; \
}
#define NS_METHOD_SETTER_STR(_method, _member) \
_method(const char *aString)\
{\
PR_FREEIF(_member);\
if (aString) _member = PL_strdup(aString); \
else _member = nsnull;\
return NS_OK; \
}
/* Getter/Setter macros.
Usage:
NS_IMPL_[CLASS_]GETTER[_<type>](method, [type,] member);
NS_IMPL_[CLASS_]SETTER[_<type>](method, [type,] member);
NS_IMPL_[CLASS_]GETSET[_<type>]([class, ]postfix, [type,] member);
where:
CLASS_ - implementation is inside a class definition
(otherwise the class name is needed)
Do NOT use in publicly exported header files, because
the implementation may be included many times over.
Instead, use the non-CLASS_ version.
_<type> - For more complex (STR, IFACE) data types
(otherwise the simple data type is needed)
method - name of the method, such as GetWidth or SetColor
type - simple data type if required
member - class member variable such as m_width or mColor
class - the class name, such as Window or MyObject
postfix - Method part after Get/Set such as "Width" for "GetWidth"
Example:
class Window {
public:
NS_IMPL_CLASS_GETSET(Width, int, m_width);
NS_IMPL_CLASS_GETTER_STR(GetColor, m_color);
NS_IMETHOD SetColor(char *color);
private:
int m_width; // read/write
char *m_color; // readonly
};
// defined outside of class
NS_IMPL_SETTER_STR(Window::GetColor, m_color);
Questions/Comments to alecf@netscape.com
*/
/*
* Getter/Setter implementation within a class definition
*/
/* simple data types */
#define NS_IMPL_CLASS_GETTER(_method, _type, _member) \
NS_IMETHOD NS_METHOD_GETTER(_method, _type, _member)
#define NS_IMPL_CLASS_SETTER(_method, _type, _member) \
NS_IMETHOD NS_METHOD_SETTER(_method, _type, _member)
#define NS_IMPL_CLASS_GETSET(_postfix, _type, _member) \
NS_IMPL_CLASS_GETTER(Get##_postfix, _type, _member) \
NS_IMPL_CLASS_SETTER(Set##_postfix, _type, _member)
/* strings */
#define NS_IMPL_CLASS_GETTER_STR(_method, _member) \
NS_IMETHOD NS_METHOD_GETTER_STR(_method, _member)
#define NS_IMPL_CLASS_SETTER_STR(_method, _member) \
NS_IMETHOD NS_METHOD_SETTER_STR(_method, _member)
#define NS_IMPL_CLASS_GETSET_STR(_postfix, _member) \
NS_IMPL_CLASS_GETTER_STR(Get##_postfix, _member) \
NS_IMPL_CLASS_SETTER_STR(Set##_postfix, _member)
/* Getter/Setter implementation outside of a class definition */
/* simple data types */
#define NS_IMPL_GETTER(_method, _type, _member) \
NS_IMETHODIMP NS_METHOD_GETTER(_method, _type, _member)
#define NS_IMPL_SETTER(_method, _type, _member) \
NS_IMETHODIMP NS_METHOD_SETTER(_method, _type, _member)
#define NS_IMPL_GETSET(_class, _postfix, _type, _member) \
NS_IMPL_GETTER(_class::Get##_postfix, _type, _member) \
NS_IMPL_SETTER(_class::Set##_postfix, _type, _member)
/* strings */
#define NS_IMPL_GETTER_STR(_method, _member) \
NS_IMETHODIMP NS_METHOD_GETTER_STR(_method, _member)
#define NS_IMPL_SETTER_STR(_method, _member) \
NS_IMETHODIMP NS_METHOD_SETTER_STR(_method, _member)
#define NS_IMPL_GETSET_STR(_class, _postfix, _member) \
NS_IMPL_GETTER_STR(_class::Get##_postfix, _member) \
NS_IMPL_SETTER_STR(_class::Set##_postfix, _member)
/**
* IID for the nsIsThreadsafe interface
* {88210890-47a6-11d2-bec3-00805f8a66dc}
*
* This interface is *only* used for debugging purposes to determine if
* a given component is threadsafe.
*/
#define NS_ISTHREADSAFE_IID \
{ 0x88210890, 0x47a6, 0x11d2, \
{0xbe, 0xc3, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
#if defined(NS_MT_SUPPORTED)
#define NS_LOCK_INSTANCE() \
PR_CEnterMonitor((void*)this)
#define NS_UNLOCK_INSTANCE() \
PR_CExitMonitor((void*)this)
#else
#define NS_LOCK_INSTANCE()
#define NS_UNLOCK_INSTANCE()
#endif
/**
* This implements query interface with two assumptions: First, the
* class in question implements nsISupports and its own interface and
* nothing else. Second, the implementation of the class's primary
* inheritance chain leads to its own interface.
*
* @param _class The name of the class implementing the method
* @param _classiiddef The name of the #define symbol that defines the IID
* for the class (e.g. NS_ISUPPORTS_IID)
*/
#if defined(NS_DEBUG)
#define NS_VERIFY_THREADSAFE_INTERFACE(_iface) \
if (NULL != (_iface)) { \
nsISupports* tmp; \
static NS_DEFINE_IID(kIsThreadsafeIID, NS_ISTHREADSAFE_IID); \
NS_PRECONDITION((NS_OK == _iface->QueryInterface(kIsThreadsafeIID, \
(void**)&tmp)), \
"Interface is not threadsafe"); \
}
#else
#define NS_VERIFY_THREADSAFE_INTERFACE(_iface)
#endif
////////////////////////////////////////////////////////////////////////////////
#endif

View File

@@ -1,275 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* Scott Collins <scc@ScottCollins.net>
* Dan Mosedale <dmose@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsISupportsUtils_h__
#define nsISupportsUtils_h__
#ifndef nscore_h___
#include "nscore.h"
#endif
#ifndef nsISupportsBase_h__
#include "nsISupportsBase.h"
#endif
#ifndef nsError_h__
#include "nsError.h"
#endif
#ifndef nsDebug_h___
#include "nsDebug.h"
#endif
#ifndef nsISupportsImpl_h__
#include "nsISupportsImpl.h"
#endif
#ifndef nsISupportsObsolete_h__
#include "nsISupportsObsolete.h"
#endif
/**
* Macro for instantiating a new object that implements nsISupports.
* Use this in your factory methods to allow for refcnt tracing.
* Note that you can only use this if you adhere to the no arguments
* constructor com policy (which you really should!).
* @param _result Where the new instance pointer is stored
* @param _type The type of object to call "new" with.
*/
#define NS_NEWXPCOM(_result,_type) \
PR_BEGIN_MACRO \
_result = new _type(); \
NS_LOG_NEW_XPCOM(_result, #_type, sizeof(_type), __FILE__, __LINE__); \
PR_END_MACRO
/**
* Macro for deleting an object that implements nsISupports.
* Use this in your Release methods to allow for refcnt tracing.
* @param _ptr The object to delete.
*/
#define NS_DELETEXPCOM(_ptr) \
PR_BEGIN_MACRO \
NS_LOG_DELETE_XPCOM((_ptr), __FILE__, __LINE__); \
delete (_ptr); \
PR_END_MACRO
/**
* Macro for adding a reference to an interface.
* @param _ptr The interface pointer.
*/
#define NS_ADDREF(_ptr) \
NS_LOG_ADDREF_CALL((_ptr), (_ptr)->AddRef(), __FILE__, __LINE__)
/**
* Macro for adding a reference to this. This macro should be used
* because NS_ADDREF (when tracing) may require an ambiguous cast
* from the pointers primary type to nsISupports. This macro sidesteps
* that entire problem.
*/
#define NS_ADDREF_THIS() \
NS_LOG_ADDREF_CALL(this, AddRef(), __FILE__, __LINE__)
extern "C++" {
// ...because some one is accidentally including this file inside
// an |extern "C"|
template <class T>
inline
nsrefcnt
ns_if_addref( T expr )
// Making this a |inline| |template| allows |expr| to be evaluated only once,
// yet still denies you the ability to |AddRef()| an |nsCOMPtr|.
// Note that |NS_ADDREF()| already has this property in the non-logging case.
{
return expr ? expr->AddRef() : 0;
}
} /* extern "C++" */
/**
* Macro for adding a reference to an interface that checks for NULL.
* @param _expr The interface pointer.
*/
#ifdef NS_BUILD_REFCNT_LOGGING
#define NS_IF_ADDREF(_expr) \
((0 != (_expr)) \
? NS_LOG_ADDREF_CALL((_expr), ns_if_addref(_expr), __FILE__, __LINE__) \
: 0)
#else
#define NS_IF_ADDREF(_expr) ns_if_addref(_expr)
#endif
/*
* Given these declarations, it explicitly OK and (in the non-logging build) efficient
* to end a `getter' with:
*
* NS_IF_ADDREF(*result = mThing);
*
* even if |mThing| is an |nsCOMPtr|. If |mThing| is an |nsCOMPtr|, however, it is still
* _illegal_ to say |NS_IF_ADDREF(mThing)|.
*/
/**
* Macro for releasing a reference to an interface.
*
* Note that when NS_LOSING_ARCHITECTURE is defined that the release will
* be done before the trace message is logged. If the reference count
* goes to zero and implementation of Release logs a message, the two
* messages will be logged out of order.
*
* @param _ptr The interface pointer.
*/
#define NS_RELEASE(_ptr) \
PR_BEGIN_MACRO \
NS_LOG_RELEASE_CALL((_ptr), (_ptr)->Release(), __FILE__, __LINE__); \
(_ptr) = 0; \
PR_END_MACRO
/**
* Macro for releasing a reference to an interface.
*
* Note that when NS_LOSING_ARCHITECTURE is defined that the release will
* be done before the trace message is logged. If the reference count
* goes to zero and implementation of Release logs a message, the two
* messages will be logged out of order.
*
* @param _ptr The interface pointer.
*/
#define NS_RELEASE_THIS() \
NS_LOG_RELEASE_CALL(this, Release(), __FILE__, __LINE__)
/**
* Macro for releasing a reference to an interface, except that this
* macro preserves the return value from the underlying Release call.
* The interface pointer argument will only be NULLed if the reference count
* goes to zero.
*
* Note that when NS_LOSING_ARCHITECTURE is defined that the release will
* be done before the trace message is logged. If the reference count
* goes to zero and implementation of Release logs a message, the two
* messages will be logged out of order.
*
* @param _ptr The interface pointer.
*/
#define NS_RELEASE2(_ptr,_rv) \
PR_BEGIN_MACRO \
_rv = NS_LOG_RELEASE_CALL((_ptr), (_ptr)->Release(),__FILE__,__LINE__); \
if (0 == (_rv)) (_ptr) = 0; \
PR_END_MACRO
/**
* Macro for releasing a reference to an interface that checks for NULL;
*
* Note that when NS_LOSING_ARCHITECTURE is defined that the release will
* be done before the trace message is logged. If the reference count
* goes to zero and implementation of Release logs a message, the two
* messages will be logged out of order.
*
* @param _ptr The interface pointer.
*/
#define NS_IF_RELEASE(_ptr) \
PR_BEGIN_MACRO \
if (_ptr) { \
NS_LOG_RELEASE_CALL((_ptr), (_ptr)->Release(), __FILE__, __LINE__); \
(_ptr) = 0; \
} \
PR_END_MACRO
/*
* Often you have to cast an implementation pointer, e.g., |this|, to an
* |nsISupports*|, but because you have multiple inheritance, a simple cast
* is ambiguous. One could simply say, e.g., (given a base |nsIBase|),
* |NS_STATIC_CAST(nsIBase*, this)|; but that disguises the fact that what
* you are really doing is disambiguating the |nsISupports|. You could make
* that more obvious with a double cast, e.g., |NS_STATIC_CAST(nsISupports*,
* NS_STATIC_CAST(nsIBase*, this))|, but that is bulky and harder to read...
*
* The following macro is clean, short, and obvious. In the example above,
* you would use it like this: |NS_ISUPPORTS_CAST(nsIBase*, this)|.
*/
#define NS_ISUPPORTS_CAST(__unambiguousBase, __expr) \
NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(__unambiguousBase, __expr))
extern "C++" {
// ...because some one is accidentally including this file inside
// an |extern "C"|
class nsISupports;
template <class T>
struct nsCOMTypeInfo
{
static const nsIID& GetIID() { return T::GetIID(); }
};
NS_SPECIALIZE_TEMPLATE
struct nsCOMTypeInfo<nsISupports>
{
static const nsIID& GetIID() {
static const nsIID iid_NS_ISUPPORTS_IID = NS_ISUPPORTS_IID; return iid_NS_ISUPPORTS_IID;
}
};
#define NS_GET_IID(T) nsCOMTypeInfo<T>::GetIID()
// a type-safe shortcut for calling the |QueryInterface()| member function
template <class T, class DestinationType>
inline
nsresult
CallQueryInterface( T* aSource, DestinationType** aDestination )
{
NS_PRECONDITION(aSource, "null parameter");
NS_PRECONDITION(aDestination, "null parameter");
return aSource->QueryInterface(NS_GET_IID(DestinationType),
NS_REINTERPRET_CAST(void**, aDestination));
}
} // extern "C++"
#endif /* __nsISupportsUtils_h */

View File

@@ -1,62 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Shaver <shaver@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
/**
* System information service.
*
* At present, a thin wrapper around PR_GetSystemInfo.
*/
[scriptable,uuid(4189b420-1dd2-11b2-bff7-daaf5c1f7b10)]
interface nsISystemInfo : nsISupports
{
/** The system hostname. */
readonly attribute string hostname;
/** The operating system name. */
readonly attribute string OSName;
/** The operating system version. */
readonly attribute string OSVersion;
/** The processor architecture of the machine. */
readonly attribute string architecture;
};

View File

@@ -1,88 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Original Author:
* Scott Collins <scc@mozilla.org>
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsISupports.idl"
/**
* An instance of |nsIWeakReference| is a proxy object that cooperates with
* its referent to give clients a non-owning, non-dangling reference. Clients
* own the proxy, and should generally manage it with an |nsCOMPtr| (see the
* type |nsWeakPtr| for a |typedef| name that stands out) as they would any
* other XPCOM object. The |QueryReferent| member function provides a
* (hopefully short-lived) owning reference on demand, through which clients
* can get useful access to the referent, while it still exists.
*
* @status FROZEN
* @version 1.0
* @see nsISupportsWeakReference
* @see nsWeakReference
* @see nsWeakPtr
*/
[scriptable, uuid(9188bc85-f92e-11d2-81ef-0060083a0bcf)]
interface nsIWeakReference : nsISupports
{
/**
* |QueryReferent| queries the referent, if it exists, and like |QueryInterface|, produces
* an owning reference to the desired interface. It is designed to look and act exactly
* like (a proxied) |QueryInterface|. Don't hold on to the produced interface permanently;
* that would defeat the purpose of using a non-owning |nsIWeakReference| in the first place.
*/
void QueryReferent( in nsIIDRef uuid, [iid_is(uuid), retval] out nsQIResult result );
};
/**
* |nsISupportsWeakReference| is a factory interface which produces appropriate
* instances of |nsIWeakReference|. Weak references in this scheme can only be
* produced for objects that implement this interface.
*
* @status FROZEN
* @version 1.0
* @see nsIWeakReference
* @see nsSupportsWeakReference
*/
[scriptable, uuid(9188bc86-f92e-11d2-81ef-0060083a0bcf)]
interface nsISupportsWeakReference : nsISupports
{
/**
* |GetWeakReference| produces an appropriate instance of |nsIWeakReference|.
* As with all good XPCOM `getters', you own the resulting interface and should
* manage it with an |nsCOMPtr|.
*
* @see nsIWeakReference
* @see nsWeakPtr
* @see nsCOMPtr
*/
nsIWeakReference GetWeakReference();
};
%{C++
#ifndef MOZILLA_STRICT_API
#include "nsIWeakReferenceUtils.h"
#endif
%}

View File

@@ -1,162 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Scott Collins <scc@mozilla.org> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIWeakReferenceUtils_h__
#define nsIWeakReferenceUtils_h__
#ifndef nsCOMPtr_h__
#include "nsCOMPtr.h"
#endif
typedef nsCOMPtr<nsIWeakReference> nsWeakPtr;
/**
*
*/
// a type-safe shortcut for calling the |QueryReferent()| member function
// T must inherit from nsIWeakReference, but the cast may be ambiguous.
template <class T, class DestinationType>
inline
nsresult
CallQueryReferent( T* aSource, DestinationType** aDestination )
{
NS_PRECONDITION(aSource, "null parameter");
NS_PRECONDITION(aDestination, "null parameter");
return aSource->QueryReferent(NS_GET_IID(DestinationType),
NS_REINTERPRET_CAST(void**, aDestination));
}
class NS_EXPORT nsQueryReferent : public nsCOMPtr_helper
{
public:
nsQueryReferent( nsIWeakReference* aWeakPtr, nsresult* error )
: mWeakPtr(aWeakPtr),
mErrorPtr(error)
{
// nothing else to do here
}
virtual nsresult operator()( const nsIID& aIID, void** ) const;
private:
nsIWeakReference* mWeakPtr;
nsresult* mErrorPtr;
};
inline
const nsQueryReferent
do_QueryReferent( nsIWeakReference* aRawPtr, nsresult* error = 0 )
{
return nsQueryReferent(aRawPtr, error);
}
class NS_COM nsGetWeakReference : public nsCOMPtr_helper
{
public:
nsGetWeakReference( nsISupports* aRawPtr, nsresult* error )
: mRawPtr(aRawPtr),
mErrorPtr(error)
{
// nothing else to do here
}
virtual nsresult operator()( const nsIID&, void** ) const;
private:
nsISupports* mRawPtr;
nsresult* mErrorPtr;
};
/**
* |do_GetWeakReference| is a convenience function that bundles up all the work needed
* to get a weak reference to an arbitrary object, i.e., the |QueryInterface|, test, and
* call through to |GetWeakReference|, and put it into your |nsCOMPtr|.
* It is specifically designed to cooperate with |nsCOMPtr| (or |nsWeakPtr|) like so:
* |nsWeakPtr myWeakPtr = do_GetWeakReference(aPtr);|.
*/
inline
const nsGetWeakReference
do_GetWeakReference( nsISupports* aRawPtr, nsresult* error = 0 )
{
return nsGetWeakReference(aRawPtr, error);
}
inline
void
do_GetWeakReference( nsIWeakReference* aRawPtr, nsresult* error = 0 )
{
// This signature exists soley to _stop_ you from doing a bad thing.
// Saying |do_GetWeakReference()| on a weak reference itself,
// is very likely to be a programmer error.
}
template <class T>
inline
void
do_GetWeakReference( already_AddRefed<T>& )
{
// This signature exists soley to _stop_ you from doing the bad thing.
// Saying |do_GetWeakReference()| on a pointer that is not otherwise owned by
// someone else is an automatic leak. See <http://bugzilla.mozilla.org/show_bug.cgi?id=8221>.
}
template <class T>
inline
void
do_GetWeakReference( already_AddRefed<T>&, nsresult* )
{
// This signature exists soley to _stop_ you from doing the bad thing.
// Saying |do_GetWeakReference()| on a pointer that is not otherwise owned by
// someone else is an automatic leak. See <http://bugzilla.mozilla.org/show_bug.cgi?id=8221>.
}
/**
* Deprecated, use |do_GetWeakReference| instead.
*/
extern NS_COM
nsIWeakReference*
NS_GetWeakReference( nsISupports* , nsresult* aResult=0 );
#endif

View File

@@ -1,231 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Patrick C. Beard <beard@netscape.com>
*/
#if defined(GC_LEAK_DETECTOR)
#include "nsLeakDetector.h"
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIGenericFactory.h"
#include "nsILeakDetector.h"
#include "nsICollection.h"
#include <stdio.h>
#include <time.h>
#include "gc.h"
extern "C" {
extern FILE *GC_stdout, *GC_stderr;
extern void GC_trace_object(GC_PTR object, int verbose);
extern void GC_mark_object(GC_PTR object, GC_word mark);
}
static nsresult nextLeakFile()
{
if (GC_stderr != NULL)
fclose(GC_stderr);
// generate a time stamped report name.
time_t timer;
time(&timer);
tm* now = localtime(&timer);
char reportName[256];
sprintf(reportName, "Leaks%02d%02d%02d",
now->tm_hour, now->tm_min, now->tm_sec);
GC_stderr = fopen(reportName, "w");
return NS_OK;
}
static FILE* openTraceFile()
{
// generate a time stamped report name.
time_t timer;
time(&timer);
tm* now = localtime(&timer);
char reportName[256];
sprintf(reportName, "Trace%02d%02d%02d",
now->tm_hour, now->tm_min, now->tm_sec);
return fopen(reportName, "w");
}
class nsLeakDetector : public nsILeakDetector {
public:
nsLeakDetector();
virtual ~nsLeakDetector();
NS_DECL_ISUPPORTS
NS_DECL_NSILEAKDETECTOR
};
NS_IMPL_ISUPPORTS1(nsLeakDetector, nsILeakDetector)
nsLeakDetector::nsLeakDetector() {
NS_INIT_REFCNT();
}
nsLeakDetector::~nsLeakDetector() {}
NS_METHOD nsLeakDetector::DumpLeaks()
{
GC_gcollect();
return nextLeakFile();
}
NS_METHOD nsLeakDetector::TraceObject(nsISupports* object, PRBool verbose)
{
FILE* trace = openTraceFile();
if (trace != NULL) {
FILE* old_stderr = GC_stderr;
GC_stderr = trace;
GC_trace_object(object, (verbose ? 1 : 0));
GC_stderr = old_stderr;
fclose(trace);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_METHOD nsLeakDetector::TraceCollection(nsICollection* objects, PRBool verbose)
{
PRUint32 count;
if (NS_FAILED(objects->Count(&count)))
return NS_ERROR_FAILURE;
nsCOMPtr<nsISupports>* elements = new nsCOMPtr<nsISupports>[count];
if (elements == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
for (PRUint32 i = 0; i < count; ++i)
objects->GetElementAt(i, getter_AddRefs(elements[i]));
nsresult rv = NS_ERROR_FAILURE;
FILE* trace = openTraceFile();
if (trace != NULL) {
FILE* old_stderr = GC_stderr;
GC_stderr = trace;
GC_trace_object(elements, (verbose ? 1 : 0));
GC_stderr = old_stderr;
fclose(trace);
rv = NS_OK;
}
delete[] elements;
return rv;
}
NS_METHOD nsLeakDetector::MarkObject(nsISupports* object, PRBool marked)
{
GC_mark_object(object, (marked ? 1 : 0));
return NS_OK;
}
NS_METHOD nsLeakDetector::GetServices(nsISupports* *result)
{
return NS_GetServiceManager((nsIServiceManager**)result);
}
#define NS_CLEAKDETECTOR_CID_STR "bb1ba360-1dd1-11b2-b30e-aa2314429f54"
#define NS_CLEAKDETECTOR_CID {0xbb1ba360, 0x1dd1, 0x11b2, {0xb3, 0x0e, 0xaa, 0x23, 0x14, 0x42, 0x9f, 0x54}}
#define NS_CLEAKDETECTOR_CONTRACTID "@mozilla.org/xpcom/leakdetector;1"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLeakDetector)
static NS_DEFINE_CID(kCLeakDetectorCID, NS_CLEAKDETECTOR_CID);
nsresult NS_InitLeakDetector()
{
nsresult rv;
// open the first leak file.
rv = nextLeakFile();
if (NS_FAILED(rv))
return rv;
static const nsModuleComponentInfo info = {
"Leak Detector", kCLeakDetectorCID, NS_CLEAKDETECTOR_CONTRACTID, nsLeakDetectorConstructor
};
// create a generic factory for the leak detector.
nsCOMPtr<nsIGenericFactory> factory;
rv = NS_NewGenericFactory(getter_AddRefs(factory), &info);
if (NS_FAILED(rv))
return rv;
// register this factory with the component manager.
return nsComponentManager::RegisterFactory(info.mCID, info.mDescription, info.mContractID, factory, PR_TRUE);
}
#ifdef XP_MAC
#define SHUTDOWN_LEAKS_EARLY
#undef SHUTDOWN_LEAKS_MEDIUM
#undef SHUTDOWN_LEAKS_LATE
#else
#undef SHUTDOWN_LEAKS_EARLY
#undef SHUTDOWN_LEAKS_MEDIUM
#define SHUTDOWN_LEAKS_LATE
#endif
class LeakDetectorFinalizer
{
public:
~LeakDetectorFinalizer();
};
#ifdef SHUTDOWN_LEAKS_LATE
// do shutdown leaks when XPCOM library is unloaded
LeakDetectorFinalizer gLeakDetectorFinalizer;
#endif
LeakDetectorFinalizer::~LeakDetectorFinalizer()
{
GC_gcollect();
#if 0
nextLeakFile();
if (GC_stdout != NULL) {
fprintf(GC_stdout, "ShutDown Leaks\n");
GC_clear_roots();
GC_gcollect();
}
#endif
}
nsresult NS_ShutdownLeakDetector()
{
#if defined(SHUTDOWN_LEAKS_MEDIUM)
// Make this the first atexit() called so it's before the atexit() crashes
// see http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=23552
static LeakDetectorFinalizer trick;
#elif defined(SHUTDOWN_LEAKS_EARLY)
// do shutdown leaks now
LeakDetectorFinalizer trick;
#endif
return NS_OK;
}
#endif /* defined(GC_LEAK_DETECTOR) */

View File

@@ -1,43 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Patrick C. Beard <beard@netscape.com>
*/
#ifndef nsLeakDetector_h
#define nsLeakDetector_h
#ifndef nsError_h
#include "nsError.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
nsresult NS_InitGarbageCollector(void);
nsresult NS_InitLeakDetector(void);
nsresult NS_ShutdownLeakDetector(void);
nsresult NS_ShutdownGarbageCollector(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* nsLeakDetector_h */

View File

@@ -1,545 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsMemoryImpl.h"
#include "prmem.h"
#include "nsAlgorithm.h"
#include "nsIServiceManager.h"
#include "nsIObserverService.h"
#include "nsAutoLock.h"
#include "nsIThread.h"
#include "nsIEventQueueService.h"
#include "nsString.h"
#if defined(XP_WIN)
#include <windows.h>
#define NS_MEMORY_FLUSHER_THREAD
#elif defined(XP_MAC)
#include <MacMemory.h>
#define NS_MEMORY_FLUSHER_THREAD
#else
// Need to implement the nsIMemory::IsLowMemory() predicate
#undef NS_MEMORY_FLUSHER_THREAD
#endif
//----------------------------------------------------------------------
#if defined(XDEBUG_waterson)
#define NS_TEST_MEMORY_FLUSHER
#endif
/**
* A runnable that is used to periodically check the status
* of the system, determine if too much memory is in use,
* and if so, trigger a "memory flush".
*/
class MemoryFlusher : public nsIRunnable
{
protected:
nsMemoryImpl* mMemoryImpl; // WEAK, it owns us.
PRBool mRunning;
PRIntervalTime mTimeout;
PRLock* mLock;
PRCondVar* mCVar;
MemoryFlusher(nsMemoryImpl* aMemoryImpl);
virtual ~MemoryFlusher();
enum {
kInitialTimeout = 60 /*seconds*/
};
public:
/**
* Create a memory flusher.
* @param aResult the memory flusher
* @param aMemoryImpl the owning nsMemoryImpl object
* @return NS_OK if the memory flusher was created successfully
*/
static nsresult
Create(MemoryFlusher** aResult, nsMemoryImpl* aMemoryImpl);
NS_DECL_ISUPPORTS
NS_DECL_NSIRUNNABLE
/**
* Stop the memory flusher.
*/
nsresult Stop();
};
MemoryFlusher::MemoryFlusher(nsMemoryImpl* aMemoryImpl)
: mMemoryImpl(aMemoryImpl),
mRunning(PR_FALSE),
mTimeout(PR_SecondsToInterval(kInitialTimeout)),
mLock(nsnull),
mCVar(nsnull)
{
NS_INIT_REFCNT();
}
MemoryFlusher::~MemoryFlusher()
{
if (mLock)
PR_DestroyLock(mLock);
if (mCVar)
PR_DestroyCondVar(mCVar);
}
nsresult
MemoryFlusher::Create(MemoryFlusher** aResult, nsMemoryImpl* aMemoryImpl)
{
MemoryFlusher* result = new MemoryFlusher(aMemoryImpl);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
do {
if ((result->mLock = PR_NewLock()) == nsnull)
break;
if ((result->mCVar = PR_NewCondVar(result->mLock)) == nsnull)
break;
NS_ADDREF(*aResult = result);
return NS_OK;
} while (0);
// Something bad happened if we get here...
delete result;
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMPL_THREADSAFE_ISUPPORTS1(MemoryFlusher, nsIRunnable)
NS_IMETHODIMP
MemoryFlusher::Run()
{
nsresult rv;
mRunning = PR_TRUE;
while (1) {
PRStatus status;
{
nsAutoLock l(mLock);
if (! mRunning) {
rv = NS_OK;
break;
}
status = PR_WaitCondVar(mCVar, mTimeout);
}
if (status != PR_SUCCESS) {
rv = NS_ERROR_FAILURE;
break;
}
if (! mRunning) {
rv = NS_OK;
break;
}
PRBool isLowMemory;
rv = mMemoryImpl->IsLowMemory(&isLowMemory);
if (NS_FAILED(rv))
break;
#ifdef NS_TEST_MEMORY_FLUSHER
// Fire the flusher *every* time
isLowMemory = PR_TRUE;
#endif
if (isLowMemory) {
mMemoryImpl->FlushMemory(NS_LITERAL_STRING("low-memory").get(), PR_FALSE);
}
}
mRunning = PR_FALSE;
return rv;
}
nsresult
MemoryFlusher::Stop()
{
if (mRunning) {
nsAutoLock l(mLock);
mRunning = PR_FALSE;
PR_NotifyCondVar(mCVar);
}
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMemoryImpl, nsIMemory)
NS_METHOD
nsMemoryImpl::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
NS_ENSURE_ARG_POINTER(aInstancePtr);
NS_ENSURE_PROPER_AGGREGATION(outer, aIID);
nsMemoryImpl* mm = new nsMemoryImpl();
if (mm == NULL)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
do {
rv = mm->QueryInterface(aIID, aInstancePtr);
if (NS_FAILED(rv))
break;
rv = NS_ERROR_OUT_OF_MEMORY;
mm->mFlushLock = PR_NewLock();
if (! mm->mFlushLock)
break;
rv = NS_OK;
} while (0);
if (NS_FAILED(rv))
delete mm;
return rv;
}
nsMemoryImpl::nsMemoryImpl()
: mFlusher(nsnull),
mFlushLock(nsnull),
mIsFlushing(PR_FALSE)
{
NS_INIT_REFCNT();
}
nsMemoryImpl::~nsMemoryImpl()
{
if (mFlushLock)
PR_DestroyLock(mFlushLock);
}
////////////////////////////////////////////////////////////////////////////////
// Define NS_OUT_OF_MEMORY_TESTER if you want to force memory failures
#ifdef DEBUG_xwarren
#define NS_OUT_OF_MEMORY_TESTER
#endif
#ifdef NS_OUT_OF_MEMORY_TESTER
// flush memory one in this number of times:
#define NS_FLUSH_FREQUENCY 100000
// fail allocation one in this number of flushes:
#define NS_FAIL_FREQUENCY 10
PRUint32 gFlushFreq = 0;
PRUint32 gFailFreq = 0;
static void*
mallocator(PRSize size, PRUint32& counter, PRUint32 max)
{
if (counter++ >= max) {
counter = 0;
NS_ASSERTION(0, "about to fail allocation... watch out");
return nsnull;
}
return PR_Malloc(size);
}
static void*
reallocator(void* ptr, PRSize size, PRUint32& counter, PRUint32 max)
{
if (counter++ >= max) {
counter = 0;
NS_ASSERTION(0, "about to fail reallocation... watch out");
return nsnull;
}
return PR_Realloc(ptr, size);
}
#define MALLOC1(s) mallocator(s, gFlushFreq, NS_FLUSH_FREQUENCY)
#define REALLOC1(p, s) reallocator(p, s, gFlushFreq, NS_FLUSH_FREQUENCY)
#else
#define MALLOC1(s) PR_Malloc(s)
#define REALLOC1(p, s) PR_Realloc(p, s)
#endif // NS_OUT_OF_MEMORY_TESTER
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP_(void *)
nsMemoryImpl::Alloc(PRSize size)
{
void* result = MALLOC1(size);
if (! result) {
// Request an asynchronous flush
FlushMemory(NS_LITERAL_STRING("alloc-failure").get(), PR_FALSE);
}
return result;
}
NS_IMETHODIMP_(void *)
nsMemoryImpl::Realloc(void * ptr, PRSize size)
{
void* result = REALLOC1(ptr, size);
if (! result) {
// Request an asynchronous flush
FlushMemory(NS_LITERAL_STRING("alloc-failure").get(), PR_FALSE);
}
return result;
}
NS_IMETHODIMP_(void)
nsMemoryImpl::Free(void * ptr)
{
PR_Free(ptr);
}
NS_IMETHODIMP
nsMemoryImpl::HeapMinimize(PRBool aImmediate)
{
return FlushMemory(NS_LITERAL_STRING("heap-minimize").get(), aImmediate);
}
NS_IMETHODIMP
nsMemoryImpl::IsLowMemory(PRBool *result)
{
#if defined(XP_WIN)
MEMORYSTATUS stat;
GlobalMemoryStatus(&stat);
*result = ((float)stat.dwAvailPageFile / stat.dwTotalPageFile) < 0.1;
#elif defined(XP_MAC)
const long kReserveHeapFreeSpace = (256 * 1024);
const long kReserveHeapContigSpace = (128 * 1024);
long totalSpace, contiguousSpace;
// this call measures how much memory would be available if the OS
// purged. Despite the name, it does not purge (that happens
// automatically when heap space is low).
::PurgeSpace(&totalSpace, &contiguousSpace);
if (totalSpace < kReserveHeapFreeSpace || contiguousSpace < kReserveHeapContigSpace)
{
NS_WARNING("Found that heap mem is low");
*result = PR_TRUE;
return NS_OK;
}
// see how much temp mem is available (since our allocators allocate 1Mb chunks
// in temp mem. We don't use TempMaxMem() (to get contig space) here, because it
// compacts the application heap, so can be slow.
const long kReserveTempFreeSpace = (2 * 1024 * 1024); // 2Mb
long totalTempSpace = ::TempFreeMem();
if (totalTempSpace < kReserveTempFreeSpace)
{
NS_WARNING("Found that temp mem is low");
*result = PR_TRUE;
return NS_OK;
}
*result = PR_FALSE;
#else
*result = PR_FALSE;
#endif
return NS_OK;
}
nsresult
nsMemoryImpl::FlushMemory(const PRUnichar* aReason, PRBool aImmediate)
{
nsresult rv;
if (aImmediate) {
// They've asked us to run the flusher *immediately*. We've
// got to be on the UI main thread for us to be able to do
// that...are we?
PRBool isOnUIThread = PR_FALSE;
nsCOMPtr<nsIThread> main;
rv = nsIThread::GetMainThread(getter_AddRefs(main));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIThread> current;
rv = nsIThread::GetCurrent(getter_AddRefs(current));
if (NS_SUCCEEDED(rv)) {
if (current == main)
isOnUIThread = PR_TRUE;
}
}
if (! isOnUIThread) {
NS_ERROR("can't synchronously flush memory: not on UI thread");
return NS_ERROR_FAILURE;
}
}
{
// Are we already flushing?
nsAutoLock l(mFlushLock);
if (mIsFlushing)
return NS_OK;
// Well, we are now!
mIsFlushing = PR_TRUE;
}
// Run the flushers immediately if we can; otherwise, proxy to the
// UI thread an run 'em asynchronously.
if (aImmediate) {
rv = RunFlushers(this, aReason);
}
else {
nsCOMPtr<nsIEventQueueService> eqs = do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv);
if (eqs) {
nsCOMPtr<nsIEventQueue> eq;
rv = eqs->GetThreadEventQueue(NS_UI_THREAD, getter_AddRefs(eq));
if (NS_SUCCEEDED(rv)) {
PL_InitEvent(&mFlushEvent.mEvent, this, HandleFlushEvent, DestroyFlushEvent);
mFlushEvent.mReason = aReason;
rv = eq->PostEvent(NS_REINTERPRET_CAST(PLEvent*, &mFlushEvent));
}
}
}
return rv;
}
nsresult
nsMemoryImpl::RunFlushers(nsMemoryImpl* aSelf, const PRUnichar* aReason)
{
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
if (os) {
os->NotifyObservers(aSelf, "memory-pressure", aReason);
}
{
// Done flushing
nsAutoLock l(aSelf->mFlushLock);
aSelf->mIsFlushing = PR_FALSE;
}
return NS_OK;
}
void*
nsMemoryImpl::HandleFlushEvent(PLEvent* aEvent)
{
nsMemoryImpl* self = NS_STATIC_CAST(nsMemoryImpl*, PL_GetEventOwner(aEvent));
FlushEvent* event = NS_REINTERPRET_CAST(FlushEvent*, aEvent);
RunFlushers(self, event->mReason);
return 0;
}
void
nsMemoryImpl::DestroyFlushEvent(PLEvent* aEvent)
{
// no-op, since mEvent is a member of nsMemoryImpl
}
nsMemoryImpl* gMemory = nsnull;
static void
EnsureGlobalMemoryService()
{
if (gMemory) return;
nsresult rv = nsMemoryImpl::Create(nsnull, NS_GET_IID(nsIMemory), (void**)&gMemory);
NS_ASSERTION(NS_SUCCEEDED(rv), "nsMemoryImpl::Create failed");
NS_ASSERTION(gMemory, "improper xpcom initialization");
}
nsresult
nsMemoryImpl::Startup()
{
EnsureGlobalMemoryService();
if (! gMemory)
return NS_ERROR_FAILURE;
#ifdef NS_MEMORY_FLUSHER_THREAD
nsresult rv;
// Create and start a memory flusher thread
rv = MemoryFlusher::Create(&gMemory->mFlusher, gMemory);
if (NS_FAILED(rv)) return rv;
rv = NS_NewThread(getter_AddRefs(gMemory->mFlusherThread),
gMemory->mFlusher,
0, /* XXX use default stack size? */
PR_JOINABLE_THREAD);
if (NS_FAILED(rv)) return rv;
#endif
return NS_OK;
}
nsresult
nsMemoryImpl::Shutdown()
{
if (gMemory) {
#ifdef NS_MEMORY_FLUSHER_THREAD
if (gMemory->mFlusher) {
// Stop the runnable...
gMemory->mFlusher->Stop();
NS_RELEASE(gMemory->mFlusher);
// ...and wait for the thread to exit
if (gMemory->mFlusherThread)
gMemory->mFlusherThread->Join();
}
#endif
NS_RELEASE(gMemory);
gMemory = nsnull;
}
return NS_OK;
}

View File

@@ -1,89 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsMemoryImpl_h__
#define nsMemoryImpl_h__
#include "nsMemory.h"
#include "nsISupportsArray.h"
#include "nsIRunnable.h"
#include "nsIThread.h"
#include "nsCOMPtr.h"
#include "plevent.h"
struct PRLock;
class MemoryFlusher;
class nsMemoryImpl : public nsIMemory
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMEMORY
nsMemoryImpl();
virtual ~nsMemoryImpl();
nsresult FlushMemory(const PRUnichar* aReason, PRBool aImmediate);
// called from xpcom initialization/finalization:
static nsresult Startup();
static nsresult Shutdown();
static NS_METHOD
Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
protected:
MemoryFlusher* mFlusher;
nsCOMPtr<nsIThread> mFlusherThread;
PRLock* mFlushLock;
PRBool mIsFlushing;
struct FlushEvent {
PLEvent mEvent;
const PRUnichar* mReason;
};
FlushEvent mFlushEvent;
static nsresult RunFlushers(nsMemoryImpl* aSelf, const PRUnichar* aReason);
static void* PR_CALLBACK HandleFlushEvent(PLEvent* aEvent);
static void PR_CALLBACK DestroyFlushEvent(PLEvent* aEvent);
};
#endif // nsMemoryImpl_h__

View File

@@ -1,115 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is nsStackFrameWin.h code, released
* December 20, 2000.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Michael Judge, 20-December-2000
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*/
#ifndef nsStackFrameWin_h___
#define nsStackFrameWin_h___
#if defined(_WIN32) && defined(_M_IX86) // WIN32 x86 stack walking code
#include <windows.h>
#include <imagehlp.h>
// Define these as static pointers so that we can load the DLL on the
// fly (and not introduce a link-time dependency on it). Tip o' the
// hat to Matt Pietrick for this idea. See:
//
// http://msdn.microsoft.com/library/periodic/period97/F1/D3/S245C6.htm
//
PR_BEGIN_EXTERN_C
typedef DWORD (__stdcall *SYMSETOPTIONSPROC)(DWORD);
extern SYMSETOPTIONSPROC _SymSetOptions;
typedef BOOL (__stdcall *SYMINITIALIZEPROC)(HANDLE, LPSTR, BOOL);
extern SYMINITIALIZEPROC _SymInitialize;
typedef BOOL (__stdcall *SYMCLEANUPPROC)(HANDLE);
extern SYMCLEANUPPROC _SymCleanup;
typedef BOOL (__stdcall *STACKWALKPROC)(DWORD,
HANDLE,
HANDLE,
LPSTACKFRAME,
LPVOID,
PREAD_PROCESS_MEMORY_ROUTINE,
PFUNCTION_TABLE_ACCESS_ROUTINE,
PGET_MODULE_BASE_ROUTINE,
PTRANSLATE_ADDRESS_ROUTINE);
extern STACKWALKPROC _StackWalk;
typedef LPVOID (__stdcall *SYMFUNCTIONTABLEACCESSPROC)(HANDLE, DWORD);
extern SYMFUNCTIONTABLEACCESSPROC _SymFunctionTableAccess;
typedef DWORD (__stdcall *SYMGETMODULEBASEPROC)(HANDLE, DWORD);
extern SYMGETMODULEBASEPROC _SymGetModuleBase;
typedef BOOL (__stdcall *SYMGETSYMFROMADDRPROC)(HANDLE, DWORD, PDWORD, PIMAGEHLP_SYMBOL);
extern SYMGETSYMFROMADDRPROC _SymGetSymFromAddr;
typedef DWORD ( __stdcall *SYMLOADMODULE)(HANDLE, HANDLE, PSTR, PSTR, DWORD, DWORD);
extern SYMLOADMODULE _SymLoadModule;
typedef DWORD ( __stdcall *SYMUNDNAME)(PIMAGEHLP_SYMBOL, PSTR, DWORD);
extern SYMUNDNAME _SymUnDName;
typedef DWORD ( __stdcall *SYMGETMODULEINFO)( HANDLE, DWORD, PIMAGEHLP_MODULE);
extern SYMGETMODULEINFO _SymGetModuleInfo;
typedef BOOL ( __stdcall *ENUMLOADEDMODULES)( HANDLE, PENUMLOADED_MODULES_CALLBACK, PVOID);
extern ENUMLOADEDMODULES _EnumerateLoadedModules;
typedef BOOL (__stdcall *SYMGETLINEFROMADDRPROC)(HANDLE, DWORD, PDWORD, PIMAGEHLP_LINE);
extern SYMGETLINEFROMADDRPROC _SymGetLineFromAddr;
PRBool EnsureSymInitialized();
/*
* SymGetModuleInfoEspecial
*
* Attempt to determine the module information.
* Bug 112196 says this DLL may not have been loaded at the time
* SymInitialize was called, and thus the module information
* and symbol information is not available.
* This code rectifies that problem.
* Line information is optional.
*/
BOOL SymGetModuleInfoEspecial(HANDLE aProcess, DWORD aAddr, PIMAGEHLP_MODULE aModuleInfo, PIMAGEHLP_LINE aLineInfo);
PR_END_EXTERN_C
#endif //WIN32
#endif //nsStackFrameWin_h___

View File

@@ -1,93 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Shaver <shaver@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "prsystem.h"
#include "nsSystemInfo.h"
#include "nsMemory.h"
nsSystemInfo::nsSystemInfo()
{
NS_INIT_REFCNT();
}
nsSystemInfo::~nsSystemInfo()
{
}
NS_IMPL_ISUPPORTS1(nsSystemInfo, nsISystemInfo)
#define SYSINFO_GETTER(name, cmd) \
NS_IMETHODIMP \
nsSystemInfo::Get##name(char **_retval) \
{ \
NS_ENSURE_ARG_POINTER(_retval); \
char *buf = (char *)nsMemory::Alloc(256); \
if (!buf) \
return NS_ERROR_OUT_OF_MEMORY; \
if (PR_GetSystemInfo((cmd), buf, 256) == PR_FAILURE) { \
nsMemory::Free(buf); \
return NS_ERROR_FAILURE; \
} \
*_retval = buf; \
return NS_OK; \
}
SYSINFO_GETTER(Hostname, PR_SI_HOSTNAME)
SYSINFO_GETTER(OSName, PR_SI_SYSNAME)
SYSINFO_GETTER(OSVersion, PR_SI_RELEASE)
SYSINFO_GETTER(Architecture, PR_SI_ARCHITECTURE)
NS_METHOD
nsSystemInfo::Create(nsISupports *outer, const nsIID &aIID, void **aInstancePtr)
{
nsresult rv;
if (outer)
return NS_ERROR_NO_AGGREGATION;
nsSystemInfo *it = new nsSystemInfo();
if (!it)
return NS_ERROR_OUT_OF_MEMORY;
rv = it->QueryInterface(aIID, aInstancePtr);
if (NS_FAILED(rv)) {
delete it;
*aInstancePtr = 0;
}
return rv;
}

View File

@@ -1,61 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Shaver <shaver@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISystemInfo.h"
#define NS_SYSTEMINFO_CID_STR "3c443856-1dd2-11b2-bfa1-83125c3f3887"
#define NS_SYSTEMINFO_CID \
{0x3c443856, 0x1dd2, 0x11b2, \
{ 0xbf, 0xa1, 0x83, 0x12, 0x5c, 0x3f, 0x38, 0x87 }}
#define NS_SYSTEMINFO_CLASSNAME "System Info Service"
#define NS_SYSTEMINFO_CONTRACTID "@mozilla.org/sysinfo;1"
class nsSystemInfo : public nsISystemInfo
{
NS_DECL_ISUPPORTS
public:
NS_DECL_NSISYSTEMINFO
nsSystemInfo();
virtual ~nsSystemInfo();
static NS_METHOD Create(nsISupports *outer, const nsIID& aIID,
void **aInstancePtr);
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,216 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is nsTraceMalloc.c/bloatblame.c code, released
* April 19, 2000.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Brendan Eich, 14-April-2000
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*/
#ifndef nsTraceMalloc_h___
#define nsTraceMalloc_h___
#include "prtypes.h"
PR_BEGIN_EXTERN_C
/**
* Magic "number" at start of a trace-malloc log file. Inspired by the PNG
* magic string, which inspired XPCOM's typelib (.xpt) file magic. See the
* NS_TraceMallocStartup comment (below) for magic number differences in log
* file structure.
*/
#define NS_TRACE_MALLOC_MAGIC "XPCOM\nTMLog08\r\n\032"
#define NS_TRACE_MALLOC_MAGIC_SIZE 16
/**
* Trace-malloc stats, traced via the 'Z' event at the end of a log file.
*/
typedef struct nsTMStats {
uint32 calltree_maxstack;
uint32 calltree_maxdepth;
uint32 calltree_parents;
uint32 calltree_maxkids;
uint32 calltree_kidhits;
uint32 calltree_kidmisses;
uint32 calltree_kidsteps;
uint32 callsite_recurrences;
uint32 backtrace_calls;
uint32 backtrace_failures;
uint32 btmalloc_failures;
uint32 dladdr_failures;
uint32 malloc_calls;
uint32 malloc_failures;
uint32 calloc_calls;
uint32 calloc_failures;
uint32 realloc_calls;
uint32 realloc_failures;
uint32 free_calls;
uint32 null_free_calls;
} nsTMStats;
#define NS_TMSTATS_STATIC_INITIALIZER {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
/**
* Call NS_TraceMallocStartup with a valid file descriptor to enable logging
* of compressed malloc traces, including callsite chains. Integers may be
* unsigned serial numbers, sizes, or offsets, and require at most 32 bits.
* They're encoded as follows:
* 0-127 0xxxxxxx (binary, one byte)
* 128-16383 10xxxxxx xxxxxxxx
* 16384-0x1fffff 110xxxxx xxxxxxxx xxxxxxxx
* 0x200000-0xfffffff 1110xxxx xxxxxxxx xxxxxxxx xxxxxxxx
* 0x10000000-0xffffffff 11110000 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx
* Strings are NUL-terminated ASCII.
*
* Event Operands (magic TMLog01)
* 'L' library serial, shared object filename string
* 'N' method serial, library serial, demangled name string
* 'S' site serial, parent serial, method serial, calling pc offset
* 'M' site serial, malloc size
* 'C' site serial, calloc size
* 'R' site serial, realloc oldsize, realloc size
* 'F' site serial, free size
*
* Event Operands (magic TMLog02)
* 'Z' serialized struct tmstats (20 unsigned integers),
* maxkids parent callsite serial,
* maxstack top callsite serial
*
* Event Operands (magic TMLog03)
* 'T' seconds, microseconds, caption
*
* Event Operands (magic TMLog04)
* 'R' site serial, realloc size, old site serial, realloc oldsize
*
* Event Operands (magic TMLog05)
* 'M' site serial, address, malloc size
* 'C' site serial, address, calloc size
* 'R' site serial, address, realloc size, old site serial,
* old address, old size
* 'F' site serial, address, free size
*
* Event Operands (magic TMLog06)
* 'M' site serial, interval, address, malloc size
* 'C' site serial, interval, address, calloc size
* 'R' site serial, interval, address, realloc size, old site serial,
* old address, old size
* 'F' site serial, interval, address, free size
*
* Event Operands (magic TMLog07)
* no one documented their changes.
* best of luck....
*
* Event Operands (magic TMLog08)
* 'G' filename serial, source filename string.
* 'N' method serial, library serial, source filename serial,
* source file linenumber, demangled name string
*
* See tools/trace-malloc/bloatblame.c for an example log-file reader.
*/
#define TM_EVENT_LIBRARY 'L'
#define TM_EVENT_FILENAME 'G'
#define TM_EVENT_METHOD 'N'
#define TM_EVENT_CALLSITE 'S'
#define TM_EVENT_MALLOC 'M'
#define TM_EVENT_CALLOC 'C'
#define TM_EVENT_REALLOC 'R'
#define TM_EVENT_FREE 'F'
#define TM_EVENT_STATS 'Z'
#define TM_EVENT_TIMESTAMP 'T'
PR_EXTERN(void) NS_TraceMallocStartup(int logfd);
/**
* Initialize malloc tracing, using the ``standard'' startup arguments.
*/
PR_EXTERN(int) NS_TraceMallocStartupArgs(int argc, char* argv[]);
/**
* Stop all malloc tracing, flushing any buffered events to the logfile.
*/
PR_EXTERN(void) NS_TraceMallocShutdown(void);
/**
* Disable malloc tracing.
*/
PR_EXTERN(void) NS_TraceMallocDisable(void);
/**
* Enable malloc tracing.
*/
PR_EXTERN(void) NS_TraceMallocEnable(void);
/**
* Change the log file descriptor, flushing any buffered output to the old
* fd, and writing NS_TRACE_MALLOC_MAGIC to the new file if it is zero length.
* Return the old fd, so the caller can swap open fds. Return -2 on failure,
* which means malloc failure.
*/
PR_EXTERN(int) NS_TraceMallocChangeLogFD(int fd);
/**
* Close the file descriptor fd and forget any bookkeeping associated with it.
* Do nothing if fd is -1.
*/
PR_EXTERN(void) NS_TraceMallocCloseLogFD(int fd);
/**
* Emit a timestamp event with the given caption to the current log file.
*/
PR_EXTERN(void) NS_TraceMallocLogTimestamp(const char *caption);
/**
* Walk the stack, dumping frames in standard form to ofp. If skip is 0,
* exclude the frames for NS_TraceStack and anything it calls to do the walk.
* If skip is less than 0, include -skip such frames. If skip is positive,
* exclude that many frames leading to the call to NS_TraceStack.
*/
PR_EXTERN(void)
NS_TraceStack(int skip, FILE *ofp);
/**
* Dump a human-readable listing of current allocations and their compressed
* stack backtraces to the file named by pathname. Beware this file may have
* very long lines.
*
* Return -1 on error with errno set by the system, 0 on success.
*/
PR_EXTERN(int)
NS_TraceMallocDumpAllocations(const char *pathname);
/**
* Flush all logfile buffers.
*/
PR_EXTERN(void)
NS_TraceMallocFlushLogfiles(void);
PR_END_EXTERN_C
#endif /* nsTraceMalloc_h___ */

View File

@@ -1,20 +0,0 @@
#ifndef NSTRACEMALLOCCALLBACKS_H
#define NSTRACEMALLOCCALLBACKS_H
PR_BEGIN_EXTERN_C
PR_EXTERN(void) StartupHooker();/*implemented in TraceMalloc.cpp*/
PR_EXTERN(void) ShutdownHooker();
PR_EXTERN(void) MallocCallback(void *aPtr, size_t aSize, PRUint32 start, PRUint32 end);/*implemented in nsTraceMalloc.c*/
PR_EXTERN(void) CallocCallback(void *aPtr, size_t aCount, size_t aSize, PRUint32 start, PRUint32 end);
PR_EXTERN(void) ReallocCallback(void *aPin, void* aPout, size_t aSize, PRUint32 start, PRUint32 end);
PR_EXTERN(void) FreeCallback(void *aPtr, PRUint32 start, PRUint32 end);
PR_END_EXTERN_C
#endif //NSTRACEMALLOCCALLBACKS_H

File diff suppressed because it is too large Load Diff

View File

@@ -1,263 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* L. David Baron <dbaron@fas.harvard.edu>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsTraceRefcnt_h___
#define nsTraceRefcnt_h___
#include "nsCom.h"
#include <stdio.h>
class nsISupports;
// Normaly, the implementation of NS_LOG_ADDREF and NS_LOG_RELEASE
// will use a stack crawl to determine who called Addref/Release on an
// xpcom object. If your platform can't implement a stack crawling
// function, then define this to symbol. When the symbol is defined
// then the NS_LOG_ADDREF_CALL and NS_LOG_RELEASE_CALL will expand
// differently.
#undef NS_LOSING_ARCHITECTURE
// By default refcnt logging is not part of the build.
#undef NS_BUILD_REFCNT_LOGGING
#if (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
// Make refcnt logging part of the build. This doesn't mean that
// actual logging will occur (that requires a seperate enable; see
// nsTraceRefcnt.h for more information).
#define NS_BUILD_REFCNT_LOGGING 1
#endif
// If NO_BUILD_REFCNT_LOGGING is defined then disable refcnt logging
// in the build. This overrides FORCE_BUILD_REFCNT_LOGGING.
#if defined(NO_BUILD_REFCNT_LOGGING)
#undef NS_BUILD_REFCNT_LOGGING
#endif
#ifdef NS_BUILD_REFCNT_LOGGING
#define NS_LOG_ADDREF(_p, _rc, _type, _size) \
nsTraceRefcnt::LogAddRef((_p), (_rc), (_type), (PRUint32) (_size))
#define NS_LOG_RELEASE(_p, _rc, _type) \
nsTraceRefcnt::LogRelease((_p), (_rc), (_type))
#ifdef NS_LOSING_ARCHITECTURE
#define NS_LOG_ADDREF_CALL(_p,_rc,_file,_line) \
nsTraceRefcnt::LogAddRefCall((_p), (_rc), (_file), (_line))
#define NS_LOG_RELEASE_CALL(_p,_rc,_file,_line) \
nsTraceRefcnt::LogReleaseCall((_p), (_rc), (_file), (_line))
#define NS_LOG_NEW_XPCOM(_p,_type,_size,_file,_line) \
nsTraceRefcnt::LogNewXPCOM((_p),(_type),(PRUint32)(_size),(_file),(_line))
#define NS_LOG_DELETE_XPCOM(_p,_file,_line) \
nsTraceRefcnt::LogDeleteXPCOM((_p),(_file),(_line))
#else
#define NS_LOG_ADDREF_CALL(_p,_rc,_file,_line) _rc
#define NS_LOG_RELEASE_CALL(_p,_rc,_file,_line) _rc
#define NS_LOG_NEW_XPCOM(_p,_type,_size,_file,_line)
#define NS_LOG_DELETE_XPCOM(_p,_file,_line)
#endif
#define MOZ_DECL_CTOR_COUNTER(_type)
#define MOZ_COUNT_CTOR(_type) \
PR_BEGIN_MACRO \
nsTraceRefcnt::LogCtor((void*)this, #_type, sizeof(*this)); \
PR_END_MACRO
#define MOZ_COUNT_DTOR(_type) \
PR_BEGIN_MACRO \
nsTraceRefcnt::LogDtor((void*)this, #_type, sizeof(*this)); \
PR_END_MACRO
#ifdef HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR // from autoconf (XXX needs to be
// set for non-autoconf platforms)
// nsCOMPtr.h allows these macros to be defined by clients
// These logging functions require dynamic_cast<void *>, so we don't
// define these macros if we don't have dynamic_cast.
#define NSCAP_LOG_ASSIGNMENT(_c, _p) \
if ((_p)) nsTraceRefcnt::LogAddCOMPtr((_c),NS_STATIC_CAST(nsISupports*,_p))
#define NSCAP_RELEASE(_c, _p); \
if ((_p)) { \
nsTraceRefcnt::LogReleaseCOMPtr((_c),NS_STATIC_CAST(nsISupports*,_p)); \
NS_RELEASE(_p); \
}
#endif /* HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR */
#else /* !NS_BUILD_REFCNT_LOGGING */
#define NS_LOG_ADDREF(_p, _rc, _type, _size)
#define NS_LOG_RELEASE(_p, _rc, _type)
#define NS_LOG_NEW_XPCOM(_p,_type,_size,_file,_line)
#define NS_LOG_DELETE_XPCOM(_p,_file,_line)
#define NS_LOG_ADDREF_CALL(_p,_rc,_file,_line) _rc
#define NS_LOG_RELEASE_CALL(_p,_rc,_file,_line) _rc
#define MOZ_DECL_CTOR_COUNTER(_type)
#define MOZ_COUNT_CTOR(_type)
#define MOZ_COUNT_DTOR(_type)
#endif /* NS_BUILD_REFCNT_LOGGING */
//----------------------------------------------------------------------
struct nsTraceRefcntStats {
nsrefcnt mAddRefs;
nsrefcnt mReleases;
nsrefcnt mCreates;
nsrefcnt mDestroys;
double mRefsOutstandingTotal;
double mRefsOutstandingSquared;
double mObjsOutstandingTotal;
double mObjsOutstandingSquared;
};
// Function type used by GatherStatistics. For each type that data has
// been gathered for, this function is called with the counts of the
// various operations that have been logged. The function can return
// PR_FALSE if the gathering should stop.
//
// aCurrentStats is the current value of the counters. aPrevStats is
// the previous value of the counters which is established by the
// nsTraceRefcnt::SnapshotStatistics call.
typedef PRBool (PR_CALLBACK *nsTraceRefcntStatFunc)
(const char* aTypeName,
PRUint32 aInstanceSize,
nsTraceRefcntStats* aCurrentStats,
nsTraceRefcntStats* aPrevStats,
void *aClosure);
/**
* Note: The implementations for these methods are no-ops in a build
* where NS_BUILD_REFCNT_LOGGING is disabled.
*/
class nsTraceRefcnt {
public:
static NS_COM void Startup();
static NS_COM void Shutdown();
static NS_COM void LogAddRef(void* aPtr,
nsrefcnt aNewRefCnt,
const char* aTypeName,
PRUint32 aInstanceSize);
static NS_COM void LogRelease(void* aPtr,
nsrefcnt aNewRefCnt,
const char* aTypeName);
static NS_COM void LogNewXPCOM(void* aPtr,
const char* aTypeName,
PRUint32 aInstanceSize,
const char* aFile,
int aLine);
static NS_COM void LogDeleteXPCOM(void* aPtr,
const char* aFile,
int aLine);
static NS_COM nsrefcnt LogAddRefCall(void* aPtr,
nsrefcnt aNewRefcnt,
const char* aFile,
int aLine);
static NS_COM nsrefcnt LogReleaseCall(void* aPtr,
nsrefcnt aNewRefcnt,
const char* aFile,
int aLine);
static NS_COM void LogCtor(void* aPtr, const char* aTypeName,
PRUint32 aInstanceSize);
static NS_COM void LogDtor(void* aPtr, const char* aTypeName,
PRUint32 aInstanceSize);
static NS_COM void LogAddCOMPtr(void *aCOMPtr, nsISupports *aObject);
static NS_COM void LogReleaseCOMPtr(void *aCOMPtr, nsISupports *aObject);
enum StatisticsType {
ALL_STATS,
NEW_STATS
};
static NS_COM nsresult DumpStatistics(StatisticsType type = ALL_STATS,
FILE* out = 0);
static NS_COM void ResetStatistics(void);
static NS_COM void GatherStatistics(nsTraceRefcntStatFunc aFunc,
void* aClosure);
static NS_COM void LoadLibrarySymbols(const char* aLibraryName,
void* aLibrayHandle);
static NS_COM void DemangleSymbol(const char * aSymbol,
char * aBuffer,
int aBufLen);
static NS_COM void WalkTheStack(FILE* aStream);
static NS_COM void SetPrefServiceAvailability(PRBool avail);
/**
* Tell nsTraceRefcnt whether refcounting, allocation, and destruction
* activity is legal. This is used to trigger assertions for any such
* activity that occurs because of static constructors or destructors.
*/
static NS_COM void SetActivityIsLegal(PRBool aLegal);
};
////////////////////////////////////////////////////////////////////////////////
// And now for that utility that you've all been asking for...
extern "C" NS_COM void
NS_MeanAndStdDev(double n, double sumOfValues, double sumOfSquaredValues,
double *meanResult, double *stdDevResult);
////////////////////////////////////////////////////////////////////////////////
#endif /* nsTraceRefcnt_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,263 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* L. David Baron <dbaron@fas.harvard.edu>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsTraceRefcnt_h___
#define nsTraceRefcnt_h___
#include "nsCom.h"
#include <stdio.h>
class nsISupports;
// Normaly, the implementation of NS_LOG_ADDREF and NS_LOG_RELEASE
// will use a stack crawl to determine who called Addref/Release on an
// xpcom object. If your platform can't implement a stack crawling
// function, then define this to symbol. When the symbol is defined
// then the NS_LOG_ADDREF_CALL and NS_LOG_RELEASE_CALL will expand
// differently.
#undef NS_LOSING_ARCHITECTURE
// By default refcnt logging is not part of the build.
#undef NS_BUILD_REFCNT_LOGGING
#if (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
// Make refcnt logging part of the build. This doesn't mean that
// actual logging will occur (that requires a seperate enable; see
// nsTraceRefcnt.h for more information).
#define NS_BUILD_REFCNT_LOGGING 1
#endif
// If NO_BUILD_REFCNT_LOGGING is defined then disable refcnt logging
// in the build. This overrides FORCE_BUILD_REFCNT_LOGGING.
#if defined(NO_BUILD_REFCNT_LOGGING)
#undef NS_BUILD_REFCNT_LOGGING
#endif
#ifdef NS_BUILD_REFCNT_LOGGING
#define NS_LOG_ADDREF(_p, _rc, _type, _size) \
nsTraceRefcnt::LogAddRef((_p), (_rc), (_type), (PRUint32) (_size))
#define NS_LOG_RELEASE(_p, _rc, _type) \
nsTraceRefcnt::LogRelease((_p), (_rc), (_type))
#ifdef NS_LOSING_ARCHITECTURE
#define NS_LOG_ADDREF_CALL(_p,_rc,_file,_line) \
nsTraceRefcnt::LogAddRefCall((_p), (_rc), (_file), (_line))
#define NS_LOG_RELEASE_CALL(_p,_rc,_file,_line) \
nsTraceRefcnt::LogReleaseCall((_p), (_rc), (_file), (_line))
#define NS_LOG_NEW_XPCOM(_p,_type,_size,_file,_line) \
nsTraceRefcnt::LogNewXPCOM((_p),(_type),(PRUint32)(_size),(_file),(_line))
#define NS_LOG_DELETE_XPCOM(_p,_file,_line) \
nsTraceRefcnt::LogDeleteXPCOM((_p),(_file),(_line))
#else
#define NS_LOG_ADDREF_CALL(_p,_rc,_file,_line) _rc
#define NS_LOG_RELEASE_CALL(_p,_rc,_file,_line) _rc
#define NS_LOG_NEW_XPCOM(_p,_type,_size,_file,_line)
#define NS_LOG_DELETE_XPCOM(_p,_file,_line)
#endif
#define MOZ_DECL_CTOR_COUNTER(_type)
#define MOZ_COUNT_CTOR(_type) \
PR_BEGIN_MACRO \
nsTraceRefcnt::LogCtor((void*)this, #_type, sizeof(*this)); \
PR_END_MACRO
#define MOZ_COUNT_DTOR(_type) \
PR_BEGIN_MACRO \
nsTraceRefcnt::LogDtor((void*)this, #_type, sizeof(*this)); \
PR_END_MACRO
#ifdef HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR // from autoconf (XXX needs to be
// set for non-autoconf platforms)
// nsCOMPtr.h allows these macros to be defined by clients
// These logging functions require dynamic_cast<void *>, so we don't
// define these macros if we don't have dynamic_cast.
#define NSCAP_LOG_ASSIGNMENT(_c, _p) \
if ((_p)) nsTraceRefcnt::LogAddCOMPtr((_c),NS_STATIC_CAST(nsISupports*,_p))
#define NSCAP_RELEASE(_c, _p); \
if ((_p)) { \
nsTraceRefcnt::LogReleaseCOMPtr((_c),NS_STATIC_CAST(nsISupports*,_p)); \
NS_RELEASE(_p); \
}
#endif /* HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR */
#else /* !NS_BUILD_REFCNT_LOGGING */
#define NS_LOG_ADDREF(_p, _rc, _type, _size)
#define NS_LOG_RELEASE(_p, _rc, _type)
#define NS_LOG_NEW_XPCOM(_p,_type,_size,_file,_line)
#define NS_LOG_DELETE_XPCOM(_p,_file,_line)
#define NS_LOG_ADDREF_CALL(_p,_rc,_file,_line) _rc
#define NS_LOG_RELEASE_CALL(_p,_rc,_file,_line) _rc
#define MOZ_DECL_CTOR_COUNTER(_type)
#define MOZ_COUNT_CTOR(_type)
#define MOZ_COUNT_DTOR(_type)
#endif /* NS_BUILD_REFCNT_LOGGING */
//----------------------------------------------------------------------
struct nsTraceRefcntStats {
nsrefcnt mAddRefs;
nsrefcnt mReleases;
nsrefcnt mCreates;
nsrefcnt mDestroys;
double mRefsOutstandingTotal;
double mRefsOutstandingSquared;
double mObjsOutstandingTotal;
double mObjsOutstandingSquared;
};
// Function type used by GatherStatistics. For each type that data has
// been gathered for, this function is called with the counts of the
// various operations that have been logged. The function can return
// PR_FALSE if the gathering should stop.
//
// aCurrentStats is the current value of the counters. aPrevStats is
// the previous value of the counters which is established by the
// nsTraceRefcnt::SnapshotStatistics call.
typedef PRBool (PR_CALLBACK *nsTraceRefcntStatFunc)
(const char* aTypeName,
PRUint32 aInstanceSize,
nsTraceRefcntStats* aCurrentStats,
nsTraceRefcntStats* aPrevStats,
void *aClosure);
/**
* Note: The implementations for these methods are no-ops in a build
* where NS_BUILD_REFCNT_LOGGING is disabled.
*/
class nsTraceRefcnt {
public:
static NS_COM void Startup();
static NS_COM void Shutdown();
static NS_COM void LogAddRef(void* aPtr,
nsrefcnt aNewRefCnt,
const char* aTypeName,
PRUint32 aInstanceSize);
static NS_COM void LogRelease(void* aPtr,
nsrefcnt aNewRefCnt,
const char* aTypeName);
static NS_COM void LogNewXPCOM(void* aPtr,
const char* aTypeName,
PRUint32 aInstanceSize,
const char* aFile,
int aLine);
static NS_COM void LogDeleteXPCOM(void* aPtr,
const char* aFile,
int aLine);
static NS_COM nsrefcnt LogAddRefCall(void* aPtr,
nsrefcnt aNewRefcnt,
const char* aFile,
int aLine);
static NS_COM nsrefcnt LogReleaseCall(void* aPtr,
nsrefcnt aNewRefcnt,
const char* aFile,
int aLine);
static NS_COM void LogCtor(void* aPtr, const char* aTypeName,
PRUint32 aInstanceSize);
static NS_COM void LogDtor(void* aPtr, const char* aTypeName,
PRUint32 aInstanceSize);
static NS_COM void LogAddCOMPtr(void *aCOMPtr, nsISupports *aObject);
static NS_COM void LogReleaseCOMPtr(void *aCOMPtr, nsISupports *aObject);
enum StatisticsType {
ALL_STATS,
NEW_STATS
};
static NS_COM nsresult DumpStatistics(StatisticsType type = ALL_STATS,
FILE* out = 0);
static NS_COM void ResetStatistics(void);
static NS_COM void GatherStatistics(nsTraceRefcntStatFunc aFunc,
void* aClosure);
static NS_COM void LoadLibrarySymbols(const char* aLibraryName,
void* aLibrayHandle);
static NS_COM void DemangleSymbol(const char * aSymbol,
char * aBuffer,
int aBufLen);
static NS_COM void WalkTheStack(FILE* aStream);
static NS_COM void SetPrefServiceAvailability(PRBool avail);
/**
* Tell nsTraceRefcnt whether refcounting, allocation, and destruction
* activity is legal. This is used to trigger assertions for any such
* activity that occurs because of static constructors or destructors.
*/
static NS_COM void SetActivityIsLegal(PRBool aLegal);
};
////////////////////////////////////////////////////////////////////////////////
// And now for that utility that you've all been asking for...
extern "C" NS_COM void
NS_MeanAndStdDev(double n, double sumOfValues, double sumOfSquaredValues,
double *meanResult, double *stdDevResult);
////////////////////////////////////////////////////////////////////////////////
#endif /* nsTraceRefcnt_h___ */

View File

@@ -1,292 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is nsTypeInfo.cpp code, released
* November 27, 2000.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Patrick C. Beard <beard@netscape.com>
* Chris Waterson <waterson@netscape.com>
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*/
/*
typeinfo.cpp
Speculatively use RTTI on a random object. If it contains a pointer at offset 0
that is in the current process' address space, and that so on, then attempt to
use C++ RTTI's typeid operation to obtain the name of the type.
by Patrick C. Beard.
*/
#include <typeinfo>
#include <ctype.h>
extern "C" const char* nsGetTypeName(void* ptr);
class IUnknown {
public:
virtual long QueryInterface() = 0;
virtual long AddRef() = 0;
virtual long Release() = 0;
};
#if defined(MACOS)
#include <Processes.h>
class AddressSpace {
public:
AddressSpace();
Boolean contains(void* ptr);
private:
ProcessInfoRec mInfo;
};
AddressSpace::AddressSpace()
{
ProcessSerialNumber psn = { 0, kCurrentProcess };
mInfo.processInfoLength = sizeof(mInfo);
::GetProcessInformation(&psn, &mInfo);
}
Boolean AddressSpace::contains(void* ptr)
{
UInt32 start = UInt32(mInfo.processLocation);
return (UInt32(ptr) >= start && UInt32(ptr) < (start + mInfo.processSize));
}
const char* nsGetTypeName(void* ptr)
{
// construct only one of these per process.
static AddressSpace space;
// sanity check the vtable pointer, before trying to use RTTI on the object.
void** vt = *(void***)ptr;
if (vt && !(unsigned(vt) & 0x3) && space.contains(vt) && space.contains(*vt)) {
IUnknown* u = static_cast<IUnknown*>(ptr);
const char* type = typeid(*u).name();
// make sure it looks like a C++ identifier.
if (type && (isalnum(type[0]) || type[0] == '_'))
return type;
}
return "void*";
}
#endif
// New, more "portable" Linux code is below, but this might be a useful
// model for other platforms, so keeping.
//#if defined(linux)
#if 0
#include <signal.h>
#include <setjmp.h>
static jmp_buf context;
static void handler(int signum)
{
longjmp(context, signum);
}
#define attempt() setjmp(context)
class Signaller {
public:
Signaller(int signum);
~Signaller();
private:
typedef void (*handler_t) (int signum);
int mSignal;
handler_t mOldHandler;
};
Signaller::Signaller(int signum)
: mSignal(signum), mOldHandler(signal(signum, &handler))
{
}
Signaller::~Signaller()
{
signal(mSignal, mOldHandler);
}
// The following are pointers that bamboozle our otherwise feeble
// attempts to "safely" collect type names.
//
// XXX this kind of sucks because it means that anyone trying to use
// this without NSPR will get unresolved symbols when this library
// loads. It's also not very extensible. Oh well: FIX ME!
extern "C" {
// from nsprpub/pr/src/io/priometh.c (libnspr4.so)
extern void* _pr_faulty_methods;
};
static inline int
sanity_check_vtable_i386(void** vt)
{
// Now that we're "safe" inside the signal handler, we can
// start poking around. If we're really an object with
// RTTI, then the second entry in the vtable should point
// to a function.
//
// Let's see if the second entry:
//
// 1) looks like a 4-byte aligned pointer
//
// 2) points to something that looks like the following
// i386 instructions:
//
// 55 push %ebp
// 89e5 mov %esp,%ebp
// 53 push %ebx
//
// or
//
// 55 push %ebp
// 89e5 mov %esp,%ebp
// 56 push %esi
//
// (which is the standard function prologue generated
// by egcs, plus a ``signature'' instruction that appears
// in the typeid() function's implementation).
unsigned char** fp1 = reinterpret_cast<unsigned char**>(vt) + 1;
// Does it look like an address?
unsigned char* ip = *fp1;
if ((unsigned(ip) & 3) != 0)
return 0;
// Does it look like it refers to the standard prologue?
static unsigned char prologue[] = { 0x55, 0x89, 0xE5 };
for (unsigned i = 0; i < sizeof(prologue); ++i)
if (*ip++ != prologue[i])
return 0;
// Is the next instruction a `push %ebx' or `push %esi'?
if (*ip == 0x53 || *ip == 0x56) {
return 1;
}
// Nope. There's another variant that has a `sub' instruction,
// followed by a `cmpl' and a `jne'. Check for that.
if (ip[0] == 0x83 && ip[1] == 0xec // sub
&& ip[3] == 0x83 && ip[4] == 0x3d // cmpl
&& ip[10] == 0x75 // jne
) {
return 1;
}
return 0;
}
static inline int
sanity_check_vtable_ppc(void** vt)
{
// XXX write me!
return 1;
}
#if defined(__i386)
# define SANITY_CHECK_VTABLE(vt) (sanity_check_vtable_i386(vt))
#elif defined(PPC)
# define SANITY_CHECK_VTABLE(vt) (sanity_check_vtable_ppc(vt))
#else
# define SANITY_CHECK_VTABLE(vt) (1)
#endif
const char* nsGetTypeName(void* ptr)
{
// sanity check the vtable pointer, before trying to use RTTI on the object.
void** vt = *(void***)ptr;
if (vt && !(unsigned(vt) & 3) && (vt != &_pr_faulty_methods)) {
Signaller s1(SIGSEGV);
if (attempt() == 0) {
if (SANITY_CHECK_VTABLE(vt)) {
// Looks like a function: what the hell, let's call it.
IUnknown* u = static_cast<IUnknown*>(ptr);
const char* type = typeid(*u).name();
// EGCS seems to prefix a length string.
while (isdigit(*type)) ++type;
return type;
}
}
}
return "void*";
}
#endif
#if defined(linux)
#define __USE_GNU
#include <dlfcn.h>
#include <ctype.h>
#include <string.h>
const char* nsGetTypeName(void* ptr)
{
#if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100 /* G++ V3 ABI */
const int expected_offset = 8;
const char vtable_sym_start[] = "_ZTV";
const int vtable_sym_start_length = sizeof(vtable_sym_start) - 1;
#else
const int expected_offset = 0;
const char vtable_sym_start[] = "__vt_";
const int vtable_sym_start_length = sizeof(vtable_sym_start) - 1;
#endif
void* vt = *(void**)ptr;
Dl_info info;
// If dladdr fails, if we're not at the expected offset in the vtable,
// or if the symbol name isn't a vtable symbol name, return "void*".
if ( !dladdr(vt, &info) ||
((char*)info.dli_saddr) + expected_offset != vt ||
!info.dli_sname ||
strncmp(info.dli_sname, vtable_sym_start, vtable_sym_start_length))
return "void*";
// skip the garbage at the beginning of things like
// __vt_14nsRootBoxFrame (gcc 2.96) or _ZTV14nsRootBoxFrame (gcc 3.0)
const char* rv = info.dli_sname + vtable_sym_start_length;
while (*rv && isdigit(*rv))
++rv;
return rv;
}
#endif
#ifdef XP_WIN32
const char* nsGetTypeName(void* ptr)
{
//TODO: COMPLETE THIS
return "void*";
}
#endif //XP_WIN32

View File

@@ -1,31 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Scott Collins <scc@netscape.com>
*/
#ifndef nsWeakPtr_h__
#define nsWeakPtr_h__
#include "nsIWeakReference.h"
#include "nsCOMPtr.h"
// typedef nsCOMPtr<nsIWeakReference> nsWeakPtr;
#endif

View File

@@ -1,438 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "prtypes.h"
#include "prlock.h"
#include "nscore.h"
#include "nsAutoLock.h"
#include "nsDebugHelpWin32.h"
#include "nsTraceMallocCallbacks.h"
// XXX These are *very* quick hacks and need improvement!
static PRBool GetSymbolFromAddress(uint32 addr, char* outBuf)
{
PRBool ok;
ok = dhwEnsureSymInitialized();
if(!ok)
return ok;
char buf[sizeof(IMAGEHLP_SYMBOL) + 512];
PIMAGEHLP_SYMBOL symbol = (PIMAGEHLP_SYMBOL) buf;
symbol->SizeOfStruct = sizeof(buf);
symbol->MaxNameLength = 512;
DWORD displacement;
ok = dhwSymGetSymFromAddr(::GetCurrentProcess(),
addr,
&displacement,
symbol);
if(ok)
{
char buf2[512];
sprintf(buf2, "%s+0x%08X", symbol->Name, displacement);
strcat(outBuf, buf2);
}
else
strcat(outBuf, "dunno");
return ok;
}
static PRBool GetModuleFromAddress(uint32 addr, char* outBuf)
{
PRBool ok;
ok = dhwEnsureSymInitialized();
if(!ok)
return ok;
IMAGEHLP_MODULE module;
module.SizeOfStruct = sizeof(IMAGEHLP_MODULE);
ok = dhwSymGetModuleInfo(::GetCurrentProcess(),
addr,
&module);
if(ok)
strcat(outBuf, module.ModuleName);
else
strcat(outBuf, "dunno");
return ok;
}
/***************************************************************************/
#ifdef VERBOSE
#define SHOW(x_, buf_) \
printf(#x_" = %#x... %s\n", x_, \
(buf_[0] = 0, \
GetModuleFromAddress((uint32)x_, buf_), \
strcat(buf," :: "), \
GetSymbolFromAddress((uint32)x_, buf_), \
buf_));
#else
#define SHOW(x_, buf_)
#endif //VERBOSE
/***************************************************************************/
#ifdef VERBOSE
// XXX This is a quick hack to show that x86 Win32 stack walking can be done
// with this sort of loop following the bp.
void dumpStack()
{
uint32* bp_;
uint32* bpdown;
uint32 pc;
char buf[512];
_asm { mov bp_ , ebp }
/* Stack walking code adapted from Kipp's "leaky". */
while (1) {
bpdown = (uint32*) *bp_++;
pc = *bp_;
// These addresses are iffy...
if (pc < 0x00400000 || pc > 0x7fffffff || bpdown < bp_)
break;
SHOW(pc, buf);
bp_ = bpdown;
}
printf("\n");
}
#endif
char* _stdcall call2(void* v)
{
// dumpStack();
// return 0;
return (char *)malloc(123);
}
int call1(char c, int i, double d, ... )
{
free(call2(0));
return 0;
}
/***************************************************************************/
// shows how to use the dhw stuff to hook imported functions
static BOOL g_lockOut = FALSE; //stop reentrancy
DHW_DECLARE_FUN_TYPE_AND_PROTO(dhw_malloc, void*, __cdecl, MALLOC_, (size_t));
DHWImportHooker &getMallocHooker()
{
static DHWImportHooker gMallocHooker("MSVCRTD.dll", "malloc", (PROC) dhw_malloc);
return gMallocHooker;
}
void * __cdecl dhw_malloc( size_t size )
{
PRUint32 start = PR_IntervalNow();
void* result = DHW_ORIGINAL(MALLOC_, getMallocHooker())(size);
PRUint32 end = PR_IntervalNow();
if (g_lockOut)
return result;
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* malloc called to get %d bytes. returned %#x\n", size, result);
#endif
MallocCallback(result, size, start, end);
// dumpStack();
// printf("\n");
g_lockOut = FALSE;
return result;
}
DHW_DECLARE_FUN_TYPE_AND_PROTO(dhw_calloc, void*, __cdecl, CALLOC_, (size_t,size_t));
DHWImportHooker &getCallocHooker()
{
static DHWImportHooker gCallocHooker("MSVCRTD.dll", "calloc", (PROC) dhw_calloc);
return gCallocHooker;
}
void * __cdecl dhw_calloc( size_t count, size_t size )
{
PRUint32 start = PR_IntervalNow();
void* result = DHW_ORIGINAL(CALLOC_, getCallocHooker())(count,size);
PRUint32 end = PR_IntervalNow();
if (g_lockOut)
return result;
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* calloc called to get %d many of %d bytes. returned %#x\n", count, size, result);
#endif
CallocCallback(result, count, size, start, end);
// dumpStack();
// printf("\n");
g_lockOut = FALSE;
return result;
}
DHW_DECLARE_FUN_TYPE_AND_PROTO(dhw_free, void, __cdecl, FREE_, (void*));
DHWImportHooker &getFreeHooker()
{
static DHWImportHooker gFreeHooker("MSVCRTD.dll", "free", (PROC) dhw_free);
return gFreeHooker;
}
void __cdecl dhw_free( void* p )
{
PRUint32 start = PR_IntervalNow();
DHW_ORIGINAL(FREE_, getFreeHooker())(p);
PRUint32 end = PR_IntervalNow();
if (g_lockOut)
return;
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* free called for %#x\n", p);
#endif
FreeCallback(p, start, end);
// dumpStack();
// printf("\n");
g_lockOut = FALSE;
}
DHW_DECLARE_FUN_TYPE_AND_PROTO(dhw_realloc, void*, __cdecl, REALLOC_, (void*, size_t));
DHWImportHooker &getReallocHooker()
{
static DHWImportHooker gReallocHooker("MSVCRTD.dll", "realloc", (PROC) dhw_realloc);
return gReallocHooker;
}
void * __cdecl dhw_realloc(void * pin, size_t size)
{
PRUint32 start = PR_IntervalNow();
void* pout = DHW_ORIGINAL(REALLOC_, getReallocHooker())(pin, size);
PRUint32 end = PR_IntervalNow();
if (g_lockOut)
return pout;
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* realloc called to resize to %d. old ptr: %#x. new ptr: %#x\n",
size, pin, pout);
#endif
ReallocCallback(pin, pout, size, start, end);
// dumpStack();
// printf("\n");
g_lockOut = FALSE;
return pout;
}
// Note the mangled name!
DHW_DECLARE_FUN_TYPE_AND_PROTO(dhw_new, void*, __cdecl, NEW_, (size_t));
DHWImportHooker &getNewHooker()
{
static DHWImportHooker gNewHooker("MSVCRTD.dll", "??2@YAPAXI@Z", (PROC) dhw_new);
return gNewHooker;
}
void * __cdecl dhw_new(size_t size)
{
PRUint32 start = PR_IntervalNow();
void* result = DHW_ORIGINAL(NEW_, getNewHooker())(size);
PRUint32 end = PR_IntervalNow();
if (g_lockOut)
return result;
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* new called to get %d bytes. returned %#x\n", size, result);
dumpStack();
#endif
MallocCallback(result, size, start, end);//do we need a different one for new?
// printf("\n");
g_lockOut = FALSE;
return result;
}
// Note the mangled name!
DHW_DECLARE_FUN_TYPE_AND_PROTO(dhw_delete, void, __cdecl, DELETE_, (void*));
DHWImportHooker &getDeleteHooker()
{
static DHWImportHooker gDeleteHooker("MSVCRTD.dll", "??3@YAXPAX@Z", (PROC) dhw_delete);
return gDeleteHooker;
}
void __cdecl dhw_delete(void* p)
{
PRUint32 start = PR_IntervalNow();
DHW_ORIGINAL(DELETE_, getDeleteHooker())(p);
PRUint32 end = PR_IntervalNow();
if (g_lockOut)
return;
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* delete called for %#x\n", p);
dumpStack();
#endif
FreeCallback(p, start, end);
// printf("\n");
g_lockOut = FALSE;
}
/***************************************************************************/
// A demonstration of using the _CrtSetAllocHook based hooking.
// This system sucks because you don't get to see the allocated pointer.
#if 0
class myAllocationSizePrinter : public DHWAllocationSizeDebugHook
{
public:
PRBool AllocHook(size_t size)
{
alloc_calls++ ;
total_mem += size;
if(verbosity)
{
printf("alloc called to get %d bytes.\n", size);
dumpStack();
}
return PR_TRUE;
}
PRBool ReallocHook(size_t size, size_t sizeOld)
{
realloc_calls++ ;
total_mem += size;
total_mem -= sizeOld;
if(verbosity)
{
printf("realloc called to size to %d bytes. Old size: %d.\n",
size, sizeOld);
dumpStack();
}
return PR_TRUE;
}
PRBool FreeHook(size_t size)
{
free_calls++ ;
total_mem -= size;
if(verbosity)
{
printf("free called to release %d bytes.\n", size);
dumpStack();
}
return PR_TRUE;
}
myAllocationSizePrinter(int v)
: verbosity(v),
alloc_calls(0),
realloc_calls(0),
free_calls(0),
total_mem(0) {}
virtual ~myAllocationSizePrinter(){}
void report()
{
printf("%d allocs, %d reallocs, %d frees, %d bytes leaked\n",
alloc_calls, realloc_calls, free_calls, total_mem);
}
private:
void dumpStack()
{
if(verbosity == 2)
::dumpStack();
}
int verbosity;
int alloc_calls;
int realloc_calls;
int free_calls;
size_t total_mem;
};
#endif
/*C Callbacks*/
PR_IMPLEMENT(void)
StartupHooker()
{
if (!dhwEnsureSymInitialized())
return;
//run through get all hookers
DHWImportHooker &loadlibraryW = DHWImportHooker::getLoadLibraryWHooker();
DHWImportHooker &loadlibraryExW = DHWImportHooker::getLoadLibraryExWHooker();
DHWImportHooker &loadlibraryA = DHWImportHooker::getLoadLibraryAHooker();
DHWImportHooker &loadlibraryExA = DHWImportHooker::getLoadLibraryExAHooker();
DHWImportHooker &mallochooker = getMallocHooker();
DHWImportHooker &reallochooker = getReallocHooker();
DHWImportHooker &callochooker = getCallocHooker();
DHWImportHooker &freehooker = getFreeHooker();
DHWImportHooker &newhooker = getNewHooker();
DHWImportHooker &deletehooker = getDeleteHooker();
printf("Startup Hooker\n");
}
PR_IMPLEMENT(void)
ShutdownHooker()
{
}
#if 0
int main()
{
// A demonstration of using the (sucky) _CrtSetAllocHook based hooking.
myAllocationSizePrinter ap(0);
dhwSetAllocationSizeDebugHook(&ap);
// show that the ImportHooker is hooking calls from loaded dll
DHW_DECLARE_FUN_TYPE(void, __stdcall, SOMECALL_, (void));
HMODULE module = ::LoadLibrary("Other.dll");
if(module) {
SOMECALL_ _SomeCall = (SOMECALL_) GetProcAddress(module, "SomeCall");
if(_SomeCall)
_SomeCall();
}
// show that the ImportHooker is hooking sneaky calls made from this dll.
HMODULE module2 = ::LoadLibrary("MSVCRTD.dll");
if(module2) {
MALLOC_ _sneakyMalloc = (MALLOC_) GetProcAddress(module2, "malloc");
if(_sneakyMalloc)
{
void* p = _sneakyMalloc(987);
free(p);
}
}
call1('x', 1, 1.0, "hi there", 2);
char* p = new char[10];
delete p;
void* v = malloc(10);
v = realloc(v, 15);
v = realloc(v, 5);
free(v);`
ap.report();
dhwClearAllocationSizeDebugHook();
return 0;
}
#endif //0

View File

@@ -1,310 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nscore_h___
#define nscore_h___
/**
* Incorporate the core NSPR data types which XPCOM uses.
*/
#include "prtypes.h"
/* Core XPCOM declarations. */
/**
* Macros defining the target platform...
*/
#ifdef _WIN32
#define NS_WIN32 1
#elif defined(__unix)
#define NS_UNIX 1
#elif defined(XP_OS2)
#define NS_OS2 1
#endif
/*----------------------------------------------------------------------*/
/* Import/export defines */
#ifdef NS_WIN32
#define NS_IMPORT _declspec(dllimport)
#define NS_IMPORT_(type) type _declspec(dllimport) __stdcall
#define NS_EXPORT _declspec(dllexport)
#define NS_EXPORT_(type) type _declspec(dllexport) __stdcall
#define NS_IMETHOD_(type) virtual type __stdcall
#define NS_IMETHODIMP_(type) type __stdcall
#define NS_METHOD_(type) type __stdcall
#define NS_CALLBACK_(_type, _name) _type (__stdcall * _name)
#elif defined(XP_MAC)
#define NS_IMPORT
#define NS_IMPORT_(type) type
#define NS_EXPORT __declspec(export)
#define NS_EXPORT_(type) __declspec(export) type
#define NS_IMETHOD_(type) virtual type
#define NS_IMETHODIMP_(type) type
#define NS_METHOD_(type) type
#define NS_CALLBACK_(_type, _name) _type (* _name)
#elif defined(XP_OS2)
#define NS_IMPORT
#define NS_IMPORT_(type) type
#define NS_EXPORT
#define NS_EXPORT_(type) type
#define NS_IMETHOD_(type) virtual type
#define NS_IMETHODIMP_(type) type
#define NS_METHOD_(type) type
#define NS_CALLBACK_(_type, _name) _type (* _name)
#else
#define NS_IMPORT
#define NS_IMPORT_(type) type
#define NS_EXPORT
#define NS_EXPORT_(type) type
#define NS_IMETHOD_(type) virtual type
#define NS_IMETHODIMP_(type) type
#define NS_METHOD_(type) type
#define NS_CALLBACK_(_type, _name) _type (* _name)
#endif
/**
* Generic API modifiers which return the standard XPCOM nsresult type
*/
#define NS_IMETHOD NS_IMETHOD_(nsresult)
#define NS_IMETHODIMP NS_IMETHODIMP_(nsresult)
#define NS_METHOD NS_METHOD_(nsresult)
#define NS_CALLBACK(_name) NS_CALLBACK_(nsresult, _name)
/**
* Import/Export macros for XPCOM APIs
*/
#ifdef _IMPL_NS_COM
#define NS_COM NS_EXPORT
#else
#define NS_COM NS_IMPORT
#endif
/**
* NS_NO_VTABLE is emitted by xpidl in interface declarations whenever
* xpidl can determine that the interface can't contain a constructor.
* This results in some space savings and possible runtime savings -
* see bug 49416. We undefine it first, as xpidl-generated headers
* define it for IDL uses that don't include this file.
*/
#ifdef NS_NO_VTABLE
#undef NS_NO_VTABLE
#endif
#if defined(_MSC_VER) && _MSC_VER >= 1100
#define NS_NO_VTABLE __declspec(novtable)
#else
#define NS_NO_VTABLE
#endif
/**
* Generic XPCOM result data type
*/
typedef PRUint32 nsresult;
/**
* The preferred symbol for null.
*/
#define nsnull 0
/* ------------------------------------------------------------------------ */
/* Casting macros for hiding C++ features from older compilers */
/*
All our compiler support template specialization, but not all support the
|template <>| notation. The compiler that don't understand this notation
just omit it for specialization.
Need to add an autoconf test for this.
*/
/* under Metrowerks (Mac), we don't have autoconf yet */
#ifdef __MWERKS__
#define HAVE_CPP_SPECIALIZATION
#define HAVE_CPP_PARTIAL_SPECIALIZATION
#define HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
#define HAVE_CPP_ACCESS_CHANGING_USING
#define HAVE_CPP_AMBIGUITY_RESOLVING_USING
#define HAVE_CPP_EXPLICIT
#define HAVE_CPP_TYPENAME
#define HAVE_CPP_BOOL
#define HAVE_CPP_NAMESPACE_STD
#define HAVE_CPP_UNAMBIGUOUS_STD_NOTEQUAL
#define HAVE_CPP_2BYTE_WCHAR_T
#endif
/* under VC++ (Windows), we don't have autoconf yet */
#if defined(_MSC_VER) && (_MSC_VER>=1100)
/* VC++ 5.0 and greater implement template specialization, 4.2 is unknown */
#define HAVE_CPP_SPECIALIZATION
#define HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
#define HAVE_CPP_EXPLICIT
#define HAVE_CPP_TYPENAME
#define HAVE_CPP_ACCESS_CHANGING_USING
#if (_MSC_VER<1100)
/* before 5.0, VC++ couldn't handle explicit */
#undef HAVE_CPP_EXPLICIT
#elif (_MSC_VER==1100)
/* VC++5.0 has an internal compiler error (sometimes) without this */
#undef HAVE_CPP_ACCESS_CHANGING_USING
#endif
#define HAVE_CPP_NAMESPACE_STD
#define HAVE_CPP_UNAMBIGUOUS_STD_NOTEQUAL
#define HAVE_CPP_2BYTE_WCHAR_T
#endif
/* until we get an autoconf test for this, we'll assume it's on (since we're using it already) */
#define HAVE_CPP_TYPENAME
/* waiting to find out if OS/2 VisualAge participates in autoconf */
#if defined(XP_OS2_VACPP) || defined(AIX_XLC_364) || (defined(IRIX) && !defined(__GNUC__))
#undef HAVE_CPP_TYPENAME
#endif
#ifndef __PRUNICHAR__
#define __PRUNICHAR__
/* For now, don't use wchar_t on Unix because it breaks the Netscape
* commercial build. When this is fixed there will be no need for the
* |NS_REINTERPRET_CAST| in nsLiteralString.h either.
*/
#if defined(HAVE_CPP_2BYTE_WCHAR_T) && (defined(NS_WIN32) || defined(XP_MAC))
typedef wchar_t PRUnichar;
#else
typedef PRUint16 PRUnichar;
#endif
#endif
/*
If the compiler doesn't support |explicit|, we'll just make it go away, trusting
that the builds under compilers that do have it will keep us on the straight and narrow.
*/
#ifndef HAVE_CPP_EXPLICIT
#define explicit
#endif
#ifndef HAVE_CPP_TYPENAME
#define typename
#endif
#ifdef HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
#define NS_SPECIALIZE_TEMPLATE template <>
#else
#define NS_SPECIALIZE_TEMPLATE
#endif
/* unix and beos now determine this automatically */
#if ! defined XP_UNIX && ! defined XP_BEOS && !defined(XP_OS2)
#define HAVE_CPP_NEW_CASTS /* we'll be optimistic. */
#endif
#if defined(HAVE_CPP_NEW_CASTS)
#define NS_STATIC_CAST(__type, __ptr) static_cast< __type >(__ptr)
#define NS_CONST_CAST(__type, __ptr) const_cast< __type >(__ptr)
#define NS_REINTERPRET_POINTER_CAST(__type, __ptr) reinterpret_cast< __type >(__ptr)
#define NS_REINTERPRET_NONPOINTER_CAST(__type, __obj) reinterpret_cast< __type >(__obj)
#define NS_REINTERPRET_CAST(__type, __expr) reinterpret_cast< __type >(__expr)
#else
#define NS_STATIC_CAST(__type, __ptr) ((__type)(__ptr))
#define NS_CONST_CAST(__type, __ptr) ((__type)(__ptr))
#define NS_REINTERPRET_POINTER_CAST(__type, __ptr) ((__type)((void*)(__ptr)))
#define NS_REINTERPRET_NONPOINTER_CAST(__type, __obj) ((__type)(__obj))
/* Note: the following is only appropriate for pointers. */
#define NS_REINTERPRET_CAST(__type, __expr) NS_REINTERPRET_POINTER_CAST(__type, __expr)
/*
Why cast to a |void*| first? Well, when old-style casting from
a pointer to a base to a pointer to a derived class, the cast will be
ambiguous if the source pointer type appears multiple times in the
destination, e.g.,
class Base {};
class Derived : public Base, public Base {};
void foo( Base* b )
{
((Derived*)b)->some_derived_member ... // Error: Ambiguous, expand from which |Base|?
}
an old-style cast (like |static_cast|) will change the pointer, but
here, doesn't know how. The cast to |void*| prevents it from thinking
it needs to expand the original pointer.
The cost is, |NS_REINTERPRET_CAST| is no longer appropriate for non-pointer
conversions. Also, mis-applying |NS_REINTERPRET_CAST| to cast |this| to something
will still expand the pointer to the outer object in standards complying compilers.
*/
/*
No sense in making an NS_DYNAMIC_CAST() macro: you can't duplicate
the semantics. So if you want to dynamic_cast, then just use it
"straight", no macro.
*/
#endif
/*
* Use these macros to do 64bit safe pointer conversions.
*/
#define NS_PTR_TO_INT32(x) ((char *)(x) - (char *)0)
#define NS_INT32_TO_PTR(x) ((void *)((char *)0 + (x)))
/* Include deprecated APIs... */
#ifndef nsComObsolete_h__
#include "nsComObsolete.h"
#endif
#endif /* nscore_h___ */

View File

@@ -1,128 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dan Rosen <dr@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Root idl declarations to be used by all.
* @status FROZEN
*/
%{C++
#include "nscore.h"
#include "prtime.h"
/*
* Forward declarations for new string types
*/
class nsAString;
class nsACString;
/*
* Start commenting out the C++ versions of the below in the output header
*/
#if 0
%}
typedef boolean PRBool ;
typedef octet PRUint8 ;
typedef unsigned short PRUint16 ;
typedef unsigned short PRUnichar;
typedef unsigned long PRUint32 ;
typedef unsigned long long PRUint64 ;
typedef unsigned long long PRTime ;
typedef short PRInt16 ;
typedef long PRInt32 ;
typedef long long PRInt64 ;
typedef unsigned long nsrefcnt ;
typedef unsigned long nsresult ;
// XXX need this built into xpidl compiler so that it's really size_t or PRSize
// and it's scriptable:
typedef unsigned long size_t;
[ptr] native voidPtr(void);
[ptr] native charPtr(char);
[ptr] native unicharPtr(PRUnichar);
[ref, nsid] native nsIDRef(nsID);
[ref, nsid] native nsIIDRef(nsIID);
[ref, nsid] native nsCIDRef(nsCID);
[ptr, nsid] native nsIDPtr(nsID);
[ptr, nsid] native nsIIDPtr(nsIID);
[ptr, nsid] native nsCIDPtr(nsCID);
// NOTE: Be careful in using the following 3 types. The *Ref and *Ptr variants
// are more commonly used (and better supported). Those variants require
// nsMemory alloc'd copies when used as 'out' params while these types do not.
// However, currently these types can not be used for 'in' params. And, methods
// that use them as 'out' params *must* be declared [notxpcom] (with an explicit
// return type of nsresult). This makes such methods implicitly not scriptable.
// Use of these types in methods without a [notxpcom] declaration will cause
// the xpidl compiler to raise an error.
// See: http://bugzilla.mozilla.org/show_bug.cgi?id=93792
[nsid] native nsIID(nsIID);
[nsid] native nsID(nsID);
[nsid] native nsCID(nsCID);
[ptr] native nsQIResult(void);
[ref, domstring] native DOMString(ignored);
[ref, domstring] native DOMStringRef(ignored);
[ptr, domstring] native DOMStringPtr(ignored);
[ref, utf8string] native AUTF8String(ignored);
[ref, utf8string] native AUTF8StringRef(ignored);
[ptr, utf8string] native AUTF8StringPtr(ignored);
[ref, cstring] native ACString(ignored);
[ref, cstring] native ACStringRef(ignored);
[ptr, cstring] native ACStringPtr(ignored);
[ref, astring] native AString(ignored);
[ref, astring] native AStringRef(ignored);
[ptr, astring] native AStringPtr(ignored);
%{C++
/*
* End commenting out the C++ versions of the above in the output header
*/
#endif
%}

View File

@@ -1,135 +0,0 @@
/*
* Header file of Pure API function declarations.
*
* Explicitly no copyright.
* You may recompile and redistribute these definitions as required.
*
* Version 1.0
*/
#if defined(c_plusplus) || defined(__cplusplus)
extern "C" {
#endif
#define PURE_H_VERSION 1
//////////////////////////////
// API's Specific to Purify //
//////////////////////////////
// TRUE when Purify is running.
int __cdecl PurifyIsRunning(void) ;
//
// Print a string to the viewer.
//
int __cdecl PurePrintf(const char *fmt, ...) ;
int __cdecl PurifyPrintf(const char *fmt, ...) ;
//
// Purify functions for leak and memory-in-use functionalty.
//
int __cdecl PurifyNewInuse(void) ;
int __cdecl PurifyAllInuse(void) ;
int __cdecl PurifyClearInuse(void) ;
int __cdecl PurifyNewLeaks(void) ;
int __cdecl PurifyAllLeaks(void) ;
int __cdecl PurifyClearLeaks(void) ;
//
// Purify functions for handle leakage.
//
int __cdecl PurifyAllHandlesInuse(void) ;
int __cdecl PurifyNewHandlesInuse(void) ;
//
// Functions that tell you about the state of memory.
//
int __cdecl PurifyDescribe(void *addr) ;
int __cdecl PurifyWhatColors(void *addr, int size) ;
//
// Functions to test the state of memory. If the memory is not
// accessable, an error is signaled just as if there were a memory
// reference and the function returns false.
//
int __cdecl PurifyAssertIsReadable(const void *addr, int size) ;
int __cdecl PurifyAssertIsWritable(const void *addr, int size) ;
//
// Functions to test the state of memory. If the memory is not
// accessable, these functions return false. No error is signaled.
//
int __cdecl PurifyIsReadable(const void *addr, int size) ;
int __cdecl PurifyIsWritable(const void *addr, int size) ;
int __cdecl PurifyIsInitialized(const void *addr, int size) ;
//
// Functions to set the state of memory.
//
void __cdecl PurifyMarkAsInitialized(void *addr, int size) ;
void __cdecl PurifyMarkAsUninitialized(void *addr, int size) ;
//
// Functions to do late detection of ABWs, FMWs, IPWs.
//
#define PURIFY_HEAP_CRT 0xfffffffe
#define PURIFY_HEAP_ALL 0xfffffffd
#define PURIFY_HEAP_BLOCKS_LIVE 0x80000000
#define PURIFY_HEAP_BLOCKS_DEFERRED_FREE 0x40000000
#define PURIFY_HEAP_BLOCKS_ALL (PURIFY_HEAP_BLOCKS_LIVE|PURIFY_HEAP_BLOCKS_DEFERRED_FREE)
int __cdecl PurifyHeapValidate(unsigned int hHeap, unsigned int dwFlags, const void *addr) ;
int __cdecl PurifySetLateDetectScanCounter(int counter);
int __cdecl PurifySetLateDetectScanInterval(int seconds);
////////////////////////////////
// API's Specific to Quantify //
////////////////////////////////
// TRUE when Quantify is running.
int __cdecl QuantifyIsRunning(void) ;
//
// Functions for controlling collection
//
int __cdecl QuantifyDisableRecordingData(void) ;
int __cdecl QuantifyStartRecordingData(void) ;
int __cdecl QuantifyStopRecordingData(void) ;
int __cdecl QuantifyClearData(void) ;
int __cdecl QuantifyIsRecordingData(void) ;
// Add a comment to the dataset
int __cdecl QuantifyAddAnnotation(char *) ;
// Save the current data, creating a "checkpoint" dataset
int __cdecl QuantifySaveData(void) ;
////////////////////////////////
// API's Specific to Coverage //
////////////////////////////////
// TRUE when Coverage is running.
int __cdecl CoverageIsRunning(void) ;
//
// Functions for controlling collection
//
int __cdecl CoverageDisableRecordingData(void) ;
int __cdecl CoverageStartRecordingData(void) ;
int __cdecl CoverageStopRecordingData(void) ;
int __cdecl CoverageClearData(void) ;
int __cdecl CoverageIsRecordingData(void) ;
// Add a comment to the dataset
int __cdecl CoverageAddAnnotation(char *) ;
// Save the current data, creating a "checkpoint" dataset
int __cdecl CoverageSaveData(void) ;
////////////////////////////////
// API's Specific to Purelock //
////////////////////////////////
// TRUE when Purelock is running.
int __cdecl PurelockIsRunning(void) ;
#if defined(c_plusplus) || defined(__cplusplus)
}
#endif

View File

@@ -1,126 +0,0 @@
/*
* Header file of Pure API function declarations.
*
* Explicitly no copyright.
* You may recompile and redistribute these definitions as required.
*
* NOTE1: In some situations when compiling with MFC, you should
* enable the setting 'Not using precompiled headers' in Visual C++
* to avoid a compiler diagnostic.
*
* NOTE2: This file works through the use of deep magic. Calls to functions
* in this file are replaced with calls into the OCI runtime system
* when an instrumented version of this program is run.
*
* NOTE3: The static vars avoidGy_n (where n is a unique number) are used
* to prevent optimizing the functions away when compiler option
* /Gy is set. This is needed so that NOTE2 works properly.
*/
static int avoidGy_1;
static int avoidGy_2;
static int avoidGy_3;
static int avoidGy_4;
static int avoidGy_5;
static int avoidGy_6;
static int avoidGy_7;
static int avoidGy_8;
static int avoidGy_9;
static int avoidGy_10;
static int avoidGy_11;
static int avoidGy_12;
static int avoidGy_13;
static int avoidGy_14;
static int avoidGy_15;
static int avoidGy_16;
static int avoidGy_17;
static int avoidGy_18;
static int avoidGy_19;
static int avoidGy_20;
static int avoidGy_21;
static int avoidGy_22;
static int avoidGy_23;
static int avoidGy_24;
static int avoidGy_25;
static int avoidGy_26;
static int avoidGy_27;
static int avoidGy_28;
static int avoidGy_29;
static int avoidGy_30;
static int avoidGy_31;
static int avoidGy_32;
static int avoidGy_33;
static int avoidGy_34;
static int avoidGy_35;
static int avoidGy_36;
static int avoidGy_37;
static int avoidGy_38;
static int avoidGy_39;
static int avoidGy_40;
static int avoidGy_41;
static int avoidGy_42;
static int avoidGy_43;
static int avoidGy_44;
static int avoidGy_45;
static int avoidGy_46;
static int avoidGy_47;
static int avoidGy_48;
static int avoidGy_49;
static int avoidGy_50;
static int avoidGy_51;
static int avoidGy_52;
static int avoidGy_53;
static int avoidGy_54;
static int avoidGy_55;
static int avoidGy_56;
static int avoidGy_57;
static int avoidGy_58;
static int avoidGy_59;
static int avoidGy_60;
static int avoidGy_PL_01;
__declspec(dllexport) int __cdecl PurePrintf(const char *fmt, ...) { avoidGy_1++; fmt; return 0; }
__declspec(dllexport) int __cdecl PurifyIsRunning(void) { avoidGy_2++; return 0; }
__declspec(dllexport) int __cdecl PurifyPrintf(const char *fmt, ...) { avoidGy_3++; fmt; return 0; }
__declspec(dllexport) int __cdecl PurifyNewInuse(void) { avoidGy_4++; return 0; }
__declspec(dllexport) int __cdecl PurifyAllInuse(void) { avoidGy_5++; return 0; }
__declspec(dllexport) int __cdecl PurifyClearInuse(void) { avoidGy_6++; return 0; }
__declspec(dllexport) int __cdecl PurifyNewLeaks(void) { avoidGy_7++; return 0; }
__declspec(dllexport) int __cdecl PurifyAllLeaks(void) { avoidGy_8++; return 0; }
__declspec(dllexport) int __cdecl PurifyClearLeaks(void) { avoidGy_9++; return 0; }
__declspec(dllexport) int __cdecl PurifyAllHandlesInuse(void) { avoidGy_10++; return 0; }
__declspec(dllexport) int __cdecl PurifyNewHandlesInuse(void) { avoidGy_11++; return 0; }
__declspec(dllexport) int __cdecl PurifyDescribe(void *addr) { avoidGy_12++; addr; return 0; }
__declspec(dllexport) int __cdecl PurifyWhatColors(void *addr, int size) { avoidGy_13++; addr; size; return 0; }
__declspec(dllexport) int __cdecl PurifyAssertIsReadable(const void *addr, int size) { avoidGy_14++; addr; size; return 1; }
__declspec(dllexport) int __cdecl PurifyAssertIsWritable(const void *addr, int size) { avoidGy_15++; addr; size; return 1; }
__declspec(dllexport) int __cdecl PurifyIsReadable(const void *addr, int size) { avoidGy_16++; addr; size; return 1; }
__declspec(dllexport) int __cdecl PurifyIsWritable(const void *addr, int size) { avoidGy_17++; addr; size; return 1; }
__declspec(dllexport) int __cdecl PurifyIsInitialized(const void *addr, int size) { avoidGy_18++; addr; size; return 1; }
__declspec(dllexport) int __cdecl PurifyRed(void *addr, int size) { avoidGy_19++; addr; size; return 0; }
__declspec(dllexport) int __cdecl PurifyGreen(void *addr, int size) { avoidGy_20++; addr; size; return 0; }
__declspec(dllexport) int __cdecl PurifyYellow(void *addr, int size) { avoidGy_21++; addr; size; return 0; }
__declspec(dllexport) int __cdecl PurifyBlue(void *addr, int size) { avoidGy_22++; addr; size; return 0; }
__declspec(dllexport) int __cdecl PurifyMarkAsInitialized(void *addr, int size) { avoidGy_23++; addr; size; return 0; }
__declspec(dllexport) int __cdecl PurifyMarkAsUninitialized(void *addr, int size) { avoidGy_24++; addr; size; return 0; }
__declspec(dllexport) int __cdecl PurifyMarkForTrap(void *addr, int size) { avoidGy_25++; addr; size; return 0; }
__declspec(dllexport) int __cdecl PurifyMarkForNoTrap(void *addr, int size) { avoidGy_26++; addr; size; return 0; }
__declspec(dllexport) int __cdecl PurifyHeapValidate(unsigned int hHeap, unsigned int dwFlags, const void *addr)
{ avoidGy_27++; hHeap; dwFlags; addr; return 1; }
__declspec(dllexport) int __cdecl PurifySetLateDetectScanCounter(int counter) { avoidGy_28++; counter; return 0; };
__declspec(dllexport) int __cdecl PurifySetLateDetectScanInterval(int seconds) { avoidGy_29++; seconds; return 0; };
__declspec(dllexport) int __cdecl CoverageIsRunning(void) { avoidGy_30++; return 0; }
__declspec(dllexport) int __cdecl CoverageDisableRecordingData(void) { avoidGy_31++; return 0; }
__declspec(dllexport) int __cdecl CoverageStartRecordingData(void) { avoidGy_32++; return 0; }
__declspec(dllexport) int __cdecl CoverageStopRecordingData(void) { avoidGy_33++; return 0; }
__declspec(dllexport) int __cdecl CoverageClearData(void) { avoidGy_34++; return 0; }
__declspec(dllexport) int __cdecl CoverageIsRecordingData(void) { avoidGy_35++; return 0; }
__declspec(dllexport) int __cdecl CoverageAddAnnotation(char *str) { avoidGy_36++; str; return 0; }
__declspec(dllexport) int __cdecl CoverageSaveData(void) { avoidGy_37++; return 0; }
__declspec(dllexport) int __cdecl QuantifyIsRunning(void) { avoidGy_42++; return 0; }
__declspec(dllexport) int __cdecl QuantifyDisableRecordingData(void) { avoidGy_43++; return 0; }
__declspec(dllexport) int __cdecl QuantifyStartRecordingData(void) { avoidGy_44++; return 0; }
__declspec(dllexport) int __cdecl QuantifyStopRecordingData(void) { avoidGy_45++; return 0; }
__declspec(dllexport) int __cdecl QuantifyClearData(void) { avoidGy_46++; return 0; }
__declspec(dllexport) int __cdecl QuantifyIsRecordingData(void) { avoidGy_47++; return 0; }
__declspec(dllexport) int __cdecl QuantifyAddAnnotation(char *str) { avoidGy_48++; str; return 0; }
__declspec(dllexport) int __cdecl QuantifySaveData(void) { avoidGy_49++; return 0; }
__declspec(dllexport) int __cdecl PurelockIsRunning(void) { avoidGy_PL_01++; return 0; }

View File

@@ -1,20 +0,0 @@
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
16389=An unknown error has occurred (%1$S)

View File

@@ -1 +0,0 @@
nsXPCOM.h

View File

@@ -1,140 +0,0 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpcom
LIBRARY_NAME = xpcom
# Do not set EXPORT_LIBRARY as we do not want xpcom in the static libs list
#EXPORT_LIBRARY = 1
REQUIRES = libreg \
string \
$(NULL)
# pull in MoreFiles for MacOSX
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
REQUIRES += macmorefiles
endif
CPPSRCS = nsXPComInit.cpp
ifeq ($(OS_ARCH),WINNT)
CPPSRCS += dlldeps.cpp
endif
ifdef XPCOM_USE_LEA
CSRCS += malloc.c
endif
ifdef GC_LEAK_DETECTOR
EXTRA_DSO_LIBS = boehm
endif
SHARED_LIBRARY_LIBS = \
$(DIST)/lib/$(LIB_PREFIX)xpcomds_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)xpcomio_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)xpcomcomponents_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)xpcomthreads_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)xpcomproxy_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)xpcombase_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)xptcall.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)xptinfo.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)xpt.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)xptcmd.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)mozreg_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)string_obsolete_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \
$(NULL)
LOCAL_INCLUDES = \
-I$(srcdir)/../glue \
-I$(srcdir)/../base \
-I$(srcdir)/../ds \
-I$(srcdir)/../io \
-I$(srcdir)/../components \
-I$(srcdir)/../threads \
-I$(srcdir)/../threads/_xpidlgen \
-I$(srcdir)/../proxy/src \
$(NULL)
SDK_HEADERS = \
nsXPCOM.h \
$(NULL)
SDK_BINARY = $(IMPORT_LIBRARY) $(SHARED_LIBRARY)
ifdef MOZ_DEMANGLE_SYMBOLS
EXTRA_DSO_LDOPTS += -liberty
endif
# pull in MoreFiles for MacOSX
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
EXTRA_DSO_LDOPTS += $(DEPTH)/dist/lib/libmacmorefiles_s.a
endif
# Turn off grep filter for .def files
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
XPCOM_SWITCH = 1
endif
# Force use of PIC
FORCE_USE_PIC = 1
FORCE_SHARED_LIB = 1
include $(topsrcdir)/config/rules.mk
DEFINES += \
-D_IMPL_NS_COM \
-D_IMPL_NS_BASE \
-DEXPORT_XPT_API \
-DEXPORT_XPTC_API \
-DEXPORT_XPTI_API
EXTRA_DSO_LDOPTS += $(NSPR_LIBS)
ifdef GC_LEAK_DETECTOR
DEFINES += -DGC_LEAK_DETECTOR
endif
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
CXXFLAGS += $(TK_CFLAGS)
EXTRA_DSO_LDOPTS += $(TK_LIBS)
endif
ifeq ($(OS_ARCH),BeOS)
EXTRA_DSO_LDOPTS += -lbe
endif
ifeq ($(OS_ARCH),WINNT)
DEFINES += -DWIN32_LEAN_AND_MEAN
EXTRA_DSO_LDOPTS += shell32.lib ole32.lib
ifneq (,$(MOZ_DEBUG)$(NS_TRACE_MALLOC))
EXTRA_DSO_LDOPTS += imagehlp.lib
endif
endif # WINNT

View File

@@ -1,199 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Force references to all of the symbols that we want exported from
// the dll that are located in the .lib files we link with
#include "nsVoidArray.h"
#include "nsValueArray.h"
#include "nsIAtom.h"
#include "nsFileSpec.h"
//#include "nsIBuffer.h"
//#include "nsIByteBufferInputStream.h"
#include "nsFileStream.h"
#include "nsFixedSizeAllocator.h"
#include "nsRecyclingAllocator.h"
#include "nsSpecialSystemDirectory.h"
#include "nsIThread.h"
#include "nsDeque.h"
#include "nsObserver.h"
#include "nsTraceRefcnt.h"
#include "nsXPIDLString.h"
#include "nsIEnumerator.h"
#include "nsEnumeratorUtils.h"
#include "nsQuickSort.h"
#include "nsString.h"
#include "nsPrintfCString.h"
#include "nsSupportsArray.h"
#include "nsProxyEventPrivate.h"
#include "xpt_xdr.h"
#include "xptcall.h"
#include "nsIFileSpec.h"
#include "nsILocalFile.h"
#include "nsIGenericFactory.h"
#include "nsAVLTree.h"
#include "nsHashtableEnumerator.h"
#include "nsIPipe.h"
#include "nsCWeakReference.h"
#include "nsWeakReference.h"
#include "nsISizeOfHandler.h"
#include "nsTextFormatter.h"
#include "nsStatistics.h"
#include "nsIStorageStream.h"
#include "nsLinebreakConverter.h"
#include "nsIBinaryInputStream.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIByteArrayInputStream.h"
#include "nsReadableUtils.h"
#include "nsStaticNameTable.h"
#include "nsProcess.h"
#include "nsSlidingString.h"
#include "nsIInputStreamTee.h"
#include "nsDoubleHashtable.h"
#ifdef DEBUG
#include "pure.h"
#endif
#include "pldhash.h"
#ifdef NS_TRACE_MALLOC
#include "nsTraceMalloc.h"
#endif
#include "nsVariant.h"
class dummyComparitor: public nsAVLNodeComparitor {
public:
virtual PRInt32 operator()(void* anItem1,void* anItem2)
{
return 0;
}
};
#ifdef DEBUG
extern NS_COM void
TestSegmentedBuffer();
#endif
void XXXNeverCalled()
{
nsTextFormatter::snprintf(nsnull,0,nsnull);
nsTextFormatter::smprintf(nsnull, nsnull);
nsTextFormatter::smprintf_free(nsnull);
dummyComparitor dummy;
nsVoidArray();
nsSmallVoidArray();
nsDoubleHashtableStringSupports dhss;
nsValueArray(0);
nsAVLTree(dummy, nsnull);
nsSupportsArray();
NS_GetNumberOfAtoms();
nsFileURL(NULL);
NS_NewPipe(NULL, NULL, 0, 0, PR_FALSE, PR_FALSE, NULL);
nsFileSpec s;
nsFixedSizeAllocator a;
nsRecyclingAllocator recyclingAllocator(2);
a.Init(0, 0, 0, 0, 0);
a.Alloc(0);
a.Free(0, 0);
NS_NewIOFileStream(NULL, s, 0, 0);
nsInputFileStream(s, 0, 0);
new nsSpecialSystemDirectory(nsSpecialSystemDirectory::OS_DriveDirectory);
nsIThread::GetCurrent(NULL);
nsDeque(NULL);
NS_NewObserver(NULL, NULL);
nsTraceRefcnt::DumpStatistics();
NS_NewEmptyEnumerator(NULL);
nsArrayEnumerator(NULL);
NS_NewIntersectionEnumerator(NULL, NULL, NULL);
NS_QuickSort(NULL, 0, 0, NULL, NULL);
nsStatistics("dummy");
nsString();
nsProxyObject(NULL, 0, NULL);
XPT_DoString(NULL, NULL, NULL);
XPT_DoHeader(NULL, NULL, NULL);
#ifdef DEBUG
PurePrintf(0);
#endif
XPTC_InvokeByIndex(NULL, 0, 0, NULL);
NS_NewFileSpec(NULL);
xptc_dummy();
xptc_dummy2();
XPTI_GetInterfaceInfoManager();
NS_NewGenericFactory(NULL, NULL);
NS_NewGenericModule(NULL, 0, NULL, NULL, NULL);
NS_NewGenericModule2(NULL, NULL);
NS_NewHashtableEnumerator(NULL, NULL, NULL, NULL);
nsCWeakProxy(0, 0);
nsCWeakReferent(0);
NS_GetWeakReference(NULL);
nsCOMPtr<nsISupports> dummyFoo(do_GetInterface(nsnull));
#ifdef DEBUG
TestSegmentedBuffer();
#endif
NS_NewSizeOfHandler(0);
NS_NewStorageStream(0,0, nsnull);
NS_NewBinaryInputStream(0, 0);
nsString foo;
nsPrintfCString bar("");
nsLinebreakConverter::ConvertStringLineBreaks(foo,
nsLinebreakConverter::eLinebreakAny, nsLinebreakConverter::eLinebreakContent);
NS_NewLocalFile(NULL, PR_FALSE, NULL);
nsProcess();
NS_NewByteArrayInputStream (NULL, NULL, 0);
nsStaticCaseInsensitiveNameTable();
nsAutoString str1;
nsCAutoString str2;
ToNewUnicode(str1);
ToNewUnicode(str2);
ToNewCString(str1);
ToNewCString(str2);
PL_DHashTableFinish(NULL);
nsSlidingString sliding(NULL, NULL, NULL);
NS_NewInputStreamTee(NULL, NULL, NULL);
#ifdef NS_TRACE_MALLOC
NS_TraceMallocStartup(0);
NS_TraceMallocStartupArgs(0, NULL);
NS_TraceMallocShutdown();
NS_TraceMallocDisable();
NS_TraceMallocEnable();
NS_TraceMallocChangeLogFD(0);
NS_TraceMallocCloseLogFD(0);
NS_TraceMallocLogTimestamp(NULL);
NS_TraceMallocDumpAllocations(NULL);
NS_TraceMallocFlushLogfiles();
#endif
nsVariant();
}

View File

@@ -1,107 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH=..\..
MODULE = xpcom
REQUIRES = mozreg \
string \
$(NULL)
include <$(DEPTH)\config\config.mak>
MAKE_OBJ_TYPE=DLL
LIBNAME = .\$(OBJDIR)\xpcom
DLL = $(LIBNAME).dll
EXPORTS = \
nsXPCOM.h \
$(NULL)
# if we ever add a .def file for x86 we need to deal with this.
!if "$(CPU)" == "ALPHA"
DEFFILE = xpcom_alpha.def
!endif
LINCS = \
-I..\base \
-I..\glue \
-I..\ds \
-I..\io \
-I..\components \
-I..\threads \
-I..\threads\_xpidlgen \
-I..\proxy\src \
$(NULL)
LCFLAGS=-D_IMPL_NS_COM \
-D_IMPL_NS_BASE \
-DWIN32_LEAN_AND_MEAN \
-DEXPORT_XPT_API \
-DEXPORT_XPTC_API \
!ifdef GC_LEAK_DETECTOR
-DGC_LEAK_DETECTOR \
!endif
-DEXPORT_XPTI_API
CPP_OBJS = \
.\$(OBJDIR)\nsXPComInit.obj \
.\$(OBJDIR)\dlldeps.obj \
$(NULL)
SUB_LIBRARIES = \
$(DIST)\lib\xpcombase_s.lib \
$(DIST)\lib\xpcomds_s.lib \
$(DIST)\lib\xpcomio_s.lib \
$(DIST)\lib\xpcomcomp_s.lib \
$(DIST)\lib\xpcomthreads_s.lib \
$(DIST)\lib\xpcomxpt_s.lib \
$(DIST)\lib\xpcomxptcall_s.lib \
$(DIST)\lib\xpcomxptcmd_s.lib \
$(DIST)\lib\xpcomxptinfo_s.lib \
$(DIST)\lib\xpcomproxy_s.lib \
$(DIST)\lib\string_s.lib \
$(DIST)\lib\string_obsolete_s.lib \
$(DIST)\lib\mozreg.lib \
$(DIST)\lib\xpcomglue.lib \
$(NULL)
LLIBS = $(SUB_LIBRARIES) \
$(LIBNSPR) \
$(NULL)
WIN_LIBS = \
shell32.lib \
ole32.lib \
!ifdef GC_LEAK_DETECTOR
$(DIST)\lib\boehm.lib \
!endif
!if defined(MOZ_DEBUG) || defined(MOZ_TRACE_MALLOC)
imagehlp.lib \
!endif
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(DLL)
$(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin
$(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib

File diff suppressed because it is too large Load Diff

View File

@@ -1,154 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsXPCom_h__
#define nsXPCom_h__
#include "nscore.h"
class nsIComponentManager;
class nsIComponentRegistrar;
class nsIServiceManager;
class nsIFile;
class nsIDirectoryServiceProvider;
class nsIMemory;
/**
* Initialises XPCOM. You must call this method before proceeding
* to use xpcom. The one exception is that you may call
* NS_NewLocalFile to create a nsIFile.
*
* @status FROZEN
*
* @note Use <CODE>NS_NewLocalFile</CODE> to create the file object you
* supply as the bin directory path in this call. The function
* may be safely called before the rest of XPCOM or embedding has
* been initialised.
*
* @param result The service manager. You may pass null.
*
* @param abinDirectory The directory containing the component
* registry and runtime libraries;
* or use <CODE>nsnull</CODE> to use the working
* directory.
*
* @param aAppFileLocProvider The object to be used by Gecko that specifies
* to Gecko where to find profiles, the component
* registry preferences and so on; or use
* <CODE>nsnull</CODE> for the default behaviour.
*
* @see NS_NewLocalFile
* @see nsILocalFile
* @see nsIDirectoryServiceProvider
*
* @return NS_OK for success;
* other error codes indicate a failure during initialisation.
*
*/
extern "C" NS_COM nsresult
NS_InitXPCOM2(nsIServiceManager* *result,
nsIFile* binDirectory,
nsIDirectoryServiceProvider* appFileLocationProvider);
/**
* Shutdown XPCOM. You must call this method after you are finished
* using xpcom.
*
* @status FROZEN
*
* @param servMgr The service manager which was returned by NS_InitXPCOM2.
* This will release servMgr. You may pass null.
*
* @return NS_OK for success;
* other error codes indicate a failure during initialisation.
*
*/
extern "C" NS_COM nsresult
NS_ShutdownXPCOM(nsIServiceManager* servMgr);
/**
* Public Method to access to the service manager.
*
* @status FROZEN
* @param result Interface pointer to the service manager
*
* @return NS_OK for success;
* other error codes indicate a failure during initialisation.
*
*/
extern "C" NS_COM nsresult
NS_GetServiceManager(nsIServiceManager* *result);
/**
* Public Method to access to the component manager.
*
* @status FROZEN
* @param result Interface pointer to the service
*
* @return NS_OK for success;
* other error codes indicate a failure during initialisation.
*
*/
extern "C" NS_COM nsresult
NS_GetComponentManager(nsIComponentManager* *result);
/**
* Public Method to access to the component registration manager.
*
* @status FROZEN
* @param result Interface pointer to the service
*
* @return NS_OK for success;
* other error codes indicate a failure during initialisation.
*
*/
extern "C" NS_COM nsresult
NS_GetComponentRegistrar(nsIComponentRegistrar* *result);
/**
* Public Method to access to the memory manager. See nsIMemory
*
* @status FROZEN
* @param result Interface pointer to the memory manager
*
* @return NS_OK for success;
* other error codes indicate a failure during initialisation.
*
*/
extern "C" NS_COM nsresult
NS_GetMemoryManager(nsIMemory* *result);
#endif

View File

@@ -1,70 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsXPComPrivate_h__
#define nsXPComPrivate_h__
#include "nscore.h"
/**
* Private Method to register an exit routine. This method
* allows you to setup a callback that will be called from
* the NS_ShutdownXPCOM function after all services and
* components have gone away.
*
* This API is for the exclusive use of the xpcom glue library.
*
* @status FROZEN
* @param exitRoutine pointer to user defined callback function
* of type XPCOMExitRoutine.
* @param priority higher priorities are called before lower
* priorities.
*
* @return NS_OK for success;
* other error codes indicate a failure.
*
*/
typedef NS_CALLBACK(XPCOMExitRoutine)(void);
extern "C" NS_COM nsresult
NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority);
extern "C" NS_COM nsresult
NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine);
#endif

View File

@@ -1,617 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsXPCOM.h"
#include "nsXPCOMPrivate.h"
#include "nsIRegistry.h"
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsObserverList.h"
#include "nsObserver.h"
#include "nsObserverService.h"
#include "nsProperties.h"
#include "nsIProperties.h"
#include "nsPersistentProperties.h"
#include "nsScriptableInputStream.h"
#include "nsMemoryImpl.h"
#include "nsErrorService.h"
#include "nsArena.h"
#include "nsByteBuffer.h"
#include "nsSupportsArray.h"
#include "nsSupportsPrimitives.h"
#include "nsConsoleService.h"
#include "nsExceptionService.h"
#include "nsComponentManager.h"
#include "nsIServiceManager.h"
#include "nsGenericFactory.h"
#include "nsEventQueueService.h"
#include "nsEventQueue.h"
#include "nsIProxyObjectManager.h"
#include "nsProxyEventPrivate.h" // access to the impl of nsProxyObjectManager for the generic factory registration.
#include "xptinfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsTimerImpl.h"
#include "TimerThread.h"
#include "nsThread.h"
#include "nsProcess.h"
#include "nsFileSpecImpl.h"
#include "nsSpecialSystemDirectory.h"
#include "nsEmptyEnumerator.h"
#include "nsILocalFile.h"
#include "nsLocalFile.h"
#include "nsDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsICategoryManager.h"
#include "nsStringStream.h"
#include "nsMultiplexInputStream.h"
#include "nsFastLoadService.h"
#include "nsAtomService.h"
#include "nsAtomTable.h"
#include "nsTraceRefcnt.h"
#include "nsTimelineService.h"
#include "nsVariant.h"
#ifdef GC_LEAK_DETECTOR
#include "nsLeakDetector.h"
#endif
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kMemoryCID, NS_MEMORY_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsProcess);
// ds/nsISupportsPrimitives
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsIDImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsStringImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsWStringImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRBoolImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint8Impl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint16Impl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint32Impl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint64Impl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRTimeImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsCharImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt16Impl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt32Impl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt64Impl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsFloatImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsDoubleImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsVoidImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsInterfacePointerImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsConsoleService);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomService);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsExceptionService);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerImpl);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsVariant);
#ifdef MOZ_TIMELINE
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimelineService);
#endif
static NS_METHOD
nsXPTIInterfaceInfoManagerGetSingleton(nsISupports* outer,
const nsIID& aIID,
void* *aInstancePtr)
{
NS_ENSURE_ARG_POINTER(aInstancePtr);
NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION);
nsCOMPtr<nsIInterfaceInfoManager> iim(dont_AddRef(XPTI_GetInterfaceInfoManager()));
if (!iim) {
return NS_ERROR_FAILURE;
}
return iim->QueryInterface(aIID, aInstancePtr);
}
////////////////////////////////////////////////////////////////////////////////
// XPCOM initialization
//
// To Control the order of initialization of these key components I am putting
// this function.
//
// - nsServiceManager
// - nsComponentManager
// - nsRegistry
//
// Here are key points to remember:
// - A global of all these need to exist. nsServiceManager is an independent object.
// nsComponentManager uses both the globalServiceManager and its own registry.
//
// - A static object of both the nsComponentManager and nsServiceManager
// are in use. Hence InitXPCOM() gets triggered from both
// NS_GetGlobale{Service/Component}Manager() calls.
//
// - There exists no global Registry. Registry can be created from the component manager.
//
static nsresult
RegisterGenericFactory(nsIComponentManager* compMgr,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsIGenericFactory* fact;
rv = NS_NewGenericFactory(&fact, info);
if (NS_FAILED(rv)) return rv;
// what I want to do here is QI for a Component Registration Manager. Since this
// has not been invented yet, QI to the obsolete manager. Kids, don't do this at home.
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(compMgr, &rv);
if (registrar)
rv = registrar->RegisterFactory(info->mCID,
info->mDescription,
info->mContractID,
fact);
NS_RELEASE(fact);
return rv;
}
nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = NULL;
nsIProperties *gDirectoryService = NULL;
PRBool gXPCOMShuttingDown = PR_FALSE;
// For each class that wishes to support nsIClassInfo, add a line like this
// NS_DECL_CLASSINFO(nsMyClass)
#define COMPONENT(NAME, Ctor) \
{ NS_##NAME##_CLASSNAME, NS_##NAME##_CID, NS_##NAME##_CONTRACTID, Ctor }
#define COMPONENT_CI(NAME, Ctor, Class) \
{ NS_##NAME##_CLASSNAME, NS_##NAME##_CID, NS_##NAME##_CONTRACTID, Ctor, \
NULL, NULL, NULL, NS_CI_INTERFACE_GETTER_NAME(Class), NULL, \
&NS_CLASSINFO_NAME(Class) }
static const nsModuleComponentInfo components[] = {
// ugh
#define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
#define NS_MEMORY_CLASSNAME "Global Memory Service"
COMPONENT(MEMORY, nsMemoryImpl::Create),
#define NS_ERRORSERVICE_CLASSNAME NS_ERRORSERVICE_NAME
COMPONENT(ERRORSERVICE, nsErrorService::Create),
COMPONENT(ARENA, ArenaImpl::Create),
COMPONENT(BYTEBUFFER, ByteBufferImpl::Create),
COMPONENT(SCRIPTABLEINPUTSTREAM, nsScriptableInputStream::Create),
COMPONENT(PROPERTIES, nsProperties::Create),
#define NS_PERSISTENTPROPERTIES_CID NS_IPERSISTENTPROPERTIES_CID /* sigh */
COMPONENT(PERSISTENTPROPERTIES, nsPersistentProperties::Create),
COMPONENT(SUPPORTSARRAY, nsSupportsArray::Create),
COMPONENT(CONSOLESERVICE, nsConsoleServiceConstructor),
COMPONENT(EXCEPTIONSERVICE, nsExceptionServiceConstructor),
COMPONENT(ATOMSERVICE, nsAtomServiceConstructor),
#ifdef MOZ_TIMELINE
COMPONENT(TIMELINESERVICE, nsTimelineServiceConstructor),
#endif
COMPONENT(OBSERVER, nsObserver::Create),
COMPONENT(OBSERVERSERVICE, nsObserverService::Create),
COMPONENT(GENERICFACTORY, nsGenericFactory::Create),
COMPONENT(EVENTQUEUESERVICE, nsEventQueueServiceImpl::Create),
COMPONENT(EVENTQUEUE, nsEventQueueImpl::Create),
COMPONENT(THREAD, nsThread::Create),
COMPONENT(THREADPOOL, nsThreadPool::Create),
#define NS_XPCOMPROXY_CID NS_PROXYEVENT_MANAGER_CID
COMPONENT(XPCOMPROXY, nsProxyObjectManager::Create),
COMPONENT(TIMER, nsTimerImplConstructor),
#define COMPONENT_SUPPORTS(TYPE, Type) \
COMPONENT(SUPPORTS_##TYPE, nsSupports##Type##ImplConstructor)
COMPONENT_SUPPORTS(ID, ID),
COMPONENT_SUPPORTS(STRING, String),
COMPONENT_SUPPORTS(WSTRING, WString),
COMPONENT_SUPPORTS(PRBOOL, PRBool),
COMPONENT_SUPPORTS(PRUINT8, PRUint8),
COMPONENT_SUPPORTS(PRUINT16, PRUint16),
COMPONENT_SUPPORTS(PRUINT32, PRUint32),
COMPONENT_SUPPORTS(PRUINT64, PRUint64),
COMPONENT_SUPPORTS(PRTIME, PRTime),
COMPONENT_SUPPORTS(CHAR, Char),
COMPONENT_SUPPORTS(PRINT16, PRInt16),
COMPONENT_SUPPORTS(PRINT32, PRInt32),
COMPONENT_SUPPORTS(PRINT64, PRInt64),
COMPONENT_SUPPORTS(FLOAT, Float),
COMPONENT_SUPPORTS(DOUBLE, Double),
COMPONENT_SUPPORTS(VOID, Void),
COMPONENT_SUPPORTS(INTERFACE_POINTER, InterfacePointer),
#undef COMPONENT_SUPPORTS
COMPONENT(LOCAL_FILE, nsLocalFile::nsLocalFileConstructor),
COMPONENT(DIRECTORY_SERVICE, nsDirectoryService::Create),
COMPONENT(PROCESS, nsProcessConstructor),
COMPONENT(FILESPEC, nsFileSpecImpl::Create),
COMPONENT(DIRECTORYITERATOR, nsDirectoryIteratorImpl::Create),
COMPONENT(STRINGINPUTSTREAM, nsStringInputStreamConstructor),
COMPONENT(MULTIPLEXINPUTSTREAM, nsMultiplexInputStreamConstructor),
COMPONENT(FASTLOADSERVICE, nsFastLoadService::Create),
COMPONENT(VARIANT, nsVariantConstructor),
COMPONENT(INTERFACEINFOMANAGER_SERVICE, nsXPTIInterfaceInfoManagerGetSingleton)
};
#undef COMPONENT
const int components_length = sizeof(components) / sizeof(components[0]);
// gMemory will be freed during shutdown.
static nsIMemory* gMemory = nsnull;
nsresult NS_COM NS_GetMemoryManager(nsIMemory* *result)
{
nsresult rv = NS_OK;
if (!gMemory)
{
rv = nsMemoryImpl::Create(nsnull,
NS_GET_IID(nsIMemory),
(void**)&gMemory);
}
NS_IF_ADDREF(*result = gMemory);
return rv;
}
nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result,
nsIFile* binDirectory)
{
return NS_InitXPCOM2(result, binDirectory, nsnull);
}
nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result,
nsIFile* binDirectory,
nsIDirectoryServiceProvider* appFileLocationProvider)
{
nsresult rv = NS_OK;
#ifdef NS_BUILD_REFCNT_LOGGING
nsTraceRefcnt::Startup();
#endif
// Establish the main thread here.
rv = nsIThread::SetMainThread();
if (NS_FAILED(rv)) return rv;
// Startup the memory manager
rv = nsMemoryImpl::Startup();
if (NS_FAILED(rv)) return rv;
NS_StartupLocalFile();
StartupSpecialSystemDirectory();
// Start the directory service so that the component manager init can use it.
rv = nsDirectoryService::Create(nsnull,
NS_GET_IID(nsIProperties),
(void**)&gDirectoryService);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDirectoryService> dirService = do_QueryInterface(gDirectoryService, &rv);
if (NS_FAILED(rv))
return rv;
rv = dirService->Init();
if (NS_FAILED(rv))
return rv;
// Create the Component/Service Manager
nsComponentManagerImpl *compMgr = NULL;
if (nsComponentManagerImpl::gComponentManager == NULL)
{
compMgr = new nsComponentManagerImpl();
if (compMgr == NULL)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(compMgr);
PRBool value;
if (binDirectory)
{
rv = binDirectory->IsDirectory(&value);
if (NS_SUCCEEDED(rv) && value)
gDirectoryService->Define(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, binDirectory);
//Since people are still using the nsSpecialSystemDirectory, we should init it.
char* path;
binDirectory->GetPath(&path);
nsFileSpec spec(path);
nsMemory::Free(path);
nsSpecialSystemDirectory::Set(nsSpecialSystemDirectory::Moz_BinDirectory, &spec);
}
if (appFileLocationProvider) {
rv = dirService->RegisterProvider(appFileLocationProvider);
if (NS_FAILED(rv)) return rv;
}
rv = compMgr->Init();
if (NS_FAILED(rv))
{
NS_RELEASE(compMgr);
return rv;
}
nsComponentManagerImpl::gComponentManager = compMgr;
if (result) {
nsIServiceManager *serviceManager =
NS_STATIC_CAST(nsIServiceManager*, compMgr);
NS_ADDREF(*result = serviceManager);
}
}
nsCOMPtr<nsIMemory> memory;
NS_GetMemoryManager(getter_AddRefs(memory));
// dougt - these calls will be moved into a new interface when nsIComponentManager is frozen.
rv = compMgr->RegisterService(kMemoryCID, memory);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterService(kComponentManagerCID, NS_STATIC_CAST(nsIComponentManager*, compMgr));
if (NS_FAILED(rv)) return rv;
#ifdef GC_LEAK_DETECTOR
rv = NS_InitLeakDetector();
if (NS_FAILED(rv)) return rv;
#endif
// 2. Register the global services with the component manager so that
// clients can create new objects.
// Registry
nsIFactory *registryFactory = NULL;
rv = NS_RegistryGetFactory(&registryFactory);
if (NS_FAILED(rv)) return rv;
NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID);
rv = compMgr->RegisterFactory(kRegistryCID,
NS_REGISTRY_CLASSNAME,
NS_REGISTRY_CONTRACTID,
registryFactory, PR_TRUE);
NS_RELEASE(registryFactory);
if (NS_FAILED(rv)) return rv;
// Category Manager
{
nsCOMPtr<nsIFactory> categoryManagerFactory;
if ( NS_FAILED(rv = NS_CategoryManagerGetFactory(getter_AddRefs(categoryManagerFactory))) )
return rv;
NS_DEFINE_CID(kCategoryManagerCID, NS_CATEGORYMANAGER_CID);
rv = compMgr->RegisterFactory(kCategoryManagerCID,
NS_CATEGORYMANAGER_CLASSNAME,
NS_CATEGORYMANAGER_CONTRACTID,
categoryManagerFactory,
PR_TRUE);
if ( NS_FAILED(rv) )
return rv;
}
for (int i = 0; i < components_length; i++)
RegisterGenericFactory(compMgr, &components[i]);
// Prepopulate registry for performance
// Ignore return value. It is ok if this fails.
nsComponentManagerImpl::gComponentManager->PlatformPrePopulateRegistry();
// Pay the cost at startup time of starting this singleton.
nsIInterfaceInfoManager* iim = XPTI_GetInterfaceInfoManager();
NS_IF_RELEASE(iim);
return rv;
}
static nsVoidArray gExitRoutines;
static void CallExitRoutines()
{
PRInt32 count = gExitRoutines.Count();
for (PRInt32 i = 0; i < count; i++) {
XPCOMExitRoutine func = (XPCOMExitRoutine) gExitRoutines.ElementAt(i);
func();
}
gExitRoutines.Clear();
}
nsresult NS_COM
NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority)
{
// priority are not used right now. It will need to be implemented as more
// classes are moved into the glue library --dougt
PRBool okay = gExitRoutines.AppendElement((void*)exitRoutine);
return okay ? NS_OK : NS_ERROR_FAILURE;
}
nsresult NS_COM
NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine)
{
PRBool okay = gExitRoutines.RemoveElement((void*)exitRoutine);
return okay ? NS_OK : NS_ERROR_FAILURE;
}
//
// NS_ShutdownXPCOM()
//
// The shutdown sequence for xpcom would be
//
// - Release the Global Service Manager
// - Release all service instances held by the global service manager
// - Release the Global Service Manager itself
// - Release the Component Manager
// - Release all factories cached by the Component Manager
// - Unload Libraries
// - Release Contractid Cache held by Component Manager
// - Release dll abstraction held by Component Manager
// - Release the Registry held by Component Manager
// - Finally, release the component manager itself
//
nsresult NS_COM NS_ShutdownXPCOM(nsIServiceManager* servMgr)
{
// Notify observers of xpcom shutting down
nsresult rv = NS_OK;
{
// Block it so that the COMPtr will get deleted before we hit
// servicemanager shutdown
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1", &rv);
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIServiceManager> mgr;
rv = NS_GetServiceManager(getter_AddRefs(mgr));
if (NS_SUCCEEDED(rv))
{
(void) observerService->NotifyObservers(mgr,
NS_XPCOM_SHUTDOWN_OBSERVER_ID,
nsnull);
}
}
}
// grab the event queue so that we can process events one last time before exiting
nsCOMPtr <nsIEventQueue> currentQ;
{
nsCOMPtr<nsIEventQueueService> eventQService =
do_GetService(kEventQueueServiceCID, &rv);
if (eventQService) {
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(currentQ));
}
}
// XPCOM is officially in shutdown mode NOW
// Set this only after the observers have been notified as this
// will cause servicemanager to become inaccessible.
gXPCOMShuttingDown = PR_TRUE;
// We may have AddRef'd for the caller of NS_InitXPCOM, so release it
// here again:
NS_IF_RELEASE(servMgr);
// Shutdown global servicemanager
nsComponentManagerImpl::gComponentManager->FreeServices();
nsServiceManager::ShutdownGlobalServiceManager(nsnull);
if (currentQ) {
currentQ->ProcessPendingEvents();
currentQ = 0;
}
// Release the directory service
NS_IF_RELEASE(gDirectoryService);
// Shutdown nsLocalFile string conversion
NS_ShutdownLocalFile();
// Shutdown the timer thread and all timers that might still be alive before
// shutting down the component manager
nsTimerImpl::Shutdown();
// Shutdown xpcom. This will release all loaders and cause others holding
// a refcount to the component manager to release it.
rv = (nsComponentManagerImpl::gComponentManager)->Shutdown();
NS_ASSERTION(NS_SUCCEEDED(rv), "Component Manager shutdown failed.");
// Release our own singletons
// Do this _after_ shutting down the component manager, because the
// JS component loader will use XPConnect to call nsIModule::canUnload,
// and that will spin up the InterfaceInfoManager again -- bad mojo
XPTI_FreeInterfaceInfoManager();
// Finally, release the component manager last because it unloads the
// libraries:
if (nsComponentManagerImpl::gComponentManager) {
nsrefcnt cnt;
NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
NS_WARN_IF_FALSE(cnt == 0, "Component Manager being held past XPCOM shutdown.");
}
nsComponentManagerImpl::gComponentManager = nsnull;
#ifdef DEBUG
extern void _FreeAutoLockStatics();
_FreeAutoLockStatics();
#endif
ShutdownSpecialSystemDirectory();
EmptyEnumeratorImpl::Shutdown();
nsMemoryImpl::Shutdown();
NS_IF_RELEASE(gMemory);
nsThread::Shutdown();
NS_PurgeAtomTable();
CallExitRoutines();
#ifdef NS_BUILD_REFCNT_LOGGING
nsTraceRefcnt::DumpStatistics();
nsTraceRefcnt::ResetStatistics();
nsTraceRefcnt::Shutdown();
#endif
#ifdef GC_LEAK_DETECTOR
// Shutdown the Leak detector.
NS_ShutdownLeakDetector();
#endif
return NS_OK;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,252 +0,0 @@
LIBRARY xpcom
DESCRIPTION "xpcom library"
EXPORTS
?Stub3@nsXPTCStubBase@@UAAIXZ
?Stub4@nsXPTCStubBase@@UAAIXZ
?Stub5@nsXPTCStubBase@@UAAIXZ
?Stub6@nsXPTCStubBase@@UAAIXZ
?Stub7@nsXPTCStubBase@@UAAIXZ
?Stub8@nsXPTCStubBase@@UAAIXZ
?Stub9@nsXPTCStubBase@@UAAIXZ
?Stub10@nsXPTCStubBase@@UAAIXZ
?Stub11@nsXPTCStubBase@@UAAIXZ
?Stub12@nsXPTCStubBase@@UAAIXZ
?Stub13@nsXPTCStubBase@@UAAIXZ
?Stub14@nsXPTCStubBase@@UAAIXZ
?Stub15@nsXPTCStubBase@@UAAIXZ
?Stub16@nsXPTCStubBase@@UAAIXZ
?Stub17@nsXPTCStubBase@@UAAIXZ
?Stub18@nsXPTCStubBase@@UAAIXZ
?Stub19@nsXPTCStubBase@@UAAIXZ
?Stub20@nsXPTCStubBase@@UAAIXZ
?Stub21@nsXPTCStubBase@@UAAIXZ
?Stub22@nsXPTCStubBase@@UAAIXZ
?Stub23@nsXPTCStubBase@@UAAIXZ
?Stub24@nsXPTCStubBase@@UAAIXZ
?Stub25@nsXPTCStubBase@@UAAIXZ
?Stub26@nsXPTCStubBase@@UAAIXZ
?Stub27@nsXPTCStubBase@@UAAIXZ
?Stub28@nsXPTCStubBase@@UAAIXZ
?Stub29@nsXPTCStubBase@@UAAIXZ
?Stub30@nsXPTCStubBase@@UAAIXZ
?Stub31@nsXPTCStubBase@@UAAIXZ
?Stub32@nsXPTCStubBase@@UAAIXZ
?Stub33@nsXPTCStubBase@@UAAIXZ
?Stub34@nsXPTCStubBase@@UAAIXZ
?Stub35@nsXPTCStubBase@@UAAIXZ
?Stub36@nsXPTCStubBase@@UAAIXZ
?Stub37@nsXPTCStubBase@@UAAIXZ
?Stub38@nsXPTCStubBase@@UAAIXZ
?Stub39@nsXPTCStubBase@@UAAIXZ
?Stub40@nsXPTCStubBase@@UAAIXZ
?Stub41@nsXPTCStubBase@@UAAIXZ
?Stub42@nsXPTCStubBase@@UAAIXZ
?Stub43@nsXPTCStubBase@@UAAIXZ
?Stub44@nsXPTCStubBase@@UAAIXZ
?Stub45@nsXPTCStubBase@@UAAIXZ
?Stub46@nsXPTCStubBase@@UAAIXZ
?Stub47@nsXPTCStubBase@@UAAIXZ
?Stub48@nsXPTCStubBase@@UAAIXZ
?Stub49@nsXPTCStubBase@@UAAIXZ
?Stub50@nsXPTCStubBase@@UAAIXZ
?Stub51@nsXPTCStubBase@@UAAIXZ
?Stub52@nsXPTCStubBase@@UAAIXZ
?Stub53@nsXPTCStubBase@@UAAIXZ
?Stub54@nsXPTCStubBase@@UAAIXZ
?Stub55@nsXPTCStubBase@@UAAIXZ
?Stub56@nsXPTCStubBase@@UAAIXZ
?Stub57@nsXPTCStubBase@@UAAIXZ
?Stub58@nsXPTCStubBase@@UAAIXZ
?Stub59@nsXPTCStubBase@@UAAIXZ
?Stub60@nsXPTCStubBase@@UAAIXZ
?Stub61@nsXPTCStubBase@@UAAIXZ
?Stub62@nsXPTCStubBase@@UAAIXZ
?Stub63@nsXPTCStubBase@@UAAIXZ
?Stub64@nsXPTCStubBase@@UAAIXZ
?Stub65@nsXPTCStubBase@@UAAIXZ
?Stub66@nsXPTCStubBase@@UAAIXZ
?Stub67@nsXPTCStubBase@@UAAIXZ
?Stub68@nsXPTCStubBase@@UAAIXZ
?Stub69@nsXPTCStubBase@@UAAIXZ
?Stub70@nsXPTCStubBase@@UAAIXZ
?Stub71@nsXPTCStubBase@@UAAIXZ
?Stub72@nsXPTCStubBase@@UAAIXZ
?Stub73@nsXPTCStubBase@@UAAIXZ
?Stub74@nsXPTCStubBase@@UAAIXZ
?Stub75@nsXPTCStubBase@@UAAIXZ
?Stub76@nsXPTCStubBase@@UAAIXZ
?Stub77@nsXPTCStubBase@@UAAIXZ
?Stub78@nsXPTCStubBase@@UAAIXZ
?Stub79@nsXPTCStubBase@@UAAIXZ
?Stub80@nsXPTCStubBase@@UAAIXZ
?Stub81@nsXPTCStubBase@@UAAIXZ
?Stub82@nsXPTCStubBase@@UAAIXZ
?Stub83@nsXPTCStubBase@@UAAIXZ
?Stub84@nsXPTCStubBase@@UAAIXZ
?Stub85@nsXPTCStubBase@@UAAIXZ
?Stub86@nsXPTCStubBase@@UAAIXZ
?Stub87@nsXPTCStubBase@@UAAIXZ
?Stub88@nsXPTCStubBase@@UAAIXZ
?Stub89@nsXPTCStubBase@@UAAIXZ
?Stub90@nsXPTCStubBase@@UAAIXZ
?Stub91@nsXPTCStubBase@@UAAIXZ
?Stub92@nsXPTCStubBase@@UAAIXZ
?Stub93@nsXPTCStubBase@@UAAIXZ
?Stub94@nsXPTCStubBase@@UAAIXZ
?Stub95@nsXPTCStubBase@@UAAIXZ
?Stub96@nsXPTCStubBase@@UAAIXZ
?Stub97@nsXPTCStubBase@@UAAIXZ
?Stub98@nsXPTCStubBase@@UAAIXZ
?Stub99@nsXPTCStubBase@@UAAIXZ
?Stub100@nsXPTCStubBase@@UAAIXZ
?Stub101@nsXPTCStubBase@@UAAIXZ
?Stub102@nsXPTCStubBase@@UAAIXZ
?Stub103@nsXPTCStubBase@@UAAIXZ
?Stub104@nsXPTCStubBase@@UAAIXZ
?Stub105@nsXPTCStubBase@@UAAIXZ
?Stub106@nsXPTCStubBase@@UAAIXZ
?Stub107@nsXPTCStubBase@@UAAIXZ
?Stub108@nsXPTCStubBase@@UAAIXZ
?Stub109@nsXPTCStubBase@@UAAIXZ
?Stub110@nsXPTCStubBase@@UAAIXZ
?Stub111@nsXPTCStubBase@@UAAIXZ
?Stub112@nsXPTCStubBase@@UAAIXZ
?Stub113@nsXPTCStubBase@@UAAIXZ
?Stub114@nsXPTCStubBase@@UAAIXZ
?Stub115@nsXPTCStubBase@@UAAIXZ
?Stub116@nsXPTCStubBase@@UAAIXZ
?Stub117@nsXPTCStubBase@@UAAIXZ
?Stub118@nsXPTCStubBase@@UAAIXZ
?Stub119@nsXPTCStubBase@@UAAIXZ
?Stub120@nsXPTCStubBase@@UAAIXZ
?Stub121@nsXPTCStubBase@@UAAIXZ
?Stub122@nsXPTCStubBase@@UAAIXZ
?Stub123@nsXPTCStubBase@@UAAIXZ
?Stub124@nsXPTCStubBase@@UAAIXZ
?Stub125@nsXPTCStubBase@@UAAIXZ
?Stub126@nsXPTCStubBase@@UAAIXZ
?Stub127@nsXPTCStubBase@@UAAIXZ
?Stub128@nsXPTCStubBase@@UAAIXZ
?Stub129@nsXPTCStubBase@@UAAIXZ
?Stub130@nsXPTCStubBase@@UAAIXZ
?Stub131@nsXPTCStubBase@@UAAIXZ
?Stub132@nsXPTCStubBase@@UAAIXZ
?Stub133@nsXPTCStubBase@@UAAIXZ
?Stub134@nsXPTCStubBase@@UAAIXZ
?Stub135@nsXPTCStubBase@@UAAIXZ
?Stub136@nsXPTCStubBase@@UAAIXZ
?Stub137@nsXPTCStubBase@@UAAIXZ
?Stub138@nsXPTCStubBase@@UAAIXZ
?Stub139@nsXPTCStubBase@@UAAIXZ
?Stub140@nsXPTCStubBase@@UAAIXZ
?Stub141@nsXPTCStubBase@@UAAIXZ
?Stub142@nsXPTCStubBase@@UAAIXZ
?Stub143@nsXPTCStubBase@@UAAIXZ
?Stub144@nsXPTCStubBase@@UAAIXZ
?Stub145@nsXPTCStubBase@@UAAIXZ
?Stub146@nsXPTCStubBase@@UAAIXZ
?Stub147@nsXPTCStubBase@@UAAIXZ
?Stub148@nsXPTCStubBase@@UAAIXZ
?Stub149@nsXPTCStubBase@@UAAIXZ
?Stub150@nsXPTCStubBase@@UAAIXZ
?Stub151@nsXPTCStubBase@@UAAIXZ
?Stub152@nsXPTCStubBase@@UAAIXZ
?Stub153@nsXPTCStubBase@@UAAIXZ
?Stub154@nsXPTCStubBase@@UAAIXZ
?Stub155@nsXPTCStubBase@@UAAIXZ
?Stub156@nsXPTCStubBase@@UAAIXZ
?Stub157@nsXPTCStubBase@@UAAIXZ
?Stub158@nsXPTCStubBase@@UAAIXZ
?Stub159@nsXPTCStubBase@@UAAIXZ
?Stub160@nsXPTCStubBase@@UAAIXZ
?Stub161@nsXPTCStubBase@@UAAIXZ
?Stub162@nsXPTCStubBase@@UAAIXZ
?Stub163@nsXPTCStubBase@@UAAIXZ
?Stub164@nsXPTCStubBase@@UAAIXZ
?Stub165@nsXPTCStubBase@@UAAIXZ
?Stub166@nsXPTCStubBase@@UAAIXZ
?Stub167@nsXPTCStubBase@@UAAIXZ
?Stub168@nsXPTCStubBase@@UAAIXZ
?Stub169@nsXPTCStubBase@@UAAIXZ
?Stub170@nsXPTCStubBase@@UAAIXZ
?Stub171@nsXPTCStubBase@@UAAIXZ
?Stub172@nsXPTCStubBase@@UAAIXZ
?Stub173@nsXPTCStubBase@@UAAIXZ
?Stub174@nsXPTCStubBase@@UAAIXZ
?Stub175@nsXPTCStubBase@@UAAIXZ
?Stub176@nsXPTCStubBase@@UAAIXZ
?Stub177@nsXPTCStubBase@@UAAIXZ
?Stub178@nsXPTCStubBase@@UAAIXZ
?Stub179@nsXPTCStubBase@@UAAIXZ
?Stub180@nsXPTCStubBase@@UAAIXZ
?Stub181@nsXPTCStubBase@@UAAIXZ
?Stub182@nsXPTCStubBase@@UAAIXZ
?Stub183@nsXPTCStubBase@@UAAIXZ
?Stub184@nsXPTCStubBase@@UAAIXZ
?Stub185@nsXPTCStubBase@@UAAIXZ
?Stub186@nsXPTCStubBase@@UAAIXZ
?Stub187@nsXPTCStubBase@@UAAIXZ
?Stub188@nsXPTCStubBase@@UAAIXZ
?Stub189@nsXPTCStubBase@@UAAIXZ
?Stub190@nsXPTCStubBase@@UAAIXZ
?Stub191@nsXPTCStubBase@@UAAIXZ
?Stub192@nsXPTCStubBase@@UAAIXZ
?Stub193@nsXPTCStubBase@@UAAIXZ
?Stub194@nsXPTCStubBase@@UAAIXZ
?Stub195@nsXPTCStubBase@@UAAIXZ
?Stub196@nsXPTCStubBase@@UAAIXZ
?Stub197@nsXPTCStubBase@@UAAIXZ
?Stub198@nsXPTCStubBase@@UAAIXZ
?Stub199@nsXPTCStubBase@@UAAIXZ
?Stub200@nsXPTCStubBase@@UAAIXZ
?Stub201@nsXPTCStubBase@@UAAIXZ
?Stub202@nsXPTCStubBase@@UAAIXZ
?Stub203@nsXPTCStubBase@@UAAIXZ
?Stub204@nsXPTCStubBase@@UAAIXZ
?Stub205@nsXPTCStubBase@@UAAIXZ
?Stub206@nsXPTCStubBase@@UAAIXZ
?Stub207@nsXPTCStubBase@@UAAIXZ
?Stub208@nsXPTCStubBase@@UAAIXZ
?Stub209@nsXPTCStubBase@@UAAIXZ
?Stub210@nsXPTCStubBase@@UAAIXZ
?Stub211@nsXPTCStubBase@@UAAIXZ
?Stub212@nsXPTCStubBase@@UAAIXZ
?Stub213@nsXPTCStubBase@@UAAIXZ
?Stub214@nsXPTCStubBase@@UAAIXZ
?Stub215@nsXPTCStubBase@@UAAIXZ
?Stub216@nsXPTCStubBase@@UAAIXZ
?Stub217@nsXPTCStubBase@@UAAIXZ
?Stub218@nsXPTCStubBase@@UAAIXZ
?Stub219@nsXPTCStubBase@@UAAIXZ
?Stub220@nsXPTCStubBase@@UAAIXZ
?Stub221@nsXPTCStubBase@@UAAIXZ
?Stub222@nsXPTCStubBase@@UAAIXZ
?Stub223@nsXPTCStubBase@@UAAIXZ
?Stub224@nsXPTCStubBase@@UAAIXZ
?Stub225@nsXPTCStubBase@@UAAIXZ
?Stub226@nsXPTCStubBase@@UAAIXZ
?Stub227@nsXPTCStubBase@@UAAIXZ
?Stub228@nsXPTCStubBase@@UAAIXZ
?Stub229@nsXPTCStubBase@@UAAIXZ
?Stub230@nsXPTCStubBase@@UAAIXZ
?Stub231@nsXPTCStubBase@@UAAIXZ
?Stub232@nsXPTCStubBase@@UAAIXZ
?Stub233@nsXPTCStubBase@@UAAIXZ
?Stub234@nsXPTCStubBase@@UAAIXZ
?Stub235@nsXPTCStubBase@@UAAIXZ
?Stub236@nsXPTCStubBase@@UAAIXZ
?Stub237@nsXPTCStubBase@@UAAIXZ
?Stub238@nsXPTCStubBase@@UAAIXZ
?Stub239@nsXPTCStubBase@@UAAIXZ
?Stub240@nsXPTCStubBase@@UAAIXZ
?Stub241@nsXPTCStubBase@@UAAIXZ
?Stub242@nsXPTCStubBase@@UAAIXZ
?Stub243@nsXPTCStubBase@@UAAIXZ
?Stub244@nsXPTCStubBase@@UAAIXZ
?Stub245@nsXPTCStubBase@@UAAIXZ
?Stub246@nsXPTCStubBase@@UAAIXZ
?Stub247@nsXPTCStubBase@@UAAIXZ
?Stub248@nsXPTCStubBase@@UAAIXZ
?Stub249@nsXPTCStubBase@@UAAIXZ

View File

@@ -1,10 +0,0 @@
nsIGenericFactory.h
nsIRegistryUtils.h
nsXPComFactory.h
nsComponentManagerUtils.h
nsStaticComponent.h
nsIServiceManagerObsolete.h
nsIServiceManagerUtils.h
nsComponentManagerObsolete.h
nsIComponentManagerUtils.h
nsObsoleteModuleLoading.h

Some files were not shown because too many files have changed in this diff Show More