From 8ebcced0aa8f266000cba60b355ed78e280c8804 Mon Sep 17 00:00:00 2001 From: "mrbkap%gmail.com" Date: Mon, 28 Jan 2008 23:52:54 +0000 Subject: [PATCH] Backing out to see if this is the cause for apparent random crashes. git-svn-id: svn://10.0.0.236/trunk@244264 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/src/xpconnect/src/xpcmaps.cpp | 61 +++++++++++------------- mozilla/js/src/xpconnect/src/xpcmaps.h | 8 ++-- 2 files changed, 32 insertions(+), 37 deletions(-) diff --git a/mozilla/js/src/xpconnect/src/xpcmaps.cpp b/mozilla/js/src/xpconnect/src/xpcmaps.cpp index 4b0d1414bda..6dc112c9ff1 100644 --- a/mozilla/js/src/xpconnect/src/xpcmaps.cpp +++ b/mozilla/js/src/xpconnect/src/xpcmaps.cpp @@ -653,16 +653,7 @@ XPCNativeWrapperMap::~XPCNativeWrapperMap() // implement WrappedNative2WrapperMap... struct JSDHashTableOps -WrappedNative2WrapperMap::sOps = { - JS_DHashAllocTable, - JS_DHashFreeTable, - JS_DHashVoidPtrKeyStub, - JS_DHashMatchEntryStub, - CopyLink, - ClearLink, - JS_DHashFinalizeStub, - nsnull -}; +WrappedNative2WrapperMap::sOps = { nsnull }; // static void @@ -671,25 +662,12 @@ WrappedNative2WrapperMap::ClearLink(JSDHashTable* table, { Entry* e = static_cast(entry); e->key = nsnull; - PR_REMOVE_LINK(&e->value); - memset(e, 0, sizeof(*e)); -} - -// static -void -WrappedNative2WrapperMap::CopyLink(JSDHashTable* table, - const JSDHashEntryHdr* from, - JSDHashEntryHdr* to) -{ - const Entry* oldEntry = static_cast(from); - Entry* newEntry = static_cast(to); - - newEntry->key = oldEntry->key; - newEntry->value = oldEntry->value; - - // Now update the list. - newEntry->value.next->prev = &newEntry->value; - newEntry->value.prev->next = &newEntry->value; + if(e->value) + { + PR_REMOVE_LINK(e->value); + delete e->value; + e->value = nsnull; + } } // static @@ -705,6 +683,12 @@ WrappedNative2WrapperMap::newMap(int size) WrappedNative2WrapperMap::WrappedNative2WrapperMap(int size) { + if(!sOps.allocTable) + { + sOps = *JS_DHashGetStubOps(); + sOps.clearEntry = WrappedNative2WrapperMap::ClearLink; + } + mTable = JS_NewDHashTable(&sOps, nsnull, sizeof(Entry), size); } @@ -726,7 +710,9 @@ WrappedNative2WrapperMap::Add(WrappedNative2WrapperMap* head, return nsnull; NS_ASSERTION(!entry->key || this == head, "dangling pointer?"); entry->key = wrappedObject; - Link* l = &entry->value; + Link* l = new Link; + if(!l) + return nsnull; PR_INIT_CLIST(l); l->obj = wrapper; @@ -738,7 +724,12 @@ WrappedNative2WrapperMap::Add(WrappedNative2WrapperMap* head, Entry* dummy = (Entry*) JS_DHashTableOperate(head->mTable, wrappedObject, JS_DHASH_ADD); dummy->key = wrappedObject; - headLink = &dummy->value; + headLink = dummy->value = new Link; + if(!headLink) + { + Remove(wrappedObject); + return nsnull; + } PR_INIT_CLIST(headLink); headLink->obj = nsnull; } @@ -746,6 +737,7 @@ WrappedNative2WrapperMap::Add(WrappedNative2WrapperMap* head, PR_INSERT_BEFORE(l, headLink); } + entry->value = l; return wrapper; } @@ -758,7 +750,12 @@ WrappedNative2WrapperMap::AddLink(JSObject* wrappedObject, Link* oldLink) return PR_FALSE; NS_ASSERTION(!entry->key, "Eh? What's happening?"); entry->key = wrappedObject; - Link* newLink = &entry->value; + Link* newLink = entry->value = new Link; + if(!newLink) + { + Remove(wrappedObject); + return PR_FALSE; + } PR_INSERT_LINK(newLink, oldLink); PR_REMOVE_AND_INIT_LINK(oldLink); diff --git a/mozilla/js/src/xpconnect/src/xpcmaps.h b/mozilla/js/src/xpconnect/src/xpcmaps.h index 1cb787db6ff..9c08b8cc9bb 100644 --- a/mozilla/js/src/xpconnect/src/xpcmaps.h +++ b/mozilla/js/src/xpconnect/src/xpcmaps.h @@ -689,8 +689,6 @@ class WrappedNative2WrapperMap static struct JSDHashTableOps sOps; static void ClearLink(JSDHashTable* table, JSDHashEntryHdr* entry); - static void CopyLink(JSDHashTable* table, const JSDHashEntryHdr* from, - JSDHashEntryHdr* to); public: struct Link : public PRCList @@ -702,7 +700,7 @@ public: { // Note: key must be the flat JSObject for a wrapped native. JSObject* key; - Link value; + Link* value; }; static WrappedNative2WrapperMap* newMap(int size); @@ -714,7 +712,7 @@ public: JS_DHashTableOperate(mTable, wrapper, JS_DHASH_LOOKUP); if(JS_DHASH_ENTRY_IS_FREE(entry)) return nsnull; - return entry->value.obj; + return entry->value->obj; } // Note: If the entry already exists, then this will overwrite the @@ -729,7 +727,7 @@ public: Entry* entry = (Entry*) JS_DHashTableOperate(mTable, wrappedObject, JS_DHASH_LOOKUP); if(JS_DHASH_ENTRY_IS_BUSY(entry)) - return &entry->value; + return entry->value; return nsnull; }