diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2010-11-07 16:48:21 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2010-11-07 16:48:21 +0000 |
commit | 1882c39affc3b224871790bfe06ac71f293e5f2b (patch) | |
tree | 8557cec8a83ca210d5552c304d292acccf8d9e24 | |
parent | 75fe1e3d0b617ca6ef19f145f8df0ca57977eaf6 (diff) |
Whitespace cleanups, comments
-rw-r--r-- | xdelta3/xdelta3-blkcache.h | 6 | ||||
-rw-r--r-- | xdelta3/xdelta3-test.h | 16 | ||||
-rw-r--r-- | xdelta3/xdelta3.c | 24 | ||||
-rw-r--r-- | xdelta3/xdelta3.h | 21 |
4 files changed, 35 insertions, 32 deletions
diff --git a/xdelta3/xdelta3-blkcache.h b/xdelta3/xdelta3-blkcache.h index a570665..cf5fb7f 100644 --- a/xdelta3/xdelta3-blkcache.h +++ b/xdelta3/xdelta3-blkcache.h | |||
@@ -113,10 +113,10 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, | |||
113 | else | 113 | else |
114 | { | 114 | { |
115 | /* Either a regular file (possibly compressed) or a FIFO | 115 | /* Either a regular file (possibly compressed) or a FIFO |
116 | * (possibly compressed). */ | 116 | * (possibly compressed). */ |
117 | if ((ret = main_file_open (sfile, sfile->filename, XO_READ))) | 117 | if ((ret = main_file_open (sfile, sfile->filename, XO_READ))) |
118 | { | 118 | { |
119 | return ret; | 119 | return ret; |
120 | } | 120 | } |
121 | 121 | ||
122 | /* If the file is regular we know it's size. If the file turns | 122 | /* If the file is regular we know it's size. If the file turns |
@@ -135,7 +135,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, | |||
135 | * (lru_size==1) source block. Otherwise, we know that at least | 135 | * (lru_size==1) source block. Otherwise, we know that at least |
136 | * option_srcwinsz bytes are available. Split the source window | 136 | * option_srcwinsz bytes are available. Split the source window |
137 | * into buffers. */ | 137 | * into buffers. */ |
138 | if ((lru = (main_blklru*) main_malloc (MAX_LRU_SIZE * | 138 | if ((lru = (main_blklru*) main_malloc (MAX_LRU_SIZE * |
139 | sizeof (main_blklru))) == NULL) | 139 | sizeof (main_blklru))) == NULL) |
140 | { | 140 | { |
141 | ret = ENOMEM; | 141 | ret = ENOMEM; |
diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h index 68499b1..f74e767 100644 --- a/xdelta3/xdelta3-test.h +++ b/xdelta3/xdelta3-test.h | |||
@@ -282,14 +282,14 @@ test_make_inputs (xd3_stream *stream, xoff_t *ss_out, xoff_t *ts_out) | |||
282 | for (i = 0; i < ts; ) | 282 | for (i = 0; i < ts; ) |
283 | { | 283 | { |
284 | usize_t left = ts - i; | 284 | usize_t left = ts - i; |
285 | usize_t next = mt_exp_rand ((uint32_t) TEST_ADD_MEAN, | 285 | usize_t next = mt_exp_rand ((uint32_t) TEST_ADD_MEAN, |
286 | (uint32_t) TEST_ADD_MAX); | 286 | (uint32_t) TEST_ADD_MAX); |
287 | usize_t add_left = sadd_max - sadd; | 287 | usize_t add_left = sadd_max - sadd; |
288 | double add_prob = (left == 0) ? 0 : (add_left / (double) left); | 288 | double add_prob = (left == 0) ? 0 : (add_left / (double) left); |
289 | int do_copy; | 289 | int do_copy; |
290 | 290 | ||
291 | next = min (left, next); | 291 | next = min (left, next); |
292 | do_copy = (next > add_left || | 292 | do_copy = (next > add_left || |
293 | (mt_random (&static_mtrand) / \ | 293 | (mt_random (&static_mtrand) / \ |
294 | (double)USIZE_T_MAX) >= add_prob); | 294 | (double)USIZE_T_MAX) >= add_prob); |
295 | 295 | ||
@@ -305,8 +305,8 @@ test_make_inputs (xd3_stream *stream, xoff_t *ss_out, xoff_t *ts_out) | |||
305 | if (do_copy) | 305 | if (do_copy) |
306 | { | 306 | { |
307 | /* Copy */ | 307 | /* Copy */ |
308 | size_t offset = mt_random (&static_mtrand) % ((ss_out == NULL) ? | 308 | size_t offset = mt_random (&static_mtrand) % ((ss_out == NULL) ? |
309 | i : | 309 | i : |
310 | (ss - next)); | 310 | (ss - next)); |
311 | /* DP(RINT "[%u] copy %u at %u ", i, next, offset); */ | 311 | /* DP(RINT "[%u] copy %u at %u ", i, next, offset); */ |
312 | 312 | ||
@@ -838,7 +838,7 @@ test_compress_text (xd3_stream *stream, | |||
838 | 838 | ||
839 | (*encoded_size) = 0; | 839 | (*encoded_size) = 0; |
840 | 840 | ||
841 | xd3_set_appheader (stream, test_apphead, | 841 | xd3_set_appheader (stream, test_apphead, |
842 | (usize_t) strlen ((char*) test_apphead)); | 842 | (usize_t) strlen ((char*) test_apphead)); |
843 | 843 | ||
844 | if ((ret = xd3_encode_stream (stream, test_text, sizeof (test_text), | 844 | if ((ret = xd3_encode_stream (stream, test_text, sizeof (test_text), |
@@ -2371,9 +2371,9 @@ test_identical_behavior (xd3_stream *stream, int ignore) | |||
2371 | xd3_config config; | 2371 | xd3_config config; |
2372 | memset(&source, 0, sizeof(source)); | 2372 | memset(&source, 0, sizeof(source)); |
2373 | 2373 | ||
2374 | for (i = 0; i < IDB_TGTSZ; i += 1) | 2374 | for (i = 0; i < IDB_TGTSZ; i += 1) |
2375 | { | 2375 | { |
2376 | buf[i] = (uint8_t) mt_random (&static_mtrand); | 2376 | buf[i] = (uint8_t) mt_random (&static_mtrand); |
2377 | } | 2377 | } |
2378 | 2378 | ||
2379 | stream->winsize = IDB_WINSZ; | 2379 | stream->winsize = IDB_WINSZ; |
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index 23877b1..1bc7fe5 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c | |||
@@ -1263,14 +1263,14 @@ int xd3_compute_code_table_encoding (xd3_stream *in_stream, | |||
1263 | * about 20 bytes. */ | 1263 | * about 20 bytes. */ |
1264 | uint8_t dflt_string[CODE_TABLE_STRING_SIZE]; | 1264 | uint8_t dflt_string[CODE_TABLE_STRING_SIZE]; |
1265 | uint8_t code_string[CODE_TABLE_STRING_SIZE]; | 1265 | uint8_t code_string[CODE_TABLE_STRING_SIZE]; |
1266 | 1266 | ||
1267 | xd3_compute_code_table_string (xd3_rfc3284_code_table (), dflt_string); | 1267 | xd3_compute_code_table_string (xd3_rfc3284_code_table (), dflt_string); |
1268 | xd3_compute_code_table_string (code_table, code_string); | 1268 | xd3_compute_code_table_string (code_table, code_string); |
1269 | 1269 | ||
1270 | return xd3_encode_memory (code_string, CODE_TABLE_STRING_SIZE, | 1270 | return xd3_encode_memory (code_string, CODE_TABLE_STRING_SIZE, |
1271 | dflt_string, CODE_TABLE_STRING_SIZE, | 1271 | dflt_string, CODE_TABLE_STRING_SIZE, |
1272 | comp_string, comp_string_size, | 1272 | comp_string, comp_string_size, |
1273 | CODE_TABLE_VCDIFF_SIZE, | 1273 | CODE_TABLE_VCDIFF_SIZE, |
1274 | /* flags */ 0); | 1274 | /* flags */ 0); |
1275 | } | 1275 | } |
1276 | 1276 | ||
@@ -1362,8 +1362,8 @@ xd3_apply_table_string (xd3_stream *stream, const uint8_t *code_string) | |||
1362 | xd3_dinst *code_table; | 1362 | xd3_dinst *code_table; |
1363 | 1363 | ||
1364 | if ((code_table = stream->code_table_alloc = | 1364 | if ((code_table = stream->code_table_alloc = |
1365 | (xd3_dinst*) xd3_alloc (stream, | 1365 | (xd3_dinst*) xd3_alloc (stream, |
1366 | (usize_t) sizeof (xd3_dinst), | 1366 | (usize_t) sizeof (xd3_dinst), |
1367 | 256)) == NULL) | 1367 | 256)) == NULL) |
1368 | { | 1368 | { |
1369 | return ENOMEM; | 1369 | return ENOMEM; |
@@ -1873,12 +1873,12 @@ xd3_alloc_cache (xd3_stream *stream) | |||
1873 | 1873 | ||
1874 | if (((stream->acache.s_near > 0) && | 1874 | if (((stream->acache.s_near > 0) && |
1875 | (stream->acache.near_array = (usize_t*) | 1875 | (stream->acache.near_array = (usize_t*) |
1876 | xd3_alloc (stream, stream->acache.s_near, | 1876 | xd3_alloc (stream, stream->acache.s_near, |
1877 | (usize_t) sizeof (usize_t))) | 1877 | (usize_t) sizeof (usize_t))) |
1878 | == NULL) || | 1878 | == NULL) || |
1879 | ((stream->acache.s_same > 0) && | 1879 | ((stream->acache.s_same > 0) && |
1880 | (stream->acache.same_array = (usize_t*) | 1880 | (stream->acache.same_array = (usize_t*) |
1881 | xd3_alloc (stream, stream->acache.s_same * 256, | 1881 | xd3_alloc (stream, stream->acache.s_same * 256, |
1882 | (usize_t) sizeof (usize_t))) | 1882 | (usize_t) sizeof (usize_t))) |
1883 | == NULL)) | 1883 | == NULL)) |
1884 | { | 1884 | { |
@@ -2536,7 +2536,7 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno) | |||
2536 | ret = stream->getblk (stream, source, blkno); | 2536 | ret = stream->getblk (stream, source, blkno); |
2537 | if (ret != 0) | 2537 | if (ret != 0) |
2538 | { | 2538 | { |
2539 | IF_DEBUG1 (DP(RINT "[getblk] app error blkno %"Q"u: %s\n", | 2539 | IF_DEBUG1 (DP(RINT "[getblk] app error blkno %"Q"u: %s\n", |
2540 | blkno, xd3_strerror (ret))); | 2540 | blkno, xd3_strerror (ret))); |
2541 | return ret; | 2541 | return ret; |
2542 | } | 2542 | } |
@@ -2623,7 +2623,7 @@ xd3_set_source (xd3_stream *stream, | |||
2623 | } | 2623 | } |
2624 | 2624 | ||
2625 | int | 2625 | int |
2626 | xd3_set_source_and_size (xd3_stream *stream, | 2626 | xd3_set_source_and_size (xd3_stream *stream, |
2627 | xd3_source *user_source, | 2627 | xd3_source *user_source, |
2628 | xoff_t source_size) { | 2628 | xoff_t source_size) { |
2629 | int ret = xd3_set_source (stream, user_source); | 2629 | int ret = xd3_set_source (stream, user_source); |
@@ -2799,7 +2799,7 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst) | |||
2799 | else | 2799 | else |
2800 | { | 2800 | { |
2801 | stream->srcwin_decided_early = (!stream->src->eof_known || | 2801 | stream->srcwin_decided_early = (!stream->src->eof_known || |
2802 | (stream->srcwin_cksum_pos < | 2802 | (stream->srcwin_cksum_pos < |
2803 | xd3_source_eof (stream->src))); | 2803 | xd3_source_eof (stream->src))); |
2804 | } | 2804 | } |
2805 | 2805 | ||
@@ -2807,7 +2807,7 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst) | |||
2807 | if (inst->xtra) | 2807 | if (inst->xtra) |
2808 | { | 2808 | { |
2809 | XD3_ASSERT (inst->addr >= src->srcbase); | 2809 | XD3_ASSERT (inst->addr >= src->srcbase); |
2810 | XD3_ASSERT (inst->addr + inst->size <= | 2810 | XD3_ASSERT (inst->addr + inst->size <= |
2811 | src->srcbase + src->srclen); | 2811 | src->srcbase + src->srclen); |
2812 | addr = (usize_t)(inst->addr - src->srcbase); | 2812 | addr = (usize_t)(inst->addr - src->srcbase); |
2813 | stream->n_scpy += 1; | 2813 | stream->n_scpy += 1; |
@@ -2815,7 +2815,7 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst) | |||
2815 | } | 2815 | } |
2816 | else | 2816 | else |
2817 | { | 2817 | { |
2818 | /* with source window: target copy address is offset | 2818 | /* with source window: target copy address is offset |
2819 | * by taroff. */ | 2819 | * by taroff. */ |
2820 | addr = stream->taroff + (usize_t) inst->addr; | 2820 | addr = stream->taroff + (usize_t) inst->addr; |
2821 | stream->n_tcpy += 1; | 2821 | stream->n_tcpy += 1; |
@@ -3810,7 +3810,7 @@ xd3_encode_input (xd3_stream *stream) | |||
3810 | 3810 | ||
3811 | case ENC_SEARCH: | 3811 | case ENC_SEARCH: |
3812 | IF_DEBUG2 (DP(RINT "[SEARCH] match_state %d avail_in %u %s\n", | 3812 | IF_DEBUG2 (DP(RINT "[SEARCH] match_state %d avail_in %u %s\n", |
3813 | stream->match_state, stream->avail_in, | 3813 | stream->match_state, stream->avail_in, |
3814 | stream->src ? "source" : "no source")); | 3814 | stream->src ? "source" : "no source")); |
3815 | 3815 | ||
3816 | /* Reentrant matching. */ | 3816 | /* Reentrant matching. */ |
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h index c831ac1..5dafd8d 100644 --- a/xdelta3/xdelta3.h +++ b/xdelta3/xdelta3.h | |||
@@ -1044,13 +1044,18 @@ int xd3_decode_memory (const uint8_t *input, | |||
1044 | usize_t avail_output, | 1044 | usize_t avail_output, |
1045 | int flags); | 1045 | int flags); |
1046 | 1046 | ||
1047 | /* This function encodes an in-memory input. The output array must be | 1047 | /* This function encodes an in-memory input using a pre-configured |
1048 | * large enough to hold the output or else ENOSPC is returned. The | 1048 | * xd3_stream. This allows the caller to set a variety of options |
1049 | * source (if any) should be set using xd3_set_source() with a | 1049 | * which are not available in the xd3_encode/decode_memory() |
1050 | * single-block xd3_source. This calls the underlying non-blocking | 1050 | * functions. |
1051 | * interface, xd3_encode_input(), handling the necessary input/output | 1051 | * |
1052 | * states. This method be considered a reference for any application | 1052 | * The output array must be large enough to hold the output or else |
1053 | * using xd3_encode_input() directly. | 1053 | * ENOSPC is returned. The source (if any) should be set using |
1054 | * xd3_set_source_and_size() with a single-block xd3_source. This | ||
1055 | * calls the underlying non-blocking interfaces, | ||
1056 | * xd3_encode/decode_input(), handling the necessary input/output | ||
1057 | * states. This method may be considered a reference for any | ||
1058 | * application using xd3_encode_input() directly. | ||
1054 | * | 1059 | * |
1055 | * xd3_stream stream; | 1060 | * xd3_stream stream; |
1056 | * xd3_config config; | 1061 | * xd3_config config; |
@@ -1079,8 +1084,6 @@ int xd3_decode_memory (const uint8_t *input, | |||
1079 | * xd3_config_stream(&stream, &config); | 1084 | * xd3_config_stream(&stream, &config); |
1080 | * xd3_encode_stream(&stream, ...); | 1085 | * xd3_encode_stream(&stream, ...); |
1081 | * xd3_free_stream(&stream); | 1086 | * xd3_free_stream(&stream); |
1082 | * | ||
1083 | * DO NOT USE except for testing. These methods are allocate bad buffer sizes. | ||
1084 | */ | 1087 | */ |
1085 | int xd3_encode_stream (xd3_stream *stream, | 1088 | int xd3_encode_stream (xd3_stream *stream, |
1086 | const uint8_t *input, | 1089 | const uint8_t *input, |