LoadLibraryPermanently no longer throws an exception, so this code doesn't have

to catch it.  Other minor cleanups.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29050 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-07-07 17:14:04 +00:00
parent cc2fa54dfa
commit 17aa9d3f53

View File

@ -16,42 +16,28 @@
#include "llvm/System/DynamicLibrary.h" #include "llvm/System/DynamicLibrary.h"
#include <iostream> #include <iostream>
#include <vector> #include <vector>
using namespace llvm; using namespace llvm;
static std::vector<std::string>* plugins; static std::vector<std::string> *Plugins;
void PluginLoader::operator=(const std::string &Filename) { void PluginLoader::operator=(const std::string &Filename) {
std::string ErrorMessage; if (!Plugins)
Plugins = new std::vector<std::string>();
if (!plugins) std::string Error;
plugins = new std::vector<std::string>(); if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
std::cerr << "Error opening '" << Filename << "': " << Error
try {
sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str());
plugins->push_back(Filename);
} catch (const std::string& errmsg) {
if (errmsg.empty()) {
ErrorMessage = "Unknown";
} else {
ErrorMessage = errmsg;
}
}
if (!ErrorMessage.empty())
std::cerr << "Error opening '" << Filename << "': " << ErrorMessage
<< "\n -load request ignored.\n"; << "\n -load request ignored.\n";
} else {
Plugins->push_back(Filename);
}
} }
unsigned PluginLoader::getNumPlugins() unsigned PluginLoader::getNumPlugins() {
{ return Plugins ? Plugins->size() : 0;
if(plugins)
return plugins->size();
else
return 0;
} }
std::string& PluginLoader::getPlugin(unsigned num) std::string &PluginLoader::getPlugin(unsigned num) {
{ assert(Plugins && num < Plugins->size() && "Asking for an out of bounds plugin");
assert(plugins && num < plugins->size() && "Asking for an out of bounds plugin"); return (*Plugins)[num];
return (*plugins)[num];
} }