Skip to content

Commit

Permalink
Bug 784739 - Switch from NULL to nullptr in mfbt/. r=jwalden
Browse files Browse the repository at this point in the history
  • Loading branch information
poiru committed Jul 25, 2013
1 parent 182b915 commit 0c642c6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 28 deletions.
3 changes: 2 additions & 1 deletion mfbt/GuardObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define mozilla_GuardObjects_h

#include "mozilla/Assertions.h"
#include "mozilla/NullPtr.h"
#include "mozilla/Types.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -73,7 +74,7 @@ class MOZ_EXPORT GuardObjectNotifier
bool* statementDone;

public:
GuardObjectNotifier() : statementDone(NULL) { }
GuardObjectNotifier() : statementDone(nullptr) { }

~GuardObjectNotifier() {
*statementDone = true;
Expand Down
37 changes: 19 additions & 18 deletions mfbt/LinkedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
* }
*
* 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);
* }
* };
*
Expand All @@ -58,6 +58,7 @@

#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/NullPtr.h"

#ifdef __cplusplus

Expand All @@ -70,10 +71,10 @@ 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,
Expand Down Expand Up @@ -121,8 +122,8 @@ class LinkedListElement
}

/*
* 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();
Expand All @@ -132,8 +133,8 @@ class LinkedListElement
}

/*
* 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();
Expand Down Expand Up @@ -206,18 +207,18 @@ class LinkedListElement
{ }

/*
* 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);
}
Expand Down Expand Up @@ -284,7 +285,7 @@ class LinkedList
}

/*
* 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();
Expand All @@ -294,7 +295,7 @@ class LinkedList
}

/*
* 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();
Expand All @@ -305,7 +306,7 @@ class LinkedList

/*
* Get and remove the first element of the list. If the list is empty,
* return NULL.
* return nullptr.
*/
T* popFirst() {
T* ret = sentinel.getNext();
Expand All @@ -316,7 +317,7 @@ class LinkedList

/*
* Get and remove the last element of the list. If the list is empty,
* return NULL.
* return nullptr.
*/
T* popLast() {
T* ret = sentinel.getPrevious();
Expand Down
3 changes: 2 additions & 1 deletion mfbt/RangedPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/NullPtr.h"
#include "mozilla/Util.h"

namespace mozilla {
Expand Down Expand Up @@ -60,7 +61,7 @@ class RangedPtr
#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
}

Expand Down
5 changes: 3 additions & 2 deletions mfbt/Scoped.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

#include "mozilla/Attributes.h"
#include "mozilla/GuardObjects.h"
#include "mozilla/NullPtr.h"

namespace mozilla {

Expand Down Expand Up @@ -195,7 +196,7 @@ 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)
Expand Down Expand Up @@ -258,7 +259,7 @@ 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)
Expand Down
3 changes: 2 additions & 1 deletion mfbt/ThreadLocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ __declspec(dllimport) unsigned long __stdcall TlsAlloc();

#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/NullPtr.h"

namespace mozilla {

Expand Down Expand Up @@ -107,7 +108,7 @@ ThreadLocal<T>::init()
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;
}
Expand Down
6 changes: 3 additions & 3 deletions mfbt/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ VectorBase<T, N, AP, TV>::extractRawBuffer()
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. */
Expand Down Expand Up @@ -1105,14 +1105,14 @@ 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>
Expand Down
6 changes: 4 additions & 2 deletions mfbt/tests/TestPoisonArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
* 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
Expand Down Expand Up @@ -195,8 +197,8 @@ StrW32Error(DWORD errcode)
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;
Expand Down

0 comments on commit 0c642c6

Please sign in to comment.