Commit ab98dcc9 authored by avi's avatar avi Committed by Commit bot

Switch to standard integer types in courgette/.

BUG=138542
TBR=wfh@chromium.org
NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/1543643002

Cr-Commit-Position: refs/heads/master@{#366439}
parent 34318488
......@@ -4,6 +4,9 @@
#include "courgette/adjustment_method.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <list>
#include <map>
......@@ -11,8 +14,8 @@
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "courgette/assembly_program.h"
......@@ -41,10 +44,10 @@ class LabelInfo {
Label* label_; // The label that this info a surrogate for.
// Information used only in debugging messages.
uint32 is_model_ : 1; // Is the label in the model?
uint32 debug_index_ : 31; // An unique small number for naming the label.
uint32_t is_model_ : 1; // Is the label in the model?
uint32_t debug_index_ : 31; // An unique small number for naming the label.
uint32 refs_; // Number of times this Label is referenced.
uint32_t refs_; // Number of times this Label is referenced.
LabelInfo* assignment_; // Label from other program corresponding to this.
......@@ -53,7 +56,7 @@ class LabelInfo {
LabelInfo* next_addr_; // Label(Info) at next highest address.
LabelInfo* prev_addr_; // Label(Info) at next lowest address.
std::vector<uint32> positions_; // Offsets into the trace of references.
std::vector<uint32_t> positions_; // Offsets into the trace of references.
// Just a no-argument constructor and copy constructor. Actual LabelInfo
// objects are allocated in std::pair structs in a std::map.
......@@ -149,9 +152,7 @@ struct Node {
bool in_queue_;
bool Extended() const { return !edges_.empty(); }
uint32 Weight() const {
return edges_in_frequency_order.front()->count_;
}
uint32_t Weight() const { return edges_in_frequency_order.front()->count_; }
};
static std::string ToString(Node* node) {
......@@ -190,8 +191,8 @@ struct OrderNodeByWeightDecreasing {
bool operator()(Node* a, Node* b) const {
// (Maybe tie-break on total count, followed by lowest assigned node indexes
// in path.)
uint32 a_weight = a->Weight();
uint32 b_weight = b->Weight();
uint32_t a_weight = a->Weight();
uint32_t b_weight = b->Weight();
if (a_weight != b_weight)
return a_weight > b_weight;
if (a->length_ != b->length_)
......@@ -254,7 +255,7 @@ class AssignmentProblem {
void SkipCommittedLabels(Node* node) {
ExtendNode(node, p_trace_);
uint32 skipped = 0;
uint32_t skipped = 0;
while (!node->edges_in_frequency_order.empty() &&
node->edges_in_frequency_order.front()->in_edge_->assignment_) {
++skipped;
......@@ -421,9 +422,9 @@ class AssignmentProblem {
}
}
uint32 TryExtendSequence(uint32 p_pos_start, uint32 m_pos_start) {
uint32 p_pos = p_pos_start + 1;
uint32 m_pos = m_pos_start + 1;
uint32_t TryExtendSequence(uint32_t p_pos_start, uint32_t m_pos_start) {
uint32_t p_pos = p_pos_start + 1;
uint32_t m_pos = m_pos_start + 1;
while (p_pos < p_trace_.size() && m_pos < m_trace_.size()) {
LabelInfo* p_info = p_trace_[p_pos];
......@@ -456,12 +457,13 @@ class AssignmentProblem {
return p_pos - p_pos_start;
}
uint32 TryExtendSequenceBackwards(uint32 p_pos_start, uint32 m_pos_start) {
uint32_t TryExtendSequenceBackwards(uint32_t p_pos_start,
uint32_t m_pos_start) {
if (p_pos_start == 0 || m_pos_start == 0)
return 0;
uint32 p_pos = p_pos_start - 1;
uint32 m_pos = m_pos_start - 1;
uint32_t p_pos = p_pos_start - 1;
uint32_t m_pos = m_pos_start - 1;
while (p_pos > 0 && m_pos > 0) {
LabelInfo* p_info = p_trace_[p_pos];
......@@ -522,7 +524,7 @@ class AssignmentProblem {
Node* MakeRootNode(const Trace& trace) {
Node* node = new Node(NULL, NULL);
all_nodes_.push_back(node);
for (uint32 i = 0; i < trace.size(); ++i) {
for (uint32_t i = 0; i < trace.size(); ++i) {
++node->count_;
node->places_.push_back(i);
}
......@@ -534,7 +536,7 @@ class AssignmentProblem {
if (node->Extended())
return;
for (size_t i = 0; i < node->places_.size(); ++i) {
uint32 index = node->places_.at(i);
uint32_t index = node->places_.at(i);
if (index < trace.size()) {
LabelInfo* item = trace.at(index);
Node*& slot = node->edges_[item];
......@@ -633,11 +635,11 @@ class GraphAdjuster : public AdjustmentMethod {
}
void ReferenceLabel(Trace* trace, Label* label, bool is_model) {
trace->push_back(MakeLabelInfo(label, is_model,
static_cast<uint32>(trace->size())));
trace->push_back(
MakeLabelInfo(label, is_model, static_cast<uint32_t>(trace->size())));
}
LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32 position) {
LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32_t position) {
LabelInfo& slot = label_infos_[label];
if (slot.label_ == NULL) {
slot.label_ = label;
......
......@@ -5,7 +5,7 @@
#ifndef COURGETTE_ADJUSTMENT_METHOD_H_
#define COURGETTE_ADJUSTMENT_METHOD_H_
#include "base/basictypes.h"
#include "base/macros.h"
namespace courgette {
......
......@@ -4,6 +4,9 @@
#include "courgette/adjustment_method.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <limits>
#include <list>
......@@ -12,9 +15,9 @@
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "courgette/assembly_program.h"
......@@ -176,16 +179,16 @@ class LabelInfo {
Label* label_; // The label that this info a surrogate for.
uint32 is_model_ : 1; // Is the label in the model?
uint32 debug_index_ : 31; // A small number for naming the label in debug
// output. The pair (is_model_, debug_index_) is
// unique.
uint32_t is_model_ : 1; // Is the label in the model?
uint32_t debug_index_ : 31; // A small number for naming the label in debug
// output. The pair (is_model_, debug_index_) is
// unique.
int refs_; // Number of times this Label is referenced.
LabelInfo* assignment_; // Label from other program corresponding to this.
std::vector<uint32> positions_; // Offsets into the trace of references.
std::vector<uint32_t> positions_; // Offsets into the trace of references.
private:
AssignmentCandidates* candidates_;
......@@ -213,7 +216,7 @@ class LabelInfoMaker {
public:
LabelInfoMaker() : debug_label_index_gen_(0) {}
LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32 position) {
LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32_t position) {
LabelInfo& slot = label_infos_[label];
if (slot.label_ == NULL) {
slot.label_ = label;
......@@ -364,7 +367,7 @@ LabelInfo::~LabelInfo() {
// position of one of the occurrences in the Trace.
class Shingle {
public:
static const uint8 kWidth = 5;
static const uint8_t kWidth = 5;
struct InterningLess {
bool operator()(const Shingle& a, const Shingle& b) const;
......@@ -388,7 +391,7 @@ class Shingle {
LabelInfo* at(size_t i) const { return trace_[exemplar_position_ + i]; }
void add_position(size_t position) {
positions_.push_back(static_cast<uint32>(position));
positions_.push_back(static_cast<uint32_t>(position));
}
int position_count() const { return static_cast<int>(positions_.size()); }
......@@ -414,7 +417,7 @@ class Shingle {
const Trace& trace_; // The shingle lives inside trace_.
size_t exemplar_position_; // At this position (and other positions).
std::vector<uint32> positions_; // Includes exemplar_position_.
std::vector<uint32_t> positions_; // Includes exemplar_position_.
ShinglePattern* pattern_; // Pattern changes as LabelInfos are assigned.
......@@ -430,7 +433,7 @@ class Shingle {
std::string ToString(const Shingle* instance) {
std::string s;
const char* sep = "<";
for (uint8 i = 0; i < Shingle::kWidth; ++i) {
for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
// base::StringAppendF(&s, "%s%x ", sep, instance.at(i)->label_->rva_);
s += sep;
s += ToString(instance->at(i));
......@@ -446,7 +449,7 @@ std::string ToString(const Shingle* instance) {
bool Shingle::InterningLess::operator()(
const Shingle& a,
const Shingle& b) const {
for (uint8 i = 0; i < kWidth; ++i) {
for (uint8_t i = 0; i < kWidth; ++i) {
LabelInfo* info_a = a.at(i);
LabelInfo* info_b = b.at(i);
if (info_a->label_->rva_ < info_b->label_->rva_)
......@@ -478,11 +481,11 @@ class ShinglePattern {
// --> <kFixed+0, kVariable+1, kFixed+2, kVariable+1, kFixed+0>
struct Index {
explicit Index(const Shingle* instance);
uint8 kinds_[Shingle::kWidth];
uint8 variables_;
uint8 unique_variables_;
uint8 first_variable_index_;
uint32 hash_;
uint8_t kinds_[Shingle::kWidth];
uint8_t variables_;
uint8_t unique_variables_;
uint8_t first_variable_index_;
uint32_t hash_;
int assigned_indexes_[Shingle::kWidth];
};
......@@ -526,10 +529,10 @@ std::string ToString(const ShinglePattern::Index* index) {
} else {
base::StringAppendF(&s, "<%d: ", index->variables_);
const char* sep = "";
for (uint8 i = 0; i < Shingle::kWidth; ++i) {
for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
s += sep;
sep = ", ";
uint32 kind = index->kinds_[i];
uint32_t kind = index->kinds_[i];
int offset = kind & ShinglePattern::kOffsetMask;
if (kind & ShinglePattern::kVariable)
base::StringAppendF(&s, "V%d", offset);
......@@ -622,7 +625,7 @@ struct ShinglePatternIndexLess {
if (a.hash_ < b.hash_) return true;
if (a.hash_ > b.hash_) return false;
for (uint8 i = 0; i < Shingle::kWidth; ++i) {
for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
if (a.kinds_[i] < b.kinds_[i]) return true;
if (a.kinds_[i] > b.kinds_[i]) return false;
if ((a.kinds_[i] & ShinglePattern::kVariable) == 0) {
......@@ -636,22 +639,22 @@ struct ShinglePatternIndexLess {
}
};
static uint32 hash_combine(uint32 h, uint32 v) {
static uint32_t hash_combine(uint32_t h, uint32_t v) {
h += v;
return (h * (37 + 0x0000d100)) ^ (h >> 13);
}
ShinglePattern::Index::Index(const Shingle* instance) {
uint32 hash = 0;
uint32_t hash = 0;
variables_ = 0;
unique_variables_ = 0;
first_variable_index_ = 255;
for (uint8 i = 0; i < Shingle::kWidth; ++i) {
for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
LabelInfo* info = instance->at(i);
uint8 kind = 0;
uint8_t kind = 0;
int code = -1;
uint8 j = 0;
uint8_t j = 0;
for ( ; j < i; ++j) {
if (info == instance->at(j)) { // Duplicate LabelInfo
kind = kinds_[j];
......@@ -942,7 +945,7 @@ class AssignmentProblem {
// For the positions in |info|, find the shingles that overlap that position.
void AddAffectedPositions(LabelInfo* info, ShingleSet* affected_shingles) {
const uint8 kWidth = Shingle::kWidth;
const uint8_t kWidth = Shingle::kWidth;
for (size_t i = 0; i < info->positions_.size(); ++i) {
size_t position = info->positions_[i];
// Find bounds to the subrange of |trace_| we are in.
......@@ -1059,7 +1062,7 @@ class AssignmentProblem {
// int score = p1; // ? weigh all equally??
int score = std::min(p1, m1);
for (uint8 i = 0; i < Shingle::kWidth; ++i) {
for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
LabelInfo* program_info = program_instance->at(i);
LabelInfo* model_info = model_instance->at(i);
if ((model_info->assignment_ == NULL) !=
......@@ -1275,9 +1278,8 @@ class Adjuster : public AdjustmentMethod {
}
void ReferenceLabel(Trace* trace, Label* label, bool is_model) {
trace->push_back(
label_info_maker_.MakeLabelInfo(label, is_model,
static_cast<uint32>(trace->size())));
trace->push_back(label_info_maker_.MakeLabelInfo(
label, is_model, static_cast<uint32_t>(trace->size())));
}
AssemblyProgram* prog_; // Program to be adjusted, owned by caller.
......
......@@ -5,6 +5,8 @@
#include "courgette/assembly_program.h"
#include <memory.h>
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <map>
#include <set>
......@@ -52,22 +54,20 @@ class ElfARMRelocsInstruction : public Instruction {
// Emits a single byte.
class ByteInstruction : public Instruction {
public:
explicit ByteInstruction(uint8 value) : Instruction(DEFBYTE, value) {}
uint8 byte_value() const { return info_; }
explicit ByteInstruction(uint8_t value) : Instruction(DEFBYTE, value) {}
uint8_t byte_value() const { return info_; }
};
// Emits a single byte.
class BytesInstruction : public Instruction {
public:
BytesInstruction(const uint8* values, size_t len)
: Instruction(DEFBYTES, 0),
values_(values),
len_(len) {}
const uint8* byte_values() const { return values_; }
BytesInstruction(const uint8_t* values, size_t len)
: Instruction(DEFBYTES, 0), values_(values), len_(len) {}
const uint8_t* byte_values() const { return values_; }
size_t len() const { return len_; }
private:
const uint8* values_;
const uint8_t* values_;
size_t len_;
};
......@@ -87,19 +87,25 @@ class InstructionWithLabel : public Instruction {
// a specially-compressed ARM op.
class InstructionWithLabelARM : public InstructionWithLabel {
public:
InstructionWithLabelARM(OP op, uint16 compressed_op, Label* label,
const uint8* arm_op, uint16 op_size)
: InstructionWithLabel(op, label), compressed_op_(compressed_op),
arm_op_(arm_op), op_size_(op_size) {
InstructionWithLabelARM(OP op,
uint16_t compressed_op,
Label* label,
const uint8_t* arm_op,
uint16_t op_size)
: InstructionWithLabel(op, label),
compressed_op_(compressed_op),
arm_op_(arm_op),
op_size_(op_size) {
if (label == NULL) NOTREACHED();
}
uint16 compressed_op() const { return compressed_op_; }
const uint8* arm_op() const { return arm_op_; }
uint16 op_size() const { return op_size_; }
uint16_t compressed_op() const { return compressed_op_; }
const uint8_t* arm_op() const { return arm_op_; }
uint16_t op_size() const { return op_size_; }
private:
uint16 compressed_op_;
const uint8* arm_op_;
uint16 op_size_;
uint16_t compressed_op_;
const uint8_t* arm_op_;
uint16_t op_size_;
};
} // namespace
......@@ -143,11 +149,11 @@ CheckBool AssemblyProgram::EmitOriginInstruction(RVA rva) {
return Emit(ScopedInstruction(UncheckedNew<OriginInstruction>(rva)));
}
CheckBool AssemblyProgram::EmitByteInstruction(uint8 byte) {
CheckBool AssemblyProgram::EmitByteInstruction(uint8_t byte) {
return EmitShared(GetByteInstruction(byte));
}
CheckBool AssemblyProgram::EmitBytesInstruction(const uint8* values,
CheckBool AssemblyProgram::EmitBytesInstruction(const uint8_t* values,
size_t len) {
return Emit(ScopedInstruction(UncheckedNew<BytesInstruction>(values, len)));
}
......@@ -157,8 +163,10 @@ CheckBool AssemblyProgram::EmitRel32(Label* label) {
ScopedInstruction(UncheckedNew<InstructionWithLabel>(REL32, label)));
}
CheckBool AssemblyProgram::EmitRel32ARM(uint16 op, Label* label,
const uint8* arm_op, uint16 op_size) {
CheckBool AssemblyProgram::EmitRel32ARM(uint16_t op,
Label* label,
const uint8_t* arm_op,
uint16_t op_size) {
return Emit(ScopedInstruction(UncheckedNew<InstructionWithLabelARM>(
REL32ARM, op, label, arm_op, op_size)));
}
......@@ -324,7 +332,7 @@ void AssemblyProgram::AssignRemainingIndexes(RVAToLabel* labels) {
if (prev)
prev_index = prev->index_;
else
prev_index = static_cast<uint32>(available.size());
prev_index = static_cast<uint32_t>(available.size());
if (prev_index != 0 &&
prev_index != Label::kNoIndex &&
available.at(prev_index - 1)) {
......@@ -400,14 +408,14 @@ EncodedProgram* AssemblyProgram::Encode() const {
break;
}
case DEFBYTE: {
uint8 b = static_cast<ByteInstruction*>(instruction)->byte_value();
uint8_t b = static_cast<ByteInstruction*>(instruction)->byte_value();
if (!encoded->AddCopy(1, &b))
return NULL;
break;
}
case DEFBYTES: {
const uint8* byte_values =
static_cast<BytesInstruction*>(instruction)->byte_values();
const uint8_t* byte_values =
static_cast<BytesInstruction*>(instruction)->byte_values();
size_t len = static_cast<BytesInstruction*>(instruction)->len();
if (!encoded->AddCopy(len, byte_values))
......@@ -423,9 +431,8 @@ EncodedProgram* AssemblyProgram::Encode() const {
case REL32ARM: {
Label* label =
static_cast<InstructionWithLabelARM*>(instruction)->label();
uint16 compressed_op =
static_cast<InstructionWithLabelARM*>(instruction)->
compressed_op();
uint16_t compressed_op =
static_cast<InstructionWithLabelARM*>(instruction)->compressed_op();
if (!encoded->AddRel32ARM(compressed_op, label->index_))
return NULL;
break;
......@@ -466,7 +473,7 @@ EncodedProgram* AssemblyProgram::Encode() const {
return encoded.release();
}
Instruction* AssemblyProgram::GetByteInstruction(uint8 byte) {
Instruction* AssemblyProgram::GetByteInstruction(uint8_t byte) {
if (!byte_instruction_cache_) {
Instruction** ram = nullptr;
if (!base::UncheckedMalloc(sizeof(Instruction*) * 256,
......@@ -477,7 +484,7 @@ Instruction* AssemblyProgram::GetByteInstruction(uint8 byte) {
for (int i = 0; i < 256; ++i) {
byte_instruction_cache_[i] =
UncheckedNew<ByteInstruction>(static_cast<uint8>(i));
UncheckedNew<ByteInstruction>(static_cast<uint8_t>(i));
if (!byte_instruction_cache_[i]) {
for (int j = 0; j < i; ++j)
UncheckedDelete(byte_instruction_cache_[j]);
......@@ -526,9 +533,9 @@ CheckBool AssemblyProgram::TrimLabels() {
Label* label =
static_cast<InstructionWithLabelARM*>(instruction)->label();
if (label->count_ <= lower_limit) {
const uint8* arm_op =
const uint8_t* arm_op =
static_cast<InstructionWithLabelARM*>(instruction)->arm_op();
uint16 op_size =
uint16_t op_size =
static_cast<InstructionWithLabelARM*>(instruction)->op_size();
if (op_size < 1)
......
......@@ -5,13 +5,15 @@
#ifndef COURGETTE_ASSEMBLY_PROGRAM_H_
#define COURGETTE_ASSEMBLY_PROGRAM_H_
#include <stddef.h>
#include <stdint.h>
#include <map>
#include <set>
#include <vector>
#include "base/basictypes.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "courgette/disassembler.h"
#include "courgette/image_utils.h"
#include "courgette/memory_allocator.h"
......@@ -47,8 +49,8 @@ class Instruction {
explicit Instruction(OP op) : op_(op), info_(0) {}
Instruction(OP op, unsigned int info) : op_(op), info_(info) {}
uint32 op_ : 4; // A few bits to store the OP code.
uint32 info_ : 28; // Remaining bits in first word available to subclass.
uint32_t op_ : 4; // A few bits to store the OP code.
uint32_t info_ : 28; // Remaining bits in first word available to subclass.
private:
DISALLOW_COPY_AND_ASSIGN(Instruction);
......@@ -82,7 +84,7 @@ class AssemblyProgram {
ExecutableType kind() const { return kind_; }
void set_image_base(uint64 image_base) { image_base_ = image_base; }
void set_image_base(uint64_t image_base) { image_base_ = image_base; }
// Instructions will be assembled in the order they are emitted.
......@@ -99,19 +101,21 @@ class AssemblyProgram {
CheckBool EmitOriginInstruction(RVA rva) WARN_UNUSED_RESULT;
// Generates a single byte of data or machine instruction.
CheckBool EmitByteInstruction(uint8 byte) WARN_UNUSED_RESULT;
CheckBool EmitByteInstruction(uint8_t byte) WARN_UNUSED_RESULT;
// Generates multiple bytes of data or machine instructions.
CheckBool EmitBytesInstruction(const uint8* value, size_t len)
WARN_UNUSED_RESULT;
CheckBool EmitBytesInstruction(const uint8_t* value,
size_t len) WARN_UNUSED_RESULT;
// Generates 4-byte relative reference to address of 'label'.
CheckBool EmitRel32(Label* label) WARN_UNUSED_RESULT;
// Generates 4-byte relative reference to address of 'label' for
// ARM.
CheckBool EmitRel32ARM(uint16 op, Label* label, const uint8* arm_op,
uint16 op_size) WARN_UNUSED_RESULT;
CheckBool EmitRel32ARM(uint16_t op,
Label* label,
const uint8_t* arm_op,
uint16_t op_size) WARN_UNUSED_RESULT;
// Generates 4-byte absolute reference to address of 'label'.
CheckBool EmitAbs32(Label* label) WARN_UNUSED_RESULT;
......@@ -171,10 +175,10 @@ class AssemblyProgram {
static void AssignRemainingIndexes(RVAToLabel* labels);
// Sharing instructions that emit a single byte saves a lot of space.
Instruction* GetByteInstruction(uint8 byte);
Instruction* GetByteInstruction(uint8_t byte);
scoped_ptr<Instruction* [], base::FreeDeleter> byte_instruction_cache_;
uint64 image_base_; // Desired or mandated base address of image.
uint64_t image_base_; // Desired or mandated base address of image.
InstructionVector instructions_; // All the instructions in program.
......
......@@ -4,6 +4,8 @@
#include "courgette/third_party/bsdiff.h"
#include <stddef.h>
#include "courgette/base_test_unittest.h"
#include "courgette/courgette.h"
#include "courgette/streams.h"
......
......@@ -5,6 +5,8 @@
#ifndef COURGETTE_CONSECUTIVE_RANGE_VISITOR_H_
#define COURGETTE_CONSECUTIVE_RANGE_VISITOR_H_
#include <stddef.h>
#include <iterator>
#include "base/macros.h"
......
......@@ -4,6 +4,8 @@
#include "courgette/consecutive_range_visitor.h"
#include <stddef.h>
#include <string>
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <vector>
#include "base/at_exit.h"
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
......@@ -48,7 +50,7 @@ void Problem(const char* format, ...) {
}
std::string ReadOrFail(const base::FilePath& file_name, const char* kind) {
int64 file_size = 0;
int64_t file_size = 0;
if (!base::GetFileSize(file_name, &file_size))
Problem("Can't read %s file.", kind);
std::string buffer;
......
......@@ -4,6 +4,9 @@
#include "courgette/crc.h"
#include <stdint.h>
#include <stddef.h>
#ifdef COURGETTE_USE_CRC_LIB
# include "zlib.h"
#else
......@@ -12,12 +15,11 @@ extern "C" {
}
#endif
#include "base/basictypes.h"
namespace courgette {
uint32 CalculateCrc(const uint8* buffer, size_t size) {
uint32 crc;
uint32_t CalculateCrc(const uint8_t* buffer, size_t size) {
uint32_t crc;
#ifdef COURGETTE_USE_CRC_LIB
// Calculate Crc by calling CRC method in zlib
......
......@@ -5,13 +5,14 @@
#ifndef COURGETTE_CRC_H_
#define COURGETTE_CRC_H_
#include "base/basictypes.h"
#include <stddef.h>
#include <stdint.h>
namespace courgette {
// Calculates Crc of the given buffer by calling CRC method in LZMA SDK
//
uint32 CalculateCrc(const uint8* buffer, size_t size);
uint32_t CalculateCrc(const uint8_t* buffer, size_t size);
} // namespace courgette
#endif // COURGETTE_CRC_H_
......@@ -8,7 +8,11 @@
#include "courgette/difference_estimator.h"
#include <stddef.h>
#include <stdint.h>
#include "base/containers/hash_tables.h"
#include "base/macros.h"
namespace courgette {
......@@ -21,9 +25,9 @@ namespace {
static_assert(kTupleSize >= 4 && kTupleSize <= 8,
"kTupleSize should be between 4 and 8");
size_t HashTuple(const uint8* source) {
size_t hash1 = *reinterpret_cast<const uint32*>(source);
size_t hash2 = *reinterpret_cast<const uint32*>(source + kTupleSize - 4);
size_t HashTuple(const uint8_t* source) {
size_t hash1 = *reinterpret_cast<const uint32_t*>(source);
size_t hash2 = *reinterpret_cast<const uint32_t*>(source + kTupleSize - 4);
size_t hash = ((hash1 * 17 + hash2 * 37) + (hash1 >> 17)) ^ (hash2 >> 23);
return hash;
}
......@@ -43,9 +47,9 @@ class DifferenceEstimator::Base {
void Init() {
if (region_.length() < kTupleSize)
return;
const uint8* start = region_.start();
const uint8* end = region_.end() - (kTupleSize - 1);
for (const uint8* p = start; p < end; ++p) {
const uint8_t* start = region_.start();
const uint8_t* end = region_.end() - (kTupleSize - 1);
for (const uint8_t* p = start; p < end; ++p) {
size_t hash = HashTuple(p);
hashes_.insert(hash);
}
......@@ -99,10 +103,10 @@ DifferenceEstimator::Subject* DifferenceEstimator::MakeSubject(
size_t DifferenceEstimator::Measure(Base* base, Subject* subject) {