[Groonga-commit] groonga/grnxx at 1d854f3 [master] Implicitly enable FILE_TEMPORARY if "path" == nullptr.

Back to archive index

susumu.yata null+****@clear*****
Tue Apr 23 13:33:25 JST 2013


susumu.yata	2013-04-23 13:33:25 +0900 (Tue, 23 Apr 2013)

  New Revision: 1d854f338044a73c86622afcafbc6c804a58f864
  https://github.com/groonga/grnxx/commit/1d854f338044a73c86622afcafbc6c804a58f864

  Message:
    Implicitly enable FILE_TEMPORARY if "path" == nullptr.

  Modified files:
    lib/grnxx/storage/file-posix.cpp
    lib/grnxx/storage/file-windows.cpp
    lib/grnxx/storage/file.hpp
    lib/grnxx/storage/view.hpp
    test/test_storage.cpp

  Modified: lib/grnxx/storage/file-posix.cpp (+1 -1)
===================================================================
--- lib/grnxx/storage/file-posix.cpp    2013-04-23 10:47:11 +0900 (b00cf60)
+++ lib/grnxx/storage/file-posix.cpp    2013-04-23 13:33:25 +0900 (bf7ccbf)
@@ -63,7 +63,7 @@ FileImpl *FileImpl::create(const char *path, FileFlags flags) {
     GRNXX_ERROR() << "new grnxx::storage::FileImpl failed";
     return nullptr;
   }
