diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2007-09-29 16:13:11 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2007-09-29 16:13:11 +0000 |
commit | c5ea64c0c216b1882b2a7b5c409b4c6ec0279abc (patch) | |
tree | e7cc8b30275763c253b78af8319e6b1326ab921e | |
parent | b36dd4d10d1176591e037863bc68809f75685fb6 (diff) |
Adds a test that triggers the assertion failure in djw_build_prefix,
a few cleanups, but does not fix the problem (next CL).
-rw-r--r-- | xdelta3/Makefile | 12 | ||||
-rw-r--r-- | xdelta3/xdelta3-decode.h | 1 | ||||
-rw-r--r-- | xdelta3/xdelta3-djw.h | 293 | ||||
-rwxr-xr-x | xdelta3/xdelta3-regtest.py | 2 | ||||
-rw-r--r-- | xdelta3/xdelta3-test.h | 33 | ||||
-rw-r--r-- | xdelta3/xdelta3.c | 2 |
6 files changed, 44 insertions, 299 deletions
diff --git a/xdelta3/Makefile b/xdelta3/Makefile index c8479c3..a3f0658 100644 --- a/xdelta3/Makefile +++ b/xdelta3/Makefile | |||
@@ -138,14 +138,14 @@ xdelta3.o: $(SOURCES) | |||
138 | xdelta3_wrap.o: xdelta3_wrap.c | 138 | xdelta3_wrap.o: xdelta3_wrap.c |
139 | $(CC) $(SWIG_FLAGS) \ | 139 | $(CC) $(SWIG_FLAGS) \ |
140 | -DHAVE_CONFIG_H \ | 140 | -DHAVE_CONFIG_H \ |
141 | -I/usr/include/python2.4 \ | 141 | -I/usr/include/python2.5 \ |
142 | -I/usr/lib/python2.4/config \ | 142 | -I/usr/lib/python2.5/config \ |
143 | -fpic \ | 143 | -fpic \ |
144 | -c -g xdelta3_wrap.c | 144 | -c -g xdelta3_wrap.c |
145 | 145 | ||
146 | xdelta3module.dll: xdelta3_wrap.o xdelta3.o | 146 | xdelta3module.dll: xdelta3_wrap.o xdelta3.o |
147 | gcc -shared -Wl,--enable-auto-image-base xdelta3.o xdelta3_wrap.o -L/usr/lib/python2.4/config -lpython2.4 -o xdelta3module.dll | 147 | gcc -shared -Wl,--enable-auto-image-base xdelta3.o xdelta3_wrap.o -L/usr/lib/python2.5/config -lpython2.5 -o xdelta3module.dll |
148 | cp $(SWIGTGT) /usr/lib/python2.4/site-packages | 148 | cp $(SWIGTGT) /usr/lib/python2.5/site-packages |
149 | 149 | ||
150 | xdelta3module.so: xdelta3_wrap.o xdelta3.o | 150 | xdelta3module.so: xdelta3_wrap.o xdelta3.o |
151 | ld -shared xdelta3.o xdelta3_wrap.o -o xdelta3module.so /usr/lib/libpython2.4.so -lgcc_s -lc | 151 | ld -shared xdelta3.o xdelta3_wrap.o -o xdelta3module.so /usr/lib/libpython2.4.so -lgcc_s -lc |
@@ -189,10 +189,6 @@ xdelta3-everything: $(SOURCES) | |||
189 | -DEXTERNAL_COMPRESSION=1 \ | 189 | -DEXTERNAL_COMPRESSION=1 \ |
190 | -DXD3_DEBUG=1 -lm | 190 | -DXD3_DEBUG=1 -lm |
191 | 191 | ||
192 | xdelta3-tune: $(SOURCES) | ||
193 | $(CC) -O2 -Wall -Wshadow xdelta3.c -o xdelta3-tune -DXD3_MAIN=1 \ | ||
194 | -DSECONDARY_FGK=1 -DSECONDARY_DJW=1 -DTUNE_HUFFMAN=1 | ||
195 | |||
196 | xdelta3-Opg: $(SOURCES) | 192 | xdelta3-Opg: $(SOURCES) |
197 | $(CC) -pg -g -O -Wall -Wshadow xdelta3.c -o xdelta3-Opg -DXD3_MAIN=1 \ | 193 | $(CC) -pg -g -O -Wall -Wshadow xdelta3.c -o xdelta3-Opg -DXD3_MAIN=1 \ |
198 | -DSECONDARY_DJW=1 -DXD3_POSIX=1 -DXD3_USE_LARGEFILE64=1 | 194 | -DSECONDARY_DJW=1 -DXD3_POSIX=1 -DXD3_USE_LARGEFILE64=1 |
diff --git a/xdelta3/xdelta3-decode.h b/xdelta3/xdelta3-decode.h index 2e8158b..bb03c04 100644 --- a/xdelta3/xdelta3-decode.h +++ b/xdelta3/xdelta3-decode.h | |||
@@ -337,7 +337,6 @@ xd3_decode_output_halfinst (xd3_stream *stream, xd3_hinst *inst) | |||
337 | return XD3_INVALID_INPUT; | 337 | return XD3_INVALID_INPUT; |
338 | } | 338 | } |
339 | 339 | ||
340 | /* TUNE: Probably want to eliminate memset/memcpy here */ | ||
341 | memset (stream->next_out + stream->avail_out, | 340 | memset (stream->next_out + stream->avail_out, |
342 | stream->data_sect.buf[0], | 341 | stream->data_sect.buf[0], |
343 | take); | 342 | take); |
diff --git a/xdelta3/xdelta3-djw.h b/xdelta3/xdelta3-djw.h index dc3e70b..1c77ce7 100644 --- a/xdelta3/xdelta3-djw.h +++ b/xdelta3/xdelta3-djw.h | |||
@@ -86,25 +86,6 @@ typedef struct _djw_heapen djw_heapen; | |||
86 | typedef struct _djw_prefix djw_prefix; | 86 | typedef struct _djw_prefix djw_prefix; |
87 | typedef uint32_t djw_weight; | 87 | typedef uint32_t djw_weight; |
88 | 88 | ||
89 | /* To enable Huffman tuning code... */ | ||
90 | #ifndef TUNE_HUFFMAN | ||
91 | #define TUNE_HUFFMAN 0 | ||
92 | #endif | ||
93 | |||
94 | #if TUNE_HUFFMAN == 0 | ||
95 | #define xd3_real_encode_huff xd3_encode_huff | ||
96 | #define IF_TUNE(x) | ||
97 | #define IF_NTUNE(x) x | ||
98 | #else | ||
99 | static uint xd3_bitsof_output (xd3_output *output, bit_state *bstate); | ||
100 | #define IF_TUNE(x) x | ||
101 | #define IF_NTUNE(x) | ||
102 | static djw_weight tune_freq[DJW_TOTAL_CODES]; | ||
103 | static uint8_t tune_clen[DJW_MAX_GROUPS][ALPHABET_SIZE]; | ||
104 | static usize_t tune_prefix_bits; | ||
105 | static usize_t tune_select_bits; | ||
106 | static usize_t tune_encode_bits; | ||
107 | #endif | ||
108 | struct _djw_heapen | 89 | struct _djw_heapen |
109 | { | 90 | { |
110 | uint32_t depth; | 91 | uint32_t depth; |
@@ -481,7 +462,7 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, int asize, int maxlen) | |||
481 | } | 462 | } |
482 | 463 | ||
483 | static void | 464 | static void |
484 | djw_build_codes (uint *codes, const uint8_t *clen, int asize DEBUG_ARG (int abs_max)) | 465 | djw_build_codes (uint *codes, const uint8_t *clen, int asize, int abs_max) |
485 | { | 466 | { |
486 | int i, l; | 467 | int i, l; |
487 | int min_clen = DJW_MAX_CODELEN; | 468 | int min_clen = DJW_MAX_CODELEN; |
@@ -642,14 +623,12 @@ djw_encode_prefix (xd3_stream *stream, | |||
642 | uint8_t clclen[DJW_TOTAL_CODES]; | 623 | uint8_t clclen[DJW_TOTAL_CODES]; |
643 | uint clcode[DJW_TOTAL_CODES]; | 624 | uint clcode[DJW_TOTAL_CODES]; |
644 | 625 | ||
645 | IF_TUNE (memset (clfreq, 0, sizeof (clfreq))); | ||
646 | |||
647 | /* Move-to-front encode prefix symbols, count frequencies */ | 626 | /* Move-to-front encode prefix symbols, count frequencies */ |
648 | djw_compute_prefix_1_2 (prefix, clfreq); | 627 | djw_compute_prefix_1_2 (prefix, clfreq); |
649 | 628 | ||
650 | /* Compute codes */ | 629 | /* Compute codes */ |
651 | djw_build_prefix (clfreq, clclen, DJW_TOTAL_CODES, DJW_MAX_CLCLEN); | 630 | djw_build_prefix (clfreq, clclen, DJW_TOTAL_CODES, DJW_MAX_CLCLEN); |
652 | djw_build_codes (clcode, clclen, DJW_TOTAL_CODES DEBUG_ARG (DJW_MAX_CLCLEN)); | 631 | djw_build_codes (clcode, clclen, DJW_TOTAL_CODES, DJW_MAX_CLCLEN); |
653 | 632 | ||
654 | /* Compute number of extra codes beyond basic ones for this template. */ | 633 | /* Compute number of extra codes beyond basic ones for this template. */ |
655 | num_to_encode = DJW_TOTAL_CODES; | 634 | num_to_encode = DJW_TOTAL_CODES; |
@@ -676,8 +655,6 @@ djw_encode_prefix (xd3_stream *stream, | |||
676 | if ((ret = xd3_encode_bits (stream, output, bstate, bits, code))) { return ret; } | 655 | if ((ret = xd3_encode_bits (stream, output, bstate, bits, code))) { return ret; } |
677 | } | 656 | } |
678 | 657 | ||
679 | IF_TUNE (memcpy (tune_freq, clfreq, sizeof (clfreq))); | ||
680 | |||
681 | return 0; | 658 | return 0; |
682 | } | 659 | } |
683 | 660 | ||
@@ -798,11 +775,11 @@ xd3_encode_howmany_groups (xd3_stream *stream, | |||
798 | } | 775 | } |
799 | 776 | ||
800 | static int | 777 | static int |
801 | xd3_real_encode_huff (xd3_stream *stream, | 778 | xd3_encode_huff (xd3_stream *stream, |
802 | djw_stream *h, | 779 | djw_stream *h, |
803 | xd3_output *input, | 780 | xd3_output *input, |
804 | xd3_output *output, | 781 | xd3_output *output, |
805 | xd3_sec_cfg *cfg) | 782 | xd3_sec_cfg *cfg) |
806 | { | 783 | { |
807 | int ret; | 784 | int ret; |
808 | usize_t groups, sector_size; | 785 | usize_t groups, sector_size; |
@@ -841,14 +818,13 @@ xd3_real_encode_huff (xd3_stream *stream, | |||
841 | { | 818 | { |
842 | /* Single Huffman group. */ | 819 | /* Single Huffman group. */ |
843 | uint code[ALPHABET_SIZE]; /* Codes */ | 820 | uint code[ALPHABET_SIZE]; /* Codes */ |
844 | IF_TUNE (uint8_t *clen = tune_clen[0];) | 821 | uint8_t clen[ALPHABET_SIZE]; |
845 | IF_NTUNE (uint8_t clen[ALPHABET_SIZE];) | ||
846 | uint8_t prefix_mtfsym[ALPHABET_SIZE]; | 822 | uint8_t prefix_mtfsym[ALPHABET_SIZE]; |
847 | djw_prefix prefix; | 823 | djw_prefix prefix; |
848 | 824 | ||
849 | encode_bits = | 825 | encode_bits = |
850 | djw_build_prefix (real_freq, clen, ALPHABET_SIZE, DJW_MAX_CODELEN); | 826 | djw_build_prefix (real_freq, clen, ALPHABET_SIZE, DJW_MAX_CODELEN); |
851 | djw_build_codes (code, clen, ALPHABET_SIZE DEBUG_ARG (DJW_MAX_CODELEN)); | 827 | djw_build_codes (code, clen, ALPHABET_SIZE, DJW_MAX_CODELEN); |
852 | 828 | ||
853 | if (encode_bits + EFFICIENCY_BITS >= input_bits && ! cfg->inefficient) { goto nosecond; } | 829 | if (encode_bits + EFFICIENCY_BITS >= input_bits && ! cfg->inefficient) { goto nosecond; } |
854 | 830 | ||
@@ -861,10 +837,6 @@ xd3_real_encode_huff (xd3_stream *stream, | |||
861 | 837 | ||
862 | if (encode_bits + (8 * output->next) + EFFICIENCY_BITS >= input_bits && ! cfg->inefficient) { goto nosecond; } | 838 | if (encode_bits + (8 * output->next) + EFFICIENCY_BITS >= input_bits && ! cfg->inefficient) { goto nosecond; } |
863 | 839 | ||
864 | IF_TUNE (tune_prefix_bits = xd3_bitsof_output (output, & bstate)); | ||
865 | IF_TUNE (tune_select_bits = 0); | ||
866 | IF_TUNE (tune_encode_bits = encode_bits); | ||
867 | |||
868 | /* Encode: data */ | 840 | /* Encode: data */ |
869 | for (in = input; in; in = in->next_page) | 841 | for (in = input; in; in = in->next_page) |
870 | { | 842 | { |
@@ -889,11 +861,7 @@ xd3_real_encode_huff (xd3_stream *stream, | |||
889 | { | 861 | { |
890 | /* DJW Huffman */ | 862 | /* DJW Huffman */ |
891 | djw_weight evolve_freq[DJW_MAX_GROUPS][ALPHABET_SIZE]; | 863 | djw_weight evolve_freq[DJW_MAX_GROUPS][ALPHABET_SIZE]; |
892 | #if TUNE_HUFFMAN == 0 | ||
893 | uint8_t evolve_clen[DJW_MAX_GROUPS][ALPHABET_SIZE]; | 864 | uint8_t evolve_clen[DJW_MAX_GROUPS][ALPHABET_SIZE]; |
894 | #else | ||
895 | #define evolve_clen tune_clen | ||
896 | #endif | ||
897 | djw_weight left = input_bytes; | 865 | djw_weight left = input_bytes; |
898 | int gp; | 866 | int gp; |
899 | int niter = 0; | 867 | int niter = 0; |
@@ -1129,11 +1097,7 @@ xd3_real_encode_huff (xd3_stream *stream, | |||
1129 | 1097 | ||
1130 | select_bits = | 1098 | select_bits = |
1131 | djw_build_prefix (gbest_freq, gbest_clen, groups+1, DJW_MAX_GBCLEN); | 1099 | djw_build_prefix (gbest_freq, gbest_clen, groups+1, DJW_MAX_GBCLEN); |
1132 | djw_build_codes (gbest_code, gbest_clen, groups+1 DEBUG_ARG (DJW_MAX_GBCLEN)); | 1100 | djw_build_codes (gbest_code, gbest_clen, groups+1, DJW_MAX_GBCLEN); |
1133 | |||
1134 | IF_TUNE (tune_prefix_bits = xd3_bitsof_output (output, & bstate)); | ||
1135 | IF_TUNE (tune_select_bits = select_bits); | ||
1136 | IF_TUNE (tune_encode_bits = encode_bits); | ||
1137 | 1101 | ||
1138 | for (i = 0; i < groups+1; i += 1) | 1102 | for (i = 0; i < groups+1; i += 1) |
1139 | { | 1103 | { |
@@ -1167,7 +1131,7 @@ xd3_real_encode_huff (xd3_stream *stream, | |||
1167 | /* Build code tables for each group. */ | 1131 | /* Build code tables for each group. */ |
1168 | for (gp = 0; gp < groups; gp += 1) | 1132 | for (gp = 0; gp < groups; gp += 1) |
1169 | { | 1133 | { |
1170 | djw_build_codes (evolve_code[gp], evolve_clen[gp], ALPHABET_SIZE DEBUG_ARG (DJW_MAX_CODELEN)); | 1134 | djw_build_codes (evolve_code[gp], evolve_clen[gp], ALPHABET_SIZE, DJW_MAX_CODELEN); |
1171 | } | 1135 | } |
1172 | 1136 | ||
1173 | /* Now loop over the input. */ | 1137 | /* Now loop over the input. */ |
@@ -1688,239 +1652,4 @@ xd3_decode_huff (xd3_stream *stream, | |||
1688 | return ret; | 1652 | return ret; |
1689 | } | 1653 | } |
1690 | 1654 | ||
1691 | /*********************************************************************/ | ||
1692 | /* TUNING */ | ||
1693 | /*********************************************************************/ | ||
1694 | |||
1695 | #if TUNE_HUFFMAN && XD3_ENCODER | ||
1696 | #include <stdio.h> | ||
1697 | #include "xdelta3-fgk.h" | ||
1698 | |||
1699 | static uint | ||
1700 | xd3_bitsof_output (xd3_output *output, bit_state *bstate) | ||
1701 | { | ||
1702 | uint x = 0; | ||
1703 | uint m = bstate->cur_mask; | ||
1704 | |||
1705 | while (m != 1) | ||
1706 | { | ||
1707 | x += 1; | ||
1708 | m >>= 1; | ||
1709 | } | ||
1710 | |||
1711 | return x + 8 * xd3_sizeof_output (output); | ||
1712 | } | ||
1713 | |||
1714 | static const char* xd3_sect_type (xd3_section_type type) | ||
1715 | { | ||
1716 | switch (type) | ||
1717 | { | ||
1718 | case DATA_SECTION: return "DATA"; | ||
1719 | case INST_SECTION: return "INST"; | ||
1720 | case ADDR_SECTION: return "ADDR"; | ||
1721 | } | ||
1722 | abort (); | ||
1723 | } | ||
1724 | |||
1725 | static int | ||
1726 | xd3_encode_huff (xd3_stream *stream, | ||
1727 | djw_stream *h, | ||
1728 | xd3_output *input, | ||
1729 | xd3_output *unused_output, | ||
1730 | xd3_sec_cfg *cfg) | ||
1731 | { | ||
1732 | int ret = 0; | ||
1733 | int input_size = xd3_sizeof_output (input); | ||
1734 | static int hdr = 0; | ||
1735 | const char *sect_type = xd3_sect_type (cfg->data_type); | ||
1736 | xd3_output *output; | ||
1737 | usize_t output_size; | ||
1738 | |||
1739 | if (hdr == 0) { hdr = 1; DP(RINT "____ SECT INSZ SECTORSZ GPNO OUTSZ PREFIX SELECT ENCODE\n"); } | ||
1740 | |||
1741 | DP(RINT "SECTION %s %u\n", sect_type, input_size); | ||
1742 | |||
1743 | { | ||
1744 | int gp, i; | ||
1745 | int best_size = 99999999; | ||
1746 | usize_t best_prefix = 0, best_select = 0, best_encode = 0, best_sector_size = 0; | ||
1747 | int best_gpno = -1; | ||
1748 | const char *t12 = "12"; | ||
1749 | usize_t clen_count[DJW_MAX_CODELEN+1]; | ||
1750 | djw_weight best_freq[DJW_TOTAL_CODES]; | ||
1751 | |||
1752 | for (cfg->ngroups = 1; cfg->ngroups <= /*1*/ DJW_MAX_GROUPS; cfg->ngroups += 1) | ||
1753 | { | ||
1754 | for (cfg->sector_size = 10; cfg->sector_size <= DJW_SECTORSZ_MAX; cfg->sector_size += 10) | ||
1755 | { | ||
1756 | output = xd3_alloc_output (stream, NULL); | ||
1757 | |||
1758 | if ((ret = xd3_real_encode_huff (stream, h, input, output, cfg))) { goto fail; } | ||
1759 | |||
1760 | output_size = xd3_sizeof_output (output); | ||
1761 | |||
1762 | if (output_size < best_size) | ||
1763 | { | ||
1764 | best_size = output_size; | ||
1765 | best_gpno = cfg->ngroups; | ||
1766 | best_prefix = tune_prefix_bits; | ||
1767 | best_select = tune_select_bits; | ||
1768 | best_encode = tune_encode_bits; | ||
1769 | best_sector_size = cfg->sector_size; | ||
1770 | memset (clen_count, 0, sizeof (clen_count)); | ||
1771 | |||
1772 | for (gp = 0; gp < cfg->ngroups; gp += 1) | ||
1773 | { | ||
1774 | for (i = 0; i < ALPHABET_SIZE; i += 1) | ||
1775 | { | ||
1776 | clen_count[tune_clen[gp][i]] += 1; | ||
1777 | } | ||
1778 | } | ||
1779 | |||
1780 | memcpy (best_freq, tune_freq, sizeof (tune_freq)); | ||
1781 | |||
1782 | XD3_ASSERT (sizeof (tune_freq) == sizeof (mtf_freq)); | ||
1783 | } | ||
1784 | |||
1785 | if (1) | ||
1786 | { | ||
1787 | DP(RINT "COMP%s %u %u %u %u %u %u\n", | ||
1788 | t12, cfg->ngroups, cfg->sector_size, | ||
1789 | output_size, tune_prefix_bits, tune_select_bits, tune_encode_bits); | ||
1790 | } | ||
1791 | else | ||
1792 | { | ||
1793 | fail: | ||
1794 | DP(RINT "COMP%s %u %u %u %u %u %u\n", | ||
1795 | t12, cfg->ngroups, cfg->sector_size, | ||
1796 | input_size, 0, 0, 0); | ||
1797 | } | ||
1798 | |||
1799 | xd3_free_output (stream, output); | ||
1800 | |||
1801 | XD3_ASSERT (ret == 0 || ret == XD3_NOSECOND); | ||
1802 | |||
1803 | if (cfg->ngroups == 1) { break; } | ||
1804 | } | ||
1805 | } | ||
1806 | |||
1807 | if (best_gpno > 0) | ||
1808 | { | ||
1809 | DP(RINT "BEST%s %u %u %u %u %u %u\n", | ||
1810 | t12, best_gpno, best_sector_size, | ||
1811 | best_size, best_prefix, best_select, best_encode); | ||
1812 | |||
1813 | #if 0 | ||
1814 | DP(RINT "CLEN%s ", t12); | ||
1815 | for (i = 1; i <= DJW_MAX_CODELEN; i += 1) | ||
1816 | { | ||
1817 | DP(RINT "%u ", clen_count[i]); | ||
1818 | } | ||
1819 | DP(RINT "\n"); | ||
1820 | |||
1821 | DP(RINT "FREQ%s ", t12); | ||
1822 | for (i = 0; i < DJW_TOTAL_CODES; i += 1) | ||
1823 | { | ||
1824 | DP(RINT "%u ", tune_freq[i]); | ||
1825 | } | ||
1826 | DP(RINT "\n"); | ||
1827 | #endif | ||
1828 | } | ||
1829 | } | ||
1830 | |||
1831 | /* Compare to split single-table windows. */ | ||
1832 | { | ||
1833 | int parts, i; | ||
1834 | |||
1835 | cfg->ngroups = 1; | ||
1836 | |||
1837 | for (parts = 2; parts <= DJW_MAX_GROUPS; parts += 1) | ||
1838 | { | ||
1839 | usize_t part_size = input_size / parts; | ||
1840 | xd3_output *inp = input, *partin, *partin_head; | ||
1841 | usize_t off = 0; | ||
1842 | usize_t part_total = 0; | ||
1843 | |||
1844 | if (part_size < 1000) { break; } | ||
1845 | |||
1846 | for (i = 0; i < parts; i += 1) | ||
1847 | { | ||
1848 | usize_t inc; | ||
1849 | |||
1850 | partin = partin_head = xd3_alloc_output (stream, NULL); | ||
1851 | output = xd3_alloc_output (stream, NULL); | ||
1852 | |||
1853 | for (inc = 0; ((i < parts-1) && inc < part_size) || | ||
1854 | ((i == parts-1) && inp != NULL); ) | ||
1855 | { | ||
1856 | usize_t take; | ||
1857 | |||
1858 | if (i < parts-1) | ||
1859 | { | ||
1860 | take = min (part_size - inc, inp->next - off); | ||
1861 | } | ||
1862 | else | ||
1863 | { | ||
1864 | take = inp->next - off; | ||
1865 | } | ||
1866 | |||
1867 | ret = xd3_emit_bytes (stream, & partin, inp->base + off, take); | ||
1868 | |||
1869 | off += take; | ||
1870 | inc += take; | ||
1871 | |||
1872 | if (off == inp->next) | ||
1873 | { | ||
1874 | inp = inp->next_page; | ||
1875 | off = 0; | ||
1876 | } | ||
1877 | } | ||
1878 | |||
1879 | ret = xd3_real_encode_huff (stream, h, partin_head, output, cfg); | ||
1880 | |||
1881 | part_total += xd3_sizeof_output (output); | ||
1882 | |||
1883 | xd3_free_output (stream, partin_head); | ||
1884 | xd3_free_output (stream, output); | ||
1885 | |||
1886 | XD3_ASSERT (ret == 0 || ret == XD3_NOSECOND); | ||
1887 | |||
1888 | if (ret == XD3_NOSECOND) | ||
1889 | { | ||
1890 | break; | ||
1891 | } | ||
1892 | } | ||
1893 | |||
1894 | if (ret != XD3_NOSECOND) | ||
1895 | { | ||
1896 | DP(RINT "PART %u %u\n", parts, part_total); | ||
1897 | } | ||
1898 | } | ||
1899 | } | ||
1900 | |||
1901 | /* Compare to FGK */ | ||
1902 | { | ||
1903 | fgk_stream *fgk = fgk_alloc (stream); | ||
1904 | |||
1905 | fgk_init (fgk); | ||
1906 | |||
1907 | output = xd3_alloc_output (stream, NULL); | ||
1908 | |||
1909 | ret = xd3_encode_fgk (stream, fgk, input, output, NULL); | ||
1910 | |||
1911 | output_size = xd3_sizeof_output (output); | ||
1912 | xd3_free_output (stream, output); | ||
1913 | fgk_destroy (stream, fgk); | ||
1914 | |||
1915 | XD3_ASSERT (ret == 0); | ||
1916 | |||
1917 | DP(RINT "FGK %u\n", output_size); | ||
1918 | } | ||
1919 | |||
1920 | DP(RINT "END_SECTION %s %u\n", sect_type, input_size); | ||
1921 | |||
1922 | return 0; | ||
1923 | } | ||
1924 | #endif | ||
1925 | |||
1926 | #endif | 1655 | #endif |
diff --git a/xdelta3/xdelta3-regtest.py b/xdelta3/xdelta3-regtest.py index d2c7f8a..07052f0 100755 --- a/xdelta3/xdelta3-regtest.py +++ b/xdelta3/xdelta3-regtest.py | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/usr/bin/python2.4 | 1 | #!/usr/bin/python2.5 |
2 | # xdelta 3 - delta compression tools and library | 2 | # xdelta 3 - delta compression tools and library |
3 | # Copyright (C) 2003, 2006, 2007. Joshua P. MacDonald | 3 | # Copyright (C) 2003, 2006, 2007. Joshua P. MacDonald |
4 | # | 4 | # |
diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h index c19f2fd..7d7f6a0 100644 --- a/xdelta3/xdelta3-test.h +++ b/xdelta3/xdelta3-test.h | |||
@@ -925,6 +925,7 @@ static int sec_dist_func6 (xd3_stream *stream, xd3_output *data); | |||
925 | static int sec_dist_func7 (xd3_stream *stream, xd3_output *data); | 925 | static int sec_dist_func7 (xd3_stream *stream, xd3_output *data); |
926 | static int sec_dist_func8 (xd3_stream *stream, xd3_output *data); | 926 | static int sec_dist_func8 (xd3_stream *stream, xd3_output *data); |
927 | static int sec_dist_func9 (xd3_stream *stream, xd3_output *data); | 927 | static int sec_dist_func9 (xd3_stream *stream, xd3_output *data); |
928 | static int sec_dist_func10 (xd3_stream *stream, xd3_output *data); | ||
928 | 929 | ||
929 | static sec_dist_func sec_dists[] = | 930 | static sec_dist_func sec_dists[] = |
930 | { | 931 | { |
@@ -937,6 +938,7 @@ static sec_dist_func sec_dists[] = | |||
937 | sec_dist_func7, | 938 | sec_dist_func7, |
938 | sec_dist_func8, | 939 | sec_dist_func8, |
939 | sec_dist_func9, | 940 | sec_dist_func9, |
941 | sec_dist_func10, | ||
940 | }; | 942 | }; |
941 | 943 | ||
942 | /* Test ditsribution: 100 bytes of the same character (13). */ | 944 | /* Test ditsribution: 100 bytes of the same character (13). */ |
@@ -1089,6 +1091,21 @@ sec_dist_func9 (xd3_stream *stream, xd3_output *data) | |||
1089 | return 0; | 1091 | return 0; |
1090 | } | 1092 | } |
1091 | 1093 | ||
1094 | /* Test distribution: freq[i] == i*i, creates a 21-bit code length, fixed in 3.0r. */ | ||
1095 | static int | ||
1096 | sec_dist_func10 (xd3_stream *stream, xd3_output *data) | ||
1097 | { | ||
1098 | int i, j, ret; | ||
1099 | for (i = 0; i < ALPHABET_SIZE; i += 1) | ||
1100 | { | ||
1101 | for (j = 0; j <= (i*i); j += 1) | ||
1102 | { | ||
1103 | if ((ret = xd3_emit_byte (stream, & data, i))) { return ret; } | ||
1104 | } | ||
1105 | } | ||
1106 | return 0; | ||
1107 | } | ||
1108 | |||
1092 | static int | 1109 | static int |
1093 | test_secondary_decode (xd3_stream *stream, | 1110 | test_secondary_decode (xd3_stream *stream, |
1094 | const xd3_sec_type *sec, | 1111 | const xd3_sec_type *sec, |
@@ -1213,7 +1230,8 @@ test_secondary (xd3_stream *stream, const xd3_sec_type *sec, int groups) | |||
1213 | 1230 | ||
1214 | CHECK(p_off == input_size); | 1231 | CHECK(p_off == input_size); |
1215 | 1232 | ||
1216 | if ((ret = test_secondary_decode (stream, sec, input_size, compress_size, dec_input, dec_correct, dec_output))) | 1233 | if ((ret = test_secondary_decode (stream, sec, input_size, compress_size, |
1234 | dec_input, dec_correct, dec_output))) | ||
1217 | { | 1235 | { |
1218 | DP(RINT "test %u: decode: %s", test_i, stream->msg); | 1236 | DP(RINT "test %u: decode: %s", test_i, stream->msg); |
1219 | goto fail; | 1237 | goto fail; |
@@ -1229,9 +1247,12 @@ test_secondary (xd3_stream *stream, const xd3_sec_type *sec, int groups) | |||
1229 | { | 1247 | { |
1230 | dec_input[i/8] ^= 1 << (i%8); | 1248 | dec_input[i/8] ^= 1 << (i%8); |
1231 | 1249 | ||
1232 | if ((ret = test_secondary_decode (stream, sec, input_size, compress_size, dec_input, dec_correct, dec_output)) == 0) | 1250 | if ((ret = test_secondary_decode (stream, sec, input_size, |
1251 | compress_size, dec_input, | ||
1252 | dec_correct, dec_output)) == 0) | ||
1233 | { | 1253 | { |
1234 | /*DP(RINT "test %u: decode single-bit [%u/%u] error non-failure", test_i, i/8, i%8);*/ | 1254 | /*DP(RINT "test %u: decode single-bit [%u/%u] |
1255 | error non-failure", test_i, i/8, i%8);*/ | ||
1235 | } | 1256 | } |
1236 | 1257 | ||
1237 | dec_input[i/8] ^= 1 << (i%8); | 1258 | dec_input[i/8] ^= 1 << (i%8); |
@@ -1261,8 +1282,10 @@ test_secondary (xd3_stream *stream, const xd3_sec_type *sec, int groups) | |||
1261 | return 0; | 1282 | return 0; |
1262 | } | 1283 | } |
1263 | 1284 | ||
1264 | IF_FGK (static int test_secondary_fgk (xd3_stream *stream, int gp) { return test_secondary (stream, & fgk_sec_type, gp); }) | 1285 | IF_FGK (static int test_secondary_fgk (xd3_stream *stream, int gp) |
1265 | IF_DJW (static int test_secondary_huff (xd3_stream *stream, int gp) { return test_secondary (stream, & djw_sec_type, gp); }) | 1286 | { return test_secondary (stream, & fgk_sec_type, gp); }) |
1287 | IF_DJW (static int test_secondary_huff (xd3_stream *stream, int gp) | ||
1288 | { return test_secondary (stream, & djw_sec_type, gp); }) | ||
1266 | #endif | 1289 | #endif |
1267 | 1290 | ||
1268 | /****************************************************************************************** | 1291 | /****************************************************************************************** |
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index ccb013b..a545b66 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c | |||
@@ -517,10 +517,8 @@ IF_BUILD_DEFAULT(static const xd3_smatcher __smatcher_default;) | |||
517 | /* This CPP-conditional stuff can be cleaned up... */ | 517 | /* This CPP-conditional stuff can be cleaned up... */ |
518 | #if XD3_DEBUG | 518 | #if XD3_DEBUG |
519 | #define IF_DEBUG(x) x | 519 | #define IF_DEBUG(x) x |
520 | #define DEBUG_ARG(x) , x | ||
521 | #else | 520 | #else |
522 | #define IF_DEBUG(x) | 521 | #define IF_DEBUG(x) |
523 | #define DEBUG_ARG(x) | ||
524 | #endif | 522 | #endif |
525 | #if XD3_DEBUG > 1 | 523 | #if XD3_DEBUG > 1 |
526 | #define IF_DEBUG1(x) x | 524 | #define IF_DEBUG1(x) x |