Skip to content

RZip.h for 5-34-00-patches #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions core/zip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,15 @@
# 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
${CMAKE_CURRENT_SOURCE_DIR}/src/ZDeflate.c
${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
Expand All @@ -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
Expand Down
32 changes: 12 additions & 20 deletions core/zip/Module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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)

Expand All @@ -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 $@..."
Expand All @@ -95,3 +86,4 @@ distclean-$(MODNAME): clean-$(MODNAME)
@rm -f $(ZIPDEP) $(ZIPDS) $(ZIPDH)

distclean:: distclean-$(MODNAME)

29 changes: 29 additions & 0 deletions core/zip/inc/RZip.h
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions core/zip/src/RZip.cxx
Original file line number Diff line number Diff line change
@@ -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);
}
30 changes: 14 additions & 16 deletions io/io/src/TKey.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions io/xml/src/TBufferXML.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 6 additions & 10 deletions net/net/src/TMessage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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];
Expand All @@ -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
Expand All @@ -344,8 +340,8 @@ Int_t TMessage::Compress()
}
bufcur += nout;
noutot += nout;
messbuf += kMAXBUF;
nzip += kMAXBUF;
messbuf += kMAXZIPBUF;
nzip += kMAXZIPBUF;
}
fBufCompCur = bufcur;
fCompPos = fBufCur;
Expand Down Expand Up @@ -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;
Expand Down
Loading