summaryrefslogtreecommitdiff
path: root/xdelta3
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3')
-rw-r--r--xdelta3/xdelta3-main.h51
-rw-r--r--xdelta3/xdelta3.c16
2 files changed, 35 insertions, 32 deletions
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index 6882e03..0babbf1 100644
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -2761,6 +2761,8 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd,
2761 main_blklru_list_init (& lru_list); 2761 main_blklru_list_init (& lru_list);
2762 main_blklru_list_init (& lru_free); 2762 main_blklru_list_init (& lru_free);
2763 2763
2764 IF_DEBUG1 (DP(RINT "[main_set_source] %s\n", sfile->filename));
2765
2764 /* Open it, check for seekability, set required xd3_source fields. */ 2766 /* Open it, check for seekability, set required xd3_source fields. */
2765 if (allow_fake_source) 2767 if (allow_fake_source)
2766 { 2768 {
@@ -2795,9 +2797,9 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd,
2795 seekable = 0; 2797 seekable = 0;
2796 source_size_known = 0; 2798 source_size_known = 0;
2797 2799
2798 if (option_verbose) 2800 if (option_verbose > 1)
2799 { 2801 {
2800 XPR(NT "source not seekable\n"); 2802 XPR(NT "source not seekable: %s\n", xd3_mainerror (stat_val));
2801 } 2803 }
2802 } 2804 }
2803 } 2805 }
@@ -2827,6 +2829,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd,
2827 XPR(NT XD3_LIB_ERRMSG (stream, ret)); 2829 XPR(NT XD3_LIB_ERRMSG (stream, ret));
2828 goto error; 2830 goto error;
2829 } 2831 }
2832 XD3_ASSERT (stream->src == source);
2830 2833
2831 lru_size = (option_srcwinsz + source->blksize - 1) / source->blksize; 2834 lru_size = (option_srcwinsz + source->blksize - 1) / source->blksize;
2832 option_srcwinsz = lru_size * source->blksize; 2835 option_srcwinsz = lru_size * source->blksize;
@@ -2835,7 +2838,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd,
2835 { 2838 {
2836 static char buf[32]; 2839 static char buf[32];
2837 2840
2838 XPR(NT "source %s winsize %s\n", 2841 XPR(NT "source %s: winsize %s\n",
2839 sfile->filename, main_format_bcnt(option_srcwinsz, buf)); 2842 sfile->filename, main_format_bcnt(option_srcwinsz, buf));
2840 } 2843 }
2841 2844
@@ -2864,7 +2867,10 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd,
2864 main_blklru_list_push_back (& lru_free, & lru[i]); 2867 main_blklru_list_push_back (& lru_free, & lru[i]);
2865 } 2868 }
2866 2869
2870 return 0;
2871
2867 error: 2872 error:
2873 IF_DEBUG1 (DP(RINT "[main_set_source] error %s\n", xd3_strerror (ret)));
2868 if (tmp_buf != NULL) 2874 if (tmp_buf != NULL)
2869 { 2875 {
2870 main_free (tmp_buf); 2876 main_free (tmp_buf);
@@ -3224,17 +3230,6 @@ main_input (xd3_cmd cmd,
3224 return EXIT_FAILURE; 3230 return EXIT_FAILURE;
3225 } 3231 }
3226 3232
3227 if (IS_ENCODE (cmd))
3228 {
3229 /* When encoding, open the source file, possibly decompress it.
3230 * The decoder delays this step until XD3_GOTHEADER. */
3231 if (sfile->filename != NULL &&
3232 (ret = main_set_source (& stream, cmd, sfile, & source)))
3233 {
3234 return EXIT_FAILURE;
3235 }
3236 }
3237
3238 config.winsize = winsize; 3233 config.winsize = winsize;
3239 config.srcwin_maxsz = option_srcwinsz; 3234 config.srcwin_maxsz = option_srcwinsz;
3240 config.getblk = main_getblk_func; 3235 config.getblk = main_getblk_func;
@@ -3256,6 +3251,21 @@ main_input (xd3_cmd cmd,
3256 } 3251 }
3257#endif 3252#endif
3258 3253
3254 if (cmd != CMD_DECODE)
3255 {
3256 /* When not decoding, set source now. The decoder delays this
3257 * step until XD3_GOTHEADER. */
3258 if (sfile->filename != NULL)
3259 {
3260 if ((ret = main_set_source (& stream, cmd, sfile, & source)))
3261 {
3262 return EXIT_FAILURE;
3263 }
3264
3265 XD3_ASSERT(stream.src != NULL);
3266 }
3267 }
3268
3259 /* This times each window. */ 3269 /* This times each window. */
3260 get_millisecs_since (); 3270 get_millisecs_since ();
3261 3271
@@ -3329,18 +3339,6 @@ main_input (xd3_cmd cmd,
3329 return EXIT_FAILURE; 3339 return EXIT_FAILURE;
3330 } 3340 }
3331 } 3341 }
3332 else if (cmd == CMD_PRINTHDR ||
3333 cmd == CMD_PRINTHDRS ||
3334 cmd == CMD_PRINTDELTA ||
3335 cmd == CMD_RECODE)
3336 {
3337 if (sfile->filename == NULL)
3338 {
3339 allow_fake_source = 1;
3340 sfile->filename = "<placeholder>";
3341 main_set_source (& stream, cmd, sfile, & source);
3342 }
3343 }
3344 } 3342 }
3345 /* FALLTHROUGH */ 3343 /* FALLTHROUGH */
3346 case XD3_WINSTART: 3344 case XD3_WINSTART:
@@ -3397,6 +3395,7 @@ main_input (xd3_cmd cmd,
3397 "no source copies\n", 3395 "no source copies\n",
3398 stream.current_window * winsize, 3396 stream.current_window * winsize,
3399 (stream.current_window+1) * winsize); 3397 (stream.current_window+1) * winsize);
3398 XD3_ASSERT (stream.src != NULL);
3400 } 3399 }
3401 3400
3402 /* Limited i-buffer size affects source copies */ 3401 /* Limited i-buffer size affects source copies */
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c
index 1ca1e32..515b083 100644
--- a/xdelta3/xdelta3.c
+++ b/xdelta3/xdelta3.c
@@ -2516,7 +2516,7 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno)
2516 } 2516 }
2517 2517
2518 ret = stream->getblk (stream, source, blkno); 2518 ret = stream->getblk (stream, source, blkno);
2519 2519 IF_DEBUG1 (DP(RINT "[getblk] func ret %d\n", ret));
2520 if (ret != 0) 2520 if (ret != 0)
2521 { 2521 {
2522 stream->msg = "getblk failed"; 2522 stream->msg = "getblk failed";
@@ -2579,9 +2579,6 @@ xd3_set_source (xd3_stream *stream,
2579{ 2579{
2580 usize_t shiftby; 2580 usize_t shiftby;
2581 2581
2582 IF_DEBUG2 (DP(RINT "[set source] %s\n",
2583 stream->getblk == NULL ? "async" : "sync"));
2584
2585 stream->src = src; 2582 stream->src = src;
2586 src->srclen = 0; 2583 src->srclen = 0;
2587 src->srcbase = 0; 2584 src->srcbase = 0;
@@ -3776,6 +3773,8 @@ xd3_encode_input (xd3_stream *stream)
3776 return XD3_WINSTART; 3773 return XD3_WINSTART;
3777 3774
3778 case ENC_SEARCH: 3775 case ENC_SEARCH:
3776 IF_DEBUG1 (DP(RINT "[SEARCH] match_state %d avail_in %u %s\n",
3777 stream->match_state, stream->avail_in, stream->src ? "source" : "no source"));
3779 3778
3780 /* Reentrant matching. */ 3779 /* Reentrant matching. */
3781 if (stream->src != NULL) 3780 if (stream->src != NULL)
@@ -3793,7 +3792,7 @@ xd3_encode_input (xd3_stream *stream)
3793 if (stream->avail_in > 0) 3792 if (stream->avail_in > 0)
3794 { 3793 {
3795 /* This call can't fail because the source window is 3794 /* This call can't fail because the source window is
3796 unrestricted. */ 3795 * unrestricted. */
3797 ret = xd3_source_match_setup (stream, stream->match_srcpos); 3796 ret = xd3_source_match_setup (stream, stream->match_srcpos);
3798 XD3_ASSERT (ret == 0); 3797 XD3_ASSERT (ret == 0);
3799 stream->match_state = MATCH_FORWARD; 3798 stream->match_state = MATCH_FORWARD;
@@ -4336,6 +4335,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos)
4336 * TestNonBlockingProgress test! */ 4335 * TestNonBlockingProgress test! */
4337 if (srcpos != 0 && srcpos == stream->match_last_srcpos) 4336 if (srcpos != 0 && srcpos == stream->match_last_srcpos)
4338 { 4337 {
4338 IF_DEBUG1(DP(RINT "[match_setup] looping failure\n"));
4339 goto bad; 4339 goto bad;
4340 } 4340 }
4341 4341
@@ -4402,6 +4402,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos)
4402 /* Restricted case: fail if the srcpos lies outside the source window */ 4402 /* Restricted case: fail if the srcpos lies outside the source window */
4403 if ((srcpos < src->srcbase) || (srcpos > (src->srcbase + (xoff_t) src->srclen))) 4403 if ((srcpos < src->srcbase) || (srcpos > (src->srcbase + (xoff_t) src->srclen)))
4404 { 4404 {
4405 IF_DEBUG1(DP(RINT "[match_setup] restricted source window failure\n"));
4405 goto bad; 4406 goto bad;
4406 } 4407 }
4407 else 4408 else
@@ -4513,6 +4514,9 @@ xd3_source_extend_match (xd3_stream *stream)
4513 usize_t tryrem; /* tryrem is the number of matchable bytes */ 4514 usize_t tryrem; /* tryrem is the number of matchable bytes */
4514 usize_t matched; 4515 usize_t matched;
4515 4516
4517 IF_DEBUG1(DP(RINT "[extend match] srcpos %"Q"u\n",
4518 stream->match_srcpos));
4519
4516 XD3_ASSERT (src != NULL); 4520 XD3_ASSERT (src != NULL);
4517 4521
4518 /* Does it make sense to compute backward match AFTER forward match? */ 4522 /* Does it make sense to compute backward match AFTER forward match? */
@@ -5302,7 +5306,7 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream)
5302 /* Maybe output a COPY instruction */ 5306 /* Maybe output a COPY instruction */
5303 if (match_length >= stream->min_match) 5307 if (match_length >= stream->min_match)
5304 { 5308 {
5305 IF_DEBUG1 ({ 5309 IF_DEBUG2 ({
5306 static int x = 0; 5310 static int x = 0;
5307 DP(RINT "[target match:%d] <inp %u %u> <cpy %u %u> " 5311 DP(RINT "[target match:%d] <inp %u %u> <cpy %u %u> "
5308 "(-%d) [ %u bytes ]\n", 5312 "(-%d) [ %u bytes ]\n",