mirror of
https://github.com/facebook/zstd.git
synced 2025-11-28 00:04:28 -05:00
Fix longmatch test build errors.
This commit is contained in:
parent
5cc85cf183
commit
b547d212a1
@ -6,29 +6,35 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void compress(ZSTD_CStream *ctx, ZSTD_outBuffer out, const void *data, size_t size) {
|
int compress(ZSTD_CStream *ctx, ZSTD_outBuffer out, const void *data, size_t size) {
|
||||||
ZSTD_inBuffer in = { data, size, 0 };
|
ZSTD_inBuffer in = { data, size, 0 };
|
||||||
while (in.pos < in.size) {
|
while (in.pos < in.size) {
|
||||||
ZSTD_outBuffer tmp = out;
|
ZSTD_outBuffer tmp = out;
|
||||||
const size_t rc = ZSTD_compressStream(ctx, &tmp, &in);
|
const size_t rc = ZSTD_compressStream(ctx, &tmp, &in);
|
||||||
if (ZSTD_isError(rc)) {
|
if (ZSTD_isError(rc)) {
|
||||||
exit(5);
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
ZSTD_outBuffer tmp = out;
|
ZSTD_outBuffer tmp = out;
|
||||||
const size_t rc = ZSTD_flushStream(ctx, &tmp);
|
const size_t rc = ZSTD_flushStream(ctx, &tmp);
|
||||||
if (rc != 0) { exit(6); }
|
if (rc != 0) { return 1; }
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main(int argc, const char** argv) {
|
||||||
ZSTD_CStream *ctx;
|
ZSTD_CStream *ctx;
|
||||||
ZSTD_parameters params = {};
|
ZSTD_parameters params;
|
||||||
size_t rc;
|
size_t rc;
|
||||||
unsigned windowLog;
|
unsigned windowLog;
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
/* Create stream */
|
/* Create stream */
|
||||||
ctx = ZSTD_createCStream();
|
ctx = ZSTD_createCStream();
|
||||||
if (!ctx) { return 1; }
|
if (!ctx) { return 1; }
|
||||||
/* Set parameters */
|
/* Set parameters */
|
||||||
|
memset(¶ms, 0, sizeof(params));
|
||||||
params.cParams.windowLog = 18;
|
params.cParams.windowLog = 18;
|
||||||
params.cParams.chainLog = 13;
|
params.cParams.chainLog = 13;
|
||||||
params.cParams.hashLog = 14;
|
params.cParams.hashLog = 14;
|
||||||
@ -50,25 +56,31 @@ int main() {
|
|||||||
ZSTD_outBuffer out = { dstBuffer, ZSTD_compressBound(1 << windowLog), 0 };
|
ZSTD_outBuffer out = { dstBuffer, ZSTD_compressBound(1 << windowLog), 0 };
|
||||||
const char match[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
const char match[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
const size_t randomData = (1 << windowLog) - 2*sizeof(match);
|
const size_t randomData = (1 << windowLog) - 2*sizeof(match);
|
||||||
for (size_t i = 0; i < sizeof(match); ++i) {
|
size_t i;
|
||||||
|
for (i = 0; i < sizeof(match); ++i) {
|
||||||
srcBuffer[i] = match[i];
|
srcBuffer[i] = match[i];
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < randomData; ++i) {
|
for (i = 0; i < randomData; ++i) {
|
||||||
srcBuffer[sizeof(match) + i] = (char)(rand() & 0xFF);
|
srcBuffer[sizeof(match) + i] = (char)(rand() & 0xFF);
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < sizeof(match); ++i) {
|
for (i = 0; i < sizeof(match); ++i) {
|
||||||
srcBuffer[sizeof(match) + randomData + i] = match[i];
|
srcBuffer[sizeof(match) + randomData + i] = match[i];
|
||||||
}
|
}
|
||||||
compress(ctx, out, srcBuffer, size);
|
if (compress(ctx, out, srcBuffer, size)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
compressed += size;
|
compressed += size;
|
||||||
while (compressed < toCompress) {
|
while (compressed < toCompress) {
|
||||||
const size_t block = rand() % (size - pos + 1);
|
const size_t block = rand() % (size - pos + 1);
|
||||||
if (pos == size) { pos = 0; }
|
if (pos == size) { pos = 0; }
|
||||||
compress(ctx, out, srcBuffer + pos, block);
|
if (compress(ctx, out, srcBuffer + pos, block)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
pos += block;
|
pos += block;
|
||||||
compressed += block;
|
compressed += block;
|
||||||
}
|
}
|
||||||
free(srcBuffer);
|
free(srcBuffer);
|
||||||
free(dstBuffer);
|
free(dstBuffer);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user