mirror of
https://github.com/google/brotli.git
synced 2024-11-08 13:20:05 +00:00
Fix CI build.
This commit is contained in:
parent
0747bda5e0
commit
db3a11625d
@ -4,7 +4,7 @@ include common/*.h
|
||||
include dec/*.c
|
||||
include dec/*.h
|
||||
include dec/Makefile
|
||||
include enc/*.cc
|
||||
include enc/*.c
|
||||
include enc/*.h
|
||||
include enc/Makefile
|
||||
include LICENSE
|
||||
|
@ -1,6 +1,7 @@
|
||||
#define PY_SSIZE_T_CLEAN 1
|
||||
#include <Python.h>
|
||||
#include <bytesobject.h>
|
||||
#include <vector>
|
||||
#include "../enc/encode.h"
|
||||
#include "../dec/decode.h"
|
||||
#include "../tools/version.h"
|
||||
@ -10,8 +11,6 @@
|
||||
#define PyInt_AsLong PyLong_AsLong
|
||||
#endif
|
||||
|
||||
using namespace brotli;
|
||||
|
||||
static PyObject *BrotliError;
|
||||
|
||||
static int as_bounded_int(PyObject *o, int* result, int lower_bound, int upper_bound) {
|
||||
@ -23,7 +22,7 @@ static int as_bounded_int(PyObject *o, int* result, int lower_bound, int upper_b
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mode_convertor(PyObject *o, BrotliParams::Mode *mode) {
|
||||
static int mode_convertor(PyObject *o, BrotliEncoderMode *mode) {
|
||||
if (!PyInt_Check(o)) {
|
||||
PyErr_SetString(BrotliError, "Invalid mode");
|
||||
return 0;
|
||||
@ -34,10 +33,10 @@ static int mode_convertor(PyObject *o, BrotliParams::Mode *mode) {
|
||||
PyErr_SetString(BrotliError, "Invalid mode");
|
||||
return 0;
|
||||
}
|
||||
*mode = (BrotliParams::Mode) mode_value;
|
||||
if (*mode != BrotliParams::MODE_GENERIC &&
|
||||
*mode != BrotliParams::MODE_TEXT &&
|
||||
*mode != BrotliParams::MODE_FONT) {
|
||||
*mode = (BrotliEncoderMode) mode_value;
|
||||
if (*mode != BROTLI_MODE_GENERIC &&
|
||||
*mode != BROTLI_MODE_TEXT &&
|
||||
*mode != BROTLI_MODE_FONT) {
|
||||
PyErr_SetString(BrotliError, "Invalid mode");
|
||||
return 0;
|
||||
}
|
||||
@ -116,9 +115,10 @@ PyDoc_STRVAR(compress__doc__,
|
||||
|
||||
static PyObject* brotli_compress(PyObject *self, PyObject *args, PyObject *keywds) {
|
||||
PyObject *ret = NULL;
|
||||
uint8_t *input, *output, *custom_dictionary;
|
||||
size_t length, output_length, custom_dictionary_length;
|
||||
BrotliParams::Mode mode = (BrotliParams::Mode) -1;
|
||||
uint8_t *input, *output = NULL, *custom_dictionary, *next_out;
|
||||
const uint8_t *next_in;
|
||||
size_t length, output_length, custom_dictionary_length, available_in, available_out;
|
||||
BrotliEncoderMode mode = (BrotliEncoderMode) -1;
|
||||
int quality = -1;
|
||||
int lgwin = -1;
|
||||
int lgblock = -1;
|
||||
@ -142,35 +142,37 @@ static PyObject* brotli_compress(PyObject *self, PyObject *args, PyObject *keywd
|
||||
return NULL;
|
||||
|
||||
output_length = length + (length >> 2) + 10240;
|
||||
BrotliEncoderState* enc = BrotliEncoderCreateInstance(0, 0, 0);
|
||||
if (!enc) {
|
||||
ok = false;
|
||||
goto end;
|
||||
}
|
||||
output = new uint8_t[output_length];
|
||||
|
||||
BrotliParams params;
|
||||
if ((int) mode != -1)
|
||||
params.mode = mode;
|
||||
BrotliEncoderSetParameter(enc, BROTLI_PARAM_MODE, (uint32_t)mode);
|
||||
if (quality != -1)
|
||||
params.quality = quality;
|
||||
BrotliEncoderSetParameter(enc, BROTLI_PARAM_QUALITY, (uint32_t)quality);
|
||||
if (lgwin != -1)
|
||||
params.lgwin = lgwin;
|
||||
BrotliEncoderSetParameter(enc, BROTLI_PARAM_LGWIN, (uint32_t)lgwin);
|
||||
if (lgblock != -1)
|
||||
params.lgblock = lgblock;
|
||||
BrotliEncoderSetParameter(enc, BROTLI_PARAM_LGBLOCK, (uint32_t)lgblock);
|
||||
|
||||
if (custom_dictionary_length == 0) {
|
||||
ok = BrotliCompressBuffer(params, length, input,
|
||||
&output_length, output);
|
||||
} else {
|
||||
uint8_t *custom_dictionary_start = custom_dictionary;
|
||||
BrotliMemIn in(input, length);
|
||||
BrotliMemOut out(output, output_length);
|
||||
size_t sliding_window_size = ((size_t)1) << params.lgwin;
|
||||
if (custom_dictionary_length > sliding_window_size) {
|
||||
custom_dictionary_start += custom_dictionary_length - sliding_window_size;
|
||||
custom_dictionary_length = sliding_window_size;
|
||||
}
|
||||
ok = BrotliCompressWithCustomDictionary(custom_dictionary_length,
|
||||
custom_dictionary_start, params, &in, &out);
|
||||
output_length = out.position();
|
||||
if (custom_dictionary_length != 0) {
|
||||
BrotliEncoderSetCustomDictionary(enc, custom_dictionary_length,
|
||||
custom_dictionary);
|
||||
}
|
||||
available_out = output_length;
|
||||
next_out = output;
|
||||
available_in = length;
|
||||
next_in = input;
|
||||
BrotliEncoderCompressStream(enc, BROTLI_OPERATION_FINISH,
|
||||
&available_in, &next_in,
|
||||
&available_out, &next_out, 0);
|
||||
ok = BrotliEncoderIsFinished(enc);
|
||||
|
||||
end:
|
||||
BrotliEncoderDestroyInstance(enc);
|
||||
if (ok) {
|
||||
ret = PyBytes_FromStringAndSize((char*)output, output_length);
|
||||
} else {
|
||||
@ -291,9 +293,9 @@ PyMODINIT_FUNC INIT_BROTLI(void) {
|
||||
PyModule_AddObject(m, "error", BrotliError);
|
||||
}
|
||||
|
||||
PyModule_AddIntConstant(m, "MODE_GENERIC", (int) BrotliParams::MODE_GENERIC);
|
||||
PyModule_AddIntConstant(m, "MODE_TEXT", (int) BrotliParams::MODE_TEXT);
|
||||
PyModule_AddIntConstant(m, "MODE_FONT", (int) BrotliParams::MODE_FONT);
|
||||
PyModule_AddIntConstant(m, "MODE_GENERIC", (int) BROTLI_MODE_GENERIC);
|
||||
PyModule_AddIntConstant(m, "MODE_TEXT", (int) BROTLI_MODE_TEXT);
|
||||
PyModule_AddIntConstant(m, "MODE_FONT", (int) BROTLI_MODE_FONT);
|
||||
|
||||
PyModule_AddStringConstant(m, "__version__", BROTLI_VERSION);
|
||||
|
||||
|
@ -12,7 +12,7 @@ testdata/alice29.txt
|
||||
testdata/asyoulik.txt
|
||||
testdata/lcet10.txt
|
||||
testdata/plrabn12.txt
|
||||
../enc/encode.cc
|
||||
../enc/encode.c
|
||||
../common/dictionary.h
|
||||
../dec/decode.c
|
||||
%s
|
||||
|
41
setup.py
41
setup.py
@ -126,19 +126,21 @@ brotli = Extension("brotli",
|
||||
"dec/decode.c",
|
||||
"dec/huffman.c",
|
||||
"dec/state.c",
|
||||
"enc/backward_references.cc",
|
||||
"enc/block_splitter.cc",
|
||||
"enc/brotli_bit_stream.cc",
|
||||
"enc/compress_fragment.cc",
|
||||
"enc/compress_fragment_two_pass.cc",
|
||||
"enc/encode.cc",
|
||||
"enc/entropy_encode.cc",
|
||||
"enc/histogram.cc",
|
||||
"enc/literal_cost.cc",
|
||||
"enc/metablock.cc",
|
||||
"enc/static_dict.cc",
|
||||
"enc/streams.cc",
|
||||
"enc/utf8_util.cc",
|
||||
"enc/backward_references.c",
|
||||
"enc/bit_cost.c",
|
||||
"enc/block_splitter.c",
|
||||
"enc/brotli_bit_stream.c",
|
||||
"enc/cluster.c",
|
||||
"enc/compress_fragment.c",
|
||||
"enc/compress_fragment_two_pass.c",
|
||||
"enc/encode.c",
|
||||
"enc/entropy_encode.c",
|
||||
"enc/histogram.c",
|
||||
"enc/literal_cost.c",
|
||||
"enc/memory.c",
|
||||
"enc/metablock.c",
|
||||
"enc/static_dict.c",
|
||||
"enc/utf8_util.c",
|
||||
],
|
||||
depends=[
|
||||
"common/constants.h",
|
||||
@ -155,13 +157,17 @@ brotli = Extension("brotli",
|
||||
"dec/streams.h",
|
||||
"dec/transform.h",
|
||||
"enc/backward_references.h",
|
||||
"enc/backward_references_inc.h",
|
||||
"enc/bit_cost.h",
|
||||
"enc/bit_cost_inc.h",
|
||||
"enc/block_splitter.h",
|
||||
"enc/block_splitter_inc.h",
|
||||
"enc/brotli_bit_stream.h",
|
||||
"enc/cluster.h",
|
||||
"enc/cluster_inc.h",
|
||||
"enc/command.h",
|
||||
"enc/compress_fragment.h",
|
||||
"enc/compress_fragment_tw_pass.h"
|
||||
"enc/compress_fragment_two_pass.h"
|
||||
"enc/context.h",
|
||||
"enc/dictionary_hash.h",
|
||||
"enc/encode.h",
|
||||
@ -170,16 +176,19 @@ brotli = Extension("brotli",
|
||||
"enc/fast_log.h",
|
||||
"enc/find_match_length.h",
|
||||
"enc/hash.h",
|
||||
"enc/hash_longest_match_inc.h",
|
||||
"enc/hash_longest_match_quickly_inc.h",
|
||||
"enc/histogram.h",
|
||||
"enc/histogram_inc.h",
|
||||
"enc/literal_cost.h",
|
||||
"enc/memory.h",
|
||||
"enc/metablock.h",
|
||||
"enc/metablock_inc.h",
|
||||
"enc/port.h",
|
||||
"enc/prefix.h",
|
||||
"enc/ringbuffer.h",
|
||||
"enc/static_dict.h",
|
||||
"enc/static_dict_lut.h",
|
||||
"enc/streams.h",
|
||||
"enc/transform.h",
|
||||
"enc/utf8_util.h",
|
||||
"enc/write_bits.h",
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user