[llvm] r186721 - Fix inserting new elements in a specified location.
Rafael Espindola
rafael.espindola at gmail.com
Fri Jul 19 14:23:28 PDT 2013
Author: rafael
Date: Fri Jul 19 16:23:28 2013
New Revision: 186721
URL: http://llvm.org/viewvc/llvm-project?rev=186721&view=rev
Log:
Fix inserting new elements in a specified location.
We were only handling the 'a' and 'b' options during moves before.
Added:
llvm/trunk/test/Object/archive-replace-pos.test
Modified:
llvm/trunk/tools/llvm-ar/llvm-ar.cpp
Added: llvm/trunk/test/Object/archive-replace-pos.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/archive-replace-pos.test?rev=186721&view=auto
==============================================================================
--- llvm/trunk/test/Object/archive-replace-pos.test (added)
+++ llvm/trunk/test/Object/archive-replace-pos.test Fri Jul 19 16:23:28 2013
@@ -0,0 +1,13 @@
+Test adding a member to a particular position
+
+RUN: touch %t.foo
+RUN: touch %t.bar
+RUN: rm -f %t.a
+RUN: llvm-ar rc %t.a %t.foo %t.bar
+RUN: touch %t.zed
+RUN: llvm-ar rca %t.foo %t.a %t.zed
+RUN: llvm-ar t %t.a | FileCheck %s
+
+CHECK: .foo
+CHECK-NEXT: .zed
+CHECK-NEXT: .bar
Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=186721&r1=186720&r2=186721&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Fri Jul 19 16:23:28 2013
@@ -382,6 +382,7 @@ class NewArchiveIterator {
public:
NewArchiveIterator(object::Archive::child_iterator I, Twine Name);
NewArchiveIterator(std::vector<std::string>::const_iterator I, Twine Name);
+ NewArchiveIterator();
bool isNewMember() const;
object::Archive::child_iterator getOld() const;
const char *getNew() const;
@@ -389,6 +390,8 @@ public:
};
}
+NewArchiveIterator::NewArchiveIterator() {}
+
NewArchiveIterator::NewArchiveIterator(object::Archive::child_iterator I,
Twine Name)
: IsNewMember(false), OldI(I) {
@@ -415,14 +418,20 @@ const char *NewArchiveIterator::getNew()
template <typename T>
void addMember(std::vector<NewArchiveIterator> &Members,
- std::string &StringTable, T I, StringRef Name) {
+ std::string &StringTable, T I, StringRef Name, int Pos = -1) {
if (Name.size() < 16) {
NewArchiveIterator NI(I, Twine(Name) + "/");
- Members.push_back(NI);
+ if (Pos == -1)
+ Members.push_back(NI);
+ else
+ Members[Pos] = NI;
} else {
int MapIndex = StringTable.size();
NewArchiveIterator NI(I, Twine("/") + Twine(MapIndex));
- Members.push_back(NI);
+ if (Pos == -1)
+ Members.push_back(NI);
+ else
+ Members[Pos] = NI;
StringTable += Name;
StringTable += "/\n";
}
@@ -462,6 +471,8 @@ computeNewArchiveMembers(ArchiveOperatio
else
InsertPos = Pos + 1;
}
+ if (InsertPos == Pos)
+ Ret.resize(Ret.size() + Members.size());
if (Operation != QuickAppend && !Members.empty()) {
std::vector<std::string>::iterator MI =
std::find_if(Members.begin(), Members.end(), HasName(Name));
@@ -488,23 +499,30 @@ computeNewArchiveMembers(ArchiveOperatio
if (Operation == Delete)
return Ret;
+ if (!RelPos.empty() && InsertPos == -1)
+ fail("Insertion point not found");
+
if (Operation == Move) {
+ if (Members.size() != Moved.size())
+ fail("A member to be moved is not present in the archive");
+
if (RelPos.empty()) {
Ret.insert(Ret.end(), Moved.begin(), Moved.end());
return Ret;
}
- if (InsertPos == -1)
- fail("Insertion point not found");
assert(unsigned(InsertPos) <= Ret.size());
- Ret.insert(Ret.begin() + InsertPos, Moved.begin(), Moved.end());
+ std::copy(Moved.begin(), Moved.end(), Ret.begin() + InsertPos);
return Ret;
}
+ int Pos = InsertPos;
for (std::vector<std::string>::iterator I = Members.begin(),
E = Members.end();
I != E; ++I) {
StringRef Name = sys::path::filename(*I);
- addMember(Ret, StringTable, I, Name);
+ addMember(Ret, StringTable, I, Name, Pos);
+ if (Pos != -1)
+ ++Pos;
}
return Ret;
More information about the llvm-commits
mailing list