diff --git a/core/zip/CMakeLists.txt b/core/zip/CMakeLists.txt index 57dfaf187166a..89daf20e58ec4 100644 --- a/core/zip/CMakeLists.txt +++ b/core/zip/CMakeLists.txt @@ -5,12 +5,8 @@ # of the core subdirectory. Set(ZipOldHeaders - ${CMAKE_CURRENT_SOURCE_DIR}/inc/Bits.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/Tailor.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/ZDeflate.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/ZIP.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/ZTrees.h ${CMAKE_CURRENT_SOURCE_DIR}/inc/Compression.h + ${CMAKE_CURRENT_SOURCE_DIR}/inc/RZip.h ) Set(ZipOldSource @@ -18,20 +14,6 @@ Set(ZipOldSource ${CMAKE_CURRENT_SOURCE_DIR}/src/ZInflate.c ) -Set(ZipNewHeaders - ${CMAKE_CURRENT_SOURCE_DIR}/inc/crc32.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/deflate.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/inffast.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/inffixed.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/inflate.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/inftrees.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/trees.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/zconf.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/zlib.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/gzguts.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/zutil.h -) - Set(ZipNewSource ${CMAKE_CURRENT_SOURCE_DIR}/src/adler32.c ${CMAKE_CURRENT_SOURCE_DIR}/src/compress.c @@ -53,11 +35,11 @@ Set(ZipNewSource # Depending on the system either the old and the new # or only the old compression is build if(builtin_zlib) - set(ZLIB_HEADERS ${ZipNewHeaders} ${ZipOldHeaders}) - set(ZLIB_SRCS ${ZipNewSource} ${ZipOldSource} ${CMAKE_CURRENT_SOURCE_DIR}/src/Compression.cxx) + set(ZLIB_HEADERS ${ZipOldHeaders}) + set(ZLIB_SRCS ${ZipNewSource} ${ZipOldSource} ${CMAKE_CURRENT_SOURCE_DIR}/src/Compression.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/RZip.cxx) else() set(ZLIB_HEADERS ${ZipOldHeaders}) - set(ZLIB_SRCS ${ZipOldSource} ${CMAKE_CURRENT_SOURCE_DIR}/src/Compression.cxx) + set(ZLIB_SRCS ${ZipOldSource} ${CMAKE_CURRENT_SOURCE_DIR}/src/Compression.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/RZip.cxx) endif() # Define all the header files which should be installed when diff --git a/core/zip/Module.mk b/core/zip/Module.mk index 98765b750c22e..ac28af6d9bbe7 100644 --- a/core/zip/Module.mk +++ b/core/zip/Module.mk @@ -19,28 +19,12 @@ ZIPDO := $(ZIPDS:.cxx=.o) ZIPDH := $(ZIPDS:.cxx=.h) ZIPDICTH := $(MODDIRI)/Compression.h -ZIPOLDH := $(MODDIRI)/Bits.h \ - $(MODDIRI)/Tailor.h \ - $(MODDIRI)/ZDeflate.h \ - $(MODDIRI)/ZIP.h \ - $(MODDIRI)/ZTrees.h \ - $(MODDIRI)/Compression.h +ZIPOLDH := $(MODDIRI)/Compression.h \ + $(MODDIRI)/RZip.h ZIPOLDS := $(MODDIRS)/ZDeflate.c \ $(MODDIRS)/ZInflate.c -ZIPNEWH := $(MODDIRI)/crc32.h \ - $(MODDIRI)/deflate.h \ - $(MODDIRI)/inffast.h \ - $(MODDIRI)/inffixed.h \ - $(MODDIRI)/inflate.h \ - $(MODDIRI)/inftrees.h \ - $(MODDIRI)/trees.h \ - $(MODDIRI)/zconf.h \ - $(MODDIRI)/zlib.h \ - $(MODDIRI)/gzguts.h \ - $(MODDIRI)/zutil.h - ZIPNEWS := $(MODDIRS)/adler32.c \ $(MODDIRS)/compress.c \ $(MODDIRS)/crc32.c \ @@ -56,14 +40,18 @@ ZIPNEWS := $(MODDIRS)/adler32.c \ $(MODDIRS)/trees.c \ $(MODDIRS)/uncompr.c \ $(MODDIRS)/zutil.c + ifeq ($(BUILTINZLIB),yes) -ZIPH := $(ZIPOLDH) $(ZIPNEWH) +ZIPH := $(ZIPOLDH) ZIPS := $(ZIPOLDS) $(ZIPNEWS) else ZIPH := $(ZIPOLDH) ZIPS := $(ZIPOLDS) endif -ZIPS1 := $(MODDIRS)/Compression.cxx + +ZIPS1 := $(MODDIRS)/Compression.cxx \ + $(MODDIRS)/RZip.cxx + ZIPO := $(call stripsrc,$(ZIPS:.c=.o) $(ZIPS1:.cxx=.o)) ZIPDEP := $(ZIPO:.o=.d) $(ZIPDO:.o=.d) @@ -79,6 +67,9 @@ INCLUDEFILES += $(ZIPDEP) include/%.h: $(ZIPDIRI)/%.h cp $< $@ +$(ZIPO) : CFLAGS += -I$(ZIPDIRI) +$(ZIPO) : CXXFLAGS += -I$(ZIPDIRI) + $(ZIPDS): $(ZIPDICTH) $(ZIPL) $(ROOTCINTTMPDEP) $(MAKEDIR) @echo "Generating dictionary $@..." @@ -95,3 +86,4 @@ distclean-$(MODNAME): clean-$(MODNAME) @rm -f $(ZIPDEP) $(ZIPDS) $(ZIPDH) distclean:: distclean-$(MODNAME) + \ No newline at end of file diff --git a/core/zip/inc/RZip.h b/core/zip/inc/RZip.h new file mode 100644 index 0000000000000..6ab2c68d25739 --- /dev/null +++ b/core/zip/inc/RZip.h @@ -0,0 +1,29 @@ +// @(#)root/zip:$Id$ +// Author: Sergey Linev 7 July 2014 + +/************************************************************************* + * Copyright (C) 1995-2014, Rene Brun and Fons Rademakers. * + * All rights reserved. * + * * + * For the licensing terms see $ROOTSYS/LICENSE. * + * For the list of contributors see $ROOTSYS/README/CREDITS. * + *************************************************************************/ + +#ifndef ROOT_RZip +#define ROOT_RZip + +extern "C" unsigned long R__crc32(unsigned long crc, const unsigned char* buf, unsigned int len); + +extern "C" unsigned long R__memcompress(char *tgt, unsigned long tgtsize, char *src, unsigned long srcsize); + +extern "C" void R__zipMultipleAlgorithm(int cxlevel, int *srcsize, char *src, int *tgtsize, char *tgt, int *irep, int compressionAlgorithm); + +extern "C" void R__zip(int cxlevel, int *srcsize, char *src, int *tgtsize, char *tgt, int *irep); + +extern "C" void R__unzip(int *srcsize, unsigned char *src, int *tgtsize, unsigned char *tgt, int *irep); + +extern "C" int R__unzip_header(int *srcsize, unsigned char *src, int *tgtsize); + +enum { kMAXZIPBUF = 0xffffff }; + +#endif diff --git a/core/zip/src/RZip.cxx b/core/zip/src/RZip.cxx new file mode 100644 index 0000000000000..4d284515eba98 --- /dev/null +++ b/core/zip/src/RZip.cxx @@ -0,0 +1,19 @@ +// @(#)root/zip:$Id$ +// Author: Sergey Linev 7 July 2014 + +/************************************************************************* + * Copyright (C) 1995-2014, Rene Brun and Fons Rademakers. * + * All rights reserved. * + * * + * For the licensing terms see $ROOTSYS/LICENSE. * + * For the list of contributors see $ROOTSYS/README/CREDITS. * + *************************************************************************/ + +#include "RZip.h" + +#include "zlib.h" + +unsigned long R__crc32(unsigned long crc, const unsigned char* buf, unsigned int len) +{ + return crc32(crc, buf, len); +} diff --git a/io/io/src/TKey.cxx b/io/io/src/TKey.cxx index 6045c2d8fcde5..0e5a7aa4d2d76 100644 --- a/io/io/src/TKey.cxx +++ b/io/io/src/TKey.cxx @@ -61,10 +61,8 @@ #include "TVirtualStreamerInfo.h" #include "TSchemaRuleSet.h" -extern "C" void R__zipMultipleAlgorithm(int cxlevel, int *srcsize, char *src, int *tgtsize, char *tgt, int *irep, int compressionAlgorithm); -extern "C" void R__unzip(Int_t *nin, UChar_t *bufin, Int_t *lout, char *bufout, Int_t *nout); -extern "C" int R__unzip_header(Int_t *nin, UChar_t *bufin, Int_t *lout); -const Int_t kMAXBUF = 0xffffff; +#include "RZip.h" + const Int_t kTitleMax = 32000; #if 0 const Int_t kMAXFILEBUFFER = 262144; @@ -251,7 +249,7 @@ TKey::TKey(const TObject *obj, const char *name, Int_t bufsize, TDirectory* moth Int_t cxlevel = GetFile() ? GetFile()->GetCompressionLevel() : 0; Int_t cxAlgorithm = GetFile() ? GetFile()->GetCompressionAlgorithm() : 0; if (cxlevel > 0 && fObjlen > 256) { - Int_t nbuffers = 1 + (fObjlen - 1)/kMAXBUF; + Int_t nbuffers = 1 + (fObjlen - 1)/kMAXZIPBUF; Int_t buflen = TMath::Max(512,fKeylen + fObjlen + 9*nbuffers + 28); //add 28 bytes in case object is placed in a deleted gap fBuffer = new char[buflen]; char *objbuf = fBufferRef->Buffer() + fKeylen; @@ -260,7 +258,7 @@ TKey::TKey(const TObject *obj, const char *name, Int_t bufsize, TDirectory* moth nzip = 0; for (Int_t i = 0; i < nbuffers; ++i) { if (i == nbuffers - 1) bufmax = fObjlen - nzip; - else bufmax = kMAXBUF; + else bufmax = kMAXZIPBUF; R__zipMultipleAlgorithm(cxlevel, &bufmax, objbuf, &bufmax, bufcur, &nout, cxAlgorithm); if (nout == 0 || nout >= fObjlen) { //this happens when the buffer cannot be compressed fBuffer = fBufferRef->Buffer(); @@ -271,8 +269,8 @@ TKey::TKey(const TObject *obj, const char *name, Int_t bufsize, TDirectory* moth } bufcur += nout; noutot += nout; - objbuf += kMAXBUF; - nzip += kMAXBUF; + objbuf += kMAXZIPBUF; + nzip += kMAXZIPBUF; } Create(noutot); fBufferRef->SetBufferOffset(0); @@ -342,7 +340,7 @@ TKey::TKey(const void *obj, const TClass *cl, const char *name, Int_t bufsize, T Int_t cxlevel = GetFile() ? GetFile()->GetCompressionLevel() : 0; Int_t cxAlgorithm = GetFile() ? GetFile()->GetCompressionAlgorithm() : 0; if (cxlevel > 0 && fObjlen > 256) { - Int_t nbuffers = 1 + (fObjlen - 1)/kMAXBUF; + Int_t nbuffers = 1 + (fObjlen - 1)/kMAXZIPBUF; Int_t buflen = TMath::Max(512,fKeylen + fObjlen + 9*nbuffers + 28); //add 28 bytes in case object is placed in a deleted gap fBuffer = new char[buflen]; char *objbuf = fBufferRef->Buffer() + fKeylen; @@ -351,7 +349,7 @@ TKey::TKey(const void *obj, const TClass *cl, const char *name, Int_t bufsize, T nzip = 0; for (Int_t i = 0; i < nbuffers; ++i) { if (i == nbuffers - 1) bufmax = fObjlen - nzip; - else bufmax = kMAXBUF; + else bufmax = kMAXZIPBUF; R__zipMultipleAlgorithm(cxlevel, &bufmax, objbuf, &bufmax, bufcur, &nout, cxAlgorithm); if (nout == 0 || nout >= fObjlen) { //this happens when the buffer cannot be compressed fBuffer = fBufferRef->Buffer(); @@ -362,8 +360,8 @@ TKey::TKey(const void *obj, const TClass *cl, const char *name, Int_t bufsize, T } bufcur += nout; noutot += nout; - objbuf += kMAXBUF; - nzip += kMAXBUF; + objbuf += kMAXZIPBUF; + nzip += kMAXZIPBUF; } Create(noutot); fBufferRef->SetBufferOffset(0); @@ -789,7 +787,7 @@ TObject *TKey::ReadObj() while (1) { Int_t hc = R__unzip_header(&nin, bufcur, &nbuf); if (hc!=0) break; - R__unzip(&nin, bufcur, &nbuf, objbuf, &nout); + R__unzip(&nin, bufcur, &nbuf, (unsigned char*) objbuf, &nout); if (!nout) break; noutot += nout; if (noutot >= fObjlen) break; @@ -919,7 +917,7 @@ TObject *TKey::ReadObjWithBuffer(char *bufferRead) while (1) { Int_t hc = R__unzip_header(&nin, bufcur, &nbuf); if (hc!=0) break; - R__unzip(&nin, bufcur, &nbuf, objbuf, &nout); + R__unzip(&nin, bufcur, &nbuf, (unsigned char*) objbuf, &nout); if (!nout) break; noutot += nout; if (noutot >= fObjlen) break; @@ -1066,7 +1064,7 @@ void *TKey::ReadObjectAny(const TClass* expectedClass) while (1) { Int_t hc = R__unzip_header(&nin, bufcur, &nbuf); if (hc!=0) break; - R__unzip(&nin, bufcur, &nbuf, objbuf, &nout); + R__unzip(&nin, bufcur, &nbuf, (unsigned char*) objbuf, &nout); if (!nout) break; noutot += nout; if (noutot >= fObjlen) break; @@ -1156,7 +1154,7 @@ Int_t TKey::Read(TObject *obj) while (1) { Int_t hc = R__unzip_header(&nin, bufcur, &nbuf); if (hc!=0) break; - R__unzip(&nin, bufcur, &nbuf, objbuf, &nout); + R__unzip(&nin, bufcur, &nbuf, (unsigned char*) objbuf, &nout); if (!nout) break; noutot += nout; if (noutot >= fObjlen) break; diff --git a/io/xml/src/TBufferXML.cxx b/io/xml/src/TBufferXML.cxx index cff24f2e22802..4cb66b070b7f0 100644 --- a/io/xml/src/TBufferXML.cxx +++ b/io/xml/src/TBufferXML.cxx @@ -40,10 +40,7 @@ #include "TMemberStreamer.h" #include "TStreamer.h" #include "TStreamerInfoActions.h" - -extern "C" void R__zipMultipleAlgorithm(int cxlevel, int *srcsize, char *src, int *tgtsize, char *tgt, int *irep, int compressionAlgorithm); -extern "C" void R__unzip(int *srcsize, unsigned char *src, int *tgtsize, unsigned char *tgt, int *irep); -extern "C" int R__unzip_header(Int_t *nin, UChar_t *bufin, Int_t *lout); +#include "RZip.h" #ifdef R__VISUAL_CPLUSPLUS #define FLong64 "%I64d" @@ -546,7 +543,7 @@ void TBufferXML::XmlReadBlock(XMLNodePointer_t blocknode) int srcsize; int tgtsize; - int status = R__unzip_header(&srcsize, (unsigned char*) fUnzipBuffer, &tgtsize); + int status = R__unzip_header(&srcsize, (UChar_t*) fUnzipBuffer, &tgtsize); int unzipRes = 0; if (status == 0) { diff --git a/net/net/src/TMessage.cxx b/net/net/src/TMessage.cxx index 395cddcc56cda..66ae88d95afa2 100644 --- a/net/net/src/TMessage.cxx +++ b/net/net/src/TMessage.cxx @@ -25,11 +25,7 @@ #include "Bytes.h" #include "TFile.h" #include "TProcessID.h" - -extern "C" void R__zipMultipleAlgorithm(int cxlevel, int *srcsize, char *src, int *tgtsize, char *tgt, int *irep, int compressionAlgorithm); -extern "C" void R__unzip(Int_t *nin, UChar_t *bufin, Int_t *lout, char *bufout, Int_t *nout); -extern "C" int R__unzip_header(Int_t *nin, UChar_t *bufin, Int_t *lout); -const Int_t kMAXBUF = 0xffffff; +#include "RZip.h" Bool_t TMessage::fgEvolution = kFALSE; @@ -319,7 +315,7 @@ Int_t TMessage::Compress() Int_t hdrlen = 2*sizeof(UInt_t); Int_t messlen = Length() - hdrlen; - Int_t nbuffers = 1 + (messlen - 1) / kMAXBUF; + Int_t nbuffers = 1 + (messlen - 1) / kMAXZIPBUF; Int_t chdrlen = 3*sizeof(UInt_t); // compressed buffer header length Int_t buflen = TMath::Max(512, chdrlen + messlen + 9*nbuffers); fBufComp = new char[buflen]; @@ -332,7 +328,7 @@ Int_t TMessage::Compress() if (i == nbuffers - 1) bufmax = messlen - nzip; else - bufmax = kMAXBUF; + bufmax = kMAXZIPBUF; R__zipMultipleAlgorithm(compressionLevel, &bufmax, messbuf, &bufmax, bufcur, &nout, compressionAlgorithm); if (nout == 0 || nout >= messlen) { //this happens when the buffer cannot be compressed @@ -344,8 +340,8 @@ Int_t TMessage::Compress() } bufcur += nout; noutot += nout; - messbuf += kMAXBUF; - nzip += kMAXBUF; + messbuf += kMAXZIPBUF; + nzip += kMAXZIPBUF; } fBufCompCur = bufcur; fCompPos = fBufCur; @@ -392,7 +388,7 @@ Int_t TMessage::Uncompress() while (1) { Int_t hc = R__unzip_header(&nin, bufcur, &nbuf); if (hc!=0) break; - R__unzip(&nin, bufcur, &nbuf, messbuf, &nout); + R__unzip(&nin, bufcur, &nbuf, (unsigned char*) messbuf, &nout); if (!nout) break; noutot += nout; if (noutot >= buflen - hdrlen) break; diff --git a/tree/tree/src/TBasket.cxx b/tree/tree/src/TBasket.cxx index 0c47bd4c9bf1f..81e8ab8fda191 100644 --- a/tree/tree/src/TBasket.cxx +++ b/tree/tree/src/TBasket.cxx @@ -18,6 +18,7 @@ #include "TTreeCache.h" #include "TVirtualPerfStats.h" #include "TTimeStamp.h" +#include "RZip.h" // TODO: Copied from TBranch.cxx #if (__GNUC__ >= 3) || defined(__INTEL_COMPILER) @@ -32,11 +33,6 @@ #define R__likely(expr) expr #endif -extern "C" void R__zipMultipleAlgorithm(int cxlevel, int *srcsize, char *src, int *tgtsize, char *tgt, int *irep, int compressionAlgorithm); -extern "C" void R__unzip(Int_t *nin, UChar_t *bufin, Int_t *lout, char *bufout, Int_t *nout); -extern "C" int R__unzip_header(Int_t *nin, UChar_t *bufin, Int_t *lout); - -const Int_t kMAXBUF = 0xFFFFFF; const UInt_t kDisplacementMask = 0xFF000000; // In the streamer the two highest bytes of // the fEntryOffset are used to stored displacement. @@ -564,7 +560,7 @@ Int_t TBasket::ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file) goto AfterBuffer; } - R__unzip(&nin, rawCompressedObjectBuffer, &nbuf, rawUncompressedObjectBuffer, &nout); + R__unzip(&nin, rawCompressedObjectBuffer, &nbuf, (unsigned char*) rawUncompressedObjectBuffer, &nout); if (!nout) break; noutot += nout; nintot += nin; @@ -960,7 +956,7 @@ Int_t TBasket::WriteBuffer() Int_t cxlevel = fBranch->GetCompressionLevel(); Int_t cxAlgorithm = fBranch->GetCompressionAlgorithm(); if (cxlevel > 0) { - Int_t nbuffers = 1 + (fObjlen - 1) / kMAXBUF; + Int_t nbuffers = 1 + (fObjlen - 1) / kMAXZIPBUF; Int_t buflen = fKeylen + fObjlen + 9 * nbuffers + 28; //add 28 bytes in case object is placed in a deleted gap InitializeCompressedBuffer(buflen, file); if (!fCompressedBufferRef) { @@ -975,7 +971,7 @@ Int_t TBasket::WriteBuffer() nzip = 0; for (Int_t i = 0; i < nbuffers; ++i) { if (i == nbuffers - 1) bufmax = fObjlen - nzip; - else bufmax = kMAXBUF; + else bufmax = kMAXZIPBUF; //compress the buffer R__zipMultipleAlgorithm(cxlevel, &bufmax, objbuf, &bufmax, bufcur, &nout, cxAlgorithm); @@ -999,8 +995,8 @@ Int_t TBasket::WriteBuffer() } bufcur += nout; noutot += nout; - objbuf += kMAXBUF; - nzip += kMAXBUF; + objbuf += kMAXZIPBUF; + nzip += kMAXZIPBUF; } nout = noutot; Create(noutot,file);