Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: courgette/assembly_program.cc

Issue 6677141: Switch out use of std::string and std::vector for large allocations for a buffer class that doesn... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: fix linux build error. remove unnecessary call Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « courgette/assembly_program.h ('k') | courgette/courgette_tool.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: courgette/assembly_program.cc
===================================================================
--- courgette/assembly_program.cc (revision 80344)
+++ courgette/assembly_program.cc (working copy)
@@ -86,8 +86,7 @@
} // namespace
AssemblyProgram::AssemblyProgram()
- : byte_instruction_cache_(NULL),
- image_base_(0) {
+ : image_base_(0) {
}
static void DeleteContainedLabels(const RVAToLabel& labels) {
@@ -101,33 +100,32 @@
if (instruction->op() != DEFBYTE) // Will be in byte_instruction_cache_.
delete instruction;
}
- if (byte_instruction_cache_) {
+ if (byte_instruction_cache_.get()) {
for (size_t i = 0; i < 256; ++i)
delete byte_instruction_cache_[i];
- delete[] byte_instruction_cache_;
}
DeleteContainedLabels(rel32_labels_);
DeleteContainedLabels(abs32_labels_);
}
-void AssemblyProgram::EmitMakeRelocsInstruction() {
- Emit(new MakeRelocsInstruction());
+CheckBool AssemblyProgram::EmitMakeRelocsInstruction() {
+ return Emit(new(std::nothrow) MakeRelocsInstruction());
}
-void AssemblyProgram::EmitOriginInstruction(RVA rva) {
- Emit(new OriginInstruction(rva));
+CheckBool AssemblyProgram::EmitOriginInstruction(RVA rva) {
+ return Emit(new(std::nothrow) OriginInstruction(rva));
}
-void AssemblyProgram::EmitByteInstruction(uint8 byte) {
- Emit(GetByteInstruction(byte));
+CheckBool AssemblyProgram::EmitByteInstruction(uint8 byte) {
+ return Emit(GetByteInstruction(byte));
}
-void AssemblyProgram::EmitRel32(Label* label) {
- Emit(new InstructionWithLabel(REL32, label));
+CheckBool AssemblyProgram::EmitRel32(Label* label) {
+ return Emit(new(std::nothrow) InstructionWithLabel(REL32, label));
}
-void AssemblyProgram::EmitAbs32(Label* label) {
- Emit(new InstructionWithLabel(ABS32, label));
+CheckBool AssemblyProgram::EmitAbs32(Label* label) {
+ return Emit(new(std::nothrow) InstructionWithLabel(ABS32, label));
}
Label* AssemblyProgram::FindOrMakeAbs32Label(RVA rva) {
@@ -167,10 +165,19 @@
return NULL;
}
+CheckBool AssemblyProgram::Emit(Instruction* instruction) {
+ if (!instruction)
+ return false;
+ bool ok = instructions_.push_back(instruction);
+ if (!ok)
+ delete instruction;
+ return ok;
+}
+
Label* AssemblyProgram::FindLabel(RVA rva, RVAToLabel* labels) {
Label*& slot = (*labels)[rva];
- if (slot == 0) {
- slot = new Label(rva);
+ if (slot == NULL) {
+ slot = new(std::nothrow) Label(rva);
}
return slot;
}
@@ -307,7 +314,10 @@
}
EncodedProgram* AssemblyProgram::Encode() const {
- scoped_ptr<EncodedProgram> encoded(new EncodedProgram());
+ scoped_ptr<EncodedProgram> encoded(new(std::nothrow) EncodedProgram());
+ if (!encoded.get())
+ return NULL;
+
encoded->set_image_base(image_base_);
if (!DefineLabels(abs32_labels_, encoded.get(),
@@ -362,10 +372,20 @@
}
Instruction* AssemblyProgram::GetByteInstruction(uint8 byte) {
- if (!byte_instruction_cache_) {
- byte_instruction_cache_ = new Instruction*[256];
+ if (!byte_instruction_cache_.get()) {
+ byte_instruction_cache_.reset(new(std::nothrow) Instruction*[256]);
+ if (!byte_instruction_cache_.get())
+ return NULL;
+
for (int i = 0; i < 256; ++i) {
- byte_instruction_cache_[i] = new ByteInstruction(static_cast<uint8>(i));
+ byte_instruction_cache_[i] =
+ new(std::nothrow) ByteInstruction(static_cast<uint8>(i));
+ if (!byte_instruction_cache_[i]) {
+ for (int j = 0; j < i; ++j)
+ delete byte_instruction_cache_[j];
+ byte_instruction_cache_.reset();
+ return NULL;
+ }
}
}
« no previous file with comments | « courgette/assembly_program.h ('k') | courgette/courgette_tool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698