Bug 1268772 (part 5) - Use MOZ_MUST_USE in other parts of xpcom/ds/. r=erahm.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 28 Apr 2016 17:11:17 +1000
changeset 295705 1d99e6c5a2bf41b983658369b97c5d152649695b
parent 295704 ca1b48e0c972772ddad2708febc86f3ab10c5c28
child 295706 bf82810f72802f6fadbffe23e2f21eb2ddc5a417
push id19015
push usercbook@mozilla.com
push dateMon, 02 May 2016 09:39:23 +0000
treeherderfx-team@2080375bc69d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1268772
milestone49.0a1
Bug 1268772 (part 5) - Use MOZ_MUST_USE in other parts of xpcom/ds/. r=erahm. As well as adding MOZ_MUST_USE to a number of functions, this patch: - Changes the return type of nsObserverList::GetObserverList() from |nsresult| to |void|, because it always returned NS_OK and none of the callers checked the result. - Removes an unnecessary |new| check in nsSupportsArray::Enumerate().
xpcom/ds/Tokenizer.h
xpcom/ds/nsObserverList.cpp
xpcom/ds/nsObserverList.h
xpcom/ds/nsObserverService.cpp
xpcom/ds/nsObserverService.h
xpcom/ds/nsPersistentProperties.h
xpcom/ds/nsStringEnumerator.h
xpcom/ds/nsSupportsArray.cpp
xpcom/ds/nsSupportsArray.h
--- a/xpcom/ds/Tokenizer.h
+++ b/xpcom/ds/Tokenizer.h
@@ -204,31 +204,32 @@ public:
    * and returns true.  Otherwise does nothing and returns false.
    */
   MOZ_MUST_USE
   bool CheckEOF() { return Check(Token::EndOfFile()); }
 
   /**
    * These are shortcuts to obtain the value immediately when the token type matches.
    */
-  bool ReadChar(char* aValue);
-  bool ReadChar(bool (*aClassifier)(const char aChar), char* aValue);
-  bool ReadWord(nsACString& aValue);
-  bool ReadWord(nsDependentCSubstring& aValue);
+  MOZ_MUST_USE bool ReadChar(char* aValue);
+  MOZ_MUST_USE bool ReadChar(bool (*aClassifier)(const char aChar),
+                             char* aValue);
+  MOZ_MUST_USE bool ReadWord(nsACString& aValue);
+  MOZ_MUST_USE bool ReadWord(nsDependentCSubstring& aValue);
 
   /**
    * This is an integer read helper.  It returns false and doesn't move the read
    * cursor when any of the following happens:
    *  - the token at the read cursor is not an integer
    *  - the final number doesn't fit the T type
    * Otherwise true is returned, aValue is filled with the integral number
    * and the cursor is moved forward.
    */
   template <typename T>
