Bug 784739 - Switch from NULL to nullptr in mfbt/. r=jwalden
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Thu, 25 Jul 2013 16:31:48 -0700
changeset 140140 e978bb426e87a0cdca79f827904c954ffdc47439
parent 140139 7a73c9157311ef9ca8023d8db59692825c66f368
child 140141 77df61af1a84b8e5d554920e1f48781de6d63600
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjwalden
bugs784739
milestone25.0a1
Bug 784739 - Switch from NULL to nullptr in mfbt/. r=jwalden
mfbt/GuardObjects.h
mfbt/LinkedList.h
mfbt/RangedPtr.h
mfbt/Scoped.h
mfbt/ThreadLocal.h
mfbt/Vector.h
mfbt/tests/TestPoisonArea.cpp
--- a/mfbt/GuardObjects.h
+++ b/mfbt/GuardObjects.h
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Implementation of macros to ensure correct use of RAII Auto* objects. */
 
 #ifndef mozilla_GuardObjects_h
 #define mozilla_GuardObjects_h
 
 #include "mozilla/Assertions.h"
+#include "mozilla/NullPtr.h"
 #include "mozilla/Types.h"
 
 #ifdef __cplusplus
 
 #ifdef DEBUG
 
 namespace mozilla {
 namespace detail {
@@ -68,17 +69,17 @@ namespace detail {
  * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla
  */
 class MOZ_EXPORT GuardObjectNotifier
 {
   private:
     bool* statementDone;
 
   public:
-    GuardObjectNotifier() : statementDone(NULL) { }
+    GuardObjectNotifier() : statementDone(nullptr) { }
 
     ~GuardObjectNotifier() {
       *statementDone = true;
     }
 
     void setStatementDone(bool* statementIsDone) {
       statementDone = statementIsDone;
     }
--- a/mfbt/LinkedList.h
+++ b/mfbt/LinkedList.h
@@ -41,44 +41,45 @@
  *       void removeObserver(Observer* observer) {
  *         // Will assert if |observer| is not part of some list.
  *         observer.remove();
  *         // Or, will assert if |observer| is not part of |list| specifically.
  *         // observer.removeFrom(list);
  *       }
  *
  *       void notifyObservers(char* topic) {
- *         for (Observer* o = list.getFirst(); o != NULL; o = o->getNext())
- *           o->Observe(topic);
+ *         for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext())
+ *           o->observe(topic);
  *       }
  *   };
  *
  */
 
 #ifndef mozilla_LinkedList_h
 #define mozilla_LinkedList_h
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/NullPtr.h"
 
 #ifdef __cplusplus
 
 namespace mozilla {
 
 template<typename T>
 class LinkedList;
 
 template<typename T>
 class LinkedListElement
 {
     /*
-     * It's convenient that we return NULL when getNext() or getPrevious() hits
-     * the end of the list, but doing so costs an extra word of storage in each
-     * linked list node (to keep track of whether |this| is the sentinel node)
-     * and a branch on this value in getNext/getPrevious.
+     * It's convenient that we return nullptr when getNext() or getPrevious()
+     * hits the end of the list, but doing so costs an extra word of storage in
+     * each linked list node (to keep track of whether |this| is the sentinel
+     * node) and a branch on this value in getNext/getPrevious.
      *
      * We could get rid of the extra word of storage by shoving the "is
      * sentinel" bit into one of the pointers, although this would, of course,
      * have performance implications of its own.
      *
      * But the goal here isn't to win an award for the fastest or slimmest
      * linked list; rather, we want a *convenient* linked list.  So we won't
      * waste time guessing which micro-optimization strategy is best.
@@ -116,29 +117,29 @@ class LinkedListElement
     { }
 
     ~LinkedListElement() {
       if (!isSentinel && isInList())
         remove();
     }
 
     /*
-     * Get the next element in the list, or NULL if this is the last element in
-     * the list.
+     * Get the next element in the list, or nullptr if this is the last element
+     * in the list.
      */
     T* getNext() {
       return next->asT();
     }
     const T* getNext() const {
       return next->asT();
     }
 
     /*
-     * Get the previous element in the list, or NULL if this is the first element
-     * in the list.
+     * Get the previous element in the list, or nullptr if this is the first
+     * element in the list.
      */
     T* getPrevious() {
       return prev->asT();
     }
     const T* getPrevious() const {
       return prev->asT();
     }
 
@@ -201,28 +202,28 @@ class LinkedListElement
 
     LinkedListElement(NodeKind nodeKind)
       : next(MOZ_THIS_IN_INITIALIZER_LIST()),
         prev(MOZ_THIS_IN_INITIALIZER_LIST()),
         isSentinel(nodeKind == NODE_KIND_SENTINEL)
     { }
 
     /*
-     * Return |this| cast to T* if we're a normal node, or return NULL if we're
-     * a sentinel node.
+     * Return |this| cast to T* if we're a normal node, or return nullptr if
+     * we're a sentinel node.
      */
     T* asT() {
       if (isSentinel)
-        return NULL;
+        return nullptr;
 
       return static_cast<T*>(this);
     }
     const T* asT() const {
       if (isSentinel)
-        return NULL;
+        return nullptr;
 
       return static_cast<const T*>(this);
     }
 
     /*
      * Insert elem after this element, but don't check that this element is in
      * the list.  This is called by LinkedList::insertFront().
      */
@@ -279,49 +280,49 @@ class LinkedList
     /*
      * Add elem to the back of the list.
      */
     void insertBack(T* elem) {
       sentinel.setPreviousUnsafe(elem);
     }
 
     /*
-     * Get the first element of the list, or NULL if the list is empty.
+     * Get the first element of the list, or nullptr if the list is empty.
      */
     T* getFirst() {
       return sentinel.getNext();
     }
     const T* getFirst() const {
       return sentinel.getNext();
     }
 
     /*
-     * Get the last element of the list, or NULL if the list is empty.
+     * Get the last element of the list, or nullptr if the list is empty.
      */
     T* getLast() {
       return sentinel.getPrevious();
     }
     const T* getLast() const {
       return sentinel.getPrevious();
     }
 
     /*
      * Get and remove the first element of the list.  If the list is empty,
-     * return NULL.
+     * return nullptr.
      */
     T* popFirst() {
       T* ret = sentinel.getNext();
       if (ret)
         static_cast<LinkedListElement<T>*>(ret)->remove();
       return ret;
     }
 
     /*
      * Get and remove the last element of the list.  If the list is empty,
-     * return NULL.
+     * return nullptr.
      */
     T* popLast() {
       T* ret = sentinel.getPrevious();
       if (ret)
         static_cast<LinkedListElement<T>*>(ret)->remove();
       return ret;
     }
 
--- a/mfbt/RangedPtr.h
+++ b/mfbt/RangedPtr.h
@@ -9,16 +9,17 @@
  * construction.
  */
 
 #ifndef mozilla_RangedPtr_h
 #define mozilla_RangedPtr_h
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/NullPtr.h"
 #include "mozilla/Util.h"
 
 namespace mozilla {
 
 /*
  * RangedPtr is a smart pointer restricted to an address range specified at
  * creation.  The pointer (and any smart pointers derived from it) must remain
  * within the range [start, end] (inclusive of end to facilitate use as
@@ -55,17 +56,17 @@ class RangedPtr
       MOZ_ASSERT(ptr <= rangeEnd);
     }
 
     /* Creates a new pointer for |p|, restricted to this pointer's range. */
     RangedPtr<T> create(T *p) const {
 #ifdef DEBUG
       return RangedPtr<T>(p, rangeStart, rangeEnd);
 #else
-      return RangedPtr<T>(p, NULL, size_t(0));
+      return RangedPtr<T>(p, nullptr, size_t(0));
 #endif
     }
 
     uintptr_t asUintptr() const { return uintptr_t(ptr); }
 
   public:
     RangedPtr(T* p, T* start, T* end)
       : ptr(p)
--- a/mfbt/Scoped.h
+++ b/mfbt/Scoped.h
@@ -49,16 +49,17 @@
  * and |MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE|  to simplify the definition
  * of RAII classes for other scenarios. These macros have been used to
  * automatically close file descriptors/file handles when reaching the end of
  * the scope, graphics contexts, etc.
  */
 
 #include "mozilla/Attributes.h"
 #include "mozilla/GuardObjects.h"
+#include "mozilla/NullPtr.h"
 
 namespace mozilla {
 
 /*
  * Scoped is a helper to create RAII wrappers
  * Type argument |Traits| is expected to have the following structure:
  *
  *   struct Traits {
@@ -190,17 +191,17 @@ struct name : public mozilla::Scoped<Tra
  *   struct S { ... };
  *   ScopedFreePtr<S> foo = malloc(sizeof(S));
  *   ScopedFreePtr<char> bar = strdup(str);
  */
 template<typename T>
 struct ScopedFreePtrTraits
 {
     typedef T* type;
-    static T* empty() { return NULL; }
+    static T* empty() { return nullptr; }
     static void release(T* ptr) { free(ptr); }
 };
 SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits)
 
 /*
  * ScopedDeletePtr is a RAII wrapper for pointers that need to be deleted.
  *
  *   struct S { ... };
@@ -253,17 +254,17 @@ template <> inline void TypeSpecificDele
 typedef ::mozilla::TypeSpecificScopedPointer<Type> name;
 
 template <typename T> void TypeSpecificDelete(T * value);
 
 template <typename T>
 struct TypeSpecificScopedPointerTraits
 {
     typedef T* type;
-    const static type empty() { return NULL; }
+    const static type empty() { return nullptr; }
     const static void release(type value)
     {
       if (value)
         TypeSpecificDelete(value);
     }
 };
 
 SCOPED_TEMPLATE(TypeSpecificScopedPointer, TypeSpecificScopedPointerTraits)
--- a/mfbt/ThreadLocal.h
+++ b/mfbt/ThreadLocal.h
@@ -24,16 +24,17 @@ extern "C" {
 }
 #else
 #  include <pthread.h>
 #  include <signal.h>
 #endif
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/NullPtr.h"
 
 namespace mozilla {
 
 // sig_safe_t denotes an atomic type which can be read or stored in a single
 // instruction.  This means that data of this type is safe to be manipulated
 // from a signal handler, or other similar asynchronous execution contexts.
 #if defined(XP_WIN)
 typedef unsigned long sig_safe_t;
@@ -102,17 +103,17 @@ ThreadLocal<T>::init()
   MOZ_STATIC_ASSERT(sizeof(T) <= sizeof(void*),
                     "mozilla::ThreadLocal can't be used for types larger than "
                     "a pointer");
   MOZ_ASSERT(!initialized());
 #ifdef XP_WIN
   key = TlsAlloc();
   inited = key != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES
 #else
-  inited = !pthread_key_create(&key, NULL);
+  inited = !pthread_key_create(&key, nullptr);
 #endif
   return inited;
 }
 
 template<typename T>
 inline T
 ThreadLocal<T>::get() const
 {
--- a/mfbt/Vector.h
+++ b/mfbt/Vector.h
@@ -1045,17 +1045,17 @@ VectorBase<T, N, AP, TV>::popCopy()
 template<typename T, size_t N, class AP, class TV>
 inline T*
 VectorBase<T, N, AP, TV>::extractRawBuffer()
 {
   T* ret;
   if (usingInlineStorage()) {
     ret = reinterpret_cast<T*>(this->malloc_(mLength * sizeof(T)));
     if (!ret)
-        return NULL;
+      return nullptr;
     Impl::copyConstruct(ret, beginNoCheck(), endNoCheck());
     Impl::destroy(beginNoCheck(), endNoCheck());
     /* mBegin, mCapacity are unchanged. */
     mLength = 0;
   } else {
     ret = mBegin;
     mBegin = static_cast<T*>(storage.addr());
     mLength = 0;
@@ -1100,24 +1100,24 @@ VectorBase<T, N, AP, TV>::replaceRawBuff
   mReserved = aLength;
 #endif
 }
 
 template<typename T, size_t N, class AP, class TV>
 inline size_t
 VectorBase<T, N, AP, TV>::sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const
 {
-    return usingInlineStorage() ? 0 : mallocSizeOf(beginNoCheck());
+  return usingInlineStorage() ? 0 : mallocSizeOf(beginNoCheck());
 }
 
 template<typename T, size_t N, class AP, class TV>
 inline size_t
 VectorBase<T, N, AP, TV>::sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const
 {
-    return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf);
+  return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf);
 }
 
 template<typename T, size_t N, class AP, class TV>
 inline void
 VectorBase<T, N, AP, TV>::swap(TV& other)
 {
   MOZ_STATIC_ASSERT(N == 0,
                     "still need to implement this for N != 0");
--- a/mfbt/tests/TestPoisonArea.cpp
+++ b/mfbt/tests/TestPoisonArea.cpp
@@ -74,16 +74,18 @@
  *    *64*-bit processes on Linux - and we don't even run this code for
  *    64-bit processes.
  *
  * 4. VirtualQuery() does not produce any useful information if
  *    applied to kernel memory - in fact, it doesn't write its output
  *    at all.  Thus, it is not used here.
  */
 
+#include "mozilla/NullPtr.h"
+
 // MAP_ANON(YMOUS) is not in any standard, and the C99 PRI* macros are
 // not in C++98.  Add defines as necessary.
 #define __STDC_FORMAT_MACROS
 #define _GNU_SOURCE 1
 #define _DARWIN_C_SOURCE 1
 
 #include <stddef.h>
 
@@ -190,18 +192,18 @@ static const ia64_instr _return_instr =
 // Uses of this function deliberately leak the string.
 static LPSTR
 StrW32Error(DWORD errcode)
 {
   LPSTR errmsg;
   FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
                  FORMAT_MESSAGE_FROM_SYSTEM |
                  FORMAT_MESSAGE_IGNORE_INSERTS,
-                 NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                 (LPSTR) &errmsg, 0, NULL);
+                 nullptr, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                 (LPSTR)&errmsg, 0, nullptr);
 
   // FormatMessage puts an unwanted newline at the end of the string
   size_t n = strlen(errmsg)-1;
   while (errmsg[n] == '\r' || errmsg[n] == '\n') n--;
   errmsg[n+1] = '\0';
   return errmsg;
 }
 #define LastErrMsg() (StrW32Error(GetLastError()))