mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 858671. Make do_GetAtom infallible. r=khuey
This commit is contained in:
parent
07a59e8ded
commit
d0390f6f9c
@ -478,43 +478,52 @@ NS_SizeOfAtomTablesIncludingThis(nsMallocSizeOfFun aMallocSizeOf) {
|
||||
|
||||
#define ATOM_HASHTABLE_INITIAL_SIZE 4096
|
||||
|
||||
static inline bool
|
||||
static void HandleOOM()
|
||||
{
|
||||
fputs("Out of memory allocating atom hashtable.\n", stderr);
|
||||
MOZ_CRASH();
|
||||
MOZ_NOT_REACHED();
|
||||
}
|
||||
|
||||
static inline void
|
||||
EnsureTableExists()
|
||||
{
|
||||
if (gAtomTable.ops) {
|
||||
return true;
|
||||
if (!gAtomTable.ops &&
|
||||
!PL_DHashTableInit(&gAtomTable, &AtomTableOps, 0,
|
||||
sizeof(AtomTableEntry), ATOM_HASHTABLE_INITIAL_SIZE)) {
|
||||
// Initialization failed.
|
||||
HandleOOM();
|
||||
}
|
||||
if (PL_DHashTableInit(&gAtomTable, &AtomTableOps, 0,
|
||||
sizeof(AtomTableEntry), ATOM_HASHTABLE_INITIAL_SIZE)) {
|
||||
return true;
|
||||
}
|
||||
// Initialization failed.
|
||||
gAtomTable.ops = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline AtomTableEntry*
|
||||
GetAtomHashEntry(const char* aString, uint32_t aLength)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
||||
if (!EnsureTableExists()) {
|
||||
return nullptr;
|
||||
}
|
||||
EnsureTableExists();
|
||||
AtomTableKey key(aString, aLength);
|
||||
return static_cast<AtomTableEntry*>
|
||||
(PL_DHashTableOperate(&gAtomTable, &key, PL_DHASH_ADD));
|
||||
AtomTableEntry* e =
|
||||
static_cast<AtomTableEntry*>
|
||||
(PL_DHashTableOperate(&gAtomTable, &key, PL_DHASH_ADD));
|
||||
if (!e) {
|
||||
HandleOOM();
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
static inline AtomTableEntry*
|
||||
GetAtomHashEntry(const PRUnichar* aString, uint32_t aLength)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
||||
if (!EnsureTableExists()) {
|
||||
return nullptr;
|
||||
}
|
||||
EnsureTableExists();
|
||||
AtomTableKey key(aString, aLength);
|
||||
return static_cast<AtomTableEntry*>
|
||||
(PL_DHashTableOperate(&gAtomTable, &key, PL_DHASH_ADD));
|
||||
AtomTableEntry* e =
|
||||
static_cast<AtomTableEntry*>
|
||||
(PL_DHashTableOperate(&gAtomTable, &key, PL_DHASH_ADD));
|
||||
if (!e) {
|
||||
HandleOOM();
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
class CheckStaticAtomSizes
|
||||
|
@ -97,7 +97,7 @@ protected:
|
||||
|
||||
/**
|
||||
* Find an atom that matches the given UTF-8 string.
|
||||
* The string is assumed to be zero terminated.
|
||||
* The string is assumed to be zero terminated. Never returns null.
|
||||
*/
|
||||
extern nsIAtom* NS_NewAtom(const char* aUTF8String);
|
||||
|
||||
@ -105,7 +105,7 @@ inline already_AddRefed<nsIAtom> do_GetAtom(const char* aUTF8String)
|
||||
{ return NS_NewAtom(aUTF8String); }
|
||||
|
||||
/**
|
||||
* Find an atom that matches the given UTF-8 string.
|
||||
* Find an atom that matches the given UTF-8 string. Never returns null.
|
||||
*/
|
||||
extern nsIAtom* NS_NewAtom(const nsACString& aUTF8String);
|
||||
inline already_AddRefed<nsIAtom> do_GetAtom(const nsACString& aUTF8String)
|
||||
@ -113,14 +113,14 @@ inline already_AddRefed<nsIAtom> do_GetAtom(const nsACString& aUTF8String)
|
||||
|
||||
/**
|
||||
* Find an atom that matches the given UTF-16 string.
|
||||
* The string is assumed to be zero terminated.
|
||||
* The string is assumed to be zero terminated. Never returns null.
|
||||
*/
|
||||
extern nsIAtom* NS_NewAtom(const PRUnichar* aUTF16String);
|
||||
inline already_AddRefed<nsIAtom> do_GetAtom(const PRUnichar* aUTF16String)
|
||||
{ return NS_NewAtom(aUTF16String); }
|
||||
|
||||
/**
|
||||
* Find an atom that matches the given UTF-16 string.
|
||||
* Find an atom that matches the given UTF-16 string. Never returns null.
|
||||
*/
|
||||
extern nsIAtom* NS_NewAtom(const nsAString& aUTF16String);
|
||||
extern nsIAtom* NS_NewPermanentAtom(const nsAString& aUTF16String);
|
||||
|
Loading…
Reference in New Issue
Block a user