From e9096dcd503f7481d198e7f5429cc304ab8d11d4 Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Sun, 9 Jan 2011 06:35:11 -0500 Subject: [PATCH] Switch to using C code and make the 7z deflate accessor into a C function --- 7z/7z.h | 13 +++++++------ 7z/7zdeflate.cc | 11 ++++------- 7z/Makefile | 4 ++-- general.c | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/7z/7z.h b/7z/7z.h index 4669615..6929032 100644 --- a/7z/7z.h +++ b/7z/7z.h @@ -1,15 +1,16 @@ #ifndef __7Z_H #define __7Z_H -/* #ifndef __cplusplus -extern "C++" { -#endif */ +#ifdef __cplusplus +extern "C" { +#endif + +int compress_deflate_7z(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned *out_size, unsigned num_passes, unsigned num_fast_bytes); -bool compress_deflate_7z(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned& out_size, unsigned num_passes, unsigned num_fast_bytes) throw (); -/* #ifndef __cplusplus +#ifdef __cplusplus } -#endif */ +#endif #endif diff --git a/7z/7zdeflate.cc b/7z/7zdeflate.cc index 6572000..7a33b13 100644 --- a/7z/7zdeflate.cc +++ b/7z/7zdeflate.cc @@ -2,9 +2,9 @@ #include "DeflateEncoder.h" -bool compress_deflate_7z(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned& out_size, unsigned num_passes, unsigned num_fast_bytes) throw () +extern "C" int compress_deflate_7z(const unsigned char* in_data, unsigned in_size, + unsigned char* out_data, unsigned *out_size, unsigned num_passes, unsigned num_fast_bytes) { - try { NDeflate::NEncoder::CCoder cc; if (cc.SetEncoderNumPasses(num_passes) != S_OK) @@ -14,20 +14,17 @@ bool compress_deflate_7z(const unsigned char* in_data, unsigned in_size, unsigne return false; ISequentialInStream in(reinterpret_cast(in_data), in_size); - ISequentialOutStream out(reinterpret_cast(out_data), out_size); + ISequentialOutStream out(reinterpret_cast(out_data), *out_size); UINT64 in_size_l = in_size; if (cc.Code(&in, &out, &in_size_l) != S_OK) return false; - out_size = out.size_get(); + *out_size = out.size_get(); if (out.overflow_get()) return false; return true; - } catch (...) { - return false; - } } diff --git a/7z/Makefile b/7z/Makefile index 946a3cc..f2d4a9c 100644 --- a/7z/Makefile +++ b/7z/Makefile @@ -1,8 +1,8 @@ -CC = gcc +CC = g++ SRC = 7zdeflate.cc CRC.cc DeflateEncoder.cc HuffmanEncoder.cc IInOutStreams.cc LSBFEncoder.cc OutByte.cc WindowIn.cc OBJ = $(SRC:.cc=.o) all: $(OBJ) %.o:%.cc - $(CC) -O3 -D__GNU_C__ -c $< + $(CC) -O3 -c $< diff --git a/general.c b/general.c index 767202f..1d7c03d 100644 --- a/general.c +++ b/general.c @@ -39,7 +39,7 @@ uint zlib_compress(void* src, uint srcLen, void* dest, uint destLen, int level, break; } // limits: passes [1-255], fastbytes [3-257(kMatchMaxLen)] - if(!compress_deflate_7z((unsigned char*)src, srcLen, destPtr, outSize, passes, fastbytes)) + if(!compress_deflate_7z((unsigned char*)src, srcLen, destPtr, &outSize, passes, fastbytes)) return 0; if(outSize+6 > destLen) return 0; -- 2.39.5