[llvm-commits] CVS: llvm/lib/System/Win32/DynamicLibrary.inc MappedFile.inc Memory.inc Path.inc Signals.inc Win32.h

Reid Spencer reid at x10sys.com
Fri Aug 25 14:37:34 PDT 2006



Changes in directory llvm/lib/System/Win32:

DynamicLibrary.inc updated: 1.16 -> 1.17
MappedFile.inc updated: 1.6 -> 1.7
Memory.inc updated: 1.8 -> 1.9
Path.inc updated: 1.56 -> 1.57
Signals.inc updated: 1.21 -> 1.22
Win32.h updated: 1.8 -> 1.9
---
Log message:

For PR797: http://llvm.org/PR797 :
Make the Win32 code exception free (untested/uncompiled) which forced some
interface changes which had ripple effect. This should be the last of 797.


---
Diffs of the changes:  (+51 -67)

 DynamicLibrary.inc |   12 +-----------
 MappedFile.inc     |   29 ++++++++++++++++++-----------
 Memory.inc         |    4 ++--
 Path.inc           |   22 +++++++++++-----------
 Signals.inc        |   27 +++++++++++++++++++--------
 Win32.h            |   24 ------------------------
 6 files changed, 51 insertions(+), 67 deletions(-)


Index: llvm/lib/System/Win32/DynamicLibrary.inc
diff -u llvm/lib/System/Win32/DynamicLibrary.inc:1.16 llvm/lib/System/Win32/DynamicLibrary.inc:1.17
--- llvm/lib/System/Win32/DynamicLibrary.inc:1.16	Fri Jul  7 12:12:36 2006
+++ llvm/lib/System/Win32/DynamicLibrary.inc	Fri Aug 25 16:37:17 2006
@@ -65,16 +65,6 @@
   OpenedHandles.push_back((HMODULE)handle);
 }
 
-DynamicLibrary::DynamicLibrary(const char*filename) : handle(0) {
-  HMODULE a_handle = LoadLibrary(filename);
-
-  if (a_handle == 0)
-    ThrowError(std::string(filename) + ": Can't open : ");
-
-  handle = a_handle;
-  OpenedHandles.push_back(a_handle);
-}
-
 DynamicLibrary::~DynamicLibrary() {
   if (handle == 0)
     return;
@@ -100,7 +90,7 @@
     HMODULE a_handle = LoadLibrary(filename);
 
     if (a_handle == 0)
-      return GetError(std::string(filename) + ": Can't open : ", ErrMsg);
+      return MakeErrMsg(ErrMsg, std::string(filename) + ": Can't open : ");
 
     OpenedHandles.push_back(a_handle);
   } else {


Index: llvm/lib/System/Win32/MappedFile.inc
diff -u llvm/lib/System/Win32/MappedFile.inc:1.6 llvm/lib/System/Win32/MappedFile.inc:1.7
--- llvm/lib/System/Win32/MappedFile.inc:1.6	Thu May  5 17:33:09 2005
+++ llvm/lib/System/Win32/MappedFile.inc	Fri Aug 25 16:37:17 2006
@@ -27,7 +27,7 @@
   size_t size;
 };
 
-void MappedFile::initialize() {
+bool MappedFile::initialize(std::string* ErrMsg) {
   assert(!info_);
   info_ = new MappedFileInfo;
   info_->hFile = INVALID_HANDLE_VALUE;
@@ -42,7 +42,8 @@
   if (info_->hFile == INVALID_HANDLE_VALUE) {
     delete info_;
     info_ = NULL;
-    ThrowError(std::string("Can't open file: ") + path_.toString());
+    return MakeErrMsg(ErrMsg,
+      std::string("Can't open file: ") + path_.toString());
   }
 
   LARGE_INTEGER size;
@@ -51,7 +52,8 @@
     CloseHandle(info_->hFile);
     delete info_;
     info_ = NULL;
-    ThrowError(std::string("Can't get size of file: ") + path_.toString());
+    return MakeErrMsg(ErrMsg, 
+      std::string("Can't get size of file: ") + path_.toString());
   }
 }
 
@@ -75,7 +77,7 @@
   }
 }
 
