Bug 1418425 - Update bsdiff to use libz instead of bz2 for the crc algo r=andi,glandium
authorSylvestre Ledru <sledru@mozilla.com>
Fri, 12 Jan 2018 16:13:45 +0100
changeset 453347 47fbcaf5ad059616de22219b12223b798b6b758f
parent 453346 142001babb39d7cce8b88a2103ba8863fce685ad
child 453348 2e95ebdcae6d37cc1b3c3f220b05210f419aea64
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersandi, glandium
bugs1418425
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1418425 - Update bsdiff to use libz instead of bz2 for the crc algo r=andi,glandium MozReview-Commit-ID: 2GLmnzF9CMh
other-licenses/bsdiff/bsdiff.c
other-licenses/bsdiff/moz.build
--- a/other-licenses/bsdiff/bsdiff.c
+++ b/other-licenses/bsdiff/bsdiff.c
@@ -9,16 +9,19 @@
 
   ChangeLog:
   2005-05-05 - Use the modified header struct from bspatch.h; use 32-bit
                values throughout.
                  --Benjamin Smedberg <benjamin@smedbergs.us>
   2005-05-18 - Use the same CRC algorithm as bzip2, and leverage the CRC table
                provided by libbz2.
                  --Darin Fisher <darin@meer.net>
+  2017-11-25 - Use zlib instead of bz2 for the CRC function
+                 --Sylvestre Ledru <s@mozilla.com>
+
 */
 
 #include "bspatch.h"
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <fcntl.h>
@@ -26,39 +29,20 @@
 #ifdef XP_WIN
 #include <io.h>
 #include <winsock2.h>
 #else
 #include <unistd.h>
 #include <arpa/inet.h>
 #define _O_BINARY 0
 #endif
-
 #undef MIN
 #define MIN(x,y) (((x)<(y)) ? (x) : (y))
 
-/*---------------------------------------------------------------------------*/
-
-/* This variable lives in libbz2.  It's declared in bzlib_private.h, so we just
- * declare it here to avoid including that entire header file.
- */
-extern unsigned int BZ2_crc32Table[256];
-
-static unsigned int
-crc32(const unsigned char *buf, unsigned int len)
-{
-	unsigned int crc = 0xffffffffL;
-
-	const unsigned char *end = buf + len;
-	for (; buf != end; ++buf)
-		crc = (crc << 8) ^ BZ2_crc32Table[(crc >> 24) ^ *buf];
-
-	crc = ~crc;
-	return crc;
-}
+#include "zlib.h"
 
 /*---------------------------------------------------------------------------*/
 
 static void
 reporterr(int e, const char *fmt, ...)
 {
 	if (fmt) {
 		va_list args;
@@ -222,17 +206,17 @@ int main(int argc,char *argv[])
 
 	int32_t s,Sf,lenf,Sb,lenb;
 	int32_t overlap,Ss,lens;
 	int32_t i;
 
 	int32_t dblen,eblen;
 	unsigned char *db,*eb;
 
-	unsigned int scrc;
+	unsigned int scrc = crc32(0L, Z_NULL, 0);
 
 	MBSPatchHeader header = {
 		{'M','B','D','I','F','F','1','0'},
 		0, 0, 0, 0, 0, 0
 	};
 
 	uint32_t numtriples;
 
@@ -244,17 +228,17 @@ int main(int argc,char *argv[])
 	if(((fd=open(argv[1],O_RDONLY|_O_BINARY,0))<0) ||
 		((oldsize=lseek(fd,0,SEEK_END))==-1) ||
 		((old=(unsigned char*) malloc(oldsize+1))==NULL) ||
 		(lseek(fd,0,SEEK_SET)!=0) ||
 		(read(fd,old,oldsize)!=oldsize) ||
 		(close(fd)==-1))
 		reporterr(1,"%s\n",argv[1]);
 
-	scrc = crc32(old, oldsize);
+        scrc = crc32(scrc, old, oldsize);
 
 	if(((I=(int32_t*) malloc((oldsize+1)*sizeof(int32_t)))==NULL) ||
 		((V=(int32_t*) malloc((oldsize+1)*sizeof(int32_t)))==NULL))
 		reporterr(1,NULL);
 
 	qsufsort(I,V,old,oldsize);
 
 	free(V);
--- a/other-licenses/bsdiff/moz.build
+++ b/other-licenses/bsdiff/moz.build
@@ -5,26 +5,26 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 HOST_SOURCES += [
     'bsdiff.c',
 ]
 
 HostProgram('mbsdiff')
 
-if CONFIG['MOZ_SYSTEM_BZ2']:
-    HOST_OS_LIBS += CONFIG['MOZ_BZ2_LIBS']
-else:
-    HOST_USE_LIBS += [
-        'hostbz2',
-    ]
-
 if CONFIG['HOST_OS_ARCH'] == 'WINNT':
     HOST_OS_LIBS += [
         'ws2_32',
+        'vcruntime',
     ]
     USE_STATIC_LIBS = True
 
 LOCAL_INCLUDES += [
     '/toolkit/mozapps/update/updater',
 ]
 
-HOST_CXXFLAGS += CONFIG['MOZ_BZ2_CFLAGS']
+if CONFIG['MOZ_SYSTEM_ZLIB']:
+    HOST_CFLAGS += CONFIG['MOZ_ZLIB_CFLAGS']
+    HOST_OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
+else:
+    LOCAL_INCLUDES += ['/modules/zlib/src']
+    HOST_USE_LIBS += ['hostzlib']
+