From 380782f6b6df96246152a4405d245e995dd8ba29 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Mar 2018 05:54:10 +1100 Subject: [PATCH] Bug 1445113 - Disallow duplicate static atoms. r=froydnj This will allow us to work with direct pointers to static atoms that are initialized at compile-time, rather than pointers to pointers to static atoms that are initialized at runtime. MozReview-Commit-ID: K04pEicuqu3 --HG-- extra : rebase_source : c5d895b34567c621f4591769390fc95a4c6ff405 --- xpcom/ds/nsAtomTable.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/xpcom/ds/nsAtomTable.cpp b/xpcom/ds/nsAtomTable.cpp index 1a1509cf2992..47221515d2e9 100644 --- a/xpcom/ds/nsAtomTable.cpp +++ b/xpcom/ds/nsAtomTable.cpp @@ -666,20 +666,17 @@ nsAtomTable::RegisterStaticAtoms(const nsStaticAtomSetup* aSetup, AtomTableEntry* he = table.Add(key); if (he->mAtom) { - // Disallow creating a dynamic atom, and then later, while the dynamic - // atom is still alive, registering that same atom as a static atom. It - // causes subtle bugs, and we're programming in C++ here, not Smalltalk. - if (!he->mAtom->IsStatic()) { - nsAutoCString name; - he->mAtom->ToUTF8String(name); - MOZ_CRASH_UNSAFE_PRINTF( - "Static atom registration for %s should be pushed back", name.get()); - } - // XXX: A duplicate static atom! Bug 1445113 will disallow this case. - *atomp = static_cast(he->mAtom); - } else { - he->mAtom = *atomp = const_cast(atom); + // There are two ways we could get here. + // - Register two static atoms with the same string. + // - Create a dynamic atom and then register a static atom with the same + // string while the dynamic atom is alive. + // Both cases can cause subtle bugs, and are disallowed. We're + // programming in C++ here, not Smalltalk. + nsAutoCString name; + he->mAtom->ToUTF8String(name); + MOZ_CRASH_UNSAFE_PRINTF("Atom for '%s' already exists", name.get()); } + he->mAtom = *atomp = const_cast(atom); } }