Bug 1131199, part 2 - Make PLDHashtInitEntry infallible. r=froydnj

Also, drop the unused table argument.
This commit is contained in:
Andrew McCreight 2015-02-11 09:46:40 -08:00
parent 55eaced49c
commit c946357872
16 changed files with 37 additions and 76 deletions

View File

@ -379,13 +379,11 @@ public:
nsRefPtr<EventListenerManager> mListenerManager;
};
static bool
EventListenerManagerHashInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
const void *key)
static void
EventListenerManagerHashInitEntry(PLDHashEntryHdr *entry, const void *key)
{
// Initialize the entry with placement new
new (entry) EventListenerManagerMapEntry(key);
return true;
}
static void

View File

@ -3957,8 +3957,8 @@ SubDocClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
}
}
static bool
SubDocInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry, const void *key)
static void
SubDocInitEntry(PLDHashEntryHdr *entry, const void *key)
{
SubDocMapEntry *e =
const_cast<SubDocMapEntry *>
@ -3968,7 +3968,6 @@ SubDocInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry, const void *key)
NS_ADDREF(e->mKey);
e->mSubDocument = nullptr;
return true;
}
nsresult

View File

@ -99,9 +99,8 @@ GlobalNameHashClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
memset(&e->mGlobalName, 0, sizeof(nsGlobalNameStruct));
}
static bool
GlobalNameHashInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
const void *key)
static void
GlobalNameHashInitEntry(PLDHashEntryHdr *entry, const void *key)
{
GlobalNameMapEntry *e = static_cast<GlobalNameMapEntry *>(entry);
const nsAString *keyStr = static_cast<const nsAString *>(key);
@ -112,7 +111,6 @@ GlobalNameHashInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
// This will set e->mGlobalName.mType to
// nsGlobalNameStruct::eTypeNotInitialized
memset(&e->mGlobalName, 0, sizeof(nsGlobalNameStruct));
return true;
}
NS_IMPL_ISUPPORTS(

View File

@ -244,13 +244,11 @@ RuleHash_CSMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
return match_atom == entry_atom;
}
static bool
RuleHash_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
const void *key)
static void
RuleHash_InitEntry(PLDHashEntryHdr *hdr, const void *key)
{
RuleHashTableEntry* entry = static_cast<RuleHashTableEntry*>(hdr);
new (entry) RuleHashTableEntry();
return true;
}
static void
@ -284,14 +282,12 @@ RuleHash_TagTable_MatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
return match_atom == entry_atom;
}
static bool
RuleHash_TagTable_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
const void *key)
static void
RuleHash_TagTable_InitEntry(PLDHashEntryHdr *hdr, const void *key)
{
RuleHashTagTableEntry* entry = static_cast<RuleHashTagTableEntry*>(hdr);
new (entry) RuleHashTagTableEntry();
entry->mTag = const_cast<nsIAtom*>(static_cast<const nsIAtom*>(key));
return true;
}
static void
@ -836,14 +832,12 @@ AtomSelector_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
(static_cast<AtomSelectorEntry*>(hdr))->~AtomSelectorEntry();
}
static bool
AtomSelector_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
const void *key)
static void
AtomSelector_InitEntry(PLDHashEntryHdr *hdr, const void *key)
{
AtomSelectorEntry *entry = static_cast<AtomSelectorEntry*>(hdr);
new (entry) AtomSelectorEntry();
entry->mAtom = const_cast<nsIAtom*>(static_cast<const nsIAtom*>(key));
return true;
}
static void
@ -3320,13 +3314,11 @@ MatchWeightEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
return entry->data.mWeight == NS_PTR_TO_INT32(key);
}
static bool
InitWeightEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
const void *key)
static void
InitWeightEntry(PLDHashEntryHdr *hdr, const void *key)
{
RuleByWeightEntry* entry = static_cast<RuleByWeightEntry*>(hdr);
new (entry) RuleByWeightEntry();
return true;
}
static const PLDHashTableOps gRulesByWeightOps = {

View File

@ -208,9 +208,8 @@ LangRuleTable_MatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
return entry->mRule->mLang == *lang;
}
static bool
LangRuleTable_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
const void *key)
static void
LangRuleTable_InitEntry(PLDHashEntryHdr *hdr, const void *key)
{
const nsString *lang = static_cast<const nsString*>(key);
@ -218,8 +217,6 @@ LangRuleTable_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
// Create the unique rule for this language
entry->mRule = new nsHTMLStyleSheet::LangRule(*lang);
return true;
}
static const PLDHashTableOps LangRuleTable_Ops = {

View File

@ -78,16 +78,14 @@ RequestHashClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
e->~RequestMapEntry();
}
static bool
RequestHashInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
const void *key)
static void
RequestHashInitEntry(PLDHashEntryHdr *entry, const void *key)
{
const nsIRequest *const_request = static_cast<const nsIRequest *>(key);
nsIRequest *request = const_cast<nsIRequest *>(const_request);
// Initialize the entry with placement new
new (entry) RequestMapEntry(request);
return true;
}

View File

