Fix VS compilation warnings; cleanup API.
diff --git a/enc/brotli_bit_stream.c b/enc/brotli_bit_stream.c
index 9b755f2..a58199e 100644
--- a/enc/brotli_bit_stream.c
+++ b/enc/brotli_bit_stream.c
@@ -122,7 +122,7 @@
size_t nbits = Log2FloorNonZero(n);
BrotliWriteBits(1, 1, storage_ix, storage);
BrotliWriteBits(3, nbits, storage_ix, storage);
- BrotliWriteBits(nbits, n - (1u << nbits), storage_ix, storage);
+ BrotliWriteBits(nbits, n - ((size_t)1 << nbits), storage_ix, storage);
}
}
diff --git a/enc/compress_fragment.c b/enc/compress_fragment.c
index d69cc66..061e4a9 100644
--- a/enc/compress_fragment.c
+++ b/enc/compress_fragment.c
@@ -194,7 +194,7 @@
const uint32_t nbits = Log2FloorNonZero(tail);
const size_t code = nbits + 50;
BrotliWriteBits(depth[code], bits[code], storage_ix, storage);
- BrotliWriteBits(nbits, tail - (1u << nbits), storage_ix, storage);
+ BrotliWriteBits(nbits, tail - ((size_t)1 << nbits), storage_ix, storage);
++histo[code];
} else {
BrotliWriteBits(depth[61], bits[61], storage_ix, storage);
@@ -243,7 +243,7 @@
const uint32_t nbits = Log2FloorNonZero(tail);
const size_t code = nbits + 28;
BrotliWriteBits(depth[code], bits[code], storage_ix, storage);
- BrotliWriteBits(nbits, tail - (1u << nbits), storage_ix, storage);
+ BrotliWriteBits(nbits, tail - ((size_t)1 << nbits), storage_ix, storage);
++histo[code];
} else {
BrotliWriteBits(depth[39], bits[39], storage_ix, storage);
@@ -282,7 +282,7 @@
const uint32_t nbits = Log2FloorNonZero(tail);
const size_t code = nbits + 28;
BrotliWriteBits(depth[code], bits[code], storage_ix, storage);
- BrotliWriteBits(nbits, tail - (1u << nbits), storage_ix, storage);
+ BrotliWriteBits(nbits, tail - ((size_t)1 << nbits), storage_ix, storage);
BrotliWriteBits(depth[64], bits[64], storage_ix, storage);
++histo[code];
++histo[64];
diff --git a/enc/compress_fragment_two_pass.c b/enc/compress_fragment_two_pass.c
index 3eb1f94..acb9851 100644
--- a/enc/compress_fragment_two_pass.c
+++ b/enc/compress_fragment_two_pass.c
@@ -153,7 +153,7 @@
const size_t tail = copylen - 70;
const size_t nbits = Log2FloorNonZero(tail);
const size_t code = nbits + 52;
- const size_t extra = tail - (1u << nbits);
+ const size_t extra = tail - ((size_t)1 << nbits);
**commands = (uint32_t)(code | (extra << 8));
} else {
const size_t extra = copylen - 2118;
@@ -187,7 +187,7 @@
const size_t tail = copylen - 72;
const size_t nbits = Log2FloorNonZero(tail);
const size_t code = nbits + 52;
- const size_t extra = tail - (1u << nbits);
+ const size_t extra = tail - ((size_t)1 << nbits);
**commands = (uint32_t)(code | (extra << 8));
++(*commands);
**commands = 64;
diff --git a/enc/compressor.cc b/enc/compressor.cc
index c53e4b3..6c77698 100644
--- a/enc/compressor.cc
+++ b/enc/compressor.cc
@@ -12,26 +12,28 @@
namespace brotli {
-static void ConvertParams(const BrotliParams* from, BrotliEncoderParams* to) {
- BrotliEncoderParamsSetDefault(to);
+static void SetParams(const BrotliParams* from, BrotliEncoderState* to) {
+ BrotliEncoderMode mode = BROTLI_MODE_GENERIC;
if (from->mode == BrotliParams::MODE_TEXT) {
- to->mode = BROTLI_MODE_TEXT;
+ mode = BROTLI_MODE_TEXT;
} else if (from->mode == BrotliParams::MODE_FONT) {
- to->mode = BROTLI_MODE_FONT;
+ mode = BROTLI_MODE_FONT;
}
- to->quality = from->quality;
- to->lgwin = from->lgwin;
- to->lgblock = from->lgblock;
+ BrotliEncoderSetParameter(to, BROTLI_PARAM_MODE, (uint32_t)mode);
+ BrotliEncoderSetParameter(to, BROTLI_PARAM_QUALITY, (uint32_t)from->quality);
+ BrotliEncoderSetParameter(to, BROTLI_PARAM_LGWIN, (uint32_t)from->lgwin);
+ BrotliEncoderSetParameter(to, BROTLI_PARAM_LGBLOCK, (uint32_t)from->lgblock);
}
BrotliCompressor::BrotliCompressor(BrotliParams params) {
- BrotliEncoderParams encoder_params;
- ConvertParams(¶ms, &encoder_params);
- state_ = BrotliEncoderCreateState(&encoder_params, 0, 0, 0);
+ state_ = BrotliEncoderCreateInstance(0, 0, 0);
if (state_ == 0) std::exit(EXIT_FAILURE); /* OOM */
+ SetParams(¶ms, state_);
}
-BrotliCompressor::~BrotliCompressor(void) { BrotliEncoderDestroyState(state_); }
+BrotliCompressor::~BrotliCompressor(void) {
+ BrotliEncoderDestroyInstance(state_);
+}
bool BrotliCompressor::WriteMetaBlock(const size_t input_size,
const uint8_t* input_buffer,
@@ -95,12 +97,11 @@
const uint8_t* next_in = NULL;
size_t total_out = 0;
bool end_of_input = false;
- BrotliEncoderParams encoder_params;
BrotliEncoderState* s;
- ConvertParams(¶ms, &encoder_params);
- s = BrotliEncoderCreateState(&encoder_params, 0, 0, 0);
+ s = BrotliEncoderCreateInstance(0, 0, 0);
if (!s) return 0;
+ SetParams(¶ms, s);
BrotliEncoderSetCustomDictionary(s, dictsize, dict);
output_buffer = new uint8_t[kOutputBufferSize];
@@ -130,7 +131,7 @@
}
delete[] output_buffer;
- BrotliEncoderDestroyState(s);
+ BrotliEncoderDestroyInstance(s);
return result ? 1 : 0;
}
diff --git a/enc/encode.c b/enc/encode.c
index d234213..cffc4fb 100644
--- a/enc/encode.c
+++ b/enc/encode.c
@@ -42,7 +42,8 @@
#define COPY_ARRAY(dst, src) memcpy(dst, src, sizeof(src));
-void BrotliEncoderParamsSetDefault(BrotliEncoderParams* self) {
+static void BrotliEncoderParamsSetDefault(
+ BrotliEncoderParams* self) {
self->mode = BROTLI_DEFAULT_MODE;
self->quality = BROTLI_DEFAULT_QUALITY;
self->lgwin = BROTLI_DEFAULT_WINDOW;
@@ -118,7 +119,7 @@
size_t BrotliEncoderInputBlockSize(BrotliEncoderState* s) {
if (!EnsureInitialized(s)) return 0;
- return 1u << s->params_.lgblock;
+ return (size_t)1 << s->params_.lgblock;
}
static uint64_t UnprocessedInputSize(BrotliEncoderState* s) {
@@ -761,7 +762,7 @@
}
}
-void BrotliEncoderSetCustomDictionary(BrotliEncoderState* s, const size_t size,
+void BrotliEncoderSetCustomDictionary(BrotliEncoderState* s, size_t size,
const uint8_t* dict) {
size_t max_dict_size = MaxBackwardLimit(s->params_.lgwin);
size_t dict_size = size;
@@ -894,7 +895,8 @@
&s->num_literals_);
if (BROTLI_IS_OOM(m)) return 0;
- max_length = BROTLI_MIN(size_t, mask + 1, 1u << kBrotliMaxInputBlockBits);
+ max_length =
+ BROTLI_MIN(size_t, mask + 1, (size_t)1 << kBrotliMaxInputBlockBits);
{
const size_t max_literals = max_length / 8;
const size_t max_commands = max_length / 8;
@@ -1291,7 +1293,6 @@
size_t* encoded_size,
uint8_t* encoded_buffer) {
BrotliEncoderState* s;
- BrotliEncoderParams params;
size_t out_size = *encoded_size;
const uint8_t* input_start = input_buffer;
uint8_t* output_start = encoded_buffer;
@@ -1317,11 +1318,7 @@
return 1;
}
- BrotliEncoderParamsSetDefault(¶ms);
- params.quality = quality;
- params.lgwin = lgwin;
- params.mode = mode;
- s = BrotliEncoderCreateState(¶ms, 0, 0, 0);
+ s = BrotliEncoderCreateInstance(0, 0, 0);
if (!s) {
return 0;
} else {
@@ -1330,11 +1327,15 @@
size_t available_out = *encoded_size;
uint8_t* next_out = encoded_buffer;
size_t total_out = 0;
- int result = BrotliEncoderCompressStream(s, BROTLI_OPERATION_FINISH,
+ int result = 0;
+ BrotliEncoderSetParameter(s, BROTLI_PARAM_QUALITY, (uint32_t)quality);
+ BrotliEncoderSetParameter(s, BROTLI_PARAM_LGWIN, (uint32_t)lgwin);
+ BrotliEncoderSetParameter(s, BROTLI_PARAM_MODE, (uint32_t)mode);
+ result = BrotliEncoderCompressStream(s, BROTLI_OPERATION_FINISH,
&available_in, &next_in, &available_out, &next_out, &total_out);
if (!BrotliEncoderIsFinished(s)) result = 0;
*encoded_size = total_out;
- BrotliEncoderDestroyState(s);
+ BrotliEncoderDestroyInstance(s);
if (!result || (max_out_size && *encoded_size > max_out_size)) {
goto fallback;
}
@@ -1369,7 +1370,7 @@
BrotliEncoderState* s, BrotliEncoderOperation op, size_t* available_in,
const uint8_t** next_in, size_t* available_out, uint8_t** next_out,
size_t* total_out) {
- const size_t block_size_limit = 1u << s->params_.lgwin;
+ const size_t block_size_limit = (size_t)1 << s->params_.lgwin;
const size_t buf_size = BROTLI_MIN(size_t, kCompressFragmentTwoPassBlockSize,
BROTLI_MIN(size_t, *available_in, block_size_limit));
uint32_t* tmp_command_buf = NULL;
diff --git a/enc/encode.h b/enc/encode.h
index a99f5c8..87d24ab 100644
--- a/enc/encode.h
+++ b/enc/encode.h
@@ -69,9 +69,6 @@
BROTLI_PARAM_LGBLOCK = 3
} BrotliEncoderParameter;
-/* DEPRECATED */
-void BrotliEncoderParamsSetDefault(BrotliEncoderParams* params);
-
/* A state can not be reused for multiple brotli streams. */
typedef struct BrotliEncoderStateStruct BrotliEncoderState;
@@ -85,30 +82,9 @@
BrotliEncoderState* BrotliEncoderCreateInstance(brotli_alloc_func alloc_func,
brotli_free_func free_func,
void* opaque);
-/* DEPRECATED */
-static inline BrotliEncoderState* BrotliEncoderCreateState(
- const BrotliEncoderParams* params, brotli_alloc_func alloc_func,
- brotli_free_func free_func, void* opaque) {
- BrotliEncoderState* result = BrotliEncoderCreateInstance(
- alloc_func, free_func, opaque);
- if (!result) return result;
- BrotliEncoderSetParameter(
- result, BROTLI_PARAM_MODE, (uint32_t)params->mode);
- BrotliEncoderSetParameter(
- result, BROTLI_PARAM_QUALITY, (uint32_t)params->quality);
- BrotliEncoderSetParameter(
- result, BROTLI_PARAM_LGWIN, (uint32_t)params->lgwin);
- BrotliEncoderSetParameter(
- result, BROTLI_PARAM_LGBLOCK, (uint32_t)params->lgblock);
- return result;
-}
/* Deinitializes and frees BrotliEncoderState instance. */
void BrotliEncoderDestroyInstance(BrotliEncoderState* state);
-/* DEPRECATED */
-static inline void BrotliEncoderDestroyState(BrotliEncoderState* state) {
- BrotliEncoderDestroyInstance(state);
-}
/* The maximum input size that can be processed at once. */
size_t BrotliEncoderInputBlockSize(BrotliEncoderState* state);
diff --git a/enc/entropy_encode.c b/enc/entropy_encode.c
index 1c110c2..29ceabf 100644
--- a/enc/entropy_encode.c
+++ b/enc/entropy_encode.c
@@ -42,8 +42,8 @@
}
/* Sort the root nodes, least popular first. */
-static inline int SortHuffmanTree(const HuffmanTree* v0,
- const HuffmanTree* v1) {
+static BROTLI_INLINE int SortHuffmanTree(const HuffmanTree* v0,
+ const HuffmanTree* v1) {
if (v0->total_count_ != v1->total_count_) {
return (v0->total_count_ < v1->total_count_) ? 1 : 0;
}
@@ -463,7 +463,7 @@
bits = (uint16_t)(bits >> 4);
retval |= kLut[bits & 0xf];
}
- retval >>= (-num_bits & 0x3);
+ retval >>= ((0 - num_bits) & 0x3);
return (uint16_t)retval;
}
diff --git a/enc/memory.c b/enc/memory.c
index de4a649..1d977d4 100644
--- a/enc/memory.c
+++ b/enc/memory.c
@@ -11,7 +11,7 @@
#include <assert.h>
#include <stdlib.h> /* exit, free, malloc */
-#include <strings.h> /* memcpy */
+#include <string.h> /* memcpy */
#include "../common/types.h"
#include "./port.h"
diff --git a/enc/static_dict.c b/enc/static_dict.c
index 1b52dea..cfc12d0 100644
--- a/enc/static_dict.c
+++ b/enc/static_dict.c
@@ -90,7 +90,7 @@
for (i = 0; i < num; ++i) {
const DictWord w = kStaticDictionaryWords[offset + i];
const size_t l = w.len;
- const size_t n = 1u << kBrotliDictionarySizeBitsByLength[l];
+ const size_t n = (size_t)1 << kBrotliDictionarySizeBitsByLength[l];
const size_t id = w.idx;
if (w.transform == 0) {
const size_t matchlen = DictMatchLength(data, id, l, max_length);
@@ -329,7 +329,7 @@
for (i = 0; i < num; ++i) {
const DictWord w = kStaticDictionaryWords[offset + i];
const size_t l = w.len;
- const size_t n = 1u << kBrotliDictionarySizeBitsByLength[l];
+ const size_t n = (size_t)1 << kBrotliDictionarySizeBitsByLength[l];
const size_t id = w.idx;
if (w.transform == 0) {
const uint8_t* s;
@@ -421,7 +421,7 @@
for (i = 0; i < num; ++i) {
const DictWord w = kStaticDictionaryWords[offset + i];
const size_t l = w.len;
- const size_t n = 1u << kBrotliDictionarySizeBitsByLength[l];
+ const size_t n = (size_t)1 << kBrotliDictionarySizeBitsByLength[l];
const size_t id = w.idx;
if (w.transform == 0 && IsMatch(w, &data[2], max_length - 2)) {
if (data[0] == 0xc2) {
@@ -450,7 +450,7 @@
for (i = 0; i < num; ++i) {
const DictWord w = kStaticDictionaryWords[offset + i];
const size_t l = w.len;
- const size_t n = 1u << kBrotliDictionarySizeBitsByLength[l];
+ const size_t n = (size_t)1 << kBrotliDictionarySizeBitsByLength[l];
const size_t id = w.idx;
if (w.transform == 0 && IsMatch(w, &data[5], max_length - 5)) {
AddMatch(id + (data[0] == ' ' ? 41 : 72) * n, l + 5, l, matches);