summaryrefslogtreecommitdiff
path: root/xdelta3
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2009-10-25 19:16:41 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2009-10-25 19:16:41 +0000
commitca626a8f838cb329c22b02bcb5c81538a09eea6f (patch)
tree7041ac80eea21c728bb4447eae9bedb3510814f0 /xdelta3
parent0e486ef0fc9d4ea3aa05e120d09459e5cc7af098 (diff)
Test crashes in recode test w/ "allow_fake_source" support, getting close?
Diffstat (limited to 'xdelta3')
-rw-r--r--xdelta3/Makefile2
-rw-r--r--xdelta3/xdelta3-decode.h8
-rw-r--r--xdelta3/xdelta3-djw.h36
-rw-r--r--xdelta3/xdelta3-test.h14
-rw-r--r--xdelta3/xdelta3.c8
5 files changed, 35 insertions, 33 deletions
diff --git a/xdelta3/Makefile b/xdelta3/Makefile
index 55268c5..743ec98 100644
--- a/xdelta3/Makefile
+++ b/xdelta3/Makefile
@@ -82,7 +82,7 @@ SWIG_FLAGS = -DXD3_DEBUG=1 \
82 -DVCDIFF_TOOLS=1 \ 82 -DVCDIFF_TOOLS=1 \
83 -DSWIG_MODULE=1 83 -DSWIG_MODULE=1
84 84
85all: xdelta3-debug xdelta3 85all: xdelta3-debug xdelta3-debug2 xdelta3
86 (cd testing && make) 86 (cd testing && make)
87 87
88all-py: all $(PYTGT) $(SWIGTGT) 88all-py: all $(PYTGT) $(SWIGTGT)
diff --git a/xdelta3/xdelta3-decode.h b/xdelta3/xdelta3-decode.h
index 6412b47..9c812e7 100644
--- a/xdelta3/xdelta3-decode.h
+++ b/xdelta3/xdelta3-decode.h
@@ -444,7 +444,7 @@ xd3_decode_output_halfinst (xd3_stream *stream, xd3_hinst *inst)
444 if ((source->onblk != blksize) && 444 if ((source->onblk != blksize) &&
445 (blkoff + take > source->onblk)) 445 (blkoff + take > source->onblk))
446 { 446 {
447 IF_DEBUG1(DP(RINT "block %"Q"u onblk %u blksize %u blkoff %u take %u\n", 447 IF_DEBUG2(DP(RINT "block %"Q"u onblk %u blksize %u blkoff %u take %u\n",
448 block, 448 block,
449 source->onblk, 449 source->onblk,
450 blksize, 450 blksize,
@@ -671,7 +671,7 @@ xd3_decode_emit (xd3_stream *stream)
671 671
672 if (stream->avail_out != stream->dec_tgtlen) 672 if (stream->avail_out != stream->dec_tgtlen)
673 { 673 {
674 IF_DEBUG1 (DP(RINT "AVAIL_OUT(%d) != DEC_TGTLEN(%d)\n", 674 IF_DEBUG2 (DP(RINT "AVAIL_OUT(%d) != DEC_TGTLEN(%d)\n",
675 stream->avail_out, stream->dec_tgtlen)); 675 stream->avail_out, stream->dec_tgtlen));
676 stream->msg = "wrong window length"; 676 stream->msg = "wrong window length";
677 return XD3_INVALID_INPUT; 677 return XD3_INVALID_INPUT;
@@ -918,7 +918,7 @@ xd3_decode_input (xd3_stream *stream)
918 918
919 stream->dec_state = DEC_CPYLEN; 919 stream->dec_state = DEC_CPYLEN;
920 920
921 IF_DEBUG1 (DP(RINT "--------- TARGET WINDOW %"Q"u -----------\n", 921 IF_DEBUG2 (DP(RINT "--------- TARGET WINDOW %"Q"u -----------\n",
922 stream->current_window)); 922 stream->current_window));
923 } 923 }
924 924
@@ -1074,7 +1074,7 @@ xd3_decode_input (xd3_stream *stream)
1074 &src->cpyoff_blocks, 1074 &src->cpyoff_blocks,
1075 &src->cpyoff_blkoff); 1075 &src->cpyoff_blkoff);
1076 1076
1077 IF_DEBUG1(DP(RINT 1077 IF_DEBUG2(DP(RINT
1078 "decode cpyoff %"Q"u " 1078 "decode cpyoff %"Q"u "
1079 "cpyblkno %"Q"u " 1079 "cpyblkno %"Q"u "
1080 "cpyblkoff %u " 1080 "cpyblkoff %u "
diff --git a/xdelta3/xdelta3-djw.h b/xdelta3/xdelta3-djw.h
index 53de230..7407b1f 100644
--- a/xdelta3/xdelta3-djw.h
+++ b/xdelta3/xdelta3-djw.h
@@ -315,7 +315,7 @@ heap_check (usize_t *heap, djw_heapen *ents, usize_t heap_last)
315 /* Heap property: child not less than parent */ 315 /* Heap property: child not less than parent */
316 XD3_ASSERT (! heap_less (& ents[heap[i]], & ents[heap[i/2]])); 316 XD3_ASSERT (! heap_less (& ents[heap[i]], & ents[heap[i/2]]));
317 317
318 IF_DEBUG1 (DP(RINT "heap[%d] = %u\n", i, ents[heap[i]].freq)); 318 IF_DEBUG2 (DP(RINT "heap[%d] = %u\n", i, ents[heap[i]].freq));
319 } 319 }
320} 320}
321#endif 321#endif
@@ -401,7 +401,7 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t
401 for (i = 0; i < asize; i += 1) 401 for (i = 0; i < asize; i += 1)
402 { 402 {
403 ents[i+1].freq = freq[i]; 403 ents[i+1].freq = freq[i];
404 IF_DEBUG1 (DP(RINT "ents[%d] = freq[%d] = %d\n", 404 IF_DEBUG2 (DP(RINT "ents[%d] = freq[%d] = %d\n",
405 i+1, i, freq[i])); 405 i+1, i, freq[i]));
406 } 406 }
407 407
@@ -480,7 +480,7 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t
480 } 480 }
481 481
482 /* clen is 0-origin, unlike ents. */ 482 /* clen is 0-origin, unlike ents. */
483 IF_DEBUG1 (DP(RINT "clen[%d] = %d\n", i-1, b)); 483 IF_DEBUG2 (DP(RINT "clen[%d] = %d\n", i-1, b));
484 clen[i-1] = b; 484 clen[i-1] = b;
485 } 485 }
486 486
@@ -488,7 +488,7 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t
488 488
489 if (! overflow) 489 if (! overflow)
490 { 490 {
491 IF_DEBUG1 (if (first_bits != total_bits) 491 IF_DEBUG2 (if (first_bits != total_bits)
492 { 492 {
493 DP(RINT "code length overflow changed %u bits\n", 493 DP(RINT "code length overflow changed %u bits\n",
494 (usize_t)(total_bits - first_bits)); 494 (usize_t)(total_bits - first_bits));
@@ -541,7 +541,7 @@ djw_build_codes (usize_t *codes, const uint8_t *clen, usize_t asize, usize_t abs
541 code <<= 1; 541 code <<= 1;
542 } 542 }
543 543
544 IF_DEBUG1 ({ 544 IF_DEBUG2 ({
545 for (i = 0; i < asize; i += 1) 545 for (i = 0; i < asize; i += 1)
546 { 546 {
547 DP(RINT "code[%d] = %u\n", i, codes[i]); 547 DP(RINT "code[%d] = %u\n", i, codes[i]);
@@ -628,7 +628,7 @@ djw_count_freqs (djw_weight *freq, xd3_output *input)
628 while (++p < p_max); 628 while (++p < p_max);
629 } 629 }
630 630
631 IF_DEBUG1 ({int i; 631 IF_DEBUG2 ({int i;
632 DP(RINT "freqs: "); 632 DP(RINT "freqs: ");
633 for (i = 0; i < ALPHABET_SIZE; i += 1) 633 for (i = 0; i < ALPHABET_SIZE; i += 1)
634 { 634 {
@@ -973,7 +973,7 @@ xd3_encode_huff (xd3_stream *stream,
973 usize_t gbest_no; 973 usize_t gbest_no;
974 usize_t gpcnt; 974 usize_t gpcnt;
975 const uint8_t *p; 975 const uint8_t *p;
976 IF_DEBUG1 (usize_t gcount[DJW_MAX_GROUPS]); 976 IF_DEBUG2 (usize_t gcount[DJW_MAX_GROUPS]);
977 977
978 /* Encode: sector size (5 bits) */ 978 /* Encode: sector size (5 bits) */
979 if ((ret = xd3_encode_bits (stream, & output, & bstate, 979 if ((ret = xd3_encode_bits (stream, & output, & bstate,
@@ -1010,7 +1010,7 @@ xd3_encode_huff (xd3_stream *stream,
1010 djw_weight sum = 0; 1010 djw_weight sum = 0;
1011 djw_weight goal = left / (groups - gp); 1011 djw_weight goal = left / (groups - gp);
1012 1012
1013 IF_DEBUG1 (usize_t nz = 0); 1013 IF_DEBUG2 (usize_t nz = 0);
1014 1014
1015 /* Due to the single-code granularity of this distribution, it may 1015 /* Due to the single-code granularity of this distribution, it may
1016 * be that we can't generate a distribution for each group. In that 1016 * be that we can't generate a distribution for each group. In that
@@ -1018,7 +1018,7 @@ xd3_encode_huff (xd3_stream *stream,
1018 * testing group behavior, so don't mess things up. */ 1018 * testing group behavior, so don't mess things up. */
1019 if (goal == 0 && !cfg->inefficient) 1019 if (goal == 0 && !cfg->inefficient)
1020 { 1020 {
1021 IF_DEBUG1 (DP(RINT "too many groups (%u), dropping one\n", 1021 IF_DEBUG2 (DP(RINT "too many groups (%u), dropping one\n",
1022 groups)); 1022 groups));
1023 groups -= 1; 1023 groups -= 1;
1024 goto regroup; 1024 goto regroup;
@@ -1028,11 +1028,11 @@ xd3_encode_huff (xd3_stream *stream,
1028 while (sum < goal) 1028 while (sum < goal)
1029 { 1029 {
1030 XD3_ASSERT (sym2 < ALPHABET_SIZE); 1030 XD3_ASSERT (sym2 < ALPHABET_SIZE);
1031 IF_DEBUG1 (nz += real_freq[sym2] != 0); 1031 IF_DEBUG2 (nz += real_freq[sym2] != 0);
1032 sum += real_freq[sym2++]; 1032 sum += real_freq[sym2++];
1033 } 1033 }
1034 1034
1035 IF_DEBUG1(DP(RINT "group %u has symbols %u..%u (%u non-zero) " 1035 IF_DEBUG2(DP(RINT "group %u has symbols %u..%u (%u non-zero) "
1036 "(%u/%u = %.3f)\n", 1036 "(%u/%u = %.3f)\n",
1037 gp, sym1, sym2, nz, sum, 1037 gp, sym1, sym2, nz, sum,
1038 input_bytes, sum / (double)input_bytes);); 1038 input_bytes, sum / (double)input_bytes););
@@ -1051,7 +1051,7 @@ xd3_encode_huff (xd3_stream *stream,
1051 niter += 1; 1051 niter += 1;
1052 gbest_no = 0; 1052 gbest_no = 0;
1053 memset (evolve_freq, 0, sizeof (evolve_freq[0]) * groups); 1053 memset (evolve_freq, 0, sizeof (evolve_freq[0]) * groups);
1054 IF_DEBUG1 (memset (gcount, 0, sizeof (gcount[0]) * groups)); 1054 IF_DEBUG2 (memset (gcount, 0, sizeof (gcount[0]) * groups));
1055 1055
1056 /* For each input page (loop is irregular to allow non-pow2-size group 1056 /* For each input page (loop is irregular to allow non-pow2-size group
1057 * size. */ 1057 * size. */
@@ -1103,7 +1103,7 @@ xd3_encode_huff (xd3_stream *stream,
1103 1103
1104 XD3_ASSERT(gbest_no < gbest_max); 1104 XD3_ASSERT(gbest_no < gbest_max);
1105 gbest[gbest_no++] = winner; 1105 gbest[gbest_no++] = winner;
1106 IF_DEBUG1 (gcount[winner] += 1); 1106 IF_DEBUG2 (gcount[winner] += 1);
1107 1107
1108 p = p0; 1108 p = p0;
1109 in = in0; 1109 in = in0;
@@ -1155,19 +1155,19 @@ xd3_encode_huff (xd3_stream *stream,
1155 * for the (output_bits==0) assert after all bits are output. */ 1155 * for the (output_bits==0) assert after all bits are output. */
1156 if (any_zeros) 1156 if (any_zeros)
1157 { 1157 {
1158 IF_DEBUG1 (usize_t save_total = output_bits); 1158 IF_DEBUG2 (usize_t save_total = output_bits);
1159 1159
1160 for (i = 0; i < ALPHABET_SIZE; i += 1) 1160 for (i = 0; i < ALPHABET_SIZE; i += 1)
1161 { 1161 {
1162 if (evolve_zero[i]) { output_bits -= evolve_clen[gp][i]; } 1162 if (evolve_zero[i]) { output_bits -= evolve_clen[gp][i]; }
1163 } 1163 }
1164 1164
1165 IF_DEBUG1 (DP(RINT "evolve_zero reduced %u bits in group %u\n", 1165 IF_DEBUG2 (DP(RINT "evolve_zero reduced %u bits in group %u\n",
1166 save_total - output_bits, gp)); 1166 save_total - output_bits, gp));
1167 } 1167 }
1168 } 1168 }
1169 1169
1170 IF_DEBUG1( 1170 IF_DEBUG2(
1171 DP(RINT "pass %u total bits: %u group uses: ", niter, output_bits); 1171 DP(RINT "pass %u total bits: %u group uses: ", niter, output_bits);
1172 for (gp = 0; gp < groups; gp += 1) { DP(RINT "%u ", gcount[gp]); } 1172 for (gp = 0; gp < groups; gp += 1) { DP(RINT "%u ", gcount[gp]); }
1173 DP(RINT "\n"); 1173 DP(RINT "\n");
@@ -1175,7 +1175,7 @@ xd3_encode_huff (xd3_stream *stream,
1175 1175
1176 /* End iteration. */ 1176 /* End iteration. */
1177 1177
1178 IF_DEBUG1 (if (niter > 1 && best_bits < output_bits) { 1178 IF_DEBUG2 (if (niter > 1 && best_bits < output_bits) {
1179 DP(RINT "iteration lost %u bits\n", output_bits - best_bits); }); 1179 DP(RINT "iteration lost %u bits\n", output_bits - best_bits); });
1180 1180
1181 if (niter == 1 || (niter < DJW_MAX_ITER && 1181 if (niter == 1 || (niter < DJW_MAX_ITER &&
@@ -1191,7 +1191,7 @@ xd3_encode_huff (xd3_stream *stream,
1191 goto nosecond; 1191 goto nosecond;
1192 } 1192 }
1193 1193
1194 IF_DEBUG1 (DP(RINT "djw compression: %u -> %0.3f\n", 1194 IF_DEBUG2 (DP(RINT "djw compression: %u -> %0.3f\n",
1195 input_bytes, output_bits / 8.0)); 1195 input_bytes, output_bits / 8.0));
1196 1196
1197 /* Encode: prefix */ 1197 /* Encode: prefix */
diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h
index 97acd54..7788faa 100644
--- a/xdelta3/xdelta3-test.h
+++ b/xdelta3/xdelta3-test.h
@@ -216,13 +216,13 @@ test_unlink (char* file)
216static void 216static void
217test_cleanup (void) 217test_cleanup (void)
218{ 218{
219 test_unlink (TEST_TARGET_FILE); 219/* test_unlink (TEST_TARGET_FILE); */
220 test_unlink (TEST_SOURCE_FILE); 220/* test_unlink (TEST_SOURCE_FILE); */
221 test_unlink (TEST_DELTA_FILE); 221/* test_unlink (TEST_DELTA_FILE); */
222 test_unlink (TEST_RECON_FILE); 222/* test_unlink (TEST_RECON_FILE); */
223 test_unlink (TEST_RECON2_FILE); 223/* test_unlink (TEST_RECON2_FILE); */
224 test_unlink (TEST_COPY_FILE); 224/* test_unlink (TEST_COPY_FILE); */
225 test_unlink (TEST_NOPERM_FILE); 225/* test_unlink (TEST_NOPERM_FILE); */
226} 226}
227 227
228static int 228static int
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c
index 11cab28..7e1ba07 100644
--- a/xdelta3/xdelta3.c
+++ b/xdelta3/xdelta3.c
@@ -2541,7 +2541,7 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno)
2541 { 2541 {
2542 if (!source->eof_known) 2542 if (!source->eof_known)
2543 { 2543 {
2544 IF_DEBUG1 (DP(RINT "[getblk] eof block has %d bytes; source length known %"Q"u\n", 2544 IF_DEBUG2 (DP(RINT "[getblk] eof block has %d bytes; source length known %"Q"u\n",
2545 xd3_bytes_on_srcblk (source, blkno), 2545 xd3_bytes_on_srcblk (source, blkno),
2546 xd3_source_eof (source))); 2546 xd3_source_eof (source)));
2547 source->eof_known = 1; 2547 source->eof_known = 1;
@@ -2552,7 +2552,7 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno)
2552 } 2552 }
2553 2553
2554 XD3_ASSERT (source->curblk != NULL); 2554 XD3_ASSERT (source->curblk != NULL);
2555 IF_DEBUG1 (DP(RINT "[getblk] read source block %"Q"u onblk %u blksize %u\n", 2555 IF_DEBUG2 (DP(RINT "[getblk] read source block %"Q"u onblk %u blksize %u\n",
2556 blkno, source->onblk, source->blksize)); 2556 blkno, source->onblk, source->blksize));
2557 2557
2558 if (blkno == source->max_blkno) 2558 if (blkno == source->max_blkno)
@@ -2579,7 +2579,7 @@ xd3_set_source (xd3_stream *stream,
2579{ 2579{
2580 usize_t shiftby; 2580 usize_t shiftby;
2581 2581
2582 IF_DEBUG1 (DP(RINT "[set source] %s\n", 2582 IF_DEBUG2 (DP(RINT "[set source] %s\n",
2583 stream->getblk == NULL ? "async" : "sync")); 2583 stream->getblk == NULL ? "async" : "sync"));
2584 2584
2585 stream->src = src; 2585 stream->src = src;
@@ -2608,6 +2608,8 @@ xd3_set_source_and_size (xd3_stream *stream, xd3_source *user_source, xoff_t sou
2608 if (ret == 0) 2608 if (ret == 0)
2609 { 2609 {
2610 stream->src->eof_known = 1; 2610 stream->src->eof_known = 1;
2611 IF_DEBUG2 (DP(RINT "[set source] size known %"Q"u\n",
2612 source_size));
2611 2613
2612 xd3_blksize_div(source_size, 2614 xd3_blksize_div(source_size,
2613 stream->src, 2615 stream->src,