-void* MappedFile::map() {
+void* MappedFile::map(std::string* ErrMsg) {
   if (!isMapped()) {
     DWORD prot = PAGE_READONLY;
     if (options_ & EXEC_ACCESS)
@@ -83,15 +85,18 @@
     else if (options_ & WRITE_ACCESS)
       prot = PAGE_READWRITE;
     info_->hMapping = CreateFileMapping(info_->hFile, NULL, prot, 0, 0, NULL);
-    if (info_->hMapping == NULL)
-      ThrowError(std::string("Can't map file: ") + path_.toString());
+    if (info_->hMapping == NULL) {
+      MakeErrMsg(ErrMsg, std::string("Can't map file: ") + path_.toString());
+      return 0;
+    }
 
     prot = (options_ & WRITE_ACCESS) ? FILE_MAP_WRITE : FILE_MAP_READ;
     base_ = MapViewOfFileEx(info_->hMapping, prot, 0, 0, 0, NULL);
     if (base_ == NULL) {
       CloseHandle(info_->hMapping);
       info_->hMapping = NULL;
-      ThrowError(std::string("Can't map file: ") + path_.toString());
+      MakeErrMsg(ErrMsg, std::string("Can't map file: ") + path_.toString());
+      return 0;
     }
   }
   return base_;
@@ -102,7 +107,7 @@
   return info_->size;
 }
 
-void MappedFile::size(size_t new_size) {
+bool MappedFile::size(size_t new_size, std::string* ErrMsg) {
   assert(info_ && "MappedFile not initialized");
 
   // Take the mapping out of memory.
@@ -117,14 +122,16 @@
     LARGE_INTEGER eof;
     eof.QuadPart = new_size;
     if (!SetFilePointerEx(info_->hFile, eof, NULL, FILE_BEGIN))
-      ThrowError(std::string("Can't set end of file: ") + path_.toString());
+      return MakeErrMsg(ErrMsg, 
+        std::string("Can't set end of file: ") + path_.toString());
     if (!SetEndOfFile(info_->hFile))
-      ThrowError(std::string("Can't set end of file: ") + path_.toString());
+      return MakeErrMsg(ErrMsg, 
+        std::string("Can't set end of file: ") + path_.toString());
     info_->size = new_size;
   }
 
   // Remap the file.
-  map();
+  return map(ErrMsg);
 }
 
 }


Index: llvm/lib/System/Win32/Memory.inc
diff -u llvm/lib/System/Win32/Memory.inc:1.8 llvm/lib/System/Win32/Memory.inc:1.9
--- llvm/lib/System/Win32/Memory.inc:1.8	Wed Jul 26 15:37:11 2006
+++ llvm/lib/System/Win32/Memory.inc	Fri Aug 25 16:37:17 2006
@@ -36,7 +36,7 @@
   void *pa = VirtualAlloc(NULL, NumPages*pageSize, MEM_COMMIT,
                   PAGE_EXECUTE_READWRITE);
   if (pa == NULL) {
-    GetError("Can't allocate RWX Memory: ", ErrMsg);
+    MakeErrMsg(ErrMsg, "Can't allocate RWX Memory: ");
     return MemoryBlock();
   }
 
@@ -49,7 +49,7 @@
 bool Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) {
   if (M.Address == 0 || M.Size == 0) return false;
   if (!VirtualFree(M.Address, 0, MEM_RELEASE))
-    return GetError("Can't release RWX Memory: ", ErrMsg);
+    return MakeErrMsg(ErrMsg, "Can't release RWX Memory: ");
   return false;
 }
 


Index: llvm/lib/System/Win32/Path.inc
diff -u llvm/lib/System/Win32/Path.inc:1.56 llvm/lib/System/Win32/Path.inc:1.57
--- llvm/lib/System/Win32/Path.inc:1.56	Thu Aug 24 13:58:37 2006
+++ llvm/lib/System/Win32/Path.inc	Fri Aug 25 16:37:17 2006
@@ -292,8 +292,8 @@
 Path::getFileStatus(FileStatus &info, std::string *ErrStr) const {
   WIN32_FILE_ATTRIBUTE_DATA fi;
   if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi))
-    return GetError("getStatusInfo():" + std::string(path) +
-                    ": Can't get status: ", ErrStr);
+    return MakeErrMsg(ErrStr, "getStatusInfo():" + std::string(path) +
+                    ": Can't get status: ");
 
   info.fileSize = fi.nFileSizeHigh;
   info.fileSize <<= sizeof(fi.nFileSizeHigh)*8;
@@ -547,7 +547,7 @@
     // attribute first.
     if (attr & FILE_ATTRIBUTE_READONLY) {
       if (!SetFileAttributes(path.c_str(), attr & ~FILE_ATTRIBUTE_READONLY))
-        return GetError(path + ": Can't destroy file: ", ErrStr);
+        return MakeErrMsg(ErrStr, path + ": Can't destroy file: ");
     }
 
     if (!DeleteFile(path.c_str()))
@@ -593,7 +593,7 @@
         FindClose(h);
         if (err != ERROR_NO_MORE_FILES) {
           SetLastError(err);
-          return GetError(path + ": Can't read directory: ", ErrStr);
+          return MakeErrMsg(ErrStr, path + ": Can't read directory: ");
         }
 
         for (std::vector<Path>::iterator I = list.begin(); I != list.end();
@@ -603,14 +603,14 @@
         }
       } else {
         if (GetLastError() != ERROR_FILE_NOT_FOUND)
-          return GetError(path + ": Can't read directory: ", ErrStr);
+          return MakeErrMsg(ErrStr, path + ": Can't read directory: ");
       }
     }
 
     pathname[lastchar] = 0;
     if (!RemoveDirectory(pathname))
-      return GetError(std::string(pathname) + ": Can't destroy directory: ",
-                      ErrStr);
+      return MakeErrMsg(ErrStr, 
+        std::string(pathname) + ": Can't destroy directory: ");
     return false;
   } 
   // It appears the path doesn't exist.
