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

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: Created 9 years, 9 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
Index: courgette/assembly_program.cc
===================================================================
--- courgette/assembly_program.cc (revision 80344)
+++ courgette/assembly_program.cc (working copy)
@@ -110,24 +110,24 @@
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) {
@@ -170,7 +170,7 @@
Label* AssemblyProgram::FindLabel(RVA rva, RVAToLabel* labels) {
Label*& slot = (*labels)[rva];
if (slot == 0) {
grt (UTC plus 2) 2011/04/05 17:10:08 use NULL rather than 0
tommi (sloooow) - chröme 2011/04/05 19:06:53 Done.
- slot = new Label(rva);
+ slot = new(std::nothrow) Label(rva);
}
return slot;
}
@@ -307,7 +307,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(),
@@ -363,9 +366,19 @@
Instruction* AssemblyProgram::GetByteInstruction(uint8 byte) {
if (!byte_instruction_cache_) {
- byte_instruction_cache_ = new Instruction*[256];
+ byte_instruction_cache_ = new(std::nothrow) Instruction*[256];
+ if (!byte_instruction_cache_)
+ 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];
+ delete [] byte_instruction_cache_;
+ return NULL;
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698