summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3.h
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/xdelta3.h')
-rw-r--r--xdelta3/xdelta3.h119
1 files changed, 82 insertions, 37 deletions
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h
index 11bbdb8..1b8f083 100644
--- a/xdelta3/xdelta3.h
+++ b/xdelta3/xdelta3.h
@@ -17,7 +17,7 @@
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20/* To know more about Xdelta, start by reading xdelta3.c. If you are 20/* To learn more about Xdelta, start by reading xdelta3.c. If you are
21 * ready to use the API, continue reading here. There are two 21 * ready to use the API, continue reading here. There are two
22 * interfaces -- xd3_encode_input and xd3_decode_input -- plus a dozen 22 * interfaces -- xd3_encode_input and xd3_decode_input -- plus a dozen
23 * or so related calls. This interface is styled after Zlib. */ 23 * or so related calls. This interface is styled after Zlib. */
@@ -25,7 +25,7 @@
25#ifndef _XDELTA3_H_ 25#ifndef _XDELTA3_H_
26#define _XDELTA3_H_ 26#define _XDELTA3_H_
27 27
28#define _POSIX_SOURCE 28#define _POSIX_SOURCE 200112L
29#define _ISOC99_SOURCE 29#define _ISOC99_SOURCE
30#define _C99_SOURCE 30#define _C99_SOURCE
31 31
@@ -71,7 +71,7 @@
71 * 71 *
72 * 8-16MB is reasonable, probably don't need to go larger. */ 72 * 8-16MB is reasonable, probably don't need to go larger. */
73#ifndef XD3_HARDMAXWINSIZE 73#ifndef XD3_HARDMAXWINSIZE
74#define XD3_HARDMAXWINSIZE (1U<<24) 74#define XD3_HARDMAXWINSIZE (1U<<26)
75#endif 75#endif
76/* The IOPT_SIZE value sets the size of a buffer used to batch 76/* The IOPT_SIZE value sets the size of a buffer used to batch
77 * overlapping copy instructions before they are optimized by picking 77 * overlapping copy instructions before they are optimized by picking
@@ -87,8 +87,7 @@
87#define XD3_DEFAULT_SPREVSZ (1U<<18) 87#define XD3_DEFAULT_SPREVSZ (1U<<18)
88#endif 88#endif
89 89
90/* The default compression level 90/* The default compression level */
91 */
92#ifndef XD3_DEFAULT_LEVEL 91#ifndef XD3_DEFAULT_LEVEL
93#define XD3_DEFAULT_LEVEL 3 92#define XD3_DEFAULT_LEVEL 3
94#endif 93#endif
@@ -101,6 +100,12 @@
101#define XD3_USE_LARGEFILE64 1 100#define XD3_USE_LARGEFILE64 1
102#endif 101#endif
103 102
103/* The source window size is limited to 2GB unless
104 * XD3_USE_LARGEWINDOW64 is defined to 1. */
105#ifndef XD3_USE_LARGEWINDOW64
106#define XD3_USE_LARGEWINDOW64 0
107#endif
108
104/* Sizes and addresses within VCDIFF windows are represented as usize_t 109/* Sizes and addresses within VCDIFF windows are represented as usize_t
105 * 110 *
106 * For source-file offsets and total file sizes, total input and 111 * For source-file offsets and total file sizes, total input and
@@ -109,6 +114,8 @@
109 * the 32bit boundary [xdelta3-test.h]). 114 * the 32bit boundary [xdelta3-test.h]).
110 */ 115 */
111#ifndef _WIN32 116#ifndef _WIN32
117#define __STDC_FORMAT_MACROS
118#include <inttypes.h>
112#include <stdint.h> 119#include <stdint.h>
113#else /* WIN32 case */ 120#else /* WIN32 case */
114#define WIN32_LEAN_AND_MEAN 121#define WIN32_LEAN_AND_MEAN
@@ -148,8 +155,7 @@ typedef ULONGLONG uint64_t;
148#endif /* _MSC_VER defined */ 155#endif /* _MSC_VER defined */
149#endif /* _WIN32 defined */ 156#endif /* _WIN32 defined */
150 157
151typedef uint32_t usize_t; 158/* Settings based on the size of xoff_t (32 vs 64 file offsets) */
152
153#if XD3_USE_LARGEFILE64 159#if XD3_USE_LARGEFILE64
154/* xoff_t is a 64-bit type */ 160/* xoff_t is a 64-bit type */
155#define __USE_FILE_OFFSET64 1 /* GLIBC: for 64bit fileops, ... ? */ 161#define __USE_FILE_OFFSET64 1 /* GLIBC: for 64bit fileops, ... ? */
@@ -162,6 +168,7 @@ typedef uint32_t usize_t;
162#define _FILE_OFFSET_BITS 64 168#define _FILE_OFFSET_BITS 64
163#endif 169#endif
164 170
171/* Set a xoff_t typedef and the "Q" printf insert. */
165#if defined(_WIN32) 172#if defined(_WIN32)
166typedef uint64_t xoff_t; 173typedef uint64_t xoff_t;
167/* Note: The following generates benign warnings in a mingw 174/* Note: The following generates benign warnings in a mingw
@@ -176,7 +183,7 @@ typedef size_t xoff_t;
176#elif SIZEOF_UNSIGNED_LONG_LONG == 8 183#elif SIZEOF_UNSIGNED_LONG_LONG == 8
177typedef unsigned long long xoff_t; 184typedef unsigned long long xoff_t;
178#define Q "ll" 185#define Q "ll"
179#endif /* #define Q */ 186#endif /* typedef and #define Q */
180 187
181#define SIZEOF_XOFF_T 8 188#define SIZEOF_XOFF_T 8
182 189
@@ -194,9 +201,45 @@ typedef uint32_t xoff_t;
194#define Q 201#define Q
195#endif /* 64 vs 32 bit xoff_t */ 202#endif /* 64 vs 32 bit xoff_t */
196 203
197/* Note: This gets modified in the 64bithash branch. */ 204/* Settings based on the size of usize_t (32 and 64 bit window size) */
205#if XD3_USE_LARGESIZET
206
207/* Set a usize_ttypedef and the "W" printf insert. */
208#if defined(_WIN32)
209typedef uint64_t usize_t;
210/* Note: The following generates benign warnings in a mingw
211 * cross-compiler */
212#define W "I64"
213#elif SIZEOF_UNSIGNED_LONG == 8
214typedef unsigned long usize_t;
215#define W "l"
216#elif SIZEOF_SIZE_T == 8
217typedef size_t usize_t;
218#define W "z"
219#elif SIZEOF_UNSIGNED_LONG_LONG == 8
220typedef unsigned long long usize_t;
221#define W "ll"
222#endif /* typedef and #define W */
223
224#define SIZEOF_USIZE_T 8
225
226#else /* XD3_USE_LARGESIZET == 0 */
227
228#if SIZEOF_UNSIGNED_INT == 4
229typedef unsigned int usize_t;
230#elif SIZEOF_UNSIGNED_LONG == 4
231typedef unsigned long usize_t;
232#else
233typedef uint32_t usize_t;
234#endif /* usize_t is 32 bits */
235
198#define SIZEOF_USIZE_T 4 236#define SIZEOF_USIZE_T 4
237#define W
199 238
239#endif /* 64 vs 32 bit usize_t */
240
241/* Settings based on the size of size_t (the system-provided,
242 * usually-but-maybe-not an unsigned type) */
200#if SIZEOF_SIZE_T == 4 243#if SIZEOF_SIZE_T == 4
201#define Z "z" 244#define Z "z"
202#elif SIZEOF_SIZE_T == 8 245#elif SIZEOF_SIZE_T == 8
@@ -339,9 +382,12 @@ typedef int (xd3_comp_table_func) (xd3_stream *stream,
339 382
340 383
341#if XD3_DEBUG 384#if XD3_DEBUG
342#define XD3_ASSERT(x) \ 385#define XD3_ASSERT(x) \
343 do { if (! (x)) { DP(RINT "%s:%d: XD3 assertion failed: %s\n", __FILE__, __LINE__, #x); \ 386 do { \
344 abort (); } } while (0) 387 if (! (x)) { \
388 DP(RINT "%s:%d: XD3 assertion failed: %s\n", \
389 __FILE__, __LINE__, #x); \
390 abort (); } } while (0)
345#else 391#else
346#define XD3_ASSERT(x) (void)0 392#define XD3_ASSERT(x) (void)0
347#endif /* XD3_DEBUG */ 393#endif /* XD3_DEBUG */
@@ -589,9 +635,9 @@ struct _xd3_dinst
589/* the decoded form of a single (half) instruction. */ 635/* the decoded form of a single (half) instruction. */
590struct _xd3_hinst 636struct _xd3_hinst
591{ 637{
592 uint8_t type; 638 uint8_t type;
593 uint32_t size; /* TODO: why decode breaks if this is usize_t? */ 639 usize_t size;
594 uint32_t addr; /* TODO: why decode breaks if this is usize_t? */ 640 usize_t addr;
595}; 641};
596 642
597/* the form of a whole-file instruction */ 643/* the form of a whole-file instruction */
@@ -618,7 +664,7 @@ struct _xd3_desect
618{ 664{
619 const uint8_t *buf; 665 const uint8_t *buf;
620 const uint8_t *buf_max; 666 const uint8_t *buf_max;
621 uint32_t size; /* TODO: why decode breaks if this is usize_t? */ 667 usize_t size;
622 usize_t pos; 668 usize_t pos;
623 669
624 /* used in xdelta3-decode.h */ 670 /* used in xdelta3-decode.h */
@@ -666,9 +712,13 @@ struct _xd3_smatcher
666/* hash table size & power-of-two hash function. */ 712/* hash table size & power-of-two hash function. */
667struct _xd3_hash_cfg 713struct _xd3_hash_cfg
668{ 714{
669 usize_t size; 715 usize_t size; // Number of buckets
670 usize_t shift; 716 usize_t shift;
671 usize_t mask; 717 usize_t mask;
718 usize_t look; // How wide is this checksum
719 usize_t multiplier; // K * powers[0]
720 usize_t *powers; // Array of [0,look) where powers[look-1] == 1
721 // and powers[N] = powers[N+1]*K (Rabin-Karp)
672}; 722};
673 723
674/* the sprev list */ 724/* the sprev list */
@@ -728,7 +778,7 @@ struct _xd3_config
728 xd3_alloc_func *alloc; 778 xd3_alloc_func *alloc;
729 xd3_free_func *freef; 779 xd3_free_func *freef;
730 void *opaque; /* Not used. */ 780 void *opaque; /* Not used. */
731 int flags; /* stream->flags are initialized 781 uint32_t flags; /* stream->flags are initialized
732 * from xd3_config & never 782 * from xd3_config & never
733 * modified by the library. Use 783 * modified by the library. Use
734 * xd3_set_flags to modify flags 784 * xd3_set_flags to modify flags
@@ -771,8 +821,8 @@ struct _xd3_source
771 usize_t srclen; /* length of this source window */ 821 usize_t srclen; /* length of this source window */
772 xoff_t srcbase; /* offset of this source window 822 xoff_t srcbase; /* offset of this source window
773 in the source itself */ 823 in the source itself */
774 int shiftby; /* for power-of-two blocksizes */ 824 usize_t shiftby; /* for power-of-two blocksizes */
775 int maskby; /* for power-of-two blocksizes */ 825 usize_t maskby; /* for power-of-two blocksizes */
776 xoff_t cpyoff_blocks; /* offset of dec_cpyoff in blocks */ 826 xoff_t cpyoff_blocks; /* offset of dec_cpyoff in blocks */
777 usize_t cpyoff_blkoff; /* offset of copy window in 827 usize_t cpyoff_blkoff; /* offset of copy window in
778 blocks, remainder */ 828 blocks, remainder */
@@ -833,7 +883,7 @@ struct _xd3_stream
833 xd3_free_func *free; /* free function */ 883 xd3_free_func *free; /* free function */
834 void* opaque; /* private data object passed to 884 void* opaque; /* private data object passed to
835 alloc, free, and getblk */ 885 alloc, free, and getblk */
836 int flags; /* various options */ 886 uint32_t flags; /* various options */
837 887
838 /* secondary compressor configuration */ 888 /* secondary compressor configuration */
839 xd3_sec_cfg sec_data; /* Secondary compressor config: data */ 889 xd3_sec_cfg sec_data; /* Secondary compressor config: data */
@@ -931,13 +981,11 @@ struct _xd3_stream
931 981
932 usize_t dec_secondid; /* Optional secondary compressor ID. */ 982 usize_t dec_secondid; /* Optional secondary compressor ID. */
933 983
934 /* TODO: why decode breaks if this is usize_t? */ 984 usize_t dec_codetblsz; /* Optional code table: length. */
935 uint32_t dec_codetblsz; /* Optional code table: length. */
936 uint8_t *dec_codetbl; /* Optional code table: storage. */ 985 uint8_t *dec_codetbl; /* Optional code table: storage. */
937 usize_t dec_codetblbytes; /* Optional code table: position. */ 986 usize_t dec_codetblbytes; /* Optional code table: position. */
938 987
939 /* TODO: why decode breaks if this is usize_t? */ 988 usize_t dec_appheadsz; /* Optional application header:
940 uint32_t dec_appheadsz; /* Optional application header:
941 size. */ 989 size. */
942 uint8_t *dec_appheader; /* Optional application header: 990 uint8_t *dec_appheader; /* Optional application header:
943 storage */ 991 storage */
@@ -948,15 +996,12 @@ struct _xd3_stream
948 uint8_t dec_cksum[4]; /* Optional checksum: storage. */ 996 uint8_t dec_cksum[4]; /* Optional checksum: storage. */
949 uint32_t dec_adler32; /* Optional checksum: value. */ 997 uint32_t dec_adler32; /* Optional checksum: value. */
950 998
951 /* TODO: why decode breaks if this is usize_t? */ 999 usize_t dec_cpylen; /* length of copy window
952 uint32_t dec_cpylen; /* length of copy window
953 (VCD_SOURCE or VCD_TARGET) */ 1000 (VCD_SOURCE or VCD_TARGET) */
954 xoff_t dec_cpyoff; /* offset of copy window 1001 xoff_t dec_cpyoff; /* offset of copy window
955 (VCD_SOURCE or VCD_TARGET) */ 1002 (VCD_SOURCE or VCD_TARGET) */
956 /* TODO: why decode breaks if this is usize_t? */ 1003 usize_t dec_enclen; /* length of delta encoding */
957 uint32_t dec_enclen; /* length of delta encoding */ 1004 usize_t dec_tgtlen; /* length of target window */
958 /* TODO: why decode breaks if this is usize_t? */
959 uint32_t dec_tgtlen; /* length of target window */
960 1005
961#if USE_UINT64 1006#if USE_UINT64
962 uint64_t dec_64part; /* part of a decoded uint64_t */ 1007 uint64_t dec_64part; /* part of a decoded uint64_t */
@@ -1262,7 +1307,7 @@ const char* xd3_strerror (int ret);
1262 specified flags. */ 1307 specified flags. */
1263static inline 1308static inline
1264void xd3_init_config (xd3_config *config, 1309void xd3_init_config (xd3_config *config,
1265 int flags) 1310 uint32_t flags)
1266{ 1311{
1267 memset (config, 0, sizeof (*config)); 1312 memset (config, 0, sizeof (*config));
1268 config->flags = flags; 1313 config->flags = flags;
@@ -1325,7 +1370,7 @@ usize_t xd3_encoder_srclen (xd3_stream *stream) {
1325 1370
1326/* Checks for legal flag changes. */ 1371/* Checks for legal flag changes. */
1327static inline 1372static inline
1328void xd3_set_flags (xd3_stream *stream, int flags) 1373void xd3_set_flags (xd3_stream *stream, uint32_t flags)
1329{ 1374{
1330 /* The bitwise difference should contain only XD3_FLUSH or 1375 /* The bitwise difference should contain only XD3_FLUSH or
1331 XD3_SKIP_WINDOW */ 1376 XD3_SKIP_WINDOW */
@@ -1350,8 +1395,8 @@ void xd3_blksize_div (const xoff_t offset,
1350 const xd3_source *source, 1395 const xd3_source *source,
1351 xoff_t *blkno, 1396 xoff_t *blkno,
1352 usize_t *blkoff) { 1397 usize_t *blkoff) {
1353 *blkno = (xoff_t) (offset >> source->shiftby); 1398 *blkno = offset >> source->shiftby;
1354 *blkoff = (usize_t) (offset & source->maskby); 1399 *blkoff = offset & source->maskby;
1355 XD3_ASSERT (*blkoff < source->blksize); 1400 XD3_ASSERT (*blkoff < source->blksize);
1356} 1401}
1357 1402