Fix Microsoft VisualStudio build of brotli
- Move all variable declarations to the beginning of the block - #ifdef-out read/write calls
This commit is contained in:
@@ -149,8 +149,9 @@ static BROTLI_INLINE void BrotliFillBitWindow(BrotliBitReader* const br) {
|
|||||||
// Requires that n_bits is positive.
|
// Requires that n_bits is positive.
|
||||||
static BROTLI_INLINE uint32_t BrotliReadBits(
|
static BROTLI_INLINE uint32_t BrotliReadBits(
|
||||||
BrotliBitReader* const br, int n_bits) {
|
BrotliBitReader* const br, int n_bits) {
|
||||||
|
uint32_t val;
|
||||||
BrotliFillBitWindow(br);
|
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
|
#ifdef BROTLI_DECODE_DEBUG
|
||||||
printf("[BrotliReadBits] %010ld %2d val: %6x\n",
|
printf("[BrotliReadBits] %010ld %2d val: %6x\n",
|
||||||
(br->pos_ << 3) + br->bit_pos_ - 64, n_bits, val);
|
(br->pos_ << 3) + br->bit_pos_ - 64, n_bits, val);
|
||||||
|
|||||||
+20
-14
@@ -84,14 +84,15 @@ static void DecodeMetaBlockLength(BrotliBitReader* br,
|
|||||||
size_t* meta_block_length,
|
size_t* meta_block_length,
|
||||||
int* input_end,
|
int* input_end,
|
||||||
int* is_uncompressed) {
|
int* is_uncompressed) {
|
||||||
|
int size_nibbles;
|
||||||
|
int i;
|
||||||
*input_end = BrotliReadBits(br, 1);
|
*input_end = BrotliReadBits(br, 1);
|
||||||
*meta_block_length = 0;
|
*meta_block_length = 0;
|
||||||
*is_uncompressed = 0;
|
*is_uncompressed = 0;
|
||||||
if (*input_end && BrotliReadBits(br, 1)) {
|
if (*input_end && BrotliReadBits(br, 1)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int size_nibbles = BrotliReadBits(br, 2) + 4;
|
size_nibbles = BrotliReadBits(br, 2) + 4;
|
||||||
int i;
|
|
||||||
for (i = 0; i < size_nibbles; ++i) {
|
for (i = 0; i < size_nibbles; ++i) {
|
||||||
*meta_block_length |= BrotliReadBits(br, 4) << (i * 4);
|
*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.
|
// Decodes the next Huffman code from bit-stream.
|
||||||
static BROTLI_INLINE int ReadSymbol(const HuffmanTree* tree,
|
static BROTLI_INLINE int ReadSymbol(const HuffmanTree* tree,
|
||||||
BrotliBitReader* br) {
|
BrotliBitReader* br) {
|
||||||
|
uint32_t bits;
|
||||||
|
int bitpos;
|
||||||
|
int lut_ix;
|
||||||
|
int lut_bits;
|
||||||
const HuffmanTreeNode* node = tree->root_;
|
const HuffmanTreeNode* node = tree->root_;
|
||||||
BrotliFillBitWindow(br);
|
BrotliFillBitWindow(br);
|
||||||
uint32_t bits = BrotliPrefetchBits(br);
|
bits = BrotliPrefetchBits(br);
|
||||||
int bitpos = br->bit_pos_;
|
bitpos = br->bit_pos_;
|
||||||
// Check if we find the bit combination from the Huffman lookup table.
|
// Check if we find the bit combination from the Huffman lookup table.
|
||||||
const int lut_ix = bits & (HUFF_LUT - 1);
|
lut_ix = bits & (HUFF_LUT - 1);
|
||||||
const int lut_bits = tree->lut_bits_[lut_ix];
|
lut_bits = tree->lut_bits_[lut_ix];
|
||||||
if (lut_bits <= HUFF_LUT_BITS) {
|
if (lut_bits <= HUFF_LUT_BITS) {
|
||||||
BrotliSetBitPos(br, bitpos + lut_bits);
|
BrotliSetBitPos(br, bitpos + lut_bits);
|
||||||
return tree->lut_symbol_[lut_ix];
|
return tree->lut_symbol_[lut_ix];
|
||||||
@@ -587,13 +592,13 @@ int BrotliDecompressedSize(size_t encoded_size,
|
|||||||
BrotliMemInput memin;
|
BrotliMemInput memin;
|
||||||
BrotliInput input = BrotliInitMemInput(encoded_buffer, encoded_size, &memin);
|
BrotliInput input = BrotliInitMemInput(encoded_buffer, encoded_size, &memin);
|
||||||
BrotliBitReader br;
|
BrotliBitReader br;
|
||||||
|
size_t meta_block_len;
|
||||||
|
int input_end;
|
||||||
|
int is_uncompressed;
|
||||||
if (!BrotliInitBitReader(&br, input)) {
|
if (!BrotliInitBitReader(&br, input)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DecodeWindowBits(&br);
|
DecodeWindowBits(&br);
|
||||||
size_t meta_block_len;
|
|
||||||
int input_end;
|
|
||||||
int is_uncompressed;
|
|
||||||
DecodeMetaBlockLength(&br, &meta_block_len, &input_end, &is_uncompressed);
|
DecodeMetaBlockLength(&br, &meta_block_len, &input_end, &is_uncompressed);
|
||||||
if (!input_end) {
|
if (!input_end) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -636,6 +641,10 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
|
|||||||
HuffmanTreeGroup hgroup[3];
|
HuffmanTreeGroup hgroup[3];
|
||||||
BrotliBitReader br;
|
BrotliBitReader br;
|
||||||
|
|
||||||
|
static const int kRingBufferWriteAheadSlack = 16;
|
||||||
|
|
||||||
|
static const int kMaxDictionaryWordLength = 0;
|
||||||
|
|
||||||
if (!BrotliInitBitReader(&br, input)) {
|
if (!BrotliInitBitReader(&br, input)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -644,10 +653,6 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
|
|||||||
window_bits = DecodeWindowBits(&br);
|
window_bits = DecodeWindowBits(&br);
|
||||||
max_backward_distance = (1 << window_bits) - 16;
|
max_backward_distance = (1 << window_bits) - 16;
|
||||||
|
|
||||||
static const int kRingBufferWriteAheadSlack = 16;
|
|
||||||
|
|
||||||
static const int kMaxDictionaryWordLength = 0;
|
|
||||||
|
|
||||||
ringbuffer_size = 1 << window_bits;
|
ringbuffer_size = 1 << window_bits;
|
||||||
ringbuffer_mask = ringbuffer_size - 1;
|
ringbuffer_mask = ringbuffer_size - 1;
|
||||||
ringbuffer = (uint8_t*)malloc(ringbuffer_size +
|
ringbuffer = (uint8_t*)malloc(ringbuffer_size +
|
||||||
@@ -848,6 +853,7 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
|
|||||||
if (pos == meta_block_end_pos) break;
|
if (pos == meta_block_end_pos) break;
|
||||||
|
|
||||||
if (distance_code < 0) {
|
if (distance_code < 0) {
|
||||||
|
uint8_t context;
|
||||||
if (!BrotliReadMoreInput(&br)) {
|
if (!BrotliReadMoreInput(&br)) {
|
||||||
printf("[BrotliDecompress] Unexpected end of input.\n");
|
printf("[BrotliDecompress] Unexpected end of input.\n");
|
||||||
ok = 0;
|
ok = 0;
|
||||||
@@ -862,7 +868,7 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
|
|||||||
dist_context_map_slice = dist_context_map + dist_context_offset;
|
dist_context_map_slice = dist_context_map + dist_context_offset;
|
||||||
}
|
}
|
||||||
--block_length[2];
|
--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];
|
dist_htree_index = dist_context_map_slice[context];
|
||||||
distance_code = ReadCopyDistance(&hgroup[2].htrees[dist_htree_index],
|
distance_code = ReadCopyDistance(&hgroup[2].htrees[dist_htree_index],
|
||||||
num_direct_distance_codes,
|
num_direct_distance_codes,
|
||||||
|
|||||||
@@ -154,8 +154,9 @@ static int TreeAddSymbol(HuffmanTree* const tree,
|
|||||||
int i = 1 << (HUFF_LUT_BITS - code_length);
|
int i = 1 << (HUFF_LUT_BITS - code_length);
|
||||||
base_code = ReverseBitsShort(code, code_length);
|
base_code = ReverseBitsShort(code, code_length);
|
||||||
do {
|
do {
|
||||||
|
int idx;
|
||||||
--i;
|
--i;
|
||||||
const int idx = base_code | (i << code_length);
|
idx = base_code | (i << code_length);
|
||||||
tree->lut_symbol_[idx] = (int16_t)symbol;
|
tree->lut_symbol_[idx] = (int16_t)symbol;
|
||||||
tree->lut_bits_[idx] = code_length;
|
tree->lut_bits_[idx] = code_length;
|
||||||
} while (i > 0);
|
} while (i > 0);
|
||||||
|
|||||||
+12
-2
@@ -15,7 +15,9 @@
|
|||||||
// Functions for streaming input and output.
|
// Functions for streaming input and output.
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef _WIN32
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
#include "./streams.h"
|
#include "./streams.h"
|
||||||
|
|
||||||
#if defined(__cplusplus) || defined(c_plusplus)
|
#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,
|
BrotliInput BrotliInitMemInput(const uint8_t* buffer, size_t length,
|
||||||
BrotliMemInput* mem_input) {
|
BrotliMemInput* mem_input) {
|
||||||
|
BrotliInput input;
|
||||||
mem_input->buffer = buffer;
|
mem_input->buffer = buffer;
|
||||||
mem_input->length = length;
|
mem_input->length = length;
|
||||||
mem_input->pos = 0;
|
mem_input->pos = 0;
|
||||||
BrotliInput input;
|
|
||||||
input.cb_ = &BrotliMemInputFunction;
|
input.cb_ = &BrotliMemInputFunction;
|
||||||
input.data_ = mem_input;
|
input.data_ = mem_input;
|
||||||
return 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,
|
BrotliOutput BrotliInitMemOutput(uint8_t* buffer, size_t length,
|
||||||
BrotliMemOutput* mem_output) {
|
BrotliMemOutput* mem_output) {
|
||||||
|
BrotliOutput output;
|
||||||
mem_output->buffer = buffer;
|
mem_output->buffer = buffer;
|
||||||
mem_output->length = length;
|
mem_output->length = length;
|
||||||
mem_output->pos = 0;
|
mem_output->pos = 0;
|
||||||
BrotliOutput output;
|
|
||||||
output.cb_ = &BrotliMemOutputFunction;
|
output.cb_ = &BrotliMemOutputFunction;
|
||||||
output.data_ = mem_output;
|
output.data_ = mem_output;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BrotliStdinInputFunction(void* data, uint8_t* buf, size_t count) {
|
int BrotliStdinInputFunction(void* data, uint8_t* buf, size_t count) {
|
||||||
|
#ifndef _WIN32
|
||||||
return read(STDIN_FILENO, buf, count);
|
return read(STDIN_FILENO, buf, count);
|
||||||
|
#else
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
BrotliInput BrotliStdinInput() {
|
BrotliInput BrotliStdinInput() {
|
||||||
@@ -79,7 +85,11 @@ BrotliInput BrotliStdinInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int BrotliStdoutOutputFunction(void* data, const uint8_t* buf, size_t count) {
|
int BrotliStdoutOutputFunction(void* data, const uint8_t* buf, size_t count) {
|
||||||
|
#ifndef _WIN32
|
||||||
return write(STDOUT_FILENO, buf, count);
|
return write(STDOUT_FILENO, buf, count);
|
||||||
|
#else
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
BrotliOutput BrotliStdoutOutput() {
|
BrotliOutput BrotliStdoutOutput() {
|
||||||
|
|||||||
Reference in New Issue
Block a user