Browse Source

[2831] use NULL instead of 0; maybe worth discussing, but out of scope of task.

JINMEI Tatuya 12 years ago
parent
commit
f6dae94a7b

+ 4 - 4
src/lib/util/memory_segment_mapped.cc

@@ -89,7 +89,7 @@ struct MemorySegmentMapped::Impl {
 };
 };
 
 
 MemorySegmentMapped::MemorySegmentMapped(const std::string& filename) :
 MemorySegmentMapped::MemorySegmentMapped(const std::string& filename) :
-    impl_(0)
+    impl_(NULL)
 {
 {
     try {
     try {
         impl_ = new Impl(filename, true);
         impl_ = new Impl(filename, true);
@@ -102,7 +102,7 @@ MemorySegmentMapped::MemorySegmentMapped(const std::string& filename) :
 
 
 MemorySegmentMapped::MemorySegmentMapped(const std::string& filename,
 MemorySegmentMapped::MemorySegmentMapped(const std::string& filename,
                                          bool create, size_t initial_size) :
                                          bool create, size_t initial_size) :
-    impl_(0)
+    impl_(NULL)
 {
 {
     try {
     try {
         if (create) {
         if (create) {
@@ -156,7 +156,7 @@ MemorySegmentMapped::deallocate(void* ptr, size_t) {
         isc_throw(InvalidOperation, "allocate attempt on read-only segment");
         isc_throw(InvalidOperation, "allocate attempt on read-only segment");
     }
     }
 
 
-    // the underlying deallocate() would deal with the case where ptr == 0,
+    // the underlying deallocate() would deal with the case where ptr == NULL,
     // but it's an undocumented behavior, so we handle it ourselves for safety.
     // but it's an undocumented behavior, so we handle it ourselves for safety.
     if (!ptr) {
     if (!ptr) {
         return;
         return;
@@ -177,7 +177,7 @@ MemorySegmentMapped::getNamedAddress(const char* name) {
     if (storage) {
     if (storage) {
         return (storage->get());
         return (storage->get());
     }
     }
-    return (0);
+    return (NULL);
 }
 }
 
 
 bool
 bool

+ 9 - 8
src/lib/util/tests/memory_segment_mapped_unittest.cc

@@ -152,7 +152,7 @@ TEST_F(MemorySegmentMappedTest, allocate) {
 
 
     // Now, the allocation should now succeed.
     // Now, the allocation should now succeed.
     void* ptr = segment_->allocate(prev_size + 1);
     void* ptr = segment_->allocate(prev_size + 1);
-    EXPECT_NE(static_cast<void*>(0), ptr);
+    EXPECT_NE(static_cast<void*>(NULL), ptr);
     EXPECT_FALSE(segment_->allMemoryDeallocated());
     EXPECT_FALSE(segment_->allMemoryDeallocated());
 
 
     // Same set of checks, but for a larger size.
     // Same set of checks, but for a larger size.
@@ -162,7 +162,7 @@ TEST_F(MemorySegmentMappedTest, allocate) {
     EXPECT_EQ(prev_size * 16, segment_->getSize());
     EXPECT_EQ(prev_size * 16, segment_->getSize());
     // And allocate() should now succeed.
     // And allocate() should now succeed.
     ptr = segment_->allocate(prev_size * 10);
     ptr = segment_->allocate(prev_size * 10);
-    EXPECT_NE(static_cast<void*>(0), ptr);
+    EXPECT_NE(static_cast<void*>(NULL), ptr);
 
 
     // (we'll left the regions created in the file there; the entire file
     // (we'll left the regions created in the file there; the entire file
     // will be removed at the end of the test)
     // will be removed at the end of the test)
@@ -186,7 +186,7 @@ TEST_F(MemorySegmentMappedTest, DISABLED_allocateHuge) {
 
 
 TEST_F(MemorySegmentMappedTest, badDeallocate) {
 TEST_F(MemorySegmentMappedTest, badDeallocate) {
     void* ptr = segment_->allocate(4);
     void* ptr = segment_->allocate(4);
-    EXPECT_NE(static_cast<void*>(0), ptr);
+    EXPECT_NE(static_cast<void*>(NULL), ptr);
 
 
     segment_->deallocate(ptr, 4); // this is okay
     segment_->deallocate(ptr, 4); // this is okay
     // This is duplicate dealloc; should trigger assertion failure.
     // This is duplicate dealloc; should trigger assertion failure.
@@ -200,7 +200,7 @@ TEST_F(MemorySegmentMappedTest, badDeallocate) {
     // default).
     // default).
     if (!isc::util::unittests::runningOnValgrind()) {
     if (!isc::util::unittests::runningOnValgrind()) {
         ptr = segment_->allocate(4);
         ptr = segment_->allocate(4);
-        EXPECT_NE(static_cast<void*>(0), ptr);
+        EXPECT_NE(static_cast<void*>(NULL), ptr);
         EXPECT_DEATH_IF_SUPPORTED({
         EXPECT_DEATH_IF_SUPPORTED({
                 segment_->deallocate(static_cast<char*>(ptr) + 1, 3);
                 segment_->deallocate(static_cast<char*>(ptr) + 1, 3);
             }, "");
             }, "");
@@ -209,7 +209,7 @@ TEST_F(MemorySegmentMappedTest, badDeallocate) {
 
 
     // Invalid size; this implementation doesn't detect such errors.
     // Invalid size; this implementation doesn't detect such errors.
     ptr = segment_->allocate(4);
     ptr = segment_->allocate(4);
-    EXPECT_NE(static_cast<void*>(0), ptr);
+    EXPECT_NE(static_cast<void*>(NULL), ptr);
     segment_->deallocate(ptr, 8);
     segment_->deallocate(ptr, 8);
     EXPECT_TRUE(segment_->allMemoryDeallocated());
     EXPECT_TRUE(segment_->allMemoryDeallocated());
 }
 }
@@ -237,8 +237,8 @@ TEST_F(MemorySegmentMappedTest, namedAddress) {
     segment_.reset(new MemorySegmentMapped(mapped_file, true, 1024));
     segment_.reset(new MemorySegmentMapped(mapped_file, true, 1024));
     const std::string long_name(1025, 'x'); // definitely larger than segment
     const std::string long_name(1025, 'x'); // definitely larger than segment
     // setNamedAddress should return true, indicating segment has grown.
     // setNamedAddress should return true, indicating segment has grown.
-    EXPECT_TRUE(segment_->setNamedAddress(long_name.c_str(), 0));
-    EXPECT_EQ(static_cast<void*>(0),
+    EXPECT_TRUE(segment_->setNamedAddress(long_name.c_str(), NULL));
+    EXPECT_EQ(static_cast<void*>(NULL),
               segment_->getNamedAddress(long_name.c_str()));
               segment_->getNamedAddress(long_name.c_str()));
 }
 }
 
 
@@ -278,7 +278,8 @@ TEST_F(MemorySegmentMappedTest, violateReadOnly) {
     EXPECT_THROW(MemorySegmentMapped(mapped_file).
     EXPECT_THROW(MemorySegmentMapped(mapped_file).
                  allocate(DEFAULT_INITIAL_SIZE * 2),
                  allocate(DEFAULT_INITIAL_SIZE * 2),
                  isc::InvalidOperation);
                  isc::InvalidOperation);
-    EXPECT_THROW(MemorySegmentMapped(mapped_file).setNamedAddress("test", 0),
+    EXPECT_THROW(MemorySegmentMapped(mapped_file).setNamedAddress("test",
+                                                                  NULL),
                  isc::InvalidOperation);
                  isc::InvalidOperation);
     EXPECT_THROW(MemorySegmentMapped(mapped_file).clearNamedAddress("test"),
     EXPECT_THROW(MemorySegmentMapped(mapped_file).clearNamedAddress("test"),
                  isc::InvalidOperation);
                  isc::InvalidOperation);