From bcb07d68e689c0641be5a5d9b692b779aa9deeb0 Mon Sep 17 00:00:00 2001 From: Josh MacDonald Date: Sun, 19 Oct 2014 00:56:02 -0700 Subject: Support for 64bit usize_t w/ XD3_USE_LARGEWINDOW64 --- xdelta3/Makefile.am | 5 ++- xdelta3/xdelta3-blkcache.h | 22 +++++------ xdelta3/xdelta3-decode.h | 29 ++++++++------- xdelta3/xdelta3-djw.h | 4 +- xdelta3/xdelta3-main.h | 85 ++++++++++++++++++++++-------------------- xdelta3/xdelta3-second.h | 2 +- xdelta3/xdelta3-test.h | 39 ++++++++++++------- xdelta3/xdelta3.c | 48 ++++++++++++------------ xdelta3/xdelta3.h | 93 +++++++++++++++++++++++++++++----------------- 9 files changed, 184 insertions(+), 143 deletions(-) (limited to 'xdelta3') diff --git a/xdelta3/Makefile.am b/xdelta3/Makefile.am index 3907351..9369100 100644 --- a/xdelta3/Makefile.am +++ b/xdelta3/Makefile.am @@ -38,7 +38,7 @@ xdelta3regtest_SOURCES = $(common_SOURCES) \ # Note: for extra sanity checks, enable -Wconversion. Note there # are a lot of false positives. WFLAGS = -Wall -Wshadow -fno-builtin -Wextra -Wsign-compare \ - -Wextra -Wno-unused-parameter -Wconversion + -Wextra -Wno-unused-parameter # -Wconversion C_WFLAGS = $(WFLAGS) -pedantic -std=c99 @@ -50,6 +50,7 @@ common_CFLAGS = \ -DSECONDARY_FGK=1 \ -DXD3_POSIX=1 \ -DXD3_USE_LARGEFILE64=1 \ + -DXD3_USE_LARGEWINDOW64=1 \ -DXD3_MAIN=1 if DEBUG_SYMBOLS @@ -57,7 +58,7 @@ if DEBUG_SYMBOLS endif # For additional debugging, add -DXD3_DEBUG=1, 2, 3, ... -xdelta3_CFLAGS = $(C_WFLAGS) $(common_CFLAGS) -DXD3_DEBUG=0 +xdelta3_CFLAGS = $(C_WFLAGS) $(common_CFLAGS) -DXD3_DEBUG=3 xdelta3_LDADD = -lm xdelta3decode_CFLAGS = \ diff --git a/xdelta3/xdelta3-blkcache.h b/xdelta3/xdelta3-blkcache.h index e73a2ab..839ba33 100644 --- a/xdelta3/xdelta3-blkcache.h +++ b/xdelta3/xdelta3-blkcache.h @@ -246,7 +246,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, if (sfile->size_known) { - short_sprintf (srcszbuf, "source size %s [%"Q"u]", + short_sprintf (srcszbuf, "source size %s [%"Q"]", main_format_bcnt (source_size, &srccntbuf), source_size); } @@ -259,7 +259,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, if (option_verbose > 1) { - short_sprintf (nbufs, " #bufs %u", lru_size); + short_sprintf (nbufs, " #bufs %"Z, lru_size); } XPR(NT "source %s %s blksize %s window %s%s%s\n", @@ -366,7 +366,7 @@ main_read_seek_source (xd3_stream *stream, if (!option_quiet) { XPR(NT "source can't seek backwards; requested block offset " - "%"Q"u source position is %"Q"u\n", + "%"Q" source position is %"Q"\n", pos, sfile->source_position); } @@ -386,7 +386,7 @@ main_read_seek_source (xd3_stream *stream, if (option_verbose > 1) { - XPR(NT "seek error at offset %"Q"u: %s\n", + XPR(NT "seek error at offset %"Q": %s\n", pos, xd3_mainerror (ret)); } } @@ -395,7 +395,7 @@ main_read_seek_source (xd3_stream *stream, if (option_verbose > 1 && pos != sfile->source_position) { - XPR(NT "non-seekable source skipping %"Q"u bytes @ %"Q"u\n", + XPR(NT "non-seekable source skipping %"Q" bytes @ %"Q"\n", pos - sfile->source_position, sfile->source_position); } @@ -440,7 +440,7 @@ main_read_seek_source (xd3_stream *stream, sfile->source_position += nread; blru->size = nread; - IF_DEBUG1 (DP(RINT "[getblk] skip blkno %"Q"u size %u\n", + IF_DEBUG1 (DP(RINT "[getblk] skip blkno %"Q" size %u\n", skip_blkno, blru->size)); XD3_ASSERT (sfile->source_position <= pos); @@ -536,20 +536,20 @@ main_getblk_func (xd3_stream *stream, { if (blru->blkno != blkno) { - XPR(NT "source block %"Q"u read %zu ejects %"Q"u (lru_hits=%u, " + XPR(NT "source block %"Q" read %zu ejects %"Q" (lru_hits=%u, " "lru_misses=%u, lru_filled=%u)\n", blkno, nread, blru->blkno, lru_hits, lru_misses, lru_filled); } else { - XPR(NT "source block %"Q"u read %zu (lru_hits=%u, " + XPR(NT "source block %"Q" read %zu (lru_hits=%u, " "lru_misses=%u, lru_filled=%u)\n", blkno, nread, lru_hits, lru_misses, lru_filled); } } else { - XPR(NT "source block %"Q"u read %zu (lru_hits=%u, lru_misses=%u, " + XPR(NT "source block %"Q" read %zu (lru_hits=%u, lru_misses=%u, " "lru_filled=%u)\n", blkno, nread, lru_hits, lru_misses, lru_filled); } @@ -561,8 +561,8 @@ main_getblk_func (xd3_stream *stream, blru->size = nread; blru->blkno = blkno; - IF_DEBUG1 (DP(RINT "[main_getblk] blkno %"Q"u onblk %zu pos %"Q"u " - "srcpos %"Q"u\n", + IF_DEBUG1 (DP(RINT "[main_getblk] blkno %"Q" onblk %zu pos %"Q" " + "srcpos %"Q"\n", blkno, nread, pos, sfile->source_position)); return 0; diff --git a/xdelta3/xdelta3-decode.h b/xdelta3/xdelta3-decode.h index b0051aa..c95f8b5 100644 --- a/xdelta3/xdelta3-decode.h +++ b/xdelta3/xdelta3-decode.h @@ -224,13 +224,14 @@ xd3_decode_parse_halfinst (xd3_stream *stream, xd3_hinst *inst) { IF_DEBUG2 ({ static int cnt = 0; - XPR(NT "DECODE:%u: COPY at %"Q"u (winoffset %u) size %u winaddr %u\n", - cnt++, - stream->total_out + (stream->dec_position - - stream->dec_cpylen), - (stream->dec_position - stream->dec_cpylen), - inst->size, - inst->addr); + XPR(NT "DECODE:%u: COPY at %"Q" (winoffset %"Z") " + "size %"Z" winaddr %"Z"\n", + cnt++, + stream->total_out + (stream->dec_position - + stream->dec_cpylen), + (stream->dec_position - stream->dec_cpylen), + inst->size, + inst->addr); }); if ((ret = xd3_decode_address (stream, @@ -265,7 +266,7 @@ xd3_decode_parse_halfinst (xd3_stream *stream, xd3_hinst *inst) if (inst->type == XD3_ADD) { static int cnt; - XPR(NT "DECODE:%d: ADD at %"Q"u (winoffset %u) size %u\n", + XPR(NT "DECODE:%d: ADD at %"Q" (winoffset %"Z") size %"Z"\n", cnt++, (stream->total_out + stream->dec_position - stream->dec_cpylen), stream->dec_position - stream->dec_cpylen, @@ -275,7 +276,7 @@ xd3_decode_parse_halfinst (xd3_stream *stream, xd3_hinst *inst) { static int cnt; XD3_ASSERT (inst->type == XD3_RUN); - XPR(NT "DECODE:%d: RUN at %"Q"u (winoffset %u) size %u\n", + XPR(NT "DECODE:%d: RUN at %"Q" (winoffset %"Z") size %"Z"\n", cnt++, stream->total_out + stream->dec_position - stream->dec_cpylen, stream->dec_position - stream->dec_cpylen, @@ -453,8 +454,8 @@ xd3_decode_output_halfinst (xd3_stream *stream, xd3_hinst *inst) if ((source->onblk != blksize) && (blkoff + take > source->onblk)) { - IF_DEBUG1 (XPR(NT "[srcfile] short at blkno %"Q"u onblk " - "%u blksize %u blkoff %u take %u\n", + IF_DEBUG1 (XPR(NT "[srcfile] short at blkno %"Q" onblk " + "%"Z" blksize %"Z" blkoff %"Z" take %"Z"\n", block, source->onblk, blksize, @@ -916,7 +917,7 @@ xd3_decode_input (xd3_stream *stream) stream->dec_state = DEC_CPYLEN; - IF_DEBUG2 (DP(RINT "--------- TARGET WINDOW %"Q"u -----------\n", + IF_DEBUG2 (DP(RINT "--------- TARGET WINDOW %"Q" -----------\n", stream->current_window)); } @@ -1073,8 +1074,8 @@ xd3_decode_input (xd3_stream *stream) &src->cpyoff_blkoff); IF_DEBUG1(DP(RINT - "decode cpyoff %"Q"u " - "cpyblkno %"Q"u " + "decode cpyoff %"Q" " + "cpyblkno %"Q" " "cpyblkoff %u " "blksize %u\n", stream->dec_cpyoff, diff --git a/xdelta3/xdelta3-djw.h b/xdelta3/xdelta3-djw.h index cba061e..729f492 100644 --- a/xdelta3/xdelta3-djw.h +++ b/xdelta3/xdelta3-djw.h @@ -493,8 +493,8 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t { IF_DEBUG2 (if (first_bits != total_bits) { - DP(RINT "code length overflow changed %u bits\n", - (usize_t)(total_bits - first_bits)); + DP(RINT "code length overflow changed %"Z" bits\n", + total_bits - first_bits); }); return total_bits; } diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h index 108a71a..030bc85 100644 --- a/xdelta3/xdelta3-main.h +++ b/xdelta3/xdelta3-main.h @@ -383,6 +383,7 @@ main_config (void) XPR(NTR "XD3_STDIO=%d\n", XD3_STDIO); XPR(NTR "XD3_WIN32=%d\n", XD3_WIN32); XPR(NTR "XD3_USE_LARGEFILE64=%d\n", XD3_USE_LARGEFILE64); + XPR(NTR "XD3_USE_LARGEWINDOW64=%d\n", XD3_USE_LARGEWINDOW64); XPR(NTR "XD3_DEFAULT_LEVEL=%d\n", XD3_DEFAULT_LEVEL); XPR(NTR "XD3_DEFAULT_IOPT_SIZE=%d\n", XD3_DEFAULT_IOPT_SIZE); XPR(NTR "XD3_DEFAULT_SPREVSZ=%d\n", XD3_DEFAULT_SPREVSZ); @@ -610,7 +611,7 @@ main_format_bcnt (xoff_t r, shortbuf *buf) if (r >= 100 && r < 1000) { - short_sprintf (*buf, "%"Q"u %s", r, fmts[i]); + short_sprintf (*buf, "%"Q" %s", r, fmts[i]); return buf->buf; } @@ -710,12 +711,12 @@ main_atoux (const char* arg, xoff_t *xo, xoff_t low, if (x < low) { - XPR(NT "-%c: minimum value: %"Q"u\n", which, low); + XPR(NT "-%c: minimum value: %"Q"\n", which, low); return EXIT_FAILURE; } if (high != 0 && x > high) { - XPR(NT "-%c: maximum value: %"Q"u\n", which, high); + XPR(NT "-%c: maximum value: %"Q"\n", which, high); return EXIT_FAILURE; } (*xo) = x; @@ -1105,7 +1106,7 @@ main_file_write (main_file *ofile, uint8_t *buf, usize_t size, const char *msg) } else { - if (option_verbose > 5) { XPR(NT "write %s: %u bytes\n", + if (option_verbose > 5) { XPR(NT "write %s: %"Z" bytes\n", ofile->filename, size); } ofile->nwrite += size; } @@ -1290,7 +1291,7 @@ main_print_window (xd3_stream* stream, main_file *xfile) if ((ret = xd3_decode_instruction (stream))) { - XPR(NT "instruction decode error at %"Q"u: %s\n", + XPR(NT "instruction decode error at %"Q": %s\n", stream->dec_winstart + size, stream->msg); return ret; } @@ -1298,7 +1299,8 @@ main_print_window (xd3_stream* stream, main_file *xfile) addr_bytes = (usize_t)(stream->addr_sect.buf - addr_before); inst_bytes = (usize_t)(stream->inst_sect.buf - inst_before); - VC(UT " %06"Q"u %03u %s %6u", stream->dec_winstart + size, + VC(UT " %06"Q" %03"Z" %s %6"Z, + stream->dec_winstart + size, option_print_cpymode ? code : 0, xd3_rtype_to_string ((xd3_rtype) stream->dec_current1.type, option_print_cpymode), @@ -1310,12 +1312,12 @@ main_print_window (xd3_stream* stream, main_file *xfile) { if (stream->dec_current1.addr >= stream->dec_cpylen) { - VC(UT " T@%-6u", + VC(UT " T@%-6"Z, stream->dec_current1.addr - stream->dec_cpylen)VE; } else { - VC(UT " S@%-6"Q"u", + VC(UT " S@%-6"Q, stream->dec_cpyoff + stream->dec_current1.addr)VE; } } @@ -1329,7 +1331,7 @@ main_print_window (xd3_stream* stream, main_file *xfile) if (stream->dec_current2.type != XD3_NOOP) { - VC(UT " %s %6u", + VC(UT " %s %6"Z, xd3_rtype_to_string ((xd3_rtype) stream->dec_current2.type, option_print_cpymode), stream->dec_current2.size)VE; @@ -1338,12 +1340,12 @@ main_print_window (xd3_stream* stream, main_file *xfile) { if (stream->dec_current2.addr >= stream->dec_cpylen) { - VC(UT " T@%-6u", + VC(UT " T@%-6"Q, stream->dec_current2.addr - stream->dec_cpylen)VE; } else { - VC(UT " S@%-6"Q"u", + VC(UT " S@%-6"Q"", stream->dec_cpyoff + stream->dec_current2.addr)VE; } } @@ -1358,7 +1360,7 @@ main_print_window (xd3_stream* stream, main_file *xfile) (stream->dec_current1.type >= XD3_CPY || stream->dec_current2.type >= XD3_CPY)) { - VC(UT " %06"Q"u (inefficiency) %u encoded as %u bytes\n", + VC(UT " %06"Q" (inefficiency) %"Z" encoded as %"Z" bytes\n", stream->dec_winstart + size_before, size - size_before, addr_bytes + inst_bytes)VE; @@ -1426,7 +1428,7 @@ main_print_func (xd3_stream* stream, main_file *xfile) if (stream->dec_winstart == 0) { VC(UT "VCDIFF version: 0\n")VE; - VC(UT "VCDIFF header size: %d\n", + VC(UT "VCDIFF header size: %"Z"\n", stream->dec_hdrsize)VE; VC(UT "VCDIFF header indicator: ")VE; if ((stream->dec_hdr_ind & VCD_SECONDARY) != 0) @@ -1481,7 +1483,7 @@ main_print_func (xd3_stream* stream, main_file *xfile) VC(UT "\n")VE; } - VC(UT "VCDIFF window number: %"Q"u\n", stream->current_window)VE; + VC(UT "VCDIFF window number: %"Q"\n", stream->current_window)VE; VC(UT "VCDIFF window indicator: ")VE; if ((stream->dec_win_ind & VCD_SOURCE) != 0) VC(UT "VCD_SOURCE ")VE; if ((stream->dec_win_ind & VCD_TARGET) != 0) VC(UT "VCD_TARGET ")VE; @@ -1492,7 +1494,7 @@ main_print_func (xd3_stream* stream, main_file *xfile) if ((stream->dec_win_ind & VCD_ADLER32) != 0) { VC(UT "VCDIFF adler32 checksum: %08X\n", - (usize_t)stream->dec_adler32)VE; + stream->dec_adler32)VE; } if (stream->dec_del_ind != 0) @@ -1507,27 +1509,27 @@ main_print_func (xd3_stream* stream, main_file *xfile) if (stream->dec_winstart != 0) { - VC(UT "VCDIFF window at offset: %"Q"u\n", stream->dec_winstart)VE; + VC(UT "VCDIFF window at offset: %"Q"\n", stream->dec_winstart)VE; } if (SRCORTGT (stream->dec_win_ind)) { - VC(UT "VCDIFF copy window length: %u\n", - (usize_t)stream->dec_cpylen)VE; - VC(UT "VCDIFF copy window offset: %"Q"u\n", + VC(UT "VCDIFF copy window length: %"Z"\n", + stream->dec_cpylen)VE; + VC(UT "VCDIFF copy window offset: %"Q"\n", stream->dec_cpyoff)VE; } - VC(UT "VCDIFF delta encoding length: %u\n", + VC(UT "VCDIFF delta encoding length: %"Z"\n", (usize_t)stream->dec_enclen)VE; - VC(UT "VCDIFF target window length: %u\n", + VC(UT "VCDIFF target window length: %"Z"\n", (usize_t)stream->dec_tgtlen)VE; - VC(UT "VCDIFF data section length: %u\n", + VC(UT "VCDIFF data section length: %"Z"\n", (usize_t)stream->data_sect.size)VE; - VC(UT "VCDIFF inst section length: %u\n", + VC(UT "VCDIFF inst section length: %"Z"\n", (usize_t)stream->inst_sect.size)VE; - VC(UT "VCDIFF addr section length: %u\n", + VC(UT "VCDIFF addr section length: %"Z"\n", (usize_t)stream->addr_sect.size)VE; ret = 0; @@ -1967,8 +1969,11 @@ main_merge_output (xd3_stream *stream, main_file *ofile) XD3_ASSERT (inst->addr >= window_start); addr = inst->addr - window_start; } - IF_DEBUG2 (XPR(NTR "[merge copy] winpos %u take %u addr %"Q"u mode %u\n", - window_pos, take, addr, inst->mode)); + IF_DEBUG2 ({ + XPR(NTR "[merge copy] winpos %"Z" take %"Z" " + "addr %"Q" mode %u\n", + window_pos, take, addr, inst->mode); + }); if ((ret = xd3_found_match (recode_stream, window_pos, take, addr, inst->mode != 0))) { @@ -2243,7 +2248,7 @@ main_pipe_copier (uint8_t *pipe_buf, if (option_verbose && skipped != 0) { - XPR(NT "skipping %"Q"u bytes in %s\n", + XPR(NT "skipping %"Q" bytes in %s\n", skipped, ifile->filename); } return 0; @@ -3041,7 +3046,7 @@ main_input (xd3_cmd cmd, { const char *s = option_smatch_config; char *e; - usize_t values[XD3_SOFTCFG_VARCNT]; + long values[XD3_SOFTCFG_VARCNT]; int got; config.smatch_cfg = XD3_SMATCH_SOFT; @@ -3284,7 +3289,7 @@ main_input (xd3_cmd cmd, /* Warn when no source copies are found */ if (option_verbose && ! xd3_encoder_used_source (& stream)) { - XPR(NT "warning: input window %"Q"u..%"Q"u has " + XPR(NT "warning: input window %"Q"..%"Q" has " "no source copies\n", stream.current_window * winsize, (stream.current_window+1) * winsize); @@ -3297,8 +3302,8 @@ main_input (xd3_cmd cmd, stream.srcwin_decided_early && stream.i_slots_used > stream.iopt_size) { - XPR(NT "warning: input position %"Q"u overflowed " - "instruction buffer, needed %u (vs. %u), " + XPR(NT "warning: input position %"Q" overflowed " + "instruction buffer, needed %"Z" (vs. %"Z"), " "consider changing -I\n", stream.current_window * winsize, stream.i_slots_used, stream.iopt_size); @@ -3321,7 +3326,7 @@ main_input (xd3_cmd cmd, if (option_verbose > 1) { - XPR(NT "%"Q"u: in %s (%s): out %s (%s): " + XPR(NT "%"Q": in %s (%s): out %s (%s): " "total in %s: out %s: %s: srcpos %s\n", stream.current_window, main_format_bcnt (this_read, &rdb), @@ -3335,7 +3340,7 @@ main_input (xd3_cmd cmd, } else { - XPR(NT "%"Q"u: in %s: out %s: total in %s: " + XPR(NT "%"Q": in %s: out %s: total in %s: " "out %s: %s\n", stream.current_window, main_format_bcnt (this_read, &rdb), @@ -3422,21 +3427,21 @@ done: if (option_verbose > 1 && cmd == CMD_ENCODE) { XPR(NT "scanner configuration: %s\n", stream.smatcher.name); - XPR(NT "target hash table size: %u\n", stream.small_hash.size); + XPR(NT "target hash table size: %"Z"\n", stream.small_hash.size); if (sfile != NULL && sfile->filename != NULL) { - XPR(NT "source hash table size: %u\n", stream.large_hash.size); + XPR(NT "source hash table size: %"Z"\n", stream.large_hash.size); } } if (option_verbose > 2 && cmd == CMD_ENCODE) { - XPR(NT "source copies: %"Q"u (%"Q"u bytes)\n", + XPR(NT "source copies: %"Q" (%"Q" bytes)\n", stream.n_scpy, stream.l_scpy); - XPR(NT "target copies: %"Q"u (%"Q"u bytes)\n", + XPR(NT "target copies: %"Q" (%"Q" bytes)\n", stream.n_tcpy, stream.l_tcpy); - XPR(NT "adds: %"Q"u (%"Q"u bytes)\n", stream.n_add, stream.l_add); - XPR(NT "runs: %"Q"u (%"Q"u bytes)\n", stream.n_run, stream.l_run); + XPR(NT "adds: %"Q" (%"Q" bytes)\n", stream.n_add, stream.l_add); + XPR(NT "runs: %"Q" (%"Q" bytes)\n", stream.n_run, stream.l_run); } #endif @@ -3448,7 +3453,7 @@ done: long end_time = get_millisecs_now (); xoff_t nwrite = ofile != NULL ? ofile->nwrite : 0; - XPR(NT "finished in %s; input %"Q"u output %"Q"u bytes (%0.2f%%)\n", + XPR(NT "finished in %s; input %"Q" output %"Q" bytes (%0.2f%%)\n", main_format_millis (end_time - start_time, &tm), ifile->nread, nwrite, 100.0 * nwrite / ifile->nread); } diff --git a/xdelta3/xdelta3-second.h b/xdelta3/xdelta3-second.h index 1c8a406..098a5d5 100644 --- a/xdelta3/xdelta3-second.h +++ b/xdelta3/xdelta3-second.h @@ -122,7 +122,7 @@ xd3_decode_secondary (xd3_stream *stream, xd3_desect *sect, xd3_sec_stream **sec_streamp) { - uint32_t dec_size; + usize_t dec_size; uint8_t *out_used; int ret; diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h index 948a1d6..3d505fc 100644 --- a/xdelta3/xdelta3-test.h +++ b/xdelta3/xdelta3-test.h @@ -139,7 +139,10 @@ static char TEST_RECON2_FILE[TESTFILESIZE]; static char TEST_COPY_FILE[TESTFILESIZE]; static char TEST_NOPERM_FILE[TESTFILESIZE]; -#define CHECK(cond) if (!(cond)) { XPR(NT "check failure: " #cond); abort(); } +#define CHECK(cond) \ + if (!(cond)) { \ + XPR(NT __FILE__":%d: check failure: " #cond, __LINE__); \ + abort(); } #if SHELL_TESTS /* Use a fixed soft config so that test values are fixed. See also @@ -199,7 +202,7 @@ test_random_numbers (xd3_stream *stream, int ignore) for (i = 0; i < n_rounds; i += 1) { - sum += mt_exp_rand (mean, USIZE_T_MAX); + sum += mt_exp_rand (mean, UINT32_MAX); } average = (double) sum / (double) n_rounds; @@ -411,7 +414,7 @@ test_compare_files (const char* tgt, const char *rec) { if (obuf[i] != rbuf[i]) { - XPR(NT "byte %u (read %u @ %"Q"u) %d != %d\n", + XPR(NT "byte %u (read %u @ %"Q") %d != %d\n", (int)i, (int)oc, offset, obuf[i], rbuf[i]); diffs++; return XD3_INTERNAL; @@ -677,13 +680,13 @@ test_forward_match (xd3_stream *stream, int unused) for (i = 0; i < 256; i++) { - CHECK(xd3_forward_match(buf1, buf2, i) == (int)i); + CHECK(xd3_forward_match(buf1, buf2, i) == i); } for (i = 0; i < 255; i++) { buf2[i] = 1; - CHECK(xd3_forward_match(buf1, buf2, 256) == (int)i); + CHECK(xd3_forward_match(buf1, buf2, 256) == i); buf2[i] = 0; } @@ -732,7 +735,7 @@ test_address_cache (xd3_stream *stream, int unused) usize_t prev_i; usize_t nearby; - p = (mt_random (&static_mtrand) / (double)USIZE_T_MAX); + p = (mt_random (&static_mtrand) / (double)UINT32_MAX); prev_i = mt_random (&static_mtrand) % offset; nearby = (mt_random (&static_mtrand) % 256) % offset; nearby = max (1U, nearby); @@ -763,9 +766,13 @@ test_address_cache (xd3_stream *stream, int unused) for (offset = 1; offset < ADDR_CACHE_ROUNDS; offset += 1) { - uint32_t addr; + usize_t addr; - if ((ret = xd3_decode_address (stream, offset, modes[offset], & buf, buf_max, & addr))) { return ret; } + if ((ret = xd3_decode_address (stream, offset, modes[offset], + & buf, buf_max, & addr))) + { + return ret; + } if (addr != addrs[offset]) { @@ -1391,7 +1398,7 @@ test_secondary (xd3_stream *stream, const xd3_sec_type *sec, usize_t groups) if ((ret = sec->encode (stream, enc_stream, in_head, out_head, & cfg))) { - XPR(NT "test %u: encode: %s", test_i, stream->msg); + XPR(NT "test %"Z": encode: %s", test_i, stream->msg); goto fail; } @@ -1430,7 +1437,7 @@ test_secondary (xd3_stream *stream, const xd3_sec_type *sec, usize_t groups) compress_size, dec_input, dec_correct, dec_output))) { - XPR(NT "test %u: decode: %s", test_i, stream->msg); + XPR(NT "test %"Z": decode: %s", test_i, stream->msg); goto fail; } @@ -1759,7 +1766,7 @@ test_command_line_arguments (xd3_stream *stream, int ignore) if (ratio >= TEST_ADD_RATIO + TEST_EPSILON) { XPR(NT "test encode with size ratio %.4f, " - "expected < %.4f (%"Q"u, %"Q"u)\n", + "expected < %.4f (%"Q", %"Q")\n", ratio, TEST_ADD_RATIO + TEST_EPSILON, dsize, tsize); stream->msg = "strange encoding"; return XD3_INTERNAL; @@ -2645,14 +2652,14 @@ test_string_matching (xd3_stream *stream, int ignore) default: CHECK(0); } - snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%d/%d", + snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%"Z"/%"Z"", inst->pos, inst->size); rptr += strlen (rptr); if (inst->type == XD3_CPY) { *rptr++ = '@'; - snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%"Q"d", inst->addr); + snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%"Q, inst->addr); rptr += strlen (rptr); } @@ -2668,7 +2675,7 @@ test_string_matching (xd3_stream *stream, int ignore) if (strcmp (rbuf, test->result) != 0) { - XPR(NT "test %u: expected %s: got %s", i, test->result, rbuf); + XPR(NT "test %"Z": expected %s: got %s", i, test->result, rbuf); stream->msg = "wrong result"; return XD3_INTERNAL; } @@ -2743,6 +2750,7 @@ test_iopt_flush_instructions (xd3_stream *stream, int ignore) /* * This tests the 32/64bit ambiguity for source-window matching. */ +#if !XD3_USE_LARGEWINDOW64 static int test_source_cksum_offset (xd3_stream *stream, int ignore) { @@ -2788,6 +2796,7 @@ test_source_cksum_offset (xd3_stream *stream, int ignore) } return 0; } +#endif /* !XD3_USE_LARGEWINDOW64 */ static int test_in_memory (xd3_stream *stream, int ignore) @@ -2868,7 +2877,9 @@ xd3_selftest (void) DO_TEST (in_memory, 0, 0); DO_TEST (iopt_flush_instructions, 0, 0); +#if !XD3_USE_LARGEWINDOW64 DO_TEST (source_cksum_offset, 0, 0); +#endif DO_TEST (decompress_single_bit_error, 0, 3); DO_TEST (decompress_single_bit_error, XD3_ADLER32, 3); diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index c17a298..e194681 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c @@ -1644,7 +1644,7 @@ xd3_encode_address (xd3_stream *stream, static int xd3_decode_address (xd3_stream *stream, usize_t here, usize_t mode, const uint8_t **inpp, - const uint8_t *max, uint32_t *valp) + const uint8_t *max, usize_t *valp) { int ret; usize_t same_start = 2 + stream->acache.s_near; @@ -2164,11 +2164,11 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno) ret = stream->getblk (stream, source, blkno); if (ret != 0) { - IF_DEBUG1 (DP(RINT "[getblk] app error blkno %"Q"u: %s\n", + IF_DEBUG1 (DP(RINT "[getblk] app error blkno %"Q": %s\n", blkno, xd3_strerror (ret))); return ret; } - IF_DEBUG2 (DP(RINT "[getblk] read source block %"Q"u onblk " + IF_DEBUG2 (DP(RINT "[getblk] read source block %"Q" onblk " "%u blksize %u\n", blkno, source->onblk, source->blksize)); } @@ -2184,8 +2184,8 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno) { source->frontier_blkno = blkno + 1; - IF_DEBUG2 (DP(RINT "[getblk] full source blkno %"Q"u: " - "source length unknown %"Q"u\n", + IF_DEBUG2 (DP(RINT "[getblk] full source blkno %"Q": " + "source length unknown %"Q"\n", blkno, xd3_source_eof (source))); } @@ -2194,7 +2194,7 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno) if (!source->eof_known) { IF_DEBUG2 (DP(RINT "[getblk] eof block has %d bytes; " - "source length known %"Q"u\n", + "source length known %"Q"\n", xd3_bytes_on_srcblk (source, blkno), xd3_source_eof (source))); source->eof_known = 1; @@ -2264,7 +2264,7 @@ xd3_set_source_and_size (xd3_stream *stream, if (ret == 0) { stream->src->eof_known = 1; - IF_DEBUG2 (DP(RINT "[set source] size known %"Q"u\n", + IF_DEBUG2 (DP(RINT "[set source] size known %"Q"\n", source_size)); xd3_blksize_div(source_size, @@ -2474,7 +2474,7 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst) IF_DEBUG2 ({ static int cnt; - DP(RINT "[iopt copy:%d] pos %"Q"u-%"Q"u addr %"Q"u-%"Q"u size %u\n", + DP(RINT "[iopt copy:%d] pos %"Q"-%"Q" addr %"Q"-%"Q" size %u\n", cnt++, stream->total_in + inst->pos, stream->total_in + inst->pos + inst->size, @@ -2493,7 +2493,7 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst) IF_DEBUG2 ({ static int cnt; - DP(RINT "[iopt run:%d] pos %"Q"u size %u\n", cnt++, stream->total_in + inst->pos, inst->size); + DP(RINT "[iopt run:%d] pos %"Q" size %u\n", cnt++, stream->total_in + inst->pos, inst->size); }); break; } @@ -2507,7 +2507,7 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst) IF_DEBUG2 ({ static int cnt; - DP(RINT "[iopt add:%d] pos %"Q"u size %u\n", cnt++, stream->total_in + inst->pos, inst->size); + DP(RINT "[iopt add:%d] pos %"Q" size %u\n", cnt++, stream->total_in + inst->pos, inst->size); }); break; @@ -3410,7 +3410,7 @@ xd3_encode_input (xd3_stream *stream) stream->enc_state = ENC_SEARCH; - IF_DEBUG2 (DP(RINT "[WINSTART:%"Q"u] input bytes %u offset %"Q"u\n", + IF_DEBUG2 (DP(RINT "[WINSTART:%"Q"] input bytes %u offset %"Q"\n", stream->current_window, stream->avail_in, stream->total_in)); return XD3_WINSTART; @@ -3551,7 +3551,7 @@ xd3_encode_input (xd3_stream *stream) stream->total_in += (xoff_t) stream->avail_in; stream->enc_state = ENC_POSTWIN; - IF_DEBUG2 (DP(RINT "[WINFINISH:%"Q"u] in=%"Q"u\n", + IF_DEBUG2 (DP(RINT "[WINFINISH:%"Q"] in=%"Q"\n", stream->current_window, stream->total_in)); return XD3_WINFINISH; @@ -4002,13 +4002,13 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos) * back further than the LRU cache maintaining FIFO discipline, (to * avoid seeking). */ frontier_pos = stream->src->frontier_blkno * stream->src->blksize; - IF_DEBUG2(DP(RINT "[match_setup] frontier_pos %"Q"u, srcpos %"Q"u, " - "src->max_winsize %"Q"u\n", + IF_DEBUG2(DP(RINT "[match_setup] frontier_pos %"Q", srcpos %"Q", " + "src->max_winsize %"Q"\n", frontier_pos, srcpos, stream->src->max_winsize)); if (srcpos < frontier_pos && frontier_pos - srcpos > stream->src->max_winsize) { IF_DEBUG1(DP(RINT "[match_setup] rejected due to src->max_winsize " - "distance eof=%"Q"u srcpos=%"Q"u maxsz=%"Q"u\n", + "distance eof=%"Q" srcpos=%"Q" maxsz=%"Q"\n", xd3_source_eof (stream->src), srcpos, stream->src->max_winsize)); goto bad; @@ -4065,7 +4065,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos) } IF_DEBUG2(DP(RINT - "[match_setup] srcpos %"Q"u (tgtpos %"Q"u) " + "[match_setup] srcpos %"Q" (tgtpos %"Q") " "unrestricted maxback %u maxfwd %u\n", srcpos, stream->total_in + stream->input_position, @@ -4101,7 +4101,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos) } IF_DEBUG1(DP(RINT - "[match_setup] srcpos %"Q"u (tgtpos %"Q"u) " + "[match_setup] srcpos %"Q" (tgtpos %"Q") " "restricted maxback %u maxfwd %u\n", srcpos, stream->total_in + stream->input_position, @@ -4180,7 +4180,7 @@ xd3_source_extend_match (xd3_stream *stream) usize_t tryrem; /* tryrem is the number of matchable bytes */ usize_t matched; - IF_DEBUG2(DP(RINT "[extend match] srcpos %"Q"u\n", + IF_DEBUG2(DP(RINT "[extend match] srcpos %"Q"\n", stream->match_srcpos)); XD3_ASSERT (src != NULL); @@ -4218,7 +4218,7 @@ xd3_source_extend_match (xd3_stream *stream) tryrem = min (tryoff, stream->match_maxback - stream->match_back); - IF_DEBUG2(DP(RINT "[maxback] maxback %u trysrc %"Q"u/%u tgt %u tryrem %u\n", + IF_DEBUG2(DP(RINT "[maxback] maxback %u trysrc %"Q"/%u tgt %u tryrem %u\n", stream->match_maxback, tryblk, tryoff, streamoff, tryrem)); /* TODO: This code can be optimized similar to xd3_match_forward() */ @@ -4339,7 +4339,7 @@ xd3_source_extend_match (xd3_stream *stream) IF_DEBUG2 ({ static int x = 0; - DP(RINT "[source match:%d] (%s) [ %u bytes ]\n", + DP(RINT "[source match:%d] (%s) [ %u bytes ]\n", x++, stream->total_in + target_position, stream->total_in + target_position + match_length, @@ -4666,13 +4666,13 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point) ret = XD3_INTERNAL; } IF_DEBUG1 (DP(RINT - "[srcwin_move_point] async getblk return for %"Q"u\n", + "[srcwin_move_point] async getblk return for %"Q"\n", blkno)); return ret; } IF_DEBUG1 (DP(RINT - "[srcwin_move_point] T=%"Q"u{%"Q"u} S=%"Q"u EOF=%"Q"u %s\n", + "[srcwin_move_point] T=%"Q"{%"Q"} S=%"Q" EOF=%"Q" %s\n", stream->total_in + stream->input_position, logical_input_cksum_pos, stream->srcwin_cksum_pos, @@ -4720,8 +4720,8 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point) } IF_DEBUG1 (DP(RINT - "[srcwin_move_point] exited loop T=%"Q"u{%"Q"u} " - "S=%"Q"u EOF=%"Q"u %s\n", + "[srcwin_move_point] exited loop T=%"Q"{%"Q"} " + "S=%"Q" EOF=%"Q" %s\n", stream->total_in + stream->input_position, logical_input_cksum_pos, stream->srcwin_cksum_pos, diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h index a643526..d8ea1ab 100644 --- a/xdelta3/xdelta3.h +++ b/xdelta3/xdelta3.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* To know more about Xdelta, start by reading xdelta3.c. If you are +/* To learn more about Xdelta, start by reading xdelta3.c. If you are * ready to use the API, continue reading here. There are two * interfaces -- xd3_encode_input and xd3_decode_input -- plus a dozen * or so related calls. This interface is styled after Zlib. */ @@ -87,8 +87,7 @@ #define XD3_DEFAULT_SPREVSZ (1U<<18) #endif -/* The default compression level - */ +/* The default compression level */ #ifndef XD3_DEFAULT_LEVEL #define XD3_DEFAULT_LEVEL 3 #endif @@ -101,6 +100,12 @@ #define XD3_USE_LARGEFILE64 1 #endif +/* The default source window size is limited to 2GB unless + * XD3_USE_LARGEWINDOW64 is defined to 1. */ +#ifndef XD3_USE_LARGEWINDOW64 +#define XD3_USE_LARGEWINDOW64 0 +#endif + /* Sizes and addresses within VCDIFF windows are represented as usize_t * * For source-file offsets and total file sizes, total input and @@ -109,6 +114,8 @@ * the 32bit boundary [xdelta3-test.h]). */ #ifndef _WIN32 +#define __STDC_FORMAT_MACROS +#include #include #else #define WIN32_LEAN_AND_MEAN @@ -142,8 +149,6 @@ typedef ULONGLONG uint64_t; #endif #endif -typedef uint32_t usize_t; - #if XD3_USE_LARGEFILE64 #define __USE_FILE_OFFSET64 1 /* GLIBC: for 64bit fileops, ... ? */ #ifndef _LARGEFILE_SOURCE @@ -153,23 +158,43 @@ typedef uint32_t usize_t; #define _FILE_OFFSET_BITS 64 #endif -typedef uint64_t xoff_t; #define SIZEOF_XOFF_T 8 -#define SIZEOF_USIZE_T 4 -#ifndef WIN32 -#if SIZEOF_SIZE_T == 8 -#define Q "z" -#else -#define Q "ll" -#endif -#else -#define Q "I64" +typedef uint64_t xoff_t; + +#ifndef _WIN32 +#define Q PRIu64 +//#define Qd PRId64 +#else /* _WIN32 */ +#define Q "I64u" +//#define Qd "I64d" #endif -#else -typedef uint32_t xoff_t; + +#else /* XD3_USE_LARGEFILE64 */ + #define SIZEOF_XOFF_T 4 +typedef uint32_t xoff_t; + +#define Q "u" +//#define Qd "d" + +#endif /* XD3_USE_LARGEFILE64 */ + +#if XD3_USE_LARGEWINDOW64 + +#if !XD3_USE_LARGEFILE64 +#error "Invalid configuration" +#endif + +#define SIZEOF_USIZE_T 8 +typedef uint64_t usize_t; + +#define Z Q +#else /* XD3_USE_LARGEWINDOW64 */ + #define SIZEOF_USIZE_T 4 -#define Q +typedef uint32_t usize_t; + +#define Z "u" #endif #define USE_UINT32 (SIZEOF_USIZE_T == 4 || \ @@ -302,9 +327,12 @@ typedef int (xd3_comp_table_func) (xd3_stream *stream, #if XD3_DEBUG -#define XD3_ASSERT(x) \ - do { if (! (x)) { DP(RINT "%s:%d: XD3 assertion failed: %s\n", __FILE__, __LINE__, #x); \ - abort (); } } while (0) +#define XD3_ASSERT(x) \ + do { \ + if (! (x)) { \ + DP(RINT "%s:%d: XD3 assertion failed: %s\n", \ + __FILE__, __LINE__, #x); \ + abort (); } } while (0) #else #define XD3_ASSERT(x) (void)0 #endif /* XD3_DEBUG */ @@ -556,9 +584,9 @@ struct _xd3_dinst /* the decoded form of a single (half) instruction. */ struct _xd3_hinst { - uint8_t type; - uint32_t size; /* TODO: why decode breaks if this is usize_t? */ - uint32_t addr; /* TODO: why decode breaks if this is usize_t? */ + uint8_t type; + usize_t size; + usize_t addr; }; /* the form of a whole-file instruction */ @@ -585,7 +613,7 @@ struct _xd3_desect { const uint8_t *buf; const uint8_t *buf_max; - uint32_t size; /* TODO: why decode breaks if this is usize_t? */ + usize_t size; usize_t pos; /* used in xdelta3-decode.h */ @@ -898,13 +926,11 @@ struct _xd3_stream usize_t dec_secondid; /* Optional secondary compressor ID. */ - /* TODO: why decode breaks if this is usize_t? */ - uint32_t dec_codetblsz; /* Optional code table: length. */ + usize_t dec_codetblsz; /* Optional code table: length. */ uint8_t *dec_codetbl; /* Optional code table: storage. */ usize_t dec_codetblbytes; /* Optional code table: position. */ - /* TODO: why decode breaks if this is usize_t? */ - uint32_t dec_appheadsz; /* Optional application header: + usize_t dec_appheadsz; /* Optional application header: size. */ uint8_t *dec_appheader; /* Optional application header: storage */ @@ -915,15 +941,12 @@ struct _xd3_stream uint8_t dec_cksum[4]; /* Optional checksum: storage. */ uint32_t dec_adler32; /* Optional checksum: value. */ - /* TODO: why decode breaks if this is usize_t? */ - uint32_t dec_cpylen; /* length of copy window + usize_t dec_cpylen; /* length of copy window (VCD_SOURCE or VCD_TARGET) */ xoff_t dec_cpyoff; /* offset of copy window (VCD_SOURCE or VCD_TARGET) */ - /* TODO: why decode breaks if this is usize_t? */ - uint32_t dec_enclen; /* length of delta encoding */ - /* TODO: why decode breaks if this is usize_t? */ - uint32_t dec_tgtlen; /* length of target window */ + usize_t dec_enclen; /* length of delta encoding */ + usize_t dec_tgtlen; /* length of target window */ #if USE_UINT64 uint64_t dec_64part; /* part of a decoded uint64_t */ -- cgit v1.2.3