-  if (~flags & FILE_TEMPORARY) {
+  if (path && (~flags & FILE_TEMPORARY)) {
     if (!file->create_persistent_file(path, flags)) {
       return nullptr;
     }

  Modified: lib/grnxx/storage/file-windows.cpp (+1 -1)
===================================================================
--- lib/grnxx/storage/file-windows.cpp    2013-04-23 10:47:11 +0900 (957ab83)
+++ lib/grnxx/storage/file-windows.cpp    2013-04-23 13:33:25 +0900 (01f904b)
@@ -61,7 +61,7 @@ FileImpl *FileImpl::create(const char *path, FileFlags flags) {
     GRNXX_ERROR() << "new grnxx::storage::FileImpl failed";
     return nullptr;
   }
-  if (~flags & FILE_TEMPORARY) {
+  if (path && (~flags & FILE_TEMPORARY)) {
     if (!file->create_persistent_file(path, flags)) {
       return nullptr;
     }

  Modified: lib/grnxx/storage/file.hpp (+5 -5)
===================================================================
--- lib/grnxx/storage/file.hpp    2013-04-23 10:47:11 +0900 (ceeb21a)
+++ lib/grnxx/storage/file.hpp    2013-04-23 13:33:25 +0900 (d788a75)
@@ -35,6 +35,7 @@ constexpr FileFlags FILE_DEFAULT   = FileFlags::define(0x00);
 // Open a file in read-only mode.
 constexpr FileFlags FILE_READ_ONLY = FileFlags::define(0x01);
 // Create a temporary file.
+// This flag is implicitly enabled if "path" == nullptr.
 constexpr FileFlags FILE_TEMPORARY = FileFlags::define(0x02);
 
 StringBuilder &operator<<(StringBuilder &builder, FileFlags flags);
@@ -57,18 +58,17 @@ class File {
   virtual ~File();
 
   // Create a file.
-  // "path" == nullptr is acceptable iff "flags" contains FILE_TEMPORARY.
+  // FILE_TEMPORARY is implicitly enabled if "path" == nullptr.
   // The available flag is FILE_TEMPORARY.
-  static File *create(const char *path = nullptr,
+  static File *create(const char *path,
                       FileFlags flags = FILE_DEFAULT);
   // Open a file.
   // The available flag is FILE_READ_ONLY.
-  static File *open(const char *path = nullptr,
+  static File *open(const char *path,
                     FileFlags flags = FILE_DEFAULT);
   // Open or create a file.
-  // "path" == nullptr is acceptable iff "flags" contains FILE_TEMPORARY.
   // There are no available flags.
-  static File *open_or_create(const char *path = nullptr,
+  static File *open_or_create(const char *path,
                               FileFlags flags = FILE_DEFAULT);
 
   // Return true iff "path" refers to a regular file.

  Modified: lib/grnxx/storage/view.hpp (+2 -2)
===================================================================
--- lib/grnxx/storage/view.hpp    2013-04-23 10:47:11 +0900 (666a45e)
+++ lib/grnxx/storage/view.hpp    2013-04-23 13:33:25 +0900 (04e5e76)
@@ -33,12 +33,12 @@ typedef FlagsImpl<View> ViewFlags;
 // Use the default settings.
 constexpr ViewFlags VIEW_DEFAULT   = ViewFlags::define(0x00);
 // Create an anonymous memory mapping.
-// This flag is automatically enabled if "file" == nullptr.
+// This flag is implicitly enabled if "file" == nullptr.
 constexpr ViewFlags VIEW_ANONYMOUS = ViewFlags::define(0x01);
 // Use huge pages if available, or use regular pages.
 constexpr ViewFlags VIEW_HUGE_TLB  = ViewFlags::define(0x02);
 // Create a read-only memory mapping.
-// This flag is automatically enabled if "file" is read-only.
+// This flag is implicitly enabled if "file" is read-only.
 constexpr ViewFlags VIEW_READ_ONLY = ViewFlags::define(0x04);
 
 StringBuilder &operator<<(StringBuilder &builder, ViewFlags flags);

  Modified: test/test_storage.cpp (+9 -15)
===================================================================
--- test/test_storage.cpp    2013-04-23 10:47:11 +0900 (5e60ec9)
+++ test/test_storage.cpp    2013-04-23 13:33:25 +0900 (a73ee89)
@@ -79,11 +79,9 @@ void test_file_create() {
                                           grnxx::storage::FILE_TEMPORARY));
   assert(file);
 
-  file.reset(grnxx::storage::File::create(nullptr,
-                                          grnxx::storage::FILE_TEMPORARY));
+  file.reset(grnxx::storage::File::create(nullptr));
   assert(file);
-  file.reset(grnxx::storage::File::create(nullptr,
-                                          grnxx::storage::FILE_TEMPORARY));
+  file.reset(grnxx::storage::File::create(nullptr));
   assert(file);
 
   grnxx::storage::File::unlink(FILE_PATH);
@@ -172,7 +170,7 @@ void test_file_lock_and_unlock() {
 
 void test_file_sync() {
   std::unique_ptr<grnxx::storage::File> file(
-      grnxx::storage::File::create(nullptr, grnxx::storage::FILE_TEMPORARY));
+      grnxx::storage::File::create(nullptr));
   assert(file);
 
   assert(file->sync());
@@ -180,7 +178,7 @@ void test_file_sync() {
 
 void test_file_resize_and_size() {
   std::unique_ptr<grnxx::storage::File> file(
-      grnxx::storage::File::create(nullptr, grnxx::storage::FILE_TEMPORARY));
+      grnxx::storage::File::create(nullptr));
   assert(file);
 
   assert(file->size() == 0);
@@ -230,7 +228,7 @@ void test_file_flags() {
 
 void test_file_handle() {
   std::unique_ptr<grnxx::storage::File> file(
-      grnxx::storage::File::create(nullptr, grnxx::storage::FILE_TEMPORARY));
+      grnxx::storage::File::create(nullptr));
   assert(file);
 
   assert(file->handle());
@@ -240,8 +238,7 @@ void test_view_create() {
   std::unique_ptr<grnxx::storage::File> file;
   std::unique_ptr<grnxx::storage::View> view;
 
-  file.reset(grnxx::storage::File::create(nullptr,
-                                          grnxx::storage::FILE_TEMPORARY));
+  file.reset(grnxx::storage::File::create(nullptr));
   assert(file);
   view.reset(grnxx::storage::View::create(file.get()));
   assert(!view);
@@ -284,8 +281,7 @@ void test_view_sync() {
   std::unique_ptr<grnxx::storage::File> file;
   std::unique_ptr<grnxx::storage::View> view;
 
-  file.reset(grnxx::storage::File::create(nullptr,
-                                          grnxx::storage::FILE_TEMPORARY));
+  file.reset(grnxx::storage::File::create(nullptr));
   assert(file);
   assert(file->resize(1 << 20));
 
@@ -337,8 +333,7 @@ void test_view_address() {
   std::unique_ptr<grnxx::storage::File> file;
   std::unique_ptr<grnxx::storage::View> view;
 
-  file.reset(grnxx::storage::File::create(nullptr,
-                                          grnxx::storage::FILE_TEMPORARY));
+  file.reset(grnxx::storage::File::create(nullptr));
   assert(file);
   assert(file->resize(10));
 
@@ -354,8 +349,7 @@ void test_view_size() {
   std::unique_ptr<grnxx::storage::File> file;
   std::unique_ptr<grnxx::storage::View> view;
 
-  file.reset(grnxx::storage::File::create(nullptr,
-                                          grnxx::storage::FILE_TEMPORARY));
+  file.reset(grnxx::storage::File::create(nullptr));
   assert(file);
   assert(file->resize(1 << 20));
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index