From 91a3707d5f25b8ea7d7c16e3a53c36aab7c1d508 Mon Sep 17 00:00:00 2001 From: Brindusan Cristian Date: Tue, 24 Jul 2018 04:55:03 +0300 Subject: [PATCH] Backed out 3 changesets (bug 1477579) for build bustages on xpcshell\selftest.py and crashtest failures on /components/nsComponentManager.cpp. CLOSED TREE Backed out changeset aa9a8f18e98f (bug 1477579) Backed out changeset 5fb0b7746a5d (bug 1477579) Backed out changeset 8359f8fe4184 (bug 1477579) --- dom/base/nsContentUtils.cpp | 3 +- dom/base/nsDocument.cpp | 4 +- dom/plugins/base/nsPluginHost.cpp | 17 +- dom/push/PushNotifier.cpp | 4 +- gfx/thebes/gfxSVGGlyphs.cpp | 2 +- image/SVGDocumentWrapper.cpp | 2 +- layout/base/nsStyleSheetService.cpp | 2 +- .../components/commandlines/nsCommandLine.cpp | 8 +- toolkit/xre/nsAppStartupNotifier.cpp | 9 +- uriloader/base/nsURILoader.cpp | 3 +- .../exthandler/nsExternalHelperAppService.cpp | 3 +- xpcom/components/nsCategoryCache.cpp | 10 +- xpcom/components/nsCategoryCache.h | 4 +- xpcom/components/nsCategoryManager.cpp | 159 +++++++++++------- xpcom/components/nsCategoryManager.h | 37 ++-- xpcom/components/nsComponentManager.cpp | 91 ++++------ xpcom/components/nsComponentManager.h | 2 +- xpcom/components/nsICategoryManager.idl | 77 +-------- xpcom/components/nsServiceManagerUtils.h | 9 +- xpcom/ds/nsHashKeys.h | 31 ---- xpcom/io/nsDirectoryService.cpp | 4 +- 21 files changed, 199 insertions(+), 282 deletions(-) diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index a7fde53421752..40916ed72fa34 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -6952,7 +6952,8 @@ nsContentUtils::FindInternalContentViewer(const nsACString& aType, nsCString contractID; nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", - aType, contractID); + PromiseFlatCString(aType).get(), + getter_Copies(contractID)); if (NS_SUCCEEDED(rv)) { docFactory = do_GetService(contractID.get()); if (docFactory && aLoaderType) { diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 00d1b343784e0..91e87364214cf 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -1089,8 +1089,8 @@ nsExternalResourceMap::PendingLoad::SetupViewer(nsIRequest* aRequest, do_GetService(NS_CATEGORYMANAGER_CONTRACTID); NS_ENSURE_TRUE(catMan, NS_ERROR_NOT_AVAILABLE); nsCString contractId; - nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", type, - contractId); + nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", type.get(), + getter_Copies(contractId)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr docLoaderFactory = do_GetService(contractId.get()); diff --git a/dom/plugins/base/nsPluginHost.cpp b/dom/plugins/base/nsPluginHost.cpp index 4fbfa83c77d4d..da1753251a4d8 100644 --- a/dom/plugins/base/nsPluginHost.cpp +++ b/dom/plugins/base/nsPluginHost.cpp @@ -2771,15 +2771,16 @@ nsPluginHost::RegisterWithCategoryManager(const nsCString& aMimeType, return; } - NS_NAMED_LITERAL_CSTRING(contractId, - "@mozilla.org/content/plugin/document-loader-factory;1"); + const char *contractId = + "@mozilla.org/content/plugin/document-loader-factory;1"; if (aType == ePluginRegister) { catMan->AddCategoryEntry("Gecko-Content-Viewers", - aMimeType, + aMimeType.get(), contractId, false, /* persist: broken by bug 193031 */ - mOverrideInternalTypes); + mOverrideInternalTypes, + nullptr); } else { if (aType == ePluginMaybeUnregister) { // Bail out if this type is still used by an enabled plugin @@ -2793,10 +2794,12 @@ nsPluginHost::RegisterWithCategoryManager(const nsCString& aMimeType, // Only delete the entry if a plugin registered for it nsCString value; nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", - aMimeType, value); - if (NS_SUCCEEDED(rv) && value == contractId) { + aMimeType.get(), + getter_Copies(value)); + if (NS_SUCCEEDED(rv) && strcmp(value.get(), contractId) == 0) { catMan->DeleteCategoryEntry("Gecko-Content-Viewers", - aMimeType, true); + aMimeType.get(), + true); } } } diff --git a/dom/push/PushNotifier.cpp b/dom/push/PushNotifier.cpp index f09c2ac10cf78..739bb2dccf11b 100644 --- a/dom/push/PushNotifier.cpp +++ b/dom/push/PushNotifier.cpp @@ -320,7 +320,9 @@ PushDispatcher::DoNotifyObservers(nsISupports *aSubject, const char *aTopic, do_GetService(NS_CATEGORYMANAGER_CONTRACTID); if (catMan) { nsCString contractId; - nsresult rv = catMan->GetCategoryEntry("push", mScope, contractId); + nsresult rv = catMan->GetCategoryEntry("push", + mScope.BeginReading(), + getter_Copies(contractId)); if (NS_SUCCEEDED(rv)) { // Ensure the service is created - we don't need to do anything with // it though - we assume the service constructor attaches a listener. diff --git a/gfx/thebes/gfxSVGGlyphs.cpp b/gfx/thebes/gfxSVGGlyphs.cpp index cbb14fd086b7d..99ee3c66f83fe 100644 --- a/gfx/thebes/gfxSVGGlyphs.cpp +++ b/gfx/thebes/gfxSVGGlyphs.cpp @@ -137,7 +137,7 @@ gfxSVGGlyphsDocument::SetupPresentation() { nsCOMPtr catMan = do_GetService(NS_CATEGORYMANAGER_CONTRACTID); nsCString contractId; - nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", "image/svg+xml", contractId); + nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", "image/svg+xml", getter_Copies(contractId)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr docLoaderFactory = diff --git a/image/SVGDocumentWrapper.cpp b/image/SVGDocumentWrapper.cpp index 76b4e7a4c007e..8d5215846c8c7 100644 --- a/image/SVGDocumentWrapper.cpp +++ b/image/SVGDocumentWrapper.cpp @@ -332,7 +332,7 @@ SVGDocumentWrapper::SetupViewer(nsIRequest* aRequest, NS_ENSURE_TRUE(catMan, NS_ERROR_NOT_AVAILABLE); nsCString contractId; nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", IMAGE_SVG_XML, - contractId); + getter_Copies(contractId)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr docLoaderFactory = do_GetService(contractId.get()); diff --git a/layout/base/nsStyleSheetService.cpp b/layout/base/nsStyleSheetService.cpp index d91ba5c5df18c..1c7f21638448b 100644 --- a/layout/base/nsStyleSheetService.cpp +++ b/layout/base/nsStyleSheetService.cpp @@ -74,7 +74,7 @@ nsStyleSheetService::RegisterFromEnumerator(nsICategoryManager *aManager, icStr->GetData(name); nsCString spec; - aManager->GetCategoryEntry(nsDependentCString(aCategory), name, spec); + aManager->GetCategoryEntry(aCategory, name.get(), getter_Copies(spec)); nsCOMPtr uri; NS_NewURI(getter_AddRefs(uri), spec); diff --git a/toolkit/components/commandlines/nsCommandLine.cpp b/toolkit/components/commandlines/nsCommandLine.cpp index 7f9faf819091c..9a93461183854 100644 --- a/toolkit/components/commandlines/nsCommandLine.cpp +++ b/toolkit/components/commandlines/nsCommandLine.cpp @@ -515,8 +515,9 @@ nsCommandLine::EnumerateHandlers(EnumerateHandlersCallback aCallback, void *aClo strenum->GetNext(entry); nsCString contractID; - rv = catman->GetCategoryEntry("command-line-handler", entry, - contractID); + rv = catman->GetCategoryEntry("command-line-handler", + entry.get(), + getter_Copies(contractID)); if (NS_FAILED(rv)) continue; @@ -561,7 +562,8 @@ nsCommandLine::EnumerateValidators(EnumerateValidatorsCallback aCallback, void * nsCString contractID; rv = catman->GetCategoryEntry("command-line-validator", - entry, contractID); + entry.get(), + getter_Copies(contractID)); if (contractID.IsVoid()) continue; diff --git a/toolkit/xre/nsAppStartupNotifier.cpp b/toolkit/xre/nsAppStartupNotifier.cpp index fad6c50869190..f66067640fd45 100644 --- a/toolkit/xre/nsAppStartupNotifier.cpp +++ b/toolkit/xre/nsAppStartupNotifier.cpp @@ -30,10 +30,8 @@ NS_IMETHODIMP nsAppStartupNotifier::Observe(nsISupports *aSubject, const char *a do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); - nsDependentCString topic(aTopic); - nsCOMPtr enumerator; - rv = categoryManager->EnumerateCategory(topic, + rv = categoryManager->EnumerateCategory(aTopic, getter_AddRefs(enumerator)); if (NS_FAILED(rv)) return rv; @@ -46,8 +44,9 @@ NS_IMETHODIMP nsAppStartupNotifier::Observe(nsISupports *aSubject, const char *a rv = category->GetData(categoryEntry); nsCString contractId; - categoryManager->GetCategoryEntry(topic, categoryEntry, - contractId); + categoryManager->GetCategoryEntry(aTopic, + categoryEntry.get(), + getter_Copies(contractId)); if (NS_SUCCEEDED(rv)) { diff --git a/uriloader/base/nsURILoader.cpp b/uriloader/base/nsURILoader.cpp index c222933ceef0e..5f007878a9600 100644 --- a/uriloader/base/nsURILoader.cpp +++ b/uriloader/base/nsURILoader.cpp @@ -465,7 +465,8 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports * if (catman) { nsCString contractidString; rv = catman->GetCategoryEntry(NS_CONTENT_LISTENER_CATEGORYMANAGER_ENTRY, - mContentType, contractidString); + mContentType.get(), + getter_Copies(contractidString)); if (NS_SUCCEEDED(rv) && !contractidString.IsEmpty()) { LOG((" Listener contractid for '%s' is '%s'", mContentType.get(), contractidString.get())); diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index e85068439becd..4ae754d14bf87 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -2693,7 +2693,8 @@ nsExternalHelperAppService::GetTypeFromExtension(const nsACString& aFileExt, // Read the MIME type from the category entry, if available nsCString type; nsresult rv = catMan->GetCategoryEntry("ext-to-type-mapping", - lowercaseFileExt, type); + lowercaseFileExt.get(), + getter_Copies(type)); if (NS_SUCCEEDED(rv)) { aContentType = type; return NS_OK; diff --git a/xpcom/components/nsCategoryCache.cpp b/xpcom/components/nsCategoryCache.cpp index fc3ea2aabbe73..0224d33b7648b 100644 --- a/xpcom/components/nsCategoryCache.cpp +++ b/xpcom/components/nsCategoryCache.cpp @@ -13,7 +13,7 @@ #include "nsCategoryCache.h" -nsCategoryObserver::nsCategoryObserver(const nsACString& aCategory) +nsCategoryObserver::nsCategoryObserver(const char* aCategory) : mCategory(aCategory) , mCallback(nullptr) , mClosure(nullptr) @@ -43,7 +43,9 @@ nsCategoryObserver::nsCategoryObserver(const nsACString& aCategory) strings->GetNext(entryName); nsCString entryValue; - rv = catMan->GetCategoryEntry(aCategory, entryName, entryValue); + rv = catMan->GetCategoryEntry(aCategory, + entryName.get(), + getter_Copies(entryValue)); if (NS_SUCCEEDED(rv)) { nsCOMPtr service = do_GetService(entryValue.get()); if (service) { @@ -149,7 +151,9 @@ nsCategoryObserver::Observe(nsISupports* aSubject, const char* aTopic, } nsCString entryValue; - catMan->GetCategoryEntry(mCategory, str, entryValue); + catMan->GetCategoryEntry(mCategory.get(), + str.get(), + getter_Copies(entryValue)); nsCOMPtr service = do_GetService(entryValue.get()); diff --git a/xpcom/components/nsCategoryCache.h b/xpcom/components/nsCategoryCache.h index 517b4036e1462..cbde29cbd8c8e 100644 --- a/xpcom/components/nsCategoryCache.h +++ b/xpcom/components/nsCategoryCache.h @@ -28,7 +28,7 @@ class nsCategoryObserver final : public nsIObserver ~nsCategoryObserver(); public: - explicit nsCategoryObserver(const nsACString& aCategory); + explicit nsCategoryObserver(const char* aCategory); void ListenerDied(); void SetListener(void(aCallback)(void*), void* aClosure); @@ -104,7 +104,7 @@ class nsCategoryCache final // Lazy initialization, so that services in this category can't // cause reentrant getService (bug 386376) if (!mObserver) { - mObserver = new nsCategoryObserver(mCategoryName); + mObserver = new nsCategoryObserver(mCategoryName.get()); mObserver->SetListener(nsCategoryCache::OnCategoryChanged, this); } } diff --git a/xpcom/components/nsCategoryManager.cpp b/xpcom/components/nsCategoryManager.cpp index b96187ecc65c8..d29abbfb492e6 100644 --- a/xpcom/components/nsCategoryManager.cpp +++ b/xpcom/components/nsCategoryManager.cpp @@ -206,47 +206,45 @@ CategoryNode::operator new(size_t aSize, CategoryAllocator* aArena) return aArena->Allocate(aSize, mozilla::fallible); } -static inline const char* -MaybeStrdup(const nsACString& aStr, CategoryAllocator* aArena) -{ - if (aStr.IsLiteral()) { - return aStr.BeginReading(); - } - return ArenaStrdup(PromiseFlatCString(aStr).get(), *aArena); -} - nsresult -CategoryNode::GetLeaf(const nsACString& aEntryName, - nsACString& aResult) +CategoryNode::GetLeaf(const char* aEntryName, + char** aResult) { MutexAutoLock lock(mLock); nsresult rv = NS_ERROR_NOT_AVAILABLE; - CategoryLeaf* ent = mTable.GetEntry(PromiseFlatCString(aEntryName).get()); + CategoryLeaf* ent = mTable.GetEntry(aEntryName); if (ent && ent->value) { - aResult.Assign(ent->value); - return NS_OK; + *aResult = NS_strdup(ent->value); + if (*aResult) { + rv = NS_OK; + } } return rv; } nsresult -CategoryNode::AddLeaf(const nsACString& aEntryName, - const nsACString& aValue, +CategoryNode::AddLeaf(const char* aEntryName, + const char* aValue, bool aReplace, - nsACString& aResult, + char** aResult, CategoryAllocator* aArena) { - aResult.SetIsVoid(true); - - auto entryName = PromiseFlatCString(aEntryName); + if (aResult) { + *aResult = nullptr; + } MutexAutoLock lock(mLock); - CategoryLeaf* leaf = mTable.GetEntry(entryName.get()); + CategoryLeaf* leaf = mTable.GetEntry(aEntryName); if (!leaf) { - leaf = mTable.PutEntry(MaybeStrdup(aEntryName, aArena)); + const char* arenaEntryName = ArenaStrdup(aEntryName, *aArena); + if (!arenaEntryName) { + return NS_ERROR_OUT_OF_MEMORY; + } + + leaf = mTable.PutEntry(arenaEntryName); if (!leaf) { return NS_ERROR_OUT_OF_MEMORY; } @@ -256,24 +254,31 @@ CategoryNode::AddLeaf(const nsACString& aEntryName, return NS_ERROR_INVALID_ARG; } - if (leaf->value) { - aResult.AssignLiteral(leaf->value, strlen(leaf->value)); - } else { - aResult.SetIsVoid(true); + const char* arenaValue = ArenaStrdup(aValue, *aArena); + if (!arenaValue) { + return NS_ERROR_OUT_OF_MEMORY; + } + + if (aResult && leaf->value) { + *aResult = ToNewCString(nsDependentCString(leaf->value)); + if (!*aResult) { + return NS_ERROR_OUT_OF_MEMORY; + } } - leaf->value = MaybeStrdup(aValue, aArena); + + leaf->value = arenaValue; return NS_OK; } void -CategoryNode::DeleteLeaf(const nsACString& aEntryName) +CategoryNode::DeleteLeaf(const char* aEntryName) { // we don't throw any errors, because it normally doesn't matter // and it makes JS a lot cleaner MutexAutoLock lock(mLock); // we can just remove the entire hash entry without introspection - mTable.RemoveEntry(PromiseFlatCString(aEntryName).get()); + mTable.RemoveEntry(aEntryName); } nsresult @@ -334,7 +339,8 @@ CategoryEnumerator::Create(nsClassHashtable& // if a category has no entries, we pretend it doesn't exist CategoryNode* aNode = iter.UserData(); if (aNode->Count()) { - enumObj->mArray[enumObj->mCount++] = iter.Key(); + const char* str = iter.Key(); + enumObj->mArray[enumObj->mCount++] = str; } } @@ -417,10 +423,10 @@ nsCategoryManager::~nsCategoryManager() } inline CategoryNode* -nsCategoryManager::get_category(const nsACString& aName) +nsCategoryManager::get_category(const char* aName) { CategoryNode* node; - if (!mTable.Get(PromiseFlatCString(aName).get(), &node)) { + if (!mTable.Get(aName, &node)) { return nullptr; } return node; @@ -463,7 +469,7 @@ class CategoryNotificationRunnable : public Runnable public: CategoryNotificationRunnable(nsISupports* aSubject, const char* aTopic, - const nsACString& aData) + const char* aData) : Runnable("CategoryNotificationRunnable") , mSubject(aSubject) , mTopic(aTopic) @@ -496,8 +502,8 @@ CategoryNotificationRunnable::Run() void nsCategoryManager::NotifyObservers(const char* aTopic, - const nsACString& aCategoryName, - const nsACString& aEntryName) + const char* aCategoryName, + const char* aEntryName) { if (mSuppressNotifications) { return; @@ -505,14 +511,14 @@ nsCategoryManager::NotifyObservers(const char* aTopic, RefPtr r; - if (aEntryName.Length()) { + if (aEntryName) { nsCOMPtr entry = do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID); if (!entry) { return; } - nsresult rv = entry->SetData(aEntryName); + nsresult rv = entry->SetData(nsDependentCString(aEntryName)); if (NS_FAILED(rv)) { return; } @@ -528,10 +534,16 @@ nsCategoryManager::NotifyObservers(const char* aTopic, } NS_IMETHODIMP -nsCategoryManager::GetCategoryEntry(const nsACString& aCategoryName, - const nsACString& aEntryName, - nsACString& aResult) +nsCategoryManager::GetCategoryEntry(const char* aCategoryName, + const char* aEntryName, + char** aResult) { + if (NS_WARN_IF(!aCategoryName) || + NS_WARN_IF(!aEntryName) || + NS_WARN_IF(!aResult)) { + return NS_ERROR_INVALID_ARG; + } + nsresult status = NS_ERROR_NOT_AVAILABLE; CategoryNode* category; @@ -548,12 +560,12 @@ nsCategoryManager::GetCategoryEntry(const nsACString& aCategoryName, } NS_IMETHODIMP -nsCategoryManager::AddCategoryEntry(const nsACString& aCategoryName, - const nsACString& aEntryName, - const nsACString& aValue, +nsCategoryManager::AddCategoryEntry(const char* aCategoryName, + const char* aEntryName, + const char* aValue, bool aPersist, bool aReplace, - nsACString& aResult) + char** aResult) { if (aPersist) { NS_ERROR("Category manager doesn't support persistence."); @@ -565,13 +577,15 @@ nsCategoryManager::AddCategoryEntry(const nsACString& aCategoryName, } void -nsCategoryManager::AddCategoryEntry(const nsACString& aCategoryName, - const nsACString& aEntryName, - const nsACString& aValue, +nsCategoryManager::AddCategoryEntry(const char* aCategoryName, + const char* aEntryName, + const char* aValue, bool aReplace, - nsACString& aOldValue) + char** aOldValue) { - aOldValue.SetIsVoid(true); + if (aOldValue) { + *aOldValue = nullptr; + } // Before we can insert a new entry, we'll need to // find the |CategoryNode| to put it in... @@ -584,8 +598,8 @@ nsCategoryManager::AddCategoryEntry(const nsACString& aCategoryName, // That category doesn't exist yet; let's make it. category = CategoryNode::Create(&mArena); - mTable.Put(MaybeStrdup(aCategoryName, &mArena), - category); + char* categoryName = ArenaStrdup(aCategoryName, mArena); + mTable.Put(categoryName, category); } } @@ -593,28 +607,41 @@ nsCategoryManager::AddCategoryEntry(const nsACString& aCategoryName, return; } + // We will need the return value of AddLeaf even if the called doesn't want it + char* oldEntry = nullptr; + nsresult rv = category->AddLeaf(aEntryName, aValue, aReplace, - aOldValue, + &oldEntry, &mArena); if (NS_SUCCEEDED(rv)) { - if (!aOldValue.IsEmpty()) { + if (oldEntry) { NotifyObservers(NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID, aCategoryName, aEntryName); } NotifyObservers(NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID, aCategoryName, aEntryName); + if (aOldValue) { + *aOldValue = oldEntry; + } else { + free(oldEntry); + } } } NS_IMETHODIMP -nsCategoryManager::DeleteCategoryEntry(const nsACString& aCategoryName, - const nsACString& aEntryName, +nsCategoryManager::DeleteCategoryEntry(const char* aCategoryName, + const char* aEntryName, bool aDontPersist) { + if (NS_WARN_IF(!aCategoryName) || + NS_WARN_IF(!aEntryName)) { + return NS_ERROR_INVALID_ARG; + } + /* Note: no errors are reported since failure to delete probably won't hurt you, and returning errors seriously @@ -638,8 +665,12 @@ nsCategoryManager::DeleteCategoryEntry(const nsACString& aCategoryName, } NS_IMETHODIMP -nsCategoryManager::DeleteCategory(const nsACString& aCategoryName) +nsCategoryManager::DeleteCategory(const char* aCategoryName) { + if (NS_WARN_IF(!aCategoryName)) { + return NS_ERROR_INVALID_ARG; + } + // the categories are arena-allocated, so we don't // actually delete them. We just remove all of the // leaf nodes. @@ -653,16 +684,21 @@ nsCategoryManager::DeleteCategory(const nsACString& aCategoryName) if (category) { category->Clear(); NotifyObservers(NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID, - aCategoryName, VoidCString()); + aCategoryName, nullptr); } return NS_OK; } NS_IMETHODIMP -nsCategoryManager::EnumerateCategory(const nsACString& aCategoryName, +nsCategoryManager::EnumerateCategory(const char* aCategoryName, nsISimpleEnumerator** aResult) { + if (NS_WARN_IF(!aCategoryName) || + NS_WARN_IF(!aResult)) { + return NS_ERROR_INVALID_ARG; + } + CategoryNode* category; { MutexAutoLock lock(mLock); @@ -731,10 +767,8 @@ NS_CreateServicesFromCategory(const char* aCategory, return; } - nsDependentCString category(aCategory); - nsCOMPtr enumerator; - rv = categoryManager->EnumerateCategory(category, + rv = categoryManager->EnumerateCategory(aCategory, getter_AddRefs(enumerator)); if (NS_FAILED(rv)) { return; @@ -756,7 +790,8 @@ NS_CreateServicesFromCategory(const char* aCategory, } nsCString contractID; - rv = categoryManager->GetCategoryEntry(category, entryString, contractID); + rv = categoryManager->GetCategoryEntry(aCategory, entryString.get(), + getter_Copies(contractID)); if (NS_FAILED(rv)) { continue; } diff --git a/xpcom/components/nsCategoryManager.h b/xpcom/components/nsCategoryManager.h index a54f418d6980d..292ebbe2f0721 100644 --- a/xpcom/components/nsCategoryManager.h +++ b/xpcom/components/nsCategoryManager.h @@ -50,16 +50,16 @@ class CategoryLeaf : public nsDepCharHashKey class CategoryNode { public: - nsresult GetLeaf(const nsACString& aEntryName, - nsACString& aResult); + nsresult GetLeaf(const char* aEntryName, + char** aResult); - nsresult AddLeaf(const nsACString& aEntryName, - const nsACString& aValue, + nsresult AddLeaf(const char* aEntryName, + const char* aValue, bool aReplace, - nsACString& aResult, + char** aResult, CategoryAllocator* aArena); - void DeleteLeaf(const nsACString& aEntryName); + void DeleteLeaf(const char* aEntryName); void Clear() { @@ -114,20 +114,11 @@ class nsCategoryManager final */ nsresult SuppressNotifications(bool aSuppress); - void AddCategoryEntry(const nsACString& aCategory, - const nsACString& aKey, - const nsACString& aValue, - bool aReplace, - nsACString& aOldValue); - - void AddCategoryEntry(const nsACString& aCategory, - const nsACString& aKey, - const nsACString& aValue, - bool aReplace = true) - { - nsCString oldValue; - return AddCategoryEntry(aCategory, aKey, aValue, aReplace, oldValue); - } + void AddCategoryEntry(const char* aCategory, + const char* aKey, + const char* aValue, + bool aReplace = true, + char** aOldValue = nullptr); static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult); void InitMemoryReporter(); @@ -143,10 +134,10 @@ class nsCategoryManager final size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf); - CategoryNode* get_category(const nsACString& aName); + CategoryNode* get_category(const char* aName); void NotifyObservers(const char* aTopic, - const nsACString& aCategoryName, // must be a static string - const nsACString& aEntryName); + const char* aCategoryName, // must be a static string + const char* aEntryName); CategoryAllocator mArena; nsClassHashtable mTable; diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp index 835b8d2ec0a9b..f5082bf06327f 100644 --- a/xpcom/components/nsComponentManager.cpp +++ b/xpcom/components/nsComponentManager.cpp @@ -57,10 +57,6 @@ #include "mozilla/Logging.h" #include "LogModulePrefWatcher.h" -#ifdef MOZ_MEMORY -#include "mozmemory.h" -#endif - using namespace mozilla; static LazyLogModule nsComponentManagerLog("nsComponentManager"); @@ -102,6 +98,12 @@ nsGetServiceFromCategory::operator()(const nsIID& aIID, goto error; } + if (!mCategory || !mEntry) { + // when categories have defaults, use that for null mEntry + rv = NS_ERROR_NULL_POINTER; + goto error; + } + rv = compMgr->nsComponentManagerImpl::GetService(kCategoryManagerCID, NS_GET_IID(nsICategoryManager), getter_AddRefs(catman)); @@ -110,7 +112,8 @@ nsGetServiceFromCategory::operator()(const nsIID& aIID, } /* find the contractID for category.entry */ - rv = catman->GetCategoryEntry(mCategory, mEntry, value); + rv = catman->GetCategoryEntry(mCategory, mEntry, + getter_Copies(value)); if (NS_FAILED(rv)) { goto error; } @@ -465,39 +468,6 @@ ProcessSelectorMatches(Module::ProcessSelector aSelector) static const int kModuleVersionWithSelector = 51; -template -static void -AssertNotMallocAllocated(T* aPtr) -{ -#if defined(DEBUG) && defined(MOZ_MEMORY) - jemalloc_ptr_info_t info; - jemalloc_ptr_info((void*)aPtr, &info); - MOZ_ASSERT(info.tag == TagUnknown); -#endif -} - -template -static void -AssertNotStackAllocated(T* aPtr) -{ - // The main thread's stack should be allocated at the top of our address - // space. Anything stack allocated should be above us on the stack, and - // therefore above our first argument pointer. - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(uintptr_t(aPtr) < uintptr_t(&aPtr)); -} - -static inline nsCString -AsLiteralCString(const char* aStr) -{ - AssertNotMallocAllocated(aStr); - AssertNotStackAllocated(aStr); - - nsCString str; - str.AssignLiteral(aStr, strlen(aStr)); - return str; -} - void nsComponentManagerImpl::RegisterModule(const mozilla::Module* aModule, FileLocation* aFile) @@ -548,10 +518,9 @@ nsComponentManagerImpl::RegisterModule(const mozilla::Module* aModule, if (aModule->mCategoryEntries) { const mozilla::Module::CategoryEntry* entry; for (entry = aModule->mCategoryEntries; entry->category; ++entry) - nsCategoryManager::GetSingleton()->AddCategoryEntry( - AsLiteralCString(entry->category), - AsLiteralCString(entry->entry), - AsLiteralCString(entry->value)); + nsCategoryManager::GetSingleton()->AddCategoryEntry(entry->category, + entry->entry, + entry->value); } } @@ -566,7 +535,7 @@ nsComponentManagerImpl::RegisterCIDEntryLocked( return; } - if (auto entry = mFactories.LookupForAdd(aEntry->cid)) { + if (auto entry = mFactories.LookupForAdd(*aEntry->cid)) { nsFactoryEntry* f = entry.Data(); NS_WARNING("Re-registering a CID?"); @@ -599,7 +568,7 @@ nsComponentManagerImpl::RegisterContractIDLocked( return; } - nsFactoryEntry* f = mFactories.Get(aEntry->cid); + nsFactoryEntry* f = mFactories.Get(*aEntry->cid); if (!f) { NS_WARNING("No CID found when attempting to map contract ID"); @@ -614,7 +583,7 @@ nsComponentManagerImpl::RegisterContractIDLocked( return; } - mContractIDs.Put(AsLiteralCString(aEntry->contractid), f); + mContractIDs.Put(nsDependentCString(aEntry->contractid), f); } static void @@ -693,8 +662,9 @@ nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& aCx, fl.GetURIString(hash); MutexLock lock(mLock); - nsFactoryEntry* f = mFactories.Get(&cid); - if (f) { + auto entry = mFactories.LookupForAdd(cid); + if (entry) { + nsFactoryEntry* f = entry.Data(); char idstr[NSID_LENGTH]; cid.ToProvidedString(idstr); @@ -730,7 +700,7 @@ nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& aCx, auto* e = new (KnownNotNull, place) mozilla::Module::CIDEntry(); e->cid = permanentCID; - mFactories.Put(permanentCID, new nsFactoryEntry(e, km)); + entry.OrInsert([e, km] () { return new nsFactoryEntry(e, km); }); } void @@ -750,7 +720,7 @@ nsComponentManagerImpl::ManifestContract(ManifestProcessingContext& aCx, } MutexLock lock(mLock); - nsFactoryEntry* f = mFactories.Get(&cid); + nsFactoryEntry* f = mFactories.Get(cid); if (!f) { lock.Unlock(); LogMessageWithContext(aCx.mFile, aLineNo, @@ -771,8 +741,7 @@ nsComponentManagerImpl::ManifestCategory(ManifestProcessingContext& aCx, char* value = aArgv[2]; nsCategoryManager::GetSingleton()-> - AddCategoryEntry(nsDependentCString(category), nsDependentCString(key), - nsDependentCString(value)); + AddCategoryEntry(category, key, value); } void @@ -918,7 +887,7 @@ nsFactoryEntry* nsComponentManagerImpl::GetFactoryEntry(const nsCID& aClass) { SafeMutexAutoLock lock(mLock); - return mFactories.Get(&aClass); + return mFactories.Get(aClass); } already_AddRefed @@ -1247,7 +1216,7 @@ nsComponentManagerImpl::GetService(const nsCID& aClass, nsCOMPtr service; MutexLock lock(mLock); - nsFactoryEntry* entry = mFactories.Get(&aClass); + nsFactoryEntry* entry = mFactories.Get(aClass); if (!entry) { return NS_ERROR_FACTORY_NOT_REGISTERED; } @@ -1363,7 +1332,7 @@ nsComponentManagerImpl::IsServiceInstantiated(const nsCID& aClass, { SafeMutexAutoLock lock(mLock); - entry = mFactories.Get(&aClass); + entry = mFactories.Get(aClass); } if (entry && entry->mServiceObject) { @@ -1542,8 +1511,8 @@ nsComponentManagerImpl::LoaderForExtension(const nsACString& aExt) { nsCOMPtr loader = mLoaderMap.Get(aExt); if (!loader) { - loader = do_GetServiceFromCategory(NS_LITERAL_CSTRING("module-loader"), - aExt); + loader = do_GetServiceFromCategory("module-loader", + PromiseFlatCString(aExt).get()); if (!loader) { return nullptr; } @@ -1568,7 +1537,7 @@ nsComponentManagerImpl::RegisterFactory(const nsCID& aClass, } SafeMutexAutoLock lock(mLock); - nsFactoryEntry* oldf = mFactories.Get(&aClass); + nsFactoryEntry* oldf = mFactories.Get(aClass); if (!oldf) { return NS_ERROR_FACTORY_NOT_REGISTERED; } @@ -1580,7 +1549,7 @@ nsComponentManagerImpl::RegisterFactory(const nsCID& aClass, nsAutoPtr f(new nsFactoryEntry(aClass, aFactory)); SafeMutexAutoLock lock(mLock); - if (auto entry = mFactories.LookupForAdd(f->mCIDEntry->cid)) { + if (auto entry = mFactories.LookupForAdd(aClass)) { return NS_ERROR_FACTORY_EXISTS; } else { if (aContractID) { @@ -1603,7 +1572,7 @@ nsComponentManagerImpl::UnregisterFactory(const nsCID& aClass, { SafeMutexAutoLock lock(mLock); - auto entry = mFactories.Lookup(&aClass); + auto entry = mFactories.Lookup(aClass); nsFactoryEntry* f = entry ? entry.Data() : nullptr; if (!f || f->mFactory != aFactory) { return NS_ERROR_FACTORY_NOT_REGISTERED; @@ -1691,9 +1660,9 @@ nsComponentManagerImpl::EnumerateCIDs(nsISimpleEnumerator** aEnumerator) { nsCOMArray array; for (auto iter = mFactories.Iter(); !iter.Done(); iter.Next()) { - const nsID* id = iter.Key(); + const nsID& id = iter.Key(); nsCOMPtr wrapper = new nsSupportsID(); - wrapper->SetData(id); + wrapper->SetData(&id); array.AppendObject(wrapper); } return NS_NewArrayEnumerator(aEnumerator, array); diff --git a/xpcom/components/nsComponentManager.h b/xpcom/components/nsComponentManager.h index ad3db81db94eb..d50ee74238201 100644 --- a/xpcom/components/nsComponentManager.h +++ b/xpcom/components/nsComponentManager.h @@ -167,7 +167,7 @@ class nsComponentManagerImpl final uint32_t aContractIDLen); nsFactoryEntry* GetFactoryEntry(const nsCID& aClass); - nsDataHashtable mFactories; + nsDataHashtable mFactories; nsDataHashtable mContractIDs; SafeMutex mLock; diff --git a/xpcom/components/nsICategoryManager.idl b/xpcom/components/nsICategoryManager.idl index 6fc4f639ab56e..e33d3ed8bfdae 100644 --- a/xpcom/components/nsICategoryManager.idl +++ b/xpcom/components/nsICategoryManager.idl @@ -7,15 +7,11 @@ interface nsISimpleEnumerator; -%{C++ -#include "nsString.h" -%} - /* * nsICategoryManager */ -[builtinclass, scriptable, uuid(3275b2cd-af6d-429a-80d7-f0c5120342ac)] +[scriptable, uuid(3275b2cd-af6d-429a-80d7-f0c5120342ac)] interface nsICategoryManager : nsISupports { /** @@ -24,7 +20,7 @@ interface nsICategoryManager : nsISupports * @param aEntry The entry you're looking for ("http") * @return The value. */ - ACString getCategoryEntry(in ACString aCategory, in ACString aEntry); + string getCategoryEntry(in string aCategory, in string aEntry); /** * Add an entry to a category. @@ -35,9 +31,9 @@ interface nsICategoryManager : nsISupports * @param aReplace Should we replace an existing entry? * @return Previous entry, if any */ - ACString addCategoryEntry(in ACString aCategory, in ACString aEntry, - in ACString aValue, in boolean aPersist, - in boolean aReplace); + string addCategoryEntry(in string aCategory, in string aEntry, + in string aValue, in boolean aPersist, + in boolean aReplace); /** * Delete an entry from the category. @@ -45,14 +41,14 @@ interface nsICategoryManager : nsISupports * @param aEntry The entry to be added ("http") * @param aPersist Delete persistent data from registry, if present? */ - void deleteCategoryEntry(in ACString aCategory, in ACString aEntry, - in boolean aPersist); + void deleteCategoryEntry(in string aCategory, in string aEntry, + in boolean aPersist); /** * Delete a category and all entries. * @param aCategory The category to be deleted. */ - void deleteCategory(in ACString aCategory); + void deleteCategory(in string aCategory); /** * Enumerate the entries in a category. @@ -60,7 +56,7 @@ interface nsICategoryManager : nsISupports * @return a simple enumerator, each result QIs to * nsISupportsCString. */ - nsISimpleEnumerator enumerateCategory(in ACString aCategory); + nsISimpleEnumerator enumerateCategory(in string aCategory); /** * Enumerate all existing categories @@ -69,60 +65,5 @@ interface nsICategoryManager : nsISupports * nsISupportsCString. */ nsISimpleEnumerator enumerateCategories(); - - %{C++ - template - nsresult - GetCategoryEntry(const char (&aCategory)[N], const nsACString& aEntry, - nsACString& aResult) - { - return GetCategoryEntry(nsLiteralCString(aCategory), - aEntry, aResult); - } - - template - nsresult - GetCategoryEntry(const char (&aCategory)[N], const char (&aEntry)[M], - nsACString& aResult) - { - return GetCategoryEntry(nsLiteralCString(aCategory), - nsLiteralCString(aEntry), - aResult); - } - - nsresult - AddCategoryEntry(const nsACString& aCategory, const nsACString& aEntry, - const nsACString& aValue, bool aPersist, bool aReplace) - { - nsCString oldValue; - return AddCategoryEntry(aCategory, aEntry, aValue, aPersist, aReplace, - oldValue); - } - - template - nsresult - AddCategoryEntry(const char (&aCategory)[N], const nsACString& aEntry, - const nsACString& aValue, bool aPersist, bool aReplace) - { - nsCString oldValue; - return AddCategoryEntry(nsLiteralCString(aCategory), aEntry, aValue, - aPersist, aReplace, oldValue); - } - - template - nsresult - DeleteCategoryEntry(const char (&aCategory)[N], const nsACString& aEntry, bool aPersist) - { - return DeleteCategoryEntry(nsLiteralCString(aCategory), aEntry, aPersist); - } - - - template - nsresult - EnumerateCategory(const char (&aCategory)[N], nsISimpleEnumerator** aResult) - { - return EnumerateCategory(nsLiteralCString(aCategory), aResult); - } - %} }; diff --git a/xpcom/components/nsServiceManagerUtils.h b/xpcom/components/nsServiceManagerUtils.h index e91af8d182240..9bcd9ae8e850b 100644 --- a/xpcom/components/nsServiceManagerUtils.h +++ b/xpcom/components/nsServiceManagerUtils.h @@ -9,7 +9,6 @@ #include "nsIServiceManager.h" #include "nsCOMPtr.h" -#include "nsString.h" inline const nsGetServiceByCID do_GetService(const nsCID& aCID) @@ -38,7 +37,7 @@ do_GetService(const char* aContractID, nsresult* aError) class MOZ_STACK_CLASS nsGetServiceFromCategory final : public nsCOMPtr_helper { public: - nsGetServiceFromCategory(const nsACString& aCategory, const nsACString& aEntry, + nsGetServiceFromCategory(const char* aCategory, const char* aEntry, nsresult* aErrorPtr) : mCategory(aCategory) , mEntry(aEntry) @@ -49,13 +48,13 @@ class MOZ_STACK_CLASS nsGetServiceFromCategory final : public nsCOMPtr_helper virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const override; protected: - const nsCString mCategory; - const nsCString mEntry; + const char* mCategory; + const char* mEntry; nsresult* mErrorPtr; }; inline const nsGetServiceFromCategory -do_GetServiceFromCategory(const nsACString& aCategory, const nsACString& aEntry, +do_GetServiceFromCategory(const char* aCategory, const char* aEntry, nsresult* aError = 0) { return nsGetServiceFromCategory(aCategory, aEntry, aError); diff --git a/xpcom/ds/nsHashKeys.h b/xpcom/ds/nsHashKeys.h index 795d8bda13030..e8a996e2166bc 100644 --- a/xpcom/ds/nsHashKeys.h +++ b/xpcom/ds/nsHashKeys.h @@ -473,37 +473,6 @@ class nsIDHashKey : public PLDHashEntryHdr const nsID mID; }; -/** - * hashkey wrapper using nsID* KeyType - * - * @see nsTHashtable::EntryType for specification - */ -class nsIDPointerHashKey : public PLDHashEntryHdr -{ -public: - typedef const nsID* KeyType; - typedef const nsID* KeyTypePointer; - - explicit nsIDPointerHashKey(const nsID* aInID) : mID(aInID) {} - nsIDPointerHashKey(const nsIDPointerHashKey& aToCopy) : mID(aToCopy.mID) {} - ~nsIDPointerHashKey() = default; - - KeyType GetKey() const { return mID; } - bool KeyEquals(KeyTypePointer aKey) const { return aKey->Equals(*mID); } - - static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; } - static PLDHashNumber HashKey(KeyTypePointer aKey) - { - // Hash the nsID object's raw bytes. - return mozilla::HashBytes(aKey, sizeof(*aKey)); - } - - enum { ALLOW_MEMMOVE = true }; - -private: - const nsID* mID; -}; - /** * hashkey wrapper for "dependent" const char*; this class does not "own" * its string pointer. diff --git a/xpcom/io/nsDirectoryService.cpp b/xpcom/io/nsDirectoryService.cpp index c3e3bc6b3a334..be7ba1424a2ef 100644 --- a/xpcom/io/nsDirectoryService.cpp +++ b/xpcom/io/nsDirectoryService.cpp @@ -358,8 +358,8 @@ nsDirectoryService::RegisterCategoryProviders() strings->GetNext(entry); nsCString contractID; - catman->GetCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY, entry, - contractID); + catman->GetCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY, entry.get(), + getter_Copies(contractID)); if (!contractID.IsVoid()) { nsCOMPtr provider = do_GetService(contractID.get());