-  bool ReadInteger(T* aValue)
+  MOZ_MUST_USE bool ReadInteger(T* aValue)
   {
     MOZ_RELEASE_ASSERT(aValue);
 
     nsACString::const_char_iterator rollback = mRollback;
     nsACString::const_char_iterator cursor = mCursor;
     Token t;
     if (!Check(TOKEN_INTEGER, t)) {
       return false;
@@ -294,18 +295,22 @@ public:
    * on aInclude.
    * If aToken isn't found aResult is set to the substring between the current
    * position and the end of the string.
    * If aToken is found, the method returns true. Otherwise it returns false.
    *
    * Calling Rollback() after ReadUntil() will return the read cursor to the
    * position it had before ReadUntil was called.
    */
-  bool ReadUntil(Token const& aToken, nsDependentCSubstring& aResult, ClaimInclusion aInclude = EXCLUDE_LAST);
-  bool ReadUntil(Token const& aToken, nsACString& aResult, ClaimInclusion aInclude = EXCLUDE_LAST);
+  MOZ_MUST_USE bool
+  ReadUntil(Token const& aToken, nsDependentCSubstring& aResult,
+            ClaimInclusion aInclude = EXCLUDE_LAST);
+  MOZ_MUST_USE bool
+  ReadUntil(Token const& aToken, nsACString& aResult,
+            ClaimInclusion aInclude = EXCLUDE_LAST);
 
 protected:
   // false if we have already read the EOF token.
   bool HasInput() const;
   // Main parsing function, it doesn't shift the read cursor, just returns the next
   // token position.
   nsACString::const_char_iterator Parse(Token& aToken) const;
   // Is read cursor at the end?
--- a/xpcom/ds/nsObserverList.cpp
+++ b/xpcom/ds/nsObserverList.cpp
@@ -54,22 +54,21 @@ nsObserverList::RemoveObserver(nsIObserv
 
   if (!mObservers.RemoveElement(observerRef)) {
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
-nsresult
+void
 nsObserverList::GetObserverList(nsISimpleEnumerator** anEnumerator)
 {
   RefPtr<nsObserverEnumerator> e(new nsObserverEnumerator(this));
   e.forget(anEnumerator);
-  return NS_OK;
 }
 
 void
 nsObserverList::FillObserverArray(nsCOMArray<nsIObserver>& aArray)
 {
   aArray.SetCapacity(mObservers.Length());
 
   nsTArray<ObserverRef> observers(mObservers);
--- a/xpcom/ds/nsObserverList.h
+++ b/xpcom/ds/nsObserverList.h
@@ -51,23 +51,23 @@ public:
     MOZ_COUNT_CTOR(nsObserverList);
   }
 
   ~nsObserverList()
   {
     MOZ_COUNT_DTOR(nsObserverList);
   }
 
-  nsresult AddObserver(nsIObserver* aObserver, bool aOwnsWeak);
-  nsresult RemoveObserver(nsIObserver* aObserver);
+  MOZ_MUST_USE nsresult AddObserver(nsIObserver* aObserver, bool aOwnsWeak);
+  MOZ_MUST_USE nsresult RemoveObserver(nsIObserver* aObserver);
 
   void NotifyObservers(nsISupports* aSubject,
                        const char* aTopic,
                        const char16_t* aSomeData);
-  nsresult GetObserverList(nsISimpleEnumerator** aEnumerator);
+  void GetObserverList(nsISimpleEnumerator** aEnumerator);
 
   // Fill an array with the observers of this category.
   // The array is filled in last-added-first order.
   void FillObserverArray(nsCOMArray<nsIObserver>& aArray);
 
   // Like FillObserverArray(), but only for strongly held observers.
   void AppendStrongObservers(nsCOMArray<nsIObserver>& aArray);
 
--- a/xpcom/ds/nsObserverService.cpp
+++ b/xpcom/ds/nsObserverService.cpp
@@ -278,17 +278,18 @@ nsObserverService::EnumerateObservers(co
     return NS_ERROR_INVALID_ARG;
   }
 
   nsObserverList* observerList = mObserverTopicTable.GetEntry(aTopic);
   if (!observerList) {
     return NS_NewEmptyEnumerator(anEnumerator);
   }
 
-  return observerList->GetObserverList(anEnumerator);
+  observerList->GetObserverList(anEnumerator);
+  return NS_OK;
 }
 
 // Enumerate observers of aTopic and call Observe on each.
 NS_IMETHODIMP nsObserverService::NotifyObservers(nsISupports* aSubject,
                                                  const char* aTopic,
                                                  const char16_t* aSomeData)
 {
   LOG(("nsObserverService::NotifyObservers(%s)", aTopic));
--- a/xpcom/ds/nsObserverService.h
+++ b/xpcom/ds/nsObserverService.h
@@ -29,18 +29,18 @@ public:
   nsObserverService();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVERSERVICE
   NS_DECL_NSIMEMORYREPORTER
 
   void Shutdown();
 
-  static nsresult Create(nsISupports* aOuter, const nsIID& aIID,
-                         void** aInstancePtr);
+  static MOZ_MUST_USE nsresult Create(nsISupports* aOuter, const nsIID& aIID,
+                                      void** aInstancePtr);
 
   // Unmark any strongly held observers implemented in JS so the cycle
   // collector will not traverse them.
   NS_IMETHOD UnmarkGrayStrongObservers();
 
 private:
   ~nsObserverService(void);
   void RegisterReporter();
--- a/xpcom/ds/nsPersistentProperties.h
+++ b/xpcom/ds/nsPersistentProperties.h
@@ -20,17 +20,18 @@ class nsPersistentProperties final : pub
 {
 public:
   nsPersistentProperties();
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIPROPERTIES
   NS_DECL_NSIPERSISTENTPROPERTIES
 
-  static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
+  static MOZ_MUST_USE nsresult
+  Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
 private:
   ~nsPersistentProperties();
 
 protected:
   nsCOMPtr<nsIUnicharInputStream> mIn;
 
   PLDHashTable mTable;
--- a/xpcom/ds/nsStringEnumerator.h
+++ b/xpcom/ds/nsStringEnumerator.h
@@ -38,54 +38,54 @@
 // array.AppendCString("abc");
 // array.AppendCString("def");
 // NS_NewStringEnumerator(&enumerator, &array, true);
 //
 // // call some internal method which iterates the enumerator
 // InternalMethod(enumerator);
 // NS_RELEASE(enumerator);
 //
-nsresult
+MOZ_MUST_USE nsresult
 NS_NewStringEnumerator(nsIStringEnumerator** aResult,
                        const nsTArray<nsString>* aArray,
                        nsISupports* aOwner);
-nsresult
+MOZ_MUST_USE nsresult
 NS_NewUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult,
                            const nsTArray<nsCString>* aArray);
 
-nsresult
+MOZ_MUST_USE nsresult
 NS_NewStringEnumerator(nsIStringEnumerator** aResult,
                        const nsTArray<nsString>* aArray);
 
 // Adopting string enumerators assume ownership of the array and will
 // call |operator delete| on the array when the enumerator is destroyed
 // this is useful when the provider creates an array solely for the
 // purpose of creating the enumerator.
 // For example:
 //
 // nsTArray<nsCString>* array = new nsTArray<nsCString>;
 // array->AppendString("abcd");
 // NS_NewAdoptingStringEnumerator(&result, array);
-nsresult
+MOZ_MUST_USE nsresult
 NS_NewAdoptingStringEnumerator(nsIStringEnumerator** aResult,
                                nsTArray<nsString>* aArray);
 
-nsresult
+MOZ_MUST_USE nsresult
 NS_NewAdoptingUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult,
                                    nsTArray<nsCString>* aArray);
 
 
 // these versions take a refcounted "owner" which will be addreffed
 // when the enumerator is created, and destroyed when the enumerator
 // is released. This allows providers to give non-owning pointers to
 // ns*StringArray member variables without worrying about lifetime
 // issues
 // For example:
 //
 // nsresult MyClass::Enumerate(nsIUTF8StringEnumerator** aResult) {
 //     mCategoryList->AppendString("abcd");
 //     return NS_NewStringEnumerator(aResult, mCategoryList, this);
 // }
 //
-nsresult
+MOZ_MUST_USE nsresult
 NS_NewUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult,
                            const nsTArray<nsCString>* aArray,
                            nsISupports* aOwner);
--- a/xpcom/ds/nsSupportsArray.cpp
+++ b/xpcom/ds/nsSupportsArray.cpp
@@ -597,19 +597,16 @@ nsSupportsArray::SizeTo(int32_t aSize)
 
   return true;
 }
 
 NS_IMETHODIMP
 nsSupportsArray::Enumerate(nsIEnumerator** aResult)
 {
   nsSupportsArrayEnumerator* e = new nsSupportsArrayEnumerator(this);
-  if (!e) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
   *aResult = e;
   NS_ADDREF(e);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSupportsArray::Clone(nsISupportsArray** aResult)
 {
--- a/xpcom/ds/nsSupportsArray.h
+++ b/xpcom/ds/nsSupportsArray.h
@@ -15,51 +15,55 @@
 static const uint32_t kAutoArraySize = 8;
 
 class nsSupportsArray final : public nsISupportsArray
 {
   ~nsSupportsArray(void); // nonvirtual since we're not subclassed
 
 public:
   nsSupportsArray(void);
-  static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
+
+  static MOZ_MUST_USE nsresult
+  Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
   NS_DECL_THREADSAFE_ISUPPORTS
 
   NS_DECL_NSISERIALIZABLE
 
   // nsICollection methods:
   NS_IMETHOD Count(uint32_t* aResult) override
   {
     *aResult = mCount;
     return NS_OK;
   }
   NS_IMETHOD GetElementAt(uint32_t aIndex, nsISupports** aResult) override;
-  NS_IMETHOD QueryElementAt(uint32_t aIndex, const nsIID& aIID, void** aResult) override
+  MOZ_MUST_USE NS_IMETHOD
+  QueryElementAt(uint32_t aIndex, const nsIID& aIID, void** aResult) override
   {
     if (aIndex < mCount) {
       nsISupports* element = mArray[aIndex];
       if (element) {
         return element->QueryInterface(aIID, aResult);
       }
     }
     return NS_ERROR_FAILURE;
   }
-  NS_IMETHOD SetElementAt(uint32_t aIndex, nsISupports* aValue) override
+  MOZ_MUST_USE NS_IMETHOD
+  SetElementAt(uint32_t aIndex, nsISupports* aValue) override
   {
     return ReplaceElementAt(aValue, aIndex) ? NS_OK : NS_ERROR_FAILURE;
   }
-  NS_IMETHOD AppendElement(nsISupports* aElement) override
+  MOZ_MUST_USE NS_IMETHOD AppendElement(nsISupports* aElement) override
   {
     // XXX Invalid cast of bool to nsresult (bug 778110)
     return (nsresult)InsertElementAt(aElement, mCount)/* ? NS_OK : NS_ERROR_FAILURE*/;
   }
   // XXX this is badly named - should be RemoveFirstElement
-  NS_IMETHOD RemoveElement(nsISupports* aElement) override;
-  NS_IMETHOD_(bool) MoveElement(int32_t aFrom, int32_t aTo) override;
+  MOZ_MUST_USE NS_IMETHOD RemoveElement(nsISupports* aElement) override;
+  MOZ_MUST_USE NS_IMETHOD_(bool) MoveElement(int32_t aFrom, int32_t aTo) override;
   NS_IMETHOD Enumerate(nsIEnumerator** aResult) override;
   NS_IMETHOD Clear(void) override;
 
   // nsISupportsArray methods:
   NS_IMETHOD_(bool) Equals(const nsISupportsArray* aOther) override;
 
   NS_IMETHOD_(int32_t) IndexOf(const nsISupports* aPossibleElement) override;
   NS_IMETHOD_(int32_t) IndexOfStartingAt(const nsISupports* aPossibleElement,
@@ -80,51 +84,58 @@ public:
   }
 
   NS_IMETHOD GetLastIndexOf(nsISupports* aPossibleElement, int32_t* aResult) override
   {
     *aResult = LastIndexOf(aPossibleElement);
     return NS_OK;
   }
 
-  NS_IMETHOD_(bool) InsertElementAt(nsISupports* aElement, uint32_t aIndex) override;
+  MOZ_MUST_USE NS_IMETHOD_(bool)
+  InsertElementAt(nsISupports* aElement, uint32_t aIndex) override;
 
-  NS_IMETHOD_(bool) ReplaceElementAt(nsISupports* aElement, uint32_t aIndex) override;
+  MOZ_MUST_USE NS_IMETHOD_(bool)
+  ReplaceElementAt(nsISupports* aElement, uint32_t aIndex) override;
 
-  NS_IMETHOD_(bool) RemoveElementAt(uint32_t aIndex) override
+  MOZ_MUST_USE NS_IMETHOD_(bool)
+  RemoveElementAt(uint32_t aIndex) override
   {
     return RemoveElementsAt(aIndex, 1);
   }
-  NS_IMETHOD_(bool) RemoveLastElement(const nsISupports* aElement) override;
+  MOZ_MUST_USE NS_IMETHOD_(bool)
+  RemoveLastElement(const nsISupports* aElement) override;
 
-  NS_IMETHOD DeleteLastElement(nsISupports* aElement) override
+  MOZ_MUST_USE NS_IMETHOD DeleteLastElement(nsISupports* aElement) override
   {
     return (RemoveLastElement(aElement) ? NS_OK : NS_ERROR_FAILURE);
   }
 
-  NS_IMETHOD DeleteElementAt(uint32_t aIndex) override
+  MOZ_MUST_USE NS_IMETHOD DeleteElementAt(uint32_t aIndex) override
   {
     return (RemoveElementAt(aIndex) ? NS_OK : NS_ERROR_FAILURE);
   }
 
-  NS_IMETHOD_(bool) AppendElements(nsISupportsArray* aElements) override
+  MOZ_MUST_USE NS_IMETHOD_(bool)
+  AppendElements(nsISupportsArray* aElements) override
   {
     return InsertElementsAt(aElements, mCount);
   }
 
   NS_IMETHOD Compact(void) override;
 
-  NS_IMETHOD Clone(nsISupportsArray** aResult) override;
+  MOZ_MUST_USE NS_IMETHOD Clone(nsISupportsArray** aResult) override;
+
+  MOZ_MUST_USE NS_IMETHOD_(bool)
+  InsertElementsAt(nsISupportsArray* aOther, uint32_t aIndex) override;
 
-  NS_IMETHOD_(bool) InsertElementsAt(nsISupportsArray* aOther,
-                                     uint32_t aIndex) override;
+  MOZ_MUST_USE NS_IMETHOD_(bool)
+  RemoveElementsAt(uint32_t aIndex, uint32_t aCount) override;
 
-  NS_IMETHOD_(bool) RemoveElementsAt(uint32_t aIndex, uint32_t aCount) override;
-
-  NS_IMETHOD_(bool) SizeTo(int32_t aSize) override;
+  MOZ_MUST_USE NS_IMETHOD_(bool)
+  SizeTo(int32_t aSize) override;
 protected:
   void DeleteArray(void);
 
   void GrowArrayBy(int32_t aGrowBy);
 
   nsISupports** mArray;
   uint32_t mArraySize;
   uint32_t mCount;