aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoltan Szabadka <szabadka@google.com>2013-12-13 10:39:46 +0100
committerZoltan Szabadka <szabadka@google.com>2013-12-13 10:39:46 +0100
commit19320557a93cf81b778576ed046556e0702adbd1 (patch)
tree0b64abb2aca827fc232e635500244ed3667ce4b7
parent2e5995bd9628953ebd8bfdadbfbc3af0c8296167 (diff)
downloadsrc-19320557a93cf81b778576ed046556e0702adbd1.tar.gz
Fix Microsoft VisualStudio build of brotli
- Move all variable declarations to the beginning of the block - #ifdef-out read/write calls
-rw-r--r--brotli/dec/bit_reader.h3
-rw-r--r--brotli/dec/decode.c34
-rw-r--r--brotli/dec/huffman.c3
-rw-r--r--brotli/dec/streams.c14
4 files changed, 36 insertions, 18 deletions
diff --git a/brotli/dec/bit_reader.h b/brotli/dec/bit_reader.h
index a7ad460..96be036 100644
--- a/brotli/dec/bit_reader.h
+++ b/brotli/dec/bit_reader.h
@@ -149,8 +149,9 @@ static BROTLI_INLINE void BrotliFillBitWindow(BrotliBitReader* const br) {
// Requires that n_bits is positive.
static BROTLI_INLINE uint32_t BrotliReadBits(
BrotliBitReader* const br, int n_bits) {
+ uint32_t val;
BrotliFillBitWindow(br);
- const uint32_t val = (uint32_t)(br->val_ >> br->bit_pos_) & kBitMask[n_bits];
+ val = (uint32_t)(br->val_ >> br->bit_pos_) & kBitMask[n_bits];
#ifdef BROTLI_DECODE_DEBUG
printf("[BrotliReadBits] %010ld %2d val: %6x\n",
(br->pos_ << 3) + br->bit_pos_ - 64, n_bits, val);
diff --git a/brotli/dec/decode.c b/brotli/dec/decode.c
index df59463..ed9ef86 100644
--- a/brotli/dec/decode.c
+++ b/brotli/dec/decode.c
@@ -84,14 +84,15 @@ static void DecodeMetaBlockLength(BrotliBitReader* br,
size_t* meta_block_length,
int* input_end,
int* is_uncompressed) {
+ int size_nibbles;
+ int i;
*input_end = BrotliReadBits(br, 1);
*meta_block_length = 0;
*is_uncompressed = 0;
if (*input_end && BrotliReadBits(br, 1)) {
return;
}
- int size_nibbles = BrotliReadBits(br, 2) + 4;
- int i;
+ size_nibbles = BrotliReadBits(br, 2) + 4;
for (i = 0; i < size_nibbles; ++i) {
*meta_block_length |= BrotliReadBits(br, 4) << (i * 4);
}
@@ -104,13 +105,17 @@ static void DecodeMetaBlockLength(BrotliBitReader* br,
// Decodes the next Huffman code from bit-stream.
static BROTLI_INLINE int ReadSymbol(const HuffmanTree* tree,
BrotliBitReader* br) {
+ uint32_t bits;
+ int bitpos;
+ int lut_ix;
+ int lut_bits;
const HuffmanTreeNode* node = tree->root_;
BrotliFillBitWindow(br);
- uint32_t bits = BrotliPrefetchBits(br);
- int bitpos = br->bit_pos_;
+ bits = BrotliPrefetchBits(br);
+ bitpos = br->bit_pos_;
// Check if we find the bit combination from the Huffman lookup table.
- const int lut_ix = bits & (HUFF_LUT - 1);
- const int lut_bits = tree->lut_bits_[lut_ix];
+ lut_ix = bits & (HUFF_LUT - 1);
+ lut_bits = tree->lut_bits_[lut_ix];
if (lut_bits <= HUFF_LUT_BITS) {
BrotliSetBitPos(br, bitpos + lut_bits);
return tree->lut_symbol_[lut_ix];
@@ -587,13 +592,13 @@ int BrotliDecompressedSize(size_t encoded_size,
BrotliMemInput memin;
BrotliInput input = BrotliInitMemInput(encoded_buffer, encoded_size, &memin);
BrotliBitReader br;
+ size_t meta_block_len;
+ int input_end;
+ int is_uncompressed;
if (!BrotliInitBitReader(&br, input)) {
return 0;
}
DecodeWindowBits(&br);
- size_t meta_block_len;
- int input_end;
- int is_uncompressed;
DecodeMetaBlockLength(&br, &meta_block_len, &input_end, &is_uncompressed);
if (!input_end) {
return 0;
@@ -636,6 +641,10 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
HuffmanTreeGroup hgroup[3];
BrotliBitReader br;
+ static const int kRingBufferWriteAheadSlack = 16;
+
+ static const int kMaxDictionaryWordLength = 0;
+
if (!BrotliInitBitReader(&br, input)) {
return 0;
}
@@ -644,10 +653,6 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
window_bits = DecodeWindowBits(&br);
max_backward_distance = (1 << window_bits) - 16;
- static const int kRingBufferWriteAheadSlack = 16;
-
- static const int kMaxDictionaryWordLength = 0;
-
ringbuffer_size = 1 << window_bits;
ringbuffer_mask = ringbuffer_size - 1;
ringbuffer = (uint8_t*)malloc(ringbuffer_size +
@@ -848,6 +853,7 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
if (pos == meta_block_end_pos) break;
if (distance_code < 0) {
+ uint8_t context;
if (!BrotliReadMoreInput(&br)) {
printf("[BrotliDecompress] Unexpected end of input.\n");
ok = 0;
@@ -862,7 +868,7 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
dist_context_map_slice = dist_context_map + dist_context_offset;
}
--block_length[2];
- uint8_t context = copy_length > 4 ? 3 : copy_length - 2;
+ context = copy_length > 4 ? 3 : copy_length - 2;
dist_htree_index = dist_context_map_slice[context];
distance_code = ReadCopyDistance(&hgroup[2].htrees[dist_htree_index],
num_direct_distance_codes,
diff --git a/brotli/dec/huffman.c b/brotli/dec/huffman.c
index b24a760..6327792 100644
--- a/brotli/dec/huffman.c
+++ b/brotli/dec/huffman.c
@@ -154,8 +154,9 @@ static int TreeAddSymbol(HuffmanTree* const tree,
int i = 1 << (HUFF_LUT_BITS - code_length);
base_code = ReverseBitsShort(code, code_length);
do {
+ int idx;
--i;
- const int idx = base_code | (i << code_length);
+ idx = base_code | (i << code_length);
tree->lut_symbol_[idx] = (int16_t)symbol;
tree->lut_bits_[idx] = code_length;
} while (i > 0);
diff --git a/brotli/dec/streams.c b/brotli/dec/streams.c
index ac1a55d..2a34773 100644
--- a/brotli/dec/streams.c
+++ b/brotli/dec/streams.c
@@ -15,7 +15,9 @@
// Functions for streaming input and output.
#include <string.h>
+#ifndef _WIN32
#include <unistd.h>
+#endif
#include "./streams.h"
#if defined(__cplusplus) || defined(c_plusplus)
@@ -37,10 +39,10 @@ int BrotliMemInputFunction(void* data, uint8_t* buf, size_t count) {
BrotliInput BrotliInitMemInput(const uint8_t* buffer, size_t length,
BrotliMemInput* mem_input) {
+ BrotliInput input;
mem_input->buffer = buffer;
mem_input->length = length;
mem_input->pos = 0;
- BrotliInput input;
input.cb_ = &BrotliMemInputFunction;
input.data_ = mem_input;
return input;
@@ -58,17 +60,21 @@ int BrotliMemOutputFunction(void* data, const uint8_t* buf, size_t count) {
BrotliOutput BrotliInitMemOutput(uint8_t* buffer, size_t length,
BrotliMemOutput* mem_output) {
+ BrotliOutput output;
mem_output->buffer = buffer;
mem_output->length = length;
mem_output->pos = 0;
- BrotliOutput output;
output.cb_ = &BrotliMemOutputFunction;
output.data_ = mem_output;
return output;
}
int BrotliStdinInputFunction(void* data, uint8_t* buf, size_t count) {
+#ifndef _WIN32
return read(STDIN_FILENO, buf, count);
+#else
+ return -1;
+#endif
}
BrotliInput BrotliStdinInput() {
@@ -79,7 +85,11 @@ BrotliInput BrotliStdinInput() {
}
int BrotliStdoutOutputFunction(void* data, const uint8_t* buf, size_t count) {
+#ifndef _WIN32
return write(STDOUT_FILENO, buf, count);
+#else
+ return -1;
+#endif
}
BrotliOutput BrotliStdoutOutput() {