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

Unified Diff: courgette/assembly_program.cc

Issue 1650013002: Revert of [Courgette] Refactor: Manage AssemblyProgram and EncodedProgram with scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: courgette/assembly_program.cc
diff --git a/courgette/assembly_program.cc b/courgette/assembly_program.cc
index de843f1329050e46d10da2cbb4eef90a74d7711a..20eee96ff5e04b5e0d1e77642526b6d7c7698a4e 100644
--- a/courgette/assembly_program.cc
+++ b/courgette/assembly_program.cc
@@ -7,12 +7,16 @@
#include <memory.h>
#include <stddef.h>
#include <stdint.h>
-
-#include <utility>
+#include <algorithm>
+#include <map>
+#include <set>
+#include <sstream>
#include <vector>
#include "base/logging.h"
#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+
#include "courgette/courgette.h"
#include "courgette/encoded_program.h"
@@ -361,13 +365,13 @@
<< " infill " << fill_infill_count;
}
-scoped_ptr<EncodedProgram> AssemblyProgram::Encode() const {
+EncodedProgram* AssemblyProgram::Encode() const {
scoped_ptr<EncodedProgram> encoded(new EncodedProgram());
encoded->set_image_base(image_base_);
if (!encoded->DefineLabels(abs32_labels_, rel32_labels_))
- return nullptr;
+ return NULL;
for (size_t i = 0; i < instructions_.size(); ++i) {
Instruction* instruction = instructions_[i];
@@ -376,13 +380,13 @@
case ORIGIN: {
OriginInstruction* org = static_cast<OriginInstruction*>(instruction);
if (!encoded->AddOrigin(org->origin_rva()))
- return nullptr;
+ return NULL;
break;
}
case DEFBYTE: {
uint8_t b = static_cast<ByteInstruction*>(instruction)->byte_value();
if (!encoded->AddCopy(1, &b))
- return nullptr;
+ return NULL;
break;
}
case DEFBYTES: {
@@ -391,13 +395,13 @@
size_t len = static_cast<BytesInstruction*>(instruction)->len();
if (!encoded->AddCopy(len, byte_values))
- return nullptr;
+ return NULL;
break;
}
case REL32: {
Label* label = static_cast<InstructionWithLabel*>(instruction)->label();
if (!encoded->AddRel32(label->index_))
- return nullptr;
+ return NULL;
break;
}
case REL32ARM: {
@@ -406,34 +410,34 @@
uint16_t compressed_op =
static_cast<InstructionWithLabelARM*>(instruction)->compressed_op();
if (!encoded->AddRel32ARM(compressed_op, label->index_))
- return nullptr;
+ return NULL;
break;
}
case ABS32: {
Label* label = static_cast<InstructionWithLabel*>(instruction)->label();
if (!encoded->AddAbs32(label->index_))
- return nullptr;
+ return NULL;
break;
}
case ABS64: {
Label* label = static_cast<InstructionWithLabel*>(instruction)->label();
if (!encoded->AddAbs64(label->index_))
- return nullptr;
+ return NULL;
break;
}
case MAKEPERELOCS: {
if (!encoded->AddPeMakeRelocs(kind_))
- return nullptr;
+ return NULL;
break;
}
case MAKEELFRELOCS: {
if (!encoded->AddElfMakeRelocs())
- return nullptr;
+ return NULL;
break;
}
case MAKEELFARMRELOCS: {
if (!encoded->AddElfARMMakeRelocs())
- return nullptr;
+ return NULL;
break;
}
default: {
@@ -442,7 +446,7 @@
}
}
- return encoded;
+ return encoded.release();
}
Instruction* AssemblyProgram::GetByteInstruction(uint8_t byte) {
@@ -526,13 +530,15 @@
////////////////////////////////////////////////////////////////////////////////
-Status Encode(const AssemblyProgram& program,
- scoped_ptr<EncodedProgram>* output) {
- // Explicitly release any memory associated with the output before encoding.
- output->reset();
-
- *output = program.Encode();
- return (*output) ? C_OK : C_GENERAL_ERROR;
+Status Encode(AssemblyProgram* program, EncodedProgram** output) {
+ *output = NULL;
+ EncodedProgram *encoded = program->Encode();
+ if (encoded) {
+ *output = encoded;
+ return C_OK;
+ } else {
+ return C_GENERAL_ERROR;
+ }
}
} // namespace courgette
« no previous file with comments | « courgette/assembly_program.h ('k') | courgette/courgette.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698