summaryrefslogtreecommitdiffstats
path: root/lib/System
diff options
context:
space:
mode:
Diffstat (limited to 'lib/System')
-rw-r--r--lib/System/DynamicLibrary.cpp52
-rw-r--r--lib/System/Path.cpp21
-rw-r--r--lib/System/Unix/Path.inc70
-rw-r--r--lib/System/Unix/Process.inc2
-rw-r--r--lib/System/Win32/Path.inc32
5 files changed, 89 insertions, 88 deletions
diff --git a/lib/System/DynamicLibrary.cpp b/lib/System/DynamicLibrary.cpp
index 7eb9f5f..63baa6d 100644
--- a/lib/System/DynamicLibrary.cpp
+++ b/lib/System/DynamicLibrary.cpp
@@ -69,29 +69,7 @@ bool DynamicLibrary::LoadLibraryPermanently(const char *Filename,
return false;
}
-void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
- // First check symbols added via AddSymbol().
- if (ExplicitSymbols) {
- std::map<std::string, void *>::iterator I =
- ExplicitSymbols->find(symbolName);
- std::map<std::string, void *>::iterator E = ExplicitSymbols->end();
-
- if (I != E)
- return I->second;
- }
-
- // Now search the libraries.
- if (OpenedHandles) {
- for (std::vector<void *>::iterator I = OpenedHandles->begin(),
- E = OpenedHandles->end(); I != E; ++I) {
- //lt_ptr ptr = lt_dlsym(*I, symbolName);
- void *ptr = dlsym(*I, symbolName);
- if (ptr) {
- return ptr;
- }
- }
- }
-
+static void *SearchForAddressOfSpecialSymbol(const char* symbolName) {
#define EXPLICIT_SYMBOL(SYM) \
extern void *SYM; if (!strcmp(symbolName, #SYM)) return &SYM
@@ -128,6 +106,34 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
#endif
#undef EXPLICIT_SYMBOL
+ return 0;
+}
+
+void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
+ // First check symbols added via AddSymbol().
+ if (ExplicitSymbols) {
+ std::map<std::string, void *>::iterator I =
+ ExplicitSymbols->find(symbolName);
+ std::map<std::string, void *>::iterator E = ExplicitSymbols->end();
+
+ if (I != E)
+ return I->second;
+ }
+
+ // Now search the libraries.
+ if (OpenedHandles) {
+ for (std::vector<void *>::iterator I = OpenedHandles->begin(),
+ E = OpenedHandles->end(); I != E; ++I) {
+ //lt_ptr ptr = lt_dlsym(*I, symbolName);
+ void *ptr = dlsym(*I, symbolName);
+ if (ptr) {
+ return ptr;
+ }
+ }
+ }
+
+ if (void *Result = SearchForAddressOfSpecialSymbol(symbolName))
+ return Result;
// This macro returns the address of a well-known, explicit symbol
#define EXPLICIT_SYMBOL(SYM) \
diff --git a/lib/System/Path.cpp b/lib/System/Path.cpp
index 8e1fa53..6844530 100644
--- a/lib/System/Path.cpp
+++ b/lib/System/Path.cpp
@@ -176,7 +176,7 @@ Path::FindLibrary(std::string& name) {
return sys::Path();
}
-std::string Path::GetDLLSuffix() {
+StringRef Path::GetDLLSuffix() {
return LTDL_SHLIB_EXT;
}
@@ -191,7 +191,7 @@ Path::isBitcodeFile() const {
return FT == Bitcode_FileType;
}
-bool Path::hasMagicNumber(const std::string &Magic) const {
+bool Path::hasMagicNumber(StringRef Magic) const {
std::string actualMagic;
if (getMagicNumber(actualMagic, static_cast<unsigned>(Magic.size())))
return Magic == actualMagic;
@@ -217,8 +217,9 @@ static void getPathList(const char*path, std::vector<Path>& Paths) {
Paths.push_back(tmpPath);
}
-static std::string getDirnameCharSep(const std::string& path, char Sep) {
-
+static StringRef getDirnameCharSep(StringRef path, const char *Sep) {
+ assert(Sep[0] != '\0' && Sep[1] == '\0' &&
+ "Sep must be a 1-character string literal.");
if (path.empty())
return ".";
@@ -227,31 +228,31 @@ static std::string getDirnameCharSep(const std::string& path, char Sep) {
signed pos = static_cast<signed>(path.size()) - 1;
- while (pos >= 0 && path[pos] == Sep)
+ while (pos >= 0 && path[pos] == Sep[0])
--pos;
if (pos < 0)
- return path[0] == Sep ? std::string(1, Sep) : std::string(".");
+ return path[0] == Sep[0] ? Sep : ".";
// Any slashes left?
signed i = 0;
- while (i < pos && path[i] != Sep)
+ while (i < pos && path[i] != Sep[0])
++i;
if (i == pos) // No slashes? Return "."
return ".";
// There is at least one slash left. Remove all trailing non-slashes.
- while (pos >= 0 && path[pos] != Sep)
+ while (pos >= 0 && path[pos] != Sep[0])
--pos;
// Remove any trailing slashes.
- while (pos >= 0 && path[pos] == Sep)
+ while (pos >= 0 && path[pos] == Sep[0])
--pos;
if (pos < 0)
- return path[0] == Sep ? std::string(1, Sep) : std::string(".");
+ return path[0] == Sep[0] ? Sep : ".";
return path.substr(0, pos+1);
}
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index 33b26f7..a99720c 100644
--- a/lib/System/Unix/Path.inc
+++ b/lib/System/Unix/Path.inc
@@ -16,7 +16,6 @@
//=== is guaranteed to work on *all* UNIX variants.
//===----------------------------------------------------------------------===//
-#include "llvm/ADT/SmallVector.h"
#include "Unix.h"
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
@@ -79,15 +78,15 @@ using namespace sys;
const char sys::PathSeparator = ':';
-Path::Path(const std::string& p)
+Path::Path(StringRef p)
: path(p) {}
Path::Path(const char *StrStart, unsigned StrLen)
: path(StrStart, StrLen) {}
Path&
-Path::operator=(const std::string &that) {
- path = that;
+Path::operator=(StringRef that) {
+ path.assign(that.data(), that.size());
return *this;
}
@@ -378,11 +377,11 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) {
}
-std::string Path::getDirname() const {
- return getDirnameCharSep(path, '/');
+StringRef Path::getDirname() const {
+ return getDirnameCharSep(path, "/");
}
-std::string
+StringRef
Path::getBasename() const {
// Find the last slash
std::string::size_type slash = path.rfind('/');
@@ -393,12 +392,12 @@ Path::getBasename() const {
std::string::size_type dot = path.rfind('.');
if (dot == std::string::npos || dot < slash)
- return path.substr(slash);
+ return StringRef(path).substr(slash);
else
- return path.substr(slash, dot - slash);
+ return StringRef(path).substr(slash, dot - slash);
}
-std::string
+StringRef
Path::getSuffix() const {
// Find the last slash
std::string::size_type slash = path.rfind('/');
@@ -409,26 +408,24 @@ Path::getSuffix() const {
std::string::size_type dot = path.rfind('.');
if (dot == std::string::npos || dot < slash)
- return std::string();
+ return StringRef("");
else
- return path.substr(dot + 1);
+ return StringRef(path).substr(dot + 1);
}
-bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
+bool Path::getMagicNumber(std::string &Magic, unsigned len) const {
assert(len < 1024 && "Request for magic string too long");
- SmallVector<char, 128> Buf;
- Buf.resize(1 + len);
- char* buf = Buf.data();
+ char Buf[1025];
int fd = ::open(path.c_str(), O_RDONLY);
if (fd < 0)
return false;
- ssize_t bytes_read = ::read(fd, buf, len);
+ ssize_t bytes_read = ::read(fd, Buf, len);
::close(fd);
if (ssize_t(len) != bytes_read) {
Magic.clear();
return false;
}
- Magic.assign(buf,len);
+ Magic.assign(Buf, len);
return true;
}
@@ -481,7 +478,7 @@ Path::canExecute() const {
return true;
}
-std::string
+StringRef
Path::getLast() const {
// Find the last slash
size_t pos = path.rfind('/');
@@ -495,12 +492,12 @@ Path::getLast() const {
// Find the second to last slash
size_t pos2 = path.rfind('/', pos-1);
if (pos2 == std::string::npos)
- return path.substr(0,pos);
+ return StringRef(path).substr(0,pos);
else
- return path.substr(pos2+1,pos-pos2-1);
+ return StringRef(path).substr(pos2+1,pos-pos2-1);
}
// Return everything after the last slash
- return path.substr(pos+1);
+ return StringRef(path).substr(pos+1);
}
const FileStatus *
@@ -592,7 +589,7 @@ Path::getDirectoryContents(std::set<Path>& result, std::string* ErrMsg) const {
}
bool
-Path::set(const std::string& a_path) {
+Path::set(StringRef a_path) {
if (a_path.empty())
return false;
std::string save(path);
@@ -605,7 +602,7 @@ Path::set(const std::string& a_path) {
}
bool
-Path::appendComponent(const std::string& name) {
+Path::appendComponent(StringRef name) {
if (name.empty())
return false;
std::string save(path);
@@ -637,7 +634,7 @@ Path::eraseComponent() {
}
bool
-Path::appendSuffix(const std::string& suffix) {
+Path::appendSuffix(StringRef suffix) {
std::string save(path);
path.append(".");
path.append(suffix);
@@ -861,18 +858,15 @@ Path::makeUnique(bool reuse_current, std::string* ErrMsg) {
// Append an XXXXXX pattern to the end of the file for use with mkstemp,
// mktemp or our own implementation.
- SmallVector<char, 128> Buf;
- Buf.resize(path.size()+8);
- char *FNBuffer = Buf.data();
- path.copy(FNBuffer,path.size());
+ std::string Buf(path);
if (isDirectory())
- strcpy(FNBuffer+path.size(), "/XXXXXX");
+ Buf += "/XXXXXX";
else
- strcpy(FNBuffer+path.size(), "-XXXXXX");
+ Buf += "-XXXXXX";
#if defined(HAVE_MKSTEMP)
int TempFD;
- if ((TempFD = mkstemp(FNBuffer)) == -1)
+ if ((TempFD = mkstemp((char*)Buf.c_str())) == -1)
return MakeErrMsg(ErrMsg, path + ": can't make unique filename");
// We don't need to hold the temp file descriptor... we will trust that no one
@@ -880,21 +874,21 @@ Path::makeUnique(bool reuse_current, std::string* ErrMsg) {
close(TempFD);
// Save the name
- path = FNBuffer;
+ path = Buf;
#elif defined(HAVE_MKTEMP)
// If we don't have mkstemp, use the old and obsolete mktemp function.
- if (mktemp(FNBuffer) == 0)
+ if (mktemp(Buf.c_str()) == 0)
return MakeErrMsg(ErrMsg, path + ": can't make unique filename");
// Save the name
- path = FNBuffer;
+ path = Buf;
#else
// Okay, looks like we have to do it all by our lonesome.
static unsigned FCounter = 0;
unsigned offset = path.size() + 1;
- while ( FCounter < 999999 && exists()) {
- sprintf(FNBuffer+offset,"%06u",++FCounter);
- path = FNBuffer;
+ while (FCounter < 999999 && exists()) {
+ sprintf(Buf.data()+offset, "%06u", ++FCounter);
+ path = Buf;
}
if (FCounter > 999999)
return MakeErrMsg(ErrMsg,
diff --git a/lib/System/Unix/Process.inc b/lib/System/Unix/Process.inc
index 911b8c3..cf6a47a 100644
--- a/lib/System/Unix/Process.inc
+++ b/lib/System/Unix/Process.inc
@@ -277,7 +277,7 @@ bool Process::ColorNeedsFlush() {
COLOR(FGBG, "7", BOLD)\
}
-static const char* colorcodes[2][2][8] = {
+static const char colorcodes[2][2][8][10] = {
{ ALLCOLORS("3",""), ALLCOLORS("3","1;") },
{ ALLCOLORS("4",""), ALLCOLORS("4","1;") }
};
diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc
index 634fbc7..b5f6374 100644
--- a/lib/System/Win32/Path.inc
+++ b/lib/System/Win32/Path.inc
@@ -47,7 +47,7 @@ namespace llvm {
namespace sys {
const char PathSeparator = ';';
-Path::Path(const std::string& p)
+Path::Path(llvm::StringRef p)
: path(p) {
FlipBackSlashes(path);
}
@@ -58,8 +58,8 @@ Path::Path(const char *StrStart, unsigned StrLen)
}
Path&
-Path::operator=(const std::string &that) {
- path = that;
+Path::operator=(StringRef that) {
+ path.assign(that.data(), that.size());
FlipBackSlashes(path);
return *this;
}
@@ -287,11 +287,11 @@ Path::isRootDirectory() const {
return len > 0 && path[len-1] == '/';
}
-std::string Path::getDirname() const {
- return getDirnameCharSep(path, '/');
+StringRef Path::getDirname() const {
+ return getDirnameCharSep(path, "/");
}
-std::string
+StringRef
Path::getBasename() const {
// Find the last slash
size_t slash = path.rfind('/');
@@ -302,12 +302,12 @@ Path::getBasename() const {
size_t dot = path.rfind('.');
if (dot == std::string::npos || dot < slash)
- return path.substr(slash);
+ return StringRef(path).substr(slash);
else
- return path.substr(slash, dot - slash);
+ return StringRef(path).substr(slash, dot - slash);
}
-std::string
+StringRef
Path::getSuffix() const {
// Find the last slash
size_t slash = path.rfind('/');
@@ -318,9 +318,9 @@ Path::getSuffix() const {
size_t dot = path.rfind('.');
if (dot == std::string::npos || dot < slash)
- return std::string();
+ return StringRef("");
else
- return path.substr(dot + 1);
+ return StringRef(path).substr(dot + 1);
}
bool
@@ -364,7 +364,7 @@ Path::isRegularFile() const {
return true;
}
-std::string
+StringRef
Path::getLast() const {
// Find the last slash
size_t pos = path.rfind('/');
@@ -378,7 +378,7 @@ Path::getLast() const {
return path;
// Return everything after the last slash
- return path.substr(pos+1);
+ return StringRef(path).substr(pos+1);
}
const FileStatus *
@@ -490,7 +490,7 @@ Path::getDirectoryContents(std::set<Path>& result, std::string* ErrMsg) const {
}
bool
-Path::set(const std::string& a_path) {
+Path::set(StringRef a_path) {
if (a_path.empty())
return false;
std::string save(path);
@@ -504,7 +504,7 @@ Path::set(const std::string& a_path) {
}
bool
-Path::appendComponent(const std::string& name) {
+Path::appendComponent(StringRef name) {
if (name.empty())
return false;
std::string save(path);
@@ -536,7 +536,7 @@ Path::eraseComponent() {
}
bool
-Path::appendSuffix(const std::string& suffix) {
+Path::appendSuffix(StringRef suffix) {
std::string save(path);
path.append(".");
path.append(suffix);
OpenPOWER on IntegriCloud