Change LoadLibraryPermanently to not throw an exception.
authorChris Lattner <sabre@nondot.org>
Fri, 7 Jul 2006 17:12:36 +0000 (17:12 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 7 Jul 2006 17:12:36 +0000 (17:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29048 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/System/DynamicLibrary.h
lib/System/DynamicLibrary.cpp
lib/System/Win32/DynamicLibrary.inc

index f90126c7360bdcc096a68c9c5ae088cfbd83c558..e053daf4405623df32b317fb5f1f532c6bb88ee3 100644 (file)
@@ -65,10 +65,11 @@ namespace sys {
     public:
       /// This function allows a library to be loaded without instantiating a
       /// DynamicLibrary object. Consequently, it is marked as being permanent
-      /// and will only be unloaded when the program terminates.
-      /// @throws std::string on error.
+      /// and will only be unloaded when the program terminates.  This returns
+      /// false on success or returns true and fills in *ErrMsg on failure.
       /// @brief Open a dynamic library permanently.
-      static void LoadLibraryPermanently(const char* filename);
+      static bool LoadLibraryPermanently(const char* filename,
+                                         std::string *ErrMsg = 0);
 
       /// This function will search through all previously loaded dynamic
       /// libraries for the symbol \p symbolName. If it is found, the addressof
index 9bec68e5a954e5291832a858f228a6c0fc023d69..435513d4ff1edd71163d46fca7d9a6954e74488a 100644 (file)
@@ -18,7 +18,8 @@
 // Collection of symbol name/value pairs to be searched prior to any libraries.
 static std::map<std::string, void *> g_symbols;
 
-void llvm::sys::DynamicLibrary::AddSymbol(const char* symbolName, void *symbolValue) {
+void llvm::sys::DynamicLibrary::AddSymbol(const char* symbolName,
+                                          void *symbolValue) {
   g_symbols[symbolName] = symbolValue;
 }
 
@@ -99,20 +100,25 @@ DynamicLibrary::~DynamicLibrary() {
   }
 }
 
-void DynamicLibrary::LoadLibraryPermanently(const char* filename) {
+bool DynamicLibrary::LoadLibraryPermanently(const char *Filename,
+                                            std::string *ErrMsg) {
   check_ltdl_initialization();
-  lt_dlhandle a_handle = lt_dlopen(filename);
+  lt_dlhandle a_handle = lt_dlopen(Filename);
 
   if (a_handle == 0)
-    a_handle = lt_dlopenext(filename);
+    a_handle = lt_dlopenext(Filename);
 
-  if (a_handle == 0)
-    throw std::string("Can't open :") +
-          (filename ? filename : "<current process>") + ": " + lt_dlerror();
+  if (a_handle == 0) {
+    if (ErrMsg)
+      *ErrMsg = std::string("Can't open :") +
+          (Filename ? Filename : "<current process>") + ": " + lt_dlerror();
+    return true;
+  }
 
   lt_dlmakeresident(a_handle);
 
   OpenedHandles.push_back(a_handle);
+  return false;
 }
 
 void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
index d214ba0e727fa97216b02784bc3e35d65e2aca10..287a4c009e688b6109458bcdaa593a8c16b57a96 100644 (file)
@@ -94,12 +94,13 @@ DynamicLibrary::~DynamicLibrary() {
   }
 }
 
-void DynamicLibrary::LoadLibraryPermanently(const char* filename) {
+bool DynamicLibrary::LoadLibraryPermanently(const char *filename,
+                                            std::string *ErrMsg) {
   if (filename) {
     HMODULE a_handle = LoadLibrary(filename);
 
     if (a_handle == 0)
-      ThrowError(std::string(filename) + ": Can't open : ");
+      return GetError(std::string(filename) + ": Can't open : ", ErrMsg);
 
     OpenedHandles.push_back(a_handle);
   } else {
@@ -110,6 +111,7 @@ void DynamicLibrary::LoadLibraryPermanently(const char* filename) {
 
   // Because we don't remember the handle, we will never free it; hence,
   // it is loaded permanently.
+  return false;
 }
 
 void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {