mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-03 02:43:51 +00:00
Remove EH use from the Archive library and adjust its users accordingly.
llvm-svn: 29066
This commit is contained in:
parent
00f6c95af4
commit
9f4deeabf4
@ -438,12 +438,14 @@ class Archive {
|
||||
/// name will be truncated at 15 characters. If \p Compress is specified,
|
||||
/// all archive members will be compressed before being written. If
|
||||
/// \p PrintSymTab is true, the symbol table will be printed to std::cout.
|
||||
/// @throws std::string if an error occurs
|
||||
/// @returns false if an error occurred, \p error set to error message
|
||||
/// @returns true if the writing succeeded.
|
||||
/// @brief Write (possibly modified) archive contents to disk
|
||||
void writeToDisk(
|
||||
bool writeToDisk(
|
||||
bool CreateSymbolTable=false, ///< Create Symbol table
|
||||
bool TruncateNames=false, ///< Truncate the filename to 15 chars
|
||||
bool Compress=false ///< Compress files
|
||||
bool Compress=false, ///< Compress files
|
||||
std::string* error = 0 ///< If non-null, where error msg is set
|
||||
);
|
||||
|
||||
/// This method adds a new file to the archive. The \p filename is examined
|
||||
@ -481,9 +483,19 @@ class Archive {
|
||||
/// @brief Write the symbol table to an ofstream.
|
||||
void writeSymbolTable(std::ofstream& ARFile);
|
||||
|
||||
/// @brief Write one ArchiveMember to an ofstream.
|
||||
void writeMember(const ArchiveMember& member, std::ofstream& ARFile,
|
||||
bool CreateSymbolTable, bool TruncateNames, bool ShouldCompress);
|
||||
/// Writes one ArchiveMember to an ofstream. If an error occurs, returns
|
||||
/// false, otherwise true. If an error occurs and error is non-null then
|
||||
/// it will be set to an error message.
|
||||
/// @returns true Writing member succeeded
|
||||
/// @returns false Writing member failed, \p error set to error message
|
||||
bool writeMember(
|
||||
const ArchiveMember& member, ///< The member to be written
|
||||
std::ofstream& ARFile, ///< The file to write member onto
|
||||
bool CreateSymbolTable, ///< Should symbol table be created?
|
||||
bool TruncateNames, ///< Should names be truncated to 11 chars?
|
||||
bool ShouldCompress, ///< Should the member be compressed?
|
||||
std::string* error = 0 ///< If non-null, place were error msg is set
|
||||
);
|
||||
|
||||
/// @brief Fill in an ArchiveMemberHeader from ArchiveMember.
|
||||
bool fillHeader(const ArchiveMember&mbr,
|
||||
|
@ -184,13 +184,14 @@ Archive::addFileBefore(const sys::Path& filePath, iterator where) {
|
||||
}
|
||||
|
||||
// Write one member out to the file.
|
||||
void
|
||||
bool
|
||||
Archive::writeMember(
|
||||
const ArchiveMember& member,
|
||||
std::ofstream& ARFile,
|
||||
bool CreateSymbolTable,
|
||||
bool TruncateNames,
|
||||
bool ShouldCompress
|
||||
bool ShouldCompress,
|
||||
std::string* error
|
||||
) {
|
||||
|
||||
unsigned filepos = ARFile.tellp();
|
||||
@ -235,8 +236,12 @@ Archive::writeMember(
|
||||
// We don't need this module any more.
|
||||
delete MP;
|
||||
} else {
|
||||
throw std::string("Can't parse bytecode member: ") +
|
||||
member.getPath().toString();
|
||||
if (mFile != 0) {
|
||||
mFile->close();
|
||||
delete mFile;
|
||||
}
|
||||
if (error)
|
||||
*error = "Can't parse bytecode member: " + member.getPath().toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,7 +268,9 @@ Archive::writeMember(
|
||||
data +=4;
|
||||
fSize -= 4;
|
||||
}
|
||||
fSize = Compressor::compressToNewBuffer(data,fSize,output);
|
||||
fSize = Compressor::compressToNewBuffer(data,fSize,output,error);
|
||||
if (fSize == 0)
|
||||
return false;
|
||||
data = output;
|
||||
if (member.isBytecode())
|
||||
hdrSize = -fSize-4;
|
||||
@ -307,6 +314,7 @@ Archive::writeMember(
|
||||
mFile->close();
|
||||
delete mFile;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Write out the LLVM symbol table as an archive member to the file.
|
||||
@ -364,9 +372,10 @@ Archive::writeSymbolTable(std::ofstream& ARFile) {
|
||||
// This writes to a temporary file first. Options are for creating a symbol
|
||||
// table, flattening the file names (no directories, 15 chars max) and
|
||||
// compressing each archive member.
|
||||
void
|
||||
Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
||||
|
||||
bool
|
||||
Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress,
|
||||
std::string* error)
|
||||
{
|
||||
// Make sure they haven't opened up the file, not loaded it,
|
||||
// but are now trying to write it which would wipe out the file.
|
||||
assert(!(members.empty() && mapfile->size() > 8) &&
|
||||
@ -379,8 +388,6 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
||||
// Make sure the temporary gets removed if we crash
|
||||
sys::RemoveFileOnSignal(TmpArchive);
|
||||
|
||||
// Ensure we can remove the temporary even in the face of an exception
|
||||
try {
|
||||
// Create archive file for output.
|
||||
std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
|
||||
std::ios::binary;
|
||||
@ -388,7 +395,11 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
||||
|
||||
// Check for errors opening or creating archive file.
|
||||
if ( !ArchiveFile.is_open() || ArchiveFile.bad() ) {
|
||||
throw std::string("Error opening archive file: ") + archPath.toString();
|
||||
if (TmpArchive.exists())
|
||||
TmpArchive.eraseFromDisk();
|
||||
if (error)
|
||||
*error = "Error opening archive file: " + archPath.toString();
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we're creating a symbol table, reset it now
|
||||
@ -403,7 +414,14 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
||||
// Loop over all member files, and write them out. Note that this also
|
||||
// builds the symbol table, symTab.
|
||||
for ( MembersList::iterator I = begin(), E = end(); I != E; ++I) {
|
||||
writeMember(*I,ArchiveFile,CreateSymbolTable,TruncateNames,Compress);
|
||||
if (!writeMember(*I,ArchiveFile,CreateSymbolTable,
|
||||
TruncateNames,Compress,error))
|
||||
{
|
||||
if (TmpArchive.exists())
|
||||
TmpArchive.eraseFromDisk();
|
||||
ArchiveFile.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Close archive file.
|
||||
@ -421,16 +439,19 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
||||
sys::MappedFile arch(TmpArchive);
|
||||
const char* base = (const char*) arch.map();
|
||||
|
||||
// Open another temporary file in order to avoid invalidating the mmapped data
|
||||
// Open another temporary file in order to avoid invalidating the
|
||||
// mmapped data
|
||||
sys::Path FinalFilePath = archPath;
|
||||
FinalFilePath.createTemporaryFileOnDisk();
|
||||
sys::RemoveFileOnSignal(FinalFilePath);
|
||||
try {
|
||||
|
||||
|
||||
std::ofstream FinalFile(FinalFilePath.c_str(), io_mode);
|
||||
if ( !FinalFile.is_open() || FinalFile.bad() ) {
|
||||
throw std::string("Error opening archive file: ") + FinalFilePath.toString();
|
||||
if (TmpArchive.exists())
|
||||
TmpArchive.eraseFromDisk();
|
||||
if (error)
|
||||
*error = "Error opening archive file: " + FinalFilePath.toString();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write the file magic number
|
||||
@ -459,24 +480,14 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
||||
|
||||
// Move the final file over top of TmpArchive
|
||||
FinalFilePath.renamePathOnDisk(TmpArchive);
|
||||
} catch (...) {
|
||||
// Make sure we clean up.
|
||||
if (FinalFilePath.exists())
|
||||
FinalFilePath.eraseFromDisk();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// Before we replace the actual archive, we need to forget all the
|
||||
// members, since they point to data in that old archive. We need to do
|
||||
// we cannot replace an open file on Windows.
|
||||
// this because we cannot replace an open file on Windows.
|
||||
cleanUpMemory();
|
||||
|
||||
TmpArchive.renamePathOnDisk(archPath);
|
||||
} catch (...) {
|
||||
// Make sure we clean up.
|
||||
if (TmpArchive.exists())
|
||||
TmpArchive.eraseFromDisk();
|
||||
throw;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -484,7 +484,9 @@ void doDelete() {
|
||||
}
|
||||
|
||||
// We're done editting, reconstruct the archive.
|
||||
TheArchive->writeToDisk(SymTable,TruncateNames,Compression);
|
||||
std::string errmsg;
|
||||
if (!TheArchive->writeToDisk(SymTable,TruncateNames,Compression,&errmsg))
|
||||
throw errmsg;
|
||||
if (ReallyVerbose)
|
||||
printSymbolTable();
|
||||
}
|
||||
@ -536,7 +538,9 @@ void doMove() {
|
||||
}
|
||||
|
||||
// We're done editting, reconstruct the archive.
|
||||
TheArchive->writeToDisk(SymTable,TruncateNames,Compression);
|
||||
std::string errmsg;
|
||||
if (!TheArchive->writeToDisk(SymTable,TruncateNames,Compression,&errmsg))
|
||||
throw errmsg;
|
||||
if (ReallyVerbose)
|
||||
printSymbolTable();
|
||||
}
|
||||
@ -555,7 +559,9 @@ void doQuickAppend() {
|
||||
}
|
||||
|
||||
// We're done editting, reconstruct the archive.
|
||||
TheArchive->writeToDisk(SymTable,TruncateNames,Compression);
|
||||
std::string errmsg;
|
||||
if (!TheArchive->writeToDisk(SymTable,TruncateNames,Compression,&errmsg))
|
||||
throw errmsg;
|
||||
if (ReallyVerbose)
|
||||
printSymbolTable();
|
||||
}
|
||||
@ -642,7 +648,9 @@ void doReplaceOrInsert() {
|
||||
}
|
||||
|
||||
// We're done editting, reconstruct the archive.
|
||||
TheArchive->writeToDisk(SymTable,TruncateNames,Compression);
|
||||
std::string errmsg;
|
||||
if (!TheArchive->writeToDisk(SymTable,TruncateNames,Compression,&errmsg))
|
||||
throw errmsg;
|
||||
if (ReallyVerbose)
|
||||
printSymbolTable();
|
||||
}
|
||||
|
@ -74,7 +74,8 @@ int main(int argc, char **argv) {
|
||||
if (!TheArchive)
|
||||
throw err_msg;
|
||||
|
||||
TheArchive->writeToDisk(true, false, false );
|
||||
if (!TheArchive->writeToDisk(true, false, false, &err_msg ))
|
||||
throw err_msg;
|
||||
|
||||
if (Verbose)
|
||||
printSymbolTable(TheArchive);
|
||||
|
Loading…
x
Reference in New Issue
Block a user