Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions xdelta3/testing/checksum_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,17 +404,17 @@ template <typename Checksum> struct test_result : public test_result_base {

void print() {
if (fstats.count != count()) {
fprintf(stderr, "internal error: %" W "d != %" W "d\n", fstats.count,
count());
fprintf(stderr, "internal error: %" XD3_W "d != %" XD3_W "d\n",
fstats.count, count());
abort();
}
print_header();
printf("%-32s%d/%d 2^%" W "u\t%" W "u\t%0.4f\t%.4f\t%.4f\t%.1e\t%.2f\t"
"%" W "u\t%" W "u\n",
test_name, Checksum::cksum_size, Checksum::cksum_skip, h_bits,
count(), uniqueness(), fullness(), coverage(), collisions(),
0.001 * accum_iters * test_size / accum_millis, accum_iters,
colls());
printf(
"%-32s%d/%d 2^%" XD3_W "u\t%" XD3_W "u\t%0.4f\t%.4f\t%.4f\t%.1e\t%.2f\t"
"%" XD3_W "u\t%" XD3_W "u\n",
test_name, Checksum::cksum_size, Checksum::cksum_skip, h_bits, count(),
uniqueness(), fullness(), coverage(), collisions(),
0.001 * accum_iters * test_size / accum_millis, accum_iters, colls());
}

usize_t size_log2(usize_t slots) {
Expand Down
6 changes: 3 additions & 3 deletions xdelta3/testing/delta.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class Delta {
// xd3_winst &winst = stream_.whole_target.inst[i];
// switch (winst.type) {
// case XD3_RUN:
// DP(RINT, "%" Q "u run %" W "u\n", winst.position, winst.size);
// DP(RINT, "%" XD3_Q "u run %" XD3_W "u\n", winst.position, winst.size);
// break;
// case XD3_ADD:
// DP(RINT "%" Q "u add %" W "u\n", winst.position, winst.size);
// DP(RINT "%" XD3_Q "u add %" XD3_W "u\n", winst.position, winst.size);
// break;
// default:
// DP(RINT "%" Q "u copy %" W "u @ %" Q "u (mode %u)\n",
// DP(RINT "%" XD3_Q "u copy %" XD3_W "u @ %" XD3_Q "u (mode %u)\n",
// winst.position, winst.size, winst.addr, winst.mode);
// break;
// }
Expand Down
4 changes: 2 additions & 2 deletions xdelta3/testing/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Block {
// xoff_t pos = 0;
// for (size_t i = 0; i < Size(); i++) {
// if (pos % 16 == 0) {
// DP(RINT "%5" Q "x: ", pos);
// DP(RINT "%5" XD3_Q "x: ", pos);
// }
// DP(RINT "%02x ", (*this)[i]);
// if (pos % 16 == 15) {
Expand Down Expand Up @@ -293,7 +293,7 @@ class ExtFile {
pid_t pid = getpid();
char buf[64];
xoff_t xpid = pid;
snprintf(buf, 64, "/tmp/regtest.%" Q "u.%d", xpid, static_counter++);
snprintf(buf, 64, "/tmp/regtest.%" XD3_Q "u.%d", xpid, static_counter++);
filename_.append(buf);
unlink(filename_.c_str());
}
Expand Down
26 changes: 13 additions & 13 deletions xdelta3/testing/regtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ template <typename Constants> class Regtest {
bool done = false;
bool done_after_input = false;

IF_DEBUG1(XPR(NTR "source %" Q "u[%" Z "u] target %" Q "u winsize %" Z
"u\n",
IF_DEBUG1(XPR(NTR "source %" XD3_Q "u[%" XD3_Z "u] target %" XD3_Q
"u winsize %" XD3_Z "u\n",
source_file.Size(), options.block_size, target_file.Size(),
Constants::WINDOW_SIZE));

Expand All @@ -109,11 +109,11 @@ template <typename Constants> class Regtest {

xoff_t blks = target_iterator.Blocks();

IF_DEBUG2(XPR(NTR "target in %s: %" Q "u[%" Z "u] %" Q "u(%" Q "u) "
"verified %" Q "u\n",
encoding ? "encoding" : "decoding",
target_iterator.Offset(), target_block.Size(),
target_iterator.Blkno(), blks, verified_bytes));
IF_DEBUG2(XPR(
NTR "target in %s: %" XD3_Q "u[%" XD3_Z "u] %" XD3_Q "u(%" XD3_Q "u) "
"verified %" XD3_Q "u\n",
encoding ? "encoding" : "decoding", target_iterator.Offset(),
target_block.Size(), target_iterator.Blkno(), blks, verified_bytes));

if (blks == 0 || target_iterator.Blkno() == (blks - 1)) {
xd3_set_flags(&encode_stream, XD3_FLUSH | encode_stream.flags);
Expand Down Expand Up @@ -156,8 +156,8 @@ template <typename Constants> class Regtest {
xd3_source *src = (encoding ? &encode_source : &decode_source);
Block *block = (encoding ? &encode_source_block : &decode_source_block);
if (encoding) {
IF_DEBUG2(XPR(NTR "[srcblock] %" Q "u last srcpos %" Q "u "
"encodepos %" Q "u\n",
IF_DEBUG2(XPR(NTR "[srcblock] %" XD3_Q "u last srcpos %" XD3_Q "u "
"encodepos %" XD3_Q "u\n",
encode_source.getblkno, encode_stream.match_last_srcpos,
encode_stream.input_position + encode_stream.total_in));
}
Expand Down Expand Up @@ -229,7 +229,7 @@ template <typename Constants> class Regtest {
ExtFile *coded_data, const Options &options) {
vector<const char *> ecmd;
char bbuf[16];
snprintf(bbuf, sizeof(bbuf), "-B%" Q "u", options.encode_srcwin_maxsz);
snprintf(bbuf, sizeof(bbuf), "-B%" XD3_Q "u", options.encode_srcwin_maxsz);
ecmd.push_back("xdelta3");
ecmd.push_back(bbuf);
ecmd.push_back("-s");
Expand Down Expand Up @@ -341,7 +341,7 @@ template <typename Constants> class Regtest {
void TestPrintf() {
char buf[64];
xoff_t x = XOFF_T_MAX;
snprintf_func(buf, sizeof(buf), "%" Q "u", x);
snprintf_func(buf, sizeof(buf), "%" XD3_Q "u", x);
const char *expect =
XD3_USE_LARGEFILE64 ? "18446744073709551615" : "4294967295";
XD3_ASSERT(strcmp(buf, expect) == 0);
Expand Down Expand Up @@ -784,7 +784,7 @@ template <typename Constants> class Regtest {
InMemoryEncodeDecode(spec0, spec1, &block, options);
Delta delta(block);

IF_DEBUG1(DP(RINT "[stride=%d] changes=%" W "u adds=%" Q "u\n", s,
IF_DEBUG1(DP(RINT "[stride=%d] changes=%" XD3_W "u adds=%" XD3_Q "u\n", s,
changes, delta.AddedBytes()));
double allowance = Constants::BLOCK_SIZE < 8192 || s < 30 ? 3.0 : 1.1;
CHECK_GE(allowance * changes, (double)delta.AddedBytes());
Expand Down Expand Up @@ -1217,7 +1217,7 @@ template <class T> void UnitTest() {

// These are Xdelta tests.
template <class T> void MainTest() {
XPR(NT "Blocksize %" Q "u windowsize %" Z "u\n", T::BLOCK_SIZE,
XPR(NT "Blocksize %" XD3_Q "u windowsize %" XD3_Z "u\n", T::BLOCK_SIZE,
T::WINDOW_SIZE);
Regtest<T> regtest;
TEST(TestEmptyInMemory);
Expand Down
34 changes: 20 additions & 14 deletions xdelta3/xdelta3-blkcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static int main_set_source(xd3_stream *stream, xd3_cmd cmd, main_file *sfile,
static shortbuf nbufs;

if (sfile->size_known) {
short_sprintf(srcszbuf, "source size %s [%" Q "u]",
short_sprintf(srcszbuf, "source size %s [%" XD3_Q "u]",
main_format_bcnt(source_size, &srccntbuf), source_size);
} else {
short_sprintf(srcszbuf, "%s", "source size unknown");
Expand All @@ -236,7 +236,7 @@ static int main_set_source(xd3_stream *stream, xd3_cmd cmd, main_file *sfile,
nbufs.buf[0] = 0;

if (option_verbose > 1) {
short_sprintf(nbufs, " #bufs %" W "u", lru_size);
short_sprintf(nbufs, " #bufs %" XD3_W "u", lru_size);
}

XPR(NT "source %s %s blksize %s window %s%s%s\n", sfile->filename,
Expand Down Expand Up @@ -275,12 +275,14 @@ static int main_getblk_lru(xd3_source *source, xoff_t blkno,
main_blklru_list_remove(blru);
main_blklru_list_push_back(&lru_list, blru);
(*blrup) = blru;
IF_DEBUG1(DP(RINT "[getblk_lru] HIT blkno = %" Q "u lru_size=%" W "u\n",
IF_DEBUG1(DP(RINT "[getblk_lru] HIT blkno = %" XD3_Q
"u lru_size=%" XD3_W "u\n",
blkno, lru_size));
return 0;
}
}
IF_DEBUG1(DP(RINT "[getblk_lru] MISS blkno = %" Q "u lru_size=%" W "u\n",
IF_DEBUG1(DP(RINT "[getblk_lru] MISS blkno = %" XD3_Q "u lru_size=%" XD3_W
"u\n",
blkno, lru_size));
}

Expand Down Expand Up @@ -325,7 +327,7 @@ static int main_read_seek_source(xd3_stream *stream, xd3_source *source,
* because of do_src_fifo during encode. */
if (!option_quiet) {
XPR(NT "source can't seek backwards; requested block offset "
"%" Q "u source position is %" Q "u\n",
"%" XD3_Q "u source position is %" XD3_Q "u\n",
pos, sfile->source_position);
}

Expand All @@ -342,14 +344,15 @@ static int main_read_seek_source(xd3_stream *stream, xd3_source *source,
XPR(NT "source can't seek, will use FIFO for %s\n", sfile->filename);

if (option_verbose > 1) {
XPR(NT "seek error at offset %" Q "u: %s\n", pos, xd3_mainerror(ret));
XPR(NT "seek error at offset %" XD3_Q "u: %s\n", pos,
xd3_mainerror(ret));
}
}

sfile->seek_failed = 1;

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 %" XD3_Q "u bytes @ %" XD3_Q "u\n",
pos - sfile->source_position, sfile->source_position);
}

Expand Down Expand Up @@ -378,15 +381,15 @@ static int main_read_seek_source(xd3_stream *stream, xd3_source *source,

if (nread != source->blksize) {
IF_DEBUG1(
DP(RINT "[getblk] short skip block nread = %" Z "u\n", nread));
DP(RINT "[getblk] short skip block nread = %" XD3_Z "u\n", nread));
stream->msg = "non-seekable input is short";
return XD3_INVALID_INPUT;
}

sfile->source_position += nread;
blru->size = nread;

IF_DEBUG1(DP(RINT "[getblk] skip blkno %" Q "u size %" W "u\n",
IF_DEBUG1(DP(RINT "[getblk] skip blkno %" XD3_Q "u size %" XD3_W "u\n",
skip_blkno, blru->size));

XD3_ASSERT(sfile->source_position <= pos);
Expand Down Expand Up @@ -457,16 +460,18 @@ static int main_getblk_func(xd3_stream *stream, xd3_source *source,
if (option_verbose > 3) {
if (blru->blkno != XD3_INVALID_OFFSET) {
if (blru->blkno != blkno) {
XPR(NT "source block %" Q "u read %" Z "u ejects %" Q "u (lru_hits=%u, "
XPR(NT "source block %" XD3_Q "u read %" XD3_Z "u ejects %" XD3_Q
"u (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 %" Z "u (lru_hits=%u, "
XPR(NT "source block %" XD3_Q "u read %" XD3_Z "u (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 %" Z "u (lru_hits=%u, lru_misses=%u, "
XPR(NT "source block %" XD3_Q "u read %" XD3_Z
"u (lru_hits=%u, lru_misses=%u, "
"lru_filled=%u)\n",
blkno, nread, lru_hits, lru_misses, lru_filled);
}
Expand All @@ -478,8 +483,9 @@ static int main_getblk_func(xd3_stream *stream, xd3_source *source,
blru->size = nread;
blru->blkno = blkno;

IF_DEBUG1(DP(RINT "[main_getblk] blkno %" Q "u onblk %" Z "u pos %" Q "u "
"srcpos %" Q "u\n",
IF_DEBUG1(DP(RINT "[main_getblk] blkno %" XD3_Q "u onblk %" XD3_Z
"u pos %" XD3_Q "u "
"srcpos %" XD3_Q "u\n",
blkno, nread, pos, sfile->source_position));

return 0;
Expand Down
44 changes: 24 additions & 20 deletions xdelta3/xdelta3-decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ static int xd3_decode_setup_buffers(xd3_stream *stream) {

static int xd3_decode_allocate(xd3_stream *stream, usize_t size,
uint8_t **buf_ptr, usize_t *buf_alloc) {
IF_DEBUG2(DP(RINT "[xd3_decode_allocate] size %" W "u alloc %" W "u\n", size,
*buf_alloc));
IF_DEBUG2(DP(RINT "[xd3_decode_allocate] size %" XD3_W "u alloc %" XD3_W
"u\n",
size, *buf_alloc));

if (*buf_ptr != NULL && *buf_alloc < size) {
xd3_free(stream, *buf_ptr);
Expand Down Expand Up @@ -175,8 +176,8 @@ static int xd3_decode_section(xd3_stream *stream, xd3_desect *section,
/* No allocation/copy needed */
section->buf = stream->next_in;
sect_take = section->size;
IF_DEBUG1(DP(RINT "[xd3_decode_section] zerocopy %" W "u @ %" W
"u avail %" W "u\n",
IF_DEBUG1(DP(RINT "[xd3_decode_section] zerocopy %" XD3_W "u @ %" XD3_W
"u avail %" XD3_W "u\n",
sect_take, section->pos, stream->avail_in));
} else {
usize_t sect_need = section->size - section->pos;
Expand All @@ -195,8 +196,8 @@ static int xd3_decode_section(xd3_stream *stream, xd3_desect *section,
section->buf = section->copied1;
}

IF_DEBUG2(DP(RINT "[xd3_decode_section] take %" W "u @ %" W "u [need %" W
"u] avail %" W "u\n",
IF_DEBUG2(DP(RINT "[xd3_decode_section] take %" XD3_W "u @ %" XD3_W
"u [need %" XD3_W "u] avail %" XD3_W "u\n",
sect_take, section->pos, sect_need, stream->avail_in));
XD3_ASSERT(section->pos + sect_take <= section->alloc1);

Expand All @@ -211,7 +212,8 @@ static int xd3_decode_section(xd3_stream *stream, xd3_desect *section,
}

if (section->pos < section->size) {
IF_DEBUG1(DP(RINT "[xd3_decode_section] further input required %" W "u\n",
IF_DEBUG1(DP(RINT "[xd3_decode_section] further input required %" XD3_W
"u\n",
section->size - section->pos));
stream->msg = "further input required";
return XD3_INPUT;
Expand Down Expand Up @@ -244,8 +246,8 @@ static int xd3_decode_parse_halfinst(xd3_stream *stream, xd3_hinst *inst) {
if (inst->type >= XD3_CPY) {
IF_DEBUG2({
static int cnt = 0;
XPR(NT "DECODE:%u: COPY at %" Q "u (winoffset %" W "u) "
"size %" W "u winaddr %" W "u\n",
XPR(NT "DECODE:%u: COPY at %" XD3_Q "u (winoffset %" XD3_W "u) "
"size %" XD3_W "u winaddr %" XD3_W "u\n",
cnt++,
stream->total_out + (stream->dec_position - stream->dec_cpylen),
(stream->dec_position - stream->dec_cpylen), inst->size, inst->addr);
Expand Down Expand Up @@ -274,14 +276,16 @@ static int xd3_decode_parse_halfinst(xd3_stream *stream, xd3_hinst *inst) {
IF_DEBUG2({
if (inst->type == XD3_ADD) {
static int cnt;
XPR(NT "DECODE:%d: ADD at %" Q "u (winoffset %" W "u) size %" W "u\n",
XPR(NT "DECODE:%d: ADD at %" XD3_Q "u (winoffset %" XD3_W
"u) size %" XD3_W "u\n",
cnt++,
(stream->total_out + stream->dec_position - stream->dec_cpylen),
stream->dec_position - stream->dec_cpylen, inst->size);
} else {
static int cnt;
XD3_ASSERT(inst->type == XD3_RUN);
XPR(NT "DECODE:%d: RUN at %" Q "u (winoffset %" W "u) size %" W "u\n",
XPR(NT "DECODE:%d: RUN at %" XD3_Q "u (winoffset %" XD3_W
"u) size %" XD3_W "u\n",
cnt++,
stream->total_out + stream->dec_position - stream->dec_cpylen,
stream->dec_position - stream->dec_cpylen, inst->size);
Expand Down Expand Up @@ -440,9 +444,9 @@ static int xd3_decode_output_halfinst(xd3_stream *stream, xd3_hinst *inst) {
/* This block is either full, or a partial block that
* must contain enough bytes. */
if ((source->onblk != blksize) && (blkoff + take > source->onblk)) {
IF_DEBUG1(XPR(NT "[srcfile] short at blkno %" Q "u onblk "
"%" W "u blksize %" W "u blkoff %" W "u take %" W
"u\n",
IF_DEBUG1(XPR(NT "[srcfile] short at blkno %" XD3_Q "u onblk "
"%" XD3_W "u blksize %" XD3_W "u blkoff %" XD3_W
"u take %" XD3_W "u\n",
block, source->onblk, blksize, blkoff, take));
stream->msg = "source file too short";
return XD3_INVALID_INPUT;
Expand Down Expand Up @@ -664,7 +668,7 @@ static int xd3_decode_emit(xd3_stream *stream) {
}

if (stream->avail_out != stream->dec_tgtlen) {
IF_DEBUG2(DP(RINT "AVAIL_OUT(%" W "u) != DEC_TGTLEN(%" W "u)\n",
IF_DEBUG2(DP(RINT "AVAIL_OUT(%" XD3_W "u) != DEC_TGTLEN(%" XD3_W "u)\n",
stream->avail_out, stream->dec_tgtlen));
stream->msg = "wrong window length";
return XD3_INVALID_INPUT;
Expand Down Expand Up @@ -881,7 +885,7 @@ int 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 %" XD3_Q "u -----------\n",
stream->current_window));
}

Expand Down Expand Up @@ -1024,10 +1028,10 @@ int xd3_decode_input(xd3_stream *stream) {
xd3_blksize_div(stream->dec_cpyoff, src, &src->cpyoff_blocks,
&src->cpyoff_blkoff);

IF_DEBUG2(DP(RINT "[decode_cpyoff] %" Q "u "
"cpyblkno %" Q "u "
"cpyblkoff %" W "u "
"blksize %" W "u\n",
IF_DEBUG2(DP(RINT "[decode_cpyoff] %" XD3_Q "u "
"cpyblkno %" XD3_Q "u "
"cpyblkoff %" XD3_W "u "
"blksize %" XD3_W "u\n",
stream->dec_cpyoff, src->cpyoff_blocks, src->cpyoff_blkoff,
src->blksize));
}
Expand Down
Loading
Loading