diff options
author | Joshua MacDonald <josh.macdonald@gmail.com> | 2015-12-29 22:20:25 -0800 |
---|---|---|
committer | Joshua MacDonald <josh.macdonald@gmail.com> | 2015-12-29 22:20:25 -0800 |
commit | 259cf80fb6caba7c2688adeeb5b0092c3959becd (patch) | |
tree | 21941cb4869f89866585316ede67fe291d1f8a54 | |
parent | ec9905aa755eafb64f08fc59ca7e67ea57498264 (diff) |
Build on Darwin. Replace xd3_(read|decode|sizeof|emit)_(size|offset) macros w/ functions.
-rw-r--r-- | xdelta3/testing/checksum_test.cc | 11 | ||||
-rw-r--r-- | xdelta3/xdelta3-decode.h | 1 | ||||
-rw-r--r-- | xdelta3/xdelta3-internal.h | 62 | ||||
-rw-r--r-- | xdelta3/xdelta3.h | 14 |
4 files changed, 60 insertions, 28 deletions
diff --git a/xdelta3/testing/checksum_test.cc b/xdelta3/testing/checksum_test.cc index c508753..897b913 100644 --- a/xdelta3/testing/checksum_test.cc +++ b/xdelta3/testing/checksum_test.cc | |||
@@ -59,6 +59,11 @@ usize_t bitsof<uint64_t>() { | |||
59 | return 64; | 59 | return 64; |
60 | } | 60 | } |
61 | 61 | ||
62 | template<> | ||
63 | usize_t bitsof<usize_t>() { | ||
64 | return sizeof(usize_t) * 8; | ||
65 | } | ||
66 | |||
62 | template <typename Word> | 67 | template <typename Word> |
63 | struct hhash { // shift "s" bits leaving the high bits as a hash value for | 68 | struct hhash { // shift "s" bits leaving the high bits as a hash value for |
64 | // this checksum, which are the most "distant" in terms of the | 69 | // this checksum, which are the most "distant" in terms of the |
@@ -448,12 +453,12 @@ struct test_result : public test_result_base { | |||
448 | 453 | ||
449 | void print() { | 454 | void print() { |
450 | if (fstats.count != count()) { | 455 | if (fstats.count != count()) { |
451 | fprintf(stderr, "internal error: %d != %d\n", fstats.count, count()); | 456 | fprintf(stderr, "internal error: %" W "d != %" W "d\n", fstats.count, count()); |
452 | abort(); | 457 | abort(); |
453 | } | 458 | } |
454 | print_header(); | 459 | print_header(); |
455 | printf("%-32s%d/%d 2^%" Z "\t%" Z "\t%0.4f\t%.4f\t%.4f\t%.1e\t%.2f\t" | 460 | printf("%-32s%d/%d 2^%" Z "u\t%" Z "u\t%0.4f\t%.4f\t%.4f\t%.1e\t%.2f\t" |
456 | "%" Z "\t%" Z "\n", | 461 | "%" Z "u\t%" Z "u\n", |
457 | test_name, | 462 | test_name, |
458 | Checksum::cksum_size, | 463 | Checksum::cksum_size, |
459 | Checksum::cksum_skip, | 464 | Checksum::cksum_skip, |
diff --git a/xdelta3/xdelta3-decode.h b/xdelta3/xdelta3-decode.h index 0cb8857..e71b624 100644 --- a/xdelta3/xdelta3-decode.h +++ b/xdelta3/xdelta3-decode.h | |||
@@ -1026,7 +1026,6 @@ xd3_decode_input (xd3_stream *stream) | |||
1026 | 1026 | ||
1027 | case DEC_CPYOFF: | 1027 | case DEC_CPYOFF: |
1028 | /* Copy window offset: only if VCD_SOURCE or VCD_TARGET is set */ | 1028 | /* Copy window offset: only if VCD_SOURCE or VCD_TARGET is set */ |
1029 | |||
1030 | OFFSET_CASE(SRCORTGT (stream->dec_win_ind), stream->dec_cpyoff, | 1029 | OFFSET_CASE(SRCORTGT (stream->dec_win_ind), stream->dec_cpyoff, |
1031 | DEC_ENCLEN); | 1030 | DEC_ENCLEN); |
1032 | 1031 | ||
diff --git a/xdelta3/xdelta3-internal.h b/xdelta3/xdelta3-internal.h index d54584d..e9fc5f3 100644 --- a/xdelta3/xdelta3-internal.h +++ b/xdelta3/xdelta3-internal.h | |||
@@ -301,7 +301,7 @@ xd3_emit_uint32_t (xd3_stream *stream, xd3_output **output, uint32_t num) | |||
301 | #endif /* USE_UINT32 */ | 301 | #endif /* USE_UINT32 */ |
302 | 302 | ||
303 | #if USE_UINT64 | 303 | #if USE_UINT64 |
304 | static uint32_t | 304 | static inline uint32_t |
305 | xd3_sizeof_uint64_t (uint64_t num) | 305 | xd3_sizeof_uint64_t (uint64_t num) |
306 | { | 306 | { |
307 | IF_SIZEOF64(1); | 307 | IF_SIZEOF64(1); |
@@ -321,7 +321,7 @@ static inline int | |||
321 | xd3_decode_uint64_t (xd3_stream *stream, uint64_t *val) | 321 | xd3_decode_uint64_t (xd3_stream *stream, uint64_t *val) |
322 | { DECODE_INTEGER_TYPE (stream->dec_64part, UINT64_OFLOW_MASK); } | 322 | { DECODE_INTEGER_TYPE (stream->dec_64part, UINT64_OFLOW_MASK); } |
323 | 323 | ||
324 | static int | 324 | static inline int |
325 | xd3_read_uint64_t (xd3_stream *stream, const uint8_t **inpp, | 325 | xd3_read_uint64_t (xd3_stream *stream, const uint8_t **inpp, |
326 | const uint8_t *maxp, uint64_t *valp) | 326 | const uint8_t *maxp, uint64_t *valp) |
327 | { READ_INTEGER_TYPE (uint64_t, UINT64_OFLOW_MASK); } | 327 | { READ_INTEGER_TYPE (uint64_t, UINT64_OFLOW_MASK); } |
@@ -336,35 +336,65 @@ xd3_emit_uint64_t (xd3_stream *stream, xd3_output **output, uint64_t num) | |||
336 | #if SIZEOF_USIZE_T == 4 | 336 | #if SIZEOF_USIZE_T == 4 |
337 | #define USIZE_T_MAX UINT32_MAX | 337 | #define USIZE_T_MAX UINT32_MAX |
338 | #define USIZE_T_MAXBLKSZ 0x80000000U | 338 | #define USIZE_T_MAXBLKSZ 0x80000000U |
339 | #define xd3_decode_size xd3_decode_uint32_t | 339 | #define XD3_MAXSRCWINSZ (1ULL << 31) |
340 | #define xd3_emit_size xd3_emit_uint32_t | ||
341 | #define xd3_sizeof_size xd3_sizeof_uint32_t | ||
342 | #define xd3_read_size xd3_read_uint32_t | ||
343 | #define xd3_large_cksum xd3_large32_cksum | 340 | #define xd3_large_cksum xd3_large32_cksum |
344 | #define xd3_large_cksum_update xd3_large32_cksum_update | 341 | #define xd3_large_cksum_update xd3_large32_cksum_update |
345 | #define xd3_hash_multiplier xd3_hash_multiplier32 | 342 | #define xd3_hash_multiplier xd3_hash_multiplier32 |
346 | #define XD3_MAXSRCWINSZ (1ULL << 31) | 343 | |
344 | static inline uint32_t xd3_sizeof_size (usize_t num) | ||
345 | { return xd3_sizeof_uint32_t (num); } | ||
346 | static inline int xd3_decode_size (xd3_stream *stream, usize_t *valp) | ||
347 | { return xd3_decode_uint32_t (stream, (uint32_t*) valp); } | ||
348 | static inline int xd3_read_size (xd3_stream *stream, const uint8_t **inpp, | ||
349 | const uint8_t *maxp, usize_t *valp) | ||
350 | { return xd3_read_uint32_t (stream, inpp, maxp, (uint32_t*) valp); } | ||
351 | #if XD3_ENCODER | ||
352 | static inline int xd3_emit_size (xd3_stream *stream, xd3_output **output, usize_t num) | ||
353 | { return xd3_emit_uint32_t (stream, output, num); } | ||
354 | #endif | ||
355 | |||
347 | #elif SIZEOF_USIZE_T == 8 | 356 | #elif SIZEOF_USIZE_T == 8 |
348 | #define USIZE_T_MAX UINT64_MAX | 357 | #define USIZE_T_MAX UINT64_MAX |
349 | #define USIZE_T_MAXBLKSZ 0x8000000000000000ULL | 358 | #define USIZE_T_MAXBLKSZ 0x8000000000000000ULL |
350 | #define xd3_decode_size xd3_decode_uint64_t | 359 | #define XD3_MAXSRCWINSZ (1ULL << 61) |
351 | #define xd3_emit_size xd3_emit_uint64_t | ||
352 | #define xd3_sizeof_size xd3_sizeof_uint64_t | ||
353 | #define xd3_read_size xd3_read_uint64_t | ||
354 | #define xd3_large_cksum xd3_large64_cksum | 360 | #define xd3_large_cksum xd3_large64_cksum |
355 | #define xd3_large_cksum_update xd3_large64_cksum_update | 361 | #define xd3_large_cksum_update xd3_large64_cksum_update |
356 | #define xd3_hash_multiplier xd3_hash_multiplier64 | 362 | #define xd3_hash_multiplier xd3_hash_multiplier64 |
357 | #define XD3_MAXSRCWINSZ (1ULL << 61) | 363 | |
364 | static inline uint32_t xd3_sizeof_size (usize_t num) | ||
365 | { return xd3_sizeof_uint64_t (num); } | ||
366 | static inline int xd3_decode_size (xd3_stream *stream, usize_t *valp) | ||
367 | { return xd3_decode_uint64_t (stream, (uint64_t*) valp); } | ||
368 | static inline int xd3_read_size (xd3_stream *stream, const uint8_t **inpp, | ||
369 | const uint8_t *maxp, usize_t *valp) | ||
370 | { return xd3_read_uint64_t (stream, inpp, maxp, (uint64_t*) valp); } | ||
371 | #if XD3_ENCODER | ||
372 | static inline int xd3_emit_size (xd3_stream *stream, xd3_output **output, usize_t num) | ||
373 | { return xd3_emit_uint64_t (stream, output, num); } | ||
374 | #endif | ||
375 | |||
358 | #endif /* SIZEOF_USIZE_T */ | 376 | #endif /* SIZEOF_USIZE_T */ |
359 | 377 | ||
360 | #if SIZEOF_XOFF_T == 4 | 378 | #if SIZEOF_XOFF_T == 4 |
361 | #define XOFF_T_MAX UINT32_MAX | 379 | #define XOFF_T_MAX UINT32_MAX |
362 | #define xd3_decode_offset xd3_decode_uint32_t | 380 | |
363 | #define xd3_emit_offset xd3_emit_uint32_t | 381 | static inline int xd3_decode_offset (xd3_stream *stream, xoff_t *valp) |
382 | { return xd3_decode_uint32_t (stream, (uint32_t*) valp); } | ||
383 | #if XD3_ENCODER | ||
384 | static inline int xd3_emit_offset (xd3_stream *stream, xd3_output **output, xoff_t num) | ||
385 | { return xd3_emit_uint32_t (stream, output, num); } | ||
386 | #endif | ||
387 | |||
364 | #elif SIZEOF_XOFF_T == 8 | 388 | #elif SIZEOF_XOFF_T == 8 |
365 | #define XOFF_T_MAX UINT64_MAX | 389 | #define XOFF_T_MAX UINT64_MAX |
366 | #define xd3_decode_offset xd3_decode_uint64_t | 390 | |
367 | #define xd3_emit_offset xd3_emit_uint64_t | 391 | static inline int xd3_decode_offset (xd3_stream *stream, xoff_t *valp) |
392 | { return xd3_decode_uint64_t (stream, (uint64_t*) valp); } | ||
393 | #if XD3_ENCODER | ||
394 | static inline int xd3_emit_offset (xd3_stream *stream, xd3_output **output, xoff_t num) | ||
395 | { return xd3_emit_uint64_t (stream, output, num); } | ||
396 | #endif | ||
397 | |||
368 | #endif | 398 | #endif |
369 | 399 | ||
370 | #define USIZE_T_OVERFLOW(a,b) ((USIZE_T_MAX - (usize_t) (a)) < (usize_t) (b)) | 400 | #define USIZE_T_OVERFLOW(a,b) ((USIZE_T_MAX - (usize_t) (a)) < (usize_t) (b)) |
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h index f00f887..1b134eb 100644 --- a/xdelta3/xdelta3.h +++ b/xdelta3/xdelta3.h | |||
@@ -122,13 +122,11 @@ | |||
122 | 122 | ||
123 | #ifndef WINVER | 123 | #ifndef WINVER |
124 | #if XD3_USE_LARGEFILE64 | 124 | #if XD3_USE_LARGEFILE64 |
125 | /* 64 bit file offsets: uses GetFileSizeEx and SetFilePointerEx. | 125 | /* 64 bit file offsets: uses GetFileSizeEx and SetFilePointerEx. */ |
126 | * requires Win2000 or newer version of WinNT */ | ||
127 | #define WINVER 0x0500 | 126 | #define WINVER 0x0500 |
128 | #define _WIN32_WINNT 0x0500 | 127 | #define _WIN32_WINNT 0x0500 |
129 | #else /* xoff_t is 32bit */ | 128 | #else /* xoff_t is 32bit */ |
130 | /* 32 bit (DWORD) file offsets: uses GetFileSize and | 129 | /* 32 bit file offsets: uses GetFileSize and SetFilePointer. */ |
131 | * SetFilePointer. compatible with win9x-me and WinNT4 */ | ||
132 | #define WINVER 0x0400 | 130 | #define WINVER 0x0400 |
133 | #define _WIN32_WINNT 0x0400 | 131 | #define _WIN32_WINNT 0x0400 |
134 | #endif /* if XD3_USE_LARGEFILE64 */ | 132 | #endif /* if XD3_USE_LARGEFILE64 */ |
@@ -136,9 +134,8 @@ | |||
136 | 134 | ||
137 | #include <windows.h> | 135 | #include <windows.h> |
138 | 136 | ||
139 | /* _MSV_VER is defined by Microsoft tools, not by mingw32 */ | 137 | /* _MSV_VER is defined by Microsoft tools, not by Mingw32 */ |
140 | #ifdef _MSC_VER | 138 | #ifdef _MSC_VER |
141 | /*#define inline*/ | ||
142 | typedef signed int ssize_t; | 139 | typedef signed int ssize_t; |
143 | #if _MSC_VER < 1600 | 140 | #if _MSC_VER < 1600 |
144 | typedef unsigned char uint8_t; | 141 | typedef unsigned char uint8_t; |
@@ -150,15 +147,16 @@ typedef ULONGLONG uint64_t; | |||
150 | #include <stdint.h> | 147 | #include <stdint.h> |
151 | #endif /* _MSC_VER < 1600 */ | 148 | #endif /* _MSC_VER < 1600 */ |
152 | #else /* _MSC_VER not defined */ | 149 | #else /* _MSC_VER not defined */ |
153 | /* mingw32, lcc and watcom provide a proper header */ | 150 | /* Mingw32 */ |
154 | #include <stdint.h> | 151 | #include <stdint.h> |
155 | #endif /* _MSC_VER defined */ | 152 | #endif /* _MSC_VER defined */ |
153 | |||
156 | #endif /* _WIN32 defined */ | 154 | #endif /* _WIN32 defined */ |
157 | 155 | ||
158 | /* Settings based on the size of xoff_t (32 vs 64 file offsets) */ | 156 | /* Settings based on the size of xoff_t (32 vs 64 file offsets) */ |
159 | #if XD3_USE_LARGEFILE64 | 157 | #if XD3_USE_LARGEFILE64 |
160 | /* xoff_t is a 64-bit type */ | 158 | /* xoff_t is a 64-bit type */ |
161 | #define __USE_FILE_OFFSET64 1 /* GLIBC: for 64bit fileops, ... ? */ | 159 | #define __USE_FILE_OFFSET64 1 /* GLIBC: for 64bit fileops. */ |
162 | 160 | ||
163 | #ifndef _LARGEFILE_SOURCE | 161 | #ifndef _LARGEFILE_SOURCE |
164 | #define _LARGEFILE_SOURCE | 162 | #define _LARGEFILE_SOURCE |