Dependencies

(libz) Cleanups
(glslang) SPVRemapper.cpp and disassemble.cpp don't seem
to be necessary to compile in
This commit is contained in:
twinaphex 2020-06-30 16:52:06 +02:00
parent d405a317f3
commit 92945b17e2
7 changed files with 358 additions and 240 deletions

View File

@ -1565,7 +1565,11 @@ ifeq ($(HAVE_BUILTINGLSLANG), 1)
GLSLANG_SOURCES := \ GLSLANG_SOURCES := \
gfx/drivers_shader/glslang.cpp \ gfx/drivers_shader/glslang.cpp \
$(wildcard $(DEPS_DIR)/glslang/glslang/SPIRV/*.cpp) \ $(DEPS_DIR)/glslang/glslang/SPIRV/doc.cpp \
$(DEPS_DIR)/glslang/glslang/SPIRV/GlslangToSpv.cpp \
$(DEPS_DIR)/glslang/glslang/SPIRV/InReadableOrder.cpp \
$(DEPS_DIR)/glslang/glslang/SPIRV/Logger.cpp \
$(DEPS_DIR)/glslang/glslang/SPIRV/SpvBuilder.cpp \
$(wildcard $(DEPS_DIR)/glslang/glslang/glslang/GenericCodeGen/*.cpp) \ $(wildcard $(DEPS_DIR)/glslang/glslang/glslang/GenericCodeGen/*.cpp) \
$(wildcard $(DEPS_DIR)/glslang/glslang/OGLCompilersDLL/*.cpp) \ $(wildcard $(DEPS_DIR)/glslang/glslang/OGLCompilersDLL/*.cpp) \
$(wildcard $(DEPS_DIR)/glslang/glslang/glslang/MachineIndependent/*.cpp) \ $(wildcard $(DEPS_DIR)/glslang/glslang/glslang/MachineIndependent/*.cpp) \

465
deps/libz/deflate.c vendored
View File

@ -217,13 +217,15 @@ int deflateInit2_(z_streamp strm, int level, int method, int windowBits, int mem
*/ */
if (version == Z_NULL || version[0] != my_version[0] || if (version == Z_NULL || version[0] != my_version[0] ||
stream_size != sizeof(z_stream)) { stream_size != sizeof(z_stream))
return Z_VERSION_ERROR; return Z_VERSION_ERROR;
}
if (strm == Z_NULL) return Z_STREAM_ERROR; if (strm == Z_NULL)
return Z_STREAM_ERROR;
strm->msg = Z_NULL; strm->msg = Z_NULL;
if (strm->zalloc == (alloc_func)0) { if (strm->zalloc == (alloc_func)0)
{
#ifdef Z_SOLO #ifdef Z_SOLO
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
#else #else
@ -239,68 +241,77 @@ int deflateInit2_(z_streamp strm, int level, int method, int windowBits, int mem
#endif #endif
#ifdef FASTEST #ifdef FASTEST
if (level != 0) level = 1; if (level != 0)
level = 1;
#else #else
if (level == Z_DEFAULT_COMPRESSION) level = 6; if (level == Z_DEFAULT_COMPRESSION)
level = 6;
#endif #endif
if (windowBits < 0) { /* suppress zlib wrapper */ if (windowBits < 0)
wrap = 0; { /* suppress zlib wrapper */
wrap = 0;
windowBits = -windowBits; windowBits = -windowBits;
} }
#ifdef GZIP #ifdef GZIP
else if (windowBits > 15) { else if (windowBits > 15)
wrap = 2; /* write gzip wrapper instead */ {
wrap = 2; /* write gzip wrapper instead */
windowBits -= 16; windowBits -= 16;
} }
#endif #endif
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
strategy < 0 || strategy > Z_FIXED) { strategy < 0 || strategy > Z_FIXED)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
}
if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
if (s == Z_NULL) return Z_MEM_ERROR;
strm->state = (struct internal_state*)s;
s->strm = strm;
s->wrap = wrap; if (windowBits == 8)
s->gzhead = Z_NULL; windowBits = 9; /* until 256-byte window bug fixed */
s->w_bits = windowBits; s = (deflate_state *)ZALLOC(strm, 1, sizeof(deflate_state));
s->w_size = 1 << s->w_bits;
s->w_mask = s->w_size - 1;
s->hash_bits = memLevel + 7; if (s == Z_NULL)
s->hash_size = 1 << s->hash_bits; return Z_MEM_ERROR;
s->hash_mask = s->hash_size - 1;
s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); strm->state = (struct internal_state*)s;
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); s->strm = strm;
s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
s->high_water = 0; /* nothing written to s->window yet */ s->wrap = wrap;
s->gzhead = Z_NULL;
s->w_bits = windowBits;
s->w_size = 1 << s->w_bits;
s->w_mask = s->w_size - 1;
s->hash_bits = memLevel + 7;
s->hash_size = 1 << s->hash_bits;
s->hash_mask = s->hash_size - 1;
s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
s->window = (Bytef*) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
s->prev = (Posf*) ZALLOC(strm, s->w_size, sizeof(Pos));
s->head = (Posf*) ZALLOC(strm, s->hash_size, sizeof(Pos));
s->high_water = 0; /* nothing written to s->window yet */
s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
s->pending_buf = (uchf *) overlay; s->pending_buf = (uchf *) overlay;
s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
s->pending_buf == Z_NULL) { s->pending_buf == Z_NULL)
{
s->status = FINISH_STATE; s->status = FINISH_STATE;
strm->msg = ERR_MSG(Z_MEM_ERROR); strm->msg = ERR_MSG(Z_MEM_ERROR);
deflateEnd (strm); deflateEnd (strm);
return Z_MEM_ERROR; return Z_MEM_ERROR;
} }
s->d_buf = overlay + s->lit_bufsize/sizeof(ush); s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
s->level = level; s->level = level;
s->strategy = strategy; s->strategy = strategy;
s->method = (Byte)method; s->method = (Byte)method;
return deflateReset(strm); return deflateReset(strm);
} }
@ -327,24 +338,28 @@ int deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLeng
s->wrap = 0; /* avoid computing Adler-32 in read_buf */ s->wrap = 0; /* avoid computing Adler-32 in read_buf */
/* if dictionary would fill window, just replace the history */ /* if dictionary would fill window, just replace the history */
if (dictLength >= s->w_size) { if (dictLength >= s->w_size)
if (wrap == 0) { /* already empty otherwise */ {
if (wrap == 0)
{
/* already empty otherwise */
CLEAR_HASH(s); CLEAR_HASH(s);
s->strstart = 0; s->strstart = 0;
s->block_start = 0L; s->block_start = 0L;
s->insert = 0; s->insert = 0;
} }
dictionary += dictLength - s->w_size; /* use the tail */ dictionary += dictLength - s->w_size; /* use the tail */
dictLength = s->w_size; dictLength = s->w_size;
} }
/* insert dictionary into window and hash */ /* insert dictionary into window and hash */
avail = strm->avail_in; avail = strm->avail_in;
next = strm->next_in; next = strm->next_in;
strm->avail_in = dictLength; strm->avail_in = dictLength;
strm->next_in = (Bytef *)dictionary; strm->next_in = (Bytef *)dictionary;
fill_window(s); fill_window(s);
while (s->lookahead >= MIN_MATCH) { while (s->lookahead >= MIN_MATCH)
{
str = s->strstart; str = s->strstart;
n = s->lookahead - (MIN_MATCH-1); n = s->lookahead - (MIN_MATCH-1);
do { do {
@ -359,15 +374,15 @@ int deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLeng
s->lookahead = MIN_MATCH-1; s->lookahead = MIN_MATCH-1;
fill_window(s); fill_window(s);
} }
s->strstart += s->lookahead; s->strstart += s->lookahead;
s->block_start = (long)s->strstart; s->block_start = (long)s->strstart;
s->insert = s->lookahead; s->insert = s->lookahead;
s->lookahead = 0; s->lookahead = 0;
s->match_length = s->prev_length = MIN_MATCH-1; s->match_length = s->prev_length = MIN_MATCH-1;
s->match_available = 0; s->match_available = 0;
strm->next_in = next; strm->next_in = next;
strm->avail_in = avail; strm->avail_in = avail;
s->wrap = wrap; s->wrap = wrap;
return Z_OK; return Z_OK;
} }
@ -377,28 +392,26 @@ int deflateResetKeep (z_streamp strm)
deflate_state *s; deflate_state *s;
if (strm == Z_NULL || strm->state == Z_NULL || if (strm == Z_NULL || strm->state == Z_NULL ||
strm->zalloc == Z_NULL || strm->zfree == Z_NULL) { strm->zalloc == Z_NULL || strm->zfree == Z_NULL)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
}
strm->total_in = strm->total_out = 0; strm->total_in = strm->total_out = 0;
strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
strm->data_type = Z_UNKNOWN; strm->data_type = Z_UNKNOWN;
s = (deflate_state *)strm->state; s = (deflate_state *)strm->state;
s->pending = 0; s->pending = 0;
s->pending_out = s->pending_buf; s->pending_out = s->pending_buf;
if (s->wrap < 0) { if (s->wrap < 0)
s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
} s->status = s->wrap ? INIT_STATE : BUSY_STATE;
s->status = s->wrap ? INIT_STATE : BUSY_STATE; strm->adler =
strm->adler =
#ifdef GZIP #ifdef GZIP
s->wrap == 2 ? crc32(0L, Z_NULL, 0) : s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
#endif #endif
adler32(0L, Z_NULL, 0); adler32(0L, Z_NULL, 0);
s->last_flush = Z_NO_FLUSH; s->last_flush = Z_NO_FLUSH;
_tr_init(s); _tr_init(s);
@ -408,9 +421,7 @@ int deflateResetKeep (z_streamp strm)
/* ========================================================================= */ /* ========================================================================= */
int deflateReset (z_streamp strm) int deflateReset (z_streamp strm)
{ {
int ret; int ret = deflateResetKeep(strm);
ret = deflateResetKeep(strm);
if (ret == Z_OK) if (ret == Z_OK)
lm_init((deflate_state*)strm->state); lm_init((deflate_state*)strm->state);
return ret; return ret;
@ -419,8 +430,10 @@ int deflateReset (z_streamp strm)
/* ========================================================================= */ /* ========================================================================= */
int deflateSetHeader (z_streamp strm, gz_headerp head) int deflateSetHeader (z_streamp strm, gz_headerp head)
{ {
struct internal_state_deflate *state = (struct internal_state_deflate*)strm->state; struct internal_state_deflate *state =
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; (struct internal_state_deflate*)strm->state;
if (strm == Z_NULL || strm->state == Z_NULL)
return Z_STREAM_ERROR;
if (state->wrap != 2) if (state->wrap != 2)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
state->gzhead = head; state->gzhead = head;
@ -430,8 +443,10 @@ int deflateSetHeader (z_streamp strm, gz_headerp head)
/* ========================================================================= */ /* ========================================================================= */
int deflatePending (z_streamp strm, unsigned *pending, int *bits) int deflatePending (z_streamp strm, unsigned *pending, int *bits)
{ {
struct internal_state_deflate *state = (struct internal_state_deflate*)strm->state; struct internal_state_deflate *state =
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; (struct internal_state_deflate*)strm->state;
if (strm == Z_NULL || strm->state == Z_NULL)
return Z_STREAM_ERROR;
if (pending != Z_NULL) if (pending != Z_NULL)
*pending = state->pending; *pending = state->pending;
if (bits != Z_NULL) if (bits != Z_NULL)
@ -445,10 +460,14 @@ int deflatePrime (z_streamp strm, int bits, int value)
deflate_state *s; deflate_state *s;
int put; int put;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (strm == Z_NULL || strm->state == Z_NULL)
return Z_STREAM_ERROR;
s = (deflate_state*)strm->state; s = (deflate_state*)strm->state;
if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
return Z_BUF_ERROR; return Z_BUF_ERROR;
do { do {
put = Buf_size - s->bi_valid; put = Buf_size - s->bi_valid;
if (put > bits) if (put > bits)
@ -469,28 +488,34 @@ int deflateParams(z_streamp strm, int level, int strategy)
compress_func func; compress_func func;
int err = Z_OK; int err = Z_OK;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (strm == Z_NULL || strm->state == Z_NULL)
return Z_STREAM_ERROR;
s = (deflate_state*)strm->state; s = (deflate_state*)strm->state;
#ifdef FASTEST #ifdef FASTEST
if (level != 0) level = 1; if (level != 0)
level = 1;
#else #else
if (level == Z_DEFAULT_COMPRESSION) level = 6; if (level == Z_DEFAULT_COMPRESSION)
level = 6;
#endif #endif
if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
}
func = configuration_table[s->level].func; func = configuration_table[s->level].func;
if ((strategy != s->strategy || func != configuration_table[level].func) && if ((strategy != s->strategy || func != configuration_table[level].func) &&
strm->total_in != 0) { strm->total_in != 0)
{
/* Flush the last buffer: */ /* Flush the last buffer: */
err = deflate(strm, Z_BLOCK); err = deflate(strm, Z_BLOCK);
if (err == Z_BUF_ERROR && s->pending == 0) if (err == Z_BUF_ERROR && s->pending == 0)
err = Z_OK; err = Z_OK;
} }
if (s->level != level) { if (s->level != level)
s->level = level; {
s->level = level;
s->max_lazy_match = configuration_table[level].max_lazy; s->max_lazy_match = configuration_table[level].max_lazy;
s->good_match = configuration_table[level].good_length; s->good_match = configuration_table[level].good_length;
s->nice_match = configuration_table[level].nice_length; s->nice_match = configuration_table[level].nice_length;
@ -505,11 +530,13 @@ int deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length,
{ {
deflate_state *s; deflate_state *s;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (strm == Z_NULL || strm->state == Z_NULL)
s = (deflate_state*)strm->state; return Z_STREAM_ERROR;
s->good_match = good_length;
s->max_lazy_match = max_lazy; s = (deflate_state*)strm->state;
s->nice_match = nice_length; s->good_match = good_length;
s->max_lazy_match = max_lazy;
s->nice_match = nice_length;
s->max_chain_length = max_chain; s->max_chain_length = max_chain;
return Z_OK; return Z_OK;
} }
@ -534,11 +561,11 @@ int deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length,
uLong deflateBound(z_streamp strm, uLong sourceLen) uLong deflateBound(z_streamp strm, uLong sourceLen)
{ {
deflate_state *s; deflate_state *s;
uLong complen, wraplen; uLong wraplen;
Bytef *str; Bytef *str;
/* conservative upper bound for compressed data */ /* conservative upper bound for compressed data */
complen = sourceLen + uLong complen = sourceLen +
((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
/* if can't get parameters, return conservative bound plus zlib wrapper */ /* if can't get parameters, return conservative bound plus zlib wrapper */
@ -547,7 +574,9 @@ uLong deflateBound(z_streamp strm, uLong sourceLen)
/* compute wrapper length */ /* compute wrapper length */
s = (deflate_state*)strm->state; s = (deflate_state*)strm->state;
switch (s->wrap) {
switch (s->wrap)
{
case 0: /* raw deflate */ case 0: /* raw deflate */
wraplen = 0; wraplen = 0;
break; break;
@ -556,7 +585,8 @@ uLong deflateBound(z_streamp strm, uLong sourceLen)
break; break;
case 2: /* gzip wrapper */ case 2: /* gzip wrapper */
wraplen = 18; wraplen = 18;
if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ if (s->gzhead != Z_NULL)
{ /* user-supplied gzip header */
if (s->gzhead->extra != Z_NULL) if (s->gzhead->extra != Z_NULL)
wraplen += 2 + s->gzhead->extra_len; wraplen += 2 + s->gzhead->extra_len;
str = s->gzhead->name; str = s->gzhead->name;
@ -611,7 +641,8 @@ static void flush_pending(z_streamp strm)
_tr_flush_bits(s); _tr_flush_bits(s);
len = s->pending; len = s->pending;
if (len > strm->avail_out) len = strm->avail_out; if (len > strm->avail_out) len = strm->avail_out;
if (len == 0) return; if (len == 0)
return;
zmemcpy(strm->next_out, s->pending_out, len); zmemcpy(strm->next_out, s->pending_out, len);
strm->next_out += len; strm->next_out += len;
@ -619,9 +650,8 @@ static void flush_pending(z_streamp strm)
strm->total_out += len; strm->total_out += len;
strm->avail_out -= len; strm->avail_out -= len;
s->pending -= len; s->pending -= len;
if (s->pending == 0) { if (s->pending == 0)
s->pending_out = s->pending_buf; s->pending_out = s->pending_buf;
}
} }
/* ========================================================================= */ /* ========================================================================= */
@ -631,9 +661,9 @@ int deflate (z_streamp strm, int flush)
deflate_state *s; deflate_state *s;
if (strm == Z_NULL || strm->state == Z_NULL || if (strm == Z_NULL || strm->state == Z_NULL ||
flush > Z_BLOCK || flush < 0) { flush > Z_BLOCK || flush < 0)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
}
s = (deflate_state*)strm->state; s = (deflate_state*)strm->state;
if (strm->next_out == Z_NULL || if (strm->next_out == Z_NULL ||
@ -643,19 +673,22 @@ int deflate (z_streamp strm, int flush)
} }
if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
s->strm = strm; /* just in case */ s->strm = strm; /* just in case */
old_flush = s->last_flush; old_flush = s->last_flush;
s->last_flush = flush; s->last_flush = flush;
/* Write the header */ /* Write the header */
if (s->status == INIT_STATE) { if (s->status == INIT_STATE)
{
#ifdef GZIP #ifdef GZIP
if (s->wrap == 2) { if (s->wrap == 2)
{
strm->adler = crc32(0L, Z_NULL, 0); strm->adler = crc32(0L, Z_NULL, 0);
put_byte(s, 31); put_byte(s, 31);
put_byte(s, 139); put_byte(s, 139);
put_byte(s, 8); put_byte(s, 8);
if (s->gzhead == Z_NULL) { if (s->gzhead == Z_NULL)
{
put_byte(s, 0); put_byte(s, 0);
put_byte(s, 0); put_byte(s, 0);
put_byte(s, 0); put_byte(s, 0);
@ -667,7 +700,8 @@ int deflate (z_streamp strm, int flush)
put_byte(s, OS_CODE); put_byte(s, OS_CODE);
s->status = BUSY_STATE; s->status = BUSY_STATE;
} }
else { else
{
put_byte(s, (s->gzhead->text ? 1 : 0) + put_byte(s, (s->gzhead->text ? 1 : 0) +
(s->gzhead->hcrc ? 2 : 0) + (s->gzhead->hcrc ? 2 : 0) +
(s->gzhead->extra == Z_NULL ? 0 : 4) + (s->gzhead->extra == Z_NULL ? 0 : 4) +
@ -942,19 +976,20 @@ int deflateEnd (z_streamp strm)
struct internal_state_deflate *state; struct internal_state_deflate *state;
int status; int status;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (strm == Z_NULL || strm->state == Z_NULL)
state = (struct internal_state_deflate*)strm->state; return Z_STREAM_ERROR;
state = (struct internal_state_deflate*)strm->state;
status = state->status; status = state->status;
if (status != INIT_STATE && if (status != INIT_STATE &&
status != EXTRA_STATE && status != EXTRA_STATE &&
status != NAME_STATE && status != NAME_STATE &&
status != COMMENT_STATE && status != COMMENT_STATE &&
status != HCRC_STATE && status != HCRC_STATE &&
status != BUSY_STATE && status != BUSY_STATE &&
status != FINISH_STATE) { status != FINISH_STATE)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
}
/* Deallocate in reverse order of allocations: */ /* Deallocate in reverse order of allocations: */
TRY_FREE(strm, state->pending_buf); TRY_FREE(strm, state->pending_buf);
@ -982,44 +1017,45 @@ int deflateCopy (z_streamp dest, z_streamp source)
deflate_state *ss; deflate_state *ss;
ushf *overlay; ushf *overlay;
if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL)
if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
}
ss = (deflate_state*)source->state; ss = (deflate_state*)source->state;
zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
if (ds == Z_NULL) return Z_MEM_ERROR; if (ds == Z_NULL)
dest->state = (struct internal_state FAR *) ds; return Z_MEM_ERROR;
dest->state = (struct internal_state FAR *) ds;
zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
ds->strm = dest; ds->strm = dest;
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
ds->pending_buf = (uchf *) overlay; ds->pending_buf = (uchf *) overlay;
if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
ds->pending_buf == Z_NULL) { ds->pending_buf == Z_NULL)
{
deflateEnd (dest); deflateEnd (dest);
return Z_MEM_ERROR; return Z_MEM_ERROR;
} }
/* following zmemcpy do not work for 16-bit MSDOS */ /* following zmemcpy do not work for 16-bit MSDOS */
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
ds->l_desc.dyn_tree = ds->dyn_ltree; ds->l_desc.dyn_tree = ds->dyn_ltree;
ds->d_desc.dyn_tree = ds->dyn_dtree; ds->d_desc.dyn_tree = ds->dyn_dtree;
ds->bl_desc.dyn_tree = ds->bl_tree; ds->bl_desc.dyn_tree = ds->bl_tree;
return Z_OK; return Z_OK;
@ -1035,22 +1071,23 @@ int deflateCopy (z_streamp dest, z_streamp source)
*/ */
static int read_buf(z_streamp strm, Bytef *buf, unsigned size) static int read_buf(z_streamp strm, Bytef *buf, unsigned size)
{ {
struct internal_state_deflate *state = (struct internal_state_deflate*)strm->state; struct internal_state_deflate
*state = (struct internal_state_deflate*)strm->state;
unsigned len = strm->avail_in; unsigned len = strm->avail_in;
if (len > size) len = size; if (len > size)
if (len == 0) return 0; len = size;
if (len == 0)
return 0;
strm->avail_in -= len; strm->avail_in -= len;
zmemcpy(buf, strm->next_in, len); zmemcpy(buf, strm->next_in, len);
if (state->wrap == 1) { if (state->wrap == 1)
strm->adler = adler32(strm->adler, buf, len); strm->adler = adler32(strm->adler, buf, len);
}
#ifdef GZIP #ifdef GZIP
else if (state->wrap == 2) { else if (state->wrap == 2)
strm->adler = crc32(strm->adler, buf, len); strm->adler = crc32(strm->adler, buf, len);
}
#endif #endif
strm->next_in += len; strm->next_in += len;
strm->total_in += len; strm->total_in += len;
@ -1074,13 +1111,13 @@ static void lm_init (deflate_state *s)
s->nice_match = configuration_table[s->level].nice_length; s->nice_match = configuration_table[s->level].nice_length;
s->max_chain_length = configuration_table[s->level].max_chain; s->max_chain_length = configuration_table[s->level].max_chain;
s->strstart = 0; s->strstart = 0;
s->block_start = 0L; s->block_start = 0L;
s->lookahead = 0; s->lookahead = 0;
s->insert = 0; s->insert = 0;
s->match_length = s->prev_length = MIN_MATCH-1; s->match_length = s->prev_length = MIN_MATCH-1;
s->match_available = 0; s->match_available = 0;
s->ins_h = 0; s->ins_h = 0;
#ifndef FASTEST #ifndef FASTEST
#ifdef ASMV #ifdef ASMV
match_init(); /* initialize the asm code */ match_init(); /* initialize the asm code */
@ -1104,12 +1141,14 @@ static void lm_init (deflate_state *s)
*/ */
static uInt longest_match(deflate_state *s, IPos cur_match) static uInt longest_match(deflate_state *s, IPos cur_match)
{ {
unsigned chain_length = s->max_chain_length;/* max hash chain length */
register Bytef *scan = s->window + s->strstart; /* current string */
register Bytef *match; /* matched string */ register Bytef *match; /* matched string */
register int len; /* length of current match */ register int len; /* length of current match */
int best_len = s->prev_length; /* best match length so far */ unsigned chain_length = s->max_chain_length; /* max hash chain length */
int nice_match = s->nice_match; /* stop if match long enough */ register Bytef *scan = s->window + s->strstart; /* current string */
int best_len = s->prev_length;
/* best match length so far */
int nice_match = s->nice_match;
/* stop if match long enough */
IPos limit = s->strstart > (IPos)MAX_DIST(s) ? IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
s->strstart - (IPos)MAX_DIST(s) : NIL; s->strstart - (IPos)MAX_DIST(s) : NIL;
/* Stop when cur_match becomes <= limit. To simplify the code, /* Stop when cur_match becomes <= limit. To simplify the code,
@ -1122,11 +1161,11 @@ static uInt longest_match(deflate_state *s, IPos cur_match)
/* Compare two bytes at a time. Note: this is not always beneficial. /* Compare two bytes at a time. Note: this is not always beneficial.
* Try with and without -DUNALIGNED_OK to check. * Try with and without -DUNALIGNED_OK to check.
*/ */
register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
register ush scan_start = *(ushf*)scan; register ush scan_start = *(ushf*)scan;
register ush scan_end = *(ushf*)(scan+best_len-1); register ush scan_end = *(ushf*)(scan+best_len-1);
#else #else
register Bytef *strend = s->window + s->strstart + MAX_MATCH; register Bytef *strend = s->window + s->strstart + MAX_MATCH;
register Byte scan_end1 = scan[best_len-1]; register Byte scan_end1 = scan[best_len-1];
register Byte scan_end = scan[best_len]; register Byte scan_end = scan[best_len];
#endif #endif
@ -1137,13 +1176,14 @@ static uInt longest_match(deflate_state *s, IPos cur_match)
Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
/* Do not waste too much time if we already have a good match: */ /* Do not waste too much time if we already have a good match: */
if (s->prev_length >= s->good_match) { if (s->prev_length >= s->good_match)
chain_length >>= 2; chain_length >>= 2;
}
/* Do not look for matches beyond the end of the input. This is necessary /* Do not look for matches beyond the end of the input. This is necessary
* to make deflate deterministic. * to make deflate deterministic.
*/ */
if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; if ((uInt)nice_match > s->lookahead)
nice_match = s->lookahead;
Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
@ -1197,7 +1237,8 @@ static uInt longest_match(deflate_state *s, IPos cur_match)
if (match[best_len] != scan_end || if (match[best_len] != scan_end ||
match[best_len-1] != scan_end1 || match[best_len-1] != scan_end1 ||
*match != *scan || *match != *scan ||
*++match != scan[1]) continue; *++match != scan[1])
continue;
/* The check at best_len-1 can be removed because it will be made /* The check at best_len-1 can be removed because it will be made
* again later. (This heuristic is not always a win.) * again later. (This heuristic is not always a win.)
@ -1495,15 +1536,15 @@ static block_state deflate_stored(deflate_state *s, int flush)
ulg max_block_size = 0xffff; ulg max_block_size = 0xffff;
ulg max_start; ulg max_start;
if (max_block_size > s->pending_buf_size - 5) { if (max_block_size > s->pending_buf_size - 5)
max_block_size = s->pending_buf_size - 5; max_block_size = s->pending_buf_size - 5;
}
/* Copy as much as possible from input to output: */ /* Copy as much as possible from input to output: */
for (;;) { for (;;)
{
/* Fill the window as much as possible: */ /* Fill the window as much as possible: */
if (s->lookahead <= 1) { if (s->lookahead <= 1)
{
Assert(s->strstart < s->w_size+MAX_DIST(s) || Assert(s->strstart < s->w_size+MAX_DIST(s) ||
s->block_start >= (long)s->w_size, "slide too late"); s->block_start >= (long)s->w_size, "slide too late");
@ -1519,7 +1560,8 @@ static block_state deflate_stored(deflate_state *s, int flush)
/* Emit a stored block if pending_buf will be full: */ /* Emit a stored block if pending_buf will be full: */
max_start = s->block_start + max_block_size; max_start = s->block_start + max_block_size;
if (s->strstart == 0 || (ulg)s->strstart >= max_start) { if (s->strstart == 0 || (ulg)s->strstart >= max_start)
{
/* strstart == 0 is possible when wraparound on 16-bit machine */ /* strstart == 0 is possible when wraparound on 16-bit machine */
s->lookahead = (uInt)(s->strstart - max_start); s->lookahead = (uInt)(s->strstart - max_start);
s->strstart = (uInt)max_start; s->strstart = (uInt)max_start;
@ -1533,7 +1575,8 @@ static block_state deflate_stored(deflate_state *s, int flush)
} }
} }
s->insert = 0; s->insert = 0;
if (flush == Z_FINISH) { if (flush == Z_FINISH)
{
FLUSH_BLOCK(s, 1); FLUSH_BLOCK(s, 1);
return finish_done; return finish_done;
} }
@ -1554,32 +1597,36 @@ static block_state deflate_fast(deflate_state *s, int flush)
IPos hash_head; /* head of the hash chain */ IPos hash_head; /* head of the hash chain */
int bflush; /* set if current block must be flushed */ int bflush; /* set if current block must be flushed */
for (;;) { for (;;)
{
/* Make sure that we always have enough lookahead, except /* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes * at the end of the input file. We need MAX_MATCH bytes
* for the next match, plus MIN_MATCH bytes to insert the * for the next match, plus MIN_MATCH bytes to insert the
* string following the next match. * string following the next match.
*/ */
if (s->lookahead < MIN_LOOKAHEAD) { if (s->lookahead < MIN_LOOKAHEAD)
{
fill_window(s); fill_window(s);
if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH)
return need_more; return need_more;
} if (s->lookahead == 0)
if (s->lookahead == 0) break; /* flush the current block */ break; /* flush the current block */
} }
/* Insert the string window[strstart .. strstart+2] in the /* Insert the string window[strstart .. strstart+2] in the
* dictionary, and set hash_head to the head of the hash chain: * dictionary, and set hash_head to the head of the hash chain:
*/ */
hash_head = NIL; hash_head = NIL;
if (s->lookahead >= MIN_MATCH) { if (s->lookahead >= MIN_MATCH)
{
INSERT_STRING(s, s->strstart, hash_head); INSERT_STRING(s, s->strstart, hash_head);
} }
/* Find the longest match, discarding those <= prev_length. /* Find the longest match, discarding those <= prev_length.
* At this point we have always match_length < MIN_MATCH * At this point we have always match_length < MIN_MATCH
*/ */
if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s))
{
/* To simplify the code, we prevent matches with the string /* To simplify the code, we prevent matches with the string
* of window index 0 (in particular we have to avoid a match * of window index 0 (in particular we have to avoid a match
* of the string with itself at the start of the input file). * of the string with itself at the start of the input file).
@ -1587,7 +1634,8 @@ static block_state deflate_fast(deflate_state *s, int flush)
s->match_length = longest_match (s, hash_head); s->match_length = longest_match (s, hash_head);
/* longest_match() sets match_start */ /* longest_match() sets match_start */
} }
if (s->match_length >= MIN_MATCH) { if (s->match_length >= MIN_MATCH)
{
_tr_tally_dist(s, s->strstart - s->match_start, _tr_tally_dist(s, s->strstart - s->match_start,
s->match_length - MIN_MATCH, bflush); s->match_length - MIN_MATCH, bflush);
@ -1598,7 +1646,8 @@ static block_state deflate_fast(deflate_state *s, int flush)
*/ */
#ifndef FASTEST #ifndef FASTEST
if (s->match_length <= s->max_insert_length && if (s->match_length <= s->max_insert_length &&
s->lookahead >= MIN_MATCH) { s->lookahead >= MIN_MATCH)
{
s->match_length--; /* string at strstart already in table */ s->match_length--; /* string at strstart already in table */
do { do {
s->strstart++; s->strstart++;
@ -1608,7 +1657,8 @@ static block_state deflate_fast(deflate_state *s, int flush)
*/ */
} while (--s->match_length != 0); } while (--s->match_length != 0);
s->strstart++; s->strstart++;
} else }
else
#endif #endif
{ {
s->strstart += s->match_length; s->strstart += s->match_length;
@ -1622,7 +1672,9 @@ static block_state deflate_fast(deflate_state *s, int flush)
* matter since it will be recomputed at next deflate call. * matter since it will be recomputed at next deflate call.
*/ */
} }
} else { }
else
{
/* No match, output a literal byte */ /* No match, output a literal byte */
Tracevv((stderr,"%c", s->window[s->strstart])); Tracevv((stderr,"%c", s->window[s->strstart]));
_tr_tally_lit (s, s->window[s->strstart], bflush); _tr_tally_lit (s, s->window[s->strstart], bflush);
@ -1632,7 +1684,8 @@ static block_state deflate_fast(deflate_state *s, int flush)
if (bflush) FLUSH_BLOCK(s, 0); if (bflush) FLUSH_BLOCK(s, 0);
} }
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
if (flush == Z_FINISH) { if (flush == Z_FINISH)
{
FLUSH_BLOCK(s, 1); FLUSH_BLOCK(s, 1);
return finish_done; return finish_done;
} }
@ -1653,25 +1706,28 @@ static block_state deflate_slow(deflate_state *s, int flush)
int bflush; /* set if current block must be flushed */ int bflush; /* set if current block must be flushed */
/* Process the input block. */ /* Process the input block. */
for (;;) { for (;;)
{
/* Make sure that we always have enough lookahead, except /* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes * at the end of the input file. We need MAX_MATCH bytes
* for the next match, plus MIN_MATCH bytes to insert the * for the next match, plus MIN_MATCH bytes to insert the
* string following the next match. * string following the next match.
*/ */
if (s->lookahead < MIN_LOOKAHEAD) { if (s->lookahead < MIN_LOOKAHEAD)
{
fill_window(s); fill_window(s);
if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH)
return need_more; return need_more;
} if (s->lookahead == 0)
if (s->lookahead == 0) break; /* flush the current block */ break; /* flush the current block */
} }
/* Insert the string window[strstart .. strstart+2] in the /* Insert the string window[strstart .. strstart+2] in the
* dictionary, and set hash_head to the head of the hash chain: * dictionary, and set hash_head to the head of the hash chain:
*/ */
hash_head = NIL; hash_head = NIL;
if (s->lookahead >= MIN_MATCH) { if (s->lookahead >= MIN_MATCH)
{
INSERT_STRING(s, s->strstart, hash_head); INSERT_STRING(s, s->strstart, hash_head);
} }
@ -1681,7 +1737,8 @@ static block_state deflate_slow(deflate_state *s, int flush)
s->match_length = MIN_MATCH-1; s->match_length = MIN_MATCH-1;
if (hash_head != NIL && s->prev_length < s->max_lazy_match && if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
s->strstart - hash_head <= MAX_DIST(s)) { s->strstart - hash_head <= MAX_DIST(s))
{
/* To simplify the code, we prevent matches with the string /* To simplify the code, we prevent matches with the string
* of window index 0 (in particular we have to avoid a match * of window index 0 (in particular we have to avoid a match
* of the string with itself at the start of the input file). * of the string with itself at the start of the input file).
@ -1694,7 +1751,8 @@ static block_state deflate_slow(deflate_state *s, int flush)
|| (s->match_length == MIN_MATCH && || (s->match_length == MIN_MATCH &&
s->strstart - s->match_start > TOO_FAR) s->strstart - s->match_start > TOO_FAR)
#endif #endif
)) { ))
{
/* If prev_match is also MIN_MATCH, match_start is garbage /* If prev_match is also MIN_MATCH, match_start is garbage
* but we will ignore the current match anyway. * but we will ignore the current match anyway.
@ -1705,7 +1763,8 @@ static block_state deflate_slow(deflate_state *s, int flush)
/* If there was a match at the previous step and the current /* If there was a match at the previous step and the current
* match is not better, output the previous match: * match is not better, output the previous match:
*/ */
if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length)
{
uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
/* Do not insert strings in hash table beyond this. */ /* Do not insert strings in hash table beyond this. */
@ -1730,7 +1789,9 @@ static block_state deflate_slow(deflate_state *s, int flush)
if (bflush) FLUSH_BLOCK(s, 0); if (bflush) FLUSH_BLOCK(s, 0);
} else if (s->match_available) { }
else if (s->match_available)
{
/* If there was no match at the previous position, output a /* If there was no match at the previous position, output a
* single literal. If there was a match but the current match * single literal. If there was a match but the current match
* is longer, truncate the previous match to a single literal. * is longer, truncate the previous match to a single literal.
@ -1743,7 +1804,9 @@ static block_state deflate_slow(deflate_state *s, int flush)
s->strstart++; s->strstart++;
s->lookahead--; s->lookahead--;
if (s->strm->avail_out == 0) return need_more; if (s->strm->avail_out == 0) return need_more;
} else { }
else
{
/* There is no previous match to compare with, wait for /* There is no previous match to compare with, wait for
* the next step to decide. * the next step to decide.
*/ */
@ -1753,13 +1816,15 @@ static block_state deflate_slow(deflate_state *s, int flush)
} }
} }
Assert (flush != Z_NO_FLUSH, "no flush?"); Assert (flush != Z_NO_FLUSH, "no flush?");
if (s->match_available) { if (s->match_available)
{
Tracevv((stderr,"%c", s->window[s->strstart-1])); Tracevv((stderr,"%c", s->window[s->strstart-1]));
_tr_tally_lit(s, s->window[s->strstart-1], bflush); _tr_tally_lit(s, s->window[s->strstart-1], bflush);
s->match_available = 0; s->match_available = 0;
} }
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
if (flush == Z_FINISH) { if (flush == Z_FINISH)
{
FLUSH_BLOCK(s, 1); FLUSH_BLOCK(s, 1);
return finish_done; return finish_done;
} }
@ -1780,25 +1845,29 @@ static block_state deflate_rle(deflate_state *s, int flush)
uInt prev; /* byte at distance one to match */ uInt prev; /* byte at distance one to match */
Bytef *scan, *strend; /* scan goes up to strend for length of run */ Bytef *scan, *strend; /* scan goes up to strend for length of run */
for (;;) { for (;;)
{
/* Make sure that we always have enough lookahead, except /* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes * at the end of the input file. We need MAX_MATCH bytes
* for the longest run, plus one for the unrolled loop. * for the longest run, plus one for the unrolled loop.
*/ */
if (s->lookahead <= MAX_MATCH) { if (s->lookahead <= MAX_MATCH)
{
fill_window(s); fill_window(s);
if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) { if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH)
return need_more; return need_more;
} if (s->lookahead == 0)
if (s->lookahead == 0) break; /* flush the current block */ break; /* flush the current block */
} }
/* See how many times the previous byte repeats */ /* See how many times the previous byte repeats */
s->match_length = 0; s->match_length = 0;
if (s->lookahead >= MIN_MATCH && s->strstart > 0) { if (s->lookahead >= MIN_MATCH && s->strstart > 0)
{
scan = s->window + s->strstart - 1; scan = s->window + s->strstart - 1;
prev = *scan; prev = *scan;
if (prev == *++scan && prev == *++scan && prev == *++scan) { if (prev == *++scan && prev == *++scan && prev == *++scan)
{
strend = s->window + s->strstart + MAX_MATCH; strend = s->window + s->strstart + MAX_MATCH;
do { do {
} while (prev == *++scan && prev == *++scan && } while (prev == *++scan && prev == *++scan &&
@ -1814,13 +1883,16 @@ static block_state deflate_rle(deflate_state *s, int flush)
} }
/* Emit match if have run of MIN_MATCH or longer, else emit literal */ /* Emit match if have run of MIN_MATCH or longer, else emit literal */
if (s->match_length >= MIN_MATCH) { if (s->match_length >= MIN_MATCH)
{
_tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
s->lookahead -= s->match_length; s->lookahead -= s->match_length;
s->strstart += s->match_length; s->strstart += s->match_length;
s->match_length = 0; s->match_length = 0;
} else { }
else
{
/* No match, output a literal byte */ /* No match, output a literal byte */
Tracevv((stderr,"%c", s->window[s->strstart])); Tracevv((stderr,"%c", s->window[s->strstart]));
_tr_tally_lit (s, s->window[s->strstart], bflush); _tr_tally_lit (s, s->window[s->strstart], bflush);
@ -1830,7 +1902,8 @@ static block_state deflate_rle(deflate_state *s, int flush)
if (bflush) FLUSH_BLOCK(s, 0); if (bflush) FLUSH_BLOCK(s, 0);
} }
s->insert = 0; s->insert = 0;
if (flush == Z_FINISH) { if (flush == Z_FINISH)
{
FLUSH_BLOCK(s, 1); FLUSH_BLOCK(s, 1);
return finish_done; return finish_done;
} }
@ -1847,11 +1920,14 @@ static block_state deflate_huff(deflate_state *s, int flush)
{ {
int bflush; /* set if current block must be flushed */ int bflush; /* set if current block must be flushed */
for (;;) { for (;;)
{
/* Make sure that we have a literal to write. */ /* Make sure that we have a literal to write. */
if (s->lookahead == 0) { if (s->lookahead == 0)
{
fill_window(s); fill_window(s);
if (s->lookahead == 0) { if (s->lookahead == 0)
{
if (flush == Z_NO_FLUSH) if (flush == Z_NO_FLUSH)
return need_more; return need_more;
break; /* flush the current block */ break; /* flush the current block */
@ -1867,7 +1943,8 @@ static block_state deflate_huff(deflate_state *s, int flush)
if (bflush) FLUSH_BLOCK(s, 0); if (bflush) FLUSH_BLOCK(s, 0);
} }
s->insert = 0; s->insert = 0;
if (flush == Z_FINISH) { if (flush == Z_FINISH)
{
FLUSH_BLOCK(s, 1); FLUSH_BLOCK(s, 1);
return finish_done; return finish_done;
} }

6
deps/libz/gzclose.c vendored
View File

@ -20,8 +20,8 @@ int gzclose(gzFile file)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
state = (gz_statep)file; state = (gz_statep)file;
return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); if (state->mode != GZ_READ)
#else return gzclose_w(file);
return gzclose_r(file);
#endif #endif
return gzclose_r(file);
} }

14
deps/libz/gzlib.c vendored
View File

@ -517,8 +517,9 @@ void gzclearerr(gzFile file)
return; return;
/* clear error and end-of-file */ /* clear error and end-of-file */
if (state->mode == GZ_READ) { if (state->mode == GZ_READ)
state->eof = 0; {
state->eof = 0;
state->past = 0; state->past = 0;
} }
gz_error(state, Z_OK, NULL); gz_error(state, Z_OK, NULL);
@ -533,7 +534,8 @@ void gzclearerr(gzFile file)
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
{ {
/* free previously allocated message and clear */ /* free previously allocated message and clear */
if (state->msg != NULL) { if (state->msg != NULL)
{
if (state->err != Z_MEM_ERROR) if (state->err != Z_MEM_ERROR)
free(state->msg); free(state->msg);
state->msg = NULL; state->msg = NULL;
@ -554,7 +556,8 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
/* construct error message with path */ /* construct error message with path */
if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) == if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
NULL) { NULL)
{
state->err = Z_MEM_ERROR; state->err = Z_MEM_ERROR;
return; return;
} }
@ -566,7 +569,6 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
strlcat(state->msg, ": ", sizeof(state->msg)); strlcat(state->msg, ": ", sizeof(state->msg));
strlcat(state->msg, msg, sizeof(state->msg)); strlcat(state->msg, msg, sizeof(state->msg));
#endif #endif
return;
} }
#ifndef INT_MAX #ifndef INT_MAX
@ -574,7 +576,7 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
available) -- we need to do this to cover cases where 2's complement not available) -- we need to do this to cover cases where 2's complement not
used, since C standard permits 1's complement and sign-bit representations, used, since C standard permits 1's complement and sign-bit representations,
otherwise we could just use ((unsigned)-1) >> 1 */ otherwise we could just use ((unsigned)-1) >> 1 */
unsigned ZLIB_INTERNAL gz_intmax() unsigned ZLIB_INTERNAL gz_intmax(void)
{ {
unsigned p, q; unsigned p, q;

30
deps/libz/uncompr.c vendored
View File

@ -21,31 +21,39 @@
enough memory, Z_BUF_ERROR if there was not enough room in the output enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted. buffer, or Z_DATA_ERROR if the input data was corrupted.
*/ */
int uncompress (unsigned char *dest, uint32_t *destLen, const unsigned char *source, uint32_t sourceLen) int uncompress (
unsigned char *dest,
uint32_t *destLen,
const unsigned char *source,
uint32_t sourceLen)
{ {
z_stream stream;
int err; int err;
z_stream stream;
stream.next_in = (Bytef *)source; stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen; stream.avail_in = (uInt)sourceLen;
/* Check for source > 64K on 16-bit machine: */ /* Check for source > 64K on 16-bit machine: */
if ((uint32_t)stream.avail_in != sourceLen) return Z_BUF_ERROR; if ((uint32_t)stream.avail_in != sourceLen)
return Z_BUF_ERROR;
stream.next_out = dest; stream.next_out = dest;
stream.avail_out = (uInt)*destLen; stream.avail_out = (uInt)*destLen;
if ((uint32_t)stream.avail_out != *destLen) return Z_BUF_ERROR; if ((uint32_t)stream.avail_out != *destLen)
return Z_BUF_ERROR;
stream.zalloc = Z_NULL; stream.zalloc = Z_NULL;
stream.zfree = Z_NULL; stream.zfree = Z_NULL;
err = inflateInit(&stream); err = inflateInit(&stream);
if (err != Z_OK) return err; if (err != Z_OK)
return err;
err = inflate(&stream, Z_FINISH); err = inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) if (err != Z_STREAM_END)
{ {
inflateEnd(&stream); inflateEnd(&stream);
if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) if ( err == Z_NEED_DICT ||
(err == Z_BUF_ERROR && stream.avail_in == 0))
return Z_DATA_ERROR; return Z_DATA_ERROR;
return err; return err;
} }

75
deps/libz/zutil.c vendored
View File

@ -30,32 +30,62 @@ const char * zlibVersion(void)
uLong zlibCompileFlags(void) uLong zlibCompileFlags(void)
{ {
uLong flags; uLong flags = 0;
flags = 0; switch ((int)(sizeof(uInt)))
switch ((int)(sizeof(uInt))) { {
case 2: break; case 2:
case 4: flags += 1; break; break;
case 8: flags += 2; break; case 4:
default: flags += 3; flags += 1;
break;
case 8:
flags += 2;
break;
default:
flags += 3;
} }
switch ((int)(sizeof(uLong))) {
case 2: break; switch ((int)(sizeof(uLong)))
case 4: flags += 1 << 2; break; {
case 8: flags += 2 << 2; break; case 2:
default: flags += 3 << 2; break;
case 4:
flags += 1 << 2;
break;
case 8:
flags += 2 << 2;
break;
default:
flags += 3 << 2;
} }
switch ((int)(sizeof(voidpf))) {
case 2: break; switch ((int)(sizeof(voidpf)))
case 4: flags += 1 << 4; break; {
case 8: flags += 2 << 4; break; case 2:
default: flags += 3 << 4; break;
case 4:
flags += 1 << 4;
break;
case 8:
flags += 2 << 4;
break;
default:
flags += 3 << 4;
} }
switch ((int)(sizeof(z_off_t))) {
case 2: break; switch ((int)(sizeof(z_off_t)))
case 4: flags += 1 << 6; break; {
case 8: flags += 2 << 6; break; case 2:
default: flags += 3 << 6; break;
case 4:
flags += 1 << 6;
break;
case 8:
flags += 2 << 6;
break;
default:
flags += 3 << 6;
} }
#ifdef DEBUG #ifdef DEBUG
flags += 1 << 8; flags += 1 << 8;
@ -151,5 +181,4 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
{ {
free(ptr); free(ptr);
if (opaque) return; /* make compiler happy */
} }

View File

@ -9,13 +9,11 @@
#endif #endif
#include "../gfx/drivers_shader/glslang.cpp" #include "../gfx/drivers_shader/glslang.cpp"
#include "../deps/glslang/glslang/SPIRV/disassemble.cpp"
#include "../deps/glslang/glslang/SPIRV/doc.cpp" #include "../deps/glslang/glslang/SPIRV/doc.cpp"
#include "../deps/glslang/glslang/SPIRV/GlslangToSpv.cpp" #include "../deps/glslang/glslang/SPIRV/GlslangToSpv.cpp"
#include "../deps/glslang/glslang/SPIRV/InReadableOrder.cpp" #include "../deps/glslang/glslang/SPIRV/InReadableOrder.cpp"
#include "../deps/glslang/glslang/SPIRV/Logger.cpp" #include "../deps/glslang/glslang/SPIRV/Logger.cpp"
#include "../deps/glslang/glslang/SPIRV/SpvBuilder.cpp" #include "../deps/glslang/glslang/SPIRV/SpvBuilder.cpp"
#include "../deps/glslang/glslang/SPIRV/SPVRemapper.cpp"
#include "../deps/glslang/glslang/glslang/GenericCodeGen/CodeGen.cpp" #include "../deps/glslang/glslang/glslang/GenericCodeGen/CodeGen.cpp"
#include "../deps/glslang/glslang/glslang/GenericCodeGen/Link.cpp" #include "../deps/glslang/glslang/glslang/GenericCodeGen/Link.cpp"