@ -459,14 +459,12 @@ HostDB_ClearEntry(PLDHashTable *table,
NS_RELEASE(he->rec);
}
static bool
HostDB_InitEntry(PLDHashTable *table,
PLDHashEntryHdr *entry,
static void
HostDB_InitEntry(PLDHashEntryHdr *entry,
const void *key)
{
nsHostDBEnt *he = static_cast<nsHostDBEnt *>(entry);
nsHostRecord::Create(static_cast<const nsHostKey *>(key), &he->rec);
return true;
}
static const PLDHashTableOps gHostDB_ops =

View File

@ -63,13 +63,11 @@ RequestMapMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
return entry->r == key;
}
static bool
RequestMapInitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
const void *key)
static void
RequestMapInitEntry(PLDHashEntryHdr *hdr, const void *key)
{
RequestHashEntry *entry = static_cast<RequestHashEntry*>(hdr);
entry->r = (void*)key;
return true;
}
static const PLDHashTableOps gMapOps = {

View File

@ -71,14 +71,12 @@ CompareCacheMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
return entryPtr->entry->key == key;
}
static bool
CompareCacheInitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
const void *key)
static void
CompareCacheInitEntry(PLDHashEntryHdr *hdr, const void *key)
{
new (hdr) CompareCacheHashEntryPtr();
CompareCacheHashEntryPtr *entryPtr = static_cast<CompareCacheHashEntryPtr*>(hdr);
entryPtr->entry->key = (void*)key;
return true;
}
static void

View File

@ -23,13 +23,11 @@ ObjectSetMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
return entry->obj == static_cast<const nsNSSShutDownObject*>(key);
}
static bool
ObjectSetInitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
const void *key)
static void
ObjectSetInitEntry(PLDHashEntryHdr *hdr, const void *key)
{
ObjectHashEntry *entry = static_cast<ObjectHashEntry*>(hdr);
entry->obj = const_cast<nsNSSShutDownObject*>(static_cast<const nsNSSShutDownObject*>(key));
return true;
}
static const PLDHashTableOps gSetOps = {

View File

@ -64,14 +64,12 @@ void GetURIStringFromRequest(nsIRequest* request, nsACString &name)
bool
nsDocLoader::RequestInfoHashInitEntry(PLDHashTable* table,
PLDHashEntryHdr* entry,
void
nsDocLoader::RequestInfoHashInitEntry(PLDHashEntryHdr* entry,
const void* key)
{
// Initialize the entry with placement new
new (entry) nsRequestInfo(key);
return true;
}
void

View File

@ -246,8 +246,7 @@ protected:
nsAutoPtr<nsStatusInfo> mLastStatus;
};
static bool RequestInfoHashInitEntry(PLDHashTable* table, PLDHashEntryHdr* entry,
const void* key);
static void RequestInfoHashInitEntry(PLDHashEntryHdr* entry, const void* key);
static void RequestInfoHashClearEntry(PLDHashTable* table, PLDHashEntryHdr* entry);
// IMPORTANT: The ownership implicit in the following member

View File

@ -283,13 +283,10 @@ AtomTableClearEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry)
}
}
static bool
AtomTableInitEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry,
const void* aKey)
static void
AtomTableInitEntry(PLDHashEntryHdr* aEntry, const void* aKey)
{
static_cast<AtomTableEntry*>(aEntry)->mAtom = nullptr;
return true;
}

View File

@ -335,8 +335,7 @@ protected:
static void s_ClearEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry);
static bool s_InitEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry,
const void* aKey);
static void s_InitEntry(PLDHashEntryHdr* aEntry, const void* aKey);
/**
* passed internally during enumeration. Allocated on the stack.
@ -486,13 +485,11 @@ nsTHashtable<EntryType>::s_ClearEntry(PLDHashTable* aTable,
}
template<class EntryType>
bool
nsTHashtable<EntryType>::s_InitEntry(PLDHashTable* aTable,
PLDHashEntryHdr* aEntry,
void
nsTHashtable<EntryType>::s_InitEntry(PLDHashEntryHdr* aEntry,
const void* aKey)
{
new (aEntry) EntryType(reinterpret_cast<KeyTypePointer>(aKey));
return true;
}
template<class EntryType>

View File

@ -622,11 +622,8 @@ PLDHashTable::Add(const void* aKey)
mRemovedCount--;
keyHash |= COLLISION_FLAG;
}
if (mOps->initEntry && !mOps->initEntry(this, entry, aKey)) {
/* We haven't claimed entry yet; fail with null return. */
memset(entry + 1, 0, mEntrySize - sizeof(*entry));
entry = nullptr;
goto exit;
if (mOps->initEntry) {
mOps->initEntry(entry, aKey);
}
entry->mKeyHash = keyHash;
mEntryCount++;

View File

@ -349,8 +349,7 @@ typedef void (*PLDHashClearEntry)(PLDHashTable* aTable,
* new one. At that point, aEntry->mKeyHash is not set yet, to avoid claiming
* the last free entry in a severely overloaded table.
*/
typedef bool (*PLDHashInitEntry)(PLDHashTable* aTable, PLDHashEntryHdr* aEntry,
const void* aKey);
typedef void (*PLDHashInitEntry)(PLDHashEntryHdr* aEntry, const void* aKey);
/*
* Finally, the "vtable" structure for PLDHashTable. The first four hooks