diff options
Diffstat (limited to 'xdelta3')
-rw-r--r-- | xdelta3/Makefile.am | 2 | ||||
-rw-r--r-- | xdelta3/Makefile.mingw | 7 | ||||
-rw-r--r-- | xdelta3/Makefile.orig | 9 | ||||
-rw-r--r-- | xdelta3/xdelta3-decode.h | 22 | ||||
-rw-r--r-- | xdelta3/xdelta3-main.h | 9 | ||||
-rw-r--r-- | xdelta3/xdelta3-test.h | 45 | ||||
-rw-r--r-- | xdelta3/xdelta3.c | 480 | ||||
-rw-r--r-- | xdelta3/xdelta3.h | 5 | ||||
-rw-r--r-- | xdelta3/xdelta3.i | 1 |
9 files changed, 9 insertions, 571 deletions
diff --git a/xdelta3/Makefile.am b/xdelta3/Makefile.am index dd2f2d5..94fce8a 100644 --- a/xdelta3/Makefile.am +++ b/xdelta3/Makefile.am | |||
@@ -44,7 +44,6 @@ C_WFLAGS = $(WFLAGS) -pedantic -std=c99 | |||
44 | CXX_WFLAGS = $(WFLAGS) | 44 | CXX_WFLAGS = $(WFLAGS) |
45 | 45 | ||
46 | common_CFLAGS = \ | 46 | common_CFLAGS = \ |
47 | -DGENERIC_ENCODE_TABLES=0 \ | ||
48 | -DREGRESSION_TEST=1 \ | 47 | -DREGRESSION_TEST=1 \ |
49 | -DSECONDARY_DJW=1 \ | 48 | -DSECONDARY_DJW=1 \ |
50 | -DSECONDARY_FGK=1 \ | 49 | -DSECONDARY_FGK=1 \ |
@@ -62,7 +61,6 @@ xdelta3_LDADD = -lm | |||
62 | 61 | ||
63 | xdelta3decode_CFLAGS = \ | 62 | xdelta3decode_CFLAGS = \ |
64 | $(C_WFLAGS) \ | 63 | $(C_WFLAGS) \ |
65 | -DGENERIC_ENCODE_TABLES=0 \ | ||
66 | -DREGRESSION_TEST=0 \ | 64 | -DREGRESSION_TEST=0 \ |
67 | -DSECONDARY_DJW=0 \ | 65 | -DSECONDARY_DJW=0 \ |
68 | -DSECONDARY_FGK=0 \ | 66 | -DSECONDARY_FGK=0 \ |
diff --git a/xdelta3/Makefile.mingw b/xdelta3/Makefile.mingw index 1804d97..20ea9be 100644 --- a/xdelta3/Makefile.mingw +++ b/xdelta3/Makefile.mingw | |||
@@ -72,7 +72,6 @@ EXTRA = Makefile COPYING linkxd3lib.c badcopy.c xdelta3.swig \ | |||
72 | SWIG_FLAGS = -DXD3_DEBUG=0 \ | 72 | SWIG_FLAGS = -DXD3_DEBUG=0 \ |
73 | -DEXTERNAL_COMPRESSION=0 \ | 73 | -DEXTERNAL_COMPRESSION=0 \ |
74 | -DXD3_USE_LARGEFILE64=1 \ | 74 | -DXD3_USE_LARGEFILE64=1 \ |
75 | -DGENERIC_ENCODE_TABLES=1 \ | ||
76 | -DSECONDARY_DJW=1 \ | 75 | -DSECONDARY_DJW=1 \ |
77 | -DVCDIFF_TOOLS=1 \ | 76 | -DVCDIFF_TOOLS=1 \ |
78 | -DSWIG_MODULE=1 | 77 | -DSWIG_MODULE=1 |
@@ -105,7 +104,6 @@ wix: xdelta3.wxs xdelta3.wxi readme.txt Release\xdelta3.exe | |||
105 | xdelta3.exe: $(SOURCES) | 104 | xdelta3.exe: $(SOURCES) |
106 | $(CC) $(CFLAGS) -O3 xdelta3.c -lm -o xdelta3.exe \ | 105 | $(CC) $(CFLAGS) -O3 xdelta3.c -lm -o xdelta3.exe \ |
107 | $(XDWINFLAGS) \ | 106 | $(XDWINFLAGS) \ |
108 | -DGENERIC_ENCODE_TABLES=0 \ | ||
109 | -DREGRESSION_TEST=1 \ | 107 | -DREGRESSION_TEST=1 \ |
110 | -DSECONDARY_DJW=1 \ | 108 | -DSECONDARY_DJW=1 \ |
111 | -DSECONDARY_FGK=1 \ | 109 | -DSECONDARY_FGK=1 \ |
@@ -116,7 +114,6 @@ xdelta3.exe: $(SOURCES) | |||
116 | xdelta3-debug.exe: $(SOURCES) | 114 | xdelta3-debug.exe: $(SOURCES) |
117 | $(CC) -g $(CFLAGS) xdelta3.c -lm -o xdelta3-debug.exe \ | 115 | $(CC) -g $(CFLAGS) xdelta3.c -lm -o xdelta3-debug.exe \ |
118 | $(XDWINFLAGS) \ | 116 | $(XDWINFLAGS) \ |
119 | -DGENERIC_ENCODE_TABLES=1 \ | ||
120 | -DREGRESSION_TEST=1 \ | 117 | -DREGRESSION_TEST=1 \ |
121 | -DSECONDARY_DJW=1 \ | 118 | -DSECONDARY_DJW=1 \ |
122 | -DSECONDARY_FGK=1 \ | 119 | -DSECONDARY_FGK=1 \ |
@@ -141,7 +138,6 @@ xdelta3-debug2.exe: $(SOURCES) | |||
141 | -DXD3_DEBUG=2 \ | 138 | -DXD3_DEBUG=2 \ |
142 | -DXD3_MAIN=1 \ | 139 | -DXD3_MAIN=1 \ |
143 | -DXD3_USE_LARGEFILE64=1 \ | 140 | -DXD3_USE_LARGEFILE64=1 \ |
144 | -DGENERIC_ENCODE_TABLES=1 \ | ||
145 | -DREGRESSION_TEST=1 \ | 141 | -DREGRESSION_TEST=1 \ |
146 | -DSECONDARY_DJW=1 \ | 142 | -DSECONDARY_DJW=1 \ |
147 | -DSECONDARY_FGK=1 \ | 143 | -DSECONDARY_FGK=1 \ |
@@ -151,7 +147,6 @@ xdelta3-debug3.exe: $(SOURCES) | |||
151 | $(CC) -g $(CFLAGS) xdelta3.c -o xdelta3-debug3.exe \ | 147 | $(CC) -g $(CFLAGS) xdelta3.c -o xdelta3-debug3.exe \ |
152 | $(XDWINFLAGS) \ | 148 | $(XDWINFLAGS) \ |
153 | -DXD3_MAIN=1 \ | 149 | -DXD3_MAIN=1 \ |
154 | -DGENERIC_ENCODE_TABLES=1 \ | ||
155 | -DXD3_USE_LARGEFILE64=1 \ | 150 | -DXD3_USE_LARGEFILE64=1 \ |
156 | -DREGRESSION_TEST=1 \ | 151 | -DREGRESSION_TEST=1 \ |
157 | -DXD3_DEBUG=3 \ | 152 | -DXD3_DEBUG=3 \ |
@@ -221,8 +216,6 @@ xdelta3-everything.exe: $(SOURCES) | |||
221 | -DREGRESSION_TEST=1 \ | 216 | -DREGRESSION_TEST=1 \ |
222 | -DSECONDARY_FGK=1 \ | 217 | -DSECONDARY_FGK=1 \ |
223 | -DSECONDARY_DJW=1 \ | 218 | -DSECONDARY_DJW=1 \ |
224 | -DGENERIC_ENCODE_TABLES=1 \ | ||
225 | -DGENERIC_ENCODE_TABLES_COMPUTE=1 \ | ||
226 | -DXD3_DEBUG=1 \ | 219 | -DXD3_DEBUG=1 \ |
227 | -lm | 220 | -lm |
228 | 221 | ||
diff --git a/xdelta3/Makefile.orig b/xdelta3/Makefile.orig index 7fa34ed..33b0ea4 100644 --- a/xdelta3/Makefile.orig +++ b/xdelta3/Makefile.orig | |||
@@ -79,7 +79,6 @@ EXTRA = Makefile COPYING linkxd3lib.c badcopy.c xdelta3.swig \ | |||
79 | SWIG_FLAGS = -DXD3_DEBUG=1 \ | 79 | SWIG_FLAGS = -DXD3_DEBUG=1 \ |
80 | -DEXTERNAL_COMPRESSION=0 \ | 80 | -DEXTERNAL_COMPRESSION=0 \ |
81 | -DXD3_USE_LARGEFILE64=1 \ | 81 | -DXD3_USE_LARGEFILE64=1 \ |
82 | -DGENERIC_ENCODE_TABLES=1 \ | ||
83 | -DSECONDARY_DJW=1 \ | 82 | -DSECONDARY_DJW=1 \ |
84 | -DVCDIFF_TOOLS=1 \ | 83 | -DVCDIFF_TOOLS=1 \ |
85 | -DSWIG_MODULE=1 | 84 | -DSWIG_MODULE=1 |
@@ -128,7 +127,6 @@ wix: xdelta3.wxs xdelta3.wxi readme.txt Release\xdelta3.exe | |||
128 | 127 | ||
129 | xdelta3: $(SOURCES) | 128 | xdelta3: $(SOURCES) |
130 | $(CC) $(CFLAGS) -O3 xdelta3.c -lm -o xdelta3 \ | 129 | $(CC) $(CFLAGS) -O3 xdelta3.c -lm -o xdelta3 \ |
131 | -DGENERIC_ENCODE_TABLES=0 \ | ||
132 | -DREGRESSION_TEST=1 \ | 130 | -DREGRESSION_TEST=1 \ |
133 | -DSECONDARY_DJW=1 \ | 131 | -DSECONDARY_DJW=1 \ |
134 | -DSECONDARY_FGK=1 \ | 132 | -DSECONDARY_FGK=1 \ |
@@ -140,7 +138,6 @@ xdelta3: $(SOURCES) | |||
140 | xdelta3-debug32: $(SOURCES) | 138 | xdelta3-debug32: $(SOURCES) |
141 | $(CC) -g $(CFLAGS) xdelta3.c -lm -o xdelta3-debug32 \ | 139 | $(CC) -g $(CFLAGS) xdelta3.c -lm -o xdelta3-debug32 \ |
142 | -arch i386 \ | 140 | -arch i386 \ |
143 | -DGENERIC_ENCODE_TABLES=1 \ | ||
144 | -DREGRESSION_TEST=1 \ | 141 | -DREGRESSION_TEST=1 \ |
145 | -DSECONDARY_DJW=1 \ | 142 | -DSECONDARY_DJW=1 \ |
146 | -DSECONDARY_FGK=1 \ | 143 | -DSECONDARY_FGK=1 \ |
@@ -152,7 +149,6 @@ xdelta3-debug32: $(SOURCES) | |||
152 | xdelta3-debug64: $(SOURCES) | 149 | xdelta3-debug64: $(SOURCES) |
153 | $(CC) -g $(CFLAGS) xdelta3.c -lm -o xdelta3-debug64 \ | 150 | $(CC) -g $(CFLAGS) xdelta3.c -lm -o xdelta3-debug64 \ |
154 | -arch x86_64 \ | 151 | -arch x86_64 \ |
155 | -DGENERIC_ENCODE_TABLES=1 \ | ||
156 | -DREGRESSION_TEST=1 \ | 152 | -DREGRESSION_TEST=1 \ |
157 | -DSECONDARY_DJW=1 \ | 153 | -DSECONDARY_DJW=1 \ |
158 | -DSECONDARY_FGK=1 \ | 154 | -DSECONDARY_FGK=1 \ |
@@ -163,7 +159,6 @@ xdelta3-debug64: $(SOURCES) | |||
163 | 159 | ||
164 | xdelta3-warnings: $(SOURCES) | 160 | xdelta3-warnings: $(SOURCES) |
165 | $(CC) -g $(CFLAGS) $(WFLAGS) xdelta3.c -lm -o xdelta3-warnings \ | 161 | $(CC) -g $(CFLAGS) $(WFLAGS) xdelta3.c -lm -o xdelta3-warnings \ |
166 | -DGENERIC_ENCODE_TABLES=1 \ | ||
167 | -DREGRESSION_TEST=1 \ | 162 | -DREGRESSION_TEST=1 \ |
168 | -DSECONDARY_DJW=1 \ | 163 | -DSECONDARY_DJW=1 \ |
169 | -DSECONDARY_FGK=1 \ | 164 | -DSECONDARY_FGK=1 \ |
@@ -189,7 +184,6 @@ xdelta3-debug2: $(SOURCES) | |||
189 | -DXD3_MAIN=1 \ | 184 | -DXD3_MAIN=1 \ |
190 | -DXD3_POSIX=1 \ | 185 | -DXD3_POSIX=1 \ |
191 | -DXD3_USE_LARGEFILE64=1 \ | 186 | -DXD3_USE_LARGEFILE64=1 \ |
192 | -DGENERIC_ENCODE_TABLES=1 \ | ||
193 | -DREGRESSION_TEST=1 \ | 187 | -DREGRESSION_TEST=1 \ |
194 | -DSECONDARY_DJW=1 \ | 188 | -DSECONDARY_DJW=1 \ |
195 | -DSECONDARY_FGK=1 \ | 189 | -DSECONDARY_FGK=1 \ |
@@ -198,7 +192,6 @@ xdelta3-debug2: $(SOURCES) | |||
198 | xdelta3-debugstdio: $(SOURCES) | 192 | xdelta3-debugstdio: $(SOURCES) |
199 | $(CC) -g $(CFLAGS) xdelta3.c -o xdelta3-debugstdio \ | 193 | $(CC) -g $(CFLAGS) xdelta3.c -o xdelta3-debugstdio \ |
200 | -DXD3_MAIN=1 \ | 194 | -DXD3_MAIN=1 \ |
201 | -DGENERIC_ENCODE_TABLES=1 \ | ||
202 | -DXD3_USE_LARGEFILE64=1 \ | 195 | -DXD3_USE_LARGEFILE64=1 \ |
203 | -DXD3_STDIO=1 \ | 196 | -DXD3_STDIO=1 \ |
204 | -DREGRESSION_TEST=1 \ | 197 | -DREGRESSION_TEST=1 \ |
@@ -304,8 +297,6 @@ xdelta3-everything: $(SOURCES) | |||
304 | -DREGRESSION_TEST=1 \ | 297 | -DREGRESSION_TEST=1 \ |
305 | -DSECONDARY_FGK=1 \ | 298 | -DSECONDARY_FGK=1 \ |
306 | -DSECONDARY_DJW=1 \ | 299 | -DSECONDARY_DJW=1 \ |
307 | -DGENERIC_ENCODE_TABLES=1 \ | ||
308 | -DGENERIC_ENCODE_TABLES_COMPUTE=1 \ | ||
309 | -DXD3_POSIX=1 \ | 300 | -DXD3_POSIX=1 \ |
310 | -DEXTERNAL_COMPRESSION=1 \ | 301 | -DEXTERNAL_COMPRESSION=1 \ |
311 | -DXD3_DEBUG=1 \ | 302 | -DXD3_DEBUG=1 \ |
diff --git a/xdelta3/xdelta3-decode.h b/xdelta3/xdelta3-decode.h index c0cb578..b0051aa 100644 --- a/xdelta3/xdelta3-decode.h +++ b/xdelta3/xdelta3-decode.h | |||
@@ -841,27 +841,7 @@ xd3_decode_input (xd3_stream *stream) | |||
841 | 841 | ||
842 | if ((stream->dec_hdr_ind & VCD_CODETABLE) != 0) | 842 | if ((stream->dec_hdr_ind & VCD_CODETABLE) != 0) |
843 | { | 843 | { |
844 | /* Get the code table data. */ | 844 | return XD3_UNIMPLEMENTED; |
845 | if ((stream->dec_codetbl == NULL) && | ||
846 | (stream->dec_codetbl = | ||
847 | (uint8_t*) xd3_alloc (stream, | ||
848 | stream->dec_codetblsz, 1)) == NULL) | ||
849 | { | ||
850 | return ENOMEM; | ||
851 | } | ||
852 | |||
853 | if ((ret = xd3_decode_bytes (stream, stream->dec_codetbl, | ||
854 | & stream->dec_codetblbytes, | ||
855 | stream->dec_codetblsz))) | ||
856 | { | ||
857 | return ret; | ||
858 | } | ||
859 | |||
860 | if ((ret = xd3_apply_table_encoding (stream, stream->dec_codetbl, | ||
861 | stream->dec_codetblbytes))) | ||
862 | { | ||
863 | return ret; | ||
864 | } | ||
865 | } | 845 | } |
866 | else | 846 | else |
867 | { | 847 | { |
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h index ccf062c..018a697 100644 --- a/xdelta3/xdelta3-main.h +++ b/xdelta3/xdelta3-main.h | |||
@@ -241,7 +241,6 @@ static uint8_t* option_appheader = NULL; | |||
241 | static int option_use_secondary = 0; | 241 | static int option_use_secondary = 0; |
242 | static const char* option_secondary = NULL; | 242 | static const char* option_secondary = NULL; |
243 | static int option_use_checksum = 1; | 243 | static int option_use_checksum = 1; |
244 | static int option_use_altcodetable = 0; | ||
245 | static const char* option_smatch_config = NULL; | 244 | static const char* option_smatch_config = NULL; |
246 | static int option_no_compress = 0; | 245 | static int option_no_compress = 0; |
247 | static int option_no_output = 0; /* do not write output */ | 246 | static int option_no_output = 0; /* do not write output */ |
@@ -371,8 +370,6 @@ main_config (void) | |||
371 | main_version (); | 370 | main_version (); |
372 | 371 | ||
373 | XPR(NTR "EXTERNAL_COMPRESSION=%d\n", EXTERNAL_COMPRESSION); | 372 | XPR(NTR "EXTERNAL_COMPRESSION=%d\n", EXTERNAL_COMPRESSION); |
374 | XPR(NTR "GENERIC_ENCODE_TABLES=%d\n", GENERIC_ENCODE_TABLES); | ||
375 | XPR(NTR "GENERIC_ENCODE_TABLES_COMPUTE=%d\n", GENERIC_ENCODE_TABLES_COMPUTE); | ||
376 | XPR(NTR "REGRESSION_TEST=%d\n", REGRESSION_TEST); | 373 | XPR(NTR "REGRESSION_TEST=%d\n", REGRESSION_TEST); |
377 | XPR(NTR "SECONDARY_DJW=%d\n", SECONDARY_DJW); | 374 | XPR(NTR "SECONDARY_DJW=%d\n", SECONDARY_DJW); |
378 | XPR(NTR "SECONDARY_FGK=%d\n", SECONDARY_FGK); | 375 | XPR(NTR "SECONDARY_FGK=%d\n", SECONDARY_FGK); |
@@ -413,7 +410,6 @@ reset_defaults(void) | |||
413 | option_appheader = NULL; | 410 | option_appheader = NULL; |
414 | option_use_secondary = 0; | 411 | option_use_secondary = 0; |
415 | option_secondary = NULL; | 412 | option_secondary = NULL; |
416 | option_use_altcodetable = 0; | ||
417 | option_smatch_config = NULL; | 413 | option_smatch_config = NULL; |
418 | option_no_compress = 0; | 414 | option_no_compress = 0; |
419 | option_no_output = 0; | 415 | option_no_output = 0; |
@@ -3041,7 +3037,6 @@ main_input (xd3_cmd cmd, | |||
3041 | output_func = main_write_output; | 3037 | output_func = main_write_output; |
3042 | 3038 | ||
3043 | if (option_no_compress) { stream_flags |= XD3_NOCOMPRESS; } | 3039 | if (option_no_compress) { stream_flags |= XD3_NOCOMPRESS; } |
3044 | if (option_use_altcodetable) { stream_flags |= XD3_ALT_CODE_TABLE; } | ||
3045 | if (option_smatch_config) | 3040 | if (option_smatch_config) |
3046 | { | 3041 | { |
3047 | const char *s = option_smatch_config; | 3042 | const char *s = option_smatch_config; |
@@ -3558,7 +3553,7 @@ int main (int argc, char **argv) | |||
3558 | #endif | 3553 | #endif |
3559 | { | 3554 | { |
3560 | static const char *flags = | 3555 | static const char *flags = |
3561 | "0123456789cdefhnqvDFJNORTVs:m:B:C:E:I:L:O:M:P:W:A::S::"; | 3556 | "0123456789cdefhnqvDFJNORVs:m:B:C:E:I:L:O:M:P:W:A::S::"; |
3562 | xd3_cmd cmd; | 3557 | xd3_cmd cmd; |
3563 | main_file ifile; | 3558 | main_file ifile; |
3564 | main_file ofile; | 3559 | main_file ofile; |
@@ -3758,7 +3753,6 @@ int main (int argc, char **argv) | |||
3758 | 3753 | ||
3759 | case 'n': option_use_checksum = 0; break; | 3754 | case 'n': option_use_checksum = 0; break; |
3760 | case 'N': option_no_compress = 1; break; | 3755 | case 'N': option_no_compress = 1; break; |
3761 | case 'T': option_use_altcodetable = 1; break; | ||
3762 | case 'C': option_smatch_config = my_optarg; break; | 3756 | case 'C': option_smatch_config = my_optarg; break; |
3763 | case 'J': option_no_output = 1; break; | 3757 | case 'J': option_no_output = 1; break; |
3764 | case 'S': if (my_optarg == NULL) | 3758 | case 'S': if (my_optarg == NULL) |
@@ -4038,7 +4032,6 @@ main_help (void) | |||
4038 | XPR(NTR " -C soft config (encode, undocumented)\n"); | 4032 | XPR(NTR " -C soft config (encode, undocumented)\n"); |
4039 | XPR(NTR " -A [apphead] disable/provide application header (encode)\n"); | 4033 | XPR(NTR " -A [apphead] disable/provide application header (encode)\n"); |
4040 | XPR(NTR " -J disable output (check/compute only)\n"); | 4034 | XPR(NTR " -J disable output (check/compute only)\n"); |
4041 | XPR(NTR " -T use alternate code table (test)\n"); | ||
4042 | XPR(NTR " -m arguments for \"merge\"\n"); | 4035 | XPR(NTR " -m arguments for \"merge\"\n"); |
4043 | 4036 | ||
4044 | XPR(NTR "the XDELTA environment variable may contain extra args:\n"); | 4037 | XPR(NTR "the XDELTA environment variable may contain extra args:\n"); |
diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h index 0e10251..948a1d6 100644 --- a/xdelta3/xdelta3-test.h +++ b/xdelta3/xdelta3-test.h | |||
@@ -1550,42 +1550,6 @@ test_choose_instruction (xd3_stream *stream, int ignore) | |||
1550 | } | 1550 | } |
1551 | 1551 | ||
1552 | /*********************************************************************** | 1552 | /*********************************************************************** |
1553 | TEST INSTRUCTION TABLE CODING | ||
1554 | ***********************************************************************/ | ||
1555 | |||
1556 | #if GENERIC_ENCODE_TABLES | ||
1557 | /* Test that encoding and decoding a code table works */ | ||
1558 | static int | ||
1559 | test_encode_code_table (xd3_stream *stream, int ignore) | ||
1560 | { | ||
1561 | int ret; | ||
1562 | const uint8_t *comp_data; | ||
1563 | usize_t comp_size; | ||
1564 | |||
1565 | if ((ret = xd3_compute_alternate_table_encoding (stream, & comp_data, & comp_size))) | ||
1566 | { | ||
1567 | return ret; | ||
1568 | } | ||
1569 | |||
1570 | stream->acache.s_near = __alternate_code_table_desc.near_modes; | ||
1571 | stream->acache.s_same = __alternate_code_table_desc.same_modes; | ||
1572 | |||
1573 | if ((ret = xd3_apply_table_encoding (stream, comp_data, comp_size))) | ||
1574 | { | ||
1575 | return ret; | ||
1576 | } | ||
1577 | |||
1578 | if (memcmp (stream->code_table, xd3_alternate_code_table (), sizeof (xd3_dinst) * 256) != 0) | ||
1579 | { | ||
1580 | stream->msg = "wrong code table reconstruction"; | ||
1581 | return XD3_INTERNAL; | ||
1582 | } | ||
1583 | |||
1584 | return 0; | ||
1585 | } | ||
1586 | #endif | ||
1587 | |||
1588 | /*********************************************************************** | ||
1589 | 64BIT STREAMING | 1553 | 64BIT STREAMING |
1590 | ***********************************************************************/ | 1554 | ***********************************************************************/ |
1591 | 1555 | ||
@@ -2897,16 +2861,12 @@ xd3_selftest (void) | |||
2897 | DO_TEST (forward_match, 0, 0); | 2861 | DO_TEST (forward_match, 0, 0); |
2898 | 2862 | ||
2899 | DO_TEST (address_cache, 0, 0); | 2863 | DO_TEST (address_cache, 0, 0); |
2900 | IF_GENCODETBL (DO_TEST (address_cache, XD3_ALT_CODE_TABLE, 0)); | ||
2901 | 2864 | ||
2902 | DO_TEST (string_matching, 0, 0); | 2865 | DO_TEST (string_matching, 0, 0); |
2903 | DO_TEST (choose_instruction, 0, 0); | 2866 | DO_TEST (choose_instruction, 0, 0); |
2904 | DO_TEST (identical_behavior, 0, 0); | 2867 | DO_TEST (identical_behavior, 0, 0); |
2905 | DO_TEST (in_memory, 0, 0); | 2868 | DO_TEST (in_memory, 0, 0); |
2906 | 2869 | ||
2907 | IF_GENCODETBL (DO_TEST (choose_instruction, XD3_ALT_CODE_TABLE, 0)); | ||
2908 | IF_GENCODETBL (DO_TEST (encode_code_table, 0, 0)); | ||
2909 | |||
2910 | DO_TEST (iopt_flush_instructions, 0, 0); | 2870 | DO_TEST (iopt_flush_instructions, 0, 0); |
2911 | DO_TEST (source_cksum_offset, 0, 0); | 2871 | DO_TEST (source_cksum_offset, 0, 0); |
2912 | 2872 | ||
@@ -2917,11 +2877,6 @@ xd3_selftest (void) | |||
2917 | IF_FGK (DO_TEST (decompress_single_bit_error, XD3_SEC_FGK, 3)); | 2877 | IF_FGK (DO_TEST (decompress_single_bit_error, XD3_SEC_FGK, 3)); |
2918 | IF_DJW (DO_TEST (decompress_single_bit_error, XD3_SEC_DJW, 8)); | 2878 | IF_DJW (DO_TEST (decompress_single_bit_error, XD3_SEC_DJW, 8)); |
2919 | 2879 | ||
2920 | /* There are many expected non-failures for ALT_CODE_TABLE because | ||
2921 | * not all of the instruction codes are used. */ | ||
2922 | IF_GENCODETBL ( | ||
2923 | DO_TEST (decompress_single_bit_error, XD3_ALT_CODE_TABLE, 224)); | ||
2924 | |||
2925 | #if SHELL_TESTS | 2880 | #if SHELL_TESTS |
2926 | DO_TEST (force_behavior, 0, 0); | 2881 | DO_TEST (force_behavior, 0, 0); |
2927 | DO_TEST (stdout_behavior, 0, 0); | 2882 | DO_TEST (stdout_behavior, 0, 0); |
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index 78a331e..8513aac 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c | |||
@@ -294,16 +294,6 @@ | |||
294 | #endif | 294 | #endif |
295 | #endif | 295 | #endif |
296 | 296 | ||
297 | #ifndef GENERIC_ENCODE_TABLES /* These three are the RFC-spec app-specific */ | ||
298 | #define GENERIC_ENCODE_TABLES 0 /* code features. This is tested but not */ | ||
299 | #endif /* recommended unless there's a real use. */ | ||
300 | #ifndef GENERIC_ENCODE_TABLES_COMPUTE | ||
301 | #define GENERIC_ENCODE_TABLES_COMPUTE 0 | ||
302 | #endif | ||
303 | #ifndef GENERIC_ENCODE_TABLES_COMPUTE_PRINT | ||
304 | #define GENERIC_ENCODE_TABLES_COMPUTE_PRINT 0 | ||
305 | #endif | ||
306 | |||
307 | #if XD3_ENCODER | 297 | #if XD3_ENCODER |
308 | #define IF_ENCODER(x) x | 298 | #define IF_ENCODER(x) x |
309 | #else | 299 | #else |
@@ -559,8 +549,6 @@ static void xd3_verify_small_state (xd3_stream *stream, | |||
559 | static int xd3_decode_allocate (xd3_stream *stream, usize_t size, | 549 | static int xd3_decode_allocate (xd3_stream *stream, usize_t size, |
560 | uint8_t **copied1, usize_t *alloc1); | 550 | uint8_t **copied1, usize_t *alloc1); |
561 | 551 | ||
562 | static void xd3_compute_code_table_string (const xd3_dinst *code_table, | ||
563 | uint8_t *str); | ||
564 | static void* xd3_alloc (xd3_stream *stream, usize_t elts, usize_t size); | 552 | static void* xd3_alloc (xd3_stream *stream, usize_t elts, usize_t size); |
565 | static void xd3_free (xd3_stream *stream, void *ptr); | 553 | static void xd3_free (xd3_stream *stream, void *ptr); |
566 | 554 | ||
@@ -881,14 +869,10 @@ const uint16_t __single_hash[256] = | |||
881 | 869 | ||
882 | /* The XD3_CHOOSE_INSTRUCTION calls xd3_choose_instruction with the | 870 | /* The XD3_CHOOSE_INSTRUCTION calls xd3_choose_instruction with the |
883 | * table description when GENERIC_ENCODE_TABLES are in use. The | 871 | * table description when GENERIC_ENCODE_TABLES are in use. The |
884 | * IF_GENCODETBL macro enables generic-code-table specific code. */ | 872 | * IF_GENCODETBL macro enables generic-code-table specific code |
885 | #if GENERIC_ENCODE_TABLES | 873 | * (removed 10/2014). */ |
886 | #define XD3_CHOOSE_INSTRUCTION(stream,prev,inst) xd3_choose_instruction (stream->code_table_desc, prev, inst) | 874 | #define XD3_CHOOSE_INSTRUCTION(stream,prev,inst) \ |
887 | #define IF_GENCODETBL(x) x | 875 | xd3_choose_instruction (prev, inst) |
888 | #else | ||
889 | #define XD3_CHOOSE_INSTRUCTION(stream,prev,inst) xd3_choose_instruction (prev, inst) | ||
890 | #define IF_GENCODETBL(x) | ||
891 | #endif | ||
892 | 876 | ||
893 | /* This structure maintains information needed by | 877 | /* This structure maintains information needed by |
894 | * xd3_choose_instruction to compute the code for a double instruction | 878 | * xd3_choose_instruction to compute the code for a double instruction |
@@ -950,50 +934,6 @@ static const xd3_code_table_desc __rfc3284_code_table_desc = { | |||
950 | { {4,247,1},{4,248,1},{4,249,1},{4,250,1},{4,251,1},{4,252,1},{4,253,1},{4,254,1},{4,255,1} }, | 934 | { {4,247,1},{4,248,1},{4,249,1},{4,250,1},{4,251,1},{4,252,1},{4,253,1},{4,254,1},{4,255,1} }, |
951 | }; | 935 | }; |
952 | 936 | ||
953 | #if GENERIC_ENCODE_TABLES | ||
954 | /* An alternate code table for testing (5 near, 0 same): | ||
955 | * | ||
956 | * TYPE SIZE MODE TYPE SIZE MODE INDEX | ||
957 | * --------------------------------------------------------------- | ||
958 | * 1. Run 0 0 Noop 0 0 0 | ||
959 | * 2. Add 0, [1,23] 0 Noop 0 0 [1,24] | ||
960 | * 3. Copy 0, [4,20] 0 Noop 0 0 [25,42] | ||
961 | * 4. Copy 0, [4,20] 1 Noop 0 0 [43,60] | ||
962 | * 5. Copy 0, [4,20] 2 Noop 0 0 [61,78] | ||
963 | * 6. Copy 0, [4,20] 3 Noop 0 0 [79,96] | ||
964 | * 7. Copy 0, [4,20] 4 Noop 0 0 [97,114] | ||
965 | * 8. Copy 0, [4,20] 5 Noop 0 0 [115,132] | ||
966 | * 9. Copy 0, [4,20] 6 Noop 0 0 [133,150] | ||
967 | * 10. Add [1,4] 0 Copy [4,6] 0 [151,162] | ||
968 | * 11. Add [1,4] 0 Copy [4,6] 1 [163,174] | ||
969 | * 12. Add [1,4] 0 Copy [4,6] 2 [175,186] | ||
970 | * 13. Add [1,4] 0 Copy [4,6] 3 [187,198] | ||
971 | * 14. Add [1,4] 0 Copy [4,6] 4 [199,210] | ||
972 | * 15. Add [1,4] 0 Copy [4,6] 5 [211,222] | ||
973 | * 16. Add [1,4] 0 Copy [4,6] 6 [223,234] | ||
974 | * 17. Copy 4 [0,6] Add [1,3] 0 [235,255] | ||
975 | * --------------------------------------------------------------- */ | ||
976 | static const xd3_code_table_desc __alternate_code_table_desc = { | ||
977 | 23, /* add sizes */ | ||
978 | 5, /* near modes */ | ||
979 | 0, /* same modes */ | ||
980 | 17, /* copy sizes */ | ||
981 | |||
982 | 4, /* add-copy max add */ | ||
983 | 6, /* add-copy max cpy, near */ | ||
984 | 0, /* add-copy max cpy, same */ | ||
985 | |||
986 | 3, /* copy-add max add */ | ||
987 | 4, /* copy-add max cpy, near */ | ||
988 | 0, /* copy-add max cpy, same */ | ||
989 | |||
990 | /* addcopy */ | ||
991 | { {6,151,3},{6,163,3},{6,175,3},{6,187,3},{6,199,3},{6,211,3},{6,223,3},{0,0,0},{0,0,0} }, | ||
992 | /* copyadd */ | ||
993 | { {4,235,1},{4,238,1},{4,241,1},{4,244,1},{4,247,1},{4,250,1},{4,253,1},{0,0,0},{0,0,0} }, | ||
994 | }; | ||
995 | #endif | ||
996 | |||
997 | /* Computes code table entries of TBL using the specified description. */ | 937 | /* Computes code table entries of TBL using the specified description. */ |
998 | static void | 938 | static void |
999 | xd3_build_code_table (const xd3_code_table_desc *desc, xd3_dinst *tbl) | 939 | xd3_build_code_table (const xd3_code_table_desc *desc, xd3_dinst *tbl) |
@@ -1076,117 +1016,6 @@ xd3_rfc3284_code_table (void) | |||
1076 | } | 1016 | } |
1077 | 1017 | ||
1078 | #if XD3_ENCODER | 1018 | #if XD3_ENCODER |
1079 | #if GENERIC_ENCODE_TABLES | ||
1080 | /* This function generates the alternate code table. */ | ||
1081 | static const xd3_dinst* | ||
1082 | xd3_alternate_code_table (void) | ||
1083 | { | ||
1084 | static xd3_dinst __alternate_code_table[256]; | ||
1085 | |||
1086 | if (__alternate_code_table[0].type1 != XD3_RUN) | ||
1087 | { | ||
1088 | xd3_build_code_table (& __alternate_code_table_desc, __alternate_code_table); | ||
1089 | } | ||
1090 | |||
1091 | return __alternate_code_table; | ||
1092 | } | ||
1093 | |||
1094 | /* This function computes the ideal second instruction INST based on | ||
1095 | * preceding instruction PREV. If it is possible to issue a double | ||
1096 | * instruction based on this pair it sets PREV->code2, otherwise it | ||
1097 | * sets INST->code1. */ | ||
1098 | static void | ||
1099 | xd3_choose_instruction (const xd3_code_table_desc *desc, xd3_rinst *prev, xd3_rinst *inst) | ||
1100 | { | ||
1101 | switch (inst->type) | ||
1102 | { | ||
1103 | case XD3_RUN: | ||
1104 | /* The 0th instruction is RUN */ | ||
1105 | inst->code1 = 0; | ||
1106 | break; | ||
1107 | |||
1108 | case XD3_ADD: | ||
1109 | |||
1110 | if (inst->size > desc->add_sizes) | ||
1111 | { | ||
1112 | /* The first instruction is non-immediate ADD */ | ||
1113 | inst->code1 = 1; | ||
1114 | } | ||
1115 | else | ||
1116 | { | ||
1117 | /* The following ADD_SIZES instructions are immediate ADDs */ | ||
1118 | inst->code1 = 1 + inst->size; | ||
1119 | |||
1120 | /* Now check for a possible COPY-ADD double instruction */ | ||
1121 | if (prev != NULL) | ||
1122 | { | ||
1123 | int prev_mode = prev->type - XD3_CPY; | ||
1124 | |||
1125 | /* If previous is a copy. Note: as long as the previous | ||
1126 | * is not a RUN instruction, it should be a copy because | ||
1127 | * it cannot be an add. This check is more clear. */ | ||
1128 | if (prev_mode >= 0 && inst->size <= desc->copyadd_add_max) | ||
1129 | { | ||
1130 | const xd3_code_table_sizes *sizes = | ||
1131 | & desc->copyadd_max_sizes[prev_mode]; | ||
1132 | |||
1133 | /* This check and the inst->size-<= above are == in | ||
1134 | the default table. */ | ||
1135 | if (prev->size <= sizes->cpy_max) | ||
1136 | { | ||
1137 | /* The second and third exprs are 0 in the | ||
1138 | default table. */ | ||
1139 | prev->code2 = sizes->offset + | ||
1140 | (sizes->mult * (prev->size - MIN_MATCH)) + | ||
1141 | (inst->size - MIN_ADD); | ||
1142 | } | ||
1143 | } | ||
1144 | } | ||
1145 | } | ||
1146 | break; | ||
1147 | |||
1148 | default: | ||
1149 | { | ||
1150 | int mode = inst->type - XD3_CPY; | ||
1151 | |||
1152 | /* The large copy instruction is offset by the run, large add, | ||
1153 | * and immediate adds, then multipled by the number of | ||
1154 | * immediate copies plus one (the large copy) (i.e., if there | ||
1155 | * are 15 immediate copy instructions then there are 16 copy | ||
1156 | * instructions per mode). */ | ||
1157 | inst->code1 = 2 + desc->add_sizes + (1 + desc->cpy_sizes) * mode; | ||
1158 | |||
1159 | /* Now if the copy is short enough for an immediate instruction. */ | ||
1160 | if (inst->size < MIN_MATCH + desc->cpy_sizes && | ||
1161 | /* TODO: there needs to be a more comprehensive test for this | ||
1162 | * boundary condition, merge is now exercising code in which | ||
1163 | * size < MIN_MATCH is possible and it's unclear if the above | ||
1164 | * size < (MIN_MATCH + cpy_sizes) should be a <= from inspection | ||
1165 | * of the default table version below. */ | ||
1166 | inst->size >= MIN_MATCH) | ||
1167 | { | ||
1168 | inst->code1 += inst->size + 1 - MIN_MATCH; | ||
1169 | |||
1170 | /* Now check for a possible ADD-COPY double instruction. */ | ||
1171 | if ( (prev != NULL) && | ||
1172 | (prev->type == XD3_ADD) && | ||
1173 | (prev->size <= desc->addcopy_add_max) ) | ||
1174 | { | ||
1175 | const xd3_code_table_sizes *sizes = & desc->addcopy_max_sizes[mode]; | ||
1176 | |||
1177 | if (inst->size <= sizes->cpy_max) | ||
1178 | { | ||
1179 | prev->code2 = sizes->offset + | ||
1180 | (sizes->mult * (prev->size - MIN_ADD)) + | ||
1181 | (inst->size - MIN_MATCH); | ||
1182 | } | ||
1183 | } | ||
1184 | } | ||
1185 | } | ||
1186 | } | ||
1187 | } | ||
1188 | #else /* GENERIC_ENCODE_TABLES */ | ||
1189 | |||
1190 | /* This version of xd3_choose_instruction is hard-coded for the default | 1019 | /* This version of xd3_choose_instruction is hard-coded for the default |
1191 | table. */ | 1020 | table. */ |
1192 | static void | 1021 | static void |
@@ -1254,262 +1083,8 @@ xd3_choose_instruction (xd3_rinst *prev, xd3_rinst *inst) | |||
1254 | break; | 1083 | break; |
1255 | } | 1084 | } |
1256 | } | 1085 | } |
1257 | #endif /* GENERIC_ENCODE_TABLES */ | ||
1258 | |||
1259 | /*********************************************************************** | ||
1260 | Instruction table encoder/decoder | ||
1261 | ***********************************************************************/ | ||
1262 | |||
1263 | #if GENERIC_ENCODE_TABLES | ||
1264 | #if GENERIC_ENCODE_TABLES_COMPUTE == 0 | ||
1265 | |||
1266 | /* In this case, we hard-code the result of | ||
1267 | * compute_code_table_encoding for each alternate code table, | ||
1268 | * presuming that saves time/space. This has been 131 bytes, but | ||
1269 | * secondary compression was turned off. */ | ||
1270 | static const uint8_t __alternate_code_table_compressed[178] = | ||
1271 | {0xd6,0xc3,0xc4,0x00,0x00,0x01,0x8a,0x6f,0x40,0x81,0x27,0x8c,0x00,0x00,0x4a,0x4a,0x0d,0x02,0x01,0x03, | ||
1272 | 0x01,0x03,0x00,0x01,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e, | ||
1273 | 0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x00,0x01,0x01,0x01,0x02,0x02,0x02,0x03,0x03,0x03,0x04, | ||
1274 | 0x04,0x04,0x04,0x00,0x04,0x05,0x06,0x01,0x02,0x03,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x05,0x05,0x05, | ||
1275 | 0x06,0x06,0x06,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x00,0x02,0x00,0x18,0x13,0x63,0x00,0x1b,0x00,0x54, | ||
1276 | 0x00,0x15,0x23,0x6f,0x00,0x28,0x13,0x54,0x00,0x15,0x01,0x1a,0x31,0x23,0x6c,0x0d,0x23,0x48,0x00,0x15, | ||
1277 | 0x93,0x6f,0x00,0x28,0x04,0x23,0x51,0x04,0x32,0x00,0x2b,0x00,0x12,0x00,0x12,0x00,0x12,0x00,0x12,0x00, | ||
1278 | 0x12,0x00,0x12,0x53,0x57,0x9c,0x07,0x43,0x6f,0x00,0x34,0x00,0x0c,0x00,0x0c,0x00,0x0c,0x00,0x0c,0x00, | ||
1279 | 0x0c,0x00,0x0c,0x00,0x15,0x00,0x82,0x6f,0x00,0x15,0x12,0x0c,0x00,0x03,0x03,0x00,0x06,0x00,}; | ||
1280 | |||
1281 | static int | ||
1282 | xd3_compute_alternate_table_encoding (xd3_stream *stream, const uint8_t **data, usize_t *size) | ||
1283 | { | ||
1284 | (*data) = __alternate_code_table_compressed; | ||
1285 | (*size) = sizeof (__alternate_code_table_compressed); | ||
1286 | return 0; | ||
1287 | } | ||
1288 | |||
1289 | #else | ||
1290 | |||
1291 | /* The alternate code table will be computed and stored here. */ | ||
1292 | static uint8_t __alternate_code_table_compressed[CODE_TABLE_VCDIFF_SIZE]; | ||
1293 | static usize_t __alternate_code_table_compressed_size; | ||
1294 | |||
1295 | /* This function generates a delta describing the code table for | ||
1296 | * encoding within a VCDIFF file. This function is NOT thread safe | ||
1297 | * because it is only intended that this function is used to generate | ||
1298 | * statically-compiled strings. "comp_string" must be sized | ||
1299 | * CODE_TABLE_VCDIFF_SIZE. */ | ||
1300 | int xd3_compute_code_table_encoding (xd3_stream *in_stream, | ||
1301 | const xd3_dinst *code_table, | ||
1302 | uint8_t *comp_string, | ||
1303 | usize_t *comp_string_size) | ||
1304 | { | ||
1305 | /* Use DJW secondary compression if it is on by default. This saves | ||
1306 | * about 20 bytes. */ | ||
1307 | uint8_t dflt_string[CODE_TABLE_STRING_SIZE]; | ||
1308 | uint8_t code_string[CODE_TABLE_STRING_SIZE]; | ||
1309 | |||
1310 | xd3_compute_code_table_string (xd3_rfc3284_code_table (), dflt_string); | ||
1311 | xd3_compute_code_table_string (code_table, code_string); | ||
1312 | |||
1313 | return xd3_encode_memory (code_string, CODE_TABLE_STRING_SIZE, | ||
1314 | dflt_string, CODE_TABLE_STRING_SIZE, | ||
1315 | comp_string, comp_string_size, | ||
1316 | CODE_TABLE_VCDIFF_SIZE, | ||
1317 | /* flags */ 0); | ||
1318 | } | ||
1319 | |||
1320 | /* Compute a delta between alternate and rfc3284 tables. As soon as | ||
1321 | * another alternate table is added, this code should become generic. | ||
1322 | * For now there is only one alternate table for testing. */ | ||
1323 | static int | ||
1324 | xd3_compute_alternate_table_encoding (xd3_stream *stream, const uint8_t **data, usize_t *size) | ||
1325 | { | ||
1326 | int ret; | ||
1327 | |||
1328 | if (__alternate_code_table_compressed[0] == 0) | ||
1329 | { | ||
1330 | if ((ret = xd3_compute_code_table_encoding (stream, xd3_alternate_code_table (), | ||
1331 | __alternate_code_table_compressed, | ||
1332 | & __alternate_code_table_compressed_size))) | ||
1333 | { | ||
1334 | return ret; | ||
1335 | } | ||
1336 | |||
1337 | /* During development of a new code table, enable this variable to print | ||
1338 | * the new static contents and determine its size. At run time the | ||
1339 | * table will be filled in appropriately, but at least it should have | ||
1340 | * the proper size beforehand. */ | ||
1341 | #if GENERIC_ENCODE_TABLES_COMPUTE_PRINT | ||
1342 | { | ||
1343 | int i; | ||
1344 | |||
1345 | DP(RINT, "\nstatic const usize_t __alternate_code_table_compressed_size = %u;\n", | ||
1346 | __alternate_code_table_compressed_size); | ||
1347 | |||
1348 | DP(RINT, "static const uint8_t __alternate_code_table_compressed[%u] =\n{", | ||
1349 | __alternate_code_table_compressed_size); | ||
1350 | |||
1351 | for (i = 0; i < __alternate_code_table_compressed_size; i += 1) | ||
1352 | { | ||
1353 | DP(RINT, "0x%02x,", __alternate_code_table_compressed[i]); | ||
1354 | if ((i % 20) == 19) { DP(RINT, "\n"); } | ||
1355 | } | ||
1356 | |||
1357 | DP(RINT, "};\n"); | ||
1358 | } | ||
1359 | #endif | ||
1360 | } | ||
1361 | |||
1362 | (*data) = __alternate_code_table_compressed; | ||
1363 | (*size) = __alternate_code_table_compressed_size; | ||
1364 | |||
1365 | return 0; | ||
1366 | } | ||
1367 | #endif /* GENERIC_ENCODE_TABLES_COMPUTE != 0 */ | ||
1368 | #endif /* GENERIC_ENCODE_TABLES */ | ||
1369 | |||
1370 | #endif /* XD3_ENCODER */ | 1086 | #endif /* XD3_ENCODER */ |
1371 | 1087 | ||
1372 | /* This function generates the 1536-byte string specified in sections 5.4 and | ||
1373 | * 7 of rfc3284, which is used to represent a code table within a VCDIFF | ||
1374 | * file. */ | ||
1375 | void xd3_compute_code_table_string (const xd3_dinst *code_table, uint8_t *str) | ||
1376 | { | ||
1377 | int i, s; | ||
1378 | |||
1379 | XD3_ASSERT (CODE_TABLE_STRING_SIZE == 6 * 256); | ||
1380 | |||
1381 | for (s = 0; s < 6; s += 1) | ||
1382 | { | ||
1383 | for (i = 0; i < 256; i += 1) | ||
1384 | { | ||
1385 | switch (s) | ||
1386 | { | ||
1387 | case 0: *str++ = (code_table[i].type1 >= XD3_CPY ? XD3_CPY : code_table[i].type1); break; | ||
1388 | case 1: *str++ = (code_table[i].type2 >= XD3_CPY ? XD3_CPY : code_table[i].type2); break; | ||
1389 | case 2: *str++ = (code_table[i].size1); break; | ||
1390 | case 3: *str++ = (code_table[i].size2); break; | ||
1391 | case 4: *str++ = (code_table[i].type1 >= XD3_CPY ? code_table[i].type1 - XD3_CPY : 0); break; | ||
1392 | case 5: *str++ = (code_table[i].type2 >= XD3_CPY ? code_table[i].type2 - XD3_CPY : 0); break; | ||
1393 | } | ||
1394 | } | ||
1395 | } | ||
1396 | } | ||
1397 | |||
1398 | /* This function translates the code table string into the internal representation. The | ||
1399 | * stream's near and same-modes should already be set. */ | ||
1400 | static int | ||
1401 | xd3_apply_table_string (xd3_stream *stream, const uint8_t *code_string) | ||
1402 | { | ||
1403 | int i, s; | ||
1404 | int modes = TOTAL_MODES (stream); | ||
1405 | xd3_dinst *code_table; | ||
1406 | |||
1407 | if ((code_table = stream->code_table_alloc = | ||
1408 | (xd3_dinst*) xd3_alloc (stream, | ||
1409 | (usize_t) sizeof (xd3_dinst), | ||
1410 | 256)) == NULL) | ||
1411 | { | ||
1412 | return ENOMEM; | ||
1413 | } | ||
1414 | |||
1415 | for (s = 0; s < 6; s += 1) | ||
1416 | { | ||
1417 | for (i = 0; i < 256; i += 1) | ||
1418 | { | ||
1419 | switch (s) | ||
1420 | { | ||
1421 | case 0: | ||
1422 | if (*code_string > XD3_CPY) | ||
1423 | { | ||
1424 | stream->msg = "invalid code-table opcode"; | ||
1425 | return XD3_INTERNAL; | ||
1426 | } | ||
1427 | code_table[i].type1 = *code_string++; | ||
1428 | break; | ||
1429 | case 1: | ||
1430 | if (*code_string > XD3_CPY) | ||
1431 | { | ||
1432 | stream->msg = "invalid code-table opcode"; | ||
1433 | return XD3_INTERNAL; | ||
1434 | } | ||
1435 | code_table[i].type2 = *code_string++; | ||
1436 | break; | ||
1437 | case 2: | ||
1438 | if (*code_string != 0 && code_table[i].type1 == XD3_NOOP) | ||
1439 | { | ||
1440 | stream->msg = "invalid code-table size"; | ||
1441 | return XD3_INTERNAL; | ||
1442 | } | ||
1443 | code_table[i].size1 = *code_string++; | ||
1444 | break; | ||
1445 | case 3: | ||
1446 | if (*code_string != 0 && code_table[i].type2 == XD3_NOOP) | ||
1447 | { | ||
1448 | stream->msg = "invalid code-table size"; | ||
1449 | return XD3_INTERNAL; | ||
1450 | } | ||
1451 | code_table[i].size2 = *code_string++; | ||
1452 | break; | ||
1453 | case 4: | ||
1454 | if (*code_string >= modes) | ||
1455 | { | ||
1456 | stream->msg = "invalid code-table mode"; | ||
1457 | return XD3_INTERNAL; | ||
1458 | } | ||
1459 | if (*code_string != 0 && code_table[i].type1 != XD3_CPY) | ||
1460 | { | ||
1461 | stream->msg = "invalid code-table mode"; | ||
1462 | return XD3_INTERNAL; | ||
1463 | } | ||
1464 | code_table[i].type1 += *code_string++; | ||
1465 | break; | ||
1466 | case 5: | ||
1467 | if (*code_string >= modes) | ||
1468 | { | ||
1469 | stream->msg = "invalid code-table mode"; | ||
1470 | return XD3_INTERNAL; | ||
1471 | } | ||
1472 | if (*code_string != 0 && code_table[i].type2 != XD3_CPY) | ||
1473 | { | ||
1474 | stream->msg = "invalid code-table mode"; | ||
1475 | return XD3_INTERNAL; | ||
1476 | } | ||
1477 | code_table[i].type2 += *code_string++; | ||
1478 | break; | ||
1479 | } | ||
1480 | } | ||
1481 | } | ||
1482 | |||
1483 | stream->code_table = code_table; | ||
1484 | return 0; | ||
1485 | } | ||
1486 | |||
1487 | /* This function applies a code table delta and returns an actual code table. */ | ||
1488 | static int | ||
1489 | xd3_apply_table_encoding (xd3_stream *in_stream, const uint8_t *data, usize_t size) | ||
1490 | { | ||
1491 | uint8_t dflt_string[CODE_TABLE_STRING_SIZE]; | ||
1492 | uint8_t code_string[CODE_TABLE_STRING_SIZE]; | ||
1493 | usize_t code_size; | ||
1494 | int ret; | ||
1495 | |||
1496 | xd3_compute_code_table_string (xd3_rfc3284_code_table (), dflt_string); | ||
1497 | |||
1498 | if ((ret = xd3_decode_memory (data, size, | ||
1499 | dflt_string, CODE_TABLE_STRING_SIZE, | ||
1500 | code_string, &code_size, | ||
1501 | CODE_TABLE_STRING_SIZE, | ||
1502 | 0))) { return ret; } | ||
1503 | |||
1504 | if (code_size != sizeof (code_string)) | ||
1505 | { | ||
1506 | in_stream->msg = "corrupt code-table encoding"; | ||
1507 | return XD3_INTERNAL; | ||
1508 | } | ||
1509 | |||
1510 | return xd3_apply_table_string (in_stream, code_string); | ||
1511 | } | ||
1512 | |||
1513 | /***********************************************************************/ | 1088 | /***********************************************************************/ |
1514 | 1089 | ||
1515 | static inline void | 1090 | static inline void |
@@ -2438,23 +2013,8 @@ xd3_config_stream(xd3_stream *stream, | |||
2438 | return XD3_INTERNAL; | 2013 | return XD3_INTERNAL; |
2439 | } | 2014 | } |
2440 | 2015 | ||
2441 | /* Check/set encoder code table. */ | 2016 | stream->code_table_desc = & __rfc3284_code_table_desc; |
2442 | switch (stream->flags & XD3_ALT_CODE_TABLE) { | 2017 | stream->code_table_func = xd3_rfc3284_code_table; |
2443 | case 0: | ||
2444 | stream->code_table_desc = & __rfc3284_code_table_desc; | ||
2445 | stream->code_table_func = xd3_rfc3284_code_table; | ||
2446 | break; | ||
2447 | #if GENERIC_ENCODE_TABLES | ||
2448 | case XD3_ALT_CODE_TABLE: | ||
2449 | stream->code_table_desc = & __alternate_code_table_desc; | ||
2450 | stream->code_table_func = xd3_alternate_code_table; | ||
2451 | stream->comp_table_func = xd3_compute_alternate_table_encoding; | ||
2452 | break; | ||
2453 | #endif | ||
2454 | default: | ||
2455 | stream->msg = "alternate code table support was not compiled"; | ||
2456 | return XD3_INTERNAL; | ||
2457 | } | ||
2458 | 2018 | ||
2459 | /* Check sprevsz */ | 2019 | /* Check sprevsz */ |
2460 | if (smatcher->small_chain == 1 && | 2020 | if (smatcher->small_chain == 1 && |
@@ -3420,11 +2980,8 @@ xd3_emit_hdr (xd3_stream *stream) | |||
3420 | { | 2980 | { |
3421 | usize_t hdr_ind = 0; | 2981 | usize_t hdr_ind = 0; |
3422 | int use_appheader = stream->enc_appheader != NULL; | 2982 | int use_appheader = stream->enc_appheader != NULL; |
3423 | int use_gencodetbl = GENERIC_ENCODE_TABLES && | ||
3424 | (stream->code_table_desc != & __rfc3284_code_table_desc); | ||
3425 | 2983 | ||
3426 | if (use_secondary) { hdr_ind |= VCD_SECONDARY; } | 2984 | if (use_secondary) { hdr_ind |= VCD_SECONDARY; } |
3427 | if (use_gencodetbl) { hdr_ind |= VCD_CODETABLE; } | ||
3428 | if (use_appheader) { hdr_ind |= VCD_APPHEADER; } | 2985 | if (use_appheader) { hdr_ind |= VCD_APPHEADER; } |
3429 | 2986 | ||
3430 | if ((ret = xd3_emit_byte (stream, & HDR_TAIL (stream), | 2987 | if ((ret = xd3_emit_byte (stream, & HDR_TAIL (stream), |
@@ -3450,31 +3007,6 @@ xd3_emit_hdr (xd3_stream *stream) | |||
3450 | } | 3007 | } |
3451 | #endif | 3008 | #endif |
3452 | 3009 | ||
3453 | /* Compressed code table */ | ||
3454 | if (use_gencodetbl) | ||
3455 | { | ||
3456 | usize_t code_table_size; | ||
3457 | const uint8_t *code_table_data; | ||
3458 | |||
3459 | if ((ret = stream->comp_table_func (stream, & code_table_data, | ||
3460 | & code_table_size))) | ||
3461 | { | ||
3462 | return ret; | ||
3463 | } | ||
3464 | |||
3465 | if ((ret = xd3_emit_size (stream, & HDR_TAIL (stream), | ||
3466 | code_table_size + 2)) || | ||
3467 | (ret = xd3_emit_byte (stream, & HDR_TAIL (stream), | ||
3468 | stream->code_table_desc->near_modes)) || | ||
3469 | (ret = xd3_emit_byte (stream, & HDR_TAIL (stream), | ||
3470 | stream->code_table_desc->same_modes)) || | ||
3471 | (ret = xd3_emit_bytes (stream, & HDR_TAIL (stream), | ||
3472 | code_table_data, code_table_size))) | ||
3473 | { | ||
3474 | return ret; | ||
3475 | } | ||
3476 | } | ||
3477 | |||
3478 | /* Application header */ | 3010 | /* Application header */ |
3479 | if (use_appheader) | 3011 | if (use_appheader) |
3480 | { | 3012 | { |
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h index d6471fa..69204c5 100644 --- a/xdelta3/xdelta3.h +++ b/xdelta3/xdelta3.h | |||
@@ -349,7 +349,7 @@ typedef enum { | |||
349 | XD3_INVALID_INPUT = -17712, /* invalid input/decoder error */ | 349 | XD3_INVALID_INPUT = -17712, /* invalid input/decoder error */ |
350 | XD3_NOSECOND = -17713, /* when secondary compression finds no | 350 | XD3_NOSECOND = -17713, /* when secondary compression finds no |
351 | improvement. */ | 351 | improvement. */ |
352 | XD3_UNIMPLEMENTED = -17714 /* currently VCD_TARGET */ | 352 | XD3_UNIMPLEMENTED = -17714 /* currently VCD_TARGET, VCD_CODETABLE */ |
353 | } xd3_rvalues; | 353 | } xd3_rvalues; |
354 | 354 | ||
355 | /* special values in config->flags */ | 355 | /* special values in config->flags */ |
@@ -385,9 +385,6 @@ typedef enum | |||
385 | XD3_ADLER32_NOVER = (1 << 11), /* disable checksum verification in | 385 | XD3_ADLER32_NOVER = (1 << 11), /* disable checksum verification in |
386 | the decoder. */ | 386 | the decoder. */ |
387 | 387 | ||
388 | XD3_ALT_CODE_TABLE = (1 << 12), /* for testing th | ||
389 | e alternate code table encoding. */ | ||
390 | |||
391 | XD3_NOCOMPRESS = (1 << 13), /* disable ordinary data | 388 | XD3_NOCOMPRESS = (1 << 13), /* disable ordinary data |
392 | * compression feature, only search | 389 | * compression feature, only search |
393 | * the source, not the target. */ | 390 | * the source, not the target. */ |
diff --git a/xdelta3/xdelta3.i b/xdelta3/xdelta3.i index 32a5d4e..2fea015 100644 --- a/xdelta3/xdelta3.i +++ b/xdelta3/xdelta3.i | |||
@@ -74,7 +74,6 @@ enum { | |||
74 | /*XD3_SEC_OTHER,*/ | 74 | /*XD3_SEC_OTHER,*/ |
75 | XD3_ADLER32, | 75 | XD3_ADLER32, |
76 | XD3_ADLER32_NOVER, | 76 | XD3_ADLER32_NOVER, |
77 | XD3_ALT_CODE_TABLE, | ||
78 | XD3_NOCOMPRESS, | 77 | XD3_NOCOMPRESS, |
79 | XD3_BEGREEDY, | 78 | XD3_BEGREEDY, |
80 | XD3_COMPLEVEL_SHIFT, | 79 | XD3_COMPLEVEL_SHIFT, |