@@ -671,7 +671,7 @@
     DWORD err = GetLastError();
     CloseHandle(h);
     SetLastError(err);
-    return GetError(path + ": GetFileInformationByHandle: ", ErrStr);
+    return MakeErrMsg(ErrStr, path + ": GetFileInformationByHandle: ");
   }
 
   FILETIME ft;
@@ -681,7 +681,7 @@
   CloseHandle(h);
   if (!ret) {
     SetLastError(err);
-    return GetError(path + ": SetFileTime: ", ErrStr);
+    return MakeErrMsg(path + ": SetFileTime: ");
   }
 
   // Best we can do with Unix permission bits is to interpret the owner
@@ -690,13 +690,13 @@
     if (bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
       if (!SetFileAttributes(path.c_str(),
               bhfi.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY))
-        return GetError(path + ": SetFileAttributes: ", ErrStr);
+        return MakeErrMsg(ErrStr, path + ": SetFileAttributes: ");
     }
   } else {
     if (!(bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
       if (!SetFileAttributes(path.c_str(),
               bhfi.dwFileAttributes | FILE_ATTRIBUTE_READONLY))
-        return GetError(path + ": SetFileAttributes: ", ErrStr);
+        return MakeErrMsg(ErrStr, path + ": SetFileAttributes: ");
     }
   }
 


Index: llvm/lib/System/Win32/Signals.inc
diff -u llvm/lib/System/Win32/Signals.inc:1.21 llvm/lib/System/Win32/Signals.inc:1.22
--- llvm/lib/System/Win32/Signals.inc:1.21	Tue Aug  1 12:59:14 2006
+++ llvm/lib/System/Win32/Signals.inc	Fri Aug 25 16:37:17 2006
@@ -80,11 +80,14 @@
 }
 
 // RemoveFileOnSignal - The public API
-void sys::RemoveFileOnSignal(const sys::Path &Filename) {
+bool sys::RemoveFileOnSignal(const sys::Path &Filename, std::string* ErrMsg) {
   RegisterHandler();
 
-  if (CleanupExecuted)
-    throw std::string("Process terminating -- cannot register for removal");
+  if (CleanupExecuted) {
+    if (ErrMsg)
+      *ErrMsg = "Process terminating -- cannot register for removal";
+    return true;
+  }
 
   if (FilesToRemove == NULL)
     FilesToRemove = new std::vector<sys::Path>;
@@ -92,25 +95,33 @@
   FilesToRemove->push_back(Filename);
 
   LeaveCriticalSection(&CriticalSection);
+  return false;
 }
 
 // RemoveDirectoryOnSignal - The public API
-void sys::RemoveDirectoryOnSignal(const sys::Path& path) {
+bool sys::RemoveDirectoryOnSignal(const sys::Path& path, std::string* ErrMsg) {
   // Not a directory?
   sys::FileStatus Status;
-  if (path.getFileStatus(Status) || !Status.isDir)
-    return;
+  if (path.getFileStatus(Status) || !Status.isDir) {
+    if (ErrMsg)
+      *ErrMsg = path.toString() + " is not a directory";
+    return true;
+  }
 
   RegisterHandler();
 
-  if (CleanupExecuted)
-    throw std::string("Process terminating -- cannot register for removal");
+  if (CleanupExecuted) {
+    if (ErrMsg)
+      *ErrMsg = "Process terminating -- cannot register for removal";
+    return true;
+  }
 
   if (DirectoriesToRemove == NULL)
     DirectoriesToRemove = new std::vector<sys::Path>;
   DirectoriesToRemove->push_back(path);
 
   LeaveCriticalSection(&CriticalSection);
+  return false;
 }
 
 /// PrintStackTraceOnErrorSignal - When an error signal (such as SIBABRT or


Index: llvm/lib/System/Win32/Win32.h
diff -u llvm/lib/System/Win32/Win32.h:1.8 llvm/lib/System/Win32/Win32.h:1.9
--- llvm/lib/System/Win32/Win32.h:1.8	Wed Aug 23 02:30:48 2006
+++ llvm/lib/System/Win32/Win32.h	Fri Aug 25 16:37:17 2006
@@ -24,26 +24,6 @@
 #include <cassert>
 #include <string>
 
-inline bool GetError(const std::string &Prefix, std::string *Dest) {
-  if (Dest == 0) return true;
-  char *buffer = NULL;
-  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
-      NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
-  *Dest = Prefix + buffer;
-  LocalFree(buffer);
-  return true;
-}
-
-inline void ThrowError(const std::string& msg) {
-  char *buffer = NULL;
-  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
-      NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
-  std::string s(msg);
-  s += buffer;
-  LocalFree(buffer);
-  throw s;
-}
-
 inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
   if (!ErrMsg)
     return true;
@@ -55,10 +35,6 @@
   return true;
 }
 
-inline void ThrowErrno(const std::string& prefix) {
-  ThrowError(prefix + ": " + strerror(errno));
-}
-
 inline void MakeErrnoMsg(std::string* ErrMsg, const std::string & prefix) {
   MakeErrorMsg(prefix + ": " + strerror(errno));
 }






More information about the llvm-commits mailing list