Browse Source

[2831] added note about too small initial_size, and added a test for the case.

JINMEI Tatuya 12 years ago
parent
commit
bafbce54b6

+ 6 - 0
src/lib/util/memory_segment_mapped.h

@@ -84,6 +84,12 @@ public:
     /// these conditions is not met, \c MemorySegmentOpenError exception
     /// will be thrown.
     ///
+    /// When initial_size is specified but is too small (including a value of
+    /// 0), the underlying Boost library will reject it, and this constructor
+    /// throws \c MemorySegmentOpenError exception.  The Boost documentation
+    /// does not specify how large it should be, but the default
+    /// \c INITIAL_SIZE should be sufficiently large in practice.
+    ///
     /// \throw MemorySegmentOpenError see the description.
     ///
     /// \param filename The file name to be mapped to memory.

+ 6 - 0
src/lib/util/tests/memory_segment_mapped_unittest.cc

@@ -128,6 +128,12 @@ TEST_F(MemorySegmentMappedTest, openFail) {
                                      false),
                  MemorySegmentOpenError);
 
+    // creating with a very small size fails (for sure about 0, and other
+    // small values should also make it fail, but it's internal restriction
+    // of Boost and cannot be predictable).
+    EXPECT_THROW(MemorySegmentMapped(mapped_file, true, 0),
+                 MemorySegmentOpenError);
+
     // Close the existing segment, break its file with bogus data, and
     // try to reopen.  It should fail with exception whether in the
     // read-only or read-write, or "create if not exist" mode.