summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xdelta3/xdelta3-blkcache.h13
-rw-r--r--xdelta3/xdelta3-internal.h2
-rw-r--r--xdelta3/xdelta3-main.h27
-rw-r--r--xdelta3/xdelta3.h2
-rwxr-xr-xxdelta3/xdelta3.vcxproj20
5 files changed, 51 insertions, 13 deletions
diff --git a/xdelta3/xdelta3-blkcache.h b/xdelta3/xdelta3-blkcache.h
index dcd4c06..36f8216 100644
--- a/xdelta3/xdelta3-blkcache.h
+++ b/xdelta3/xdelta3-blkcache.h
@@ -21,6 +21,8 @@
21/* TODO: This code is heavily revised from 3.0z but still needs major 21/* TODO: This code is heavily revised from 3.0z but still needs major
22 * refactoring. */ 22 * refactoring. */
23 23
24#include "xdelta3-internal.h"
25
24typedef struct _main_blklru main_blklru; 26typedef struct _main_blklru main_blklru;
25typedef struct _main_blklru_list main_blklru_list; 27typedef struct _main_blklru_list main_blklru_list;
26 28
@@ -38,8 +40,7 @@ struct _main_blklru
38 main_blklru_list link; 40 main_blklru_list link;
39}; 41};
40 42
41/* TODO: The value for MAX_LRU_SIZE has what significance? */ 43#define MAX_LRU_SIZE 32U
42#define MAX_LRU_SIZE 32U /* must be a power of 2 */
43#define XD3_MINSRCWINSZ (XD3_ALLOCSIZE * MAX_LRU_SIZE) 44#define XD3_MINSRCWINSZ (XD3_ALLOCSIZE * MAX_LRU_SIZE)
44 45
45XD3_MAKELIST(main_blklru_list,main_blklru,link); 46XD3_MAKELIST(main_blklru_list,main_blklru,link);
@@ -67,7 +68,7 @@ static void main_lru_cleanup (void)
67{ 68{
68 if (lru != NULL) 69 if (lru != NULL)
69 { 70 {
70 main_free (lru[0].blk); 71 main_buffree (lru[0].blk);
71 } 72 }
72 73
73 main_free (lru); 74 main_free (lru);
@@ -145,7 +146,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd,
145 memset (lru, 0, sizeof(lru[0]) * MAX_LRU_SIZE); 146 memset (lru, 0, sizeof(lru[0]) * MAX_LRU_SIZE);
146 147
147 /* Allocate the entire buffer. */ 148 /* Allocate the entire buffer. */
148 if ((lru[0].blk = (uint8_t*) main_malloc (option_srcwinsz)) == NULL) 149 if ((lru[0].blk = (uint8_t*) main_bufalloc (option_srcwinsz)) == NULL)
149 { 150 {
150 ret = ENOMEM; 151 ret = ENOMEM;
151 return ret; 152 return ret;
@@ -189,11 +190,11 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd,
189 if (!sfile->size_known || source_size > option_srcwinsz) 190 if (!sfile->size_known || source_size > option_srcwinsz)
190 { 191 {
191 /* Modify block 0, change blocksize. */ 192 /* Modify block 0, change blocksize. */
192 lru_size = MAX_LRU_SIZE; 193 blksize = option_srcwinsz / MAX_LRU_SIZE;
193 blksize = option_srcwinsz / MAX_LRU_SIZE; /* Power of 2 */
194 source->blksize = blksize; 194 source->blksize = blksize;
195 source->onblk = blksize; /* xd3 sets onblk */ 195 source->onblk = blksize; /* xd3 sets onblk */
196 lru[0].size = blksize; 196 lru[0].size = blksize;
197 lru_size = MAX_LRU_SIZE;
197 198
198 /* Setup rest of blocks. */ 199 /* Setup rest of blocks. */
199 for (i = 1; i < lru_size; i += 1) 200 for (i = 1; i < lru_size; i += 1)
diff --git a/xdelta3/xdelta3-internal.h b/xdelta3/xdelta3-internal.h
index 10ecb38..955a277 100644
--- a/xdelta3/xdelta3-internal.h
+++ b/xdelta3/xdelta3-internal.h
@@ -23,6 +23,8 @@
23typedef struct _main_file main_file; 23typedef struct _main_file main_file;
24typedef struct _main_extcomp main_extcomp; 24typedef struct _main_extcomp main_extcomp;
25 25
26void main_buffree (void *ptr);
27void* main_bufalloc (usize_t size);
26void main_file_init (main_file *xfile); 28void main_file_init (main_file *xfile);
27int main_file_close (main_file *xfile); 29int main_file_close (main_file *xfile);
28void main_file_cleanup (main_file *xfile); 30void main_file_cleanup (main_file *xfile);
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index dfac8b7..5b1efa9 100644
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -391,6 +391,7 @@ main_config (void)
391 XPR(NTR "XD3_HARDMAXWINSIZE=%d\n", XD3_HARDMAXWINSIZE); 391 XPR(NTR "XD3_HARDMAXWINSIZE=%d\n", XD3_HARDMAXWINSIZE);
392 XPR(NTR "sizeof(void*)=%d\n", (int)sizeof(void*)); 392 XPR(NTR "sizeof(void*)=%d\n", (int)sizeof(void*));
393 XPR(NTR "sizeof(int)=%d\n", (int)sizeof(int)); 393 XPR(NTR "sizeof(int)=%d\n", (int)sizeof(int));
394 XPR(NTR "sizeof(size_t)=%d\n", (int)sizeof(size_t));
394 XPR(NTR "sizeof(uint32_t)=%d\n", (int)sizeof(uint32_t)); 395 XPR(NTR "sizeof(uint32_t)=%d\n", (int)sizeof(uint32_t));
395 XPR(NTR "sizeof(uint64_t)=%d\n", (int)sizeof(uint64_t)); 396 XPR(NTR "sizeof(uint64_t)=%d\n", (int)sizeof(uint64_t));
396 XPR(NTR "sizeof(usize_t)=%d\n", (int)sizeof(usize_t)); 397 XPR(NTR "sizeof(usize_t)=%d\n", (int)sizeof(usize_t));
@@ -450,6 +451,14 @@ main_malloc1 (usize_t size)
450 return r; 451 return r;
451} 452}
452 453
454void* main_bufalloc (usize_t size) {
455#if XD3_WIN32
456 return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
457#else
458 return main_malloc1(size);
459#endif
460}
461
453static void* 462static void*
454main_malloc (usize_t size) 463main_malloc (usize_t size)
455{ 464{
@@ -484,6 +493,14 @@ main_free (void *ptr)
484 } 493 }
485} 494}
486 495
496void main_buffree (void *ptr) {
497#if XD3_WIN32
498 VirtualFree(ptr, 0, MEM_RELEASE);
499#else
500 main_free(ptr);
501#endif
502}
503
487/* This ensures that (ret = errno) always indicates failure, in case errno was 504/* This ensures that (ret = errno) always indicates failure, in case errno was
488 * accidentally not set. If this prints there's a bug somewhere. */ 505 * accidentally not set. If this prints there's a bug somewhere. */
489static int 506static int
@@ -1752,7 +1769,7 @@ main_merge_arguments (main_merge_list* merges)
1752 1769
1753 if (main_bdata != NULL) 1770 if (main_bdata != NULL)
1754 { 1771 {
1755 main_free (main_bdata); 1772 main_buffree (main_bdata);
1756 main_bdata = NULL; 1773 main_bdata = NULL;
1757 main_bsize = 0; 1774 main_bsize = 0;
1758 } 1775 }
@@ -1887,11 +1904,11 @@ main_merge_output (xd3_stream *stream, main_file *ofile)
1887 1904
1888 if (main_bsize < window_size) 1905 if (main_bsize < window_size)
1889 { 1906 {
1890 main_free (main_bdata); 1907 main_buffree (main_bdata);
1891 main_bdata = NULL; 1908 main_bdata = NULL;
1892 main_bsize = 0; 1909 main_bsize = 0;
1893 if ((main_bdata = (uint8_t*) 1910 if ((main_bdata = (uint8_t*)
1894 main_malloc (window_size)) == NULL) 1911 main_bufalloc (window_size)) == NULL)
1895 { 1912 {
1896 return ENOMEM; 1913 return ENOMEM;
1897 } 1914 }
@@ -3079,7 +3096,7 @@ main_input (xd3_cmd cmd,
3079 3096
3080 main_bsize = winsize = main_get_winsize (ifile); 3097 main_bsize = winsize = main_get_winsize (ifile);
3081 3098
3082 if ((main_bdata = (uint8_t*) main_malloc (winsize)) == NULL) 3099 if ((main_bdata = (uint8_t*) main_bufalloc (winsize)) == NULL)
3083 { 3100 {
3084 return EXIT_FAILURE; 3101 return EXIT_FAILURE;
3085 } 3102 }
@@ -3441,7 +3458,7 @@ main_cleanup (void)
3441 appheader_used = NULL; 3458 appheader_used = NULL;
3442 } 3459 }
3443 3460
3444 main_free (main_bdata); 3461 main_buffree (main_bdata);
3445 main_bdata = NULL; 3462 main_bdata = NULL;
3446 main_bsize = 0; 3463 main_bsize = 0;
3447 3464
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h
index 8a94729..6256961 100644
--- a/xdelta3/xdelta3.h
+++ b/xdelta3/xdelta3.h
@@ -29,7 +29,9 @@
29#define _ISOC99_SOURCE 29#define _ISOC99_SOURCE
30#define _C99_SOURCE 30#define _C99_SOURCE
31 31
32#if HAVE_CONFIG_H
32#include "config.h" 33#include "config.h"
34#endif
33 35
34#include <errno.h> 36#include <errno.h>
35#include <stdarg.h> 37#include <stdarg.h>
diff --git a/xdelta3/xdelta3.vcxproj b/xdelta3/xdelta3.vcxproj
index 6b82af7..8d4464b 100755
--- a/xdelta3/xdelta3.vcxproj
+++ b/xdelta3/xdelta3.vcxproj
@@ -16,6 +16,22 @@
16 <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/DXD3_DEBUG=0 /DXD3_USE_LARGEFILE64=1 /DREGRESSION_TEST=1 /DSECONDARY_DJW=1 /DSECONDARY_FGK=1 /DXD3_MAIN=1 /DXD3_WIN32=1 /DEXTERNAL_COMPRESSION=0 /DXD3_STDIO=0 /DXD3_POSIX=0;%(PreprocessorDefinitions)</PreprocessorDefinitions> 16 <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/DXD3_DEBUG=0 /DXD3_USE_LARGEFILE64=1 /DREGRESSION_TEST=1 /DSECONDARY_DJW=1 /DSECONDARY_FGK=1 /DXD3_MAIN=1 /DXD3_WIN32=1 /DEXTERNAL_COMPRESSION=0 /DXD3_STDIO=0 /DXD3_POSIX=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
17 </ClCompile> 17 </ClCompile>
18 </ItemGroup> 18 </ItemGroup>
19 <ItemGroup>
20 <ClInclude Include="xdelta3-blkcache.h" />
21 <ClInclude Include="xdelta3-cfgs.h" />
22 <ClInclude Include="xdelta3-decode.h" />
23 <ClInclude Include="xdelta3-djw.h" />
24 <ClInclude Include="xdelta3-fgk.h" />
25 <ClInclude Include="xdelta3-hash.h" />
26 <ClInclude Include="xdelta3-internal.h" />
27 <ClInclude Include="xdelta3-list.h" />
28 <ClInclude Include="xdelta3-lzma.h" />
29 <ClInclude Include="xdelta3-main.h" />
30 <ClInclude Include="xdelta3-merge.h" />
31 <ClInclude Include="xdelta3-second.h" />
32 <ClInclude Include="xdelta3-test.h" />
33 <ClInclude Include="xdelta3.h" />
34 </ItemGroup>
19 <PropertyGroup Label="Globals"> 35 <PropertyGroup Label="Globals">
20 <ProjectGuid>{8F9D37B5-B78E-4816-BE61-AEF679DBF3BC}</ProjectGuid> 36 <ProjectGuid>{8F9D37B5-B78E-4816-BE61-AEF679DBF3BC}</ProjectGuid>
21 <Keyword>Win32Proj</Keyword> 37 <Keyword>Win32Proj</Keyword>
@@ -25,13 +41,13 @@
25 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> 41 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
26 <ConfigurationType>Application</ConfigurationType> 42 <ConfigurationType>Application</ConfigurationType>
27 <UseDebugLibraries>true</UseDebugLibraries> 43 <UseDebugLibraries>true</UseDebugLibraries>
28 <CharacterSet>Unicode</CharacterSet> 44 <CharacterSet>MultiByte</CharacterSet>
29 </PropertyGroup> 45 </PropertyGroup>
30 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> 46 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
31 <ConfigurationType>Application</ConfigurationType> 47 <ConfigurationType>Application</ConfigurationType>
32 <UseDebugLibraries>false</UseDebugLibraries> 48 <UseDebugLibraries>false</UseDebugLibraries>
33 <WholeProgramOptimization>true</WholeProgramOptimization> 49 <WholeProgramOptimization>true</WholeProgramOptimization>
34 <CharacterSet>Unicode</CharacterSet> 50 <CharacterSet>MultiByte</CharacterSet>
35 </PropertyGroup> 51 </PropertyGroup>
36 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> 52 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
37 <ImportGroup Label="ExtensionSettings"> 53 <ImportGroup Label="ExtensionSettings">