mirror of
https://github.com/facebook/zstd.git
synced 2025-08-07 06:23:00 +03:00
zlibWrapped: removed dependency from ZSTD_FRAMEHEADERSIZE_MIN
This commit is contained in:
@@ -22,7 +22,7 @@ LDFLAGS = $(LOC)
|
|||||||
RM = rm -f
|
RM = rm -f
|
||||||
|
|
||||||
|
|
||||||
all: clean test testdll
|
all: clean test testdll testzstd
|
||||||
|
|
||||||
test: example
|
test: example
|
||||||
./example
|
./example
|
||||||
@@ -30,6 +30,9 @@ test: example
|
|||||||
testdll: example_d
|
testdll: example_d
|
||||||
./example_d
|
./example_d
|
||||||
|
|
||||||
|
testzstd: example_zstd
|
||||||
|
./example_zstd
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
@@ -39,12 +42,18 @@ example: $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o
|
|||||||
example_d: $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o
|
example_d: $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o
|
||||||
$(CC) $(LDFLAGS) -o $@ $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(IMPLIB)
|
$(CC) $(LDFLAGS) -o $@ $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(IMPLIB)
|
||||||
|
|
||||||
|
example_zstd: $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o
|
||||||
|
$(CC) $(LDFLAGS) -o $@ $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o $(STATICLIB)
|
||||||
|
|
||||||
$(EXAMPLE_PATH)/example.o: $(EXAMPLE_PATH)/example.c
|
$(EXAMPLE_PATH)/example.o: $(EXAMPLE_PATH)/example.c
|
||||||
$(CC) $(CFLAGS) -I. -c -o $@ $(EXAMPLE_PATH)/example.c
|
$(CC) $(CFLAGS) -I. -c -o $@ $(EXAMPLE_PATH)/example.c
|
||||||
|
|
||||||
$(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o: $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.h
|
$(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o: $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.h
|
||||||
$(CC) $(CFLAGS) -I. -c -o $@ $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c
|
$(CC) $(CFLAGS) -I. -c -o $@ $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c
|
||||||
|
|
||||||
|
$(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o: $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.h
|
||||||
|
$(CC) $(CFLAGS) -DZWRAP_USE_ZSTD=1 -I. -c -o $@ $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-$(RM) $(ZLIBWRAPPER_PATH)/*.o
|
-$(RM) $(ZLIBWRAPPER_PATH)/*.o
|
||||||
-$(RM) $(EXAMPLE_PATH)/*.o
|
-$(RM) $(EXAMPLE_PATH)/*.o
|
||||||
|
@@ -35,17 +35,17 @@
|
|||||||
#include "zstd_zlibwrapper.h"
|
#include "zstd_zlibwrapper.h"
|
||||||
#include "zstd.h"
|
#include "zstd.h"
|
||||||
#include "zstd_static.h" /* ZSTD_MAGICNUMBER */
|
#include "zstd_static.h" /* ZSTD_MAGICNUMBER */
|
||||||
#include "zstd_internal.h" /* MIN */
|
|
||||||
#include "zbuff.h"
|
#include "zbuff.h"
|
||||||
|
|
||||||
|
|
||||||
#define Z_INFLATE_SYNC 8
|
#define Z_INFLATE_SYNC 8
|
||||||
#define ZWRAP_HEADERSIZE 4
|
#define ZWRAP_HEADERSIZE 4
|
||||||
#define ZSTD_FRAMEHEADERSIZE_MIN 5
|
|
||||||
|
|
||||||
#define LOG_WRAPPER(...) // printf(__VA_ARGS__)
|
#define LOG_WRAPPER(...) // printf(__VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
|
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||||
|
|
||||||
#define FINISH_WITH_ERR(msg) { \
|
#define FINISH_WITH_ERR(msg) { \
|
||||||
fprintf(stderr, "ERROR: %s\n", msg); \
|
fprintf(stderr, "ERROR: %s\n", msg); \
|
||||||
return Z_MEM_ERROR; \
|
return Z_MEM_ERROR; \
|
||||||
@@ -253,9 +253,8 @@ ZEXTERN int ZEXPORT z_deflateParams OF((z_streamp strm,
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ZBUFF_DCtx* zbd;
|
ZBUFF_DCtx* zbd;
|
||||||
char headerBuf[ZSTD_FRAMEHEADERSIZE_MIN];
|
char headerBuf[ZWRAP_HEADERSIZE];
|
||||||
int errorCount;
|
int errorCount;
|
||||||
int requiredHeaderSize;
|
|
||||||
|
|
||||||
/* zlib params */
|
/* zlib params */
|
||||||
int stream_size;
|
int stream_size;
|
||||||
@@ -298,7 +297,6 @@ ZEXTERN int ZEXPORT z_inflateInit_ OF((z_streamp strm,
|
|||||||
zwd->zalloc = strm->zalloc;
|
zwd->zalloc = strm->zalloc;
|
||||||
zwd->zfree = strm->zfree;
|
zwd->zfree = strm->zfree;
|
||||||
zwd->opaque = strm->opaque;
|
zwd->opaque = strm->opaque;
|
||||||
zwd->requiredHeaderSize = ZWRAP_HEADERSIZE;
|
|
||||||
|
|
||||||
strm->state = (struct internal_state*) zwd;
|
strm->state = (struct internal_state*) zwd;
|
||||||
strm->total_in = 0;
|
strm->total_in = 0;
|
||||||
@@ -360,14 +358,14 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|||||||
size_t errorCode, dstCapacity, srcSize;
|
size_t errorCode, dstCapacity, srcSize;
|
||||||
ZWRAP_DCtx* zwd = (ZWRAP_DCtx*) strm->state;
|
ZWRAP_DCtx* zwd = (ZWRAP_DCtx*) strm->state;
|
||||||
LOG_WRAPPER("inflate avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
|
LOG_WRAPPER("inflate avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
|
||||||
while (strm->total_in < ZSTD_FRAMEHEADERSIZE_MIN)
|
if (strm->total_in < ZWRAP_HEADERSIZE)
|
||||||
{
|
{
|
||||||
srcSize = MIN(strm->avail_in, zwd->requiredHeaderSize - strm->total_in);
|
srcSize = MIN(strm->avail_in, ZWRAP_HEADERSIZE - strm->total_in);
|
||||||
memcpy(zwd->headerBuf+strm->total_in, strm->next_in, srcSize);
|
memcpy(zwd->headerBuf+strm->total_in, strm->next_in, srcSize);
|
||||||
strm->total_in += srcSize;
|
strm->total_in += srcSize;
|
||||||
strm->next_in += srcSize;
|
strm->next_in += srcSize;
|
||||||
strm->avail_in -= srcSize;
|
strm->avail_in -= srcSize;
|
||||||
if (strm->total_in < zwd->requiredHeaderSize) return Z_OK;
|
if (strm->total_in < ZWRAP_HEADERSIZE) return Z_OK;
|
||||||
|
|
||||||
if (MEM_readLE32(zwd->headerBuf) != ZSTD_MAGICNUMBER) {
|
if (MEM_readLE32(zwd->headerBuf) != ZSTD_MAGICNUMBER) {
|
||||||
z_stream strm2;
|
z_stream strm2;
|
||||||
@@ -401,16 +399,11 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|||||||
return inflate(strm, flush);
|
return inflate(strm, flush);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zwd->requiredHeaderSize < ZSTD_FRAMEHEADERSIZE_MIN) {
|
|
||||||
zwd->requiredHeaderSize = ZSTD_FRAMEHEADERSIZE_MIN;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
zwd->zbd = ZBUFF_createDCtx();
|
zwd->zbd = ZBUFF_createDCtx();
|
||||||
{ size_t const errorCode = ZBUFF_decompressInit(zwd->zbd);
|
{ size_t const errorCode = ZBUFF_decompressInit(zwd->zbd);
|
||||||
if (ZSTD_isError(errorCode)) return Z_MEM_ERROR; }
|
if (ZSTD_isError(errorCode)) return Z_MEM_ERROR; }
|
||||||
|
|
||||||
srcSize = ZSTD_FRAMEHEADERSIZE_MIN;
|
srcSize = ZWRAP_HEADERSIZE;
|
||||||
dstCapacity = 0;
|
dstCapacity = 0;
|
||||||
errorCode = ZBUFF_decompressContinue(zwd->zbd, strm->next_out, &dstCapacity, zwd->headerBuf, &srcSize);
|
errorCode = ZBUFF_decompressContinue(zwd->zbd, strm->next_out, &dstCapacity, zwd->headerBuf, &srcSize);
|
||||||
LOG_WRAPPER("ZBUFF_decompressContinue1 errorCode=%d srcSize=%d dstCapacity=%d\n", (int)errorCode, (int)srcSize, (int)dstCapacity);
|
LOG_WRAPPER("ZBUFF_decompressContinue1 errorCode=%d srcSize=%d dstCapacity=%d\n", (int)errorCode, (int)srcSize, (int)dstCapacity);
|
||||||
@@ -419,7 +412,6 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|||||||
return Z_MEM_ERROR;
|
return Z_MEM_ERROR;
|
||||||
}
|
}
|
||||||
if (strm->avail_in == 0) return Z_OK;
|
if (strm->avail_in == 0) return Z_OK;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
srcSize = strm->avail_in;
|
srcSize = strm->avail_in;
|
||||||
|
Reference in New Issue
Block a user